GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
BaseButton.cpp
Go to the documentation of this file.
1#include "BaseButton.h"
2
3#include "GUIFramework.h"
4
8
9using namespace std;
10
11namespace gui_framework
12{
13 LRESULT BaseButton::windowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam, bool& isUsed)
14 {
15 if (message == WM_COMMAND && id == LOWORD(wparam))
16 {
17 isUsed = true;
18
19 if (onClick)
20 {
21 onClick();
22 }
23
24 return 0;
25 }
26
27 isUsed = false;
28
29 return -1;
30 }
31
32 void BaseButton::updateLocalization(wstring_view localizedText)
33 {
34 ITextOperations::setText(localizedText);
35 }
36
37 BaseButton::BaseButton(const wstring& buttonName, const wstring& buttonText, const utility::ComponentSettings& settings, const styles::ButtonStyles& styles, BaseComposite* parent, const function<void()>& onClick) :
39 (
40 standard_classes::button,
41 buttonName,
42 settings,
43 styles,
44 parent
45 ),
46 ITextOperations(handle, buttonText),
47 onClick(onClick)
48 {
49
50 }
51
52 BaseButton::BaseButton(const wstring& buttonName, const wstring& buttonText, const utility::ComponentSettings& settings, const styles::ButtonStyles& styles, BaseComposite* parent, const string& functionName, const string& moduleName) :
53 BaseComponent
54 (
55 wstring(standard_classes::button),
56 buttonName,
57 settings,
58 styles,
59 parent
60 ),
61 ITextOperations(handle)
62 {
63 ITextOperations::setText(buttonText);
64
65 this->setOnClick(functionName, moduleName);
66 }
67
68 void BaseButton::setOnClick(const function<void()>& onClick)
69 {
70 this->onClick = onClick;
71
72 functionName.clear();
73 moduleName.clear();
74 }
75
76 void BaseButton::setOnClick(const string& functionName, const string& moduleName)
77 {
78 GUIFramework& instance = GUIFramework::get();
79 const HMODULE& module = instance.getModules().at(moduleName);
80
81 onClickSignature tem = reinterpret_cast<onClickSignature>(GetProcAddress(module, functionName.data()));
82
83 if (!tem)
84 {
85 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
86 }
87
88 onClick = tem;
89
90 this->functionName = functionName;
91 this->moduleName = moduleName;
92 }
93
94 const function<void()>& BaseButton::getOnClick() const
95 {
96 return onClick;
97 }
98
99 const string& BaseButton::getFunctionName() const
100 {
101 return functionName;
102 }
103
104 const string& BaseButton::getModuleName() const
105 {
106 return moduleName;
107 }
108
109 void BaseButton::setTextColor(uint8_t red, uint8_t green, uint8_t blue)
110 {
111 __utility::throwNotImplementedException(__FUNCTION__, "BaseButton"sv);
112 }
113
114 json::JSONBuilder BaseButton::getStructure() const
115 {
116 using json::utility::jsonObject;
117
118 if (functionName.empty())
119 {
121 }
122
123 json::JSONBuilder builder = BaseComponent::getStructure();
124 jsonObject& current = get<jsonObject>(builder[utility::to_string(windowName, ISerializable::getCodepage())]);
125
126 current.data.push_back({ "functionName"s, functionName });
127
128 current.data.push_back({ "moduleName"s, moduleName });
129
130 current.data.push_back({ "pathToModule"s, GUIFramework::get().getModulesPaths().at(moduleName) });
131
132 return builder;
133 }
134
135 void BaseButton::setText(string_view localizationKey)
136 {
137 this->setLocalizationKey(localizationKey);
138
139 ITextOperations::setText(localizationKey);
140 }
141}
virtual void updateLocalization(std::wstring_view localizedText) override
const std::string & getModuleName() const
Get onClick function associated module name.
const std::function< void()> & getOnClick() const
void setOnClick(const std::function< void()> &onClick)
Can't serialize.
const std::string & getFunctionName() const
Get onClick function name from loaded module.
BaseButton(const std::wstring &buttonName, const std::wstring &buttonText, const utility::ComponentSettings &settings, const styles::ButtonStyles &styles, BaseComposite *parent, const std::function< void()> &onClick=nullptr)
virtual void setTextColor(uint8_t red, uint8_t green, uint8_t blue) final override
Not implemented.
virtual json::JSONBuilder getStructure() const override
virtual void setText(std::string_view localizationKey) final override
std::function< void()> onClick
Definition BaseButton.h:21
virtual LRESULT windowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam, bool &isUsed) override
Base class for all windows, controls, etc.
virtual json::JSONBuilder getStructure() const override
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.
virtual void setLocalizationKey(std::string_view localizationKey) final
Base class for button styles.
void throwNotImplementedException(string_view methodName, string_view className)
Definition Utility.cpp:186
string to_string(wstring_view stringToConvert, uint32_t codepage)
Definition Utility.cpp:41
void(*)() onClickSignature
Default on click signature.