KeyPress Class Reference

Encapsulates key presses in camelot. More...

#include <keypress.h>

List of all members.

Public Member Functions

 KeyPress (KeyPressSysMsg *pKeySysMsg, WCHAR UnicodeChar)
 Constructs a KeyPress object from the given parameters.
 KeyPress (UINT32 VirtKey, BOOL PlusAdjust=FALSE, BOOL PlusConstrain=FALSE, BOOL PlusAlternative=FALSE, BOOL ExtendedKey=FALSE, BOOL WorksInDragsKey=FALSE)
 Constructs a KeyPress object from the given parameters This constructor is for use by systems that deal with "hot keys", i.e. ones that are only interested in the physical key that is being pressed.
 KeyPress (const KeyPress &c)
BOOL IsValid ()
 Allows you to see if the KeyPress is legal. The default KeyPress constuctor will always create invalid instances. It is up to other constructors, or member functions, to generate valid ones.
UINT32 GetVirtKey ()
WCHAR GetUnicode ()
BOOL IsAdjust ()
BOOL IsConstrain ()
BOOL IsAlternative ()
BOOL IsOption ()
BOOL IsModified ()
BOOL IsExtended ()
BOOL IsRepeat ()
BOOL IsRightHand ()
BOOL IsRelease ()
BOOL IsChar ()
BOOL IsPress ()
BOOL IsOkInDrags ()
INT32 operator== (const KeyPress &)
 KeyPress == operator Two KeyPress objects are equal if 1) They have the same virtual key code 2) Have the same modifier settings 3) Have the same extended flag settings 4) Have the same validity (i.e. both valid OR both invalid).

Static Public Member Functions

static BOOL Init ()
 Initialises the KeyPress class.
static FilePath GetHotKeysFilename ()
static BOOL DispatchKeyEvent (UINT32 nMsgID, UINT32 nChar, UINT32 nRepCnt, UINT32 nFlags)
 Packages an MFC key-stroke message into a form suitable for the kernel and calls the keyboard system with the event.
static BOOL TranslateMessage (wxKeyEvent *pMsg)
 Called from a low-level PreTranslateMessage() routine to allow key presses to be processed If it is a key press message, it generates a KeyPress object and sends it off to Application::OnKeyPress().
static void ResetModifierKeys ()
 Maintain integrity of our key modifier status. Win32S doesn't always tell us what key events have occured - notably when the user uses Alt-TAB to switch tasks. Hence this gets called whenever our main window is deactivated or activated. The temporary tool is updated if required.
static BOOL GenerateCharMessage (wxKeyEvent *pMsg)
 This tries to see if the keypress message can generate a WM_CHAR message.
static BOOL IsAdjustPressed ()
 Tests status of the "Adjust" key.
static BOOL IsConstrainPressed ()
 Tests status of the "Constrain" key.
static BOOL IsAlternativePressed ()
 Tests status of the "Alternative" key.
static BOOL IsEscapePressed ()
 Lets you see if an escape key combination is currently being pressed, or has been pressed since the last call to this routine.
static BOOL IsKeyPressed (UINT32 VirtKey)
 General async keypress func call.
static BOOL ModifierChanged ()
static BOOL IsGalleryShiftPressed (void)
 Tests status of the "Gallery Shift" key This is a special method for use by galleries, which must emulate the action of windows list boxes. "Gallery Shift" is the key used to select multiple items at once.
static BOOL IsGalleryCtrlPressed (void)
 Tests status of the "Gallery Ctrl" key This is a special method for use by galleries, which must emulate the action of windows list boxes. "Gallery Ctrl" is the key used to add/remove single items to/from a selection.
static KeyPressConstructVK (TCHAR ch)
 Constructs a keypress that represents the keypress required to generate the specified character. The Virtual Code will be CAMKEY(CC_NONE) if the key cannot be generated.
static BOOL AddVirtualKeyCode (UINT32 VCode, WCHAR Unicode)
 Adds the given virtual key code to the list that Camelot knows about and send around internally (rather than ignoring).
static void RemoveVirtualKeyCode (UINT32 VCode, WCHAR Unicode)
 Removes the given virtual key code that generates the givne unicode value from the list of additional virtual key codes. Only the first occurace is removed.

Private Member Functions

 CC_DECLARE_MEMDUMP (KeyPress)
 KeyPress ()
 Default constructor. Creates an invalid keypress object. The KeyPress class will have one or more public constructors or static member functions for creating valid KeyPress objects.
void Initialise ()
 Initialises all member variables of the KeyPress object to sensible values.

Static Private Member Functions

static BOOL GenerateKeyPress (wxKeyEvent *pMsg, KeyPress **ppKeyPress)
 Generates a legal, platform-independent key press object from the raw platform-dependent data provided.
static INT32 GenerateUnicode (UINT32 VirtKey, UINT32 ScanCode, BYTE *pKeyState, WCHAR *pWideCharBuf, UINT32 WideCharBufSize)
 Converts a virtual key code into a Unicode char. This is a layer on top of the Windows ToUnicode() function that will generate Unicodes in the corporate user zone for keys that do not have a standard Unicode evivalent (e.g. function keys).
static BOOL IgnoreKeyMessage (KeyPressSysMsg *pKeySysMsg)
 This filters out any invalid key messages that we may get from Windows, such as auto-repeated modifier (shift, ctrl, alt) keys.
static BOOL IsModifier (UINT32 VirtKey)
 Central modifier key identifying routine. The modifiers are as follows : Both Alt keys Both Shift keys Both Ctrl keys.
static void UpdateModifierStatus (KeyPressSysMsg *pKeySysMsg)
 If the message is a modifier key press, the static status vars for the modifier keys in the KeyPress class are updated.
static KeyPressMakeKeyPress (KeyPressSysMsg *pKeySysMsg)
 Makes a KeyPress from a KeyPressSysMsg.
static BOOL EscapePressed (KeyPress *pKeyPress)
 Deals with an Escape key press.

Private Attributes

UINT32 VirtKey
WCHAR Unicode
BOOL Adjust: 1
BOOL Constrain: 1
BOOL Alternative: 1
BOOL Option: 1
BOOL Extended: 1
BOOL Repeat: 1
BOOL RightHand: 1
BOOL Release: 1
BOOL m_fIsChar: 1
BOOL Valid: 1
BOOL WorksInDrag: 1

Static Private Attributes

static BOOL AdjustStateLeft = FALSE
static BOOL AdjustStateRight = FALSE
static BOOL ConstrainStateLeft = FALSE
static BOOL ConstrainStateRight = FALSE
static BOOL AlternativeStateLeft = FALSE
static BOOL AlternativeStateRight = FALSE
static BOOL OptionStateLeft = FALSE
static BOOL OptionStateRight = FALSE
static BOOL fModifierChanged = FALSE
static INT32 AsciiVal = -1
static BOOL ValidAsciiVal = FALSE
static BYTE LastLeadByte = 0
static List AdditionalVirtKeys


Detailed Description

Encapsulates key presses in camelot.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/94

Definition at line 187 of file keypress.h.


Constructor & Destructor Documentation

KeyPress::KeyPress KeyPressSysMsg pKeySysMsg,
WCHAR  UnicodeChar
 

Constructs a KeyPress object from the given parameters.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
pKeySysMsg = Ptr to a platform indepenent version of a Windows key press message [INPUTS] UnicodeChar = The Unicode char this key press should have
- [OUTPUTS]
Returns:
-

Errors: -

See also:
KeyPress::IsValid, KeyPress::GenerateKeyPress

Definition at line 516 of file keypress.cpp.

