HotKey Class Reference

Encapsulates hot keys in camelot. More...

#include <hotkeys.h>

Inheritance diagram for HotKey:

ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

void GetTextDesc (String_256 *pStr)
 Stuffs the hot key text desc (if it has one) into *pStr.

Static Public Member Functions

static BOOL Init ()
 Initialises the HotKey class. At the moment it just involves the reading of the hot key definitions.
static void Deinit ()
 Cleans up the HotKey class on program exit.
static BOOL AddHotKey (KeyPress *pKeyPress, TCHAR *pOpToken, String_32 *pTextDesc, BOOL CheckUnicode)
 The place where hot keys are added to Camelot.
static BOOL OnKeyPress (KeyPress *pKeyPress)
 This will invoke an operation if the given key press matches a registered hot key.
static HotKeyFindHotKey (OpDescriptor *pThisOpDesc)
 Finds the first hot key that is associated with the given op desc NULL is returned if there isn't one or the hot key has been disabled.

Private Member Functions

 HotKey ()
 The default constructor. Does nothing at the moment.
 ~HotKey ()
 The default destructor. Main job is to delete any attached objects (such as the key press object).
BOOL IsEnabled ()
 Tests to see if it is possible to invoke a hot key's operation. This will also update the status bar with a relevent message. If the op is enabled, a general description of the op is displayed If the op is disabled, a description of why is displayed.

Static Private Member Functions

static BOOL DoesHotKeyMatchKeyPress (HotKey *pHotKey, KeyPress *pKeyPress)
 Central routine for checking HotKeys against key press objects.
static BOOL ReadHotKeys ()
 Reads the hot key definitions from somewhere (either file or bound-in resource file).
static BOOL ReadHotKeysFromDisk ()
 Reads the hot key definitions from disk (i.e. writable media).
static BOOL ReadHotKeysFromRes ()
 Reads the hot key definitions from the bound in resource.
static BOOL ReadHotKeysFromFile (CCLexFile &file)
 Reads the hot key definitions from the given file.
static BOOL ReadHotKey (CCLexFile &file)
 Read one hot key definition from the given file.
static BOOL ReadToolSwitch (CCLexFile &file)
 Read one tool switch definition from the given file.
static BOOL ReadKeyDef (CCLexFile &file, KeyPress **ppKeyPress, String_256 *pOpToken, String_32 **ppTextDesc, BOOL *pCheckUnicode)
 Generates a key press object and op token from the given file.

Private Attributes

KeyPresspKeyPress
OpDescriptorpOpDesc
String_32pTextDesc
BOOL CheckUnicode

Detailed Description

Encapsulates hot keys in camelot.

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

Definition at line 121 of file hotkeys.h.


Constructor & Destructor Documentation

HotKey::HotKey  )  [private]
 

The default constructor. Does nothing at the moment.

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

Definition at line 228 of file hotkeys.cpp.

00229 {
00230     pKeyPress   = NULL;
00231     pOpDesc     = NULL;
00232     pTextDesc   = NULL;
00233     CheckUnicode= FALSE;
00234 }

HotKey::~HotKey  )  [private]
 

The default destructor. Main job is to delete any attached objects (such as the key press object).

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

Definition at line 251 of file hotkeys.cpp.

00252 {
00253     if (pKeyPress != NULL)
00254     {
00255         delete pKeyPress;
00256         pKeyPress = NULL;
00257     }
00258 
00259     if (pTextDesc != NULL)
00260     {
00261         delete pTextDesc;
00262         pTextDesc = NULL;
00263     }
00264 }


Member Function Documentation

BOOL HotKey::AddHotKey KeyPress pKeyPress,
TCHAR pOpToken,
String_32 pTextDesc,
BOOL  CheckUnicode
[static]
 

The place where hot keys are added to Camelot.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/8/94
Parameters:
pKeyPress = ptr to the key press that will invoke the operation [INPUTS] pOpToken = ptr to the char array of the operation's op token pTextDesc = ptr to a string that describes the hot key (e.g. "Ctrl+X") CheckUnicode= Flag to determine how the hot key is compared with key press objects
- [OUTPUTS]
Returns:
TRUE if it could find the operation and the ky press was valid FALSE if something hideous happend
See also:
-

