00001
00048 #ifndef INC_GRE_OBJECTBASE_H
00049 #define INC_GRE_OBJECTBASE_H
00050
00051 #ifndef INC_GRE_MSG_H
00052 #include <gre/msg.h>
00053 #endif
00054
00055
00056 #ifndef GENERATING_DOXYGEN_OUTPUT
00057 struct MICONSTRUCT;
00058 #endif
00059
00060
00061 namespace GRE {
00062
00064 class OBJECT {
00065
00066 public:
00067
00069 enum TYPE {
00070 TYPE_None = 0,
00071 TYPE_System = 0x01,
00072 TYPE_Layout = 0x02,
00073 TYPE_Group = 0x04,
00074 TYPE_Layer = 0x08,
00075 TYPE_View = 0x10,
00076 TYPE_All = 0xFF
00077 };
00078
00079 typedef void (*CBFUNC)(const GRE::MSG*, void*);
00080
00082 void AddRef (
00083 ) { ++m_RefCount; }
00084
00094 static int AllocPrivIndex (
00095 );
00096
00098 explicit OBJECT (
00099 OBJECT::TYPE type
00100 );
00101
00103 virtual ~OBJECT (
00104 ) = 0;
00105
00121 void CallbackAdd (
00122 CBFUNC cbfunc,
00123 void *cbdata,
00124 OBJECT::TYPE objtypes
00125 ) { m_CallbackList.Add(cbfunc,cbdata,objtypes); }
00126
00129 void CallbackInvoke (
00130 GRE::MSG::ACTION action,
00131 GRE::VIEW *view = 0,
00132 ELEMTYPE elemtype = ELEMTYPE_Empty
00133 ) { GRE::MSG msg(action,this,view,elemtype); CallbackInvoke(msg); }
00134
00137 void CallbackInvoke (
00138 GRE::MSG::ACTION action,
00139 ELEMTYPE elemtype
00140 ) { GRE::MSG msg(action,this,elemtype); CallbackInvoke(msg); }
00141
00144 void CallbackInvoke (
00145 GRE::VIEW *view,
00146 GRE::MSG::ACTION action
00147 ) { GRE::MSG msg(action,this,view); CallbackInvoke(msg); }
00148
00151 void CallbackInvoke (
00152 const GRE::MSG& msg
00153 );
00154
00162 void CallbackRemove (
00163 CBFUNC cbfunc,
00164 void *cbdata,
00165 OBJECT::TYPE objtypes = TYPE_All
00166 ) { m_CallbackList.Remove(cbfunc,cbdata,objtypes); }
00167
00175 bool Destroy (
00176 bool NotifyParent = true
00177 ) { return (v_Destroy(NotifyParent)); }
00178
00187 bool DestroyRequested (
00188 ) const { return (m_DestroyRequested); }
00189
00191 MICONSTRUCT* GetIcon (
00192 ) const { return (v_GetIcon()); }
00193
00196 void *GetPrivPtr (
00197 int idx
00198 ) const { return (m_PrivData[idx]); }
00199
00201 OBJECT::TYPE GetType (
00202 ) const { return (m_objtype); }
00203
00206 const char* GetTypeName (
00207 ) const { return (v_GetTypeName()); }
00208
00211 const char* GetTypeName (
00212 char *string
00213 ) const;
00214
00221 bool IsBeingDestroyed (
00222 ) const { return (m_BeingDestroyed); }
00223
00226 bool IsTemporary (
00227 ) const { return (m_IsTemporary); }
00228
00230 void Release (
00231 );
00232
00239 void SetPrivPtr (
00240 int idx,
00241 void *privptr
00242 ) { if (idx > 0 && idx < s_PrivDataCount) m_PrivData[idx] = privptr; }
00243
00244 protected:
00245
00247 bool CallbacksBeingInvoked (
00248 ) const { return (m_RefCount > 0 || m_CallbackList.BeingInvoked()); }
00249
00251 void SetBeingDestroyed (
00252 ) { m_BeingDestroyed = true; }
00253
00255 void SetDestroyRequest (
00256 ) { m_DestroyRequested = true; }
00257
00259 void SetTemporary (
00260 ) { m_IsTemporary = true; }
00261
00262 private:
00263
00264 #ifndef GENERATING_DOXYGEN_OUTPUT
00265
00266
00268 class CBFUNCLIST {
00269 public:
00270
00271 CBFUNCLIST (
00272 );
00273
00274 ~CBFUNCLIST (
00275 );
00276
00278 void Add (
00279 CBFUNC cbfunc,
00280 void *cbdata,
00281 OBJECT::TYPE objtypes
00282 );
00283
00285 bool BeingInvoked (
00286 ) const { return (m_callcount > 0); }
00287
00289 void Invoke (
00290 const GRE::MSG& msg
00291 );
00292
00294 void Remove (
00295 CBFUNC cbfunc,
00296 void *cbdata,
00297 OBJECT::TYPE objtypes = TYPE_All
00298 );
00299
00300 private:
00301
00302 class ITEM {
00303 public:
00304
00305 ITEM (
00306 CBFUNC cbfunc,
00307 void *cbdata,
00308 OBJECT::TYPE objtypes
00309 );
00310
00311 CBFUNC m_cbfunc;
00312 void *m_cbdata;
00313 OBJECT::TYPE m_objtypes;
00314 ITEM *m_next;
00315 };
00316
00317 ITEM *m_first;
00318 UINT16 m_callcount;
00319 bool m_DidRemove;
00320 };
00321
00322 static int s_PrivDataCount;
00323 static int s_PrivDataAlloc;
00324
00325 const TYPE m_objtype;
00326 void **m_PrivData;
00327 CBFUNCLIST m_CallbackList;
00328 bool m_DestroyRequested;
00329 bool m_BeingDestroyed;
00330 bool m_IsTemporary;
00331 UINT32 m_RefCount;
00332
00333 #endif // GENERATING_DOXYGEN_OUTPUT
00334
00336 virtual bool v_Destroy (bool NotifyParent) = 0;
00337 virtual MICONSTRUCT* v_GetIcon () const = 0;
00338 virtual const char* v_GetTypeName () const = 0;
00339 };
00340 #ifndef GENERATING_DOXYGEN_OUTPUT
00341 DEFINE_ENUM_OP_BITWISE(OBJECT::TYPE);
00342 #endif
00343
00344
00345 }
00346
00347
00348
00349 #endif // INC_GRE_OBJECTBASE_H