Changeset 21529 for trunk/src


Ignore:
Timestamp:
Dec 21, 2010, 1:40:08 AM (15 years ago)
Author:
dmik
Message:

Fixed completely broken national (non-Latin1) character input in Odin. There were two problems:
1) When translating OS2 WM_CHAR to Win32 WM_CHAR in UNICODE mode, ANSI->UNICODE conversion of the character was not done.
2) When hosting windows on threads created with CreateThread(), characters in WM_CHAR were wrongly converted from OS/2 codepage to ANSI codepage while they already were in ANSI due to the message queue begin switched to it at thread startup.
3) The main thread's message queue is now also switched to ANSI at startup so the conversion from step 2) should normally not take place now.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/thread.cpp

    r21308 r21529  
    687687    winteb->o.odin.hmq = OSLibWinQueryMsgQueue(winteb->o.odin.hab);
    688688    rc = OSLibWinSetCp(winteb->o.odin.hmq, GetDisplayCodepage());
    689     dprintf(("WinSetCP was %sOK", rc ? "" : "not "));
     689    dprintf(("WinSetCP(%d) was %sOK", GetDisplayCodepage(), rc ? "" : "not "));
    690690    hookInit(winteb->o.odin.hab);
    691691
  • trunk/src/user32/pmwindow.cpp

    r21426 r21529  
    201201    hookInit(hab);
    202202
    203     //BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
    204     //dprintf(("InitPM: WinSetCP was %s OK", rc ? " " : "not "));
     203    BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
     204    dprintf(("InitPM: WinSetCP(%d) was %sOK", GetDisplayCodepage(), rc ? "" : "not "));
    205205
    206206    /* IM instace is created per message queue, that is, thread */
     
    948948        {
    949949            MSG extramsg;
    950             char cpfrom[10] = {0};
    951             char cpto[10] = {0};
    952             ULONG  ulCpSize, ulCP, mp2l;
    953 
    954             mp2l = (ULONG)mp2 & 0x0000FFFF;
    955950            memcpy(&extramsg, pWinMsg, sizeof(MSG));
    956951            extramsg.message = WINWM_CHAR;
    957             DosQueryCp(sizeof(ulCP), &ulCP, &ulCpSize);
    958             sprintf(cpfrom,"IBM-%d\0", ulCP);
    959             sprintf(cpto,"IBM-%d\0", GetDisplayCodepage());
    960             if (cp2cp(cpfrom, cpto, (char*)&mp2l, (char*)&extramsg.wParam, 1))
    961                 extramsg.wParam = (ULONG)mp2l;
     952
     953            // convert character code if needed (normally not as both
     954            // Win32ThreadProc() and InitPM() set the HMQ code page to the
     955            // Windows ANSI code page)
     956            ULONG cpFrom = WinQueryCp(HMQ_CURRENT);
     957            ULONG cpTo = GetDisplayCodepage();
     958            if (cpFrom != cpTo) {
     959                char from[3], to[3];
     960                *((USHORT*)&from) = SHORT1FROMMP(mp2);
     961                from[2] = '\0';
     962                if (WinCpTranslateString(hab, cpFrom, from, cpTo, 3, to)) {
     963                    extramsg.wParam = *((USHORT*)&to);
     964                    dprintf(("OS2: WM_CHAR cp%d->cp%d: %08X->%08X", cpFrom, cpTo,
     965                             (int)SHORT1FROMMP(mp2), (int)extramsg.wParam));
     966                } else {
     967                    dprintf(("ERROR: cp%d->cp%d failed!", cpFrom, cpTo));
     968                }
     969            } else {
     970                extramsg.wParam = SHORT1FROMMP(mp2);
     971            }
    962972
    963973            if(SHORT1FROMMP(mp1) & KC_DEADKEY)
     
    14851495    }
    14861496
    1487         case WM_CHAR:
    1488                 {
    1489                         dprintf(("PMFRAME:WM_CHAR"));
    1490                         break;
    1491                 }
     1497    case WM_CHAR:
     1498        {
     1499            dprintf(("PMFRAME:WM_CHAR"));
     1500            break;
     1501        }
    14921502
    14931503    case WM_ADJUSTWINDOWPOS:
  • trunk/src/user32/win32wbase.cpp

    r21463 r21529  
    12871287ULONG Win32BaseWindow::MsgChar(MSG *msg)
    12881288{
    1289     return IsWindowUnicode() ? DispatchMsgW( msg ) : DispatchMsgA( msg );
     1289    if (IsWindowUnicode()) {
     1290        // Unicode windows expect the character code in UTF-16 while we save it
     1291        // in ascii format, so we need to convert before sending to the window
     1292        if (msg->message == WINWM_CHAR) {
     1293            CHAR  charA;
     1294            WCHAR charW;
     1295
     1296            charA = msg->wParam;
     1297            MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
     1298            msg->wParam= charW;
     1299            dprintf(("MsgChar: Convert to Unicode src=%x res=%x", charA, charW));
     1300        }
     1301        return DispatchMsgW(msg);
     1302    }
     1303    return DispatchMsgA(msg);
    12901304}
    12911305//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.