Ignore:
Timestamp:
Apr 12, 2001, 4:04:54 PM (24 years ago)
Author:
sandervl
Message:

Sofiya: DBCS fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/win32wbase.cpp

    r5440 r5496  
    1 /* $Id: win32wbase.cpp,v 1.249 2001-04-02 17:30:58 sandervl Exp $ */
     1/* $Id: win32wbase.cpp,v 1.250 2001-04-12 14:04:32 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    109109  windowNameA      = NULL;
    110110  windowNameW      = NULL;
    111   wndNameLength    = 0;
    112111
    113112  userWindowBytes  = NULL;;
     
    545544        if (!isUnicode)
    546545        {
    547             wndNameLength = strlen(cs->lpszName);
     546            int wndNameLength = strlen(cs->lpszName);
    548547            windowNameA = (LPSTR)_smalloc(wndNameLength+1);
    549548            strcpy(windowNameA,cs->lpszName);
     
    555554        else
    556555        {
    557             wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
    558             windowNameA = (LPSTR)_smalloc(wndNameLength+1);
    559             lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
     556            // Wide
     557            int wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
    560558            windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
    561559            lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
    562             windowNameA[wndNameLength] = 0;
    563             windowNameW[wndNameLength] = 0;
     560            windowNameW[lstrlenW((LPWSTR)cs->lpszName)] = 0; // need ?
     561            // Ascii
     562            LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR)cs->lpszName);
     563            if(tmp) {
     564                long tmpLength = strlen( tmp );
     565                windowNameA = (LPSTR)_smalloc(tmpLength+1);
     566                strcpy(windowNameA,tmp);
     567                windowNameA[tmpLength] = 0; // need ?
     568                HEAP_free(tmp);
     569            } else {
     570                windowNameA = (LPSTR)_smalloc(1);
     571                windowNameA[0] = 0;
     572            }
    564573        }
    565574    }
     
    13801389
    13811390    case WM_GETTEXTLENGTH:
    1382         return wndNameLength;
     1391        if(windowNameA) {
     1392          return strlen(windowNameA);
     1393        }
     1394        else {
     1395          return 0;
     1396        }
    13831397
    13841398    case WM_GETTEXT:
     
    13861400        if (!windowNameA) ((LPSTR)lParam)[0] = 0;
    13871401        else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
    1388         return min(wndNameLength, wParam);
     1402        return min((windowNameA ? strlen(windowNameA) : 0), wParam);
    13891403
    13901404    case WM_SETTEXT:
     
    13961410        if (lParam)
    13971411        {
    1398             wndNameLength = strlen(lpsz);
     1412            int wndNameLength = strlen(lpsz);
    13991413            windowNameA = (LPSTR)_smalloc(wndNameLength+1);
    14001414            strcpy(windowNameA, lpsz);
     
    14061420            windowNameA = NULL;
    14071421            windowNameW = NULL;
    1408             wndNameLength = 0;
    14091422        }
    14101423        dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
     
    16891702        sibling = GetWindow (GW_HWNDFIRST);
    16901703        while (sibling != 0) {
    1691           siblingWindow = GetWindowFromHandle (sibling);
    1692           nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
    1693 
    1694           // find the siblings mnemonic
    1695           mnemonic = '\0';
    1696           for (int i=0 ; i<nameLength ; i++) {
    1697             if (nameBuffer [i] == '&') {
    1698               mnemonic = nameBuffer [i+1];
    1699               if ((mnemonic >= 'a') && (mnemonic <= 'z'))
    1700                 mnemonic -= 32; // make it uppercase
    1701               break;  // stop searching
     1704            siblingWindow = GetWindowFromHandle (sibling);
     1705            nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
     1706
     1707            // find the siblings mnemonic
     1708            mnemonic = '\0';
     1709            for (int i=0 ; i<nameLength ; i++) {
     1710                if (IsDBCSLeadByte(nameBuffer[i])) {
     1711                    // Skip DBCS
     1712                    continue;
     1713                }
     1714                if (nameBuffer [i] == '&') {
     1715                    mnemonic = nameBuffer [i+1];
     1716                    if ((mnemonic >= 'a') && (mnemonic <= 'z'))
     1717                        mnemonic -= 32; // make it uppercase
     1718                    break;  // stop searching
     1719                }
    17021720            }
    1703           }
    1704 
    1705           // key matches siblings mnemonic, send mouseclick
    1706           if (mnemonic == (char) wParam) {
    1707             siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
    1708           }
    1709 
    1710           sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
     1721
     1722            // key matches siblings mnemonic, send mouseclick
     1723            if (mnemonic == (char) wParam) {
     1724                siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
     1725            }
     1726
     1727            sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
    17111728        }
    17121729
     
    18451862    {
    18461863    case WM_GETTEXTLENGTH:
    1847         return wndNameLength;
     1864        if(windowNameW) {
     1865             return lstrlenW(windowNameW);
     1866        }
     1867        else return 0;
    18481868
    18491869    case WM_GETTEXT:
     
    18511871        if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
    18521872        else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
    1853         return min(wndNameLength,wParam);
     1873        return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam);
    18541874
    18551875    case WM_SETTEXT:
     
    18611881        if (lParam)
    18621882        {
    1863           wndNameLength = lstrlenW(lpsz);
    1864           windowNameA = (LPSTR)_smalloc(wndNameLength+1);
    1865           lstrcpyWtoA(windowNameA,lpsz);
    1866           windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
    1867           lstrcpyW(windowNameW,lpsz);
     1883            // Wide
     1884            int wndNameLength = lstrlenW(lpsz);
     1885            windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
     1886            lstrcpyW(windowNameW,lpsz);
     1887            // Ascii
     1888            LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz);
     1889            if(tmp) {
     1890                long tmpLength = strlen( tmp );
     1891                windowNameA = (LPSTR)_smalloc(tmpLength+1);
     1892                strcpy(windowNameA,tmp);
     1893                windowNameA[tmpLength] = 0; // need ?
     1894                HEAP_free(tmp);
     1895            }
     1896            else {
     1897                windowNameA = (LPSTR)_smalloc(1);
     1898                windowNameA[0] = 0;
     1899            }
    18681900        }
    18691901        else
    18701902        {
    1871           windowNameA = NULL;
    1872           windowNameW = NULL;
    1873           wndNameLength = 0;
     1903            windowNameA = NULL;
     1904            windowNameW = NULL;
    18741905        }
    18751906        dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
     
    22982329//testestest
    22992330    //temporary workaround for file dialogs with template dialog child
    2300     //they don't redraw when switching directories 
     2331    //they don't redraw when switching directories
    23012332    //For some reason the new child's (syslistview32) update rectangle stays
    23022333    //empty after its parent is made visible with ShowWindow
     
    32383269BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
    32393270{
    3240     INT len = GetWindowTextLength();
     3271    INT len = GetWindowTextLength(fUnicode);
    32413272    BOOL res;
    32423273
    32433274    if (wndname == NULL)
    3244       return (len == 0);
     3275        return (len == 0);
    32453276
    32463277    len++;
    32473278    if (fUnicode)
    32483279    {
    3249       WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
    3250 
    3251       GetWindowTextW(text,len);
    3252       res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
    3253       free(text);
    3254     } else
    3255     {
    3256       CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
    3257 
    3258       GetWindowTextA(text,len);
    3259       res = (strcmp(text,wndname) == 0);
    3260       free(text);
     3280        WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
     3281
     3282        GetWindowTextW(text,len);
     3283        res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
     3284        free(text);
     3285    }
     3286    else
     3287    {
     3288        CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
     3289
     3290        GetWindowTextA(text,len);
     3291        res = (strcmp(text,wndname) == 0);
     3292        free(text);
    32613293    }
    32623294
     
    32673299CHAR *Win32BaseWindow::getWindowNamePtrA()
    32683300{
    3269     INT len = GetWindowTextLength();
     3301    INT len = GetWindowTextLength(FALSE);
    32703302    CHAR *text;
    32713303
     
    32813313WCHAR *Win32BaseWindow::getWindowNamePtrW()
    32823314{
    3283     INT len = GetWindowTextLength();
     3315    INT len = GetWindowTextLength(TRUE);
    32843316    WCHAR *text;
    32853317
     
    33013333//does NOT send WM_GETTEXTLENGTH.
    33023334//******************************************************************************
    3303 int Win32BaseWindow::GetWindowTextLength()
     3335int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
    33043336{
    33053337    //if the destination window is created by this process, send message
    33063338    if(dwProcessId == currentProcessId) {
    3307         return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
     3339        if(fUnicode) {
     3340             return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
     3341        }
     3342        else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
    33083343    }
    33093344    //else get data directory from window structure
    3310     return wndNameLength;
     3345    //TODO: must lock window structure.... (TODO)
     3346    if(fUnicode) {
     3347        if(windowNameW) {
     3348             return strlenW(windowNameW);
     3349        }
     3350        else return 0;
     3351    }
     3352    else {
     3353        if(windowNameA) {
     3354             return strlen(windowNameA);
     3355        }
     3356        else return 0;
     3357    }
    33113358}
    33123359//******************************************************************************
     
    33243371    if (!windowNameA) lpsz[0] = 0;
    33253372    else lstrcpynA(lpsz, windowNameA, cch);
    3326     return min(wndNameLength, cch);
     3373    return min((windowNameA ? strlen(windowNameA) : 0), cch);
    33273374}
    33283375//******************************************************************************
     
    33403387    if (!windowNameW) lpsz[0] = 0;
    33413388    else lstrcpynW(lpsz, windowNameW, cch);
    3342     return min(wndNameLength, cch);
     3389    return min((windowNameW ? strlenW(windowNameW) : 0), cch);
    33433390}
    33443391//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.