home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IKEYHDR.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
12KB
|
172 lines
#ifndef _IKEYHDR_
#define _IKEYHDR_
/*******************************************************************************
* FILE NAME: ikeyhdr.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IKeyboardHandler - Process a keyboard event for a window. *
* *
* 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 _IHANDLER_
#include <ihandler.hpp>
#endif
#ifndef _IKEYEVT_
#include <ikeyevt.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
// Forward declarations for other classes:
class IEvent;
class IKeyboardHandler : public IHandler {
typedef IHandler
Inherited;
/*******************************************************************************
* Instances of the IKeyboardHandler class can be used to process all types of *
* keyboard events. These events include: *
* - Key presses and releases *
* - Character code, hardware scan code, and virtual key events *
* - Single- or double-byte characters. *
* *
* An IKeyboardHandler object can be attached to any kind of window. While *
* the control or window with the input focus will be the first to receive a *
* keyboard event, any event that is passed on for additional processing is *
* dispatched to the owner window of the focus window. *
* *
* A keyboard event continues to travel up the owner window chain until either *
* a handler stops it or the key is processed by the window itself. As a *
* result, an IKeyboardHandler object should not stop the processing of any *
* key events that it does not understand because the key has the potential of *
* being handled by any window in the owner chain, such as the frame window. *
* *
* When an IKeyboardHandler object receives a keyboard event, the *
* IKeyboardHandler object creates an IKeyboardEvent object and routes it to *
* the following virtual functions as appropriate: *
* *
* scanCodeKeyPress - For key press events with a scan code value. *
* virtualKeyPress - For key press events with a virtual key value. *
* characterKeyPress - For key press events with a character code value. *
* key - For any and all key events. *
* *
* You should override one or more virtual functions to supply your own *
* processing of a keyboard event. If any of the above virtual functions *
* indicates that the key event requires no additional processing, the key *
* event is not passed to any additional virtual functions of the *
* IKeyboardHandler object, and it is not passed on to any other handlers. *
* The return value from a virtual function is intrepreted as follows: *
* *
* Value Meaning *
* --------------- *
* true - The IKeyboardEvent requires no additional processing and should *
* not be passed on to another handler. *
* false - The IKeyboardEvent should be passed on for additional processing *
* when the following situations occur: *
* -- If the key event is appropriate for another virtual function *
* in the IKeyboardHandler, the key event is passed to that *
* virtual function. (The virtual functions are called in the *
* order listed above.) *
* -- If there is another handler for the window, the event is *
* passed on to the next handler. *
* -- If this is the last handler for a window, the event is passed *
* on a call to the window's defaultProcedure function. (See *
* IWindow::defaultProcedure.) This could result in the event *
* being dispatched to the window's owner window, where the *
* processing of the keyboard event starts again. *
* *
* Example: *
* MyWindow::MyWindow() *
* : ... *
* { *
* MyNumericKeyHandler* keyhNumeric = new MyNumericKeyHandler(); *
* ... *
* IEntryField* efNum = new IEntryField(ID_EF, this, this, IRectangle(...));*
* keyhNumeric->handleEventsFor(efNum); *
* ... *
* show(); *
* } *
* Boolean MyNumericKeyHandler::characterKeyPress(IKeyboardEvent& kbdevt) *
* { *
* Boolean bRc = true; // assume non-numeric key *
* IString strChar = keyevt.mixedCharacter(); *
* if (strChar.length() == 1) *
* { // single-byte character *
* switch (keyevt.character()) *
* { *
* case '0': *
* ... *
* case '9': *
* { // let cases for 0 - 9 fall through to here *
* bRc = false; // let this valid key go through *
* break; *
* } *
* default: *
* break; *
* } *
* } *
* if (bRc == true) *
* { // not 0 - 9 *
* DosBeep(50, 50); // inform the user and eat the key *
* } *
* return bRc; *
* } *
*******************************************************************************/
public:
/*------------------------ Constructor/Destructor ------------------------------
| The only way to construct instances of this class is to use the default |
| constructor, which does not take any arguments. |
------------------------------------------------------------------------------*/
IKeyboardHandler ( );
virtual
~IKeyboardHandler ( );
protected:
/*---------------------------- Event Dispatching -------------------------------
| This function evaluates the event to determine if it is appropriate for |
| this handler object to process. If it is, this function calls the virtual |
| function used to process the event. |
| dispatchHandlerEvent - Calls the appropriate virtual function or |
| functions to process a keyboard event. |
------------------------------------------------------------------------------*/
virtual Boolean
dispatchHandlerEvent ( IEvent& event );
/*----------------------------- Event Processing -------------------------------
| At least one of these functions should be supplied by a derived class to |
| process a keyboard event (note that some events can be routed to more than |
| one of these virtual functions): |
| scanCodeKeyPress - Implemented by derived classes to handle scan code |
| key presses. |
| virtualKeyPress - Implemented by derived classes to handle virtual key |
| presses. |
| characterKeyPress - Implemented by derived classes to handle character |
| key presses. |
| key - Implemented by derived classes to handle any and all |
| unprocessed key events. |
------------------------------------------------------------------------------*/
virtual Boolean
scanCodeKeyPress ( IKeyboardEvent& event ),
virtualKeyPress ( IKeyboardEvent& event ),
characterKeyPress ( IKeyboardEvent& event ),
key ( IKeyboardEvent& event );
}; // IKeyboardHandler
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#endif /* _IKEYHDR_ */