00517 {
00518     VirtKey     = pKeySysMsg->VirtKey;
00519     Unicode     = UnicodeChar;
00520 
00521     Adjust      = KeyPress::AdjustStateLeft      | KeyPress::AdjustStateRight;
00522     Constrain   = KeyPress::ConstrainStateLeft   | KeyPress::ConstrainStateRight;
00523     Alternative = KeyPress::AlternativeStateLeft | KeyPress::AlternativeStateRight;
00524     Option      = KeyPress::OptionStateLeft      | KeyPress::OptionStateRight;
00525 
00526     Extended    = pKeySysMsg->Extended;
00527 
00528     // Interpret Alt+Ctrl as Extended Alt, because AltGr (UK right hand Alt) produces an additional 
00529     // Ctrl key press that is indistinguishable from a left hand Ctrl.
00530     // This means that left hand Alt+Ctrl will appear the same as right hand AltGr to Camelot.
00531     // E.g. Alt+Ctrl+Spacebar == AltGr+Spacebar
00532     if (Alternative && Constrain)
00533     {
00534         Extended  = TRUE;
00535         Constrain = FALSE;
00536     }
00537 
00538     Repeat      = pKeySysMsg->PrevDown;
00539     RightHand   = pKeySysMsg->Extended;
00540     Release     = (pKeySysMsg->Message == KM_KEYUP);
00541     m_fIsChar   = (pKeySysMsg->Message == KM_CHAR);
00542 
00543     Valid       = TRUE;     // This is now a valid KeyPress object.
00544 }

KeyPress::KeyPress UINT32  ThisVirtKey,
BOOL  PlusAdjust = FALSE,
BOOL  PlusConstrain = FALSE,
BOOL  PlusAlternative = FALSE,
BOOL  ExtendedKey = FALSE,
BOOL  WorksInDragsKey = FALSE
 

Constructs a KeyPress object from the given parameters This constructor is for use by systems that deal with "hot keys", i.e. ones that are only interested in the physical key that is being pressed.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/8/94
Parameters:
ThisVirtKey = The virtual key code of the key you want to use [INPUTS] PlusAdjust = TRUE if the key should be modified by the Adjust key PlusConstrain = TRUE if the key should be modified by the Constrain key PlusAlternative = TRUE if the key should be modified by the Alternative key ExtendedKey = TRUE if you are specifying an extended key (e.g. "Enter" key instead of "Return") WorksInDragsKey = TRUE if you want this keypress to work in the middle of drags.
- [OUTPUTS]
Returns:
-

Errors: -

See also:
KeyPress::IsValid, KeyPress::GenerateKeyPress

Definition at line 572 of file keypress.cpp.

00574 {
00575     Initialise();
00576 
00577     VirtKey     = ThisVirtKey;
00578     Adjust      = PlusAdjust;
00579     Constrain   = PlusConstrain;
00580     Alternative = PlusAlternative;
00581     Extended    = ExtendedKey;
00582     WorksInDrag = WorksInDragsKey;
00583     Valid       = TRUE;
00584 }

KeyPress::KeyPress const KeyPress c  )  [inline]
 

Definition at line 218 of file keypress.h.

00218                                : // Copy constructor as CCObject's is private which prevents synthesis working
00219         VirtKey(c.VirtKey), Unicode(c.Unicode), Adjust(c.Adjust), Constrain(c.Constrain),
00220         Alternative(c.Alternative), Option(c.Option), Extended(c.Extended), Repeat(c.Repeat),
00221         RightHand(c.RightHand), Valid(c.Valid) {}

KeyPress::KeyPress  )  [private]
 

Default constructor. Creates an invalid keypress object. The KeyPress class will have one or more public constructors or static member functions for creating valid KeyPress objects.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
KeyPress::IsValid, KeyPress::GenerateKeyPress

Definition at line 495 of file keypress.cpp.

00496 {
00497     Initialise();
00498 }


Member Function Documentation

BOOL KeyPress::AddVirtualKeyCode UINT32  VCode,
WCHAR  Unicode
[static]
 

Adds the given virtual key code to the list that Camelot knows about and send around internally (rather than ignoring).

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/10/95
Parameters:
VCode - the virtual key code to add [INPUTS] Unicode - the unicode value generated when this key is pressed
- [OUTPUTS]
Returns:
TRUE/FALSE for success/failure

Errors: -

See also:
-

Definition at line 1789 of file keypress.cpp.

01790 {
01791     // Construct a list item
01792     AdditionalVirtKey* pNew = new AdditionalVirtKey;
01793 
01794     if (pNew != NULL)
01795     {
01796         pNew->VirtualKeyCode = VCode;
01797         pNew->UnicodeValue = Unicode;
01798 
01799         AdditionalVirtKeys.AddHead(pNew);
01800     }
01801 
01802     return (pNew != NULL);
01803 }

KeyPress::CC_DECLARE_MEMDUMP KeyPress   )  [private]
 

KeyPress * KeyPress::ConstructVK TCHAR  ch  )  [static]
 

Constructs a keypress that represents the keypress required to generate the specified character. The Virtual Code will be CAMKEY(CC_NONE) if the key cannot be generated.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/10/95
Parameters:
ch - ASCII/Unicode value of required keypress [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 604 of file keypress.cpp.

00605 {
00606 //  PORTNOTETRACE( "other", "KeyPress::ConstructVK - do nothing" );
00607     KeyPress* pNew = new KeyPress();
00608 
00609 #if !defined(EXCLUDE_FROM_XARALX)
00610     if (pNew != NULL)
00611     {
00612         INT8 Result = ::VkKeyScan(ch);
00613         BYTE LowByte = Result & 0xFF;
00614         BYTE HighByte = (Result >> 8) & 0xFF;
00615 
00616         if ((HighByte == 0xFF) && (LowByte == 0xFF))
00617         {
00618             pNew->VirtKey = CAMKEY(CC_NONE);
00619         }
00620         else
00621         {
00622             pNew->VirtKey = LowByte;
00623             pNew->Adjust = HighByte & 1;
00624             pNew->Constrain = HighByte & 2;
00625             pNew->Alternative   = HighByte & 4;
00626         }
00627     }
00628 #endif
00629     
00630     return pNew;
00631 }

BOOL KeyPress::DispatchKeyEvent UINT32  nMsgID,
UINT32  nChar,
UINT32  nRepCnt,
UINT32  nFlags
[static]
 

Packages an MFC key-stroke message into a form suitable for the kernel and calls the keyboard system with the event.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/10/94
Parameters:
nMsgID the Windows ID of the key message, eg. WM_KEYDOWN [INPUTS] nChar the virtual key code / char value (depending on you believe) nRepCnt repeat count nFlags keyboard state flags, eg. key down or up
- [OUTPUTS]
Returns:
TRUE if the app processed the event.

Errors: -

See also:
KeyPress::TranslateMessage

Definition at line 454 of file keypress.cpp.

00455 {
00456     // Make sure the kernel knows which view/doc the event applies to, if any.
00457     if (Document::GetSelected() != NULL) Document::GetSelected()->SetCurrent();
00458     if (DocView::GetSelected() != NULL)  DocView::GetSelected()->SetCurrent();
00459 
00460 PORTNOTETRACE("other,", "BaseTextClass::PreOpProcessing - do nothing" );
00461 #ifndef EXCLUDE_FROM_XARALX
00462     // For compatibility with existing code we must repackage the unpacked message.
00463     // NB. the RHS of the lParam expression will work for Win16 as well.
00464     MSG msg;
00465     msg.message = nMsgID;
00466     msg.wParam  = nChar;
00467     msg.lParam  = (nRepCnt & 0xFFFF) | ((((LPARAM) nFlags) & 0xFFFF) << 16);
00468     
00469     // Call the key-press system.
00470     return TranslateMessage(&msg);
00471 #else
00472     return true;
00473 #endif
00474 }

BOOL KeyPress::EscapePressed KeyPress pKeyPress  )  [static, private]
 

Deals with an Escape key press.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/9/94
Parameters:
pKeyPress = ptr to a key press [INPUTS]
- [OUTPUTS]
Returns:
TRUE - the key was an escape event (e.g. Escape, Break, etc) FALSE - the key was not an escape key, nothing happened
If the key press was NOT an escape key, (i.e. not Escape or Ctrl+Pause (Break)), nothing happens, and FALSE is returned

if it was an escape key press, it is processed in a relevent way At the moment, this just means that the current drag is terminated, if there is one.

If it's an escape key press, and it was acted upon (e.g. a drag was terminated), TRUE is returned. Otherwise FALSE is returned

See also:

Definition at line 1447 of file keypress.cpp.

