summaryrefslogtreecommitdiffstats
path: root/private/os2/os2ses/kbdnls.c
blob: 26d6c5207a0f9430fd26e86eb6680f46fff5c9f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    kbdnls.c

Abstract:

    This module contains the NLS support for Kbd.

Author:

    KazuM 15-May-1992

Environment:

    User Mode Only

Revision History:

--*/

#ifdef DBCS

// If NLS module for console doesn't present, then NO_CONSOLE_NLS switch should be enable 
// difinition.
// If NLS module for User doesn't present, then NO_IME switch should be enable difinition.
//#define NO_CONSOLE_NLS
//#define NO_IME

#include <stdio.h>
#define WIN32_ONLY
#include "os2ses.h"
#include "event.h"
#include "trans.h"
#ifndef NO_IME
#include <ime.h>
#endif

#ifndef NO_CONSOLE_NLS
typedef struct _NLS_SHIFT_REPORT {
    WORD wVirtualKeyCode;
    BYTE NlsShiftKeyCode;
} NLS_SHIFT_REPORT, *PNLS_SHIFT_REPORT;

NLS_SHIFT_REPORT NlsShiftReport[] = {
    {VK_DBE_ALPHANUMERIC, 0x80},
    {VK_DBE_KATAKANA,     0x40},
    {VK_DBE_HIRAGANA,     0x20},
    {VK_KANJI,            0x10},
    {VK_DBE_SBCSCHAR,     0x08},
    {VK_DBE_DBCSCHAR,     0x08}
};
#endif

BYTE
MapWinToOs2KbdNlsShift(IN PKEY_EVENT_RECORD WinKey)
{
    BYTE bNlsShift = LOBYTE(HIWORD(WinKey->dwControlKeyState));

// MSKK Aug.23.1993 V-AkihiS
//    if (bNlsShift & OS2_NLS_IME_CONVERSION)
//        return bNlsShift;
//    else
//        return 0;
    return bNlsShift;
}

BYTE
MapWinToOs2KbdInterim(IN PKEY_EVENT_RECORD WinKey)
{
    return (BYTE)(HIBYTE(HIWORD(WinKey->dwControlKeyState))+0x40);
}

// MSKK Aug.10.1993 V-AkihiS
ULONG
MapWinToOs2KbdNlsChar(IN  PKEY_EVENT_RECORD WinKey,
                      OUT PKBD_MON_PACKAGE    Os2KeyInfo)
{
// MSKK Oct.30.1992 V-AkihiS
// MSKK Aug.05.1993 V-AkihiS
    BOOL Dummy;
    BYTE AsciiDbcs[2];
    PBYTE Asc;
    ULONG NumBytes, i;

    NumBytes = sizeof(AsciiDbcs);
    NumBytes = WideCharToMultiByte(SesGrp->KbdCP,
                                   0,
                                   &WinKey->uChar.UnicodeChar,
                                   1,
                                   AsciiDbcs,
                                   NumBytes,
                                   NULL,
                                   &Dummy);
    Asc = AsciiDbcs;
    for (i = 0; i < NumBytes; i ++) {
        Os2KeyInfo[i].KeyInfo.chChar = *Asc++;
        Os2KeyInfo[i].KeyInfo.chScan = 0;
        Os2KeyInfo[i].KeyInfo.fbStatus = MapWinToOs2KbdInterim(WinKey);
    }

#if DBG
    IF_OD2_DEBUG(KBD)
    {
        KdPrint(("MapWinToOs2KbdNlsChar: ASCII %x, Uni %x, VKey %x, VScan %x, Ctrl %lx =>\n       ASCII %x, Scan %x\n",
            WinKey->uChar.AsciiChar, WinKey->uChar.UnicodeChar,
            WinKey->wVirtualKeyCode, WinKey->wVirtualScanCode,
            WinKey->dwControlKeyState,
            Os2KeyInfo[0].KeyInfo.chChar, Os2KeyInfo[0].KeyInfo.chScan));
    }
#endif
    return NumBytes;
}

BYTE
MapWinToOs2KbdNlsShiftReport(IN PKEY_EVENT_RECORD WinKey,
                             IN PKBDKEYINFO       Os2Key)
{
    int i;

#ifndef NO_CONSOLE_NLS
    if (Os2Key->bNlsShift & OS2_NLS_IME_CONVERSION)
    {
        for (i=0; i < sizeof(NlsShiftReport)/sizeof(NLS_SHIFT_REPORT); i++)
            if (NlsShiftReport[i].wVirtualKeyCode == WinKey->wVirtualKeyCode)
                if (WinKey->bKeyDown)
                    return NlsShiftReport[i].NlsShiftKeyCode;
    }
#endif    
    return 0;
}

VOID
GetNlsMode(IN PKBDINFO KbdInfo)
{
    DWORD dwNlsMode;
    BYTE NlsShift;
    BYTE Interim;

#ifndef NO_CONSOLE_NLS
    if (!GetConsoleNlsMode(hConsoleInput,&dwNlsMode)) {
#if DBG
        IF_OD2_DEBUG2( KBD, OS2_EXE )
            KdPrint(("GetNlsMode: Can not get CONIN NLS Mode\n"));
#endif
        dwNlsMode = 0;
    }
#else
    dwNlsMode = 0;
#endif

    NlsShift = LOBYTE(HIWORD(dwNlsMode));
    Interim = HIBYTE(HIWORD(dwNlsMode));
    KbdInfo->fsInterim = MAKEWORD((KbdInfo->fsInterim | Interim),NlsShift);
}

VOID
SetNlsMode(IN KBDINFO KbdInfo)
{
    DWORD dwNlsMode;
    BYTE NlsShift;
    BYTE Interim;

    NlsShift = HIBYTE(KbdInfo.fsInterim);
    Interim = LOBYTE(KbdInfo.fsInterim);
    dwNlsMode = MAKELONG(0, MAKEWORD(NlsShift,Interim));

#ifndef NO_CONSOLE_NLS
// MSKK Apr.04.1993 V-AkihiS
// MSKK Aug.23.1993 V-AkihiS
    //
    // When hiragana or sbcsdbcs is set, set IME enable flag too. 
    //
    if (dwNlsMode & (NLS_DBCSCHAR | NLS_HIRAGANA)) {
        dwNlsMode |= NLS_IME_CONVERSION;
    }

    if (!SetConsoleNlsMode(hConsoleInput,dwNlsMode)) {
#if DBG
        IF_OD2_DEBUG2( KBD, OS2_EXE )
            KdPrint(("SetNlsMode: Can not set CONIN NLS Mode\n"));
#endif
        dwNlsMode = 0;
    }
#endif

}
#endif