home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IHANDLER.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
10KB
|
166 lines
#ifndef _IHANDLER_
#define _IHANDLER_
/*******************************************************************************
* FILE NAME: ihandler.hpp *
* *
* DESCRIPTION: *
* This file contains the declaration(s) of the class(es): *
* IHandler - Base window event handler class. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or *
* disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IVBASE_
#include <ivbase.hpp>
#endif
#ifndef _IEVENT_
#include <ievent.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class IString;
class IWindow;
class IHandler : public IVBase {
typedef IVBase
Inherited;
/*******************************************************************************
* The IHandler class is an abstract base for window event handlers. Derived *
* classes are written to handle specific window events (Presentation Manager *
* window messages). Windows (or the objects that create windows) add *
* instances of these handler classes to themselves by using the *
* IWindow::addHandler function. Handlers can also be added to windows by *
* using the IHandler::handleEventsFor function. *
* *
* Multiple handlers can be added to a given window. The handlers are called *
* in turn until one of them indicates that further handlers are not to be *
* called. This is achieved by the handler returning true from its *
* dispatchHandlerEvent function. If none of the handlers returns true, then *
* the original window procedure for the underlying Presentation Manager *
* window is called. *
* *
* The handler that handles a given event is also responsible for setting the *
* appropriate event result. This is done by using the IEvent::setResult *
* function. In general, a handler that returns true from dispatchHandlerEvent *
* must call IEvent::setResult on the event passed to it. This result will *
* be returned to the sender of the Presentation Manager message. *
* *
* Handlers can be detached from windows by using either the *
* IWindow::removeHandler or the IHandler::stopHandlingEventsFor function. *
* Care must be taken to detach the handler from the windows it is handling *
* prior to destroying the handler object. Typically, a window will remove *
* its handlers in its destructor. *
* *
* Handlers can be disabled to suppress their handling of events without *
* removing them from the window handler chain. *
* *
* Example: *
* // MyControl is a control with a MyHandler attached. *
* class MyControl : public IControl { *
* MyHandler *
* handler; *
* public: *
* MyControl :: MyControl ( ) *
* : IControl( ) *
* { *
* this->handler.handleEventsFor( this ); *
* } *
* ~MyControl ( ) *
* { *
* this->handler.stopHandlingEventsFor( this ); *
* } *
* }; *
*******************************************************************************/
public:
/*----------------------------- Constructor/Destructor -------------------------
| This is an abstract base class, so the constructor can only be called from |
| the constructors of derived classes. The constructor accepts no arguments |
| and simply initializes the handler in an enabled state. |
------------------------------------------------------------------------------*/
IHandler();
~IHandler();
/*---------------------------- Enabling/Disabling ------------------------------
| These functions deal with enabling and disabling the handler: |
| enable - Enables the handler, by default. It accepts an optional |
| Boolean argument that, when false, causes the handler to be |
| disabled. |
| disable - Disables the handler so that it processes no window events. |
| isEnabled - Returns whether the handler is currently enabled. |
------------------------------------------------------------------------------*/
virtual IHandler
&enable ( Boolean setting = true ),
&disable ( );
Boolean
isEnabled ( ) const;
/*---------------------------- Window Attachment -------------------------------
| These functions permit attaching and detaching the handler object to/from |
| a given window: |
| handleEventsFor - Attaches the handler to the argument IWindow |
| object. |
| stopHandlingEventsFor - Detaches the handler from the argument IWindow |
| object. |
------------------------------------------------------------------------------*/
virtual IHandler
&handleEventsFor ( IWindow *window ),
&stopHandlingEventsFor ( IWindow *window );
/*------------------------------- Diagnostics ----------------------------------
|The following functions provide diagnostic information: |
| asString - Returns IHandler(enabled) or IHandler(disabled). |
| asDebugInfo - Returns diagnostic information about the handler. |
------------------------------------------------------------------------------*/
virtual IString
asString ( ) const,
asDebugInfo ( ) const;
protected:
/*------------------------------ Event Handling --------------------------------
| The following functions provide information about handling events: |
| dispatchHandlerEvent - Called (from IWindow) when a window event occurs. |
| A given handler should return true if dispatching |
| the event to other handles should not occur. In |
| such cases, a result must be placed in the |
| argument IEvent object. |
| defaultProcedure - Sends the argument IEvent object to the original |
| window procedure for the underlying Presentation |
| Manager window. |
------------------------------------------------------------------------------*/
virtual Boolean
dispatchHandlerEvent ( IEvent &evt ) = 0;
virtual IEventResult
defaultProcedure ( IEvent &evt );
private: /*------------------------ PRIVATE ----------------------------------*/
friend IWindow;
Boolean
active;
unsigned
numWindows;
}; // class IHandler
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <ihandler.inl>
#endif
#endif // _IHANDLER_