01448 {
01449     ENSURE(pKeyPress->IsValid(),"Invalid KeyPress given");
01450 
01451     BOOL Processed = FALSE;
01452     UINT32 VirtKey = pKeyPress->GetVirtKey();
01453 
01454     // Only check non-auto-repeat "key down" key presses
01455     if (pKeyPress->IsPress() && !pKeyPress->IsRepeat())
01456     {
01457         if (VirtKey == CAMKEY(ESCAPE) || VirtKey == WXK_CANCEL)
01458         {
01459 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)                       
01460             // MarkN I've moved this code in an attempt to stop the selection being
01461             // cleared after a bar drag cancel - Chris.
01462             if (!Processed)
01463                 Processed = BaseBar::EscPressed(TRUE);
01464 
01465             // cancel any drag manager drags (and say that we have done so!!!)
01466             // stops the selection being cleared when you cancel a
01467             // colour or sprite (or any) DragManagerOp drag
01468             if(!Processed && DragManagerOp::GetCurrentManager() != NULL)
01469             {
01470                 DragManagerOp::AbortDrag();
01471                 Processed = TRUE;
01472             }
01473 #endif
01474 
01475             if (!Processed && Operation::GetCurrentDragOp() != NULL)
01476             {
01477                 OilCoord PointerPos(0,0);
01478                 ClickModifiers ClickMods;
01479 //              Spread* pSpread = NULL;
01480 
01481                 DocView* pDocView = DocView::GetSelected();
01482                 if (pDocView)
01483                     pDocView->DragFinished(Operation::GetCurrentDragOp(), PointerPos, ClickMods, FALSE);
01484 
01485                 // We've done something with this escape key press so set Processed to TRUE
01486                 // to prevent it from being passed on
01487                 Processed = (Operation::GetCurrentDragOp() == NULL);
01488             }
01489 
01490             if (!Processed && Operation::GetCurrentDragOp() != NULL)
01491             {
01492                 DocCoord PointerPos(0,0);
01493                 ClickModifiers ClickMods;
01494                 Spread* pSpread = NULL;
01495 
01496                 Operation::GetCurrentDragOp()->DragFinished(PointerPos, ClickMods, pSpread, FALSE, FALSE);
01497 
01498                 // We've done something with this escape key press so set Processed to TRUE
01499                 // to prevent it from being passed on
01500                 Processed = TRUE;
01501             }
01502 
01503             // This gives Chris a chance to terminate his bar dragging.  This was necessary as his former
01504             // way of detecting Escape (via KeyMsg broadcasts) no longer works because Escape is now a hot key, and
01505             // as such gets in there before a KeyMsg is broadcast.
01506             // (MarkN 27/4/95)
01507             /*if (!Processed)
01508                 Processed = BaseBar::EscPressed(TRUE);
01509               */
01510             // Throw away all pending key messages
01511 PORTNOTE( "other", "Remove PeekMessage" )
01512 #if !defined(EXCLUDE_FROM_XARALX)                       
01513             MSG msg;
01514             while(PeekMessage( &msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE ))
01515             ;
01516 #endif
01517         }
01518     }
01519 
01520     return Processed;
01521 }

BOOL KeyPress::GenerateCharMessage wxKeyEvent *  pMsg  )  [static]
 

