imm.c 47.5 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 * IMM32 library
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4
 * Copyright 1998 Patrik Stridvall
5
 * Copyright 2002, 2003 CodeWeavers, Aric Stewart
6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21
 */

22 23
#include <stdarg.h>

24
#include "windef.h"
25
#include "winbase.h"
26
#include "wingdi.h"
27
#include "winuser.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
28
#include "winerror.h"
29
#include "wine/debug.h"
30
#include "imm.h"
31
#include "winnls.h"
32

33
WINE_DEFAULT_DEBUG_CHANNEL(imm);
34

35 36
#define FROM_IME 0xcafe1337

37
static void (*pX11DRV_ForceXIMReset)(HWND);
38

39 40
typedef struct tagInputContextData
{
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        LPBYTE          CompositionString;
        LPBYTE          CompositionReadingString;
        LPBYTE          ResultString;
        LPBYTE          ResultReadingString;
        DWORD           dwCompStringSize;   /* buffer size */
        DWORD           dwCompStringLength; /* string length (in bytes) */
        DWORD           dwCompReadStringSize;
        DWORD           dwResultStringSize;
        DWORD           dwResultReadStringSize;
        HWND            hwnd;
        BOOL            bOpen;
        BOOL            bInternalState;
        BOOL            bRead;
        LOGFONTW        font;
        HFONT           textfont;
        COMPOSITIONFORM CompForm;
} InputContextData;
58 59

static InputContextData *root_context = NULL;
60
static HWND hwndDefault = NULL;
61
static HANDLE hImeInst;
62
static const WCHAR WC_IMECLASSNAME[] = {'I','M','E',0};
63

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
/* MSIME messages */
static UINT WM_MSIME_SERVICE;
static UINT WM_MSIME_RECONVERTOPTIONS;
static UINT WM_MSIME_MOUSE;
static UINT WM_MSIME_RECONVERTREQUEST;
static UINT WM_MSIME_RECONVERT;
static UINT WM_MSIME_QUERYPOSITION;
static UINT WM_MSIME_DOCUMENTFEED;

/*
 * prototypes
 */
static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
                                          LPARAM lParam);
static void UpdateDataInDefaultIMEWindow(HWND hwnd);
static void ImmInternalPostIMEMessage(UINT, WPARAM, LPARAM);
static void ImmInternalSetOpenStatus(BOOL fOpen);
81 82 83

static VOID IMM_PostResult(InputContextData *data)
{
84
    unsigned int i;
85
    TRACE("Posting result as IME_CHAR\n");
86 87

    for (i = 0; i < data->dwResultStringSize / sizeof (WCHAR); i++)
88 89 90 91 92 93 94 95
        ImmInternalPostIMEMessage (WM_IME_CHAR, ((WCHAR*)data->ResultString)[i],
                     1);

    /* clear the buffer */
    if (data->dwResultStringSize)
        HeapFree(GetProcessHeap(),0,data->ResultString);
    data->dwResultStringSize = 0;
    data->ResultString = NULL;
96 97 98 99 100 101
}

static void IMM_Register(void)
{
    WNDCLASSW wndClass;
    ZeroMemory(&wndClass, sizeof(WNDCLASSW));
102 103
    wndClass.style = CS_GLOBALCLASS | CS_IME | CS_HREDRAW | CS_VREDRAW;
    wndClass.lpfnWndProc = (WNDPROC) IME_WindowProc;
104 105
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
106 107 108
    wndClass.hInstance = hImeInst;
    wndClass.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
    wndClass.hIcon = NULL;
109
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
110
    wndClass.lpszMenuName   = 0;
111 112 113 114 115 116
    wndClass.lpszClassName = WC_IMECLASSNAME;
    RegisterClassW(&wndClass);
}

static void IMM_Unregister(void)
{
117
    UnregisterClassW(WC_IMECLASSNAME, NULL);
118 119
}

120 121 122 123 124 125 126 127 128 129 130
static void IMM_RegisterMessages(void)
{
    WM_MSIME_SERVICE = RegisterWindowMessageA("MSIMEService");
    WM_MSIME_RECONVERTOPTIONS = RegisterWindowMessageA("MSIMEReconvertOptions");
    WM_MSIME_MOUSE = RegisterWindowMessageA("MSIMEMouseOperation");
    WM_MSIME_RECONVERTREQUEST = RegisterWindowMessageA("MSIMEReconvertRequest");
    WM_MSIME_RECONVERT = RegisterWindowMessageA("MSIMEReconvert");
    WM_MSIME_QUERYPOSITION = RegisterWindowMessageA("MSIMEQueryPosition");
    WM_MSIME_DOCUMENTFEED = RegisterWindowMessageA("MSIMEDocumentFeed");
}

131 132 133

BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
{
134 135
    HMODULE x11drv;

136 137 138 139
    TRACE("%p, %lx, %p\n",hInstDLL,fdwReason,lpReserved);
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
140
            DisableThreadLibraryCalls(hInstDLL);
141
            hImeInst = hInstDLL;
142
            IMM_RegisterMessages();
143
            x11drv = GetModuleHandleA("winex11.drv");
144
            if (x11drv) pX11DRV_ForceXIMReset = (void *)GetProcAddress( x11drv, "ForceXIMReset");
145 146 147 148 149 150 151 152 153 154 155 156 157
            break;
        case DLL_PROCESS_DETACH:
            if (hwndDefault)
            {
                DestroyWindow(hwndDefault);
                hwndDefault = 0;
            }
            IMM_Unregister();
            break;
    }
    return TRUE;
}

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
/* for posting messages as the IME */
static void ImmInternalPostIMEMessage(UINT msg, WPARAM wParam, LPARAM lParam)
{
    HWND target = GetFocus();
    if (!target)
       PostMessageW(root_context->hwnd,msg,wParam,lParam);
    else 
       PostMessageW(target, msg, wParam, lParam);
}


static void ImmInternalSetOpenStatus(BOOL fOpen)
{
    TRACE("Setting internal state to %s\n",(fOpen)?"OPEN":"CLOSED");

   root_context->bOpen = fOpen;
   root_context->bInternalState = fOpen;

   if (fOpen == FALSE)
   {
        ShowWindow(hwndDefault,SW_HIDE);

        if (root_context->dwCompStringSize)
            HeapFree(GetProcessHeap(),0,root_context->CompositionString);
        if (root_context->dwCompReadStringSize)
            HeapFree(GetProcessHeap(),0,root_context->CompositionReadingString);
        if (root_context->dwResultStringSize)
            HeapFree(GetProcessHeap(),0,root_context->ResultString);
        if (root_context->dwResultReadStringSize)
            HeapFree(GetProcessHeap(),0,root_context->ResultReadingString);
        root_context->dwCompStringSize = 0;
        root_context->dwCompStringLength = 0;
        root_context->CompositionString = NULL;
        root_context->dwCompReadStringSize = 0;
        root_context->CompositionReadingString = NULL;
        root_context->dwResultStringSize = 0;
        root_context->ResultString = NULL;
        root_context->dwResultReadStringSize = 0;
        root_context->ResultReadingString = NULL;
    }
    else
        ShowWindow(hwndDefault, SW_SHOWNOACTIVATE);

   SendMessageW(root_context->hwnd, WM_IME_NOTIFY, IMN_SETOPENSTATUS, 0);
}

204

Alexandre Julliard's avatar
Alexandre Julliard committed
205
/***********************************************************************
206
 *		ImmAssociateContext (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
207
 */
