Bump version to 5.0-14
[LibreOffice.git] / shell / source / win32 / shlxthandler / propsheets / listviewbuilder.cxx
blob7984f2dc22dc82efea200af47e0b8aab4f211e5b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #ifdef _MSC_VER
22 #pragma warning (disable : 4786 4503)
23 #endif
25 #include "listviewbuilder.hxx"
26 #include "document_statistic.hxx"
27 #include "internal/utilities.hxx"
28 #include "internal/config.hxx"
30 #include <commctrl.h>
31 #include <tchar.h>
32 #include "internal/resource.h"
36 list_view_builder_ptr create_list_view_builder(
37 HWND hwnd_lv, const std::wstring& col1, const std::wstring& col2)
39 if (is_windows_xp_or_above())
40 return list_view_builder_ptr(new winxp_list_view_builder(hwnd_lv, col1, col2));
41 else
42 return list_view_builder_ptr(new list_view_builder(hwnd_lv, col1, col2));
47 list_view_builder::list_view_builder(
48 HWND hwnd_list_view,
49 const std::wstring& column1_title,
50 const std::wstring& column2_title) :
51 row_index_(-1),
52 hwnd_list_view_(hwnd_list_view),
53 column1_title_(column1_title),
54 column2_title_(column2_title)
60 list_view_builder::~list_view_builder()
66 void list_view_builder::build(statistic_group_list_t& gl)
68 setup_list_view();
70 statistic_group_list_t::iterator group_iter = gl.begin();
71 statistic_group_list_t::iterator group_iter_end = gl.end();
73 for (/**/; group_iter != group_iter_end; ++group_iter)
75 statistic_item_list_t::iterator item_iter = group_iter->second.begin();
76 statistic_item_list_t::iterator item_iter_end = group_iter->second.end();
78 if (item_iter != item_iter_end)
79 insert_group(group_iter->first);
81 for (/**/; item_iter != item_iter_end; ++item_iter)
82 insert_item(item_iter->title_, item_iter->value_, item_iter->editable_);
88 void list_view_builder::setup_list_view()
90 HIMAGELIST h_ils = ImageList_Create(16,15,ILC_MASK, 7, 0);
91 HBITMAP h_bmp = LoadBitmap(GetModuleHandle(MODULE_NAME), MAKEINTRESOURCE(IDB_PROPERTY_IMAGES));
92 ImageList_AddMasked(h_ils, h_bmp, RGB(255, 0, 255));
94 (void) ListView_SetImageList(hwnd_list_view_, h_ils, LVSIL_SMALL);
96 std::wstring header = GetResString(IDS_PROPERTY);
98 LVCOLUMN lvc;
99 lvc.mask = LVCF_FMT |
100 LVCF_WIDTH |
101 LVCF_TEXT |
102 LVCF_SUBITEM;
104 lvc.iSubItem = 0;
105 lvc.pszText = const_cast<wchar_t*>(header.c_str());
106 lvc.cx = 120;
107 lvc.fmt = LVCFMT_LEFT;
109 ListView_InsertColumn(hwnd_list_view_, 0, &lvc);
110 lvc.iSubItem = 1;
111 header = GetResString(IDS_PROPERTY_VALUE);
112 lvc.pszText = const_cast<wchar_t*>(header.c_str());
113 ListView_InsertColumn(hwnd_list_view_, 1, &lvc);
118 void list_view_builder::insert_group(const std::wstring& /*title*/)
120 insert_item(L"", L"", false);
125 void list_view_builder::insert_item(const std::wstring& title, const std::wstring& value, bool is_editable)
127 LVITEM lvi;
129 lvi.iItem = ++row_index_;
130 lvi.iSubItem = 0;
131 lvi.mask = LVIF_TEXT;
132 lvi.state = 0;
133 lvi.cchTextMax = static_cast<int>(title.size() + 1);
134 lvi.stateMask = 0;
135 lvi.pszText = const_cast<wchar_t*>(title.c_str());
137 if (title.length() > 0)
139 lvi.mask |= LVIF_IMAGE;
141 if (is_editable)
142 lvi.iImage = 4;
143 else
144 lvi.iImage = 3;
147 ListView_InsertItem(hwnd_list_view_, &lvi);
149 lvi.mask = LVIF_TEXT;
150 lvi.iSubItem = 1;
151 lvi.pszText = const_cast<wchar_t*>(value.c_str());
153 ListView_SetItem(hwnd_list_view_, &lvi);
158 HWND list_view_builder::get_list_view() const
160 return hwnd_list_view_;
165 winxp_list_view_builder::winxp_list_view_builder(
166 HWND hwnd_list_view,
167 const std::wstring& column1_title,
168 const std::wstring& column2_title) :
169 list_view_builder(hwnd_list_view, column1_title, column2_title),
170 group_count_(-1),
171 row_count_(0)
177 void winxp_list_view_builder::setup_list_view()
179 list_view_builder::setup_list_view();
181 ListView_EnableGroupView(get_list_view(), TRUE);
186 void winxp_list_view_builder::insert_group(const std::wstring& name)
188 LVGROUP lvg;
190 ZeroMemory(&lvg, sizeof(lvg));
192 lvg.cbSize = sizeof(lvg);
193 lvg.mask = LVGF_HEADER | LVGF_STATE | LVGF_GROUPID;
194 lvg.pszHeader = const_cast<wchar_t*>(name.c_str());
195 lvg.cchHeader = static_cast<int>(name.size() + 1);
196 lvg.iGroupId = ++group_count_;
197 lvg.state = LVGS_NORMAL;
198 lvg.uAlign = LVGA_HEADER_CENTER;
200 ListView_InsertGroup(get_list_view(), row_count_++, &lvg);
205 void winxp_list_view_builder::insert_item(
206 const std::wstring& title, const std::wstring& value, bool is_editable)
208 LVITEM lvi;
210 lvi.iItem = ++row_index_;
211 lvi.iSubItem = 0;
212 lvi.mask = LVIF_TEXT | LVIF_GROUPID;
213 lvi.state = 0;
214 lvi.stateMask = 0;
215 lvi.pszText = const_cast<wchar_t*>(title.c_str());
216 lvi.iGroupId = group_count_;
218 if (title.length() > 0)
220 lvi.mask |= LVIF_IMAGE;
222 if (is_editable)
223 lvi.iImage = 4;
224 else
225 lvi.iImage = 3;
228 ListView_InsertItem(get_list_view(), &lvi);
230 lvi.mask = LVIF_TEXT;
231 lvi.iSubItem = 1;
232 lvi.pszText = const_cast<wchar_t*>(value.c_str());
234 ListView_SetItem(get_list_view(), &lvi);
236 row_count_++;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */