Changeset 20997


Ignore:
Timestamp:
Feb 16, 2004, 2:20:10 PM (21 years ago)
Author:
sandervl
Message:

KOM: Edit control: DBCS related fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tags/trunk/src/user32/edit.c

    r20752 r20997  
    231231static INT  EDIT_EM_LineIndex(EDITSTATE *es, INT line);
    232232static INT  EDIT_EM_LineLength(EDITSTATE *es, INT index);
     233#ifdef __WIN32OS2__
     234static INT  EDIT_EM_LineLengthA(EDITSTATE *es, INT index);
     235#endif
    233236static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy);
    234237static BOOL EDIT_EM_LineScroll_internal(HWND hwnd, EDITSTATE *es, INT dx, INT dy);
     
    459462            EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE);
    460463        else
     464#ifdef __WIN32OS2__
     465        if( IsDBCSEnv() && SHIWORD( lParam ) != -1 )
     466        {
     467            INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 );
     468            LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA );
     469            WORD wLo, wHi;
     470
     471            if( textA )
     472            {
     473                WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 );
     474
     475                wLo = LOWORD( lParam );
     476                wHi = HIWORD( lParam );
     477
     478                if( wLo > countA )
     479                    wLo = countA;
     480                wLo = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, wLo, 0, 0 );
     481
     482                if( wHi > countA )
     483                    wHi = countA;
     484                wHi = ( LPARAM )MultiByteToWideChar( CP_ACP, 0, textA, wHi, 0, 0 );
     485
     486                lParam = MAKELPARAM( wLo, wHi );
     487
     488                HeapFree( GetProcessHeap(), 0, textA );
     489            }
     490#endif
    461491            EDIT_EM_SetSel(hwnd, es, LOWORD(lParam), HIWORD(lParam), FALSE);
     492#ifdef __WIN32OS2__
     493        }
     494#endif
    462495        if (!wParam)
    463496            EDIT_EM_ScrollCaret(hwnd, es);
     
    466499    case EM_SETSEL:
    467500        DPRINTF_EDIT_MSG32("EM_SETSEL");
     501#ifdef __WIN32OS2__
     502        if( !unicode && IsDBCSEnv() && ( INT )wParam != -1 && ( INT )lParam != -1 )
     503        {
     504            INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 );
     505            LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA );
     506
     507            if( textA )
     508            {
     509                WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 );
     510
     511                if(( INT )wParam > countA )
     512                    wParam = ( WPARAM ) countA;
     513                wParam = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )wParam, 0, 0 );
     514
     515                if(( INT )lParam > countA )
     516                    lParam = ( LPARAM ) countA;
     517                lParam = ( LPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )lParam, 0, 0 );
     518
     519                HeapFree( GetProcessHeap(), 0, textA );
     520            }
     521        }
     522#endif
    468523        EDIT_EM_SetSel(hwnd, es, wParam, lParam, FALSE);
    469524        EDIT_EM_ScrollCaret(hwnd, es);
     
    575630        DPRINTF_EDIT_MSG32("EM_LINEINDEX");
    576631        result = (LRESULT)EDIT_EM_LineIndex(es, (INT)wParam);
     632#ifdef __WIN32OS2__
     633        if( !unicode )
     634            result = WideCharToMultiByte( CP_ACP, 0, es->text, result, 0, 0, 0, 0 );
     635#endif
    577636        break;
    578637
     
    630689    case EM_LINELENGTH:
    631690        DPRINTF_EDIT_MSG32("EM_LINELENGTH");
     691#ifdef __WIN32OS2__
     692        if( !unicode )
     693        result = ( LRESULT )EDIT_EM_LineLengthA(es, (INT)wParam);
     694        else
     695#endif
    632696        result = (LRESULT)EDIT_EM_LineLength(es, (INT)wParam);
    633697        break;
     
    719783    case EM_LINEFROMCHAR:
    720784        DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
     785#ifdef __WIN32OS2__
     786        if( !unicode && IsDBCSEnv() && ( INT )wParam != -1 )
     787        {
     788            INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 );
     789            LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA );
     790
     791            if( textA )
     792            {
     793                WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 );
     794
     795                if(( INT )wParam > countA )
     796                    wParam = ( WPARAM )countA;
     797
     798                wParam = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )wParam, 0, 0 );
     799
     800                HeapFree( GetProcessHeap(), 0, textA );
     801            }
     802        }
     803#endif
    721804        result = (LRESULT)EDIT_EM_LineFromChar(es, (INT)wParam);
    722805        break;
     
    854937    case EM_POSFROMCHAR:
    855938        DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
     939#ifdef __WIN32OS2__
     940        if( !unicode && IsDBCSEnv() )
     941        {
     942            INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 );
     943            LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA );
     944
     945            if( textA )
     946            {
     947                WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 );
     948
     949                if(( INT )wParam > countA )
     950                    wParam = ( WPARAM ) countA;
     951                wParam = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )wParam, 0, 0 );
     952
     953                HeapFree( GetProcessHeap(), 0, textA );
     954            }
     955        }
     956#endif
    856957        result = EDIT_EM_PosFromChar(hwnd, es, (INT)wParam, FALSE);
    857958        break;
     
    860961        DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
    861962        result = EDIT_EM_CharFromPos(hwnd, es, SLOWORD(lParam), SHIWORD(lParam));
     963#ifdef __WIN32OS2__
     964        if( !unicode )
     965        {
     966            WORD wLo = LOWORD( result );
     967            WORD wHi = HIWORD( result );
     968
     969            wLo = WideCharToMultiByte( CP_ACP, 0, es->text, wLo, 0, 0, 0, 0 );
     970            wHi = WideCharToMultiByte( CP_ACP, 0, es->text, wHi, 0, 0, 0, 0 );
     971            result = ( LRESULT )MAKELONG( wLo, wHi );
     972        }
     973#endif
    862974        break;
    863975
     
    9781090        DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
    9791091        result = strlenW(es->text);
     1092#ifdef __WIN32OS2__
     1093        if( !unicode )
     1094            result = WideCharToMultiByte( CP_ACP, 0, es->text, result, 0, 0, 0, 0 );
     1095#endif
    9801096        break;
    9811097
     
    22162332    INT y;
    22172333    LRESULT pos;
     2334    HBRUSH brush;
     2335    RECT rc;
     2336
    22182337
    22192338    if (es->style & ES_MULTILINE) {
     
    22292348    x = SLOWORD(pos);
    22302349    y = SHIWORD(pos);
     2350
    22312351    li = EDIT_EM_LineIndex(es, line);
    22322352    ll = EDIT_EM_LineLength(es, li);
     
    22432363    } else
    22442364        x += EDIT_PaintText(es, dc, x, y, line, 0, ll, FALSE);
     2365
     2366#if 0
     2367#ifdef __WIN32OS2__
     2368    if ( get_app_version() >= 0x40000 &&(
     2369                !es->bEnableState || (es->style & ES_READONLY)))
     2370            brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, dc);
     2371    else
     2372            brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, dc);
     2373
     2374    if (!brush)
     2375            brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
     2376
     2377    rc.left = x;
     2378    rc.right = es->format_rect.right;
     2379    rc.top = y;
     2380    rc.bottom = y + es->line_height;
     2381
     2382    FillRect(dc, &rc, brush);
     2383#endif
     2384#endif
    22452385}
    22462386
     
    27762916    UINT e = es->selection_end;
    27772917
     2918#ifdef __WIN32OS2__
     2919    if( !es->is_unicode)
     2920    {
     2921        s = WideCharToMultiByte( CP_ACP, 0, es->text, s, 0, 0, 0, 0 );
     2922        e = WideCharToMultiByte( CP_ACP, 0, es->text, e, 0, 0, 0, 0 );
     2923    }
     2924#endif
     2925
    27782926    ORDER_UINT(s, e);
    27792927    if (start)
     
    29013049}
    29023050
     3051#ifdef __WIN32OS2__
     3052/*********************************************************************
     3053 *
     3054 *  EM_LINELENGTH for ANSI
     3055 *
     3056 */
     3057static INT EDIT_EM_LineLengthA(EDITSTATE *es, INT index)
     3058{
     3059    LINEDEF *line_def;
     3060
     3061    if (!(es->style & ES_MULTILINE))
     3062        return ( WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 ) - 1);
     3063
     3064    if (index == -1) {
     3065        /* get the number of remaining non-selected chars of selected lines */
     3066        INT32 l; /* line number */
     3067        INT32 li; /* index of first char in line */
     3068        INT32 count;
     3069        l = EDIT_EM_LineFromChar(es, es->selection_start);
     3070        li = EDIT_EM_LineIndex( es, l );
     3071        li = WideCharToMultiByte( CP_ACP, 0, es->text, li, 0, 0, 0, 0 );
     3072        /* # chars before start of selection area */
     3073        count = WideCharToMultiByte( CP_ACP, 0, es->text, es->selection_start, 0, 0, 0, 0 );
     3074        count -= li;
     3075        l = EDIT_EM_LineFromChar(es, es->selection_end);
     3076        /* # chars after end of selection */
     3077        li = EDIT_EM_LineIndex(es, l);
     3078        li = WideCharToMultiByte( CP_ACP, 0, es->text, li, 0, 0, 0, 0 );
     3079        count += li + EDIT_EM_LineLengthA(es, li);
     3080        count -= WideCharToMultiByte( CP_ACP, 0, es->text, es->selection_end, 0, 0, 0, 0 );
     3081        return count;
     3082    }
     3083    line_def = es->first_line_def;
     3084    index -= line_def->length;
     3085    while ((index >= 0) && line_def->next) {
     3086        line_def = line_def->next;
     3087        index -= line_def->length;
     3088    }
     3089    return WideCharToMultiByte( CP_ACP, 0, es->text + line_def->index, line_def->net_length, 0, 0, 0, 0 );
     3090}
     3091#endif
    29033092
    29043093/*********************************************************************
Note: See TracChangeset for help on using the changeset viewer.