208
HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
Alexandre Julliard's avatar
Alexandre Julliard committed
209
{
210 211
    InputContextData *data = (InputContextData*)hIMC;

212
    WARN("(%p, %p): semi-stub\n",hWnd,hIMC);
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

    if (!data)
        return FALSE;

    /*
     * WINE SPECIFIC! MAY CONFLICT
     * associate the root context we have an XIM created
     */
    if (hWnd == 0x000)
    {
        root_context = (InputContextData*)hIMC;
    }

    /*
     * If already associated just return
     */
    if (data->hwnd == hWnd)
        return (HIMC)data;

    if (IsWindow(data->hwnd))
    {
        /*
         * Post a message that your context is switching
         */
        SendMessageW(data->hwnd, WM_IME_SETCONTEXT, FALSE, ISC_SHOWUIALL);
    }

    data->hwnd = hWnd;

    if (IsWindow(data->hwnd))
    {
        /*
         * Post a message that your context is switching
         */
        SendMessageW(data->hwnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
    }

    /*
     * TODO: We need to keep track of the old context associated
     * with a window and return it for now we will return NULL;
     */
    return (HIMC)NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
255 256
}

257 258 259 260 261 262 263 264 265
/***********************************************************************
 *              ImmAssociateContextEx (IMM32.@)
 */
BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD dwFlags)
{
    FIXME("(%p, %p, %ld): stub\n", hWnd, hIMC, dwFlags);
    return FALSE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
266
/***********************************************************************
267
 *		ImmConfigureIMEA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
268
 */
269 270
BOOL WINAPI ImmConfigureIMEA(
  HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
Alexandre Julliard's avatar
Alexandre Julliard committed
271
{
272
  FIXME("(%p, %p, %ld, %p): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
273 274 275 276
    hKL, hWnd, dwMode, lpData
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
277 278 279
}

/***********************************************************************
280
 *		ImmConfigureIMEW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
281
 */
282 283
BOOL WINAPI ImmConfigureIMEW(
  HKL hKL, HWND hWnd, DWORD dwMode, LPVOID lpData)
Alexandre Julliard's avatar
Alexandre Julliard committed
284
{
285
  FIXME("(%p, %p, %ld, %p): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
286 287 288 289
    hKL, hWnd, dwMode, lpData
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
290 291
}

Eric Kohl's avatar
Eric Kohl committed
292
/***********************************************************************
293
 *		ImmCreateContext (IMM32.@)
Eric Kohl's avatar
Eric Kohl committed
294
 */
295
HIMC WINAPI ImmCreateContext(void)
Eric Kohl's avatar
Eric Kohl committed
296
{
297 298 299 300 301 302
    InputContextData *new_context;

    new_context = HeapAlloc(GetProcessHeap(),0,sizeof(InputContextData));
    ZeroMemory(new_context,sizeof(InputContextData));

    return (HIMC)new_context;
303 304 305 306 307 308 309
}

/***********************************************************************
 *		ImmDestroyContext (IMM32.@)
 */
BOOL WINAPI ImmDestroyContext(HIMC hIMC)
{
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    InputContextData *data = (InputContextData*)hIMC;

    TRACE("Destroying %p\n",hIMC);

    if (hIMC)
    {
        if (data->dwCompStringSize)
            HeapFree(GetProcessHeap(),0,data->CompositionString);
        if (data->dwCompReadStringSize)
            HeapFree(GetProcessHeap(),0,data->CompositionReadingString);
        if (data->dwResultStringSize)
            HeapFree(GetProcessHeap(),0,data->ResultString);
        if (data->dwResultReadStringSize)
            HeapFree(GetProcessHeap(),0,data->ResultReadingString);

325 326 327 328 329 330
        if (data->textfont)
        {
            DeleteObject(data->textfont);
            data->textfont = NULL;
        }

331 332 333
        HeapFree(GetProcessHeap(),0,data);
    }
    return TRUE;
Eric Kohl's avatar
Eric Kohl committed
334 335
}

336 337 338 339 340 341 342 343 344
/***********************************************************************
 *		ImmDisableIME (IMM32.@)
 */
BOOL WINAPI ImmDisableIME(DWORD idThread)
{
    FIXME("(%ld): stub\n", idThread);
    return TRUE;
}

345 346 347 348 349 350 351 352
/***********************************************************************
 *		ImmEnumRegisterWordA (IMM32.@)
 */
UINT WINAPI ImmEnumRegisterWordA(
  HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc,
  LPCSTR lpszReading, DWORD dwStyle,
  LPCSTR lpszRegister, LPVOID lpData)
{
353
  FIXME("(%p, %p, %s, %ld, %s, %p): stub\n",
354
    hKL, lpfnEnumProc,
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    debugstr_a(lpszReading), dwStyle,
    debugstr_a(lpszRegister), lpData
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
}

/***********************************************************************
 *		ImmEnumRegisterWordW (IMM32.@)
 */
UINT WINAPI ImmEnumRegisterWordW(
  HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc,
  LPCWSTR lpszReading, DWORD dwStyle,
  LPCWSTR lpszRegister, LPVOID lpData)
{
370
  FIXME("(%p, %p, %s, %ld, %s, %p): stub\n",
371
    hKL, lpfnEnumProc,
372 373 374 375 376 377 378
    debugstr_w(lpszReading), dwStyle,
    debugstr_w(lpszRegister), lpData
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
379
/***********************************************************************
380
 *		ImmEscapeA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
381
 */
382
LRESULT WINAPI ImmEscapeA(
383
  HKL hKL, HIMC hIMC,
384
  UINT uEscape, LPVOID lpData)
Alexandre Julliard's avatar
Alexandre Julliard committed
385
{
386
  FIXME("(%p, %p, %d, %p): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
387 388 389 390
    hKL, hIMC, uEscape, lpData
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
391 392 393
}

/***********************************************************************
394
 *		ImmEscapeW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
395
 */
396 397 398
LRESULT WINAPI ImmEscapeW(
  HKL hKL, HIMC hIMC,
  UINT uEscape, LPVOID lpData)
Alexandre Julliard's avatar
Alexandre Julliard committed
399
{
400
  FIXME("(%p, %p, %d, %p): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
401 402 403 404
    hKL, hIMC, uEscape, lpData
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
405 406 407
}

/***********************************************************************
408
 *		ImmGetCandidateListA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
409
 */
410
DWORD WINAPI ImmGetCandidateListA(
411
  HIMC hIMC, DWORD deIndex,
Alexandre Julliard's avatar
Alexandre Julliard committed
412
  LPCANDIDATELIST lpCandList, DWORD dwBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
413
{
414
  FIXME("(%p, %ld, %p, %ld): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
415 416 417 418 419
    hIMC, deIndex,
    lpCandList, dwBufLen
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
420 421 422
}

/***********************************************************************
423
 *		ImmGetCandidateListCountA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
424
 */
425 426
DWORD WINAPI ImmGetCandidateListCountA(
  HIMC hIMC, LPDWORD lpdwListCount)
Alexandre Julliard's avatar
Alexandre Julliard committed
427
{
428
  FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
Alexandre Julliard's avatar
Alexandre Julliard committed
429 430
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
431 432 433
}

/***********************************************************************
434
 *		ImmGetCandidateListCountW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
435
 */
436 437
DWORD WINAPI ImmGetCandidateListCountW(
  HIMC hIMC, LPDWORD lpdwListCount)
Alexandre Julliard's avatar
Alexandre Julliard committed
438
{
439
  FIXME("(%p, %p): stub\n", hIMC, lpdwListCount);
Alexandre Julliard's avatar
Alexandre Julliard committed
440 441
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
442 443 444
}

/***********************************************************************
445
 *		ImmGetCandidateListW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
446
 */
447
DWORD WINAPI ImmGetCandidateListW(
448
  HIMC hIMC, DWORD deIndex,
Alexandre Julliard's avatar
Alexandre Julliard committed
449
  LPCANDIDATELIST lpCandList, DWORD dwBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
450
{
451
  FIXME("(%p, %ld, %p, %ld): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
452 453 454 455 456
    hIMC, deIndex,
    lpCandList, dwBufLen
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
457 458 459
}

/***********************************************************************
460
 *		ImmGetCandidateWindow (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
461
 */
462 463
BOOL WINAPI ImmGetCandidateWindow(
  HIMC hIMC, DWORD dwBufLen, LPCANDIDATEFORM lpCandidate)
Alexandre Julliard's avatar
Alexandre Julliard committed
464
{
465
  FIXME("(%p, %ld, %p): stub\n", hIMC, dwBufLen, lpCandidate);
Alexandre Julliard's avatar
Alexandre Julliard committed
466 467
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
468 469 470
}

/***********************************************************************
471
 *		ImmGetCompositionFontA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
472
 */
473
BOOL WINAPI ImmGetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
Alexandre Julliard's avatar
Alexandre Julliard committed
474
{
475
  FIXME("(%p, %p): stub\n", hIMC, lplf);
Alexandre Julliard's avatar
Alexandre Julliard committed
476 477
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
478 479 480
}

/***********************************************************************
481
 *		ImmGetCompositionFontW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
482
 */
483
BOOL WINAPI ImmGetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
Alexandre Julliard's avatar
Alexandre Julliard committed
484
{
485
  FIXME("(%p, %p): stub\n", hIMC, lplf);
Alexandre Julliard's avatar
Alexandre Julliard committed
486 487
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
488 489 490
}

/***********************************************************************
491
 *		ImmGetCompositionStringA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
492
 */
493 494
LONG WINAPI ImmGetCompositionStringA(
  HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
495
{
496 497 498
    CHAR *buf;
    LONG rc = 0;
    InputContextData *data = (InputContextData*)hIMC;
499

500
    TRACE("(%p, 0x%lx, %p, %ld)\n", hIMC, dwIndex, lpBuf, dwBufLen);
501

502 503
    if (!data)
       return FALSE;
504

505
    if (dwIndex == GCS_RESULTSTR)
506
    {
507 508
        TRACE("GSC_RESULTSTR %p %li\n",data->ResultString,
                                    data->dwResultStringSize);
509

510 511 512 513 514 515 516 517 518
        buf = HeapAlloc( GetProcessHeap(), 0, data->dwResultStringSize * 3 );
        rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->ResultString,
                                 data->dwResultStringSize / sizeof(WCHAR), buf,
                                 data->dwResultStringSize * 3, NULL, NULL);
        if (dwBufLen >= rc)
            memcpy(lpBuf,buf,rc);

        data->bRead = TRUE;
        HeapFree( GetProcessHeap(), 0, buf );
519
    }
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
    else if (dwIndex == GCS_COMPSTR)
    {
         TRACE("GSC_COMPSTR %p %li\n",data->CompositionString,
                                     data->dwCompStringLength/ sizeof(WCHAR));

        buf = HeapAlloc( GetProcessHeap(), 0, data->dwCompStringLength * 3 );
        rc = WideCharToMultiByte(CP_ACP, 0,(LPWSTR)data->CompositionString,
                                 data->dwCompStringLength/ sizeof(WCHAR), buf,
                                 data->dwCompStringLength* 3, NULL, NULL);
        if (dwBufLen >= rc)
            memcpy(lpBuf,buf,rc);
        HeapFree( GetProcessHeap(), 0, buf );
    }
    else if (dwIndex == GCS_COMPATTR)
    {
        TRACE("GSC_COMPATTR %p %li\n",data->CompositionString,
                                    data->dwCompStringLength/ sizeof(WCHAR));

        rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->CompositionString,
                                 data->dwCompStringLength/ sizeof(WCHAR), NULL,
                                 0, NULL, NULL);
541
 
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
        if (dwBufLen >= rc)
        {
            int i=0;
            for (i = 0;  i < rc; i++)
                ((LPBYTE)lpBuf)[i] = ATTR_INPUT;
    }
    }
    else if (dwIndex == GCS_COMPCLAUSE)
    {
        TRACE("GSC_COMPCLAUSE %p %li\n",data->CompositionString,
                                    data->dwCompStringLength/ sizeof(WCHAR));
 
        rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)data->CompositionString,
                                 data->dwCompStringLength/ sizeof(WCHAR), NULL,
                                 0, NULL, NULL);
557

558 559 560 561 562 563 564 565 566 567 568
        if (dwBufLen >= sizeof(DWORD)*2)
        {
            ((LPDWORD)lpBuf)[0] = 0;
            ((LPDWORD)lpBuf)[1] = rc;
        }
        rc = sizeof(DWORD)*2;
    }
    else
    {
        FIXME("Unhandled index 0x%lx\n",dwIndex);
    }
569 570

    return rc;
Alexandre Julliard's avatar
Alexandre Julliard committed
571 572 573
}

/***********************************************************************
574
 *		ImmGetCompositionStringW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
575
 */
576
LONG WINAPI ImmGetCompositionStringW(
577
  HIMC hIMC, DWORD dwIndex,
Alexandre Julliard's avatar
Alexandre Julliard committed
578
  LPVOID lpBuf, DWORD dwBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
579
{
580
  LONG rc = 0;
581 582
  InputContextData *data = (InputContextData*)hIMC;

583
  TRACE("(%p, 0x%lx, %p, %ld)\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
584 585
    hIMC, dwIndex, lpBuf, dwBufLen
  );
586 587 588 589 590 591 592 593 594 595 596

    if (!data)
       return FALSE;

    if (dwIndex == GCS_RESULTSTR)
    {
        data->bRead = TRUE;

        if (dwBufLen >= data->dwResultStringSize)
            memcpy(lpBuf,data->ResultString,data->dwResultStringSize);
        
597
        rc =  data->dwResultStringSize;
598
    }
599
    else if (dwIndex == GCS_RESULTREADSTR)
600 601 602 603 604
    {
        if (dwBufLen >= data->dwResultReadStringSize)
            memcpy(lpBuf,data->ResultReadingString,
                    data->dwResultReadStringSize);
        
605
        rc = data->dwResultReadStringSize;
606
    }   
607 608 609 610
    else if (dwIndex == GCS_COMPSTR)
    {
        if (dwBufLen >= data->dwCompStringLength)
            memcpy(lpBuf,data->CompositionString,data->dwCompStringLength);
611

612 613 614
        rc = data->dwCompStringLength;
    }
    else if (dwIndex == GCS_COMPATTR)
615
    {
616
        unsigned int len = data->dwCompStringLength;
617
        
618 619
        if (dwBufLen >= len)
        {
620
            unsigned int i=0;
621 622 623
            for (i = 0;  i < len; i++)
                ((LPBYTE)lpBuf)[i] = ATTR_INPUT;
        }
624

625 626 627 628 629 630 631 632 633 634 635 636
        rc = len;
    }
    else if (dwIndex == GCS_COMPCLAUSE)
    {
        if (dwBufLen >= sizeof(DWORD)*2)
        {
            ((LPDWORD)lpBuf)[0] = 0;
            ((LPDWORD)lpBuf)[1] = data->dwCompStringLength/sizeof(WCHAR);
        }
        rc = sizeof(DWORD)*2;
    }
    else if (dwIndex == GCS_COMPREADSTR)
637 638 639 640 641
    {
        if (dwBufLen >= data->dwCompReadStringSize)
            memcpy(lpBuf,data->CompositionReadingString,
                    data->dwCompReadStringSize);
        
642 643 644 645 646
        rc = data->dwCompReadStringSize;
    }   
    else
    {
        FIXME("Unhandled index 0x%lx\n",dwIndex);
647 648
    }   

649
    return rc;
Alexandre Julliard's avatar
Alexandre Julliard committed
650 651 652
}

/***********************************************************************
653
 *		ImmGetCompositionWindow (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
654
 */
655
BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
Alexandre Julliard's avatar
Alexandre Julliard committed
656
{
657 658 659 660 661 662 663 664 665
    InputContextData *data = (InputContextData*)hIMC;

    TRACE("(%p, %p)\n", hIMC, lpCompForm);

    if (!data)
        return FALSE;

    memcpy(lpCompForm,&(data->CompForm),sizeof(COMPOSITIONFORM));
    return 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
666 667 668
}

/***********************************************************************
669
 *		ImmGetContext (IMM32.@)
670
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
671
 */
672
HIMC WINAPI ImmGetContext(HWND hWnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
673
{
674
    FIXME("(%p): stub\n", hWnd);
675 676 677 678 679

    if (!root_context)
        return NULL;

    root_context->hwnd = hWnd;
680
    return (HIMC)root_context;
Alexandre Julliard's avatar
Alexandre Julliard committed
681 682 683
}

/***********************************************************************
684
 *		ImmGetConversionListA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
685
 */
686 687
DWORD WINAPI ImmGetConversionListA(
  HKL hKL, HIMC hIMC,
Alexandre Julliard's avatar
Alexandre Julliard committed
688
  LPCSTR pSrc, LPCANDIDATELIST lpDst,
689
  DWORD dwBufLen, UINT uFlag)
Alexandre Julliard's avatar
Alexandre Julliard committed
690
{
691
  FIXME("(%p, %p, %s, %p, %ld, %d): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
692 693 694 695
    hKL, hIMC, debugstr_a(pSrc), lpDst, dwBufLen, uFlag
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
696 697 698
}

/***********************************************************************
699
 *		ImmGetConversionListW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
700
 */
701 702
DWORD WINAPI ImmGetConversionListW(
  HKL hKL, HIMC hIMC,
Alexandre Julliard's avatar
Alexandre Julliard committed
703
  LPCWSTR pSrc, LPCANDIDATELIST lpDst,
704
  DWORD dwBufLen, UINT uFlag)
Alexandre Julliard's avatar
Alexandre Julliard committed
705
{
706
  FIXME("(%p, %p, %s, %p, %ld, %d): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
707 708 709 710
    hKL, hIMC, debugstr_w(pSrc), lpDst, dwBufLen, uFlag
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
711 712 713
}

/***********************************************************************
714
 *		ImmGetConversionStatus (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
715
 */
716 717
BOOL WINAPI ImmGetConversionStatus(
  HIMC hIMC, LPDWORD lpfdwConversion, LPDWORD lpfdwSentence)
Alexandre Julliard's avatar
Alexandre Julliard committed
718
{
719 720 721 722 723 724
    TRACE("(%p, %p, %p): best guess\n", hIMC, lpfdwConversion, lpfdwSentence);
    if (lpfdwConversion)
        *lpfdwConversion = IME_CMODE_NATIVE;
    if (lpfdwSentence)
        *lpfdwSentence = IME_SMODE_NONE;
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
725 726 727
}

/***********************************************************************
728
 *		ImmGetDefaultIMEWnd (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
729
 */
730
HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
731
{
732
  FIXME("(%p - %p %p ): semi-stub\n", hWnd,hwndDefault, root_context);
733

734
  if (hwndDefault == NULL)
735
  {
736 737
        static const WCHAR the_name[] = {'I','M','E','\0'};

738
        IMM_Register();
739 740 741
        hwndDefault = CreateWindowExW( WS_EX_CLIENTEDGE, WC_IMECLASSNAME,
                the_name, WS_POPUPWINDOW|WS_CAPTION, 0, 0, 120, 55, 0, 0,
                hImeInst, 0);
742

743
        TRACE("Default created (%p)\n",hwndDefault);
744 745 746
  }

  return (HWND)hwndDefault;
Alexandre Julliard's avatar
Alexandre Julliard committed
747 748 749
}

/***********************************************************************
750
 *		ImmGetDescriptionA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
751
 */
752 753
UINT WINAPI ImmGetDescriptionA(
  HKL hKL, LPSTR lpszDescription, UINT uBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
754
{
755 756 757 758 759 760 761 762 763 764 765
  WCHAR *buf;
  DWORD len;

  TRACE("%p %p %d\n", hKL, lpszDescription, uBufLen);

  /* find out how many characters in the unicode buffer */
  len = ImmGetDescriptionW( hKL, NULL, 0 );

  /* allocate a buffer of that size */
  buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) );
  if( !buf )
Alexandre Julliard's avatar
Alexandre Julliard committed
766
  return 0;
767 768 769 770 771 772 773 774 775 776 777

  /* fetch the unicode buffer */
  len = ImmGetDescriptionW( hKL, buf, len + 1 );

  /* convert it back to ASCII */
  len = WideCharToMultiByte( CP_ACP, 0, buf, len + 1,
                             lpszDescription, uBufLen, NULL, NULL );

  HeapFree( GetProcessHeap(), 0, buf );

  return len;
Alexandre Julliard's avatar
Alexandre Julliard committed
778 779 780
}

/***********************************************************************
781
 *		ImmGetDescriptionW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
782
 */
783
UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
784
{
785 786 787 788 789 790 791
  static const WCHAR name[] = { 'W','i','n','e',' ','X','I','M',0 };

  FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen);

  if (!uBufLen) return lstrlenW( name );
  lstrcpynW( lpszDescription, name, uBufLen );
  return lstrlenW( lpszDescription );
Alexandre Julliard's avatar
Alexandre Julliard committed
792 793 794
}

/***********************************************************************
795
 *		ImmGetGuideLineA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
796
 */
797 798
DWORD WINAPI ImmGetGuideLineA(
  HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
799
{
800
  FIXME("(%p, %ld, %s, %ld): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
801 802 803 804
    hIMC, dwIndex, debugstr_a(lpBuf), dwBufLen
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
805 806 807
}

/***********************************************************************
808
 *		ImmGetGuideLineW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
809
 */
810
DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
811
{
812
  FIXME("(%p, %ld, %s, %ld): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
813 814 815 816
    hIMC, dwIndex, debugstr_w(lpBuf), dwBufLen
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
817 818
}

819 820 821 822 823 824
/***********************************************************************
 *		ImmGetIMEFileNameA (IMM32.@)
 */
UINT WINAPI ImmGetIMEFileNameA(
  HKL hKL, LPSTR lpszFileName, UINT uBufLen)
{
825
  FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
826 827 828 829 830 831 832 833 834 835
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
}

/***********************************************************************
 *		ImmGetIMEFileNameW (IMM32.@)
 */
UINT WINAPI ImmGetIMEFileNameW(
  HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
{
836
  FIXME("(%p, %p, %d): stub\n", hKL, lpszFileName, uBufLen);
837 838 839 840
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
841
/***********************************************************************
842
 *		ImmGetOpenStatus (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
843
 */
844
BOOL WINAPI ImmGetOpenStatus(HIMC hIMC)
Alexandre Julliard's avatar
Alexandre Julliard committed
845
{
846
  InputContextData *data = (InputContextData*)hIMC;
847

848 849
    if (!data)
        return FALSE;
850 851 852
  FIXME("(%p): semi-stub\n", hIMC);

  return data->bOpen;
Alexandre Julliard's avatar
Alexandre Julliard committed
853 854
}

855 856 857 858 859
/***********************************************************************
 *		ImmGetProperty (IMM32.@)
 */
DWORD WINAPI ImmGetProperty(HKL hKL, DWORD fdwIndex)
{
860
    DWORD rc = 0;
861
    TRACE("(%p, %ld)\n", hKL, fdwIndex);
862 863 864 865

    switch (fdwIndex)
    {
        case IGP_PROPERTY:
866 867 868 869 870 871 872 873 874 875
            TRACE("(%s)\n", "IGP_PROPERTY");
            rc = IME_PROP_UNICODE | IME_PROP_AT_CARET;
            break;
        case IGP_CONVERSION:
            FIXME("(%s)\n", "IGP_CONVERSION");
            rc = IME_CMODE_NATIVE;
            break;
        case IGP_SENTENCE:
            FIXME("%s)\n", "IGP_SENTENCE");
            rc = IME_SMODE_AUTOMATIC;
876 877
            break;
        case IGP_SETCOMPSTR:
878 879
            TRACE("(%s)\n", "IGP_SETCOMPSTR");
            rc = 0;
880 881
            break;
        case IGP_SELECT:
882
            TRACE("(%s)\n", "IGP_SELECT");
883 884 885
            rc = SELECT_CAP_CONVERSION | SELECT_CAP_SENTENCE;
            break;
        case IGP_GETIMEVERSION:
886
            TRACE("(%s)\n", "IGP_GETIMEVERSION");
887 888 889
            rc = IMEVER_0400;
            break;
        case IGP_UI:
890 891 892
            TRACE("(%s)\n", "IGP_UI");
            rc = 0;
            break;
893 894 895 896
        default:
            rc = 0;
    }
    return rc;
897 898 899 900 901 902 903 904
}

/***********************************************************************
 *		ImmGetRegisterWordStyleA (IMM32.@)
 */
UINT WINAPI ImmGetRegisterWordStyleA(
  HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf)
{
905
  FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
906 907 908 909 910 911 912 913 914 915
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
}

/***********************************************************************
 *		ImmGetRegisterWordStyleW (IMM32.@)
 */
UINT WINAPI ImmGetRegisterWordStyleW(
  HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf)
{
916
  FIXME("(%p, %d, %p): stub\n", hKL, nItem, lpStyleBuf);
917 918 919 920
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
921
/***********************************************************************
922
 *		ImmGetStatusWindowPos (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
923
 */
924
BOOL WINAPI ImmGetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
Alexandre Julliard's avatar
Alexandre Julliard committed
925
{
926
  FIXME("(%p, %p): stub\n", hIMC, lpptPos);
Alexandre Julliard's avatar
Alexandre Julliard committed
927 928
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
929 930 931
}

/***********************************************************************
932
 *		ImmGetVirtualKey (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
933
 */
934
UINT WINAPI ImmGetVirtualKey(HWND hWnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
935
{
936
  OSVERSIONINFOA version;
937
  FIXME("(%p): stub\n", hWnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
938
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
939 940 941 942
  GetVersionExA( &version );
  switch(version.dwPlatformId)
  {
  case VER_PLATFORM_WIN32_WINDOWS:
Alexandre Julliard's avatar
Alexandre Julliard committed
943
      return VK_PROCESSKEY;
944
  case VER_PLATFORM_WIN32_NT:
Alexandre Julliard's avatar
Alexandre Julliard committed
945
      return 0;
946
  default:
947
      FIXME("%ld not supported\n",version.dwPlatformId);
948 949
      return VK_PROCESSKEY;
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
950 951
}

952 953 954 955 956 957 958 959 960 961
/***********************************************************************
 *		ImmInstallIMEA (IMM32.@)
 */
HKL WINAPI ImmInstallIMEA(
  LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText)
{
  FIXME("(%s, %s): stub\n",
    debugstr_a(lpszIMEFileName), debugstr_a(lpszLayoutText)
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
962
  return NULL;
963 964 965 966 967 968 969 970 971 972 973 974
}

/***********************************************************************
 *		ImmInstallIMEW (IMM32.@)
 */
HKL WINAPI ImmInstallIMEW(
  LPCWSTR lpszIMEFileName, LPCWSTR lpszLayoutText)
{
  FIXME("(%s, %s): stub\n",
    debugstr_w(lpszIMEFileName), debugstr_w(lpszLayoutText)
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
975
  return NULL;
976 977 978 979 980 981 982
}

/***********************************************************************
 *		ImmIsIME (IMM32.@)
 */
BOOL WINAPI ImmIsIME(HKL hKL)
{
983
  TRACE("(%p): semi-stub\n", hKL);
984
  /*
985
   * FIXME: Dead key locales will return TRUE here when they should not
986
   * There is probably a more proper way to check this.
987 988
   */
  return (root_context != NULL);
989 990 991 992 993 994 995 996
}

/***********************************************************************
 *		ImmIsUIMessageA (IMM32.@)
 */
BOOL WINAPI ImmIsUIMessageA(
  HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
{
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
    BOOL rc = FALSE;

    TRACE("(%p, %x, %d, %ld)\n", hWndIME, msg, wParam, lParam);
    if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
        (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
        (msg == WM_MSIME_SERVICE) ||
        (msg == WM_MSIME_RECONVERTOPTIONS) ||
        (msg == WM_MSIME_MOUSE) ||
        (msg == WM_MSIME_RECONVERTREQUEST) ||
        (msg == WM_MSIME_RECONVERT) ||
        (msg == WM_MSIME_QUERYPOSITION) ||
        (msg == WM_MSIME_DOCUMENTFEED))

    {
        if (!hwndDefault)
            ImmGetDefaultIMEWnd(NULL);

        if (hWndIME == NULL)
            PostMessageA(hwndDefault, msg, wParam, lParam);

        rc = TRUE;
    }
    return rc;
1020 1021 1022 1023 1024 1025 1026 1027
}

/***********************************************************************
 *		ImmIsUIMessageW (IMM32.@)
 */
BOOL WINAPI ImmIsUIMessageW(
  HWND hWndIME, UINT msg, WPARAM wParam, LPARAM lParam)
{
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
    BOOL rc = FALSE;
    TRACE("(%p, %d, %d, %ld): stub\n", hWndIME, msg, wParam, lParam);
    if ((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
        (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP) ||
        (msg == WM_MSIME_SERVICE) ||
        (msg == WM_MSIME_RECONVERTOPTIONS) ||
        (msg == WM_MSIME_MOUSE) ||
        (msg == WM_MSIME_RECONVERTREQUEST) ||
        (msg == WM_MSIME_RECONVERT) ||
        (msg == WM_MSIME_QUERYPOSITION) ||
        (msg == WM_MSIME_DOCUMENTFEED))
        rc = TRUE;
    return rc;
1041 1042
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1043
/***********************************************************************
1044
 *		ImmNotifyIME (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1045
 */
1046 1047
BOOL WINAPI ImmNotifyIME(
  HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue)
Alexandre Julliard's avatar
Alexandre Julliard committed
1048
{
1049
    BOOL rc = FALSE;
1050
  FIXME("(%p, %ld, %ld, %ld): stub\n",
1051 1052
        hIMC, dwAction, dwIndex, dwValue);

1053 1054 1055
    if (!root_context)
        return rc;

1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
    switch(dwAction)
    {
        case NI_CHANGECANDIDATELIST:
            FIXME("%s\n","NI_CHANGECANDIDATELIST");
            break;
        case NI_CLOSECANDIDATE:
            FIXME("%s\n","NI_CLOSECANDIDATE");
            break;
        case NI_COMPOSITIONSTR:
            switch (dwIndex)
            {
                case CPS_CANCEL:
                    TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_CANCEL");
                    if (pX11DRV_ForceXIMReset)
                        pX11DRV_ForceXIMReset(root_context->hwnd);
                    if (root_context->dwCompStringSize)
                    {
                        HeapFree(GetProcessHeap(),0,
                                 root_context->CompositionString);
                        root_context->dwCompStringSize = 0;
                        root_context->dwCompStringLength = 0;
                        root_context->CompositionString = NULL;
                        ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
                                                  GCS_COMPSTR);
                    }
                    rc = TRUE;
                    break;
                case CPS_COMPLETE:
                    TRACE("%s - %s\n","NI_COMPOSITIONSTR","CPS_COMPLETE");
                    if (hIMC != (HIMC)FROM_IME && pX11DRV_ForceXIMReset)
                        pX11DRV_ForceXIMReset(root_context->hwnd);

                    if (root_context->dwResultStringSize)
                    {
                        HeapFree(GetProcessHeap(),0,root_context->ResultString);
                        root_context->dwResultStringSize = 0;
                        root_context->ResultString = NULL;
                    }
                    if (root_context->dwCompStringLength)
                    {
                        root_context->ResultString = HeapAlloc(
                        GetProcessHeap(), 0, root_context->dwCompStringLength);
                        root_context->dwResultStringSize =
                                        root_context->dwCompStringLength;

                        memcpy(root_context->ResultString,
                               root_context->CompositionString,
                               root_context->dwCompStringLength);

                        HeapFree(GetProcessHeap(),0,
                                 root_context->CompositionString);

                        root_context->dwCompStringSize = 0;
                        root_context->dwCompStringLength = 0;
                        root_context->CompositionString = NULL;
                        root_context->bRead = FALSE;

                        ImmInternalPostIMEMessage(WM_IME_COMPOSITION, 0,
                                                  GCS_COMPSTR);

                        ImmInternalPostIMEMessage(WM_IME_COMPOSITION,
                                            root_context->ResultString[0],
                                            GCS_RESULTSTR|GCS_RESULTCLAUSE);
                    }
                    break;
                case CPS_CONVERT:
                    FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_CONVERT");
                    break;
                case CPS_REVERT:
                    FIXME("%s - %s\n","NI_COMPOSITIONSTR","CPS_REVERT");
                    break;
                default:
                    ERR("%s - %s (%li)\n","NI_COMPOSITIONSTR","UNKNOWN",dwIndex);
                    break;
            }
            break;
        case NI_IMEMENUSELECTED:
            FIXME("%s\n", "NI_IMEMENUSELECTED");
            break;
        case NI_OPENCANDIDATE:
            FIXME("%s\n", "NI_OPENCANDIDATE");
            break;
        case NI_SELECTCANDIDATESTR:
            FIXME("%s\n", "NI_SELECTCANDIDATESTR");
            break;
        case NI_SETCANDIDATE_PAGESIZE:
            FIXME("%s\n", "NI_SETCANDIDATE_PAGESIZE");
            break;
        case NI_SETCANDIDATE_PAGESTART:
            FIXME("%s\n", "NI_SETCANDIDATE_PAGESTART");
            break;
        default:
            ERR("Unknown\n");
    }
  
    return rc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1152 1153 1154
}

/***********************************************************************
1155
 *		ImmRegisterWordA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1156
 */
1157 1158
BOOL WINAPI ImmRegisterWordA(
  HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister)
Alexandre Julliard's avatar
Alexandre Julliard committed
1159
{
1160
  FIXME("(%p, %s, %ld, %s): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1161 1162 1163 1164
    hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszRegister)
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1165 1166 1167
}

/***********************************************************************
1168
 *		ImmRegisterWordW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1169
 */
1170 1171
BOOL WINAPI ImmRegisterWordW(
  HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister)
Alexandre Julliard's avatar
Alexandre Julliard committed
1172
{
1173
  FIXME("(%p, %s, %ld, %s): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1174 1175 1176 1177
    hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszRegister)
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1178 1179 1180
}

/***********************************************************************
1181
 *		ImmReleaseContext (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1182
 */
1183
BOOL WINAPI ImmReleaseContext(HWND hWnd, HIMC hIMC)
Alexandre Julliard's avatar
Alexandre Julliard committed
1184
{
1185
  FIXME("(%p, %p): stub\n", hWnd, hIMC);
1186 1187

    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1188 1189 1190
}

/***********************************************************************
1191
 *		ImmSetCandidateWindow (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1192
 */
1193 1194
BOOL WINAPI ImmSetCandidateWindow(
  HIMC hIMC, LPCANDIDATEFORM lpCandidate)
Alexandre Julliard's avatar
Alexandre Julliard committed
1195
{
1196
  FIXME("(%p, %p): stub\n", hIMC, lpCandidate);
Alexandre Julliard's avatar
Alexandre Julliard committed
1197 1198
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1199 1200 1201
}

/***********************************************************************
1202
 *		ImmSetCompositionFontA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1203
 */
1204
BOOL WINAPI ImmSetCompositionFontA(HIMC hIMC, LPLOGFONTA lplf)
Alexandre Julliard's avatar
Alexandre Julliard committed
1205
{
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
    InputContextData *data = (InputContextData*)hIMC;
    TRACE("(%p, %p)\n", hIMC, lplf);

    if (!data)
        return FALSE;

    memcpy(&data->font,lplf,sizeof(LOGFONTA));
    MultiByteToWideChar(CP_ACP, 0, lplf->lfFaceName, -1, data->font.lfFaceName,
                        LF_FACESIZE);

    SendMessageW(root_context->hwnd, WM_IME_NOTIFY, IMN_SETCOMPOSITIONFONT, 0);

    if (data->textfont)
    {
        DeleteObject(data->textfont);
        data->textfont = NULL;
    }

    data->textfont = CreateFontIndirectW(&data->font); 
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1226 1227 1228
}

/***********************************************************************
1229
 *		ImmSetCompositionFontW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1230
 */
1231
BOOL WINAPI ImmSetCompositionFontW(HIMC hIMC, LPLOGFONTW lplf)
Alexandre Julliard's avatar
Alexandre Julliard committed
1232
{
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
    InputContextData *data = (InputContextData*)hIMC;
    TRACE("(%p, %p)\n", hIMC, lplf);

    if (!data)
        return FALSE;

    memcpy(&data->font,lplf,sizeof(LOGFONTW));
    SendMessageW(root_context->hwnd, WM_IME_NOTIFY, IMN_SETCOMPOSITIONFONT, 0);

    if (data->textfont)
    {
        DeleteObject(data->textfont);
        data->textfont = NULL;
    }
    data->textfont = CreateFontIndirectW(&data->font); 
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1249 1250 1251
}

/***********************************************************************
1252
 *		ImmSetCompositionStringA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1253
 */
1254
BOOL WINAPI ImmSetCompositionStringA(
1255 1256
  HIMC hIMC, DWORD dwIndex,
  LPCVOID lpComp, DWORD dwCompLen,
Alexandre Julliard's avatar
Alexandre Julliard committed
1257
  LPCVOID lpRead, DWORD dwReadLen)
Alexandre Julliard's avatar
Alexandre Julliard committed
1258
{
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    DWORD comp_len;
    DWORD read_len;
    WCHAR *CompBuffer = NULL;
    WCHAR *ReadBuffer = NULL;
    BOOL rc;

    TRACE("(%p, %ld, %p, %ld, %p, %ld): stub\n",
            hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);

    comp_len = MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, NULL, 0);
    if (comp_len)
    {
1271
        CompBuffer = HeapAlloc(GetProcessHeap(),0,comp_len * sizeof(WCHAR));
1272 1273 1274 1275 1276 1277
        MultiByteToWideChar(CP_ACP, 0, lpComp, dwCompLen, CompBuffer, comp_len);
    }

    read_len = MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, NULL, 0);
    if (read_len)
    {
1278
        ReadBuffer = HeapAlloc(GetProcessHeap(),0,read_len * sizeof(WCHAR));
1279 1280 1281 1282 1283 1284
        MultiByteToWideChar(CP_ACP, 0, lpRead, dwReadLen, ReadBuffer, read_len);
    }

    rc =  ImmSetCompositionStringW(hIMC, dwIndex, CompBuffer, comp_len,
                                   ReadBuffer, read_len);

1285 1286
    HeapFree(GetProcessHeap(), 0, CompBuffer);
    HeapFree(GetProcessHeap(), 0, ReadBuffer);
1287 1288

    return rc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1289 1290 1291
}

/***********************************************************************
1292
 *		ImmSetCompositionStringW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1293
 */
1294 1295
BOOL WINAPI ImmSetCompositionStringW(
	HIMC hIMC, DWORD dwIndex,
Alexandre Julliard's avatar
Alexandre Julliard committed
1296 1297 1298
	LPCVOID lpComp, DWORD dwCompLen,
	LPCVOID lpRead, DWORD dwReadLen)
{
1299 1300
     DWORD flags = 0;
     WCHAR wParam  = 0;
1301

1302 1303
     TRACE("(%p, %ld, %p, %ld, %p, %ld): stub\n",
             hIMC, dwIndex, lpComp, dwCompLen, lpRead, dwReadLen);
1304 1305


1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
     if (hIMC != (HIMC)FROM_IME)
         FIXME("PROBLEM: This only sets the wine level string\n");

     /*
      * Explanation:
      *  this sets the composition string in the imm32.dll level
      *  of the composition buffer. we cannot manipulate the xim level
      *  buffer, which means that once the xim level buffer changes again
      *  any call to this function from the application will be lost
      */

     if (lpRead && dwReadLen)
         FIXME("Reading string unimplemented\n");

     /*
      * app operating this api to also receive the message from xim
      */
1323 1324 1325

    if (dwIndex == SCS_SETSTR)
    {
1326
         flags = GCS_COMPSTR;
1327

1328 1329
         if (root_context->dwCompStringLength)
             HeapFree(GetProcessHeap(),0,root_context->CompositionString);
1330

1331 1332
         root_context->dwCompStringLength = dwCompLen;
         root_context->dwCompStringSize = dwCompLen;
1333

1334 1335 1336 1337 1338
         if (dwCompLen && lpComp)
         {
             root_context->CompositionString = HeapAlloc(GetProcessHeap(), 0,
                                                     dwCompLen);
             memcpy(root_context->CompositionString,lpComp,dwCompLen);
1339

Eric Pouech's avatar
Eric Pouech committed
1340
             wParam = ((const WCHAR*)lpComp)[0];
1341 1342 1343 1344
             flags |= GCS_COMPCLAUSE | GCS_COMPATTR;
         }
         else
             root_context->CompositionString = NULL;
1345 1346

    }
1347 1348 1349 1350 1351 1352

     UpdateDataInDefaultIMEWindow(hwndDefault);

     ImmInternalPostIMEMessage(WM_IME_COMPOSITION, wParam, flags);

     return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1353 1354 1355
}

/***********************************************************************
1356
 *		ImmSetCompositionWindow (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1357
 */
1358 1359
BOOL WINAPI ImmSetCompositionWindow(
  HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
Alexandre Julliard's avatar
Alexandre Julliard committed
1360
{
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
    BOOL reshow = FALSE;
    InputContextData *data = (InputContextData*)hIMC;

    TRACE("(%p, %p)\n", hIMC, lpCompForm);
    TRACE("\t%lx, (%li,%li), (%li,%li - %li,%li)\n",lpCompForm->dwStyle,
          lpCompForm->ptCurrentPos.x, lpCompForm->ptCurrentPos.y, lpCompForm->rcArea.top,
          lpCompForm->rcArea.left, lpCompForm->rcArea.bottom, lpCompForm->rcArea.right);

    if (!data)
        return FALSE;

    memcpy(&data->CompForm,lpCompForm,sizeof(COMPOSITIONFORM));

    if (IsWindowVisible(hwndDefault))
    {
        reshow = TRUE;
        ShowWindow(hwndDefault,SW_HIDE);
    }

    FIXME("STUB\n");

    if (reshow)
        ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);

    SendMessageW(root_context->hwnd, WM_IME_NOTIFY,IMN_SETCOMPOSITIONWINDOW, 0);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1387 1388 1389
}

/***********************************************************************
1390
 *		ImmSetConversionStatus (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1391
 */
1392 1393
BOOL WINAPI ImmSetConversionStatus(
  HIMC hIMC, DWORD fdwConversion, DWORD fdwSentence)
Alexandre Julliard's avatar
Alexandre Julliard committed
1394
{
1395
  FIXME("(%p, %ld, %ld): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1396 1397 1398 1399
    hIMC, fdwConversion, fdwSentence
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1400 1401 1402
}

/***********************************************************************
1403
 *		ImmSetOpenStatus (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1404
 */
1405
BOOL WINAPI ImmSetOpenStatus(HIMC hIMC, BOOL fOpen)
Alexandre Julliard's avatar
Alexandre Julliard committed
1406
{
1407 1408
    InputContextData *data = (InputContextData*)hIMC;
    FIXME("Semi-Stub\n");
1409 1410

    if (hIMC == (HIMC)FROM_IME)
1411
    {
1412 1413 1414 1415 1416 1417 1418 1419
        if (fOpen)
            ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION, 0, 0);

        ImmInternalSetOpenStatus(fOpen);

        if (!fOpen)
            ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION, 0, 0);

1420 1421
        return TRUE;
    }
1422 1423

    if (!data)
1424
        return FALSE;
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446

    if (fOpen != data->bInternalState)
    {
        if (fOpen == FALSE && pX11DRV_ForceXIMReset)
            pX11DRV_ForceXIMReset(data->hwnd);

        if (fOpen == FALSE)
            ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
        else
            ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);

        ImmInternalSetOpenStatus(fOpen);
        ImmInternalSetOpenStatus(!fOpen);

        if (data->bOpen == FALSE)
            ImmInternalPostIMEMessage(WM_IME_ENDCOMPOSITION,0,0);
        else
            ImmInternalPostIMEMessage(WM_IME_STARTCOMPOSITION,0,0);

        return FALSE;
    }
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1447 1448 1449
}

/***********************************************************************
1450
 *		ImmSetStatusWindowPos (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1451
 */
1452
BOOL WINAPI ImmSetStatusWindowPos(HIMC hIMC, LPPOINT lpptPos)
Alexandre Julliard's avatar
Alexandre Julliard committed
1453
{
1454
  FIXME("(%p, %p): stub\n", hIMC, lpptPos);
Alexandre Julliard's avatar
Alexandre Julliard committed
1455 1456
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1457 1458 1459
}

/***********************************************************************
1460
 *		ImmSimulateHotKey (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1461
 */
1462
BOOL WINAPI ImmSimulateHotKey(HWND hWnd, DWORD dwHotKeyID)
Alexandre Julliard's avatar
Alexandre Julliard committed
1463
{
1464
  FIXME("(%p, %ld): stub\n", hWnd, dwHotKeyID);
Alexandre Julliard's avatar
Alexandre Julliard committed
1465 1466
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1467 1468 1469
}

/***********************************************************************
1470
 *		ImmUnregisterWordA (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1471
 */
1472 1473
BOOL WINAPI ImmUnregisterWordA(
  HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister)
Alexandre Julliard's avatar
Alexandre Julliard committed
1474
{
1475
  FIXME("(%p, %s, %ld, %s): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1476 1477 1478 1479
    hKL, debugstr_a(lpszReading), dwStyle, debugstr_a(lpszUnregister)
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1480 1481 1482
}

/***********************************************************************
1483
 *		ImmUnregisterWordW (IMM32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1484
 */
1485 1486
BOOL WINAPI ImmUnregisterWordW(
  HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister)
Alexandre Julliard's avatar
Alexandre Julliard committed
1487
{
1488
  FIXME("(%p, %s, %ld, %s): stub\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1489 1490 1491 1492
    hKL, debugstr_w(lpszReading), dwStyle, debugstr_w(lpszUnregister)
  );
  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1493
}
1494

1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537

/*****
 * Internal functions to help with IME window management
 */
static void PaintDefaultIMEWnd(HWND hwnd)
{
    PAINTSTRUCT ps;
    RECT rect;
    HDC hdc = BeginPaint(hwnd,&ps);
    GetClientRect(hwnd,&rect);

    if (root_context->dwCompStringLength && root_context->CompositionString)
    {
        SIZE size;
        POINT pt;
        HFONT oldfont = NULL;

        if (root_context->textfont)
            oldfont = SelectObject(hdc,root_context->textfont);

        TextOutW(hdc, 0,0,(LPWSTR)root_context->CompositionString,
                 root_context->dwCompStringLength / sizeof(WCHAR));

        GetTextExtentPoint32W(hdc, (LPWSTR)root_context->CompositionString,
                              root_context->dwCompStringLength / sizeof(WCHAR),
                              &size);
        pt.x = size.cx;
        pt.y = size.cy;
        LPtoDP(hdc,&pt,1);
        rect.left = pt.x;

        if (oldfont)
            SelectObject(hdc,oldfont);
    }
    FillRect(hdc,&rect, (HBRUSH) (COLOR_WINDOW+1));
    EndPaint(hwnd,&ps);
}

static void UpdateDataInDefaultIMEWindow(HWND hwnd)
{
    RedrawWindow(hwnd,NULL,NULL,RDW_ERASENOW|RDW_INVALIDATE);
}

1538 1539 1540
/*
 * The window proc for the default IME window
 */
1541
static LRESULT WINAPI IME_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
1542 1543
                                          LPARAM lParam)
{
1544 1545 1546
    LRESULT rc = 0;

    TRACE("Incoming Message 0x%x  (0x%08x, 0x%08x)\n", msg, (UINT)wParam,
1547 1548
           (UINT)lParam);

1549
    switch(msg)
1550
    {
1551 1552 1553 1554
        case WM_PAINT:
            PaintDefaultIMEWnd(hwnd);
            return FALSE;

1555 1556 1557
        case WM_NCCREATE:
            return TRUE;

1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
        case WM_CREATE:
            SetWindowTextA(hwnd,"Wine Ime Active");
            return TRUE;

        case WM_SETFOCUS:
            if (wParam)
                SetFocus((HWND)wParam);
            else
                FIXME("Received focus, should never have focus\n");
            break;
1568
        case WM_IME_COMPOSITION:
1569 1570 1571 1572 1573 1574 1575
            TRACE("IME message %s, 0x%x, 0x%x (%i)\n",
                    "WM_IME_COMPOSITION", (UINT)wParam, (UINT)lParam,
                     root_context->bRead);
            if ((lParam & GCS_RESULTSTR) && (!root_context->bRead))
                    IMM_PostResult(root_context);
            else
                 UpdateDataInDefaultIMEWindow(hwnd);
1576 1577 1578 1579
            break;
        case WM_IME_STARTCOMPOSITION:
            TRACE("IME message %s, 0x%x, 0x%x\n",
                    "WM_IME_STARTCOMPOSITION", (UINT)wParam, (UINT)lParam);
1580 1581
            root_context->hwnd = GetFocus();
            ShowWindow(hwndDefault,SW_SHOWNOACTIVATE);
1582 1583 1584 1585
            break;
        case WM_IME_ENDCOMPOSITION:
            TRACE("IME message %s, 0x%x, 0x%x\n",
                    "WM_IME_ENDCOMPOSITION", (UINT)wParam, (UINT)lParam);
1586
            ShowWindow(hwndDefault,SW_HIDE);
1587 1588 1589 1590 1591
            break;
        case WM_IME_SELECT:
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_SELECT",
                (UINT)wParam, (UINT)lParam);
            break;
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
        case WM_IME_CONTROL:
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_IME_CONTROL",
                (UINT)wParam, (UINT)lParam);
            rc = 1; 
            break;
        case WM_IME_NOTIFY:
            TRACE("!! IME NOTIFY\n");
            break;
       default:
            TRACE("Non-standard message 0x%x\n",msg);
    }
    /* check the MSIME messages */
    if (msg == WM_MSIME_SERVICE)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_SERVICE",
                (UINT)wParam, (UINT)lParam);
            rc = FALSE;
1609
    }
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
    else if (msg == WM_MSIME_RECONVERTOPTIONS)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTOPTIONS",
                (UINT)wParam, (UINT)lParam);
    }
    else if (msg == WM_MSIME_MOUSE)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_MOUSE",
                (UINT)wParam, (UINT)lParam);
    }
    else if (msg == WM_MSIME_RECONVERTREQUEST)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERTREQUEST",
                (UINT)wParam, (UINT)lParam);
    }
    else if (msg == WM_MSIME_RECONVERT)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_RECONVERT",
                (UINT)wParam, (UINT)lParam);
    }
    else if (msg == WM_MSIME_QUERYPOSITION)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_QUERYPOSITION",
                (UINT)wParam, (UINT)lParam);
    }
    else if (msg == WM_MSIME_DOCUMENTFEED)
    {
            TRACE("IME message %s, 0x%x, 0x%x\n","WM_MSIME_DOCUMENTFEED",
                (UINT)wParam, (UINT)lParam);
    }
    /* DefWndProc if not an IME message */
    else if (!rc && !((msg >= WM_IME_STARTCOMPOSITION && msg <= WM_IME_KEYLAST) ||
                      (msg >= WM_IME_SETCONTEXT && msg <= WM_IME_KEYUP)))
        rc = DefWindowProcW(hwnd,msg,wParam,lParam);

    return rc;
1646
}