This tries to see if the keypress message can generate a WM_CHAR message.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/3/95
Parameters:
pMsg = A Windows keypress message [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the message was processed FALSE if the message wasn't processed
It does this by trapping numerical key pad entry of the ASCII value of the char while the Alt ky is held down. (e.g. hold down ALT, type '6' then '5' on the num key pad, then release Alt - you should get 'A' appearing at the input focus). If, on a Alt key up event we have a valid ASCII value that's been entered, we post ourselves a WM_CHAR message containing the ASCII char.

We have to do this ourselves because we get less messages generated in Win 3.1 than we do in NT, so the NT solution (act upon the auto generated WM_CHAR message) won't work an all target platforms (pain in the butt or what?). The ideal solution is to find out exactly why we don't get this extra WM_CHAR message in Win3.1, but I've traced paths of key press messages under NT and have found no obvious reason why the Win3.1 should behave differently. As we don't have single stepping technology under Win3.1, it's almost impossible to determine what's going on.

So, the time honoured CC tradition, if the OS doesn't do it, we'll do it ourselves.

Returns:
Errors: -
See also:
KeyPress::TranslateMessage

Definition at line 1556 of file keypress.cpp.

01557 {
01558     BOOL Processed = FALSE;
01559 
01560     // Get the virtual key code for the key pressed
01561     UINT32 VirtKey = pMsg->GetKeyCode();
01562 
01563     //DumpKeyMessage(pMsg);
01564 
01565     if( wxEVT_KEY_DOWN == pMsg->GetEventType() ) 
01566     {
01567         if (VirtKey == CAMKEY(MENU))
01568         {
01569             // Trap ALL Alt key down messages
01570 
01571             if (!KeyPress::ValidAsciiVal)
01572             {
01573                 // Initialise a ASCII value entry
01574                 //TRACE( _T("-*-*-*-- Starting valid ascii val\n"));
01575                 KeyPress::ValidAsciiVal = TRUE;
01576                 KeyPress::AsciiVal      = -1;
01577             }
01578         }
01579         else if (KeyPress::ValidAsciiVal && ((VirtKey < CAMKEY(NUMPAD0)) || (VirtKey > WXK_NUMPAD9)))
01580         {
01581             // If the key down message is not a num pad key between '0' and '9'
01582             // invalidate the ASCII value
01583             //TRACE( _T("-*-*-*-- (keydown) Invalidating ascii val\n"));
01584             KeyPress::ValidAsciiVal = FALSE;
01585         }
01586     }
01587     else
01588     if( wxEVT_KEY_UP == pMsg->GetEventType() ) 
01589     {
01590         if (KeyPress::ValidAsciiVal)
01591         {
01592             // Only try to produce an ASCII value if the last set of key presses has generated
01593             // a valid value
01594 
01595             if (VirtKey == CAMKEY(MENU))
01596             {
01597                 // We've received a Alt key up message, so post ourselves a WM_CHAR message that
01598                 // contains the generated ASCII value
01599 
01600                 if (KeyPress::AsciiVal >= 0)
01601                 {
01602                     // Only post the ASCII value if one's been specified via the Num key pad
01603                     // (i.e. the value >= 0)
01604                     //TRACE( _T("-*-*-*-- Posting WM_CHAR. Val = %ld\n"),KeyPress::AsciiVal);
01605 PORTNOTE("other", "Removed PostMessage usage - WM_CHAR from ascii code" )
01606 #ifndef EXCLUDE_FROM_XARALX
01607                     Processed = ::PostMessage(pMsg->hwnd,WM_CHAR,KeyPress::AsciiVal % 256,1);
01608 #endif
01609                 }
01610                 //TRACE( _T("-*-*-*-- (keyup) Invalidating ascii val. Val = %ld\n"),KeyPress::AsciiVal);
01611                 KeyPress::ValidAsciiVal = FALSE;
01612             }
01613             else if ((VirtKey >= CAMKEY(NUMPAD0)) && (VirtKey <= WXK_NUMPAD9))
01614             {
01615                 // We've got a num key pad key up event
01616                 // We have to do this bit on key up events, because for some reason under NT (and possibly
01617                 // other OSs) we don't get a key down event for the first key that's pressed while the
01618                 // Alt key is auto-repeating (wierd - any ideas welcome)
01619 
01620                 // If this is the first one (i.e. ASCII val is currently < 0), reset the value to 0
01621                 if (KeyPress::AsciiVal < 0)
01622                     KeyPress::AsciiVal = 0;
01623 
01624                 // Shift the current value up, and add in the digit of the num key pad key.
01625                 KeyPress::AsciiVal = ((KeyPress::AsciiVal*10)+(VirtKey-CAMKEY(NUMPAD0)));
01626 
01627                 // We've processed this key press
01628                 Processed = TRUE;
01629 
01630                 //TRACE( _T("-*-*-*-- ascii val digit received. Val = %ld\n"),KeyPress::AsciiVal);
01631             }
01632         }
01633     }
01634 
01635     return Processed;
01636 }

BOOL KeyPress::GenerateKeyPress wxKeyEvent *  pMsg,
KeyPress **  ppKeyPress
[static, private]
 

Generates a legal, platform-independent key press object from the raw platform-dependent data provided.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/94
Parameters:
pMsg = A Windows message [INPUTS]
*ppKeyPress = ptr to the generated KeyPress object, or NULL if not enough memory [OUTPUTS]
Returns:
TRUE if the message was to do with a key press. FALSE if the message wasn't to do with the keyboard at all & *ppKeyPress is unspecified

Errors: If the virtual key code doesn't have an equivalent Unicode value (either standard, or one that we have allocated to it), then KeyPress::IsValid() will return FALSE.

See also:
KeyPress::IsValid

Definition at line 1109 of file keypress.cpp.

01110 {
01111     // Ensure *ppKeyPress is valid, just in case we have to exit the function early
01112     *ppKeyPress = NULL;
01113 
01114     // Create a platform-indy key press message object
01115     KeyPressSysMsg KeySysMsg(pMsg);
01116 
01117     if (KeySysMsg.IsValid())
01118     {
01119         // If it's a key press message that we can ignore, then ignore it, pretending we have processed it
01120 
01121         if (!IgnoreKeyMessage(&KeySysMsg))
01122         {
01123             // We like the look of this key press event
01124 
01125             // Ensure the modifier key states are up to date
01126             UpdateModifierStatus(&KeySysMsg);
01127 
01128             // Make a KeyPress object
01129             *ppKeyPress = MakeKeyPress(&KeySysMsg);
01130 
01131             // If the mods have changed, and we were able to make a keypress object, send
01132             // a "modifiers have changed message"
01133             if (KeyPress::fModifierChanged && *ppKeyPress != NULL)
01134             {
01135                 BROADCAST_TO_ALL(KeyMsg(KeyMsg::MODIFIERCHANGED,*ppKeyPress));
01136             }
01137         }
01138 
01139 #ifdef _DEBUG
01140 /*
01141         if (*ppKeyPress != NULL)
01142         {
01143             char s[1000];
01144             _stprintf(s,"Mess = %d, Virtkey = 0x%lx, Ext = %d, PrevD = %d, Shift = %d, Ctrl = %d, Alt = %d, AShift = 0x%x, ACtrl = 0x%x, AAlt = 0x%x, IsAd = %d, IsCon = %d, IsAlt = %d",
01145             KeySysMsg.Message,
01146             KeySysMsg.VirtKey,
01147             KeySysMsg.Extended,
01148             KeySysMsg.PrevDown,
01149             KeyPress::AdjustStateLeft | KeyPress::AdjustStateRight,
01150             KeyPress::ConstrainStateLeft | KeyPress::ConstrainStateRight,
01151             KeyPress::AlternativeStateLeft | KeyPress::AlternativeStateRight,
01152             AsyncShift,
01153             AsyncCtrl,
01154             AsyncAlt,
01155             (*ppKeyPress)->IsAdjust(),
01156             (*ppKeyPress)->IsConstrain(),
01157             (*ppKeyPress)->IsAlternative()
01158             );
01159             ENSURE(FALSE,s);
01160         }
01161   */
01162         //DumpKeyMessage(pMsg);
01163 
01164 #endif // _DEBUG
01165 
01166         // Return TRUE to say that it really was a keyboard message
01167         return TRUE;
01168     }
01169     else
01170         return FALSE;   // Not a keybaord type event that we're interested in
01171 }

INT32 KeyPress::GenerateUnicode UINT32  VirtKey,
UINT32  ScanCode,
BYTE *  pKeyState,
WCHAR pWideCharBuf,
UINT32  WideCharBufSize
[static, private]
 

Converts a virtual key code into a Unicode char. This is a layer on top of the Windows ToUnicode() function that will generate Unicodes in the corporate user zone for keys that do not have a standard Unicode evivalent (e.g. function keys).

> static INT32 KeyPress::GenerateUnicode(UINT32 VirtKey,UINT32 ScanCode,BYTE* pKeyState,WCHAR* pWideCharBuf,INT32 WideCharBufSize)

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/8/94
Parameters:
VirtKey = a Windows virtual key code [INPUTS] ScanCode = the scan code generated by the keyboard pKeyState = 256 byte array filled with the current keyboard state via GetKeyboardState pWideCharBuf = buffer to stick the Unicode char(s) into WideCharBufSize = the size of the wide char buffer (min value of 2)
pWideCharBuf will contain 1 WCHAR at index [0] [OUTPUTS]
Returns:
The number of Unicode chars generated (see the Windows ToUnicode() function)
If the internal call to ToUnicode() fails, but the VirtKey is an alphabetic key, a Unicode code is generated that is equivalent to pressing Ctrl+<alphabetic key>="">, e.g. Ctrl+A = 1, Ctrl+B = 2. This happens when you press Ctrl+Alt+<alphabetic key>="">, which is only really used by the hot key system, so therefore the actual unicode code is not significant (correct at time of writing - Markn 11/1/95)
Returns:
Errors: -
See also:
KeyPress::IsValid

Definition at line 749 of file keypress.cpp.

00750 {
00751 #if defined(__WXMSW__)
00752     // Make sure we have a buffer to use
00753     ENSURE(WideCharBufSize >= 2,"The wide char buffer size should be at least 2");
00754     if (WideCharBufSize < 2) return 0;
00755 
00756     INT32 NumChars = ToUnicode(VirtKey,ScanCode,pKeyState,pWideCharBuf,WideCharBufSize,0);
00757 
00758     // NumChars == 0 if ToUnicode() failed to generate a code for the keypress
00759 
00760     // If no direct eqivalent Unicode char, see if we can generate one with the ASCII value for the VirtKey
00761     // or look one up in our extra Unicode table
00762     if (NumChars == 0)
00763     {
00764         WORD pWordBuf[10];
00765 
00766         // See if ToAscii() can make a Latin I ASCII char out of it
00767         INT32 NumASCIIChars = ToAscii(VirtKey,ScanCode,pKeyState,pWordBuf,0);
00768 
00769         if (NumASCIIChars == 1)
00770         {
00771             // Map the lower byte ASCII value onto the equivalent Unicode char
00772             pWideCharBuf[0] = pWordBuf[0] & 0xff;
00773             NumChars = 1;
00774         }
00775     }
00776 
00777     if (NumChars == 0)
00778     {
00779         // ToAscii() failed, so lets have a look in our table
00780 
00781         INT32 i=0;
00782         BOOL finished = FALSE;
00783 
00784         do
00785         {
00786             // We've finished if we've reached the ungeneratable VK code
00787             finished = (ExtraUnicodes[i].VirtKey == CAMKEY(CC_NONE));
00788 
00789             if (!finished && ExtraUnicodes[i].VirtKey == VirtKey)
00790             {
00791                 // We have found an entry in our table for the given virtual key
00792 
00793                 // Stuff the Unicode value into the buffer and set the num chars generated to 1
00794                 pWideCharBuf[0] = ExtraUnicodes[i].Unicode;
00795                 NumChars = 1;
00796                 finished = TRUE;
00797             }
00798             i++;
00799         } while (!finished);
00800 
00801         // Check the runtime list too
00802         if (NumChars != 1)
00803         {
00804             finished = FALSE;
00805             AdditionalVirtKey* pKey = (AdditionalVirtKey*)AdditionalVirtKeys.GetHead();
00806             while (!finished && (pKey != NULL))
00807             {
00808                 if (pKey->VirtualKeyCode == VirtKey)
00809                 {
00810                     pWideCharBuf[0] = pKey->UnicodeValue;
00811                     NumChars = 1;
00812                     finished = TRUE;
00813                 }
00814 
00815                 pKey = (AdditionalVirtKey*)AdditionalVirtKeys.GetNext(pKey);
00816             }
00817         }
00818     }
00819 
00820     if (NumChars == 0)
00821     {
00822         // If the virt key is obviously one that should be handled (i.e. an alphabetical key),
00823         // we automatically generate a code.
00824         // This Unicode code will be the same as the one generated by Ctrl+<alphabetical key>
00825         //
00826         // "Why do we need this?" I hear you scream. This is because ToUnicode() fails when you do a 
00827         // Ctrl+Alt+<key>.  As this is an important modifier combo used by the hot key system, we need to make it work.
00828         //
00829         // Markn - 11/1/95
00830 
00831         if (VirtKey >= 'A' && VirtKey <= 'Z')
00832         {
00833             pWideCharBuf[0] = VirtKey - 'A';
00834             NumChars = 1;
00835         }
00836     }
00837 
00838 #ifdef _DEBUG
00839     /*
00840     if (IsUserName("MarkN") && (NumChars == 0))
00841     { 
00842         Beep();
00843         TRACE( _T("\n***\nVirtKey %lx has no Unicode equivalent!\n***\n"),VirtKey); 
00844     }
00845     */
00846 #endif
00847 
00848     // Return the number of Unicode chars that have been dumped into the buffer
00849     return NumChars;
00850 #else
00851     return 0;
00852 #endif
00853 }

FilePath KeyPress::GetHotKeysFilename  )  [static]
 

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/Jun/2006
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
PathName reference to location of hotkeys config file

