GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
SeparateWindowDeserializer.cpp
Go to the documentation of this file.
2
6#include "GUIFramework.h"
8
11
13
15
16using namespace std;
17
18namespace gui_framework
19{
20 namespace deserializers
21 {
22 BaseComponent* SeparateWindowDeserializer::deserialize(const string& componentName, const json::utility::jsonObject& description, BaseComposite* parent) const
23 {
24 using json::utility::jsonObject;
25
27 parsers::MenuParser menuParser;
28 bool hasMenus = false;
29
30 parser.parse(description);
31
32 if (description.contains("menuStructure", json::utility::variantTypeEnum::jJSONObject))
33 {
34 menuParser.parse(const_cast<jsonObject&>(description.getObject("menuStructure")));
35
36 hasMenus = true;
37 }
38
39 SeparateWindow* result = nullptr;
40 uint32_t codepage = interfaces::ISerializable::getCodepage();
43
44 result = static_cast<SeparateWindow*>(creator->create(utility::to_wstring(componentName, codepage), parser.settings, creationData.getData(), nullptr));
45
46 result->setBackgroundColor(parser.backgroundColor[0], parser.backgroundColor[1], parser.backgroundColor[2]);
47
48 result->setTextColor(parser.textColor[0], parser.textColor[1], parser.textColor[2]);
49
50 result->setExitMode(parser.mode);
51
52 if (parser.pathToLargeIcon.size())
53 {
54 result->setLargeIcon(parser.pathToLargeIcon);
55 }
56
57 if (parser.pathToSmallIcon.size())
58 {
59 result->setSmallIcon(parser.pathToSmallIcon);
60 }
61
62 if (parser.onDestroyFunctionName.size())
63 {
65 }
66
67 if (parser.onCloseFunctionName.size())
68 {
70 }
71
72 if (hasMenus)
73 {
74 auto& mainMenu = result->createMainMenu(menuParser.mainMenuName);
75
76 for (const auto& i : menuParser.mainMenuItems)
77 {
78 const jsonObject& item = get<jsonObject>(i.data.front().second);
79
80 wstring text = utility::to_wstring(item.getString("itemText"), codepage);
81 const string& type = item.getString("itemType");
82
84 {
85 mainMenu->addMenuItem(make_unique<MenuItem>(text, item.getString("functionName"), item.getString("moduleName")));
86 }
88 {
89 uint64_t popupId = item.getUnsignedInt("popupId");
90 Menu* popupMenu = nullptr;
91
92 for (const auto& j : menuParser.popupItems)
93 {
94 const jsonObject& popupItem = get<jsonObject>(j.data.front().second);
95
96 if (popupItem.getUnsignedInt("menuId") == popupId)
97 {
98 popupMenu = &result->addPopupMenu(utility::to_wstring(popupItem.getString("menuName"), codepage));
99 }
100 }
101
102 if (popupMenu)
103 {
104 mainMenu->addMenuItem(DropDownMenuItemDeserializer(result).deserializeDropDownMenuItem(text, popupId, menuParser.popupItems, *popupMenu));
105 }
106 }
107 else
108 {
109 throw exceptions::deserialization::WrongMenuTypeException(type, __FILE__, __FUNCTION__, __LINE__);
110 }
111 }
112 }
113
114 if (description.contains("hotkeys", json::utility::variantTypeEnum::jJSONArray))
115 {
117 }
118
119 if (description.contains("children", json::utility::variantTypeEnum::jJSONArray))
120 {
121 const auto& children = description.getArray("children");
122
123 for (const auto& i : children)
124 {
125 const auto& [componentName, data] = get<jsonObject>(i.data.front().second).data.front();
126 const auto& description = get<jsonObject>(data);
127
128 const smartPointerType<interfaces::IDeserializer>& deserializer = GUIFramework::get().getDeserializers().at(description.getUnsignedInt("hash"));
129
130 deserializer->deserialize(componentName, description, result);
131 }
132 }
133
134 return result;
135 }
136 }
137}
std::unique_ptr< T > smartPointerType
Compatible smart pointer type.
Base class for all windows, controls, etc.
virtual void setTextColor(uint8_t red, uint8_t green, uint8_t blue)
Base class for all windows that has children windows.
void setOnDestroy(const std::function< void()> &onDestroy)
void setExitMode(exitMode mode)
virtual std::unique_ptr< Menu > & createMainMenu(const std::wstring &menuName)
It needs to be called once.
virtual Menu & addPopupMenu(const std::wstring &menuName)
Don't call move operator with return value.
void setSmallIcon(const std::filesystem::path &pathToSmallIcon)
Set small icon(16x16) for specific window.
void setLargeIcon(const std::filesystem::path &pathToLargeIcon)
Set large icon(32x32) for specific window.
virtual void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) final override
void deserializeHotkeys(const json::utility::jsonObject &description)
Deserialize hotkeys.
const std::unordered_map< size_t, smartPointerType< utility::BaseComponentCreator > > & getCreators() const
Get all current registered creators.
const std::unordered_map< size_t, smartPointerType< interfaces::IDeserializer > > & getDeserializers() const
Get all current registered deserializers.
static GUIFramework & get()
Singleton instance access.
Menu class.
Definition Menu.h:9
Standard separate window.
BaseComponent * deserialize(const std::string &componentName, const json::utility::jsonObject &description, BaseComposite *parent=nullptr) const override
SeparateWindow has no parent, you must manage the pointer.
Throws by SeparateWindowDeserializer during deserialize if JSON has wrong itemType value.
Base templated class for component creators.
wstring to_wstring(const string &stringToConvert, uint32_t codepage)
Definition Utility.cpp:82
std::vector< json::utility::jsonObject > mainMenuItems
Definition MenuParser.h:12
std::vector< json::utility::jsonObject > popupItems
Definition MenuParser.h:13
void parse(json::utility::jsonObject &description)
Parse SeparateWindow specific properties.
void parse(const json::utility::jsonObject &description) override