Ignore:
Timestamp:
Dec 29, 1999, 11:54:04 PM (26 years ago)
Author:
cbratschi
Message:

new mapping functions, fixed 1 pixel and window handle bugs

File:
1 edited

Legend:

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

    r2228 r2257  
    1 /* $Id: edit.cpp,v 1.28 1999-12-28 17:04:22 cbratschi Exp $ */
     1/* $Id: edit.cpp,v 1.29 1999-12-29 22:53:59 cbratschi Exp $ */
    22/*
    33 *      Edit control
     
    2020    new in Win98, Win2k: for single line too
    2121  - WinNT/Win2k: higher size limits (single: 0x7FFFFFFE, multi: none)
    22   - too many GetDC/ReleaseDC calls -> GetDC is very slow!
    23     EM_REPLACESEL: calls more than 10 times GetDC/ReleaseDC!
    24     add HDC parameter
     22  - too many redraws and recalculations!
    2523*/
    2624
     
    154152 *      Helper functions only valid for one type of control
    155153 */
    156 static void     EDIT_BuildLineDefs_ML(HWND hwnd, EDITSTATE *es);
     154static void     EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es);
    157155static LPSTR    EDIT_GetPasswordPointer_SL(HWND hwnd, EDITSTATE *es);
    158156static void     EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
     
    167165static INT      EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
    168166static void     EDIT_ConfinePoint(HWND hwnd, EDITSTATE *es, LPINT x, LPINT y);
    169 static void     EDIT_GetLineRect(HWND hwnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
     167static void     EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
    170168static void     EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end);
    171169static void     EDIT_LockBuffer(HWND hwnd, EDITSTATE *es);
     
    208206static INT      EDIT_EM_LineLength(HWND hwnd, EDITSTATE *es, INT index);
    209207static BOOL     EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy);
    210 static LRESULT  EDIT_EM_PosFromChar(HWND hwnd, EDITSTATE *es, INT index, BOOL after_wrap);
     208static LRESULT  EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap);
    211209static void     EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace);
    212210static LRESULT  EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action);
     
    565563        case EM_POSFROMCHAR:
    566564                //DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
    567                 result = EDIT_EM_PosFromChar(hwnd, es, (INT)wParam, FALSE);
     565                result = EDIT_EM_PosFromChar(hwnd,0, es, (INT)wParam, FALSE);
    568566                break;
    569567
     
    768766 *
    769767 */
    770 static void EDIT_BuildLineDefs_ML(HWND hwnd, EDITSTATE *es)
    771 {
    772         HDC dc = 0;
     768static void EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es)
     769{
     770        HDC hdc = 0;
    773771        HFONT old_font = 0;
    774772        LPSTR start, cp;
     
    809807                }
    810808
    811                 if (!dc)
     809                if (!hdc)
    812810                {
    813                   dc = GetDC(hwnd);
     811                  hdc = GetDC(hwnd);
    814812                  if (es->font)
    815                     old_font = SelectObject(dc, es->font);
     813                    old_font = SelectObject(hdc, es->font);
    816814                }
    817815
    818                 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
     816                current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc,
    819817                                        start, current_def->net_length,
    820818                                        es->tabs_count, es->tabs));
     
    827825                                next = EDIT_CallWordBreakProc(hwnd, es, start - es->text,
    828826                                                prev + 1, current_def->net_length, WB_RIGHT);
    829                                 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
     827                                current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc,
    830828                                                        start, next, es->tabs_count, es->tabs));
    831829                        } while (current_def->width <= fw);
     
    835833                                        prev = next;
    836834                                        next++;
    837                                         current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
     835                                        current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc,
    838836                                                                start, next, es->tabs_count, es->tabs));
    839837                                } while (current_def->width <= fw);
     
    843841                        current_def->net_length = prev;
    844842                        current_def->ending = END_WRAP;
    845                         current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, start,
     843                        current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, start,
    846844                                                current_def->net_length, es->tabs_count, es->tabs));
    847845                }
     
    864862                es->line_count++;
    865863        } while (current_def->ending != END_0);
    866         if (dc)
     864        if (hdc)
    867865        {
    868866          if (es->font)
    869                   SelectObject(dc, old_font);
    870           ReleaseDC(hwnd, dc);
     867                  SelectObject(hdc, old_font);
     868          ReleaseDC(hwnd, hdc);
    871869        }
    872870        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
     
    10581056 *
    10591057 */
    1060 static void EDIT_GetLineRect(HWND hwnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
     1058static void EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
    10611059{
    10621060        INT line_index =  EDIT_EM_LineIndex(hwnd, es, line);
     
    10681066        rc->bottom = rc->top + es->line_height;
    10691067
    1070         rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd, es, line_index + scol, TRUE));
    1071         rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd, es, line_index + ecol, TRUE))+1;
     1068        rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + scol, TRUE));
     1069        rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + ecol, TRUE))+1;
    10721070}
    10731071
     
    11341132        RECT rc;
    11351133
    1136         EDIT_GetLineRect(hwnd, es, 0, start, end, &line_rect);
     1134        EDIT_GetLineRect(hwnd,0, es, 0, start, end, &line_rect);
    11371135
    11381136        if (IntersectRect(&rc, &line_rect, &es->format_rect))
     
    11831181        HideCaret(hwnd);
    11841182        if (sl == el) {
    1185                 EDIT_GetLineRect(hwnd, es, sl, sc, ec, &rcLine);
     1183                EDIT_GetLineRect(hwnd,0, es, sl, sc, ec, &rcLine);
    11861184
    11871185                if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
    11881186                        InvalidateRect(hwnd, &rcUpdate, TRUE);
    11891187        } else {
    1190                 EDIT_GetLineRect(hwnd, es, sl, sc,
     1188                EDIT_GetLineRect(hwnd,0, es, sl, sc,
    11911189                                EDIT_EM_LineLength(hwnd, es,
    11921190                                        EDIT_EM_LineIndex(hwnd, es, sl)),
     
    11951193                        InvalidateRect(hwnd, &rcUpdate, TRUE);
    11961194                for (l = sl + 1 ; l < el ; l++) {
    1197                         EDIT_GetLineRect(hwnd, es, l, 0,
     1195                        EDIT_GetLineRect(hwnd,0, es, l, 0,
    11981196                                EDIT_EM_LineLength(hwnd, es,
    11991197                                        EDIT_EM_LineIndex(hwnd, es, l)),
     
    12021200                                InvalidateRect(hwnd, &rcUpdate, TRUE);
    12031201                }
    1204                 EDIT_GetLineRect(hwnd, es, el, 0, ec, &rcLine);
     1202                EDIT_GetLineRect(hwnd,0, es, el, 0, ec, &rcLine);
    12051203                if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
    12061204                        InvalidateRect(hwnd, &rcUpdate, TRUE);
     
    13531351        INT e = es->selection_end;
    13541352        BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
    1355         LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);
     1353        LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
    13561354        INT x = SLOWORD(pos);
    13571355        INT y = SHIWORD(pos);
     
    13781376        if (es->style & ES_MULTILINE)
    13791377                e = EDIT_CharFromPos(hwnd, es, 0x3fffffff,
    1380                         HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
     1378                        HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
    13811379        else
    13821380                e = lstrlenA(es->text);
     
    14231421        if (es->style & ES_MULTILINE)
    14241422                e = EDIT_CharFromPos(hwnd, es, -es->x_offset,
    1425                         HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
     1423                        HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
    14261424        else
    14271425                e = 0;
     
    14451443        INT e = es->selection_end;
    14461444        BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
    1447         LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);
     1445        LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
    14481446        INT x = SLOWORD(pos);
    14491447        INT y = SHIWORD(pos);
     
    14731471        INT e = es->selection_end;
    14741472        BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
    1475         LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);
     1473        LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
    14761474        INT x = SLOWORD(pos);
    14771475        INT y = SHIWORD(pos);
     
    15011499        INT e = es->selection_end;
    15021500        BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
    1503         LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);
     1501        LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
    15041502        INT x = SLOWORD(pos);
    15051503        INT y = SHIWORD(pos);
     
    15991597        //TRACE_(edit)("line=%d\n", line);
    16001598
    1601         pos = EDIT_EM_PosFromChar(hwnd, es, EDIT_EM_LineIndex(hwnd, es, line), FALSE);
     1599        pos = EDIT_EM_PosFromChar(hwnd,dc, es, EDIT_EM_LineIndex(hwnd, es, line), FALSE);
    16021600        x = SLOWORD(pos);
    16031601        y = SHIWORD(pos);
     
    17181716                             BOOL after_wrap)
    17191717{
    1720         LRESULT res = EDIT_EM_PosFromChar(hwnd, es, pos, after_wrap);
     1718        LRESULT res = EDIT_EM_PosFromChar(hwnd,0, es, pos, after_wrap);
    17211719        INT x = SLOWORD(res);
    17221720        INT y = SHIWORD(res);
     
    17641762                es->format_rect.bottom = es->format_rect.top + es->line_height;
    17651763        if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
    1766                 EDIT_BuildLineDefs_ML(hwnd, es);
     1764                EDIT_BuildLineDefs_ML(hwnd,es);
    17671765        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
    17681766}
     
    22262224                IntersectRect(&rc, &rc1, &es->format_rect);
    22272225
    2228                 ScrollWindowEx(hwnd, -dx, dy,
    2229                                 NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE);
     2226                ScrollWindowEx(hwnd,-dx,dy,NULL,&rc,(HRGN)NULL,NULL,SW_INVALIDATE);
    22302227                es->y_offset = nyoff;
    22312228                es->x_offset += dx;
     
    22422239 *
    22432240 */
    2244 static LRESULT EDIT_EM_PosFromChar(HWND hwnd, EDITSTATE *es, INT index, BOOL after_wrap)
     2241static LRESULT EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap)
    22452242{
    22462243        INT len = lstrlenA(es->text);
     
    22492246        INT x;
    22502247        INT y = 0;
    2251         HDC dc = 0;
     2248        BOOL createdDC = FALSE;
    22522249        HFONT old_font = 0;
    22532250        SIZE size;
     
    22592256          if (es->font)
    22602257            old_font = SelectObject(dc, es->font);
     2258          createdDC = TRUE;
    22612259        }
    22622260        if (es->style & ES_MULTILINE) {
     
    22962294        x += es->format_rect.left;
    22972295        y += es->format_rect.top;
    2298         if (es->font)
    2299                 SelectObject(dc, old_font);
    2300         ReleaseDC(hwnd, dc);
     2296        if (createdDC)
     2297        {
     2298          if (es->font)
     2299            SelectObject(dc, old_font);
     2300          ReleaseDC(hwnd, dc);
     2301        }
    23012302        return MAKELONG((INT16)x, (INT16)y);
    23022303}
     
    24242425        /* FIXME: really inefficient */
    24252426        if (es->style & ES_MULTILINE)
    2426                 EDIT_BuildLineDefs_ML(hwnd, es);
     2427                EDIT_BuildLineDefs_ML(hwnd,es);
    24272428
    24282429        EDIT_EM_SetSel(hwnd, es, s, s, FALSE);
     
    24982499                l = EDIT_EM_LineFromChar(hwnd, es, es->selection_end);
    24992500                li = EDIT_EM_LineIndex(hwnd, es, l);
    2500                 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP));
     2501                x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP));
    25012502                vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
    25022503                if (l >= es->y_offset + vlc)
     
    25192520                        return;
    25202521
    2521                 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));
     2522                x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE));
    25222523                format_width = es->format_rect.right - es->format_rect.left;
    25232524                if (x < es->format_rect.left)
     
    25262527                        do {
    25272528                                es->x_offset--;
    2528                                 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));
     2529                                x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE));
    25292530                        } while ((x < goal) && es->x_offset);
    25302531                        /* FIXME: use ScrollWindow() somehow to improve performance */
     
    25382539                        do {
    25392540                                es->x_offset++;
    2540                                 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));
    2541                                 x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, len, FALSE));
     2541                                x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE));
     2542                                x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, len, FALSE));
    25422543                        } while ((x > goal) && (x_last > es->format_rect.right));
    25432544                        /* FIXME: use ScrollWindow() somehow to improve performance */
     
    26062607        es->flags &= ~EF_MODIFIED;
    26072608        es->flags &= ~EF_UPDATE;
    2608         EDIT_BuildLineDefs_ML(hwnd, es);
     2609        EDIT_BuildLineDefs_ML(hwnd,es);
    26092610        EDIT_Refresh(hwnd,es,FALSE);
    26102611        EDIT_EM_ScrollCaret(hwnd, es);
     
    26712672          EDIT_SetRectNP(hwnd, es, &r);
    26722673          if (es->style & ES_MULTILINE)
    2673                   EDIT_BuildLineDefs_ML(hwnd, es);
     2674                  EDIT_BuildLineDefs_ML(hwnd,es);
    26742675
    26752676          EDIT_Refresh(hwnd,es,FALSE);
     
    28402841        es->word_break_procA = wbp;
    28412842        if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
    2842                 EDIT_BuildLineDefs_ML(hwnd, es);
     2843                EDIT_BuildLineDefs_ML(hwnd,es);
    28432844                EDIT_Refresh(hwnd,es,FALSE);
    28442845        }
     
    37393740    for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++)
    37403741    {
    3741       EDIT_GetLineRect(hwnd, es, i, 0, -1, &rcLine);
     3742      EDIT_GetLineRect(hwnd,hdc, es, i, 0, -1, &rcLine);
    37423743      if (IntersectRect(&rc, &rcRgn, &rcLine))
    37433744        EDIT_PaintLine(hwnd, es, hdc, i, rev);
     
    37453746  } else
    37463747  {
    3747     EDIT_GetLineRect(hwnd, es, 0, 0, -1, &rcLine);
     3748    EDIT_GetLineRect(hwnd,hdc, es, 0, 0, -1, &rcLine);
    37483749    if (IntersectRect(&rc, &rcRgn, &rcLine))
    37493750      EDIT_PaintLine(hwnd, es, hdc, 0, rev);
     
    38903891        EDIT_SetRectNP(hwnd, es, &r);
    38913892        if (es->style & ES_MULTILINE)
    3892                 EDIT_BuildLineDefs_ML(hwnd, es);
     3893                EDIT_BuildLineDefs_ML(hwnd,es);
    38933894
    38943895        if (redraw)
Note: See TracChangeset for help on using the changeset viewer.