Definition at line 421 of file keypress.cpp.

00422 {
00423     FilePath result;
00424 
00425     wxStandardPaths     Paths;
00426     wxString    strPath( Paths.GetUserConfigDir() );
00427     strPath += _T("/.xaralx/hotkeys");
00428 
00429     if (wxFile::Exists(strPath))
00430         result.SetPathName(strPath, FALSE);
00431 
00432     return result;
00433 }

WCHAR KeyPress::GetUnicode  )  [inline]
 

Definition at line 230 of file keypress.h.

00230 { return Unicode; } // Returns the unicode char generated by the virtual key

UINT32 KeyPress::GetVirtKey  )  [inline]
 

Definition at line 229 of file keypress.h.

00229 { return VirtKey; } // Returns the virtual key code

BOOL KeyPress::IgnoreKeyMessage KeyPressSysMsg pKeySysMsg  )  [static, private]
 

This filters out any invalid key messages that we may get from Windows, such as auto-repeated modifier (shift, ctrl, alt) keys.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/8/94
Parameters:
pKeySysMsg = Ptr to a platform indepenent version of a Windows key press message [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the key press message should be ignored FALSE if the key press message should be processed

Errors: -

See also:
KeyPress::GenerateKeyPress

Definition at line 873 of file keypress.cpp.

00874 {
00875 //  PORTNOTETRACE( "other", "KeyPress::IgnoreKeyMessage - do nothing" );
00876 
00877     ENSURE(pKeySysMsg->IsValid(),"Invalid KeyPressSysMsg given");
00878 
00879     // Ignore if it's a key down msg, and the key is a modifier, and it's an auto-repeat message
00880     BOOL Ignore = (pKeySysMsg->Message == KM_KEYDOWN && KeyPress::IsModifier(pKeySysMsg->VirtKey) && pKeySysMsg->PrevDown);
00881 
00882 #if !defined(EXCLUDE_FROM_XARALX)
00883     KeyPress* pNew = new KeyPress();
00884     if (UnicodeManager::IsDBCSOS())
00885     {
00886         // handling for DBCS characters; they roll up as two sepearte WM_CHAR messages
00887         if (!Ignore && pKeySysMsg->Message==KM_CHAR)
00888         {
00889             if (LastLeadByte==0 && IsDBCSLeadByte(pKeySysMsg->VirtKey))
00890             {
00891                 // It's a lead byte so store it away for the next message and ignore this one
00892                 TRACE( _T("Lead byte %d\n"), pKeySysMsg->VirtKey);
00893                 LastLeadByte = pKeySysMsg->VirtKey;
00894                 Ignore = TRUE;
00895             }
00896         }
00897     }
00898 #endif
00899     
00900     return Ignore;
00901 }

BOOL KeyPress::Init void   )  [static]
 

Initialises the KeyPress class.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if initialised correctly

Errors: -

See also:
KeyPress::IsValid, KeyPress::GenerateKeyPress

Definition at line 401 of file keypress.cpp.

00402 {
00403     return TRUE;
00404 }

void KeyPress::Initialise  )  [private]
 

Initialises all member variables of the KeyPress object to sensible values.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/10/96
Parameters:
- [INPUTS]
See below [OUTPUTS]
Returns:
-

Errors: -

See also:
KeyPress constructors

Definition at line 649 of file keypress.cpp.

00650 {
00651     // Some highly unlikely Unicode char
00652     Unicode     = 0xffff;
00653 
00654     // A highly unlikely virtual key
00655     VirtKey     = CAMKEY(CC_NONE);
00656 
00657     // Set all the flags to FALSE
00658     Adjust      = FALSE;
00659     Constrain   = FALSE;
00660     Alternative = FALSE;
00661     Option      = FALSE;
00662 
00663     Extended    = FALSE;
00664 
00665     Repeat      = FALSE;
00666     RightHand   = FALSE;
00667     Release     = FALSE;
00668     m_fIsChar   = FALSE;
00669 
00670     // This is an invalid KeyPress object at the moment
00671     Valid       = FALSE;
00672 }

BOOL KeyPress::IsAdjust  )  [inline]
 

Definition at line 233 of file keypress.h.

00233 { return Adjust; }

BOOL KeyPress::IsAdjustPressed  )  [static]
 

Tests status of the "Adjust" key.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/12/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the "Adjust" key is currently depressed.

Errors: -

See also:
-

Definition at line 1225 of file keypress.cpp.

01226 {
01227     return ::wxGetKeyState(CAMKEY(CC_MOD_ADJUST));
01228 }

BOOL KeyPress::IsAlternative  )  [inline]
 

Definition at line 235 of file keypress.h.

00235 { return Alternative; }

BOOL KeyPress::IsAlternativePressed  )  [static]
 

Tests status of the "Alternative" key.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/12/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the "Alternative" key is down.

Errors: -

See also:
-

Definition at line 1265 of file keypress.cpp.

01266 {
01267     return ::wxGetKeyState(CAMKEY(CC_MOD_ALTERNATIVE));
01268 }

BOOL KeyPress::IsChar  )  [inline]
 

Definition at line 243 of file keypress.h.

00243 { return m_fIsChar; }

BOOL KeyPress::IsConstrain  )  [inline]
 

Definition at line 234 of file keypress.h.

00234 { return Constrain; }

BOOL KeyPress::IsConstrainPressed  )  [static]
 

Tests status of the "Constrain" key.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/12/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the "Constrain" key is down.

Errors: -

See also:
-

Definition at line 1245 of file keypress.cpp.

01246 {
01247     return ::wxGetKeyState(CAMKEY(CC_MOD_CONSTRAIN));
01248 }

BOOL KeyPress::IsEscapePressed  )  [static]
 

Lets you see if an escape key combination is currently being pressed, or has been pressed since the last call to this routine.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE - if an escape key is being pressed, or was pressed since the last call to this routine FALSE - no escape key has been pressed
It does a GetAsyncKeyState() on certain key combinations, currently - CAMKEY(ESCAPE) CAMKEY(CANCEL) (Ctrl-Pause, or Break)

GetAsyncKeyState() returns the current key state AND whether the key was pressed since the last call to GetAsyncKeyState().

Note: If TRUE is returned, all pending key messages will have been removed before hand. using PeekMessage(...WM_KEYFIRST,WM_KEYLAST,PM_REMOVE)

See also:

Definition at line 1368 of file keypress.cpp.