Definition at line 284 of file hotkeys.cpp.

00285 {
00286     PORTNOTE( "other", "AddHotKey - Carry on even if OpDesc not found" );
00287     BOOL ok = TRUE;
00288 
00289     // Is this key press ok?
00290     if (pKeyPress->IsValid())
00291     {
00292         // We have a valid key press object, but do we have a valid op token?
00293 
00294         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(pOpToken);
00295 
00296         if (pOpDesc != NULL)
00297         {
00298             // Yes, we now have a valid op token too. Now make a HotKey object
00299 
00300             HotKey* pHotKey = new HotKey;
00301 
00302             if (pHotKey != NULL)
00303             {
00304                 // We have everything we need, so set up the HotKey and add it to the list
00305 
00306                 pHotKey->pKeyPress   = pKeyPress;
00307                 pHotKey->pOpDesc     = pOpDesc;
00308                 pHotKey->pTextDesc   = pTextDesc;
00309                 pHotKey->CheckUnicode= CheckUnicode;
00310 
00311                 HotKeyList.AddTail(pHotKey);
00312 
00313                 ok = TRUE;
00314             }
00315         }
00316         else
00317         {
00318             TRACE( _T("HotKey: Unable to find op desc \"%s\"\n"),pOpToken);
00319             // These will only get deleted if we return false so delete them here
00320             delete pKeyPress;
00321             delete pTextDesc;
00322         }
00323     }
00324 
00325     return ok;
00326 }

void HotKey::Deinit void   )  [static]
 

Cleans up the HotKey class on program exit.

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

Definition at line 208 of file hotkeys.cpp.

00209 {
00210     HotKeyList.DeleteAll();
00211 }

BOOL HotKey::DoesHotKeyMatchKeyPress HotKey pHotKey,
KeyPress pKeyPress
[static, private]
 

Central routine for checking HotKeys against key press objects.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/7/95
Parameters:
pHotKey = ptr to HotKey [INPUTS] pKeyPress = ptr to KeyPress
- [OUTPUTS]
Returns:
TRUE if HotKey matches the key press, FALSE otherwise
See also:
-

Definition at line 403 of file hotkeys.cpp.

00404 {
00405     ERROR3IF(pHotKey   == NULL,"pHotKey == NULL");
00406     ERROR3IF(pKeyPress == NULL,"pHotKey == NULL");
00407 
00408     if (pHotKey == NULL || pKeyPress == NULL)
00409         return FALSE;
00410 
00411     if (pHotKey->CheckUnicode)
00412     {
00413         ERROR3IF(pHotKey->pTextDesc == NULL,"pHotKey->pTextDesc == NULL");
00414 
00415         if (pHotKey->pTextDesc == NULL)
00416             return FALSE;
00417 
00418         TCHAR str[3];
00419 
00420         str[0] = (pKeyPress->GetUnicode() & 0xff);
00421         str[1] = ((pKeyPress->GetUnicode() & 0xff00)>>8);
00422         str[2] = 0;
00423 
00424         String_32 KeyPressStr = String_32(str);
00425 
00426         return (KeyPressStr == *pHotKey->pTextDesc);
00427     }
00428     else
00429         return (*pHotKey->pKeyPress == *pKeyPress);
00430 }

HotKey * HotKey::FindHotKey OpDescriptor pThisOpDesc  )  [static]
 

Finds the first hot key that is associated with the given op desc NULL is returned if there isn't one or the hot key has been disabled.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/9/94
Parameters:
pThisOpDesc = ptr to an op desc [INPUTS]
Returns:
ptr to a HotKey, or NULL
See also:
OpDescriptor::IsHotKeyEnabled()

Definition at line 446 of file hotkeys.cpp.

00447 {
00448     if (!pThisOpDesc->IsHotKeyEnabled())
00449     {
00450         return NULL;
00451     }
00452 
00453     HotKey* pHotKey = (HotKey*)HotKeyList.GetHead();
00454 
00455     while (pHotKey != NULL && (pHotKey->pOpDesc != pThisOpDesc))
00456         pHotKey = (HotKey*)HotKeyList.GetNext(pHotKey);
00457 
00458     return pHotKey;
00459 }

