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