01369 {
01370 PORTNOTE("other", "KeyPress::IsEscapePressed - do nothing" )
01371 #ifndef EXCLUDE_FROM_XARALX
01372 //  TRACE( _T("Warning - KeyPress::IsEscapePressed called") );
01373 /*  BOOL EscapePressed = (GetAsyncKeyState(CAMKEY(ESCAPE)) != 0);
01374     BOOL Pressed       = EscapePressed || (GetAsyncKeyState(CAMKEY(CANCEL)) != 0);
01375 
01376     if (Pressed)
01377     {
01378         BOOL EscapeKeyDown = FALSE;
01379 
01380         // Throw away all pending key messages
01381         MSG msg;
01382         while(PeekMessage( &msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE ))
01383         {
01384             // If we the actual Escape key has been pressed, see if we got an Escape Key Down event.
01385             if (EscapePressed)
01386             {
01387                 KeyPressSysMsg KeyMsg(&msg);
01388                 if (KeyMsg.IsValid() && (KeyMsg.Message == KM_KEYDOWN) && (KeyMsg.VirtKey == CAMKEY(ESCAPE)))
01389                     EscapeKeyDown = TRUE;
01390             }
01391         }
01392 
01393         // Alt+Tab Esc fix - i.e. Aborting a task switch via Alt+Tab using the Escape key.
01394         //
01395         // If the actual Escape key has been pressed, only allow it if we have been posted a KeyDown event
01396         // for the Escape key.
01397         // 
01398         // When you do Alt+Tab while in Studio, then hit Escape, unfortunately we get posted an Escape Key Up event
01399         // which also means that the line above that reads "GetAsyncKeyState(CAMKEY(ESCAPE)) != 0" will return TRUE.
01400         // Obviously we want to ignore the Escape key being pressed in this circumstance, but it seems the only way 
01401         // to identify the Escape key press as one we don't want is to see if we *don't* have a corresponding
01402         // key down event.
01403         //
01404         // if (GetAsyncKeyState(CAMKEY(ESCAPE)) != 0)  // i.e. the Escape key has been pressed
01405         // {
01406         //     if (App received a Escape KeyDown message)
01407         //        Legitimate Escape key press, so Pressed = TRUE
01408         //     else
01409         //        Escape hit outside our app, so ignore it
01410         // }
01411 
01412         // If the ActualEscape key has been pressed, then Pressed should only be TRUE if we have received a
01413         // Escape Key Down event.
01414         if (EscapePressed)
01415             Pressed = EscapeKeyDown;
01416     }
01417 
01418     return (Pressed); */
01419 #endif
01420     return false;
01421 }

BOOL KeyPress::IsExtended  )  [inline]
 

Definition at line 239 of file keypress.h.

00239 { return Extended; }

BOOL KeyPress::IsGalleryCtrlPressed void   )  [static]
 

Tests status of the "Gallery Ctrl" key This is a special method for use by galleries, which must emulate the action of windows list boxes. "Gallery Ctrl" is the key used to add/remove single items to/from a selection.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/95
Returns:
TRUE if the "Gallery Ctrl" key is down.
Notes: SHOULD NOT be used outside the gallery system

Definition at line 1332 of file keypress.cpp.

01333 {
01334     return ::wxGetKeyState(CAMKEY(CONTROL));
01335 }

BOOL KeyPress::IsGalleryShiftPressed void   )  [static]
 

Tests status of the "Gallery Shift" key This is a special method for use by galleries, which must emulate the action of windows list boxes. "Gallery Shift" is the key used to select multiple items at once.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/2/95
Returns:
TRUE if the "Gallery Shift" key is down.
Notes: SHOULD NOT be used outside the gallery system

Definition at line 1307 of file keypress.cpp.

01308 {
01309     return ::wxGetKeyState(CAMKEY(SHIFT));
01310 }

BOOL KeyPress::IsKeyPressed UINT32  VirtKey  )  [static]
 

General async keypress func call.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/7/94
Parameters:
VirtKey = key to check [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the VirtKey key is down.

Errors: -

See also:
-

Definition at line 1283 of file keypress.cpp.

01284 {
01285     return ::wxGetKeyState( wxKeyCode(VirtKey) );
01286 }

BOOL KeyPress::IsModified  )  [inline]
 

Definition at line 237 of file keypress.h.

00237 { return (IsAdjust() || IsConstrain() || IsAlternative() || IsOption()); }

BOOL KeyPress::IsModifier UINT32  VirtKey  )  [static, private]
 

Central modifier key identifying routine. The modifiers are as follows : Both Alt keys Both Shift keys Both Ctrl keys.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
VirtKey = A Windows virtual key code [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the key is one of the modifier keys FALSE otherwise

Errors: -

See also:
-

Definition at line 718 of file keypress.cpp.

00719 {
00720     return (VirtKey == CAMKEY(CC_MOD_ADJUST) || VirtKey == WXK_CC_MOD_CONSTRAIN || VirtKey == WXK_CC_MOD_ALTERNATIVE);
00721 }

BOOL KeyPress::IsOkInDrags  )  [inline]
 

Definition at line 245 of file keypress.h.

00245 { return WorksInDrag; }

BOOL KeyPress::IsOption  )  [inline]
 

Definition at line 236 of file keypress.h.

00236 { return Option; }

BOOL KeyPress::IsPress  )  [inline]
 

Definition at line 244 of file keypress.h.

00244 { return !m_fIsChar && !Release; }

BOOL KeyPress::IsRelease  )  [inline]
 

Definition at line 242 of file keypress.h.

00242 { return Release; }

BOOL KeyPress::IsRepeat  )  [inline]
 

Definition at line 240 of file keypress.h.

00240 { return Repeat; }

BOOL KeyPress::IsRightHand  )  [inline]
 

Definition at line 241 of file keypress.h.

00241 { return RightHand; }

BOOL KeyPress::IsValid  ) 
 

Allows you to see if the KeyPress is legal. The default KeyPress constuctor will always create invalid instances. It is up to other constructors, or member functions, to generate valid ones.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the KeyPress object is a valid one. FALSE otherwise

Errors: -

See also:
KeyPress::KeyPress, KeyPress::GenerateKeyPress

Definition at line 693 of file keypress.cpp.

00694 {
00695     return Valid;
00696 }

KeyPress * KeyPress::MakeKeyPress KeyPressSysMsg pKeySysMsg  )  [static, private]
 

Makes a KeyPress from a KeyPressSysMsg.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
pKeySysMsg = Ptr to a platform indepenent version of a Windows key press message [INPUTS]
- [OUTPUTS]
Returns:
Ptr to a valid KeyPress object OR NULL if not enough memory

Errors: -

See also:
KeyPress::GenerateKeyPress,KeyPress::GenerateUnicode

Definition at line 965 of file keypress.cpp.

