-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCUIElement.h
198 lines (154 loc) · 4.64 KB
/
CUIElement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/** $VER: CUIElement.h (2024.07.05) P. Stuer - Columns User Interface support **/
#pragma once
#include "framework.h"
#include "UIElement.h"
#include <ui_extension.h>
namespace uie
{
class CUIColorClient;
/// <summary>
/// Implements a Columns UI element.
/// </summary>
class CUIElement : public UIElement, public uie::window
{
public:
CUIElement();
CUIElement(const CUIElement &) = delete;
CUIElement & operator=(const CUIElement &) = delete;
CUIElement(CUIElement &&) = delete;
CUIElement & operator=(CUIElement &&) = delete;
virtual ~CUIElement();
#pragma region uie::window interface
/// <summary>
/// Gets the category of the extension.
/// </summary>
void get_category(pfc::string_base & out) const final
{
out = "Panels";
}
/// <summary>
/// Gets the type of the extension.
/// </summary>
uint32_t get_type() const final
{
return uie::type_panel;
}
HWND create_or_transfer_window(HWND parent, const window_host_ptr & newHost, const ui_helpers::window_position_t & position);
virtual void destroy_window();
/// <summary>
/// Returns true if the extension is available.
/// </summary>
virtual bool is_available(const window_host_ptr & p) const
{
return true;
}
/// <summary>
/// Gets the window handle of the extension.
/// </summary>
virtual HWND get_wnd() const
{
return *this;
}
#pragma endregion
#pragma region extension_base interface
/// <summary>
/// Gets the unique ID of extension.
/// </summary>
const GUID & get_extension_guid() const
{
return GetGUID();
}
/// <summary>
/// Gets a user-readable name of the extension.
/// </summary>
void get_name(pfc::string_base & out) const
{
out = STR_COMPONENT_NAME;
}
/// <summary>
/// Sets an instance of the configuration data.
/// </summary>
void set_config(stream_reader * reader, size_t size, abort_callback & abortHandler) final
{
_Configuration.Read(reader, size, abortHandler);
}
/// <summary>
/// Gets an instance of the configuration data.
/// </summary>
void get_config(stream_writer * writer, abort_callback & abortHandler) const final
{
_Configuration.Write(writer, abortHandler);
}
#pragma endregion
virtual bool IsWebViewVisible() const noexcept
{
return true;
}
void GetColors() noexcept override;
private:
window_host_ptr _Host;
HWND _hParent;
};
static std::vector<CUIElement *> _Elements; // Very ugly but necessary because of the weird CUI notification mechanism.
/// <summary>
/// Receives notifications from CUI when the colors change.
/// </summary>
class CUIColorClient : public cui::colours::client
{
public:
CUIColorClient() { }
CUIColorClient(const CUIColorClient &) = delete;
CUIColorClient & operator=(const CUIColorClient &) = delete;
CUIColorClient(CUIColorClient &&) = delete;
CUIColorClient & operator=(CUIColorClient &&) = delete;
virtual ~CUIColorClient() { }
#pragma region cui::colours::client
virtual const GUID & get_client_guid() const
{
static const GUID guid = GUID_UI_ELEMENT;
return guid;
}
virtual void get_name(pfc::string_base & out) const
{
out = STR_COMPONENT_NAME;
}
/// <summary>
/// Return a combination of bool_flag_t to indicate which boolean flags are supported.
/// </summary>
virtual uint32_t get_supported_bools() const override
{
return cui::colours::bool_dark_mode_enabled;
}
/// <summary>
/// Indicates whether the Theme API is supported.
/// </summary>
virtual bool get_themes_supported() const override
{
return false;
}
virtual void on_colour_changed(uint32_t changed_items_mask) const override;
/// <summary>
/// Called whenever a supported boolean flag changes. Support for a flag is determined using the get_supported_bools() method.
/// </summary>
virtual void on_bool_changed(uint32_t changed_items_mask) const override;
#pragma endregion
/// <summary>
/// Registers a CUIElement with this client.
/// </summary>
static void Register(CUIElement * element)
{
if (element == nullptr)
return;
_Elements.push_back(element);
}
/// <summary>
/// Unregisters a CUIElement from this client.
/// </summary>
static void Unregister(CUIElement * element)
{
auto Element = std::find(_Elements.begin(), _Elements.end(), element);
if (Element != _Elements.end())
_Elements.erase(Element);
}
};
}