GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
BaseMultipleSelectListBox.cpp
Go to the documentation of this file.
2
5
6#pragma push_macro("min")
7#undef min
8
9using namespace std;
10
11namespace gui_framework
12{
15 (
16 listBoxName,
17 settings,
18 styles::MultipleSelectListBoxStyles(),
19 parent
20 )
21 {
22
23 }
24
26 {
27 LRESULT result = SendMessageW(handle, LB_GETSELCOUNT, NULL, NULL);
28
29 if (result == LB_ERR)
30 {
31 throw exceptions::SelectListException(__FUNCTION__, result, __FILE__, __FUNCTION__, __LINE__);
32 }
33
34 return result;
35 }
36
38 {
39 WPARAM itemsCount = this->getCurrentSelections();
40 vector<wstring> items;
41 vector<int> indices(itemsCount);
42
43 LRESULT result = SendMessageW(handle, LB_GETSELITEMS, itemsCount, reinterpret_cast<LPARAM>(indices.data()));
44
45 if (result == LB_ERR)
46 {
47 throw exceptions::SelectListException(__FUNCTION__, result, __FILE__, __FUNCTION__, __LINE__);
48 }
49
50 items.reserve(itemsCount);
51
52 for (const auto& i : indices)
53 {
54 items.push_back(this->getValue(i));
55 }
56
57 return items;
58 }
59
60 void BaseMultipleSelectListBox::selectMultipleItems(WPARAM firstItemIndex, LPARAM lastItemIndex) const
61 {
62 if (SendMessageW(handle, LB_SELITEMRANGEEX, firstItemIndex, lastItemIndex) == LB_ERR)
63 {
64 throw exceptions::SelectListException(__FUNCTION__, LB_ERR, __FILE__, __FUNCTION__, __LINE__);
65 }
66 }
67
69 {
70 LRESULT result = SendMessageW(handle, LB_SETSEL, true, index);
71
72 if (result == LB_ERR)
73 {
74 throw exceptions::SelectListException(__FUNCTION__, result, __FILE__, __FUNCTION__, __LINE__);
75 }
76
77 return result;
78 }
79
81 {
82 using json::utility::jsonObject;
83
84 json::JSONBuilder builder = BaseComponent::getStructure();
85 jsonObject& current = get<jsonObject>(builder[utility::to_string(windowName, ISerializable::getCodepage())]);
86
87 return builder;
88 }
89}
90
91#pragma pop_macro("min")
virtual json::JSONBuilder getStructure() const override
const std::wstring windowName
Base class for all windows that has children windows.
Base class for all list boxes.
Definition BaseListBox.h:15
std::wstring getValue(size_t index) const
void selectMultipleItems(WPARAM firstItemIndex, LPARAM lastItemIndex) const
BaseMultipleSelectListBox(const std::wstring &listBoxName, const utility::ComponentSettings &settings, BaseComposite *parent)
virtual json::JSONBuilder getStructure() const override
std::vector< std::wstring > getSelectedItems() const
virtual LRESULT setCurrentSelection(LRESULT index) const final override
Exception for all list classes exceptions.
string to_string(wstring_view stringToConvert, uint32_t codepage)
Definition Utility.cpp:41