00966 {
00967 //  PORTNOTETRACE( "other", "KeyPress::MakeKeyPress - do nothing" );
00968     KeyPress*           pKeyPress = NULL;       // This will point to the key press object
00969 
00970     // Try and get a Unicode char to represent the key press
00971     WCHAR pWideChar[10];
00972     INT32 NumChars = 0;
00973     
00974     if (pKeySysMsg->Message == KM_CHAR)
00975     {
00976 #if FALSE != wxUSE_UNICODE
00977         NumChars = 1;
00978         pWideChar[0] = pKeySysMsg->m_Char;
00979 
00980         TRACEUSER( "jlh92", _T("Unicode = %c\n"), pKeySysMsg->m_Char );
00981 #else
00982         // If the message is a CHAR message, then we need to generate a Unicode value ourselves
00983         // using the char code (which is stored in the VirtKey field of the KeyPressSysMsg class)
00984         //
00985         // These codes are generated by holding down Alt and typing the ASCII value of a character
00986         // on the numerical key pad. The Virt key codes generated when doing this fail to produce
00987         // Uncode chars, so the key presses never get passed on.  However, if after this sequence an
00988         // ASCII char is specified (e.g. 'A' via Alt+ '6' '5') a WM_CHAR message is posted, so we need
00989         // to trap this and pass the Unicode equivalent of the ASCII char onto Camelot.
00990         //
00991         // The fake VirtKey code (CAMKEY(CC_NONE)) is specified so that the receiver of this key message
00992         // will not process it on the VirtKey code.  However, anyone interested in just the Unicode
00993         // value (e.g. the text tool) will process it successfully.
00994 
00995         TRACE( _T("Trail byte %d\n"), pKeySysMsg->VirtKey);
00996 
00997         char pants[3];
00998 
00999         if (UnicodeManager::IsDBCSOS())
01000         {
01001             // See if we have a lead byte 
01002             if (LastLeadByte != 0)
01003             {
01004                 pants[0] = LastLeadByte;
01005                 pants[1] = pKeySysMsg->VirtKey;
01006                 pants[2] = 0;
01007                 pWideChar[0] = UnicodeManager::MultiByteToUnicode(UnicodeManager::ComposeMultiBytes(LastLeadByte, pKeySysMsg->VirtKey));
01008             }
01009             else
01010             {
01011                 pants[0] = pKeySysMsg->VirtKey;
01012                 pants[1] = 0;
01013                 pWideChar[0] = pKeySysMsg->VirtKey;
01014             }
01015             LastLeadByte = 0;
01016         }
01017         else
01018         {
01019             pants[0] = pKeySysMsg->VirtKey;
01020             pants[1] = 0;
01021             pWideChar[0] = pKeySysMsg->VirtKey;
01022         }
01023 
01024         TRACE( _T("Entered character %s\n"),pants);
01025         TRACE( _T("Unicode value = %X\n"),pWideChar[0]);
01026 
01027         pKeySysMsg->VirtKey = CAMKEY(CC_NONE);
01028         NumChars = 1;
01029 #endif
01030     }
01031     else
01032     {
01033 #if FALSE != wxUSE_UNICODE
01034         NumChars = 1;
01035         pWideChar[0] = pKeySysMsg->m_Char;
01036         
01037         // We still have to try our custom translations (for VirtKey >= WXK_START)
01038         if( pKeySysMsg->VirtKey >= WXK_START )
01039         {
01040             INT32 i;
01041             for( i = 0; ExtraUnicodes[i].VirtKey != CAMKEY(CC_NONE); ++i )
01042             {
01043                 // We have found an entry in our table for the given virtual key
01044                 if( ExtraUnicodes[i].VirtKey == pKeySysMsg->VirtKey )
01045                 {
01046                     // Stuff the Unicode value into the buffer and set the num chars generated to 1
01047                     pWideChar[0] = ExtraUnicodes[i].Unicode;
01048                     break;
01049                 }
01050             }
01051             
01052             // Don't pass on unknown function keys
01053             if( ExtraUnicodes[i].VirtKey == CAMKEY(CC_NONE) )
01054                 NumChars = 0;
01055         }
01056         
01057         // Windows translates Ctrl+char to control codes, I don't think we need too. Hopefully
01058         // just using CR will be enought.
01059         if( IsConstrainPressed() )
01060             pWideChar[0] = _T('\n');
01061         
01062 #elif defined(__WXMSW__)
01063         BYTE pKeyState[256];            // Array to hold the current state of the keyboard
01064         if (GetKeyboardState(pKeyState))    // Scan the current keyboard state
01065         {
01066             NumChars = GenerateUnicode( pKeySysMsg->VirtKey, pKeySysMsg->ScanCode, pKeyState, pWideChar, 10 );
01067         }
01068 #else
01069         // This should never happen, but just in case we'll use a dumb implementation
01070         NumChars = 1;
01071         mbtowc( pWideChar, pKeySysMsg->VirtKey ); 
01072 #endif
01073     }
01074 
01075     if (NumChars == 1) // Make a KeyPress object if we have a valid associated Unicode character
01076     {
01077         // Construct a KeyPress object
01078         pKeyPress = new KeyPress(pKeySysMsg,pWideChar[0]);
01079 
01080         // If we make an invalid one, delete it and make sure we return NULL
01081         if (pKeyPress != NULL && !pKeyPress->IsValid())
01082         {
01083             delete pKeyPress;
01084             pKeyPress = NULL;
01085         }
01086     }
01087 
01088     return pKeyPress;
01089 }

static BOOL KeyPress::ModifierChanged  )  [inline, static]
 

Definition at line 207 of file keypress.h.

00207 { return fModifierChanged; }

INT32 KeyPress::operator== const KeyPress other  ) 
 

KeyPress == operator Two KeyPress objects are equal if 1) They have the same virtual key code 2) Have the same modifier settings 3) Have the same extended flag settings 4) Have the same validity (i.e. both valid OR both invalid).

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
other = the key press you wish to check for equivalence with this key press [INPUTS]
- [OUTPUTS]
Returns:
TRUE if equal, FALSE otherwise
THIS DOES NOT COMPARE THE UNICODE COMPONENTS OF THE TWO KeyPress OBJECTS. To compare Unicode values, use the KeyPress::GetUnicode() func.
Returns:
Errors: -
See also:
KeyPress::GetUnicode()

Definition at line 1758 of file keypress.cpp.

01759 {
01760     return ( 
01761             VirtKey     == other.VirtKey     &&
01762             Adjust      == other.Adjust      &&
01763             Constrain   == other.Constrain   &&
01764             Alternative == other.Alternative &&
01765             Option      == other.Option      && 
01766             Extended    == other.Extended    &&
01767             Valid       == other.Valid
01768            );
01769 }

void KeyPress::RemoveVirtualKeyCode UINT32  VCode,
WCHAR  Unicode
[static]
 

Removes the given virtual key code that generates the givne unicode value from the list of additional virtual key codes. Only the first occurace is removed.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/10/95
Parameters:
VCode - the virtual key code to remove [INPUTS] Unicode - the unicode value generated when this key is pressed
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1824 of file keypress.cpp.

01825 {
01826     // Loop through the list until we find the list item
01827     BOOL finished = FALSE;
01828     AdditionalVirtKey* pKey = (AdditionalVirtKey*)AdditionalVirtKeys.GetHead();
01829 
01830     while (!finished && (pKey != NULL))
01831     {
01832         AdditionalVirtKey* pNext = (AdditionalVirtKey*)AdditionalVirtKeys.GetNext(pKey);
01833         
01834         if ((pKey->VirtualKeyCode == VCode) && (pKey->UnicodeValue == Unicode))
01835         {
01836             AdditionalVirtKeys.RemoveItem(pKey);
01837             delete pKey;
01838             finished = TRUE;
01839         }
01840 
01841         pKey = pNext;
01842     }
01843 }

void KeyPress::ResetModifierKeys  )  [static]
 

Maintain integrity of our key modifier status. Win32S doesn't always tell us what key events have occured - notably when the user uses Alt-TAB to switch tasks. Hence this gets called whenever our main window is deactivated or activated. The temporary tool is updated if required.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> (Equivalent to Tim's ResetModifierKeys() routine)
Date:
26/08/94
See also:
UpdateTemporaryTool

Definition at line 1188 of file keypress.cpp.

01189 {
01190     //ENSURE(FALSE,"KeyPress::ResetModifierKeys() called");
01191 
01192     // We can't trust Win32S to tell us about all keypreses we need to know about,
01193     // so set all modifiers to ff to avoid weird effects.
01194     if (INCOMPLETE_KEYS)
01195     {
01196         KeyPress::AdjustStateLeft       = FALSE;
01197         KeyPress::AdjustStateRight      = FALSE;
01198         KeyPress::ConstrainStateLeft    = FALSE;
01199         KeyPress::ConstrainStateRight   = FALSE;
01200         KeyPress::AlternativeStateLeft  = FALSE;
01201         KeyPress::AlternativeStateRight = FALSE;
01202         KeyPress::OptionStateLeft       = FALSE;
01203         KeyPress::OptionStateRight      = FALSE;
01204     }
01205 
01206     // Temporary tool may have changed - update it.
01207     //UpdateTemporaryTool();
01208 }

BOOL KeyPress::TranslateMessage wxKeyEvent *  pMsg  )  [static]
 