void HotKey::GetTextDesc String_256 pStr  ) 
 

Stuffs the hot key text desc (if it has one) into *pStr.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/9/94
Parameters:
pStr = ptr to a string to put the text desc of the hot key [INPUTS]
*pStr contains the description [OUTPUTS]
Returns:
-
See also:
-

Definition at line 1008 of file hotkeys.cpp.

01009 {
01010     ENSURE(pStr != NULL,"pStr is NULL");
01011     if (pStr == NULL) return;
01012 
01013     if (pTextDesc != NULL)
01014         *pStr = *pTextDesc;
01015 }

BOOL HotKey::Init void   )  [static]
 

Initialises the HotKey class. At the moment it just involves the reading of the hot key definitions.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Reimplemented from SimpleCCObject.

Definition at line 189 of file hotkeys.cpp.

00190 {
00191     return (HotKey::ReadHotKeys());
00192 }

BOOL HotKey::IsEnabled  )  [private]
 

Tests to see if it is possible to invoke a hot key's operation. This will also update the status bar with a relevent message. If the op is enabled, a general description of the op is displayed If the op is disabled, a description of why is displayed.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the hot key operation is enabled FALSE otherwise

Errors: None

Definition at line 479 of file hotkeys.cpp.

00480 {
00481     ENSURE(pOpDesc != NULL, "Hot key's op desc ptr is NULL");
00482 
00483     // Check if the hot key is available to the user, i.e., it is shown
00484     if (!pOpDesc->IsHotKeyEnabled())
00485     {
00486         return FALSE;
00487     }
00488 
00489     // String that will contain the string to display in the status bar
00490     String_256 StatusMsg;
00491     
00492     // get hotkey's op state
00493     OpState HotKeyState = pOpDesc->GetOpsState(&StatusMsg);
00494 
00495     // If the op state is greyed, then the description of why it's grey should have been
00496     // set up by the GetOpsState() call
00497 
00498     // If it's not greyed, get a general description of the op to place in the status bar
00499     if (!HotKeyState.Greyed)
00500         pOpDesc->GetText(&StatusMsg,OP_DESC_TEXT);
00501     
00502     // Display msg in the status bar
00503     GetApplication()->UpdateStatusBarText(&StatusMsg);
00504 
00505     // Return TRUE if not greyed
00506     return (!HotKeyState.Greyed);
00507 }

BOOL HotKey::OnKeyPress KeyPress pKeyPress  )  [static]
 

This will invoke an operation if the given key press matches a registered hot key.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/8/94
Parameters:
pKeyPress = ptr to the key press that's just been generated [INPUTS]
- [OUTPUTS]
Returns:
TRUE if processed (i.e. a hot key was pressed), so do not pass on FALSE if not processed, so pass on to others
See also:
-

Definition at line 344 of file hotkeys.cpp.

00345 {
00346     TRACEUSER( "jlh92", _T("Key VK=%04x (%08x) in Hotkey\n"), pKeyPress->GetVirtKey(), 
00347         pKeyPress->GetUnicode() );
00348 
00349     BOOL Processed = FALSE;
00350     BOOL DuringADrag = (Operation::GetCurrentDragOp() != NULL ||
00351                         DragManagerOp::IsDragActive() ||
00352                         BaseBar::IsDragging());
00353 
00354     HotKey* pHotKey = (HotKey*)HotKeyList.GetHead();
00355     while (pHotKey != NULL && !Processed)
00356     {
00357         if (DoesHotKeyMatchKeyPress(pHotKey,pKeyPress))
00358         {
00359             TRACEUSER( "jlh92", _T("Key VK=%04x (%08x) handled as HotKey\n"), pKeyPress->GetVirtKey(), 
00360                 pKeyPress->GetUnicode() );
00361 
00362             // The key press is a hot key combination
00363             if ((pHotKey->pKeyPress->IsOkInDrags() || !DuringADrag) && pKeyPress->IsPress())
00364             {
00365                 // There is no drag happening (or the keypress works in drags), and it is a "key down" key press
00366                 // If the hot key's op is enabled, invoke it
00367                 if (pHotKey->IsEnabled())
00368                     pHotKey->pOpDesc->Invoke();
00369             }
00370 
00371             // Do not pass on if it is a hot key combination, whether the op was invoked or not
00372             Processed = TRUE;
00373         }
00374 
00375         // Get the next hot key
00376         pHotKey = (HotKey*)HotKeyList.GetNext(pHotKey);
00377     }
00378     
00379     if( !Processed )
00380     {
00381         TRACEUSER( "luke", _T("Key VK=%04x (%08x) not handled as HotKey\n"), pKeyPress->GetVirtKey(), 
00382             pKeyPress->GetUnicode() );
00383     }
00384 
00385     return Processed;
00386 }

