LibreOffice Module shell (master) 1
listviewbuilder.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "listviewbuilder.hxx"
23#include <utilities.hxx>
24#include <config.hxx>
25#include <global.hxx>
26
27#include <commctrl.h>
28#include <resource.h>
29
30// Unicode-only defines to break dependence on UNICODE define
31#if !defined ListView_InsertColumnW
32#define ListView_InsertColumnW(hwnd, iCol, pcol) \
33 static_cast<int>(SNDMSG((hwnd), LVM_INSERTCOLUMNW, WPARAM(int(iCol)), reinterpret_cast<LPARAM>(pcol)))
34#endif
35
36#if !defined ListView_InsertItemW
37#define ListView_InsertItemW(hwnd, pitem) \
38 static_cast<int>(SNDMSG((hwnd), LVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(pitem)))
39#endif
40
41#if !defined ListView_SetItemW
42#define ListView_SetItemW(hwnd, pitem) \
43 static_cast<bool>(SNDMSG((hwnd), LVM_SETITEMW, 0, reinterpret_cast<LPARAM>(pitem)))
44#endif
45
46
48 HWND hwnd_lv, const std::wstring& col1, const std::wstring& col2)
49{
50 return list_view_builder_ptr(new list_view_builder(hwnd_lv, col1, col2));
51}
52
53
55 HWND hwnd_list_view,
56 const std::wstring& column1_title,
57 const std::wstring& column2_title) :
58 row_index_(-1),
59 hwnd_list_view_(hwnd_list_view),
60 column1_title_(column1_title),
61 column2_title_(column2_title),
62 group_count_(-1),
63 row_count_(0)
64{
65}
66
69{
70}
71
72
74{
76
77 for (const auto& group : gl)
78 {
79 if (!group.second.empty())
80 insert_group(group.first);
81
82 for (const auto& item : group.second)
83 insert_item(item.title_, item.value_, item.editable_);
84 }
85}
86
87
89{
90 HIMAGELIST h_ils = ImageList_Create(16,15,ILC_MASK, 7, 0);
91 HBITMAP h_bmp = LoadBitmapW(GetCurrentModuleHandle(), MAKEINTRESOURCEW(IDB_PROPERTY_IMAGES));
92 ImageList_AddMasked(h_ils, h_bmp, RGB(255, 0, 255));
93
94 (void) ListView_SetImageList(hwnd_list_view_, h_ils, LVSIL_SMALL);
95
96 std::wstring header = GetResString(IDS_PROPERTY);
97
98 LVCOLUMNW lvc;
99 lvc.mask = LVCF_FMT |
100 LVCF_WIDTH |
101 LVCF_TEXT |
102 LVCF_SUBITEM;
103
104 lvc.iSubItem = 0;
105 lvc.pszText = const_cast<wchar_t*>(header.c_str());
106 lvc.cx = 120;
107 lvc.fmt = LVCFMT_LEFT;
108
110 lvc.iSubItem = 1;
112 lvc.pszText = const_cast<wchar_t*>(header.c_str());
114 ListView_EnableGroupView(hwnd_list_view_, TRUE);
115}
116
117
118void list_view_builder::insert_group(const std::wstring& name)
119{
120 LVGROUP lvg;
121
122 ZeroMemory(&lvg, sizeof(lvg));
123
124 lvg.cbSize = sizeof(lvg);
125 lvg.mask = LVGF_HEADER | LVGF_STATE | LVGF_GROUPID;
126 lvg.pszHeader = const_cast<wchar_t*>(name.c_str());
127 lvg.cchHeader = static_cast<int>(name.size() + 1);
128 lvg.iGroupId = ++group_count_;
129 lvg.state = LVGS_NORMAL;
130 lvg.uAlign = LVGA_HEADER_CENTER;
131
132 ListView_InsertGroup(get_list_view(), row_count_++, &lvg);
133}
134
135
136void list_view_builder::insert_item(const std::wstring& title, const std::wstring& value, bool is_editable)
137{
138 LVITEMW lvi;
139
140 lvi.iItem = ++row_index_;
141 lvi.iSubItem = 0;
142 lvi.mask = LVIF_TEXT | LVIF_GROUPID;
143 lvi.state = 0;
144 lvi.stateMask = 0;
145 lvi.pszText = const_cast<wchar_t*>(title.c_str());
146 lvi.iGroupId = group_count_;
147
148 if (title.length() > 0)
149 {
150 lvi.mask |= LVIF_IMAGE;
151
152 if (is_editable)
153 lvi.iImage = 4;
154 else
155 lvi.iImage = 3;
156 }
157
159
160 lvi.mask = LVIF_TEXT;
161 lvi.iSubItem = 1;
162 lvi.pszText = const_cast<wchar_t*>(value.c_str());
163
165
166 row_count_++;
167}
168
169
171{
172 return hwnd_list_view_;
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_Int8 header[]
virtual ~list_view_builder()
HWND get_list_view() const
virtual void insert_item(const std::wstring &title, const std::wstring &value, bool is_editable)
list_view_builder(HWND hwnd_list_view, const std::wstring &column1_title, const std::wstring &column2_title)
virtual void insert_group(const std::wstring &title)
virtual void setup_list_view()
void build(statistic_group_list_t &gl)
Any value
std::vector< statistic_group_t > statistic_group_list_t
#define TRUE
const char * name
#define ListView_InsertColumnW(hwnd, iCol, pcol)
#define ListView_InsertItemW(hwnd, pitem)
list_view_builder_ptr create_list_view_builder(HWND hwnd_lv, const std::wstring &col1, const std::wstring &col2)
#define ListView_SetItemW(hwnd, pitem)
std::unique_ptr< list_view_builder > list_view_builder_ptr
group
#define IDB_PROPERTY_IMAGES
Definition: resource.h:26
#define IDS_PROPERTY_VALUE
Definition: resource.h:52
#define IDS_PROPERTY
Definition: resource.h:51
std::wstring GetResString(int ResId)
Retrieve a string from the resources of this module.
Definition: utilities.cxx:81
HMODULE GetCurrentModuleHandle()
Definition: utilities.cxx:549