GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
IMenuItem.cpp
Go to the documentation of this file.
1#include "IMenuItem.h"
2
3#include "Utility/Utility.h"
4
5using namespace std;
6
7namespace gui_framework
8{
9 namespace interfaces
10 {
11 IMenuItem::IMenuItem(const wstring& text, const string& type) :
12 text(text),
13 type(type),
14 parent(nullptr),
15 index(0)
16 {
17
18 }
19
20 void IMenuItem::createMenuItem(HMENU parent)
21 {
22 this->setParent(parent);
23
24 auto [styles, value] = this->getCreationData();
25
26 AppendMenuW(parent, styles | MF_STRING, value, text.data());
27 }
28
29 void IMenuItem::setParent(HMENU parent)
30 {
31 this->parent = parent;
32 }
33
34 void IMenuItem::setIndex(uint32_t index)
35 {
36 this->index = index;
37 }
38
39 const wstring& IMenuItem::getText() const
40 {
41 return text;
42 }
43
44 const string& IMenuItem::getType() const
45 {
46 return type;
47 }
48
49 json::JSONBuilder IMenuItem::getStructure() const
50 {
51 uint32_t codepage = ISerializable::getCodepage();
52 json::JSONBuilder builder(codepage);
53
54 builder.
55 append("itemText"s, utility::to_string(text, codepage)).
56 append("itemType"s, type);
57
58 return builder;
59 }
60
62 {
63 DeleteMenu(parent, index, MF_BYPOSITION);
64 }
65 }
66}
virtual json::JSONBuilder getStructure() const override
Definition IMenuItem.cpp:49
virtual void createMenuItem(HMENU parent) final
Definition IMenuItem.cpp:20
virtual const std::string & getType() const final
Definition IMenuItem.cpp:44
virtual std::tuple< uint32_t, uint64_t > getCreationData() const =0
virtual void setIndex(uint32_t index) final
Definition IMenuItem.cpp:34
virtual const std::wstring & getText() const final
Definition IMenuItem.cpp:39
IMenuItem(const std::wstring &text, const std::string &type)
Definition IMenuItem.cpp:11
virtual void setParent(HMENU parent) final
Definition IMenuItem.cpp:29
string to_string(wstring_view stringToConvert, uint32_t codepage)
Definition Utility.cpp:41