BOOL HotKey::ReadHotKey CCLexFile file  )  [static, private]
 

Read one hot key definition from the given file.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/9/94
Parameters:
file = file that contains the hot key definitions [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 698 of file hotkeys.cpp.

00699 {
00700     KeyPress* pKeyPress = NULL;
00701     String_256 OpToken;
00702     String_32* pTextDesc = NULL;
00703     BOOL CheckUnicode;
00704 
00705     BOOL ok = HotKey::ReadKeyDef(file,&pKeyPress,&OpToken,&pTextDesc,&CheckUnicode);
00706 
00707     if (ok)
00708     {
00709         ok = HotKey::AddHotKey(pKeyPress,OpToken,pTextDesc,CheckUnicode);
00710         if (!ok) TRACE( _T("HotKey: Unable to add hot key to the system\n"));
00711     }
00712     else
00713     {
00714         delete pKeyPress;
00715         delete pTextDesc;
00716     }
00717 
00718     return (ok);
00719 }

BOOL HotKey::ReadHotKeys  )  [static, private]
 

Reads the hot key definitions from somewhere (either file or bound-in resource file).

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 525 of file hotkeys.cpp.

00526 {
00527     BOOL ok = HotKey::ReadHotKeysFromDisk();
00528 
00529     if (!ok) ok = HotKey::ReadHotKeysFromRes();
00530 
00531     return (ok);
00532 }

BOOL HotKey::ReadHotKeysFromDisk  )  [static, private]
 

Reads the hot key definitions from disk (i.e. writable media).

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 548 of file hotkeys.cpp.

00549 {   
00550     CCDiskFile file;                                // File
00551 
00552     FilePath filepath = KeyPress::GetHotKeysFilename();
00553     if (!filepath.IsValid())
00554         return FALSE;
00555 
00556     BOOL ok = TRUE;
00557 
00558     // Prevent file errors from being reported directly to the user
00559     BOOL OldThrowingState = file.SetThrowExceptions( TRUE );
00560     BOOL OldReportingState = file.SetReportErrors( FALSE );
00561 
00562     try
00563     {
00564         ok = file.open(filepath, ios::in);                      // Open file
00565 
00566         if (ok)
00567         {
00568                 ok = HotKey::ReadHotKeysFromFile(file);
00569                 file.close();
00570         }
00571     }
00572 
00573     catch (...)
00574     {
00575         Error::ClearError();
00576         ok = FALSE;
00577     }
00578 
00579     // Must set the exception throwing and reporting flags back to their entry states
00580     file.SetThrowExceptions( OldThrowingState );
00581     file.SetReportErrors( OldReportingState );
00582 
00583     return ok;
00584 }

BOOL HotKey::ReadHotKeysFromFile CCLexFile file  )  [static, private]
 

