update dev300-m58
[ooovba.git] / shell / source / win32 / shlxthandler / propsheets / listviewbuilder.cxx
blob4d4396f06b7e13cb266ad9135143830f71b35f04
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: listviewbuilder.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
34 #ifdef _MSC_VER
35 #pragma warning (disable : 4786 4503)
36 #endif
38 //------------------------------------
39 // include
40 //------------------------------------
41 #include "listviewbuilder.hxx"
42 #include "document_statistic.hxx"
43 #include "internal/utilities.hxx"
44 #include "internal/config.hxx"
46 #if defined _MSC_VER
47 #pragma warning(push, 1)
48 #endif
49 #include <commctrl.h>
50 #if defined _MSC_VER
51 #pragma warning(pop)
52 #endif
53 #include <commctrl.h>
54 #include <tchar.h>
55 #include "internal/resource.h"
57 //------------------------------------
59 //------------------------------------
61 list_view_builder_ptr create_list_view_builder(
62 HWND hwnd_lv, const std::wstring& col1, const std::wstring& col2)
64 if (is_windows_xp_or_above())
65 return list_view_builder_ptr(new winxp_list_view_builder(hwnd_lv, col1, col2));
66 else
67 return list_view_builder_ptr(new list_view_builder(hwnd_lv, col1, col2));
70 //------------------------------------
72 //------------------------------------
74 list_view_builder::list_view_builder(
75 HWND hwnd_list_view,
76 const std::wstring& column1_title,
77 const std::wstring& column2_title) :
78 hwnd_list_view_(hwnd_list_view),
79 row_index_(-1),
80 column1_title_(column1_title),
81 column2_title_(column2_title)
85 //------------------------------------
87 //------------------------------------
89 list_view_builder::~list_view_builder()
93 //------------------------------------
95 //------------------------------------
97 void list_view_builder::build(statistic_group_list_t& gl)
99 setup_list_view();
101 statistic_group_list_t::iterator group_iter = gl.begin();
102 statistic_group_list_t::iterator group_iter_end = gl.end();
104 for (/**/; group_iter != group_iter_end; ++group_iter)
106 statistic_item_list_t::iterator item_iter = group_iter->second.begin();
107 statistic_item_list_t::iterator item_iter_end = group_iter->second.end();
109 if (item_iter != item_iter_end)
110 insert_group(group_iter->first);
112 for (/**/; item_iter != item_iter_end; ++item_iter)
113 insert_item(item_iter->title_, item_iter->value_, item_iter->editable_);
117 //------------------------------------
119 //------------------------------------
121 void list_view_builder::setup_list_view()
123 HIMAGELIST h_ils = ImageList_Create(16,15,ILC_MASK, 7, 0);
124 HBITMAP h_bmp = LoadBitmap(GetModuleHandle(MODULE_NAME), MAKEINTRESOURCE(IDB_PROPERTY_IMAGES));
125 ImageList_AddMasked(h_ils, h_bmp, RGB(255, 0, 255));
127 ListView_SetImageList(hwnd_list_view_, h_ils, LVSIL_SMALL);
129 std::wstring header = GetResString(IDS_PROPERTY);
131 LVCOLUMN lvc;
132 lvc.mask = LVCF_FMT |
133 LVCF_WIDTH |
134 LVCF_TEXT |
135 LVCF_SUBITEM;
137 lvc.iSubItem = 0;
138 lvc.pszText = const_cast<wchar_t*>(header.c_str());
139 lvc.cx = 120;
140 lvc.fmt = LVCFMT_LEFT;
142 ListView_InsertColumn(hwnd_list_view_, 0, &lvc);
143 lvc.iSubItem = 1;
144 header = GetResString(IDS_PROPERTY_VALUE);
145 lvc.pszText = const_cast<wchar_t*>(header.c_str());
146 ListView_InsertColumn(hwnd_list_view_, 1, &lvc);
149 //------------------------------------
151 //------------------------------------
153 void list_view_builder::insert_group(const std::wstring& /*title*/)
155 insert_item(L"", L"", false);
158 //------------------------------------
160 //------------------------------------
162 void list_view_builder::insert_item(const std::wstring& title, const std::wstring& value, bool is_editable)
164 LVITEM lvi;
166 lvi.iItem = ++row_index_;
167 lvi.iSubItem = 0;
168 lvi.mask = LVIF_TEXT;
169 lvi.state = 0;
170 lvi.cchTextMax = title.size() + 1;
171 lvi.stateMask = 0;
172 lvi.pszText = const_cast<wchar_t*>(title.c_str());
174 if (title.length() > 0)
176 lvi.mask |= LVIF_IMAGE;
178 if (is_editable)
179 lvi.iImage = 4;
180 else
181 lvi.iImage = 3;
184 ListView_InsertItem(hwnd_list_view_, &lvi);
186 lvi.mask = LVIF_TEXT;
187 lvi.iSubItem = 1;
188 lvi.pszText = const_cast<wchar_t*>(value.c_str());
190 ListView_SetItem(hwnd_list_view_, &lvi);
193 //------------------------------------
195 //------------------------------------
197 HWND list_view_builder::get_list_view() const
199 return hwnd_list_view_;
202 //------------------------------------
204 //------------------------------------
206 winxp_list_view_builder::winxp_list_view_builder(
207 HWND hwnd_list_view,
208 const std::wstring& column1_title,
209 const std::wstring& column2_title) :
210 list_view_builder(hwnd_list_view, column1_title, column2_title),
211 group_count_(-1),
212 row_count_(0)
216 //------------------------------------
218 //------------------------------------
220 void winxp_list_view_builder::setup_list_view()
222 list_view_builder::setup_list_view();
224 ListView_EnableGroupView(get_list_view(), TRUE);
227 //------------------------------------
229 //------------------------------------
231 void winxp_list_view_builder::insert_group(const std::wstring& name)
233 LVGROUP lvg;
235 ZeroMemory(&lvg, sizeof(lvg));
237 lvg.cbSize = sizeof(lvg);
238 lvg.mask = LVGF_HEADER | LVGF_STATE | LVGF_GROUPID;
239 lvg.pszHeader = const_cast<wchar_t*>(name.c_str());
240 lvg.cchHeader = name.size() + 1;
241 lvg.iGroupId = ++group_count_;
242 lvg.state = LVGS_NORMAL;
243 lvg.uAlign = LVGA_HEADER_CENTER;
245 ListView_InsertGroup(get_list_view(), row_count_++, &lvg);
248 //------------------------------------
250 //------------------------------------
252 void winxp_list_view_builder::insert_item(
253 const std::wstring& title, const std::wstring& value, bool is_editable)
255 LVITEM lvi;
257 lvi.iItem = ++row_index_;
258 lvi.iSubItem = 0;
259 lvi.mask = LVIF_TEXT | LVIF_GROUPID;
260 lvi.state = 0;
261 lvi.stateMask = 0;
262 lvi.pszText = const_cast<wchar_t*>(title.c_str());
263 lvi.iGroupId = group_count_;
265 if (title.length() > 0)
267 lvi.mask |= LVIF_IMAGE;
269 if (is_editable)
270 lvi.iImage = 4;
271 else
272 lvi.iImage = 3;
275 ListView_InsertItem(get_list_view(), &lvi);
277 lvi.mask = LVIF_TEXT;
278 lvi.iSubItem = 1;
279 lvi.pszText = const_cast<wchar_t*>(value.c_str());
281 ListView_SetItem(get_list_view(), &lvi);
283 row_count_++;