GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
DropDownMenuItemDeserializer.cpp
Go to the documentation of this file.
2
4#include "Utility/Utility.h"
6
8
9using namespace std;
10
11namespace gui_framework
12{
13 namespace deserializers
14 {
16 menuHolder(menuHolder)
17 {
18
19 }
20
21 unique_ptr<DropDownMenuItem> DropDownMenuItemDeserializer::deserializeDropDownMenuItem(const wstring& text, uint64_t popupId, const std::vector<json::utility::jsonObject>& popupItems, Menu& menu)
22 {
23 using json::utility::jsonObject;
24
25 uint32_t codepage = interfaces::ISerializable::getCodepage();
26
27 for (const auto& i : popupItems)
28 {
29 const jsonObject& item = get<jsonObject>(i.data.front().second);
30
31 uint64_t menuId = item.getUnsignedInt("menuId");
32
33 if (menuId != popupId)
34 {
35 continue;
36 }
37
38 wstring name = utility::to_wstring(item.getString("menuName"), codepage);
39 const vector<jsonObject>& dropDownItems = item.getArray("items");
40
41 for (const auto& j : dropDownItems)
42 {
43 const jsonObject& dropDownItem = get<jsonObject>(j.data.front().second);
44
45 wstring text = utility::to_wstring(dropDownItem.getString("itemText"), codepage);
46
47 const string& type = dropDownItem.getString("itemType");
48
50 {
51 menu.addMenuItem(make_unique<MenuItem>(text, dropDownItem.getString("functionName"), dropDownItem.getString("moduleName")));
52 }
54 {
55 Menu* popupMenu = nullptr;
56 uint64_t insidePopupId = dropDownItem.getUnsignedInt("popupId");
57
58 for (const auto& j : popupItems)
59 {
60 const jsonObject& popupItem = get<jsonObject>(j.data.front().second);
61
62 if (popupItem.getUnsignedInt("menuId") == insidePopupId)
63 {
64 popupMenu = &menuHolder->addPopupMenu(utility::to_wstring(popupItem.getString("menuName"), codepage));
65 }
66 }
67
68 if (popupMenu)
69 {
70 menu.addMenuItem(DropDownMenuItemDeserializer(menuHolder).deserializeDropDownMenuItem(text, insidePopupId, popupItems, *popupMenu));
71 }
72 }
73 else
74 {
75 throw exceptions::deserialization::WrongMenuTypeException(type, __FILE__, __FUNCTION__, __LINE__);
76 }
77 }
78 }
79
80 return make_unique<DropDownMenuItem>(text, menu.getHandle());
81 }
82 }
83}
virtual Menu & addPopupMenu(const std::wstring &menuName)
Don't call move operator with return value.
Base class for separate windows.
Menu class.
Definition Menu.h:9
HMENU getHandle() const
Definition Menu.cpp:102
Menu & addMenuItem(std::unique_ptr< interfaces::IMenuItem > &&item)
Also calls item's createMenuItem method.
Definition Menu.cpp:58
std::unique_ptr< DropDownMenuItem > deserializeDropDownMenuItem(const std::wstring &text, uint64_t popupId, const std::vector< json::utility::jsonObject > &popupItems, Menu &menu)
Throws by SeparateWindowDeserializer during deserialize if JSON has wrong itemType value.
wstring to_wstring(const string &stringToConvert, uint32_t codepage)
Definition Utility.cpp:82