1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: listviewbuilder.cxx,v $
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"
35 #pragma warning (disable : 4786 4503)
38 //------------------------------------
40 //------------------------------------
41 #include "listviewbuilder.hxx"
42 #include "document_statistic.hxx"
43 #include "internal/utilities.hxx"
44 #include "internal/config.hxx"
47 #pragma warning(push, 1)
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
));
67 return list_view_builder_ptr(new list_view_builder(hwnd_lv
, col1
, col2
));
70 //------------------------------------
72 //------------------------------------
74 list_view_builder::list_view_builder(
76 const std::wstring
& column1_title
,
77 const std::wstring
& column2_title
) :
78 hwnd_list_view_(hwnd_list_view
),
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
)
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
);
132 lvc
.mask
= LVCF_FMT
|
138 lvc
.pszText
= const_cast<wchar_t*>(header
.c_str());
140 lvc
.fmt
= LVCFMT_LEFT
;
142 ListView_InsertColumn(hwnd_list_view_
, 0, &lvc
);
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
)
166 lvi
.iItem
= ++row_index_
;
168 lvi
.mask
= LVIF_TEXT
;
170 lvi
.cchTextMax
= title
.size() + 1;
172 lvi
.pszText
= const_cast<wchar_t*>(title
.c_str());
174 if (title
.length() > 0)
176 lvi
.mask
|= LVIF_IMAGE
;
184 ListView_InsertItem(hwnd_list_view_
, &lvi
);
186 lvi
.mask
= LVIF_TEXT
;
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(
208 const std::wstring
& column1_title
,
209 const std::wstring
& column2_title
) :
210 list_view_builder(hwnd_list_view
, column1_title
, column2_title
),
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
)
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
)
257 lvi
.iItem
= ++row_index_
;
259 lvi
.mask
= LVIF_TEXT
| LVIF_GROUPID
;
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
;
275 ListView_InsertItem(get_list_view(), &lvi
);
277 lvi
.mask
= LVIF_TEXT
;
279 lvi
.pszText
= const_cast<wchar_t*>(value
.c_str());
281 ListView_SetItem(get_list_view(), &lvi
);