Reads the hot key definitions from the given file.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/9/94
Parameters:
file = file that contains the hot key definitions [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 629 of file hotkeys.cpp.

00630 {
00631     BOOL finished = FALSE;
00632     BOOL ok;;   
00633     
00634     // Initialise lexing routines, and aspects of the lexer
00635     ok = file.InitLexer();
00636     file.SetDelimiters("\r\n");         // Set token delimiting characters
00637     file.SetCommentMarker(';');         // Set comment marker char
00638     file.SetWhitespace(" \t");          // Set whitespace chars
00639     file.SetStringDelimiters("\"\"");   // Set string delimiters
00640 
00641     HK_TokenIndex Token;
00642     const TCHAR* TokenBuf = file.GetTokenBuf(); // Token buffer remains constant until lexer deinitialisation
00643     
00644     while (ok && !finished)
00645     {
00646         // Grab a token
00647         ok = file.GetSimpleToken();
00648 
00649         // Look the token up in our table
00650         Token = FindToken(TokenBuf);
00651 
00652         switch (Token)
00653         {
00654             case HK_TOKEN_HOTKEY:
00655                 ok = HotKey::ReadHotKey(file);
00656                 break;
00657 
00658             case HK_TOKEN_TOOLSWITCH:
00659                 ok = HotKey::ReadToolSwitch(file);
00660                 break;
00661 
00662             case HK_TOKEN_HOTKEYEND:
00663                 finished = TRUE;
00664                 break;
00665 
00666             default:
00667                 TRACE( _T("HotKey: Unexpected token - %s\n"),TokenBuf);
00668                 break;
00669         }
00670     }
00671 
00672     if (!ok)
00673     {
00674         TRACE( _T("\nHotKey: Offending line - %s\n"),file.GetLineBuf());
00675         ENSURE(FALSE,"Error reading hot keys.  See TRACE output for details");
00676     }
00677 
00678     // We are now finished with the lexer
00679     file.DeinitLexer();
00680 
00681     return (ok);
00682 }

BOOL HotKey::ReadHotKeysFromRes  )  [static, private]
 

Reads the hot key definitions from the bound in resource.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 600 of file hotkeys.cpp.

00601 {
00602     CCResTextFile file;             // Resource File
00603 
00604     BOOL ok = file.open(_R(IDH_STANDARD_HOTKEYS), _R(IDT_CAM_HOTKEY_RES));      // Open resource
00605 
00606     if (ok)
00607     {
00608         ok = HotKey::ReadHotKeysFromFile(file);
00609         file.close();
00610     }
00611 
00612     return (ok);
00613 }

BOOL HotKey::ReadKeyDef CCLexFile file,
KeyPress **  ppKeyPress,
String_256 pOpToken,
String_32 **  ppTextDesc,
BOOL *  pCheckUnicode
[static, private]
 

Generates a key press object and op token from the given file.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/94
Parameters:
file = file that contains the key definitions [INPUTS] ppKeyPress = Place to put the ptr to a key press object pOpToken = ptr to string to place the op token string ppTextDesc = ptr to a ptr to a String_32 object that describes the key def (e.g. "Ctrl+X") pCheckUnicode = Flag to determine how the hot key is compared with key press objects
*ppKeyPress = a ptr to a key press object OR NULL [OUTPUTS] pOpToken = op token of op associated with the key press object OR empty string ppTextDesc = ptr to a String_32 describing the key combination. If this is NULL, then the key combo has no text description pCheckUnicode = TRUE if Unicode checking should be done, FALSE otherwise
Returns:
TRUE if OK FALSE otherwise (syntax error, not enough memory, etc)
See also:
-

Definition at line 817 of file hotkeys.cpp.

