GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
MainWindowDeserializer.h
Go to the documentation of this file.
1#pragma once
2
6#include "GUIFramework.h"
7
10
12
14
15namespace gui_framework
16{
17 namespace deserializers
18 {
21 {
22 public:
24
29 template<typename MainWindowT> requires (std::is_base_of_v<BaseMainWindow, MainWindowT>)
30 void deserialize(const std::string& componentName, const json::utility::jsonObject& description, std::unique_ptr<MainWindowT>& mainWindow) const;
31
33 };
34
35 template<typename MainWindowT> requires (std::is_base_of_v<BaseMainWindow, MainWindowT>)
36 void MainWindowDeserializer::deserialize(const std::string& componentName, const json::utility::jsonObject& description, std::unique_ptr<MainWindowT>& mainWindow) const
37 {
38 using json::utility::jsonObject;
39
41 parsers::MenuParser menuParser;
42 bool hasMenus = false;
43 uint32_t codepage = interfaces::ISerializable::getCodepage();
44
45 parser.parse(description);
46
47 if (description.contains("menuStructure", json::utility::variantTypeEnum::jJSONObject))
48 {
49 menuParser.parse(const_cast<jsonObject&>(description.getObject("menuStructure")));
50
51 hasMenus = true;
52 }
53
54 mainWindow->setBackgroundColor(parser.backgroundColor[0], parser.backgroundColor[1], parser.backgroundColor[2]);
55
56 mainWindow->setTextColor(parser.textColor[0], parser.textColor[1], parser.textColor[2]);
57
58 if (parser.pathToLargeIcon.size())
59 {
60 mainWindow->setLargeIcon(parser.pathToLargeIcon);
61 }
62
63 if (parser.pathToSmallIcon.size())
64 {
65 mainWindow->setSmallIcon(parser.pathToSmallIcon);
66 }
67
68 if (parser.onDestroyFunctionName.size())
69 {
70 mainWindow->setOnDestroy(parser.onDestroyFunctionName, parser.onDestroyFunctionModuleName);
71 }
72
73 if (parser.onCloseFunctionName.size())
74 {
75 mainWindow->setOnDestroy(parser.onCloseFunctionName, parser.onCloseFunctionModuleName);
76 }
77
78 if (parser.trayIconResource)
79 {
80 mainWindow->initTray(parser.trayIconResource, parser.alwaysShowTrayIcon);
81 }
82
83 for (const auto& [text, function] : parser.items)
84 {
85 mainWindow->addTrayMenuItem(text, function.functionName, function.moduleName);
86 }
87
88 if (hasMenus)
89 {
90 auto& mainMenu = mainWindow->createMainMenu(menuParser.mainMenuName);
91
92 for (const auto& i : menuParser.mainMenuItems)
93 {
94 const jsonObject& item = get<jsonObject>(i.data.front().second);
95
96 std::wstring text = utility::to_wstring(item.getString("itemText"), codepage);
97 const std::string& type = item.getString("itemType");
98
100 {
101 mainMenu->addMenuItem(std::make_unique<MenuItem>(text, item.getString("functionName"), item.getString("moduleName")));
102 }
104 {
105 uint64_t popupId = item.getUnsignedInt("popupId");
106 Menu* popupMenu = nullptr;
107
108 for (const auto& j : menuParser.popupItems)
109 {
110 const jsonObject& popupItem = get<jsonObject>(j.data.front().second);
111
112 if (popupItem.getUnsignedInt("menuId") == popupId)
113 {
114 popupMenu = &mainWindow->addPopupMenu(utility::to_wstring(popupItem.getString("menuName"), codepage));
115 }
116 }
117
118 if (popupMenu)
119 {
120 mainMenu->addMenuItem(DropDownMenuItemDeserializer(mainWindow).deserializeDropDownMenuItem(text, popupId, menuParser.popupItems, *popupMenu));
121 }
122 }
123 else
124 {
125 throw exceptions::deserialization::WrongMenuTypeException(type, __FILE__, __FUNCTION__, __LINE__);
126 }
127 }
128 }
129
130 if (description.contains("hotkeys", json::utility::variantTypeEnum::jJSONArray))
131 {
133 }
134
135 if (description.contains("children", json::utility::variantTypeEnum::jJSONArray))
136 {
137 const auto& children = description.getArray("children");
138
139 for (const auto& i : children)
140 {
141 const auto& [componentName, data] = get<jsonObject>(i.data.front().second).data.front();
142 const auto& description = get<jsonObject>(data);
143
144 const smartPointerType<interfaces::IDeserializer>& deserializer = GUIFramework::get().getDeserializers().at(description.getUnsignedInt("hash"));
145
146 deserializer->deserialize(componentName, description, mainWindow);
147 }
148 }
149 }
150 }
151}
#define GUI_FRAMEWORK_API
std::unique_ptr< T > smartPointerType
Compatible smart pointer type.
void deserializeHotkeys(const json::utility::jsonObject &description)
Deserialize hotkeys.
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
void deserialize(const std::string &componentName, const json::utility::jsonObject &description, std::unique_ptr< MainWindowT > &mainWindow) const
MainWindow has no parent, you must manage the pointer.
Throws by SeparateWindowDeserializer during deserialize if JSON has wrong itemType value.
wstring to_wstring(const string &stringToConvert, uint32_t codepage)
Definition Utility.cpp:82
Parse MainWindowParser specific properties.
void parse(const json::utility::jsonObject &description) override
std::vector< std::pair< std::wstring, BaseMainWindow::Function > > items
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)