1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #pragma warning (disable : 4786 4503)
25 #include "listviewbuilder.hxx"
26 #include "document_statistic.hxx"
27 #include "internal/utilities.hxx"
28 #include "internal/config.hxx"
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
));
42 return list_view_builder_ptr(new list_view_builder(hwnd_lv
, col1
, col2
));
47 list_view_builder::list_view_builder(
49 const std::wstring
& column1_title
,
50 const std::wstring
& column2_title
) :
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
)
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
);
105 lvc
.pszText
= const_cast<wchar_t*>(header
.c_str());
107 lvc
.fmt
= LVCFMT_LEFT
;
109 ListView_InsertColumn(hwnd_list_view_
, 0, &lvc
);
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
)
129 lvi
.iItem
= ++row_index_
;
131 lvi
.mask
= LVIF_TEXT
;
133 lvi
.cchTextMax
= static_cast<int>(title
.size() + 1);
135 lvi
.pszText
= const_cast<wchar_t*>(title
.c_str());
137 if (title
.length() > 0)
139 lvi
.mask
|= LVIF_IMAGE
;
147 ListView_InsertItem(hwnd_list_view_
, &lvi
);
149 lvi
.mask
= LVIF_TEXT
;
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(
167 const std::wstring
& column1_title
,
168 const std::wstring
& column2_title
) :
169 list_view_builder(hwnd_list_view
, column1_title
, column2_title
),
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
)
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
)
210 lvi
.iItem
= ++row_index_
;
212 lvi
.mask
= LVIF_TEXT
| LVIF_GROUPID
;
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
;
228 ListView_InsertItem(get_list_view(), &lvi
);
230 lvi
.mask
= LVIF_TEXT
;
232 lvi
.pszText
= const_cast<wchar_t*>(value
.c_str());
234 ListView_SetItem(get_list_view(), &lvi
);
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */