guimapky.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 649 行 · 第 1/2 页
C
649 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: GUI library key mapping for OS/2 and Windows.
*
****************************************************************************/
#include "guiwind.h"
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "guimapky.h"
#include "guixutil.h"
#include "guimkey.h"
extern gui_window *GUICurrWnd;
extern bool EditControlHasFocus;
extern gui_keystate KeyState;
#ifndef __OS2_PM__
static bool RetTrue = FALSE; /* set to TRUE of app returned
TRUE to last WM_SYSKEYDOWN or
WM_SYSKEYUP message */
#endif
typedef struct {
char value;
char regular;
char shifted;
gui_key alt;
gui_key ctrl;
} keytable;
static keytable vk_table[] = {
{ 0xbc, ',', '<', GUI_KEY_ALT_COMMA, 0 },
{ 0xbe, '.', '>', GUI_KEY_ALT_PERIOD, 0 },
{ 0xbf, '/', '?', GUI_KEY_ALT_SLASH, 0 },
{ 0xba, ';', ':', GUI_KEY_ALT_SEMICOLON, 0 },
{ 0xde, '\'', '"', GUI_KEY_ALT_QUOTE, 0 },
{ 0xdb, '[', '{', GUI_KEY_ALT_LEFT_BRACKET, GUI_KEY_CTRL_LEFT_BRACKET },
{ 0xdd, ']', '}', GUI_KEY_ALT_RIGHT_BRACKET, GUI_KEY_CTRL_RIGHT_BRACKET },
{ 0xdc, '\\', '|', GUI_KEY_ALT_BACKSLASH, GUI_KEY_CTRL_BACKSLASH },
{ 0xc0, '`', '~', GUI_KEY_ALT_BACKQUOTE, 0 },
{ 0xbd, '-', '_', GUI_KEY_ALT_MINUS, GUI_KEY_CTRL_MINUS },
{ 0xbb, '=', '+', GUI_KEY_ALT_EQUAL, 0 }
};
static char num_regular[] = "1234567890";
static char num_shifted[] = "!@#$%^&*()";
#ifndef __OS2_PM__
static char c_regular[] = "1234567890`-=[]\\;',./";
static char c_shifted[] = "!@#$%^&*()~_+{}|:\"<>?";
#else
static char c_regular[] = "1234567890`-=[]\\;',./*+";
static char c_shifted[] = "!@#$%^&*()~_+{}|:\"<>?*+";
#endif
#define EV_FUNC( n ) ( 0x13A + (n) )
#define EV_SHIFT_FUNC( n ) ( 0x153 + (n) )
#define EV_CTRL_FUNC( n ) ( 0x15d + (n) )
#define EV_ALT_FUNC( n ) ( 0x167 + (n) )
#define EV_CTRL( n ) ( (n) + 1 )
#define EV_KEYPAD_FUNC( n ) ( 0x030 + (n) )
#define EV_ALT_NUMS( n ) ( 0x178 + (n) )
static gui_key AltFunc[] =
{
GUI_KEY_ALT_A,
GUI_KEY_ALT_B,
GUI_KEY_ALT_C,
GUI_KEY_ALT_D,
GUI_KEY_ALT_E,
GUI_KEY_ALT_F,
GUI_KEY_ALT_G,
GUI_KEY_ALT_H,
GUI_KEY_ALT_I,
GUI_KEY_ALT_J,
GUI_KEY_ALT_K,
GUI_KEY_ALT_L,
GUI_KEY_ALT_M,
GUI_KEY_ALT_N,
GUI_KEY_ALT_O,
GUI_KEY_ALT_P,
GUI_KEY_ALT_K,
GUI_KEY_ALT_R,
GUI_KEY_ALT_S,
GUI_KEY_ALT_T,
GUI_KEY_ALT_U,
GUI_KEY_ALT_V,
GUI_KEY_ALT_W,
GUI_KEY_ALT_X,
GUI_KEY_ALT_Y,
GUI_KEY_ALT_Z
};
static bool convert_shiftkeys( WORD vk, gui_key *key,
char *regular, char *shifted )
{
char *str;
str = strchr( regular, vk );
if( SHIFT ) {
if( str != NULL ) {
*key = *(shifted+(str-regular));
return( TRUE );
} else {
str = strchr( shifted, vk );
if( str != NULL ) {
*key = *str;
return( TRUE );
}
}
} else if( !(CTRL) && !(ALT) ) {
if( str != NULL ) {
*key = *str;
return( TRUE );
}
}
return( FALSE );
}
static bool discard_this_vk( WORD vk )
{
bool discard;
discard = FALSE;
switch( vk ) {
case VK_SHIFT:
case VK_CONTROL:
case VK_CAPITAL :
#ifndef __OS2_PM__
case VK_MENU:
#endif
case VK_NUMLOCK :
case VK_PAUSE :
case VK_LBUTTON :
case VK_RBUTTON :
case VK_MBUTTON :
case VK_SNAPSHOT :
#ifdef __OS2_PM__
case VK_ALT :
#else
case VK_CLEAR :
case VK_SELECT :
case VK_CANCEL :
case VK_EXECUTE :
case VK_HELP :
case VK_SEPARATOR :
#endif
discard = TRUE;
break;
}
return( discard );
}
static bool convert_numeric( WORD ch, gui_key *key )
{
int t;
if( isdigit( ch ) ) {
if( SHIFT ) {
if( convert_shiftkeys( ch, key, num_regular, num_shifted ) ) return( TRUE );
*key = ch;
return( TRUE );
} else if( ALT ) {
t = ch - '1';
if( t == -1 ) {
t = 9;
}
*key = EV_ALT_NUMS( t );
return( TRUE );
} else if( CTRL ) {
if( ch == '2' ) {
*key = GUI_KEY_CTRL_2;
return( TRUE );
} else if( ch == '6' ) {
*key = GUI_KEY_CTRL_6;
return( TRUE );
}
} else {
*key = ch;
return( TRUE );
}
}
return( FALSE );
}
static bool convert_alpha( WORD ch, gui_key *key )
{
WORD t;
if( isalpha( ch ) ) {
t = toupper(ch) - 'A';
if( ALT ) {
*key = AltFunc[ t ];
} else if( CTRL ) {
*key = EV_CTRL( t );
} else if ( SHIFT ) {
*key = 'A'+ t;
} else {
*key = 'a' + t;
}
return( TRUE );
}
return( FALSE );
}
static bool convert_otherkeys( WORD vk, gui_key *key )
{
return( convert_shiftkeys( vk, key, c_regular, c_shifted ) );
}
static bool convert_ascii( WORD ch, gui_key *key )
{
if( convert_alpha( ch, key ) ) return( TRUE );
if( convert_numeric( ch, key ) ) return( TRUE );
if( convert_otherkeys( ch, key ) ) return( TRUE );
return( FALSE );
}
static bool convert_keytable( WORD vk, gui_key *key )
{
int i;
for( i=0; i < ( sizeof(vk_table) / sizeof(vk_table[0]) ); i++ ) {
if( vk == vk_table[i].value ) {
if( SHIFT ) {
*key = vk_table[i].shifted;
} else if ( ALT ) {
*key = vk_table[i].alt;
} else if ( CTRL ) {
*key = vk_table[i].ctrl;
} else {
*key = vk_table[i].regular;
}
return( TRUE );
}
}
return( FALSE );
}
#ifndef __OS2_PM__
static bool convert_numpad( WORD vk, gui_key *key )
{
if( ( vk >= VK_NUMPAD0 ) && ( vk <= VK_NUMPAD9 ) ) {
*key = EV_KEYPAD_FUNC( vk - VK_NUMPAD0 );
return( TRUE );
}
return( FALSE );
}
#endif
static bool GUIConvertVirtKeyToGUIKey( WORD vk, gui_key *key )
{
int t;
if( key == NULL ) {
return( FALSE );
}
*key = 0;
if( discard_this_vk( vk ) ) {
return( FALSE );
} else if( vk >= VK_F1 && vk <= VK_F10 ) {
t = vk - VK_F1 + 1;
if( ALT ) {
*key = EV_ALT_FUNC( t );
} else if( CTRL ) {
*key = EV_CTRL_FUNC( t );
} else if( SHIFT ) {
*key = EV_SHIFT_FUNC( t );
} else {
*key = EV_FUNC( t );
}
#ifndef __OS2_PM__
} else if( convert_numpad( vk, key ) ) {
// do nothing
#endif
} else {
switch( vk ) {
case VK_TAB:
*key = GUIMapKey( GUI_KEY_TAB );
break;
case VK_BACK:
*key= GUIMapKey( GUI_KEY_BACKSPACE );
break;
case VK_ESCAPE:
*key= GUIMapKey( GUI_KEY_ESCAPE );
break;
#ifdef __OS2_PM__
case VK_ENTER:
#endif
case VK_RETURN:
*key= GUIMapKey( GUI_KEY_ENTER );
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?