Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

scim_event.h

Go to the documentation of this file.
00001 /**
00002  * @file scim_event.h
00003  * @brief Defines the scim::KeyEvent class and related enums, functions.
00004  */
00005 
00006 /* 
00007  * Smart Common Input Method
00008  * 
00009  * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
00010  * Copyright (c) 2003 James Su <suzhe@turbolinux.com.cn>
00011  * Copyright (c) 2002 James Su <suzhe@turbolinux.com.cn>
00012  *
00013  *
00014  * This library is free software; you can redistribute it and/or
00015  * modify it under the terms of the GNU Lesser General Public
00016  * License as published by the Free Software Foundation; either
00017  * version 2 of the License, or (at your option) any later version.
00018  *
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this program; if not, write to the
00026  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00027  * Boston, MA  02111-1307  USA
00028  *
00029  * $Id: scim_event.h,v 1.15 2004/02/12 09:40:11 suzhe Exp $
00030  */
00031 
00032 #ifndef __SCIM_EVENT_H
00033 #define __SCIM_EVENT_H
00034 
00035 namespace scim {
00036 
00037 /**
00038  * @addtogroup Helper
00039  * @{
00040  */
00041 
00042 /**
00043  * @brief Enum values of all valid key masks.
00044  *
00045  * The key masks indicate which modifier keys
00046  * is pressed down during the keyboard hit.
00047  *
00048  * The special SCIM_KEY_ReleaseMask indicates
00049  * the key release event.
00050  */
00051 enum KeyMask
00052 {
00053     SCIM_KEY_NullMask     = 0,        /**< Key press event without modifier key. */
00054     SCIM_KEY_ShiftMask   = (1<<0),    /**< The shift key is pressed down */
00055     SCIM_KEY_LockMask    = (1<<1),    /**< The lock key is pressed down */
00056     SCIM_KEY_CapsLockMask= (1<<1),    /**< The caps lock key is pressed down */
00057     SCIM_KEY_ControlMask = (1<<2),    /**< The ctrl key is pressed down */
00058     SCIM_KEY_AltMask     = (1<<3),    /**< The alt key is pressed down */
00059     SCIM_KEY_Mod1Mask    = (1<<3),    /**< The mod1 key is pressed down */
00060     SCIM_KEY_Mod2Mask    = (1<<4),    /**< The mod2 key is pressed down */
00061     SCIM_KEY_NumLockMask = (1<<4),    /**< The num lock key is pressed down */
00062     SCIM_KEY_Mod3Mask    = (1<<5),    /**< The mod3 key is pressed down */
00063     SCIM_KEY_Mod4Mask    = (1<<6),    /**< The mod4 key is pressed down */
00064     SCIM_KEY_Mod5Mask    = (1<<7),    /**< The mod5 key is pressed down */
00065     SCIM_KEY_ScrollLockMask = (1<<7), /**< The scroll lock key is pressed down */
00066     SCIM_KEY_ReleaseMask = (1<<30)    /**< It's a key release event */
00067 };
00068 
00069 /**
00070  * @brief Enum values of all valid key codes.
00071  */
00072 enum KeyCode
00073 {
00074     SCIM_KEY_NullKey     = 0,
00075 
00076     /* modifier keys */
00077     SCIM_KEY_Shift_L     = 0xFFE1,    /* Left shift */
00078     SCIM_KEY_Shift_R     = 0xFFE2,    /* Right shift */
00079     SCIM_KEY_Control_L   = 0xFFE3,    /* Left control */
00080     SCIM_KEY_Control_R   = 0xFFE4,    /* Right control */
00081     SCIM_KEY_Caps_Lock   = 0xFFE5,    /* Caps lock */
00082     SCIM_KEY_Shift_Lock  = 0xFFE6,    /* Shift lock */
00083 
00084     SCIM_KEY_Meta_L      = 0xFFE7,    /* Left meta */
00085     SCIM_KEY_Meta_R      = 0xFFE8,    /* Right meta */
00086     SCIM_KEY_Alt_L       = 0xFFE9,    /* Left alt */
00087     SCIM_KEY_Alt_R       = 0xFFEA,    /* Right alt */
00088     SCIM_KEY_Super_L     = 0xFFEB,    /* Left super */
00089     SCIM_KEY_Super_R     = 0xFFEC,    /* Right super */
00090     SCIM_KEY_Hyper_L     = 0xFFED,    /* Left hyper */
00091     SCIM_KEY_Hyper_R     = 0xFFEE,    /* Right hyper */
00092 
00093     /* function keys */
00094     SCIM_KEY_BackSpace   = 0xFF08,    /* back space, back char */
00095     SCIM_KEY_Tab         = 0xFF09,
00096     SCIM_KEY_Linefeed    = 0xFF0A,    /* Linefeed, LF */
00097     SCIM_KEY_Clear       = 0xFF0B,
00098     SCIM_KEY_Return      = 0xFF0D,    /* Return, enter */
00099     SCIM_KEY_Pause       = 0xFF13,    /* Pause, hold */
00100     SCIM_KEY_Scroll_Lock = 0xFF14,
00101     SCIM_KEY_Sys_Req     = 0xFF15,
00102     SCIM_KEY_Escape      = 0xFF1B,
00103     SCIM_KEY_Delete      = 0xFFFF,    /* Delete, rubout */
00104 
00105     /* International & multi-key character composition */
00106     SCIM_KEY_Multi_key   = 0xFF20,    /* Multi-key character compose */
00107     SCIM_KEY_Codeinput   = 0xFF37,
00108     SCIM_KEY_SingleCandidate   = 0xFF3C,
00109     SCIM_KEY_MultipleCandidate = 0xFF3D,
00110     SCIM_KEY_PreviousCandidate = 0xFF3E,
00111 
00112     /* Japanese keyboard support */
00113     SCIM_KEY_Kanji       = 0xFF21,    /* Kanji, Kanji convert */
00114     SCIM_KEY_Muhenkan    = 0xFF22,    /* Cancel Conversion */
00115     SCIM_KEY_Henkan_Mode = 0xFF23,    /* Start/Stop Conversion */
00116     SCIM_KEY_Henkan      = 0xFF23,    /* Alias for Henkan_Mode */
00117     SCIM_KEY_Romaji      = 0xFF24,    /* to Romaji */
00118     SCIM_KEY_Hiragana    = 0xFF25,    /* to Hiragana */
00119     SCIM_KEY_Katakana    = 0xFF26,    /* to Katakana */
00120     SCIM_KEY_Hiragana_Katakana = 0xFF27, /* Hiragana/Katakana toggle */
00121     SCIM_KEY_Zenkaku     = 0xFF28,    /* to Zenkaku */
00122     SCIM_KEY_Hankaku     = 0xFF29,    /* to Hankaku */
00123     SCIM_KEY_Zenkaku_Hankaku   = 0xFF2A, /* Zenkaku/Hankaku toggle */
00124     SCIM_KEY_Touroku     = 0xFF2B,    /* Add to Dictionary */
00125     SCIM_KEY_Massyo      = 0xFF2C,    /* Delete from Dictionary */
00126     SCIM_KEY_Kana_Lock   = 0xFF2D,    /* Kana Lock */
00127     SCIM_KEY_Kana_Shift  = 0xFF2E,    /* Kana Shift */
00128     SCIM_KEY_Eisu_Shift  = 0xFF2F,    /* Alphanumeric Shift */
00129     SCIM_KEY_Eisu_toggle = 0xFF30,    /* Alphanumeric toggle */
00130     SCIM_KEY_Kanji_Bangou = 0xFF37,   /* Codeinput */
00131     SCIM_KEY_Zen_Koho    = 0xFF3D,    /* Multiple/All Candidate(s) */
00132     SCIM_KEY_Mae_Koho    = 0xFF3E,    /* Previous Candidate */
00133 
00134     /* Cursor control & motion */
00135     SCIM_KEY_Home        = 0xFF50,
00136     SCIM_KEY_Left        = 0xFF51,    /* Move left, left arrow */
00137     SCIM_KEY_Up          = 0xFF52,    /* Move up, up arrow */
00138     SCIM_KEY_Right       = 0xFF53,    /* Move right, right arrow */
00139     SCIM_KEY_Down        = 0xFF54,    /* Move down, down arrow */
00140     SCIM_KEY_Prior       = 0xFF55,    /* Prior, previous */
00141     SCIM_KEY_Page_Up     = 0xFF55,
00142     SCIM_KEY_Next        = 0xFF56,    /* Next */
00143     SCIM_KEY_Page_Down   = 0xFF56,
00144     SCIM_KEY_End         = 0xFF57,    /* EOL */
00145     SCIM_KEY_Begin       = 0xFF58,    /* BOL */
00146 
00147     /* Misc Functions */
00148     SCIM_KEY_Select      = 0xFF60,    /* Select, mark */
00149     SCIM_KEY_Print       = 0xFF61,
00150     SCIM_KEY_Execute     = 0xFF62,    /* Execute, run, do */
00151     SCIM_KEY_Insert      = 0xFF63,    /* Insert, insert here */
00152     SCIM_KEY_Undo        = 0xFF65,    /* Undo, oops */
00153     SCIM_KEY_Redo        = 0xFF66,    /* redo, again */
00154     SCIM_KEY_Menu        = 0xFF67,
00155     SCIM_KEY_Find        = 0xFF68,    /* Find, search */
00156     SCIM_KEY_Cancel      = 0xFF69,    /* Cancel, stop, abort, exit */
00157     SCIM_KEY_Help        = 0xFF6A,    /* Help */
00158     SCIM_KEY_Break       = 0xFF6B,
00159     SCIM_KEY_Mode_switch = 0xFF7E,    /* Character set switch */
00160     SCIM_KEY_Num_Lock    = 0xFF7F,
00161 
00162     /* keypad */
00163     SCIM_KEY_KP_Space    = 0xFF80,    /* space */
00164     SCIM_KEY_KP_Tab      = 0xFF89,
00165     SCIM_KEY_KP_Enter    = 0xFF8D,    /* enter */
00166     SCIM_KEY_KP_F1       = 0xFF91,    /* PF1, KP_A, ... */
00167     SCIM_KEY_KP_F2       = 0xFF92,
00168     SCIM_KEY_KP_F3       = 0xFF93,
00169     SCIM_KEY_KP_F4       = 0xFF94,
00170     SCIM_KEY_KP_Home     = 0xFF95,
00171     SCIM_KEY_KP_Left     = 0xFF96,
00172     SCIM_KEY_KP_Up       = 0xFF97,
00173     SCIM_KEY_KP_Right    = 0xFF98,
00174     SCIM_KEY_KP_Down     = 0xFF99,
00175     SCIM_KEY_KP_Prior    = 0xFF9A,
00176     SCIM_KEY_KP_Page_Up  = 0xFF9A,
00177     SCIM_KEY_KP_Next     = 0xFF9B,
00178     SCIM_KEY_KP_Page_Down= 0xFF9B,
00179     SCIM_KEY_KP_End      = 0xFF9C,
00180     SCIM_KEY_KP_Begin    = 0xFF9D,
00181     SCIM_KEY_KP_Insert   = 0xFF9E,
00182     SCIM_KEY_KP_Delete   = 0xFF9F,
00183     SCIM_KEY_KP_Equal    = 0xFFBD,   /* equals */
00184     SCIM_KEY_KP_Multiply = 0xFFAA,
00185     SCIM_KEY_KP_Add      = 0xFFAB,
00186     SCIM_KEY_KP_Separator= 0xFFAC,   /* separator, often comma */
00187     SCIM_KEY_KP_Subtract = 0xFFAD,
00188     SCIM_KEY_KP_Decimal  = 0xFFAE,
00189     SCIM_KEY_KP_Divide   = 0xFFAF,
00190 
00191     SCIM_KEY_KP_0        = 0xFFB0,
00192     SCIM_KEY_KP_1        = 0xFFB1,
00193     SCIM_KEY_KP_2        = 0xFFB2,
00194     SCIM_KEY_KP_3        = 0xFFB3,
00195     SCIM_KEY_KP_4        = 0xFFB4,
00196     SCIM_KEY_KP_5        = 0xFFB5,
00197     SCIM_KEY_KP_6        = 0xFFB6,
00198     SCIM_KEY_KP_7        = 0xFFB7,
00199     SCIM_KEY_KP_8        = 0xFFB8,
00200     SCIM_KEY_KP_9        = 0xFFB9,
00201 
00202     /* Auxilliary Functions */
00203     SCIM_KEY_F1          = 0xFFBE,
00204     SCIM_KEY_F2          = 0xFFBF,
00205     SCIM_KEY_F3          = 0xFFC0,
00206     SCIM_KEY_F4          = 0xFFC1,
00207     SCIM_KEY_F5          = 0xFFC2,
00208     SCIM_KEY_F6          = 0xFFC3,
00209     SCIM_KEY_F7          = 0xFFC4,
00210     SCIM_KEY_F8          = 0xFFC5,
00211     SCIM_KEY_F9          = 0xFFC6,
00212     SCIM_KEY_F10         = 0xFFC7,
00213     SCIM_KEY_F11         = 0xFFC8,
00214     SCIM_KEY_F12         = 0xFFC9,
00215 
00216     /* Latin 1 */
00217     SCIM_KEY_space       = 0x020,
00218     SCIM_KEY_exclam      = 0x021,
00219     SCIM_KEY_quotedbl    = 0x022,
00220     SCIM_KEY_numbersign  = 0x023,
00221     SCIM_KEY_dollar      = 0x024,
00222     SCIM_KEY_percent     = 0x025,
00223     SCIM_KEY_ampersand   = 0x026,
00224     SCIM_KEY_apostrophe  = 0x027,
00225     SCIM_KEY_quoteright  = 0x027,    /* deprecated */
00226     SCIM_KEY_parenleft   = 0x028,
00227     SCIM_KEY_parenright  = 0x029,
00228     SCIM_KEY_asterisk    = 0x02a,
00229     SCIM_KEY_plus        = 0x02b,
00230     SCIM_KEY_comma       = 0x02c,
00231     SCIM_KEY_minus       = 0x02d,
00232     SCIM_KEY_period      = 0x02e,
00233     SCIM_KEY_slash       = 0x02f,
00234     SCIM_KEY_0           = 0x030,
00235     SCIM_KEY_1           = 0x031,
00236     SCIM_KEY_2           = 0x032,
00237     SCIM_KEY_3           = 0x033,
00238     SCIM_KEY_4           = 0x034,
00239     SCIM_KEY_5           = 0x035,
00240     SCIM_KEY_6           = 0x036,
00241     SCIM_KEY_7           = 0x037,
00242     SCIM_KEY_8           = 0x038,
00243     SCIM_KEY_9           = 0x039,
00244     SCIM_KEY_colon       = 0x03a,
00245     SCIM_KEY_semicolon   = 0x03b,
00246     SCIM_KEY_less        = 0x03c,
00247     SCIM_KEY_equal       = 0x03d,
00248     SCIM_KEY_greater     = 0x03e,
00249     SCIM_KEY_question    = 0x03f,
00250     SCIM_KEY_at          = 0x040,
00251     SCIM_KEY_A           = 0x041,
00252     SCIM_KEY_B           = 0x042,
00253     SCIM_KEY_C           = 0x043,
00254     SCIM_KEY_D           = 0x044,
00255     SCIM_KEY_E           = 0x045,
00256     SCIM_KEY_F           = 0x046,
00257     SCIM_KEY_G           = 0x047,
00258     SCIM_KEY_H           = 0x048,
00259     SCIM_KEY_I           = 0x049,
00260     SCIM_KEY_J           = 0x04a,
00261     SCIM_KEY_K           = 0x04b,
00262     SCIM_KEY_L           = 0x04c,
00263     SCIM_KEY_M           = 0x04d,
00264     SCIM_KEY_N           = 0x04e,
00265     SCIM_KEY_O           = 0x04f,
00266     SCIM_KEY_P           = 0x050,
00267     SCIM_KEY_Q           = 0x051,
00268     SCIM_KEY_R           = 0x052,
00269     SCIM_KEY_S           = 0x053,
00270     SCIM_KEY_T           = 0x054,
00271     SCIM_KEY_U           = 0x055,
00272     SCIM_KEY_V           = 0x056,
00273     SCIM_KEY_W           = 0x057,
00274     SCIM_KEY_X           = 0x058,
00275     SCIM_KEY_Y           = 0x059,
00276     SCIM_KEY_Z           = 0x05a,
00277     SCIM_KEY_bracketleft = 0x05b,
00278     SCIM_KEY_backslash   = 0x05c,
00279     SCIM_KEY_bracketright= 0x05d,
00280     SCIM_KEY_asciicircum = 0x05e,
00281     SCIM_KEY_underscore  = 0x05f,
00282     SCIM_KEY_grave       = 0x060,
00283     SCIM_KEY_a           = 0x061,
00284     SCIM_KEY_b           = 0x062,
00285     SCIM_KEY_c           = 0x063,
00286     SCIM_KEY_d           = 0x064,
00287     SCIM_KEY_e           = 0x065,
00288     SCIM_KEY_f           = 0x066,
00289     SCIM_KEY_g           = 0x067,
00290     SCIM_KEY_h           = 0x068,
00291     SCIM_KEY_i           = 0x069,
00292     SCIM_KEY_j           = 0x06a,
00293     SCIM_KEY_k           = 0x06b,
00294     SCIM_KEY_l           = 0x06c,
00295     SCIM_KEY_m           = 0x06d,
00296     SCIM_KEY_n           = 0x06e,
00297     SCIM_KEY_o           = 0x06f,
00298     SCIM_KEY_p           = 0x070,
00299     SCIM_KEY_q           = 0x071,
00300     SCIM_KEY_r           = 0x072,
00301     SCIM_KEY_s           = 0x073,
00302     SCIM_KEY_t           = 0x074,
00303     SCIM_KEY_u           = 0x075,
00304     SCIM_KEY_v           = 0x076,
00305     SCIM_KEY_w           = 0x077,
00306     SCIM_KEY_x           = 0x078,
00307     SCIM_KEY_y           = 0x079,
00308     SCIM_KEY_z           = 0x07a,
00309     SCIM_KEY_braceleft   = 0x07b,
00310     SCIM_KEY_bar         = 0x07c,
00311     SCIM_KEY_braceright  = 0x07d,
00312     SCIM_KEY_asciitilde  = 0x07e
00313 };
00314 
00315 /**
00316  * @brief The class to store a keyboard event.
00317  *
00318  * A keyboard event contains a key code and a set of key masks.
00319  * The key masks indicate which modifier keys are pressed down and
00320  * if it's a key release event.
00321  */
00322 struct KeyEvent
00323 {
00324     int code;    /**< key code */
00325     int mask;    /**< modifier keys' mask */
00326 
00327     /**
00328      * @brief Constructor.
00329      * @param c - the key code.
00330      * @param m - the key masks.
00331      */
00332     KeyEvent (int c = 0, int m = 0)
00333         : code (c), mask (m) { }
00334 
00335     /**
00336      * @brief Check if this KeyEvent is empty.
00337      * @return true if this is a empty event.
00338      */
00339     bool empty () const { return mask == 0 && code == 0; }
00340 
00341     /**
00342      * @brief Get the ascii code of this key event.
00343      *
00344      * Not all key events have ascii codes.
00345      *
00346      * @return the ascii code of this key event.
00347      *         Zero means no ascii code.
00348      */
00349     char get_ascii_code () const;
00350 
00351     /**
00352      * @brief Check if the shift key is pressed down.
00353      */
00354     bool is_shift_down () const { return (mask & SCIM_KEY_ShiftMask) != 0; }
00355 
00356     /**
00357      * @brief Check if the lock key is pressed down.
00358      */
00359     bool is_lock_down () const { return (mask & SCIM_KEY_LockMask) != 0; }
00360 
00361     /**
00362      * @brief Check if the ctrl key is pressed down.
00363      */
00364     bool is_control_down () const { return (mask & SCIM_KEY_ControlMask) != 0; }
00365 
00366     /**
00367      * @brief Check if the alt key is pressed down.
00368      */
00369     bool is_alt_down () const { return is_mod1_down (); }
00370 
00371     /**
00372      * @brief Check if the mod1 key is pressed down.
00373      */
00374     bool is_mod1_down () const { return (mask & SCIM_KEY_Mod1Mask) != 0; }
00375 
00376     /**
00377      * @brief Check if the mod2 key is pressed down.
00378      */
00379     bool is_mod2_down () const { return (mask & SCIM_KEY_Mod2Mask) != 0; }
00380 
00381     /**
00382      * @brief Check if the mod3 key is pressed down.
00383      */
00384     bool is_mod3_down () const { return (mask & SCIM_KEY_Mod3Mask) != 0; }
00385 
00386     /**
00387      * @brief Check if the mod4 key is pressed down.
00388      */
00389     bool is_mod4_down () const { return (mask & SCIM_KEY_Mod4Mask) != 0; }
00390 
00391     /**
00392      * @brief Check if the mod5 key is pressed down.
00393      */
00394     bool is_mod5_down () const { return (mask & SCIM_KEY_Mod5Mask) != 0; }
00395 
00396     /**
00397      * @brief Check if the num lock key is pressed down.
00398      */
00399     bool is_num_lock_down () const { return (mask & SCIM_KEY_NumLockMask) != 0; }
00400 
00401     /**
00402      * @brief Check if the caps lock key is pressed down.
00403      */
00404     bool is_caps_lock_down () const { return (mask & SCIM_KEY_CapsLockMask) != 0; }
00405 
00406     /**
00407      * @brief Check if the scroll lock key is pressed down.
00408      */
00409     bool is_scroll_lock_down () const { return (mask & SCIM_KEY_ScrollLockMask) != 0; }
00410 
00411     /**
00412      * @brief Check if it's a key press event.
00413      */
00414     bool is_key_press () const { return (mask & SCIM_KEY_ReleaseMask) == 0; }
00415 
00416     /**
00417      * @brief Check if it's a key release event.
00418      */
00419     bool is_key_release () const { return (mask & SCIM_KEY_ReleaseMask) != 0; }
00420 
00421     /**
00422      * @brief Compare two key events.
00423      * @return true if they are equal.
00424      */
00425     bool operator == (const KeyEvent & key) const {
00426         return code == key.code && mask == key.mask;
00427     }
00428 
00429     /**
00430      * @brief Compare two key events.
00431      *
00432      * This operator is mainly for sorting.
00433      * 
00434      * @return true if the first is smaller.
00435      */
00436     bool operator < (const KeyEvent & key) const {
00437         return code < key.code || (code == key.code && mask < key.mask);
00438     }
00439 };
00440 
00441 /**
00442  * @typedef typedef std::vector<KeyEvent> KeyEventList
00443  * @brief The container to store a set of KeyEvent objects.
00444  *
00445  * You should use the STL container methods to manipulate its objects.
00446  */
00447 typedef std::vector<KeyEvent> KeyEventList;
00448 
00449 /**
00450  * @brief Convert a key event to a string.
00451  * @param str - the result string will be stored here.
00452  * @param key - the KeyEvent to be converted.
00453  * @return true if success.
00454  */
00455 bool scim_key_to_string (String &str, const KeyEvent & key);
00456 
00457 /**
00458  * @brief Convert a string to a KeyEvent.
00459  * @param key - the result KeyEvent will be stored here.
00460  * @param str - the string to be converted.
00461  * @return true if success.
00462  */
00463 bool scim_string_to_key (KeyEvent &key, const String & str);
00464 
00465 /**
00466  * @brief Convert a set of KeyEvents to a string.
00467  * @param str - the result string will be stored here.
00468  * @param keylist - the keys to be converted.
00469  * @return true if success.
00470  */
00471 bool scim_key_list_to_string (String &str, const KeyEventList & keylist);
00472 
00473 /**
00474  * @brief Covnert a string to a set of KeyEvents.
00475  * @param keylist - the result KeyEvents will be stored here.
00476  * @param str - the string to be converted.
00477  * @return true if success.
00478  */
00479 bool scim_string_to_key_list (KeyEventList &keylist, const String &str);
00480 
00481 /** @} */
00482 
00483 } // namespace scim
00484 
00485 #endif //__SCIM_EVENT_H
00486 
00487 /*
00488 vi:ts=4:nowrap:ai:expandtab
00489 */
00490 

Generated on Fri May 7 17:27:25 2004 for scim by doxygen 1.3.6