home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 February
/
PCWorld_2000-02_cd.bin
/
Software
/
TemaCD
/
tcvpa
/
data1.cab
/
MyFileGroup
/
INCLUDE
/
EvMaster.hpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-03
|
4KB
|
139 lines
#ifndef _INC_EVMASTER_HPP
#define _INC_EVMASTER_HPP
#ifdef BUILD_TCCORE
#define TCCORELIB __declspec(dllexport)
#else
#ifdef BUILD_LOCAL
#define TCCORELIB
#else
#define TCCORELIB __declspec(dllimport)
#endif
#endif
class TC_CEventMaster;
struct _TC_CEvInfItem;
struct TC_Event;
struct event_t
{
int type;
int id;
event_t () { type=0; id=0; }
event_t (int t,int i) { type=t; id=i; }
event_t (LPCSTR str) { type=id=0; strncpy((char*)&type,str,8); }
};
struct TC_Event
{
event_t event;
TC_CEventMaster * object;
TC_CEventMaster * sender;
long dw_user;
long arg;
TC_Event() { sender = 0; }
};
typedef BOOL (TC_CEventMaster::* C_EVENT_HANDLER)( TC_Event * ev );
typedef BOOL ( * S_EVENT_HANDLER)( TC_Event * ev );
inline BOOL operator == (const event_t &e1, const event_t &e2)
{
return (e1.type == e2.type && e1.id == e2.id);
}
inline BOOL operator > (const event_t &e1, const event_t &e2)
{
if(e1.type < e2.type ) return FALSE;
if(e1.type > e2.type ) return TRUE;
return (e1.id > e2.id);
}
inline BOOL operator < (const event_t &e1, const event_t &e2)
{
if(e1.type > e2.type ) return FALSE;
if(e1.type < e2.type ) return TRUE;
return (e1.id < e2.id);
}
inline BOOL operator == (const event_t &e1, LPCSTR s)
{
return !strncmp( (char*)&e1.type, s, 8 );
}
#define C_EVENT_CAST(f,cls) (C_EVENT_HANDLER)((BOOL(cls::*)(TC_Event*))f)
//#define SET_C_EV(t,i,o,f) SetCEventHandler(event_t(t,i),o,(C_EVENT_HANDLER)(f))
#define SET_S_EV(t,i,f) SetSEventHandler(event_t(t,(int)(i)),(S_EVENT_HANDLER)(f))
#define SET_S_EV_(t,i,f,o) SetSEventHandler(event_t(t,(int)(i)),(S_EVENT_HANDLER)(f),(long)o)
#define SET_S_EV_STR(ss,f) SetSEventHandler(event_t(ss),(S_EVENT_HANDLER)(f))
#define SET_C_EV(t,i,o,f,cls) SetCEventHandler(\
event_t((int)(t),(int)(i)),\
o,\
(C_EVENT_HANDLER)((BOOL(cls::*)(TC_Event*))f))
#define SET_THIS_EV(t,i,f,cls) SetCEventHandler(\
event_t((int)(t),(int)(i)),\
this,\
(C_EVENT_HANDLER)((BOOL(cls::*)(TC_Event*))f)\
)
#define SET_THIS_EV_(t,i,dwu,f,cls) SetCEventHandler(\
event_t((int)(t),(int)(i)),\
this,\
(C_EVENT_HANDLER)((BOOL(cls::*)(TC_Event*))f),\
dwu\
)
#define SET_OBJ_EV(w,t,i,f,cls) (w)->SetCEventHandler(\
event_t((int)(t),(int)(i)),\
w,\
(C_EVENT_HANDLER)((BOOL(cls::*)(TC_Event*))f)\
)
#define SET_THIS_EV_STR(ss,f,cls) SetCEventHandler(\
event_t(ss),\
this,\
(C_EVENT_HANDLER)((BOOL(cls::*)(TC_Event*))f)\
)
// **********************************************************************
class TCCORELIB TC_CEventMaster
{
private: TC_TArrayPTR <_TC_CEvInfItem>* _EvTbl ;
private: TC_TArrayPTR <TC_CEventMaster>* _EvHandled ;
public: TC_CEventMaster () ;
public: virtual ~TC_CEventMaster () ;
private: void _SetEventHandler (event_t event, TC_CEventMaster * object, C_EVENT_HANDLER c_func, S_EVENT_HANDLER s_func, long dw_user) ;
public: void SetCEventHandler (event_t event, TC_CEventMaster * object, C_EVENT_HANDLER c_func, long dw_user=0) ;
public: void SetSEventHandler (event_t event, S_EVENT_HANDLER s_func, long dw_user=0) ;
public: void ClearAllHandlers () ;
public: void RemoveLinkHandlers (TC_CEventMaster * object) ;
public: BOOL RemoveLinkCHandler (TC_CEventMaster * object, C_EVENT_HANDLER c_proc) ;
public: void RemoveMyHandlers () ;
public: void RemoveMyCHandler (C_EVENT_HANDLER c_proc) ;
public: BOOL CallEventHandler (TC_Event * es) ;
public: virtual void* GetInterface (LPCSTR name) ;
public: virtual const char* GetClassName () ;
public: static void Destroy (TC_CEventMaster *obj) ;
}; // end of class TC_CEventMaster
// **********************************************************************
// **********************************************************************
struct TCCORELIB _TC_CEvInfItem
{
public: event_t event ;
public: C_EVENT_HANDLER c_func ;
public: S_EVENT_HANDLER s_func ;
public: TC_CEventMaster* object ;
public: _TC_CEvInfItem* next ;
public: long dw_user ;
public: ~_TC_CEvInfItem () ;
}; // end of class _TC_CEvInfItem
// **********************************************************************
TCCORELIB BOOL _NullHandler (TC_Event *) ;
#endif // _INC_EVMASTER_HPP