summaryrefslogtreecommitdiffstats
path: root/private/os2/os2ses/imrqust.c
blob: 804c57d5f5886aa3722b122c3e5dd7740cbbd5d6 (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    imrqust.c

Abstract:

    This module contains the Immon requests thread and
    the handler for Immon requests.

Author:

    Akihiko Sasaki (v-akihis) 18-Dec-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

#define WIN32_ONLY
#include "os2ses.h"
#include <stdio.h>
#ifndef NO_IME
#include <winnls32.h>
#endif


// From immonerr.h
#define IM_NO_ERROR             0  /* IMMonitor No Error Code              */
#define IM_GENERAL_ERROR     3081  /* IMMonitor General Error (Internal)   */
#define IM_INVALID_SEG       3082  /* Cannot access application segment    */
#define IM_INVALID_SESSION   3083  /* Cannot register into Monitor chain   */

#define IM_IME_NOT_FOUND     3084  /* specified IME is not found           */
#define IM_IME_INV_ENTRY     3085  /* IME doesnot have all IMExxx entries  */
#define IM_NO_DEFAULT_IME    3086  /* there is no default IMEdit           */
#define IM_IME_NOT_INSTALL   3087  /* IME is not installed in this SG      */
#define IM_IME_FAIL_INSTALL  3088  /* fail to install requested IMEdit     */
#define IM_INVALID_LEN       3089  /* Data Length is invalid. (name.....)  */

#define IM_NOT_ENOUGH_BUFF   3090  /* buffer is not enough to save data    */

#define IM_INVALID_COMMAND   3091  /* invalid command on IMMxxx calls      */
#define IM_RESERVED_COMMAND  3092  /* command is reserved for system use   */

#define IM_INVALID_HANDLE    3093  /* invalid handle                       */

#define IM_NO_XVIO_WINDOW    3094  /* there is no XVIO windows             */
#define IM_WINDOW_HIDDEN     3095  /* cannot make window visible           */

#ifndef NO_IME
USHORT GetEditLen(IMEPRO *);
#endif

BOOL
ServeImmonRequest(IN  PIMMONREQUEST    PReq,
                  OUT PVOID            PStatus)
{
    DWORD       Rc;
    DWORD       dwNlsMode;

    Rc = 0;

    switch (PReq->Request)
    {
        case IMMONStatus:
            if (PReq->d.MonStatBlk.cb != sizeof(MONSTATBLK))
            {
#if DBG
                KdPrint(("OS2SES(ImmonRequest): invalid parameter\n"));
#endif
                Rc = ERROR_INVALID_PARAMETER;
            } else
            {
                switch (PReq->d.MonStatBlk.usInfoLevel)
                {
                    case 0x21:
#ifndef NO_IME
                        {
                            IMEPRO ImeInfo;
                            PUSHORT pInfoBuf, dst;
                            USHORT BufLen, len;


                            if (!IMPGetIME( NULL, &ImeInfo ))
                            {
#if DBG
                                KdPrint(("OS2SES(ImmonRequest): Can not get IME info\n"));
#endif
                                Rc = IM_IME_NOT_INSTALL;
                                break;

                            }

                            BufLen = PReq->d.MonStatBlk.cbInfoBuf;
                            if ((GetEditLen(&ImeInfo) + 10) > BufLen)
                            {
                                BufLen = 2;
                                Rc = IM_NOT_ENOUGH_BUFF;
                            } else 
                            {
                                pInfoBuf = dst = (PUSHORT)Os2SessionCtrlDataBaseAddress;

                                len = strlen(ImeInfo.szName) + 1;
                                *dst++ = len + 2;
                                RtlMoveMemory(dst, ImeInfo.szName, len);
                                (PCHAR) dst += len;
                                

                                len = strlen(ImeInfo.szDescription) + 1;
                                *dst++ = len + 2;
                                RtlMoveMemory(dst, ImeInfo.szDescription, len);
                                (PCHAR) dst += len;

                                len = strlen(ImeInfo.szOptions) + 1;
                                *dst++ = len + 2;
                                RtlMoveMemory(dst, ImeInfo.szOptions, len);
                                (PCHAR) dst += len;

                                *dst++ = 3;
                                *(PUCHAR) dst = '\0';
                            }
                        }
#endif
                        break;
                    case 0x23:
                        if (PReq->d.MonStatBlk.cbInfoBuf < 2)
                        {
                            Rc = ERROR_BUFFER_OVERFLOW;
                            break;
                        }
#ifndef NO_CONSOLE_NLS
                        if (!GetConsoleNlsMode(hConsoleInput,&dwNlsMode)) 
                        {
#if DBG
                            KdPrint(("OS2SES(ImmonRequest): Can not get CONIN NLS Mode\n"));
#endif
                            dwNlsMode = 0;
                        }
#else
                        dwNlsMode = 0;
#endif

#ifndef NO_IME
                        if (dwNlsMode & NLS_IME_DISABLE)
                            *(PUSHORT)Os2SessionCtrlDataBaseAddress = 0;
                        else
                            *(PUSHORT)Os2SessionCtrlDataBaseAddress = 1;
#endif

                        break;
                    default:
                        Rc = IM_INVALID_COMMAND;
                }
            }
            break;

        case IMMONActive:

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

            dwNlsMode &= ~NLS_IME_DISABLE;

            if (!SetConsoleNlsMode(hConsoleInput,dwNlsMode)) 
            {
#if DBG
                KdPrint(("OS2SES(ImmonRequest): Can not set CONIN NLS Mode\n"));
#endif
            }
            
#endif
            break;

        case IMMONInactive:
#ifndef NO_CONSOLE_NLS
            if (!GetConsoleNlsMode(hConsoleInput,&dwNlsMode)) 
            {
#if DBG
                KdPrint(("OS2SES(ImmonRequest): Can not get CONIN NLS Mode\n"));
#endif
                dwNlsMode = 0;
            }

            dwNlsMode |= NLS_IME_DISABLE;

            if (!SetConsoleNlsMode(hConsoleInput,dwNlsMode)) 
            {
#if DBG
                KdPrint(("OS2SES(ImmonRequst): Can not set CONIN NLS Mode\n"));
#endif
            }

#endif
            break;

        default:
            Rc = (DWORD)-1L;     //STATUS_INVALID_PARAMETER;
#if DBG
            IF_OD2_DEBUG( OS2_EXE)
            {
                KdPrint(("OS2SES(ImmonRequest): Unknown Immon request = %lC\n",
                    PReq->Request));
            }
#endif
    }

    if ( Rc == 1 )
    {
        Rc = GetLastError();
    }

    *(PDWORD) PStatus = Rc;

    return(TRUE);       // Continue
}

#ifndef NO_IME
USHORT 
GetEditLen(IMEPRO *ImeInfo)
{
    USHORT Length, Total;
    CHAR   *Str;
    
    Str = (PUCHAR) ImeInfo->szName;
    for (Length = 1; *Str++; Length++) ;
    
    Total = Length;
    
    Str = (PUCHAR) ImeInfo->szDescription;
    for (Length = 1; *Str++; Length++) ;
    
    Total += Length;

    Str = (PUCHAR) ImeInfo->szOptions;
    for (Length = 1; *Str++; Length++) ;
    
    return (Total + Length);
}
#endif
#endif