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             //