home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WEVENT.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-13
|
7KB
|
215 lines
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (C) 1994, by Watcom International Inc. All rights %
% reserved. No part of this software may be reproduced or %
% used in any form or by any means - graphic, electronic or %
% mechanical, including photocopying, recording, taping or %
% information storage and retrieval systems - except with the %
% written permission of Watcom International Inc. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
/*************************************************************************
*
* WEventGenerator -- Base Event class
*
*************************************************************************/
#ifndef _WEVENT_HPP_INCLUDED
#define _WEVENT_HPP_INCLUDED
#pragma warning 877 9
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#ifndef _WLLIST_HPP_INCLUDED
#include "wllist.hpp"
#endif
#undef WEVENT_DEF
#define WEVENT_DEF( name ) W ## name
enum WEventID {
#include "weventl.hpp"
WEVENT_DEF( MarkerEvent ),
WLastEvent = WMarkerEvent - 1
};
#undef WEVENT_DEF
class WObject;
struct WEventData;
/* Define a generic callback type */
typedef WBool WCMDEF (WObject::*WEventHandler)( WObject *source,
WEventData *event );
#define WEventHandlerCast( __cls, __hdlr ) \
static_cast< WBool (WObject::*)( WObject *, WEventData * ) >( \
reinterpret_cast< WBool (__cls::*)( WObject *, WEventData * ) >( \
&__cls::__hdlr ) )
/* Define a struct for setting multiple events */
struct WEventHandlerList {
WEventID eventID;
WEventHandler eventHandler;
WObject *object;
void *userData;
};
/* The event class -- an object must inherit from this class
to be able to set and invoke events */
class WCMCLASS WEventGenerator : public WObject {
WDeclareSubclass( WEventGenerator, WObject );
public:
struct event_data {
wllist_link link;
WEventID id;
WObject * object;
WEventHandler handler;
WLong returns;
void * userdata;
WBool reserved;
};
protected:
/**************************************************************
* Constructors and destructors
**************************************************************/
WEventGenerator();
virtual ~WEventGenerator();
/**************************************************************
* Properties
**************************************************************/
public:
/**************************************************************
* Methods
**************************************************************/
// CallEventHandler
virtual WBool CallEventHandler( WEventID id,
WObject * object,
WEventData * eventData=NULL,
WLong * retval=NULL,
WInt indexToStartAt=0 ) const;
// EventID
static WEventID EventID( const WChar * name );
// HasEventHandler
virtual WBool HasEventHandler( WEventID id ) const;
// RemoveAllEventHandlers
virtual WBool RemoveAllEventHandlers();
// RemoveEventHandler
virtual WBool RemoveEventHandler( WEventID id,
WBool removeAll=FALSE,
WInt * index=NULL );
virtual WBool RemoveEventHandler( WEventID id,
WObject * object,
WEventHandler handler,
WInt * index=NULL );
// RemoveEventHandlerList
//
// Remove several events at once from a null-terminated
// array of events. If no object is passed, uses "this"
// by default.
WBool RemoveEventHandlerList( WEventHandlerList * list,
WObject * object=NULL );
// SetEventHandlerList
//
// Set several events at once from a null-terminated
// array of events. If no object is passed, uses "this"
// by default.
WBool SetEventHandlerList( WEventHandlerList * list,
WObject * object=NULL );
/**************************************************************
* Item Properties
**************************************************************/
virtual WBool SetEventHandler( WEventID id, WObject * object,
WEventHandler handler,
void * userdata=NULL,
WInt * index=NULL );
virtual WBool GetEventHandler( WEventID id, WObject ** object,
WEventHandler * handler,
void ** userdata=NULL,
WEventHandler current=NULL ) const;
/**************************************************************
* Cache
**************************************************************/
// FlushCache
static void FlushCache();
// CacheSize
static WULong GetCacheSize();
static WBool SetCacheSize( WULong newSize );
/**************************************************************
* Others
**************************************************************/
protected:
virtual event_data * FindEvent( WEventID id ) const;
virtual WBool FastCallEventHandler( event_data *first,
WObject * object,
WEventData * eventData=NULL,
WLong * retval=NULL,
WInt indexToStartAt=0 ) const;
enum WEventNotice {
WEventNoticeAdd,
WEventNoticeRemove,
WEventNoticeRemoveAll
};
virtual void EventNotice( WEventID id, WEventNotice type );
/**************************************************************
* Data members
**************************************************************/
private:
WULong _bitfield : 32;
wllist_header _events;
WEventHandler _currHandler;
};
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WEVENT_HPP_INCLUDED