soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SUiDef.h
1#ifndef __SUIDEF__H__
2#define __SUIDEF__H__
3
4#include <core/SSingleton2.h>
5#include <interface/obj-ref-i.h>
7
8#include <res.mgr/SFontPool.h>
9#include <res.mgr/SSkinPool.h>
10#include <res.mgr/SStylePool.h>
12#include <res.mgr/SObjDefAttr.h>
13#include <res.mgr/SNamedValue.h>
14
15SNSBEGIN
16
17enum
18{
19 UDI_GLOBAL = 1 << 0,
20 UDI_SKIN = 1 << 1,
21 UDI_STYLE = 1 << 2,
22 UDI_TEMPLATE = 1 << 3,
23 UDI_COLOR = 1 << 4,
24 UDI_STRING = 1 << 5,
25 UDI_DIMENSION = 1 << 6,
26 UDI_FONT = 1 << 7,
27 UDI_GRADIENT = 1 << 8,
28};
29
30/**
31 * @interface IUiDefInfo
32 * @brief Interface for UI definition information.
33 */
35{
36 /**
37 * @brief Initializes the UI definition from a resource provider.
38 * @param pResProvider Pointer to the resource provider.
39 * @param pszUidef UI definition resource ID.
40 * @return Number of resources initialized.
41 */
42 virtual UINT Init(IResProvider *pResProvider, LPCTSTR pszUidef) = 0;
43
44 /**
45 * @brief Initializes the UI definition from an XML node.
46 * @param pNode XML node containing the UI definition.
47 * @param bGlobalDomain TRUE if the domain is global, FALSE otherwise.
48 * @param pResProvider Pointer to the resource provider (optional).
49 * @return Number of resources initialized.
50 */
51 virtual UINT Init2(IXmlNode *pNode, BOOL bGlobalDomain, IResProvider *pResProvider = NULL) = 0;
52
53 /**
54 * @brief Retrieves the skin pool.
55 * @return Pointer to the skin pool.
56 */
57 virtual SSkinPool *GetSkinPool() = 0;
58
59 /**
60 * @brief Retrieves the style pool.
61 * @return Pointer to the style pool.
62 */
63 virtual SStylePool *GetStylePool() = 0;
64
65 /**
66 * @brief Retrieves the template pool.
67 * @return Pointer to the template pool.
68 */
70
71 /**
72 * @brief Retrieves the gradient pool.
73 * @return Pointer to the gradient pool.
74 */
76
77 /**
78 * @brief Retrieves the named color manager.
79 * @return Reference to the named color manager.
80 */
81 virtual SNamedColor &GetNamedColor() = 0;
82
83 /**
84 * @brief Retrieves the named string manager.
85 * @return Reference to the named string manager.
86 */
88
89 /**
90 * @brief Retrieves the named dimension manager.
91 * @return Reference to the named dimension manager.
92 */
94
95 /**
96 * @brief Retrieves the named font manager.
97 * @return Reference to the named font manager.
98 */
99 virtual SNamedFont &GetNamedFont() = 0;
100
101 /**
102 * @brief Retrieves the default font information.
103 * @return Default font information as a string.
104 */
106
107 /**
108 * @brief Retrieves the caret information.
109 * @return XML node containing the caret information.
110 */
111 virtual SXmlNode GetCaretInfo() = 0;
112
113 /**
114 * @brief Retrieves the object default attribute manager.
115 * @return Pointer to the object default attribute manager.
116 */
118};
119
120#define GETUIDEF SNS::SUiDef::getSingletonPtr()
121
122#define GETSTYLE(p) GETUIDEF->GetStyle(p)
123#define GETSKIN(p1, scale) GETUIDEF->GetSkin(p1, scale)
124#define GETBUILTINSKIN(p1) GETUIDEF->GetBuiltinSkin(p1, 100)
125#define GETBUILTINSKIN2(p1, scale) GETUIDEF->GetBuiltinSkin(p1, scale)
126#define GETCOLOR(x) GETUIDEF->GetColor(x)
127#define GETSTRING(x) GETUIDEF->GetString(x)
128#define GETLAYOUTSIZE(x) GETUIDEF->GetLayoutSize(x)
129
130/**
131 * @class SUiDef
132 * @brief Manages UI definitions, including skins, styles, templates, gradients, and named values.
133 *
134 * @details This class provides functionality to manage and retrieve various UI resources such as skins, styles, templates,
135 * gradients, and named values. It also handles the initialization and management of default UI definitions.
136 */
137class SOUI_EXP SUiDef
138 : public SSingleton2<SUiDef>
139 , public SFontPool {
140 SINGLETON2_TYPE(SINGLETON_UIDEF)
141
142 public:
143 /**
144 * @brief Constructor.
145 * @param fac Pointer to the render factory.
146 */
148
149 /**
150 * @brief Destructor.
151 */
152 ~SUiDef(void);
153
154 public:
155 /**
156 * @brief Creates a new UI definition information object.
157 * @return Pointer to the created UI definition information object.
158 */
159 static IUiDefInfo *CreateUiDefInfo();
160
161 /**
162 * @brief Creates a new skin pool.
163 * @param bAutoScale TRUE if automatic scaling is enabled, FALSE otherwise.
164 * @return Pointer to the created skin pool.
165 */
166 static ISkinPool *CreateSkinPool(BOOL bAutoScale = TRUE);
167
168 /**
169 * @brief Initializes the default UI definition.
170 * @param pResProvider Pointer to the resource provider.
171 * @param pszUiDef UI definition resource ID.
172 * @return TRUE if initialization is successful, FALSE otherwise.
173 */
174 BOOL InitDefUiDef(IResProvider *pResProvider, LPCTSTR pszUiDef);
175
176 /**
177 * @brief Retrieves the default UI definition.
178 * @return Pointer to the default UI definition information object.
179 */
181
182 /**
183 * @brief Sets the default UI definition.
184 * @param pUiDefInfo Pointer to the UI definition information object.
185 * @param bUpdateDefFont TRUE if the default font should be updated, FALSE otherwise.
186 */
187 void SetUiDef(IUiDefInfo *pUiDefInfo, bool bUpdateDefFont);
188
189 public:
190 /**
191 * @brief Pushes a new UI definition information object onto the stack.
192 * @param pUiDefInfo Pointer to the UI definition information object.
193 * @param bPreivate TRUE if the UI definition is private, FALSE otherwise.
194 */
195 void PushUiDefInfo(IUiDefInfo *pUiDefInfo, BOOL bPreivate = FALSE);
196
197 /**
198 * @brief Pops a UI definition information object from the stack.
199 * @param pUiDefInfo Pointer to the UI definition information object to pop. If NULL, pops the last object.
200 * @param bPreivate TRUE if the UI definition is private, FALSE otherwise.
201 * @return TRUE if the UI definition is successfully popped, FALSE otherwise.
202 */
203 BOOL PopUiDefInfo(IUiDefInfo *pUiDefInfo, BOOL bPreivate = FALSE);
204
205 /**
206 * @brief Pushes a new skin pool onto the stack.
207 * @param pSkinPool Pointer to the skin pool.
208 */
209 void PushSkinPool(ISkinPool *pSkinPool);
210
211 /**
212 * @brief Pops a skin pool from the stack.
213 * @param pSkinPool Pointer to the skin pool to pop.
214 * @return TRUE if the skin pool is successfully popped, FALSE otherwise.
215 */
216 BOOL PopSkinPool(ISkinPool *pSkinPool);
217
218 public:
219 /**
220 * @brief Retrieves a skin object by name and scale.
221 * @param strSkinName Name of the skin.
222 * @param nScale Scale factor for the skin.
223 * @return Pointer to the skin object, or nullptr if not found.
224 */
225 ISkinObj *GetSkin(const SStringW &strSkinName, int nScale);
226
227 /**
228 * @brief Retrieves a built-in skin object by ID and scale.
229 * @param uID ID of the built-in skin.
230 * @param nScale Scale factor for the skin.
231 * @return Pointer to the built-in skin object, or nullptr if not found.
232 */
233 ISkinObj *GetBuiltinSkin(SYS_SKIN uID, int nScale);
234
235 /**
236 * @brief Retrieves the built-in skin pool.
237 * @return Pointer to the built-in skin pool.
238 */
239 ISkinPool *GetBuiltinSkinPool();
240
241 /**
242 * @brief Retrieves a style XML node by name.
243 * @param strName Name of the style.
244 * @return XML node containing the style, or an invalid node if not found.
245 */
246 SXmlNode GetStyle(const SStringW &strName);
247
248 /**
249 * @brief Retrieves a template string by name.
250 * @param strName Name of the template.
251 * @return Template string, or an empty string if not found.
252 */
253 SStringW GetTemplateString(const SStringW &strName);
254
255 /**
256 * @brief Retrieves a gradient object by name.
257 * @param strName Name of the gradient.
258 * @return Pointer to the gradient object, or nullptr if not found.
259 */
260 IGradient *GetGradient(const SStringW &strName);
261
262 /**
263 * @brief Retrieves a color value from a string.
264 * @param strColor Color string (e.g., @color/red, rgba(r,g,b,a), rgb(r,g,b), #ff0000).
265 * @return Color value as COLORREF.
266 */
267 COLORREF GetColor(const SStringW &strColor);
268
269 /**
270 * @brief Retrieves a color value by index from the default resource package.
271 * @param idx Index of the color.
272 * @return Color value as COLORREF.
273 */
274 COLORREF GetColor(int idx);
275
276 /**
277 * @brief Retrieves a string value from a string name.
278 * @param strString String name (e.g., @string/title).
279 * @return String value, or an empty string if not found.
280 */
281 SStringW GetString(const SStringW &strString);
282
283 /**
284 * @brief Retrieves a string value by index from the default resource package.
285 * @param idx Index of the string.
286 * @return String value, or an empty string if not found.
287 */
288 SStringW GetString(int idx);
289
290 /**
291 * @brief Retrieves a layout size from a string name.
292 * @param strSize String name (e.g., @dim/dimname).
293 * @return Layout size as SLayoutSize.
294 */
295 SLayoutSize GetLayoutSize(const SStringW &strSize);
296
297 /**
298 * @brief Retrieves a layout size by index from the default resource package.
299 * @param idx Index of the layout size.
300 * @return Layout size as SLayoutSize.
301 */
302 SLayoutSize GetLayoutSize(int idx);
303
304 /**
305 * @brief Retrieves a font description from a string name.
306 * @param strFont String name (e.g., @font/fontname).
307 * @return Font description as a string.
308 */
309 SStringW GetFontDesc(const SStringW &strFont);
310
311 /**
312 * @brief Retrieves a font description by index from the default resource package.
313 * @param idx Index of the font description.
314 * @return Font description as a string.
315 */
316 SStringW GetFontDesc(int idx);
317
318 public:
319 /**
320 * @brief Retrieves a font object by description and scale.
321 * @param strFont Font description string.
322 * @param scale Scale factor for the font.
323 * @return Pointer to the font object, or nullptr if not found.
324 *
325 * @details Description string format example: face:宋体,bold:0,italic:1,underline:1,strike:1,adding:10
326 */
327 IFontPtr GetFont(const SStringW &strFont, int scale);
328
329 /**
330 * @brief Sets the default font information.
331 * @param strFontInfo Default font description.
332 */
333 void SetDefFontInfo(const SStringW &strFontInfo);
334
335 /**
336 * @brief Retrieves the default font information.
337 * @return Font information as FontInfo.
338 */
339 FontInfo GetDefFontInfo() const;
340
341 protected:
342 SAutoRefPtr<IUiDefInfo> m_defUiDefInfo; // Default UI definition information
343 SList<IUiDefInfo *> m_lstUiDefInfo; // List of UI definition information objects
344 SList<ISkinPool *> m_lstSkinPools; // List of skin pools
345 SAutoRefPtr<ISkinPool> m_bulitinSkinPool; // Built-in skin pool
346 mutable SCriticalSection m_cs; // Critical section for thread safety
347};
348
349SNSEND
350
351#endif // __SUIDEF__H__
SOUI Font Management Module.
Gradient Pool Management.
Pseudo-Singleton Template.
Skin Object Pool Management.
Style Pool Management.
Smart pointer class for managing COM-style reference-counted objects.
Wrapper class for a critical section.
SFontPool(IRenderFactory *fac)
Constructor.
Definition SFontPool.cpp:41
static IFontPtr GetFont(const SStringW &strFont, int scale)
Get IFontPtr corresponding to the specified description string.
static void SetDefFontInfo(const SStringW &strFontInfo)
Set default font.
static FontInfo GetDefFontInfo()
Get default font information.
Manages the mapping of gradient names to IGradient objects.
布局大小类
Definition SLayoutSize.h:10
Manages named colors.
Manages named dimensions.
Manages named fonts.
Manages named strings.
Class for managing default attributes of objects.
Definition SObjDefAttr.h:17
Manages the mapping of skin names to ISkinObj objects.
Definition SSkinPool.h:135
A class representing an ASCII string.
Definition sstringw.h:96
Manages the mapping of style names to XML nodes.
Definition SStylePool.h:28
Manages the mapping of template names to template strings.
Definition SStylePool.h:56
SUiDef(IRenderFactory *fac)
Constructor.
Definition SUiDef.cpp:331
void PushUiDefInfo(IUiDefInfo *pUiDefInfo, BOOL bPreivate=FALSE)
Pushes a new UI definition information object onto the stack.
Definition SUiDef.cpp:408
IUiDefInfo * GetUiDef()
Retrieves the default UI definition.
Definition SUiDef.cpp:383
SStringW GetTemplateString(const SStringW &strName)
Retrieves a template string by name.
Definition SUiDef.cpp:533
IGradient * GetGradient(const SStringW &strName)
Retrieves a gradient object by name.
Definition SUiDef.cpp:550
ISkinObj * GetSkin(const SStringW &strSkinName, int nScale)
Retrieves a skin object by name and scale.
Definition SUiDef.cpp:464
static IUiDefInfo * CreateUiDefInfo()
Creates a new UI definition information object.
Definition SUiDef.cpp:649
void SetUiDef(IUiDefInfo *pUiDefInfo, bool bUpdateDefFont)
Sets the default UI definition.
Definition SUiDef.cpp:389
SXmlNode GetStyle(const SStringW &strName)
Retrieves a style XML node by name.
Definition SUiDef.cpp:516
SLayoutSize GetLayoutSize(const SStringW &strSize)
Retrieves a layout size from a string name.
Definition SUiDef.cpp:608
BOOL InitDefUiDef(IResProvider *pResProvider, LPCTSTR pszUiDef)
Initializes the default UI definition.
Definition SUiDef.cpp:369
SStringW GetFontDesc(const SStringW &strFont)
Retrieves a font description from a string name.
Definition SUiDef.cpp:628
SStringW GetString(const SStringW &strString)
Retrieves a string value from a string name.
Definition SUiDef.cpp:587
ISkinObj * GetBuiltinSkin(SYS_SKIN uID, int nScale)
Retrieves a built-in skin object by ID and scale.
Definition SUiDef.cpp:504
COLORREF GetColor(const SStringW &strColor)
Retrieves a color value from a string.
Definition SUiDef.cpp:567
BOOL PopUiDefInfo(IUiDefInfo *pUiDefInfo, BOOL bPreivate=FALSE)
Pops a UI definition information object from the stack.
Definition SUiDef.cpp:417
void PushSkinPool(ISkinPool *pSkinPool)
Pushes a new skin pool onto the stack.
Definition SUiDef.cpp:441
BOOL PopSkinPool(ISkinPool *pSkinPool)
Pops a skin pool from the stack.
Definition SUiDef.cpp:450
static ISkinPool * CreateSkinPool(BOOL bAutoScale=TRUE)
Creates a new skin pool.
Definition SUiDef.cpp:654
ISkinPool * GetBuiltinSkinPool()
Retrieves the built-in skin pool.
Definition SUiDef.cpp:510
Class representing an XML node.
Definition SXml.h:352
Font information structure.
Definition SFontInfo.h:51
Interface for reference counting.
Definition obj-ref-i.h:19
RenderFactory object.
Definition SRender-i.h:2018
ResProvider对象
Interface for Skin Objects.
Definition SSkinobj-i.h:29
Interface for UI definition information.
Definition SUiDef.h:35
virtual SSkinPool * GetSkinPool()=0
Retrieves the skin pool.
virtual SNamedString & GetNamedString()=0
Retrieves the named string manager.
virtual SNamedDimension & GetNamedDimension()=0
Retrieves the named dimension manager.
virtual UINT Init2(IXmlNode *pNode, BOOL bGlobalDomain, IResProvider *pResProvider=NULL)=0
Initializes the UI definition from an XML node.
virtual UINT Init(IResProvider *pResProvider, LPCTSTR pszUidef)=0
Initializes the UI definition from a resource provider.
virtual SGradientPool * GetGradientPool()=0
Retrieves the gradient pool.
virtual STemplatePool * GetTemplatePool()=0
Retrieves the template pool.
virtual SXmlNode GetCaretInfo()=0
Retrieves the caret information.
virtual SStylePool * GetStylePool()=0
Retrieves the style pool.
virtual SNamedColor & GetNamedColor()=0
Retrieves the named color manager.
virtual SStringW GetDefFontInfo()=0
Retrieves the default font information.
virtual SObjDefAttr * GetObjDefAttr()=0
Retrieves the object default attribute manager.
virtual SNamedFont & GetNamedFont()=0
Retrieves the named font manager.
Interface for XML nodes.
Definition sxml-i.h:128