home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 4.3 KB | 144 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWKeyF.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWKEYF_H
- #include "FWKeyF.h"
- #endif
-
- #ifndef FWEVENTH_H
- #include "FWEventH.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWEVEDEF_H
- #include "FWEveDef.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWSView.h"
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwevents
- #endif
-
- //========================================================================================
- // Macros
- //========================================================================================
-
- #define FW_ISNUMBER(c) (c >= '0' && c <= '9')
- #define FW_ISLETTER(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
-
- #ifdef FW_BUILD_MAC
- #define FW_ISBACKSPACE(c) (c == 0x08)
- #define FW_ISARROWKEY(c) (c == 0x1c || c == 0x1d || c == 0x1e || c == 0x1f)
- #endif
-
- #ifdef FW_BUILD_WIN
- // On windows these are handled as Virtual Keys
- #define FW_ISBACKSPACE(c) FALSE
- #define FW_ISARROWKEY(c) FALSE
- #endif
-
- //========================================================================================
- // CLASS FW_CAlphaNumFilter
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CAlphaNumFilter, FW_MEventHandler)
-
- //----------------------------------------------------------------------------------------
- // FW_CAlphaNumFilter::FW_CAlphaNumFilter
- //----------------------------------------------------------------------------------------
-
- FW_CAlphaNumFilter::FW_CAlphaNumFilter(Environment* ev, FW_MEventHandler* parent)
- : FW_MEventHandler()
- {
- parent->AdoptEventHandler(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAlphaNumFilter::~FW_CAlphaNumFilter
- //----------------------------------------------------------------------------------------
-
- FW_CAlphaNumFilter::~FW_CAlphaNumFilter()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAlphaNumFilter::DoCharKey
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CAlphaNumFilter::DoCharKey(Environment* ev, const FW_CCharKeyEvent& keyEvent)
- {
- char c = keyEvent.GetChar(ev);
-
- // Allow backspace and arrow keys
- if (FW_ISBACKSPACE(c) || FW_ISARROWKEY(c))
- return FW_kNotHandled;
-
- // Allow only 0-9 a-z A-Z characters
- if (FW_ISNUMBER(c) || FW_ISLETTER(c))
- return FW_kNotHandled;
- else
- return FW_kHandled;
- }
-
- //========================================================================================
- // CLASS FW_CIntegerFilter
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CIntegerFilter, FW_MEventHandler)
-
- //----------------------------------------------------------------------------------------
- // FW_CIntegerFilter::FW_CIntegerFilter
- //----------------------------------------------------------------------------------------
-
- FW_CIntegerFilter::FW_CIntegerFilter(Environment* ev, FW_MEventHandler* parent)
- : FW_MEventHandler()
- {
- parent->AdoptEventHandler(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CIntegerFilter::~FW_CIntegerFilter
- //----------------------------------------------------------------------------------------
-
- FW_CIntegerFilter::~FW_CIntegerFilter()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CIntegerFilter::DoCharKey
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CIntegerFilter::DoCharKey(Environment* ev, const FW_CCharKeyEvent& keyEvent)
- {
- char c = keyEvent.GetChar(ev);
-
- // Allow backspace and arrow keys
- if (FW_ISBACKSPACE(c) || FW_ISARROWKEY(c))
- return FW_kNotHandled;
-
- // Allow only 0-9 characters
- if (FW_ISNUMBER(c))
- return FW_kNotHandled;
- else
- return FW_kHandled;
- }
-
-