00822 {
00823     // Check the params
00824     ENSURE(ppKeyPress   != NULL,"ppKeyPress is NULL");
00825     ENSURE(pOpToken     != NULL,"pOpToken is NULL");
00826     ENSURE(ppTextDesc   != NULL,"ppTextDesc is NULL");
00827     ENSURE(pCheckUnicode!= NULL,"pCheckUnicode is NULL");
00828     if (ppKeyPress == NULL || pOpToken == NULL || ppTextDesc == NULL || pCheckUnicode == NULL) return FALSE;
00829 
00830     *ppKeyPress     = NULL;     // We haven't made a key press object yet
00831     *ppTextDesc     = NULL;     // No text description yet
00832     *pCheckUnicode  = FALSE;    // Assume we don't want Unicode checking
00833 
00834     HK_TokenIndex Token;
00835     const TCHAR* TokenBuf = file.GetTokenBuf();
00836 
00837     // This set of parameters will combine to form a key press object that represents
00838     // the hot key combination
00839     UINT32      VirtKey     = CAMKEY(CC_NONE);
00840     BOOL        Adjust      = FALSE;
00841     BOOL        Constrain   = FALSE;
00842     BOOL        Alternative = FALSE;
00843     BOOL        Extended    = FALSE;
00844     BOOL        WorksInDrag = FALSE;
00845     String_32*  pTextDesc   = NULL;
00846 
00847     // This is FALSE until we have read the text that describes the key combination
00848     BOOL TextDescRead = FALSE;
00849     BOOL EnumStringRead = FALSE;
00850 
00851     // We haven't finsihed, but we're OK at the mo
00852     BOOL finished = FALSE;
00853     BOOL ok       = TRUE;
00854 
00855     while (ok && !finished)
00856     {
00857         // Get the next token
00858         ok = file.GetSimpleToken();
00859 
00860         if (ok)
00861         {
00862             // Find out the type of the token
00863             LexTokenType TokenType = file.GetTokenType();
00864 
00865             switch (TokenType)
00866             {
00867                 case TOKEN_STRING:
00868 
00869                     if (!EnumStringRead)
00870                     {
00871                         // The first string encountered is the "WXK_" string representation of
00872                         // the enumeration.
00873 
00874                         // Make sure the enum string is not too long.
00875                         UINT32 TokenLen = camStrlen(TokenBuf);
00876                         if (TokenLen <= ENUM_STR_DESC_SIZE)
00877                         {
00878                             // Is the string not empty (i.e. "") ?
00879                             if (TokenLen > 0)
00880                             {
00881                                 VirtKey=wxKeyMap::GetKeyVal(TokenBuf);
00882                             }
00883                         }
00884                         else
00885                             TRACE( _T("HotKey: Enum string ('%s') is too long - should be <= %d"),TokenBuf,ENUM_STR_DESC_SIZE);
00886                         EnumStringRead = TRUE;
00887                     }
00888                     else if (!TextDescRead)
00889                     {
00890                         // We haven't yet read the textual desc of the key definition, so assume
00891                         // that this is it
00892 
00893                         // Make sure the desc is not too long
00894                         UINT32 TokenLen = camStrlen(TokenBuf);
00895                         if (TokenLen <= TEXT_DESC_SIZE)
00896                         {
00897                             // Is the string not empty (i.e. "") ?
00898                             if (TokenLen > 0)
00899                             {
00900                                 // if there is a valid text desc, get a String_32 ready for it
00901                                 // and put the desc in it
00902                                 pTextDesc = new String_32;
00903                                 if (pTextDesc != NULL)
00904                                     *pTextDesc = TokenBuf;
00905                                 else
00906                                     TRACE( _T("HotKey: Not enough memory for a String_32 - pathetic eh?"));
00907                             }
00908                         }
00909                         else
00910                             TRACE( _T("HotKey: Menu text ('%s') is too long - should be <= %d"),TokenBuf,TEXT_DESC_SIZE);
00911 
00912                         // We have read the text desc string
00913                         TextDescRead = TRUE;
00914                     }
00915                     else
00916                     {
00917                         // When we get a string after the menu text string, assume this is 
00918                         // the op token of the operation the hot key is intended to invoke
00919                         // Also, regard the op token string as the last aspect of a key def
00920                         *pOpToken  = TokenBuf;
00921                         finished = TRUE;
00922                     }
00923 
00924                     break;
00925 
00926                 case TOKEN_NORMAL:
00927                     {
00928                         Token = FindToken(TokenBuf);
00929                         switch (Token)
00930                         {
00931                             case HK_TOKEN_ADJUST        : Adjust         = TRUE; break;
00932                             case HK_TOKEN_CONSTRAIN     : Constrain      = TRUE; break;
00933                             case HK_TOKEN_ALTERNATIVE   : Alternative    = TRUE; break;
00934                             case HK_TOKEN_EXTENDED  : Extended       = TRUE; break;
00935                             case HK_TOKEN_WORKSINDRAG   : WorksInDrag    = TRUE; break;
00936                             case HK_TOKEN_CHECKUNICODE  : *pCheckUnicode = TRUE; break;
00937 
00938                             case HK_TOKEN_NONE:
00939                                 //Should no longer get this token.
00940                                 /*ok = (camSscanf(TokenBuf,_T("%li"),&VirtKey) == 1);
00941                                 if (!ok) TRACE( _T("HotKey: Expected a virtual key code but got : '%s'\n"),TokenBuf);
00942                                 break;*/
00943 
00944                             default:
00945                                 ok = FALSE;
00946                                 TRACE( _T("HotKey: Didn't expect to get this token ('%s') in the middle of a hot key def\n"),TokenBuf);
00947                                 break;
00948                         }
00949                     }
00950                     break;
00951 
00952                 default:
00953                     TRACE( _T("HotKey: Unexpected token - %s\n"),TokenBuf);
00954                     ok = FALSE;
00955                     break;
00956             }
00957         }
00958     }
00959 
00960 
00961     if (ok)
00962     {
00963         ok = (VirtKey != CAMKEY(CC_NONE));
00964         if (ok)
00965         {
00966             *ppKeyPress = new KeyPress(VirtKey,Adjust,Constrain,Alternative,Extended,WorksInDrag);
00967             ok = (*ppKeyPress != NULL);
00968             if (ok)
00969                 *ppTextDesc = pTextDesc;
00970             else
00971                 TRACE( _T("HotKey: Not enough memory for the key press object"));
00972         }
00973         else
00974             TRACE( _T("HotKey: Virtual key code was not found\n"));
00975     }
00976 
00977     if (!ok)
00978     {
00979         if (*ppKeyPress != NULL)
00980         {
00981             delete *ppKeyPress;
00982             *ppKeyPress = NULL;
00983         }
00984         if (pTextDesc != NULL)
00985         {
00986             delete pTextDesc;
00987             pTextDesc = NULL;
00988         }
00989     }
00990 
00991     return (ok);
00992 }

