Ignore:
Timestamp:
Dec 28, 1999, 6:04:24 PM (26 years ago)
Author:
cbratschi
Message:

* empty log message *

File:
1 edited

Legend:

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

    r2221 r2228  
    1 /* $Id: edit.cpp,v 1.27 1999-12-27 22:53:52 cbratschi Exp $ */
     1/* $Id: edit.cpp,v 1.28 1999-12-28 17:04:22 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
    2225*/
    2326
     
    182185static INT      EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action);
    183186static VOID     EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc);
    184 static VOID     EDIT_Refresh(HWND hwnd,EDITSTATE *es);
     187static VOID     EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache);
    185188
    186189/*
     
    623626                //DPRINTF_EDIT_MSG32("WM_ENABLE");
    624627                es->bEnableState = (BOOL)wParam;
    625                 EDIT_Refresh(hwnd,es);
     628                EDIT_Refresh(hwnd,es,FALSE);
    626629                break;
    627630
     
    767770static void EDIT_BuildLineDefs_ML(HWND hwnd, EDITSTATE *es)
    768771{
    769         HDC dc;
     772        HDC dc = 0;
    770773        HFONT old_font = 0;
    771774        LPSTR start, cp;
     
    782785        es->line_count = 0;
    783786        es->text_width = 0;
    784 
    785         dc = GetDC(hwnd);
    786         if (es->font)
    787                 old_font = SelectObject(dc, es->font);
    788787
    789788        fw = es->format_rect.right - es->format_rect.left;
     
    809808                        current_def->net_length = cp - start;
    810809                }
     810
     811                if (!dc)
     812                {
     813                  dc = GetDC(hwnd);
     814                  if (es->font)
     815                    old_font = SelectObject(dc, es->font);
     816                }
     817
    811818                current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
    812819                                        start, current_def->net_length,
     
    857864                es->line_count++;
    858865        } while (current_def->ending != END_0);
    859         if (es->font)
    860                 SelectObject(dc, old_font);
    861         ReleaseDC(hwnd, dc);
     866        if (dc)
     867        {
     868          if (es->font)
     869                  SelectObject(dc, old_font);
     870          ReleaseDC(hwnd, dc);
     871        }
    862872        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
    863873}
     
    905915{
    906916        INT index;
    907         HDC dc;
     917        HDC dc = 0;
    908918        HFONT old_font = 0;
    909919
     
    929939                        return line_index;
    930940                }
    931                 dc = GetDC(hwnd);
    932                 if (es->font)
    933                         old_font = SelectObject(dc, es->font);
    934                     low = line_index + 1;
    935                     high = line_index + line_def->net_length + 1;
    936                     while (low < high - 1)
    937                     {
    938                         INT mid = (low + high) / 2;
    939                         if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
    940                         else low = mid;
    941                     }
    942                     index = low;
     941                low = line_index + 1;
     942                high = line_index + line_def->net_length + 1;
     943                if (low < high-1)
     944                {
     945                  if (!dc)
     946                  {
     947                    dc = GetDC(hwnd);
     948                    if (es->font)
     949                      old_font = SelectObject(dc, es->font);
     950                  }
     951
     952                  while (low < high-1)
     953                  {
     954                    INT mid = (low + high) / 2;
     955                    if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
     956                    else low = mid;
     957                  }
     958                }
     959                index = low;
    943960
    944961                if (after_wrap)
     
    954971                        return es->x_offset;
    955972                text = EDIT_GetPasswordPointer_SL(hwnd, es);
    956                 dc = GetDC(hwnd);
    957                 if (es->font)
    958                         old_font = SelectObject(dc, es->font);
    959973                if (x < 0)
    960974                {
    961                     INT low = 0;
    962                     INT high = es->x_offset;
    963                     while (low < high - 1)
     975                  INT low = 0;
     976                  INT high = es->x_offset;
     977
     978                  if (low < high-1)
     979                  {
     980                    if (!dc)
    964981                    {
    965                         INT mid = (low + high) / 2;
    966                         GetTextExtentPoint32A( dc, text + mid,
    967                                                es->x_offset - mid, &size );
    968                         if (size.cx > -x) low = mid;
    969                         else high = mid;
     982                      dc = GetDC(hwnd);
     983                      if (es->font)
     984                        old_font = SelectObject(dc, es->font);
    970985                    }
    971                     index = low;
    972                 }
    973                 else
     986
     987                    while (low < high-1)
     988                    {
     989                      INT mid = (low + high) / 2;
     990
     991                      GetTextExtentPoint32A( dc, text + mid,
     992                                             es->x_offset - mid, &size );
     993                      if (size.cx > -x) low = mid;
     994                      else high = mid;
     995                    }
     996                  }
     997                  index = low;
     998                } else
    974999                {
    975                     INT low = es->x_offset;
    976                     INT high = lstrlenA(es->text) + 1;
    977                     while (low < high - 1)
     1000                  INT low = es->x_offset;
     1001                  INT high = lstrlenA(es->text) + 1;
     1002
     1003                  if (low < high-1)
     1004                  {
     1005                    if (!dc)
    9781006                    {
    979                         INT mid = (low + high) / 2;
    980                         GetTextExtentPoint32A( dc, text + es->x_offset,
    981                                                mid - es->x_offset, &size );
    982                         if (size.cx > x) high = mid;
    983                         else low = mid;
     1007                      dc = GetDC(hwnd);
     1008                      if (es->font)
     1009                        old_font = SelectObject(dc, es->font);
    9841010                    }
    985                     index = low;
     1011
     1012                    while (low < high-1)
     1013                    {
     1014                      INT mid = (low + high) / 2;
     1015
     1016                      GetTextExtentPoint32A( dc, text + es->x_offset,
     1017                                             mid - es->x_offset, &size );
     1018                      if (size.cx > x) high = mid;
     1019                      else low = mid;
     1020                    }
     1021                  }
     1022                  index = low;
    9861023                }
    9871024                if (es->style & ES_PASSWORD)
    9881025                        HeapFree(es->heap, 0 ,text);
    9891026        }
    990         if (es->font)
    991                 SelectObject(dc, old_font);
    992         ReleaseDC(hwnd, dc);
     1027        if (dc)
     1028        {
     1029          if (es->font)
     1030            SelectObject(dc, old_font);
     1031          ReleaseDC(hwnd, dc);
     1032        }
    9931033        return index;
    9941034}
     
    10991139        {
    11001140          HideCaret(hwnd);
    1101           InvalidateRect(hwnd, &rc, FALSE);
     1141          InvalidateRect(hwnd, &rc, TRUE);
    11021142          ShowCaret(hwnd);
    11031143        }
     
    22092249        INT x;
    22102250        INT y = 0;
    2211         HDC dc;
     2251        HDC dc = 0;
    22122252        HFONT old_font = 0;
    22132253        SIZE size;
    22142254
    22152255        index = MIN(index, len);
    2216         dc = GetDC(hwnd);
    2217         if (es->font)
    2218                 old_font = SelectObject(dc, es->font);
     2256        if (!dc)
     2257        {
     2258          dc = GetDC(hwnd);
     2259          if (es->font)
     2260            old_font = SelectObject(dc, es->font);
     2261        }
    22192262        if (es->style & ES_MULTILINE) {
    22202263                l = EDIT_EM_LineFromChar(hwnd, es, index);
     
    23842427
    23852428        EDIT_EM_SetSel(hwnd, es, s, s, FALSE);
     2429
    23862430        es->flags |= EF_MODIFIED;
    23872431        es->flags |= EF_UPDATE;
    23882432        EDIT_EM_ScrollCaret(hwnd, es);
    2389 
    23902433        EDIT_NOTIFY_PARENT(hwnd,EN_UPDATE);
    23912434        /* FIXME: really inefficient */
    2392         EDIT_Refresh(hwnd,es);
     2435        EDIT_Refresh(hwnd,es,TRUE);
    23932436}
    23942437
     
    24862529                        } while ((x < goal) && es->x_offset);
    24872530                        /* FIXME: use ScrollWindow() somehow to improve performance */
    2488                         EDIT_Refresh(hwnd,es);
     2531                        EDIT_Refresh(hwnd,es,TRUE);
    24892532                        EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE);
    24902533                } else if (x > es->format_rect.right)
     
    24992542                        } while ((x > goal) && (x_last > es->format_rect.right));
    25002543                        /* FIXME: use ScrollWindow() somehow to improve performance */
    2501                         EDIT_Refresh(hwnd,es);
     2544                        EDIT_Refresh(hwnd,es,TRUE);
    25022545                        EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE);
    25032546                }
     
    25642607        es->flags &= ~EF_UPDATE;
    25652608        EDIT_BuildLineDefs_ML(hwnd, es);
    2566         EDIT_Refresh(hwnd,es);
     2609        EDIT_Refresh(hwnd,es,FALSE);
    25672610        EDIT_EM_ScrollCaret(hwnd, es);
    25682611        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
     
    26302673                  EDIT_BuildLineDefs_ML(hwnd, es);
    26312674
    2632           EDIT_Refresh(hwnd,es);
     2675          EDIT_Refresh(hwnd,es,FALSE);
    26332676          if (es->flags & EF_FOCUSED) {
    26342677                  DestroyCaret();
     
    26702713                es->style &= ~ES_PASSWORD;
    26712714        }
    2672         EDIT_Refresh(hwnd,es);
     2715        EDIT_Refresh(hwnd,es,FALSE);
    26732716}
    26742717
     
    26932736  {
    26942737    EDIT_SetRectNP(hwnd,es,lprc);
    2695     EDIT_Refresh(hwnd,es);
     2738    EDIT_Refresh(hwnd,es,FALSE);
    26962739  }
    26972740}
     
    27982841        if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
    27992842                EDIT_BuildLineDefs_ML(hwnd, es);
    2800                 EDIT_Refresh(hwnd,es);
     2843                EDIT_Refresh(hwnd,es,FALSE);
    28012844        }
    28022845}
     
    37193762}
    37203763
    3721 static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es)
     3764static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache)
    37223765{
    37233766  HDC hdc,hdcCompatible;
     
    37263769
    37273770  if (!IsWindowVisible(hwnd)) return;
     3771
     3772  if (!useCache)
     3773  {
     3774    InvalidateRect(hwnd,NULL,TRUE);
     3775    return;
     3776  }
    37283777
    37293778  //CB: original controls redraws many times, cache drawing
     
    38443893
    38453894        if (redraw)
    3846                 EDIT_Refresh(hwnd,es);
     3895                EDIT_Refresh(hwnd,es,FALSE);
    38473896        if (es->flags & EF_FOCUSED) {
    38483897                DestroyCaret();
     
    39023951                SetRect(&rc, 0, 0, width, height);
    39033952                EDIT_SetRectNP(hwnd, es, &rc);
    3904                 EDIT_Refresh(hwnd,es);
     3953                EDIT_Refresh(hwnd,es,FALSE);
    39053954        }
    39063955}
Note: See TracChangeset for help on using the changeset viewer.