GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
BaseCheckBox.cpp
Go to the documentation of this file.
1#include "BaseCheckBox.h"
2
4#include "GUIFramework.h"
5
7
8using namespace std;
9
10namespace gui_framework
11{
12 LRESULT BaseCheckBox::windowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam, bool& isUsed)
13 {
14 if (message == WM_COMMAND && id == LOWORD(wparam))
15 {
16 isUsed = true;
17
18 LRESULT state = SendMessageW(this->handle, BM_GETCHECK, NULL, NULL);
19
20 SendMessageW(this->handle, BM_SETCHECK, !state, NULL);
21
22 if (onClear && state == BST_CHECKED)
23 {
24 onClear();
25
26 return 0;
27 }
28 else if (onCheck && state == BST_UNCHECKED)
29 {
30 onCheck();
31
32 return 0;
33 }
34 else if (onClick)
35 {
36 onClick();
37
38 return 0;
39 }
40 }
41
42 isUsed = false;
43
44 return -1;
45 }
46
47 BaseCheckBox::BaseCheckBox(const wstring& checkBoxName, const wstring& checkBoxText, const utility::ComponentSettings& settings, BaseComposite* parent, const function<void()>& onCheck, const function<void()>& onClear, const function<void()>& onClick) :
49 (
50 checkBoxName,
51 checkBoxText,
52 settings,
53 styles::CheckBoxStyles(),
54 parent,
55 onClick
56 ),
57 onCheck(onCheck),
58 onClear(onClear)
59 {
60
61 }
62
63 void BaseCheckBox::setOnCheck(const function<void()>& onCheck)
64 {
65 this->onCheck = onCheck;
66
67 onCheckFunctionName.clear();
68 onCheckModuleName.clear();
69 }
70
71 void BaseCheckBox::setOnCheck(const string& functionName, const string& moduleName)
72 {
73 GUIFramework& instance = GUIFramework::get();
74 const HMODULE& module = instance.getModules().at(moduleName);
75
76 onClickSignature tem = reinterpret_cast<onClickSignature>(GetProcAddress(module, functionName.data()));
77
78 if (!tem)
79 {
80 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
81 }
82
83 onCheck = tem;
84
87 }
88
89 void BaseCheckBox::setOnClear(const function<void()>& onClear)
90 {
91 this->onClear = onClear;
92
93 onClearFunctionName.clear();
94 onClearModuleName.clear();
95 }
96
97 void BaseCheckBox::setOnClear(const string& functionName, const string& moduleName)
98 {
99 GUIFramework& instance = GUIFramework::get();
100 const HMODULE& module = instance.getModules().at(moduleName);
101
102 onClickSignature tem = reinterpret_cast<onClickSignature>(GetProcAddress(module, functionName.data()));
103
104 if (!tem)
105 {
106 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
107 }
108
109 onClear = tem;
110
113 }
114
115 const function<void()>& BaseCheckBox::getOnCheck() const
116 {
117 return onCheck;
118 }
119
120 const function<void()>& BaseCheckBox::getOnClear() const
121 {
122 return onClear;
123 }
124
125 json::JSONBuilder BaseCheckBox::getStructure() const
126 {
127 using json::utility::jsonObject;
128
129 if (onCheckFunctionName.empty() && onClearFunctionName.empty())
130 {
132 }
133
134 json::JSONBuilder builder = BaseButton::getStructure();
135 jsonObject& current = get<jsonObject>(builder[utility::to_string(windowName, ISerializable::getCodepage())]);
136 const auto& modulesPaths = GUIFramework::get().getModulesPaths();
137
138 if (onCheckFunctionName.size())
139 {
140 current.data.push_back({ "checkFunctionName"s, onCheckFunctionName });
141
142 current.data.push_back({ "checkModuleName"s, modulesPaths.at(onCheckModuleName) });
143 }
144
145 if (onClearFunctionName.size())
146 {
147 current.data.push_back({ "clearFunctionName"s, onClearFunctionName });
148
149 current.data.push_back({ "clearModuleName"s, modulesPaths.at(onClearModuleName) });
150 }
151
152 return builder;
153 }
154}
Base class for all buttons.
Definition BaseButton.h:15
virtual json::JSONBuilder getStructure() const override
std::function< void()> onClick
Definition BaseButton.h:21
const std::function< void()> & getOnClear() const
BaseCheckBox(const std::wstring &checkBoxName, const std::wstring &checkBoxText, const utility::ComponentSettings &settings, BaseComposite *parent, const std::function< void()> &onCheck, const std::function< void()> &onClear, const std::function< void()> &onClick=nullptr)
const std::function< void()> & getOnCheck() const
virtual json::JSONBuilder getStructure() const override
void setOnClear(const std::function< void()> &onClear)
void setOnCheck(const std::function< void()> &onCheck)
std::function< void()> onClear
std::function< void()> onCheck
const std::wstring windowName
Base class for all windows that has children windows.
const std::unordered_map< std::string, std::string > & getModulesPaths() const
Get all loaded modules paths.
static GUIFramework & get()
Singleton instance access.
string to_string(wstring_view stringToConvert, uint32_t codepage)
Definition Utility.cpp:41
void(*)() onClickSignature
Default on click signature.