Called from a low-level PreTranslateMessage() routine to allow key presses to be processed If it is a key press message, it generates a KeyPress object and sends it off to Application::OnKeyPress().

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/08/94
Parameters:
pMsg = A Windows message [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the message was to do with a key press AND was processed FALSE if the message wasn't to do with the keyboard at all OR key press was not processed

Errors: -

See also:
Application::OnKeyPress

Definition at line 1656 of file keypress.cpp.

01657 {
01658 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
01659     // What kind of message is it?
01660     BOOL KeyDown = wxEVT_KEY_DOWN == pMsg->GetEventType();
01661     BOOL KeyUp   = wxEVT_KEY_UP == pMsg->GetEventType();
01662 
01663     // If it's a key event, lose the bubble help.
01664     if (KeyDown || KeyUp)
01665         ControlHelper::BubbleHelpDisable();
01666 #endif
01667     
01668     TRACEUSER( "jlh92", _T("TM - %s\n"), wxEVT_KEY_DOWN == pMsg->GetEventType() ? _T("KDN") :
01669         wxEVT_KEY_UP == pMsg->GetEventType() ? _T("KUP") : wxEVT_CHAR == pMsg->GetEventType() ? _T("KCH") : 
01670         _T("K??") );
01671 
01672     // Normal key processing.
01673     KeyPress* pKeyPress;
01674     BOOL Processed = FALSE;
01675 
01676     // See if we can generate an WM_CHAR message from the key press
01677     if (!Processed)
01678         Processed = GenerateCharMessage(pMsg);
01679 
01680     // Can we make a key press event from this message?
01681     if (!Processed && KeyPress::GenerateKeyPress(pMsg,&pKeyPress))
01682     {
01683         if (pKeyPress != NULL)
01684         {
01685             // The message was a key press and we have a key press object at pKeyPress
01686 
01687             // check for an escape key press
01688             if (!Processed)
01689                 Processed = EscapePressed(pKeyPress);
01690 
01691             // Now see if Camelot wants to use it
01692             if (!Processed)
01693                 Processed = GetApplication()->OnKeyPress(pKeyPress);
01694 
01695             // Don't process Alt key presses.  By always returning FALSE on Alt key presses, we get
01696             // normal functionality from single press/releases of Alt, even in the Selector tool
01697             if (Processed && pKeyPress->VirtKey == CAMKEY(MENU))
01698                 Processed = FALSE;
01699 
01700             //TRACE( _T("Processed = %d\n"),Processed);
01701 
01702             // Must delete the key press after use
01703             delete pKeyPress;
01704         }
01705     }
01706 
01707     if (!Processed)
01708     {
01709         // MFC ISSUES...
01710         // If we have had a key press we wish to ignore totally (i.e. repeated modifier key presses)
01711         // then return TRUE so that it doesn't get passed onto the rest of MFC.
01712         //
01713         // This is mainly for performance improvements during a drag AND modifier key press op, e.g. Alt held down
01714         // in the freehand tool for drawing straight lines.
01715         //
01716         // This fix makes modified drags usable in retail builds.  In debug builds, you get an extra hit with
01717         // AfxValidateObject (or what ever it's called), which takes about 50% of the time.
01718         //
01719         // During Drags:
01720         // We want to prevent key presses getting to MFC during drags.  In particular things like 
01721         // Ctrl-Tab (i.e. switch to new doc)
01722 
01723         KeyPressSysMsg KeySysMsg(pMsg);
01724         if (KeySysMsg.IsValid())
01725         {
01726             // We have a keypress message
01727             // Prevent it getting to MFC if we are dragging or it's one we wish to ignore
01728             Processed = ((Operation::GetCurrentDragOp()!=NULL) || IgnoreKeyMessage(&KeySysMsg));
01729         }
01730     }
01731 
01732     return Processed;
01733 }

void KeyPress::UpdateModifierStatus KeyPressSysMsg pKeySysMsg  )  [static, private]
 

If the message is a modifier key press, the static status vars for the modifier keys in the KeyPress class are updated.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/8/94
Parameters:
pKeySysMsg = Ptr to a platform indepenent version of a Windows key press message [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
KeyPress::GenerateKeyPress

Definition at line 919 of file keypress.cpp.

00920 {
00921     ENSURE(pKeySysMsg->IsValid(),"Invalid KeyPressSysMsg given");
00922 
00923     // pKeySysMsg is not used at the moment
00924     // The modifier key state is read via GetKeyState()
00925 
00926     BOOL AdjL = KeyPress::AdjustStateLeft;      BOOL AdjR = KeyPress::AdjustStateRight;
00927     BOOL ConL = KeyPress::ConstrainStateLeft;   BOOL ConR = KeyPress::ConstrainStateRight;
00928     BOOL AltL = KeyPress::AlternativeStateLeft; BOOL AltR = KeyPress::AlternativeStateRight;
00929     BOOL OptL = KeyPress::OptionStateLeft;      BOOL OptR = KeyPress::OptionStateRight;
00930 
00931     KeyPress::AdjustStateLeft       = wxGetKeyState(CAMKEY(CC_MOD_ADJUST));
00932     KeyPress::AdjustStateRight      = KeyPress::AdjustStateLeft;
00933 
00934     KeyPress::ConstrainStateLeft    = wxGetKeyState(CAMKEY(CC_MOD_CONSTRAIN));
00935     KeyPress::ConstrainStateRight   = KeyPress::ConstrainStateLeft;
00936 
00937     KeyPress::AlternativeStateLeft  = wxGetKeyState(CAMKEY(CC_MOD_ALTERNATIVE));
00938     KeyPress::AlternativeStateRight = KeyPress::AlternativeStateLeft;
00939 
00940     KeyPress::OptionStateLeft       = FALSE;
00941     KeyPress::OptionStateRight      = FALSE;
00942 
00943     KeyPress::fModifierChanged =(AdjL != KeyPress::AdjustStateLeft)     || (AdjR != KeyPress::AdjustStateRight)     ||
00944                                 (ConL != KeyPress::ConstrainStateLeft)  || (ConR != KeyPress::ConstrainStateRight)  ||
00945                                 (AltL != KeyPress::AlternativeStateLeft)|| (AltR != KeyPress::AlternativeStateRight)||
00946                                 (OptL != KeyPress::OptionStateLeft)     || (OptR != KeyPress::OptionStateRight);
00947 }


Member Data Documentation

List KeyPress::AdditionalVirtKeys [static, private]
 

Definition at line 317 of file keypress.h.

BOOL KeyPress::Adjust [private]
 

Definition at line 280 of file keypress.h.

BOOL KeyPress::AdjustStateLeft = FALSE [static, private]
 

Definition at line 297 of file keypress.h.

BOOL KeyPress::AdjustStateRight = FALSE [static, private]
 

Definition at line 298 of file keypress.h.

BOOL KeyPress::Alternative [private]
 

Definition at line 282 of file keypress.h.

BOOL KeyPress::AlternativeStateLeft = FALSE [static, private]
 

Definition at line 301 of file keypress.h.

BOOL KeyPress::AlternativeStateRight = FALSE [static, private]
 

Definition at line 302 of file keypress.h.

INT32 KeyPress::AsciiVal = -1 [static, private]
 

Definition at line 310 of file keypress.h.

BOOL KeyPress::Constrain [private]
 

Definition at line 281 of file keypress.h.

BOOL KeyPress::ConstrainStateLeft = FALSE [static, private]
 

Definition at line 299 of file keypress.h.

BOOL KeyPress::ConstrainStateRight = FALSE [static, private]
 

Definition at line 300 of file keypress.h.

BOOL KeyPress::Extended [private]
 

Definition at line 285 of file keypress.h.

BOOL KeyPress::fModifierChanged = FALSE [static, private]
 

Definition at line 307 of file keypress.h.

BYTE KeyPress::LastLeadByte = 0 [static, private]
 

Definition at line 314 of file keypress.h.

BOOL KeyPress::m_fIsChar [private]
 

Definition at line 290 of file keypress.h.

BOOL KeyPress::Option [private]
 

Definition at line 283 of file keypress.h.

BOOL KeyPress::OptionStateLeft = FALSE [static, private]
 

Definition at line 303 of file keypress.h.

BOOL KeyPress::OptionStateRight = FALSE [static, private]
 

Definition at line 304 of file keypress.h.

BOOL KeyPress::Release [private]
 

Definition at line 289 of file keypress.h.

BOOL KeyPress::Repeat [private]
 

Definition at line 287 of file keypress.h.

BOOL KeyPress::RightHand [private]
 

Definition at line 288 of file keypress.h.

WCHAR KeyPress::Unicode [private]
 

Definition at line 278 of file keypress.h.

BOOL KeyPress::Valid [private]
 

Definition at line 292 of file keypress.h.

BOOL KeyPress::ValidAsciiVal = FALSE [static, private]
 

Definition at line 311 of file keypress.h.

UINT32 KeyPress::VirtKey [private]
 

Definition at line 277 of file keypress.h.

BOOL KeyPress::WorksInDrag [private]
 

Definition at line 293 of file keypress.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:55:42 2007 for Camelot by  doxygen 1.4.4