Back to index

plt-scheme  4.2.1
EvtHandler.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: base event handler of windows etc.
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifdef __GNUG__
00028 #pragma implementation "EvtHandler.h"
00029 #endif
00030 
00031 #define  Uses_XLib
00032 #define  Uses_wxEvtHandler
00033 #include "wx.h"
00034 
00035 //-----------------------------------------------------------------------------
00036 // create/destroy wxEvtHandler
00037 //-----------------------------------------------------------------------------
00038 
00039 wxEvtHandler::wxEvtHandler(void)
00040 {
00041 }
00042 
00043 wxEvtHandler::~wxEvtHandler(void)
00044 {
00045 }
00046 
00047 //-----------------------------------------------------------------------------
00048 // translate between WX and X key symbols
00049 //-----------------------------------------------------------------------------
00050 
00051 #include <X11/keysym.h>
00052 
00053 typedef struct { KeySym x; int wx; } key_equiv;
00054 
00055 #ifndef XK_ISO_Left_Tab
00056 # define     XK_ISO_Left_Tab                                 0xFE20
00057 #endif
00058 
00059 static key_equiv key_translation[] = {
00060     { XK_Shift_L,    WXK_SHIFT },
00061     { XK_Shift_R,    WXK_SHIFT },
00062     { XK_Control_L,  WXK_CONTROL },
00063     { XK_Control_R,  WXK_CONTROL },
00064 #ifdef old_linux_keys
00065     { XK_Delete,     WXK_BACK },   // results from my private
00066     { XK_Find,              WXK_DELETE }, // keyboard mapping
00067 #else
00068     { XK_BackSpace,  WXK_BACK },
00069     { XK_Delete,     WXK_DELETE },
00070 #endif
00071     { XK_Clear,             WXK_CLEAR },
00072     { XK_Tab,        WXK_TAB },
00073     { XK_ISO_Left_Tab,  WXK_TAB },
00074     { XK_numbersign, '#' },
00075     { XK_Return,     WXK_RETURN },
00076     { ' ',           WXK_SPACE }, // necessary because of >XK_KP_Space = ' '<
00077     { XK_Escape,     WXK_ESCAPE },
00078     { XK_Pause,             WXK_PAUSE },
00079     { XK_Break,             WXK_PAUSE },
00080     { XK_Num_Lock,   WXK_NUMLOCK },
00081     { XK_Scroll_Lock,       WXK_SCROLL },
00082     { XK_Home,              WXK_HOME },
00083     { XK_End,        WXK_END },
00084     { XK_Left,              WXK_LEFT },
00085     { XK_Right,             WXK_RIGHT },
00086     { XK_Up,         WXK_UP },
00087     { XK_Down,              WXK_DOWN },
00088     { XK_Next,              WXK_NEXT },
00089     { XK_Prior,             WXK_PRIOR },
00090     { XK_Menu,              WXK_MENU },
00091     { XK_Select,     WXK_SELECT },
00092     { XK_Cancel,     WXK_CANCEL },
00093     { XK_Print,             WXK_PRINT },
00094     { XK_Execute,    WXK_EXECUTE },
00095     { XK_Insert,     WXK_INSERT },
00096     { XK_Help,              WXK_HELP },
00097     { XK_KP_Multiply,       WXK_MULTIPLY },
00098     { XK_KP_Add,     WXK_ADD },
00099     { XK_KP_Subtract,       WXK_SUBTRACT },
00100     { XK_KP_Divide,  WXK_DIVIDE },
00101     { XK_KP_Decimal, WXK_DECIMAL },
00102     { XK_KP_Equal,   '=' },
00103     { XK_KP_Space,   ' ' },
00104     { XK_KP_Tab,     WXK_TAB },
00105     { XK_KP_Enter,   3 },
00106     { XK_KP_0,              WXK_NUMPAD0 },
00107     { XK_KP_1,              WXK_NUMPAD1 },
00108     { XK_KP_2,              WXK_NUMPAD2 },
00109     { XK_KP_3,              WXK_NUMPAD3 },
00110     { XK_KP_4,              WXK_NUMPAD4 },
00111     { XK_KP_5,              WXK_NUMPAD5 },
00112     { XK_KP_6,              WXK_NUMPAD6 },
00113     { XK_KP_7,              WXK_NUMPAD7 },
00114     { XK_KP_8,              WXK_NUMPAD8 },
00115     { XK_KP_9,              WXK_NUMPAD9 },
00116     { XK_F1,         WXK_F1 },
00117     { XK_F2,         WXK_F2 },
00118     { XK_F3,         WXK_F3 },
00119     { XK_F4,         WXK_F4 },
00120     { XK_F5,         WXK_F5 },
00121     { XK_F6,         WXK_F6 },
00122     { XK_F7,         WXK_F7 },
00123     { XK_F8,         WXK_F8 },
00124     { XK_F9,         WXK_F9 },
00125     { XK_F10,        WXK_F10 },
00126     { XK_F11,        WXK_F11 },
00127     { XK_F12,        WXK_F12 },
00128     { XK_F13,        WXK_F13 },
00129     { XK_F14,        WXK_F14 },
00130     { XK_F15,        WXK_F15 },
00131     { XK_F16,        WXK_F16 },
00132     { XK_F17,        WXK_F17 },
00133     { XK_F18,        WXK_F18 },
00134     { XK_F19,        WXK_F19 },
00135     { XK_F20,        WXK_F20 },
00136     { XK_F21,        WXK_F21 },
00137     { XK_F22,        WXK_F22 },
00138     { XK_F23,        WXK_F23 },
00139     { XK_F24,        WXK_F24 }
00140 };
00141 
00142 int CharCodeXToWX(KeySym key_sym)
00143 {
00144   // first try translation
00145   int i;
00146 
00147   for (i=0; i < wxNumberOf(key_translation); ++i) {
00148     if (key_sym == key_translation[i].x)
00149       return key_translation[i].wx;
00150   }
00151 
00152   // try displayable keysyms
00153   if (key_sym <= 255)
00154     return (int)key_sym;
00155 
00156   // keysym not handled by wx
00157   return 0;
00158 }
00159 
00160 KeySym CharCodeWXToX(int id)
00161 {
00162   int i;
00163   
00164   if (!id)
00165     return 0;
00166 
00167   // first try translation
00168   for (i=0; i < wxNumberOf(key_translation); ++i) {
00169     if (id == key_translation[i].wx)
00170       return key_translation[i].x;
00171   }
00172 
00173   // try displayable keysyms
00174   if (id <= 255)
00175     return KeySym(id);
00176 
00177   // keysym not handled by wx
00178   return 0;
00179 }
00180 
00181 Bool wxIsAlt(KeySym key_sym)
00182 {
00183   if ((key_sym == XK_Alt_L) || (key_sym == XK_Alt_R)
00184       || (key_sym == XK_Meta_L) || (key_sym == XK_Meta_R)) {
00185     return TRUE;
00186   }
00187 
00188   return FALSE;
00189 }