soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SAttrCracker.h
Go to the documentation of this file.
1/**
2 * Copyright (C) 2014-2050
3 * All rights reserved.
4 *
5 * @file SAttrCracker.h
6 * @brief
7 * @version v1.0
8 * @author SOUI group
9 * @date 2014/08/15
10 *
11 * Describe 定义SOUI的XML属性解析宏
12 */
13
14#ifndef _SATTRCRACK_H
15#define _SATTRCRACK_H
16
17// Attribute Declaration
18#define SOUI_ATTRS_BEGIN() \
19 public: \
20 virtual HRESULT SetAttribute(const SNS::SStringW &strAttribName, const SNS::SStringW &strValue, BOOL bLoading = FALSE) \
21 { \
22 HRESULT hRet = E_FAIL;
23
24//从SObject派生的类是属性结尾
25#define SOUI_ATTRS_END() \
26 if (FAILED(hRet)) \
27 return __baseCls::SetAttribute(strAttribName, strValue, bLoading); \
28 return AfterAttribute(strAttribName.c_str(), strValue.c_str(), bLoading, hRet); \
29 }
30
31//不交给SObject处理的属性表结尾
32#define SOUI_ATTRS_BREAK() \
33 hRet = E_NOTIMPL; \
34 return hRet; \
35 }
36
37#define ATTR_CHAIN(varname, flag) \
38 if (FAILED(hRet) && SUCCEEDED(hRet = varname.SetAttribute(strAttribName, strValue, bLoading))) \
39 { \
40 hRet |= flag; \
41 } \
42 else
43
44#define ATTR_CHAIN_PTR(varname, flag) \
45 if (FAILED(hRet) && varname != NULL && SUCCEEDED(hRet = varname->ISetAttribute(&strAttribName, &strValue, bLoading))) \
46 { \
47 hRet |= flag; \
48 } \
49 else
50
51#define ATTR_CHAIN_CLASS(cls) \
52 if (FAILED(hRet)) \
53 hRet = cls::SetAttribute(strAttribName, strValue, bLoading);
54
55#define ATTR_CUSTOM(attribname, func) \
56 if (0 == strAttribName.CompareNoCase(attribname)) \
57 { \
58 hRet = func(strValue, bLoading); \
59 } \
60 else
61
62#define STRINGASBOOL(strValue) (strValue).CompareNoCase(L"0") != 0 && (strValue).CompareNoCase(L"false") != 0
63
64#define ATTR_BOOL(attribname, varname, allredraw) \
65 if (0 == strAttribName.CompareNoCase(attribname)) \
66 { \
67 varname = STRINGASBOOL(strValue); \
68 hRet = allredraw ? S_OK : S_FALSE; \
69 } \
70 else
71
72// Int = %d StringA
73#define ATTR_INT(attribname, varname, allredraw) \
74 if (0 == strAttribName.CompareNoCase(attribname)) \
75 { \
76 int nRet = Str2IntW(strValue, TRUE); \
77 varname = nRet; \
78 hRet = allredraw ? S_OK : S_FALSE; \
79 } \
80 else
81
82#define ATTR_LAYOUTSIZE(attribname, varname, allredraw) \
83 if (0 == strAttribName.CompareNoCase(attribname)) \
84 { \
85 varname = GETLAYOUTSIZE(strValue); \
86 hRet = allredraw ? S_OK : S_FALSE; \
87 } \
88 else
89
90#define ATTR_LAYOUTSIZE2(attribname, varname, allredraw) \
91 if (0 == strAttribName.CompareNoCase(attribname)) \
92 { \
93 SStringWList values; \
94 if (SplitString(strValue, L',', values) != 2) \
95 return E_INVALIDARG; \
96 varname[0] = GETLAYOUTSIZE(values[0]); \
97 varname[1] = GETLAYOUTSIZE(values[1]); \
98 hRet = allredraw ? S_OK : S_FALSE; \
99 } \
100 else
101
102#define ATTR_LAYOUTSIZE4(attribname, varname, allredraw) \
103 if (0 == strAttribName.CompareNoCase(attribname)) \
104 { \
105 SStringWList values; \
106 if (SplitString(strValue, L',', values) != 4) \
107 return E_INVALIDARG; \
108 varname[0] = GETLAYOUTSIZE(values[0]); \
109 varname[1] = GETLAYOUTSIZE(values[1]); \
110 varname[2] = GETLAYOUTSIZE(values[2]); \
111 varname[3] = GETLAYOUTSIZE(values[3]); \
112 hRet = allredraw ? S_OK : S_FALSE; \
113 } \
114 else
115
116#define ATTR_MARGIN(attribname, varname, allredraw) \
117 if (0 == strAttribName.CompareNoCase(attribname)) \
118 { \
119 SStringWList values; \
120 if (SplitString(strValue, L',', values) != 4) \
121 return E_INVALIDARG; \
122 varname.left = GETLAYOUTSIZE(values[0]).toPixelSize(100); \
123 varname.top = GETLAYOUTSIZE(values[1]).toPixelSize(100); \
124 varname.right = GETLAYOUTSIZE(values[2]).toPixelSize(100); \
125 varname.bottom = GETLAYOUTSIZE(values[3]).toPixelSize(100); \
126 hRet = allredraw ? S_OK : S_FALSE; \
127 } \
128 else
129
130// Rect = %d,%d,%d,%d StringA
131#define ATTR_RECT(attribname, varname, allredraw) \
132 if (0 == strAttribName.CompareNoCase(attribname)) \
133 { \
134 swscanf_s(strValue, L"%d,%d,%d,%d", &varname.left, &varname.top, &varname.right, &varname.bottom); \
135 hRet = allredraw ? S_OK : S_FALSE; \
136 } \
137 else
138
139// Size = %d,%d StringA
140#define ATTR_SIZE(attribname, varname, allredraw) \
141 if (0 == strAttribName.CompareNoCase(attribname)) \
142 { \
143 swscanf_s(strValue, L"%d,%d", &varname.cx, &varname.cy); \
144 hRet = allredraw ? S_OK : S_FALSE; \
145 } \
146 else
147
148// Point = %d,%d StringA
149#define ATTR_POINT(attribname, varname, allredraw) \
150 if (0 == strAttribName.CompareNoCase(attribname)) \
151 { \
152 swscanf_s(strValue, L"%d,%d", &varname.x, &varname.y); \
153 hRet = allredraw ? S_OK : S_FALSE; \
154 } \
155 else
156
157// Point = %d,%d StringA
158#define ATTR_SPOINT(attribname, varname, allredraw) \
159 if (0 == strAttribName.CompareNoCase(attribname)) \
160 { \
161 swscanf_s(strValue, L"%f,%f", &varname.fX, &varname.fY); \
162 hRet = allredraw ? S_OK : S_FALSE; \
163 } \
164 else
165
166// Float = %f StringA
167#define ATTR_FLOAT(attribname, varname, allredraw) \
168 if (0 == strAttribName.CompareNoCase(attribname)) \
169 { \
170 swscanf_s(strValue, L"%f", &varname); \
171 hRet = allredraw ? S_OK : S_FALSE; \
172 } \
173 else
174
175// UInt = %u StringA
176#define ATTR_UINT(attribname, varname, allredraw) \
177 if (0 == strAttribName.CompareNoCase(attribname)) \
178 { \
179 int nRet = Str2IntW(strValue, TRUE); \
180 varname = (UINT)nRet; \
181 hRet = allredraw ? S_OK : S_FALSE; \
182 } \
183 else
184
185// DWORD = %u StringA
186#define ATTR_DWORD(attribname, varname, allredraw) \
187 if (0 == strAttribName.CompareNoCase(attribname)) \
188 { \
189 int nRet = Str2IntW(strValue, TRUE); \
190 varname = (DWORD)nRet; \
191 hRet = allredraw ? S_OK : S_FALSE; \
192 } \
193 else
194
195// WORD = %u StringA
196#define ATTR_WORD(attribname, varname, allredraw) \
197 if (0 == strAttribName.CompareNoCase(attribname)) \
198 { \
199 int nRet = Str2IntW(strValue, TRUE); \
200 varname = (WORD)nRet; \
201 hRet = allredraw ? S_OK : S_FALSE; \
202 } \
203 else
204
205// bool = 0 or 1 StringA
206#define ATTR_BIT(attribname, varname, maskbit, allredraw) \
207 if (0 == strAttribName.CompareNoCase(attribname)) \
208 { \
209 bool bSet = STRINGASBOOL(strValue); \
210 if (bSet) \
211 varname |= maskbit; \
212 else \
213 varname &= ~(maskbit); \
214 hRet = allredraw ? S_OK : S_FALSE; \
215 } \
216 else
217
218// StringA = StringA
219#define ATTR_STRINGA(attribname, varname, allredraw) \
220 if (0 == strAttribName.CompareNoCase(attribname)) \
221 { \
222 SNS::SStringW strTmp = GETSTRING(strValue); \
223 varname = S_CW2A(strTmp); \
224 hRet = allredraw ? S_OK : S_FALSE; \
225 } \
226 else
227
228// StringW = StringA
229#define ATTR_STRINGW(attribname, varname, allredraw) \
230 if (0 == strAttribName.CompareNoCase(attribname)) \
231 { \
232 varname = GETSTRING(strValue); \
233 hRet = allredraw ? S_OK : S_FALSE; \
234 } \
235 else
236
237// StringT = StringA
238#define ATTR_STRINGT(attribname, varname, allredraw) \
239 if (0 == strAttribName.CompareNoCase(attribname)) \
240 { \
241 varname = S_CW2T(GETSTRING(strValue)); \
242 hRet = allredraw ? S_OK : S_FALSE; \
243 } \
244 else
245
246// StringA = StringA
247#define ATTR_I18NSTRA(attribname, varname, allredraw) \
248 if (0 == strAttribName.CompareNoCase(attribname)) \
249 { \
250 SNS::SStringW strTmp = tr(GETSTRING(strValue)); \
251 varname = S_CW2A(strTmp); \
252 hRet = allredraw ? S_OK : S_FALSE; \
253 } \
254 else
255
256// STrText = StringA
257#define ATTR_I18NSTRT(attribname, varname, allredraw) \
258 if (0 == strAttribName.CompareNoCase(attribname)) \
259 { \
260 SNS::SStringW strTmp = GETSTRING(strValue); \
261 varname.SetText(S_CW2T(strTmp)); \
262 hRet = allredraw ? S_OK : S_FALSE; \
263 } \
264 else
265
266// DWORD = 0x08x StringA
267#define ATTR_HEX(attribname, varname, allredraw) \
268 if (0 == strAttribName.CompareNoCase(attribname)) \
269 { \
270 int nRet = Str2IntW(strValue, TRUE); \
271 varname = nRet; \
272 hRet = allredraw ? S_OK : S_FALSE; \
273 } \
274 else
275
276// COLORREF = #06X or #08x or rgba(r,g,b,a) or rgb(r,g,b)
277#define ATTR_COLOR(attribname, varname, allredraw) \
278 if (0 == strAttribName.CompareNoCase(attribname)) \
279 { \
280 if (!strValue.IsEmpty()) \
281 { \
282 varname = GETCOLOR(strValue); \
283 hRet = allredraw ? S_OK : S_FALSE; \
284 } \
285 else \
286 { \
287 hRet = E_FAIL; \
288 } \
289 } \
290 else
291
292// DpiAwareFont="face:宋体;bold:1;italic:1;underline:1;adding:10"
293#define ATTR_FONT(attribname, varname, allredraw) \
294 if (0 == strAttribName.CompareNoCase(attribname)) \
295 { \
296 varname.SetFontDesc(strValue, GetScale()); \
297 hRet = allredraw ? S_OK : S_FALSE; \
298 } \
299 else
300
301// Value In {String1 : Value1, String2 : Value2 ...}
302#define ATTR_ENUM_BEGIN(attribname, vartype, allredraw) \
303 if (0 == strAttribName.CompareNoCase(attribname)) \
304 { \
305 vartype varTemp; \
306 \
307 hRet = allredraw ? S_OK : S_FALSE;
308
309#define ATTR_ENUM_VALUE(enumstring, enumvalue) \
310 if (strValue == enumstring) \
311 varTemp = enumvalue; \
312 else
313
314#define ATTR_ENUM_END(varname) \
315 return E_FAIL; \
316 \
317 varname = varTemp; \
318 } \
319 else
320
321// SwndStyle From StringA Key
322#define ATTR_STYLE(attribname, varname, allredraw) \
323 if (0 == strAttribName.CompareNoCase(attribname)) \
324 { \
325 GETSTYLE(strValue, varname); \
326 hRet = allredraw ? S_OK : S_FALSE; \
327 } \
328 else
329
330// SSkinPool From StringA Key
331#define ATTR_SKIN(attribname, varname, allredraw) \
332 if (0 == strAttribName.CompareNoCase(attribname)) \
333 { \
334 varname = GETSKIN(strValue, GetScale()); \
335 hRet = allredraw ? S_OK : S_FALSE; \
336 } \
337 else
338
339// SSkinPool From StringA Key
340#define ATTR_INTERPOLATOR(attribname, varname, allredraw) \
341 if (0 == strAttribName.CompareNoCase(attribname)) \
342 { \
343 varname.Attach(CREATEINTERPOLATOR(strValue)); \
344 hRet = allredraw ? S_OK : S_FALSE; \
345 } \
346 else
347
348// ATTR_IMAGE:直接使用IResProvider::LoadImage创建SNS::IBitmapS对象,创建成功后引用计数为1
349//不需要调用AddRef,但是用完后需要调用Release
350#define ATTR_IMAGE(attribname, varname, allredraw) \
351 if (0 == strAttribName.CompareNoCase(attribname)) \
352 { \
353 SNS::IBitmapS *pImg = LOADIMAGE2(strValue); \
354 if (!pImg) \
355 hRet = E_FAIL; \
356 else \
357 { \
358 if (varname) \
359 varname->Release(); \
360 varname = pImg; \
361 hRet = allredraw ? S_OK : S_FALSE; \
362 } \
363 } \
364 else
365
366// ATTR_IMAGEAUTOREF:varname应该是一个SAutoRefPtr<SNS::IBitmapS>对象
367#define ATTR_IMAGEAUTOREF(attribname, varname, allredraw) \
368 if (0 == strAttribName.CompareNoCase(attribname)) \
369 { \
370 SNS::IBitmapS *pImg = LOADIMAGE2(strValue); \
371 if (!pImg) \
372 hRet = E_FAIL; \
373 else \
374 { \
375 varname = pImg; \
376 pImg->Release(); \
377 hRet = allredraw ? S_OK : S_FALSE; \
378 } \
379 } \
380 else
381
382#define ATTR_ICON(attribname, varname, allredraw) \
383 if (0 == strAttribName.CompareNoCase(attribname)) \
384 { \
385 if (varname) \
386 DestroyIcon(varname); \
387 varname = LOADICON2(strValue); \
388 hRet = allredraw ? S_OK : S_FALSE; \
389 } \
390 else
391
392#define ATTR_CHAR(attribname, varname, allredraw) \
393 if (0 == strAttribName.CompareNoCase(attribname)) \
394 { \
395 varname = *(LPCWSTR)strValue; \
396 hRet = allredraw ? S_OK : S_FALSE; \
397 } \
398 else
399
400#define ATTR_ANIMATION(attribname, varname, allredraw) \
401 if (0 == strAttribName.CompareNoCase(attribname)) \
402 { \
403 varname.Attach(SApplication::getSingleton().LoadAnimation(S_CW2T(strValue))); \
404 hRet = allredraw ? S_OK : S_FALSE; \
405 } \
406 else
407
408#define ATTR_GRADIENT(attribname, varname, allredraw) \
409 if (0 == strAttribName.CompareNoCase(attribname)) \
410 { \
411 SNS::IGradient *pGradient = GETUIDEF->GetGradient(strValue); \
412 if (!pGradient) \
413 hRet = E_FAIL; \
414 else \
415 { \
416 varname = pGradient; \
417 hRet = allredraw ? S_OK : S_FALSE; \
418 } \
419 } \
420 else
421
422#endif //_SATTRCRACK_H