BOOL HotKey::ReadToolSwitch CCLexFile file  )  [static, private]
 

Read one tool switch definition from the given file.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/94
Parameters:
file = file that contains the tool switch definitions [INPUTS]
- [OUTPUTS]
Returns:
TRUE if OK, FALSE otherwise
See also:
-

Definition at line 735 of file hotkeys.cpp.

00736 {
00737     KeyPress* pKeyPress = NULL;
00738     String_256 OpToken;
00739     String_32* pTextDesc = NULL;    // This is not used with tool switches
00740     BOOL CheckUnicode;              // This is not used with tool switches
00741 
00742     BOOL ok = HotKey::ReadKeyDef(file,&pKeyPress,&OpToken,&pTextDesc,&CheckUnicode);
00743 
00744     // This text desc is ignored at the mo by the tool switch mechanism 
00745     // so if ReadKeyDef() happens to return one, destory it
00746     if (pTextDesc != NULL)
00747     {
00748         delete pTextDesc;
00749         pTextDesc = NULL;
00750     }
00751 
00752     if (ok)
00753     {
00754         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OpToken);
00755         ok = (pOpDesc != NULL);
00756 
00757         if (ok)
00758         {
00759             UINT32 ToolID = pOpDesc->GetToolID();
00760 
00761             ToolListItem* pToolListItem = Tool::Find(ToolID);
00762             ok = ((pToolListItem != NULL) && (pToolListItem->m_pTool != NULL));
00763 
00764             if (ok)
00765             {
00766                 ok = pToolListItem->m_pTool->RegisterToolSwitch(pKeyPress,TRUE);
00767                 if (!ok)
00768                 {
00769                     TRACE( _T("HotKey: Unable to register the tool switch\n"));
00770                     delete pKeyPress;
00771                 }
00772             }
00773             else
00774                 TRACE( _T("HotKey: Dodgy ToolListItem for the tool ID %ld\n"),ToolID);
00775         }
00776         else
00777             TRACE( _T("HotKey: Unable to find op '%s'\n"),(TCHAR*)OpToken);
00778     }
00779     else
00780     {
00781         delete pKeyPress;
00782     }
00783 
00784     return (ok);
00785 }


Member Data Documentation

BOOL HotKey::CheckUnicode [private]
 

Definition at line 155 of file hotkeys.h.

KeyPress* HotKey::pKeyPress [private]
 

Definition at line 152 of file hotkeys.h.

OpDescriptor* HotKey::pOpDesc [private]
 

Definition at line 153 of file hotkeys.h.

String_32* HotKey::pTextDesc [private]
 

Definition at line 154 of file hotkeys.h.


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