GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
ITextIconListView.cpp
Go to the documentation of this file.
1#include "ITextIconListView.h"
2
3using namespace std;
4
5namespace gui_framework
6{
7 namespace interfaces
8 {
9 void ITextIconListView::onRemove(size_t index)
10 {
11 textData.erase(index);
12 }
13
14 LVITEMW ITextIconListView::makeItem(std::wstring_view text, const std::filesystem::path& pathToIcon, size_t index)
15 {
16 LVITEMW item = {};
17
18 if (!icons.contains(pathToIcon))
19 {
20 icons.addImage(pathToIcon);
21 }
22
23 item.mask = LVIF_TEXT | LVIF_IMAGE;
24 item.pszText = const_cast<wchar_t*>(text.data());
25 item.cchTextMax = static_cast<int>(text.size());
26 item.iImage = icons[pathToIcon];
27 item.iItem = static_cast<int>(index);
28
29 return item;
30 }
31
34 icons(icons)
35 {
36
37 }
38
39 LRESULT ITextIconListView::addTextIconItem(wstring_view text, const filesystem::path& pathToIcon)
40 {
41 return this->insertTextIconItem(text, pathToIcon, this->size());
42 }
43
44 LRESULT ITextIconListView::addTextIconItem(string_view localizationKey, const filesystem::path& pathToIcon)
45 {
46 return this->addTextIconItem(localization::WTextLocalization::get()[localizationKey], pathToIcon);
47 }
48
49 LRESULT ITextIconListView::insertTextIconItem(wstring_view text, const filesystem::path& pathToIcon, size_t index)
50 {
51 LRESULT result = this->addItem(this->makeItem(text, pathToIcon, index));
52
53 if (result != -1)
54 {
55 textData[index] = text.size();
56 }
57
58 return result;
59 }
60
61 LRESULT ITextIconListView::insertTextIconItem(string_view localizationKey, const filesystem::path& pathToIcon, size_t index)
62 {
63 return this->insertTextIconItem(localization::WTextLocalization::get()[localizationKey], pathToIcon, index);
64 }
65
66 LRESULT ITextIconListView::changeTextIconItem(wstring_view text, const filesystem::path& pathToIcon, size_t index)
67 {
68 LRESULT result = this->setItem(this->makeItem(text, pathToIcon, index));
69
70 if (result != -1)
71 {
72 textData[index] = text.size();
73 }
74
75 return result;
76 }
77
78 LRESULT ITextIconListView::changeTextIconItem(string_view localizationKey, const filesystem::path& pathToIcon, size_t index)
79 {
80 return this->changeTextIconItem(localization::WTextLocalization::get()[localizationKey], pathToIcon, index);
81 }
82
83 tuple<wstring, uint16_t, filesystem::path> ITextIconListView::getTextIconItem(size_t index) const
84 {
85 LVITEMW item = {};
86 wstring text;
87
88 try
89 {
90 text.resize(textData.at(index) + 1);
91 }
92 catch (const out_of_range&)
93 {
94 return {};
95 }
96
97 item.iItem = static_cast<int>(index);
98 item.mask = LVIF_TEXT | LVIF_IMAGE;
99 item.pszText = text.data();
100 item.cchTextMax = static_cast<int>(text.size());
101
102 this->getItem(item);
103
104 text.pop_back();
105
106 return { text, static_cast<uint16_t>(item.iImage), icons[item.iImage] };
107 }
108 }
109}
Provides adding, deleting, setting, getting items for other list view interfaces.
virtual LRESULT addTextIconItem(std::wstring_view text, const std::filesystem::path &pathToIcon)
virtual LRESULT changeTextIconItem(std::wstring_view text, const std::filesystem::path &pathToIcon, size_t index)
ITextIconListView(HWND handle, utility::IconsHolder &icons)
virtual std::tuple< std::wstring, uint16_t, std::filesystem::path > getTextIconItem(size_t index) const
virtual LRESULT insertTextIconItem(std::wstring_view text, const std::filesystem::path &pathToIcon, size_t index)
virtual bool contains(const std::filesystem::path &pathToImage) const final
uint16_t addImage(const std::filesystem::path &pathToIcon) override