keypress.h

Go to the documentation of this file.
00001 // $Id: keypress.h 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Definition of the KeyPress class
00099 
00100 #ifndef INC_KEYPRESS
00101 #define INC_KEYPRESS
00102 
00103 //#include "listitem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 
00105 enum KeyPressSysMsgHandle
00106 {
00107     KM_KEYUP,
00108     KM_KEYDOWN,
00109     KM_CHAR
00110 };
00111 
00112 
00113 // This is the first in the range of privat Unicodes that Camelot will use to encode keys that do
00114 // not have direct Unicode equivalents
00115 #define CAMELOT_UNICODE_BASE (0xf800)
00116 #define CAMELOT_UNICODE_LAST (0xf94f)
00117 
00118 
00119 
00120 
00121 /********************************************************************************************
00122 >   class AdditionalVirtKey: public ListItem
00123 
00124     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00125     Created:    11/10/95
00126     Purpose:    Used to store 'additional' known virtual key codes so the range of handled
00127                 keys can be extended at runtime
00128 ********************************************************************************************/
00129 
00130 class AdditionalVirtKey: public ListItem
00131 {
00132 public:                
00133     UINT32 VirtualKeyCode;
00134     WCHAR UnicodeValue;
00135 };         
00136 
00137 
00138 /********************************************************************************************
00139 
00140 >   class KeyPressSysMsg: public CC_CLASS_MEMDUMP
00141 
00142     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00143     Created:    26/8/94
00144     Purpose:    Represents a key press message that is slightly more abstract than the raw
00145                 Windows message.
00146                 This will hopefully aid the porting of this code to other platforms
00147 
00148 ********************************************************************************************/
00149 
00150 class KeyPressSysMsg : public CC_CLASS_MEMDUMP
00151 {
00152     CC_DECLARE_MEMDUMP(KeyPressSysMsg);
00153 
00154 public:
00155     KeyPressSysMsg( wxKeyEvent *pMsg );
00156     BOOL IsValid();
00157 
00158     KeyPressSysMsgHandle Message;       // The message type, KM_ something
00159 
00160     UINT32              VirtKey;        // Virtual key code describing the actual key that's been pressed
00161     UINT32              RepeatCount;    // The repeat count for the key before message was posted
00162     UINT32              ScanCode;       // Keyboard scan code. Depends on keyboard manufacturer
00163 #if FALSE != wxUSE_UNICODE
00164     wxChar              m_Char;         // The character code
00165 #endif
00166 
00167     BOOL Extended   : 1;            // Set when an extended key was press (e.g. right-hand Alt or Ctrl)
00168     BOOL PrevDown   : 1;            // Set when the key was down before the key press message was sent
00169 
00170 private:
00171     BOOL Valid : 1;
00172 
00173     // VirtKey of last keypress, used to detect repeated keys
00174     static UINT32 m_LastVirtKey;
00175 };
00176 
00177 /********************************************************************************************
00178 
00179 >   class KeyPress: public CC_CLASS_MEMDUMP
00180 
00181     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00182     Created:    24/8/94
00183     Purpose:    Encapsulates key presses in camelot
00184 
00185 ********************************************************************************************/
00186 
00187 class KeyPress : public CC_CLASS_MEMDUMP
00188 {
00189     CC_DECLARE_MEMDUMP(KeyPress);
00190 
00191 public:
00192     static BOOL Init();
00193     static FilePath GetHotKeysFilename();
00194     static BOOL DispatchKeyEvent(UINT32 nMsgID, UINT32 nChar, UINT32 nRepCnt, UINT32 nFlags);
00195     static BOOL TranslateMessage( wxKeyEvent *pMsg );
00196     static void ResetModifierKeys();
00197     static BOOL GenerateCharMessage( wxKeyEvent *pMsg );
00198 
00199     // These all allow key states to be tested asynchronously, ie. without a key event happening.
00200     static BOOL IsAdjustPressed();
00201     static BOOL IsConstrainPressed();
00202     static BOOL IsAlternativePressed();
00203     static BOOL IsEscapePressed();
00204     static BOOL IsKeyPressed(UINT32 VirtKey);       // General async keypress func call.
00205 
00206     // ModifierChange() will return TRUE if the last keypress message was due to a modifier key state change
00207     static BOOL ModifierChanged() { return fModifierChanged; }
00208 
00209     // These are special methods for galleries, as they must emulate Windows list boxes
00210     // They should not be used outside the gallery system unless you're really really sure
00211     static BOOL IsGalleryShiftPressed(void);
00212     static BOOL IsGalleryCtrlPressed(void);
00213 
00214     // The constructors
00215     KeyPress(KeyPressSysMsg* pKeySysMsg,WCHAR UnicodeChar);
00216     KeyPress(UINT32 VirtKey, BOOL PlusAdjust = FALSE, BOOL PlusConstrain = FALSE, BOOL PlusAlternative = FALSE,
00217                            BOOL ExtendedKey = FALSE, BOOL WorksInDragsKey = FALSE);
00218     KeyPress(const KeyPress &c): // 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) {}
00222 
00223     static KeyPress* ConstructVK(TCHAR ch);
00224 
00225     // Lets you find out if the key press is a valid one
00226     BOOL IsValid();
00227 
00228     // Discover the key-related bits with these lovely public funcs
00229     UINT32  GetVirtKey()    { return VirtKey; } // Returns the virtual key code
00230     WCHAR   GetUnicode()    { return Unicode; } // Returns the unicode char generated by the virtual key
00231 
00232     // Public access functions to the various flags of a key press (see later for flag descriptions)
00233     BOOL IsAdjust()         { return Adjust; }
00234     BOOL IsConstrain()      { return Constrain; }
00235     BOOL IsAlternative()    { return Alternative; }
00236     BOOL IsOption()         { return Option; }
00237     BOOL IsModified()       { return (IsAdjust() || IsConstrain() || IsAlternative() || IsOption()); }
00238 
00239     BOOL IsExtended()       { return Extended; }
00240     BOOL IsRepeat()         { return Repeat; }
00241     BOOL IsRightHand()      { return RightHand; }
00242     BOOL IsRelease()        { return Release; }
00243     BOOL IsChar()           { return m_fIsChar; }
00244     BOOL IsPress()          { return !m_fIsChar && !Release; }
00245     BOOL IsOkInDrags()      { return WorksInDrag; }
00246 
00247     // The all-important equivalence operator
00248     // Main users of this are HotKey and ToolSwitch, which need to do key combination comparisons
00249     // Note: this does NOT compare the Unicode element of KeyPress objects.
00250     //       To do this you'll have to do pKeyPress1->GetUnicode() == pKeyPress2->GetUnicode()
00251     //       This is because the same unicode char could theoretically be produced by different
00252     //       key combinations, so a full comparison of two key presses may produce "not equal" when
00253     //       they have the same unicode char.
00254     INT32 operator==(const KeyPress& ); 
00255 
00256 #if defined(_DEBUG) && defined(__WXMSW__)
00257     static void DumpKeyMessage(wxKeyEvent* pMsg);
00258 #endif
00259 
00260     static BOOL AddVirtualKeyCode(UINT32 VCode, WCHAR Unicode);
00261     static void RemoveVirtualKeyCode(UINT32 VCode, WCHAR Unicode);
00262 
00263 private:
00264     // The default constuctor is private in order to force others to use one of the public constructors
00265     // or static member functions to create an instance of KeyPress
00266     KeyPress();
00267     void Initialise();
00268 
00269     static BOOL         GenerateKeyPress( wxKeyEvent *pMsg,KeyPress **ppKeyPress );
00270     static INT32        GenerateUnicode(UINT32 VirtKey,UINT32 ScanCode,BYTE* pKeyState,WCHAR* pWideCharBuf,UINT32 WideCharBufSize);
00271     static BOOL         IgnoreKeyMessage(KeyPressSysMsg* pKeySysMsg);
00272     static BOOL         IsModifier(UINT32 VirtKey);
00273     static void         UpdateModifierStatus(KeyPressSysMsg* pKeySysMsg);
00274     static KeyPress*    MakeKeyPress(KeyPressSysMsg* pKeySysMsg);
00275     static BOOL         EscapePressed(KeyPress* pKeyPress);
00276 
00277     UINT32  VirtKey;            // The virtual key code for the key
00278     WCHAR Unicode;          // The Unicode char that the virtual key generates
00279 
00280     BOOL Adjust      : 1;   // Key press modified by the Adjust modifier (usu. shift)
00281     BOOL Constrain   : 1;   // Key press modified by the Constrain modifier (usu. ctrl)
00282     BOOL Alternative : 1;   // Key press modified by the Alternative modifier (usu. alt)
00283     BOOL Option      : 1;   // Key press modified by the Option modifier (usu. Mac option key)
00284 
00285     BOOL Extended    : 1;   // The key was one of the extended keys (e.g. right-hand ctrl key)
00286 
00287     BOOL Repeat      : 1;   // The key press was generated by an auto-repeat (i.e. not the original keypress)
00288     BOOL RightHand   : 1;   // The key press was generated by a right-hand equivelent (e.g. 'Enter' and not 'Return')
00289     BOOL Release     : 1;   // The key has just been released (e.g. Windows KEYUP event)
00290     BOOL m_fIsChar   : 1; 
00291 
00292     BOOL Valid       : 1;   // Validity bit. Set means object is ok, clear means DON'T TOUCH IT!
00293     BOOL WorksInDrag : 1;   // TRUE if this keypress will work in the middle of a drag
00294 
00295     // These next vars hold the current state of the various modifier keys.
00296     // TRUE means the key is down, FALSE means the key is up
00297     static BOOL AdjustStateLeft;
00298     static BOOL AdjustStateRight;
00299     static BOOL ConstrainStateLeft;
00300     static BOOL ConstrainStateRight;
00301     static BOOL AlternativeStateLeft;
00302     static BOOL AlternativeStateRight;
00303     static BOOL OptionStateLeft;
00304     static BOOL OptionStateRight;
00305 
00306     // TRUE if the one or more of the modifier keys changed on the last keypress
00307     static BOOL fModifierChanged;
00308 
00309     // This info is used to generate WM_CHAR messages via Alt and the numerical key pad
00310     static INT32 AsciiVal;
00311     static BOOL ValidAsciiVal;
00312 
00313     // The last Lead Byte recived
00314     static BYTE LastLeadByte;
00315 
00316     // One list of additional runtime virtual key codes
00317     static List AdditionalVirtKeys;
00318 
00319 };
00320 
00321 #endif  // INC_KEYPRESS
00322 
00323 

Generated on Sat Nov 10 03:48:38 2007 for Camelot by  doxygen 1.4.4