Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenkeytrans.cpp
Go to the documentation of this file.
00001 00002 //Telnet Win32 : an ANSI telnet client. 00003 //Copyright (C) 1998-2000 Paul Brannan 00004 //Copyright (C) 1998 I.Ioannou 00005 //Copyright (C) 1997 Brad Johnson 00006 // 00007 //This program is free software; you can redistribute it and/or 00008 //modify it under the terms of the GNU General Public License 00009 //as published by the Free Software Foundation; either version 2 00010 //of the License, or (at your option) any later version. 00011 // 00012 //This program is distributed in the hope that it will be useful, 00013 //but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 //GNU General Public License for more details. 00016 // 00017 //You should have received a copy of the GNU General Public License 00018 //along with this program; if not, write to the Free Software 00019 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 // 00021 //I.Ioannou 00022 //roryt@hol.gr 00023 // 00025 00027 // Key translations - I.Ioannou (roryt@hol.gr) // 00028 // Athens - Greece December 18, 1996 02:56am // 00029 // Reads a .cfg file and keeps the definitions // 00030 // modified for alternate keymap swiching // 00031 // by Andrey V. Smilianets (smile@head.aval.kiev.ua) // 00032 // Kiev - Ukraine, December 1997. // 00033 // modified to work with MSVC and the Standard Template // 00034 // library by Paul Brannan <pbranna@clemson.edu>, // 00035 // May 25, 1998 // 00036 // updated June 7, 1998 by Paul Brannan to remove cout and // 00037 // cerr statements // 00038 // APP_KEY and APP2_Key added July 12, 1998 by Paul Brannan // 00040 // class KeyTranslator // 00041 // Load : loads or replaces the keymap // 00042 // TranslateKey : returns a char * to the key def // 00043 // AddKeyDef : Changes or adds the key translation // 00044 // DeleteKeyDef : Deletes a key def from the list // 00046 00047 #include "precomp.h" 00048 00050 // class KeyTranslator // 00051 // Load : loads or replaces the keymap // 00052 // TranslateKey : returns a sz to the key def // 00053 // AddKeyDef : Changes or adds the key translation // 00054 // DeleteKeyDef : Deletes a key def from the list // 00056 00057 00058 KeyTranslator::KeyTranslator(): 00059 mapArray(0,0,sizeof(KeyMap)), 00060 globals(0,0,sizeof(TKeyDef)) { 00061 ext_mode = 0; // Paul Brannan 8/28/98 00062 currentKeyMap = mainKeyMap = -1; 00063 }; 00064 00065 //AVS 00066 // perform keymap switching 00067 int KeyTranslator::switchMap(TKeyDef& tk) { 00068 if ( mapArray.IsEmpty() ) { 00069 return currentKeyMap = -1; 00070 }; 00071 int i = mapArray.Find(KeyMap(tk)); 00072 if ( i != INT_MAX ) { 00073 if (currentKeyMap == i) 00074 currentKeyMap = mainKeyMap; // restore to default 00075 else currentKeyMap = i; 00076 return 1; 00077 }; 00078 return 0; 00079 }; 00080 00081 // Let the calling function interpret the error code (Paul Brannan 12/17/98) 00082 int KeyTranslator::SwitchTo(int to) { 00083 00084 int max = mapArray.GetItemsInContainer(); 00085 if (max == 0) return -1; 00086 if (to < 0 || to > (max-1)) return 0; 00087 00088 currentKeyMap = to; 00089 return 1; 00090 }; 00091 00092 //AVS 00093 // rewrited to support multiple keymaps 00094 const char *KeyTranslator::TranslateKey(WORD wVirtualKeyCode, 00095 DWORD dwControlKeyState) 00096 { 00097 if ( mapArray.IsEmpty() ) return NULL; 00098 00099 TKeyDef ask(NULL, dwControlKeyState, wVirtualKeyCode); 00100 00101 // if a keymap switch pressed 00102 if ( switchMap(ask) > 0 ) return ""; 00103 00104 int i = mapArray[currentKeyMap].map.Find(ask); 00105 00106 if ( i != INT_MAX) return mapArray[currentKeyMap].map[i].GetszKey(); 00107 00108 // if not found in current keymap 00109 if ( currentKeyMap != mainKeyMap ) { 00110 i = mapArray[mainKeyMap].map.Find(ask); 00111 if ( i != INT_MAX) return mapArray[mainKeyMap].map[i].GetszKey(); 00112 }; 00113 return NULL; 00114 }; 00115 00116 00117 //AVS 00118 // rewrited to support multiple keymaps 00119 int KeyTranslator::AddKeyDef(WORD wVirtualKeyCode, DWORD dwControlKeyState, 00120 char*lpzKeyDef) 00121 { 00122 if ( ! mapArray[currentKeyMap].map.IsEmpty() ) { 00123 int i = mapArray[currentKeyMap].map.Find(TKeyDef(NULL, dwControlKeyState, wVirtualKeyCode)); 00124 if ( i != INT_MAX) { 00125 mapArray[currentKeyMap].map[i] = lpzKeyDef; 00126 return 1; 00127 } 00128 }; 00129 return mapArray[currentKeyMap].map.Add( TKeyDef(lpzKeyDef, dwControlKeyState, wVirtualKeyCode)); 00130 } 00131 00132 // Paul Brannan Feb. 22, 1999 00133 int KeyTranslator::AddKeyDef(WORD wVirtualKeyCode, DWORD dwControlKeyState, 00134 tn_ops the_op) 00135 { 00136 optype op; 00137 op.sendstr = 0; 00138 op.the_op = the_op; 00139 if ( ! mapArray[currentKeyMap].map.IsEmpty() ) { 00140 int i = mapArray[currentKeyMap].map.Find(TKeyDef(NULL, dwControlKeyState, wVirtualKeyCode)); 00141 if ( i != INT_MAX) { 00142 mapArray[currentKeyMap].map[i] = op; 00143 return 1; 00144 } 00145 }; 00146 return mapArray[currentKeyMap].map.Add( TKeyDef(op, dwControlKeyState, wVirtualKeyCode)); 00147 } 00148 00149 // AVS 00150 int KeyTranslator::LookOnGlobal(char* vkey) { 00151 if ( ! globals.IsEmpty() ) { 00152 int max = globals.GetItemsInContainer(); 00153 for ( int i = 0; i < max ; i++ ) 00154 if ( stricmp(globals[i].GetszKey(), vkey) == 0 ) 00155 return i; 00156 }; 00157 return INT_MAX; 00158 }; 00159 00160 int KeyTranslator::AddGlobalDef(WORD wVirtualKeyCode, char*lpzKeyDef) { 00161 if ( ! globals.IsEmpty() ) { 00162 int max = globals.GetItemsInContainer(); 00163 for ( int i = 0; i < max ; i++ ) { 00164 const char *s = globals[i].GetszKey(); 00165 if ( stricmp(s, lpzKeyDef) == 0 ) { 00166 globals[i] = DWORD(wVirtualKeyCode); 00167 return 1; 00168 } 00169 } 00170 } 00171 return globals.Add( TKeyDef(lpzKeyDef, 0, wVirtualKeyCode)); 00172 } 00173 00174 00175 //AVS 00176 // rewrited to support multiple keymaps 00177 int KeyTranslator::DeleteKeyDef(WORD wVirtualKeyCode, DWORD dwControlKeyState) 00178 { 00179 if ( mapArray.IsEmpty() || mapArray[currentKeyMap].map.IsEmpty() ) 00180 return 0; 00181 00182 int i = mapArray[currentKeyMap].map.Find(TKeyDef(NULL, dwControlKeyState, wVirtualKeyCode)); 00183 00184 if ( i != INT_MAX) { 00185 mapArray[currentKeyMap].map.Destroy(i); 00186 return 1; 00187 }; 00188 return 0; 00189 }; 00190 00191 //AVS 00192 // rewritten to support multiple keymaps 00193 void KeyTranslator::DeleteAllDefs(void) 00194 { 00195 // This code wants to crash under the STL; Apparently the Destroy() 00196 // function actually deletes the entry, rather than simply releasing 00197 // memory. I think flush() should do the same thing, at least the 00198 // way it is written with STL_BIDS (Paul Brannan 5/25/98). 00199 int max; 00200 00201 max = mapArray.GetItemsInContainer(); 00202 if ( ! mapArray.IsEmpty() ) { 00203 for ( int i = 0; i < max; i++ ) { 00204 if ( !mapArray[i].map.IsEmpty() ) { 00205 mapArray[i].map.Flush(); 00206 }; 00207 }; 00208 }; 00209 globals.Flush(); 00210 mapArray.Flush(); 00211 currentKeyMap = -1; 00212 mainKeyMap = -1; 00213 }; Generated on Sun May 27 2012 04:17:16 for ReactOS by
1.7.6.1
|