6#ifndef _ZFI_ZFStyleable_h_
7#define _ZFI_ZFStyleable_h_
126#define _ZFP_ZFStyleableDefault_level ZFLevelZFFrameworkHigh
130 _ZFP_ZFStyleableDefaultPointerHolder(
void) : d(
zfnull) {}
134typedef void (*_ZFP_ZFStyleableDefaultDeleteCallback)(
ZF_IN void *instance);
137 _ZFP_ZFStyleableDefaultDeleteCallbackHolder(
138 ZF_IN _ZFP_ZFStyleableDefaultDeleteCallback deleteCallback
139 ,
ZF_IN void *instance
141 : deleteCallback(deleteCallback)
145 ~_ZFP_ZFStyleableDefaultDeleteCallbackHolder(
void) {
146 if(this->deleteCallback && this->instance) {
147 this->deleteCallback(this->instance);
151 _ZFP_ZFStyleableDefaultDeleteCallback deleteCallback;
155#define _ZFP_ZFSTYLE_DEFAULT_DECLARE(YourStyle) \
157 zfclass _ZFP_ZFStyleableDefault_##YourStyle; \
160 static zfanyT<YourStyle> DefaultStyle(void); \
162 static void _ZFP_ZFStyleablEnumDefaultStyle(ZF_IN YourStyle *newInstance); \
163 static const ZFCorePointer *&_ZFP_ZFStyleableDefaultCleaner(void); \
164 static void _ZFP_ZFStyleableDefaultOnDelete(ZF_IN void *instance); \
166#define _ZFP_ZFSTYLE_DEFAULT_DEFINE(YourStyle) \
167 zfclass YourStyle::_ZFP_ZFStyleableDefault_##YourStyle : zfextend YourStyle { \
168 ZFOBJECT_DECLARE(_ZFP_ZFStyleableDefault_##YourStyle, YourStyle) \
171 virtual zfbool styleableIsDefaultStyle(void) { \
175 zfanyT<YourStyle> YourStyle::DefaultStyle(void) { \
176 static _ZFP_ZFStyleableDefaultPointerHolder *holder = _ZFP_ZFStyleableDefaultRefAccess(#YourStyle); \
177 if(holder->d == zfnull) { \
178 ZFCoreMutexLocker(); \
179 if(ZFFrameworkStateCheck(_ZFP_ZFStyleableDefault_level) == ZFFrameworkStateNotAvailable) { \
182 zfauto obj = _ZFP_ZFStyleableDefault_##YourStyle::ClassData()->newInstance(); \
183 if(obj != zfnull) { \
184 zfself::_ZFP_ZFStyleablEnumDefaultStyle(obj.to<YourStyle *>()); \
187 return (YourStyle *)holder->d; \
189 ZFMETHOD_USER_REGISTER_DETAIL_0({ \
190 return YourStyle::DefaultStyle(); \
192 public, ZFMethodTypeStatic, s, \
193 zfanyT<YourStyle>, DefaultStyle) \
194 void YourStyle::_ZFP_ZFStyleablEnumDefaultStyle(ZF_IN YourStyle *newInstance) { \
195 if(ZFFrameworkStateCheck(_ZFP_ZFStyleableDefault_level) == ZFFrameworkStateNotAvailable) { \
198 _ZFP_ZFStyleableDefaultPointerHolder *holder = _ZFP_ZFStyleableDefaultRefAccess(#YourStyle); \
199 if(holder->d == newInstance) { \
202 const ZFCorePointer *&cleanerRef = _ZFP_ZFStyleableDefaultCleaner(); \
203 const ZFCorePointer *cleanerOld = cleanerRef; \
204 const ZFCorePointer *cleanerNew = zfnull; \
205 cleanerRef = zfnull; \
206 if(newInstance != zfnull) { \
207 holder->d = zfRetain(newInstance); \
208 cleanerNew = ZFObjectGlobalInstanceAdd(ZFCorePointerForObject<_ZFP_ZFStyleableDefaultDeleteCallbackHolder *>( \
209 zfnew(_ZFP_ZFStyleableDefaultDeleteCallbackHolder, YourStyle::_ZFP_ZFStyleableDefaultOnDelete, holder->d)), \
210 _ZFP_ZFStyleableDefault_level); \
211 cleanerRef = cleanerNew; \
213 if(cleanerOld != zfnull) { \
214 ZFObjectGlobalInstanceRemove(cleanerOld, _ZFP_ZFStyleableDefault_level); \
215 holder->d = newInstance; \
216 cleanerRef = cleanerNew; \
219 const ZFCorePointer *&YourStyle::_ZFP_ZFStyleableDefaultCleaner(void) { \
220 static const ZFCorePointer *_cleaner = zfnull; \
223 void YourStyle::_ZFP_ZFStyleableDefaultOnDelete(ZF_IN void *instance) { \
224 YourStyle::_ZFP_ZFStyleableDefaultCleaner() = zfnull; \
225 _ZFP_ZFStyleableDefaultPointerHolder *holder = _ZFP_ZFStyleableDefaultRefAccess(#YourStyle); \
226 holder->d = zfnull; \
227 zfRelease((YourStyle *)instance); \
262#define ZFSTYLE_DEFAULT_DECLARE(YourStyle) \
263 _ZFP_ZFSTYLE_DEFAULT_DECLARE(YourStyle)
265#define ZFSTYLE_DEFAULT_DEFINE(YourStyle) \
266 _ZFP_ZFSTYLE_DEFAULT_DEFINE(YourStyle)
285#define ZFSTYLE_DEFAULT_AUTO_COPY() \
286 ZFINTERFACE_ON_INIT_DECLARE() { \
287 if(!this->styleableIsDefaultStyle()) { \
288 zfanyT<ZFStyleable> defaultStyle = this->defaultStyle(); \
289 if(defaultStyle != zfnull) { \
290 this->styleableCopyFrom(defaultStyle); \
291 ZFStyleDefaultApplyAutoCopy(this); \
441#define ZFStyleUpdateBlock() _ZFP_ZFStyleUpdateBlock ZFUniqueName(_ZFP_ZFStyleUpdateBlock)
444 _ZFP_ZFStyleUpdateBlock(
void) {
447 ~_ZFP_ZFStyleUpdateBlock(
void) {
494#define ZFSTYLE_DECODER_DEFINE(registerSig, decodeAction, ...) \
495 _ZFP_ZFSTYLE_DECODER_DEFINE(registerSig, decodeAction, ##__VA_ARGS__)
496#define _ZFP_ZFSTYLE_DECODER_DEFINE(registerSig, decodeAction, ...) \
497 ZF_STATIC_REGISTER_INIT(ZFStyleDecoder_##registerSig) { \
498 _ZFP_ZFStyleDecoderRegister(zftext(#registerSig), zfself::_ZFP_decode); \
500 ZF_STATIC_REGISTER_DESTROY(ZFStyleDecoder_##registerSig) { \
501 _ZFP_ZFStyleDecoderUnregister(zftext(#registerSig)); \
503 static zfbool _ZFP_decode( \
505 , ZF_IN const zfstring &styleKey \
507 decodeAction __VA_ARGS__ \
509 ZF_STATIC_REGISTER_END(ZFStyleDecoder_##registerSig)
510typedef zfbool (*_ZFP_ZFStyleDecoder)(
516 ,
ZF_IN _ZFP_ZFStyleDecoder decoder
interface shows a ZFObject is copyable
#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 zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
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 zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition ZFObjectCast.h:28
#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:126
#define zfsuperI(T_SuperType)
class ref to proper super type, see ZFObject for more info
Definition ZFObjectDeclare.h:26
#define ZFINTERFACE_ON_DEALLOC_DECLARE()
see ZFINTERFACE_ON_INIT_DECLARE
Definition ZFObjectInterface.h:298
#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:369
ZFCoreArray< zfauto > ZFStyleGetAllValue(void)
see ZFStyleGetAll
Definition ZFStyleable.h:418
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:408
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:331
base class of all objects
Definition ZFObjectCore.h:209
info for a property for ZFObject, see ZFPROPERTY_RETAIN for more info
Definition ZFProperty.h:28
virtual void copyableOnCopyFrom(ZFObject *anotherObj)
called by copy to copy contents from anotherObj
Definition ZFStyleable.h:118
ZFStyle zfself
class ref to self
Definition ZFStyleable.h:113
styleable element that can apply style from another object
Definition ZFStyleable.h:30
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
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 styleableCopyFrom, see ZFStyleable
void styleableCopyFrom(ZFObject *anotherStyleable)
copy style from another styleable, see ZFStyleable
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
void styleKey(const zfstring &styleKey)
see ZFStyleSet
see zfany
Definition zfany.h:106
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34