ZFFramework
Loading...
Searching...
No Matches
ZFStyleable.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFStyleable_h_
7#define _ZFI_ZFStyleable_h_
8
9#include "ZFSerializable.h"
10#include "ZFObjectObserver.h"
12
13// ============================================================
14// ZFStyleable
15zfclassFwd _ZFP_ZFStyleKeyHolder;
29zfinterface ZFLIB_ZFCore ZFStyleable : zfextend ZFInterface {
30 ZFINTERFACE_DECLARE(ZFStyleable, ZFInterface)
31
32public:
42 virtual void copyFrom(ZF_IN ZFObject *anotherStyleable);
43
44public:
57 return zffalse;
58 }
59
65 );
70
71protected:
76 ZF_IN ZFObject *anotherStyleable
77 , ZF_IN const ZFProperty *property
78 );
83 virtual void styleableOnCopyFrom(ZF_IN ZFObject *anotherStyleable);
84
85public:
92 ZF_IN const zfstring &propertyName
93 , ZF_IN const zfstring &styleKey
94 );
96 zffinal const zfstring &propStyle(ZF_IN const zfstring &propertyName);
97private:
98 friend zfclassFwd _ZFP_ZFStyleKeyHolder;
99
100 // ============================================================
101public:
109 ZF_IN ZFStyleable *from
110 , ZF_IN ZFStyleable *to
111 , ZF_IN zffloat progress
112 );
113
114protected:
116 virtual inline zfbool progressOnUpdate(
117 ZF_IN ZFStyleable *from
118 , ZF_IN ZFStyleable *to
119 , ZF_IN zffloat progress
120 ) {
121 return zffalse;
122 }
123};
124
125// ============================================================
126// ZFStyle
134zfclass ZFLIB_ZFCore ZFStyle : zfextend ZFObject, zfimplement ZFStyleable, zfimplement ZFSerializable {
135 ZFOBJECT_DECLARE(ZFStyle, ZFObject)
136 ZFIMPLEMENT_DECLARE(ZFStyleable, ZFSerializable)
137};
138
139// ============================================================
140// DefaultStyle
141#define _ZFP_ZFStyleableDefault_level ZFLevelZFFrameworkHigh
142extern ZFLIB_ZFCore void **_ZFP_ZFStyleableDefaultRefAccess(ZF_IN const zfstring &name);
143typedef void (*_ZFP_ZFStyleableDefaultDeleteCallback)(ZF_IN void *instance);
144zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFStyleableDefaultDeleteCallbackHolder {
145public:
146 _ZFP_ZFStyleableDefaultDeleteCallbackHolder(
147 ZF_IN _ZFP_ZFStyleableDefaultDeleteCallback deleteCallback
148 , ZF_IN void *instance
149 )
150 : deleteCallback(deleteCallback)
151 , instance(instance)
152 {
153 }
154 ~_ZFP_ZFStyleableDefaultDeleteCallbackHolder(void) {
155 if(this->deleteCallback && this->instance) {
156 this->deleteCallback(this->instance);
157 }
158 }
159private:
160 _ZFP_ZFStyleableDefaultDeleteCallback deleteCallback;
161 void *instance;
162};
163
164#define _ZFP_ZFSTYLE_DEFAULT_DECLARE(YourStyle) \
165 public: \
166 zfclass _ZFP_StyleDef_##YourStyle; \
167 public: \
168 \
169 static zfanyT<YourStyle> DefaultStyle(void); \
170 private: \
171 static void _ZFP_StyleDefU(ZF_IN YourStyle *newInstance); \
172 static ZFObject *&_ZFP_StyleDefC(void); /* cleaner */ \
173 static void _ZFP_StyleDefD(ZF_IN void *instance); /* onDelete */ \
174 public:
175#define _ZFP_ZFSTYLE_DEFAULT_DEFINE(YourStyle) \
176 zfclass YourStyle::_ZFP_StyleDef_##YourStyle : zfextend YourStyle { \
177 ZFOBJECT_DECLARE(_ZFP_StyleDef_##YourStyle, YourStyle) \
178 public: \
179 zfoverride \
180 virtual zfbool styleableIsDefaultStyle(void) { \
181 return zftrue; \
182 } \
183 }; \
184 zfanyT<YourStyle> YourStyle::DefaultStyle(void) { \
185 static void **holder = _ZFP_ZFStyleableDefaultRefAccess(#YourStyle); \
186 if(*holder == zfnull) { \
187 ZFCoreMutexLocker(); \
188 if(ZFFrameworkStateCheck(_ZFP_ZFStyleableDefault_level) == ZFFrameworkStateNotAvailable) { \
189 return zfnull; \
190 } \
191 zfauto obj = _ZFP_StyleDef_##YourStyle::ClassData()->newInstance(); \
192 if(obj != zfnull) { \
193 zfself::_ZFP_StyleDefU(obj.to<YourStyle *>()); \
194 } \
195 } \
196 return (YourStyle *)(*holder); \
197 } \
198 ZFMETHOD_USER_REGISTER_DETAIL_0(YourStyle, \
199 public, ZFMethodTypeStatic, s, \
200 zfanyT<YourStyle>, DefaultStyle) { \
201 return YourStyle::DefaultStyle(); \
202 } \
203 void YourStyle::_ZFP_StyleDefU(ZF_IN YourStyle *newInstance) { \
204 if(ZFFrameworkStateCheck(_ZFP_ZFStyleableDefault_level) == ZFFrameworkStateNotAvailable) { \
205 return; \
206 } \
207 void **holder = _ZFP_ZFStyleableDefaultRefAccess(#YourStyle); \
208 if(*holder == (void *)newInstance) { \
209 return; \
210 } \
211 ZFObject *&cleanerRef = _ZFP_StyleDefC(); \
212 zfauto cleanerOld = cleanerRef; \
213 cleanerRef = zfnull; \
214 if(newInstance != zfnull) { \
215 *holder = (void *)zfobjRetain(newInstance); \
216 zfobj<ZFValue> cleanerRefTmp(*holder, YourStyle::_ZFP_StyleDefD); \
217 cleanerRef = cleanerRefTmp; \
218 ZFObjectGlobalInstanceAdd(cleanerRef, _ZFP_ZFStyleableDefault_level); \
219 } \
220 if(cleanerOld != zfnull) { \
221 ZFObjectGlobalInstanceRemove(cleanerOld, _ZFP_ZFStyleableDefault_level); \
222 *holder = (void *)newInstance; \
223 } \
224 } \
225 ZFObject *&YourStyle::_ZFP_StyleDefC(void) { \
226 static ZFObject *_cleaner = zfnull; \
227 return _cleaner; \
228 } \
229 void YourStyle::_ZFP_StyleDefD(ZF_IN void *instance) { \
230 YourStyle::_ZFP_StyleDefC() = zfnull; \
231 void **holder = _ZFP_ZFStyleableDefaultRefAccess(#YourStyle); \
232 *holder = zfnull; \
233 zfobjRelease((YourStyle *)instance); \
234 }
235
268#define ZFSTYLE_DEFAULT_DECLARE(YourStyle) \
269 _ZFP_ZFSTYLE_DEFAULT_DECLARE(YourStyle)
270
271#define ZFSTYLE_DEFAULT_DEFINE(YourStyle) \
272 _ZFP_ZFSTYLE_DEFAULT_DEFINE(YourStyle)
273
283
291#define ZFSTYLE_DEFAULT_AUTO_COPY() \
292 ZFINTERFACE_ON_INIT_DECLARE() { \
293 if(!this->styleableIsDefaultStyle()) { \
294 zfanyT<ZFStyleable> defaultStyle = this->defaultStyle(); \
295 if(defaultStyle != zfnull) { \
296 this->copyFrom(defaultStyle); \
297 ZFStyleDefaultApplyAutoCopy(this); \
298 } \
299 } \
300 }
301
302// ============================================================
303// style holder
390 ZF_IN const zfstring &styleKey
391 , ZF_IN ZFStyleable *styleValue
392 );
407 , ZF_IN_OUT ZFCoreArray<zfauto> &styleValue
408 );
412 );
417 return ret;
418}
419
422 );
427 return ret;
428}
429
434
443
447#define ZFStyleUpdateBlock() _ZFP_ZFStyleUpdateBlock ZFUniqueName(_ZFP_ZFStyleUpdateBlock)
448zfclassLikePOD _ZFP_ZFStyleUpdateBlock {
449public:
450 _ZFP_ZFStyleUpdateBlock(void) {
452 }
453 ~_ZFP_ZFStyleUpdateBlock(void) {
455 }
456};
457
464ZFEVENT_GLOBAL(ZFLIB_ZFCore, ZFStyleOnUpdateBegin)
480ZFEVENT_GLOBAL(ZFLIB_ZFCore, ZFStyleOnInvalid)
482
483// ============================================================
506#define ZFSTYLE_DECODER_DEFINE(registerSig, decodeAction, ...) \
507 _ZFP_ZFSTYLE_DECODER_DEFINE(registerSig, decodeAction, ##__VA_ARGS__)
508#define _ZFP_ZFSTYLE_DECODER_DEFINE(registerSig, decodeAction, ...) \
509 ZF_STATIC_REGISTER_INIT(ZFStyleDecoder_##registerSig) { \
510 _ZFP_ZFStyleDecoderRegister(zftext(#registerSig), zfself::_ZFP_decode); \
511 } \
512 ZF_STATIC_REGISTER_DESTROY(ZFStyleDecoder_##registerSig) { \
513 _ZFP_ZFStyleDecoderUnregister(zftext(#registerSig)); \
514 } \
515 static zfbool _ZFP_decode( \
516 ZF_OUT zfauto &ret \
517 , ZF_IN const zfstring &styleKey \
518 ) { \
519 decodeAction __VA_ARGS__ \
520 } \
521 ZF_STATIC_REGISTER_END(ZFStyleDecoder_##registerSig)
522typedef zfbool (*_ZFP_ZFStyleDecoder)(
523 ZF_OUT zfauto &ret
524 , ZF_IN const zfstring &styleKey
525 );
526extern ZFLIB_ZFCore void _ZFP_ZFStyleDecoderRegister(
527 ZF_IN const zfstring &registerSig
528 , ZF_IN _ZFP_ZFStyleDecoder decoder
529 );
530extern ZFLIB_ZFCore void _ZFP_ZFStyleDecoderUnregister(ZF_IN const zfstring &registerSig);
531
533#endif // #ifndef _ZFI_ZFStyleable_h_
534
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:191
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:199
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:207
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_zft_zffloat zffloat
same as float, see zfindex
Definition ZFCoreTypeDef_CoreType.h:183
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_END(NameSpace)
end namespace
Definition ZFNamespace.h:60
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define ZF_NAMESPACE_BEGIN(NameSpace)
begin namespace
Definition ZFNamespace.h:40
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:123
#define ZFIMPLEMENT_DECLARE(ImplementedInterfaces,...)
see ZFINTERFACE_DECLARE
Definition ZFObjectInterface.h:169
#define zfimplement
shows class implement from interface, see ZFInterface
Definition ZFObjectInterface.h:24
#define zfinterface
shows the type is an interface, see ZFInterface
Definition ZFObjectInterface.h:20
#define ZFINTERFACE_DECLARE(InterfaceName, ParentInterface,...)
see ZFInterface
Definition ZFObjectInterface.h:100
observer types for ZFObject
#define ZFEVENT_GLOBAL(ZFLIB_, YourEvent)
declare a observer event in global scope, see ZFEVENT
Definition ZFObjectObserver.h:357
serializable interface
ZFCoreArray< zfauto > ZFStyleGetAllValue(void)
see ZFStyleGetAll
Definition ZFStyleable.h:424
void ZFStyleSet(const zfstring &styleKey, ZFStyleable *styleValue)
used to store style holder
void ZFStyleRemoveAll(void)
remove all styles, see ZFStyleSet
void ZFStyleGetAllKeyT(ZFCoreArray< zfstring > &styleKey)
see ZFStyleGetAll
void ZFStyleUpdateBegin()
see ZFStyleSet
void ZFStyleGetAllValueT(ZFCoreArray< zfauto > &styleValue)
see ZFStyleGetAll
zfauto ZFStyleGet(const zfstring &styleKey)
see ZFStyleSet
ZFCoreArray< zfstring > ZFStyleGetAllKey(void)
see ZFStyleGetAll
Definition ZFStyleable.h:414
void ZFStyleUpdateEnd()
see ZFStyleSet
void ZFStyleDefaultApplyAutoCopy(ZFStyleable *style)
util method to setup automatically copy style from ZFStyleable::defaultStyle if its property value ch...
void ZFStyleGetAll(ZFCoreArray< zfstring > &styleKey, ZFCoreArray< zfauto > &styleValue)
get all styles, for debug use only, see ZFStyleSet
light weight array
Definition ZFCoreArray.h:348
base class of all objects
Definition ZFObjectCore.h:195
info for a property for ZFObject, see ZFPROPERTY_RETAIN for more info
Definition ZFProperty.h:27
styleable element that can apply style from another object
Definition ZFStyleable.h:29
const zfstring & styleKey(void)
see ZFStyleSet
ZFCoreArray< const ZFProperty * > styleablePropertyGetAll(void)
return a list of styleable property, for debug use only
virtual zfbool styleableIsDefaultStyle(void)
true if this object is defaultStyle
Definition ZFStyleable.h:56
virtual zfanyT< ZFStyleable > defaultStyle(void)
return default style of this instance
zfbool progressUpdate(ZFStyleable *from, ZFStyleable *to, zffloat progress)
update object according to progress
void styleablePropertyGetAllT(ZFCoreArray< const ZFProperty * > &ret)
return a list of styleable property, for debug use only
virtual void styleableOnCopyFrom(ZFObject *anotherStyleable)
for subclass to achieve custom style copy step, called by copyFrom, see ZFStyleable
virtual zfautoT< ZFStyleable > copy(void)
return a copy of this object
virtual void copyFrom(ZFObject *anotherStyleable)
copy from another object
void propStyle(const zfstring &propertyName, const zfstring &styleKey)
see ZFStyleSet
const zfstring & propStyle(const zfstring &propertyName)
see ZFStyleSet
virtual void styleableOnCopyPropertyFrom(ZFObject *anotherStyleable, const ZFProperty *property)
copy property with styleable logic
virtual zfbool progressOnUpdate(ZFStyleable *from, ZFStyleable *to, zffloat progress)
see progressUpdate
Definition ZFStyleable.h:116
void styleKey(const zfstring &styleKey)
see ZFStyleSet
see zfany
Definition zfany.h:113
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
type restrict version of zfauto
Definition zfautoFwd.h:108
Definition ZFApp.h:13