Changeset 1717 for trunk/src


Ignore:
Timestamp:
Nov 12, 1999, 6:16:37 PM (26 years ago)
Author:
cbratschi
Message:

fixed several edit bugs

Location:
trunk/src/user32
Files:
2 edited

Legend:

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

    r1705 r1717  
    1 /* $Id: edit.cpp,v 1.12 1999-11-11 17:13:45 cbratschi Exp $ */
     1/* $Id: edit.cpp,v 1.13 1999-11-12 17:16:36 cbratschi Exp $ */
    22/*
    33 *      Edit control
     
    77 *      Copyright  Frans van Dorsselaer, 1996, 1997
    88 *
    9  *      Copyright  1999 Christoph Bratschi (ported from WINE)
     9 *      Copyright  1999 Christoph Bratschi
    1010 *
    1111 * WINE version: 990923
     
    1515 *      please read EDIT.TODO (and update it when you change things)
    1616 */
     17
     18/* CB: todo
     19  - EN_UPDATE: send before update
     20  - EN_CHANGE: send after update -> WM_PAINT isn't the right place
     21  - EN_HSCROLL/EN_VSCROLL: send before update
     22  - still problems with caret
     23  - WS_BORDER -> bug in Win32BaseWindow::SetWindowLong
     24*/
    1725
    1826#include <os2win.h>
     
    143151static void     EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
    144152static void     EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
     153static VOID     EDIT_UpdateScrollBars(HWND hwnd,EDITSTATE *es,BOOL updateHorz,BOOL updateVert);
    145154/*
    146155 *      Helper functions valid for both single line _and_ multi line controls
     
    166175static void     EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force);
    167176static INT      EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action);
     177static VOID     EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc);
     178static VOID     EDIT_Refresh(HWND hwnd,EDITSTATE *es);
     179
    168180/*
    169181 *      EM_XXX message handlers
     
    331343                if ((es->style & ES_MULTILINE) && lParam) {
    332344                        EDIT_SetRectNP(hwnd, es, (LPRECT)lParam);
    333                         InvalidateRect(hwnd, NULL, TRUE);
     345                        EDIT_Refresh(hwnd,es);
    334346                }
    335347                break;
     
    597609                //DPRINTF_EDIT_MSG32("WM_ENABLE");
    598610                es->bEnableState = (BOOL)wParam;
    599                 InvalidateRect(hwnd, NULL, TRUE);
     611                EDIT_Refresh(hwnd,es);
    600612                break;
    601613
     
    830842                SelectObject(dc, old_font);
    831843        ReleaseDC(hwnd, dc);
     844        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
    832845}
    833846
     
    16341647        if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
    16351648                EDIT_BuildLineDefs_ML(hwnd, es);
     1649        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
    16361650}
    16371651
     
    19962010}
    19972011
     2012static VOID EDIT_UpdateScrollBars(HWND hwnd,EDITSTATE *es,BOOL updateHorz,BOOL updateVert)
     2013{
     2014  if (updateHorz && (es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
     2015  {
     2016    SCROLLINFO si;
     2017    INT fw = es->format_rect.right - es->format_rect.left;
     2018
     2019    si.cbSize       = sizeof(SCROLLINFO);
     2020    si.fMask        = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
     2021    si.nMin         = 0;
     2022    si.nMax         = es->text_width + fw - 1;
     2023    si.nPage        = fw;
     2024    si.nPos         = es->x_offset;
     2025    SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
     2026  }
     2027
     2028  if (updateVert && (es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
     2029  {
     2030    INT vlc = (es->format_rect.bottom-es->format_rect.top)/es->line_height;
     2031    SCROLLINFO si;
     2032
     2033    si.cbSize       = sizeof(SCROLLINFO);
     2034    si.fMask        = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
     2035    si.nMin         = 0;
     2036    si.nMax         = es->line_count + vlc - 2;
     2037    si.nPage        = vlc;
     2038    si.nPos         = es->y_offset;
     2039    SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
     2040  }
     2041}
     2042
    19982043
    19992044/*********************************************************************
     
    20312076                es->y_offset = nyoff;
    20322077                es->x_offset += dx;
     2078                EDIT_UpdateScrollBars(hwnd,es,dx,dy);
    20332079        }
    20342080        if (dx && !(es->flags & EF_HSCROLL_TRACK))
     
    22042250
    22052251        /* FIXME: really inefficient */
    2206         InvalidateRect(hwnd, NULL, TRUE);
     2252        EDIT_Refresh(hwnd,es);
    22072253}
    22082254
     
    22922338                x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));
    22932339                format_width = es->format_rect.right - es->format_rect.left;
    2294                 if (x < es->format_rect.left) {
     2340                if (x < es->format_rect.left)
     2341                {
    22952342                        goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
    22962343                        do {
     
    22992346                        } while ((x < goal) && es->x_offset);
    23002347                        /* FIXME: use ScrollWindow() somehow to improve performance */
    2301                         InvalidateRect(hwnd, NULL, TRUE);
    2302                 } else if (x > es->format_rect.right) {
     2348                        EDIT_Refresh(hwnd,es);
     2349                        EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE);
     2350                } else if (x > es->format_rect.right)
     2351                {
    23032352                        INT x_last;
    23042353                        INT len = lstrlenA(es->text);
     
    23102359                        } while ((x > goal) && (x_last > es->format_rect.right));
    23112360                        /* FIXME: use ScrollWindow() somehow to improve performance */
    2312                         InvalidateRect(hwnd, NULL, TRUE);
     2361                        EDIT_Refresh(hwnd,es);
     2362                        EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE);
    23132363                }
    23142364        }
     
    23532403        es->flags &= ~EF_UPDATE;
    23542404        EDIT_BuildLineDefs_ML(hwnd, es);
    2355         InvalidateRect(hwnd, NULL, TRUE);
     2405        EDIT_Refresh(hwnd,es);
    23562406        EDIT_EM_ScrollCaret(hwnd, es);
     2407        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
    23572408}
    23582409
     
    24312482                es->style &= ~ES_PASSWORD;
    24322483        }
    2433         InvalidateRect(hwnd, NULL, TRUE);
     2484        EDIT_Refresh(hwnd,es);
    24342485}
    24352486
     
    24702521        ORDER_UINT(start, old_start);
    24712522        ORDER_UINT(old_start, old_end);
    2472         if (es->flags & EF_FOCUSED) HideCaret(hwnd);
    24732523        if (end != old_start)
    24742524        {
     
    24922542        }
    24932543        else EDIT_InvalidateText(hwnd, es, start, old_end);
    2494         if (es->flags & EF_FOCUSED) ShowCaret(hwnd);
    24952544}
    24962545
     
    25312580        if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
    25322581                EDIT_BuildLineDefs_ML(hwnd, es);
    2533                 InvalidateRect(hwnd, NULL, TRUE);
     2582                EDIT_Refresh(hwnd,es);
    25342583        }
    25352584}
     
    33263375}
    33273376
     3377static VOID EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc,BOOL eraseBkGnd)
     3378{
     3379  INT i;
     3380  HFONT old_font = 0;
     3381  RECT rc;
     3382  RECT rcLine;
     3383  RECT rcRgn;
     3384  BOOL rev = es->bEnableState && ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL));
     3385
     3386  if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(hwnd, EN_UPDATE);
     3387
     3388  if (es->flags & EF_FOCUSED) HideCaret(hwnd);
     3389
     3390  if (eraseBkGnd)
     3391  {
     3392    HBRUSH brush;
     3393
     3394    if (!es->bEnableState || (es->style & ES_READONLY))
     3395      brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, hdc);
     3396    else
     3397      brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, hdc);
     3398
     3399    if (!brush)
     3400      brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
     3401
     3402    GetClientRect(hwnd, &rc);
     3403    /*
     3404     *      FIXME:  specs say that we should UnrealizeObject() the brush,
     3405     *              but the specs of UnrealizeObject() say that we shouldn't
     3406     *              unrealize a stock object.  The default brush that
     3407     *              DefWndProc() returns is ... a stock object.
     3408     */
     3409    FillRect(hdc, &rc, brush);
     3410  }
     3411
     3412  if(es->style & WS_BORDER)
     3413  {
     3414    GetClientRect(hwnd, &rc);
     3415    if(es->style & ES_MULTILINE)
     3416    {
     3417      if(es->style & WS_HSCROLL) rc.bottom++;
     3418      if(es->style & WS_VSCROLL) rc.right++;
     3419    }
     3420    Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
     3421  }
     3422
     3423  IntersectClipRect(hdc, es->format_rect.left,
     3424                        es->format_rect.top,
     3425                        es->format_rect.right,
     3426                        es->format_rect.bottom);
     3427  if (es->style & ES_MULTILINE)
     3428  {
     3429    GetClientRect(hwnd, &rc);
     3430    IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
     3431  }
     3432  if (es->font) old_font = SelectObject(hdc, es->font);
     3433  if (!es->bEnableState || (es->style & ES_READONLY))
     3434    EDIT_SEND_CTLCOLORSTATIC(hwnd, hdc);
     3435  else
     3436    EDIT_SEND_CTLCOLOR(hwnd, hdc);
     3437  if (!es->bEnableState)
     3438    SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
     3439  GetClipBox(hdc, &rcRgn);
     3440  if (es->style & ES_MULTILINE)
     3441  {
     3442    INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
     3443
     3444    for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++)
     3445    {
     3446      EDIT_GetLineRect(hwnd, es, i, 0, -1, &rcLine);
     3447      if (IntersectRect(&rc, &rcRgn, &rcLine))
     3448        EDIT_PaintLine(hwnd, es, hdc, i, rev);
     3449    }
     3450  } else
     3451  {
     3452    EDIT_GetLineRect(hwnd, es, 0, 0, -1, &rcLine);
     3453    if (IntersectRect(&rc, &rcRgn, &rcLine))
     3454      EDIT_PaintLine(hwnd, es, hdc, 0, rev);
     3455  }
     3456  if (es->font) SelectObject(hdc, old_font);
     3457  if (es->flags & EF_FOCUSED)
     3458    EDIT_SetCaretPos(hwnd, es, es->selection_end,es->flags & EF_AFTER_WRAP);
     3459
     3460  if (es->flags & EF_FOCUSED) ShowCaret(hwnd);
     3461
     3462  //CB: replace
     3463  if (es->flags & EF_UPDATE)
     3464  {
     3465    es->flags &= ~EF_UPDATE;
     3466    EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
     3467  }
     3468}
     3469
     3470static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es)
     3471{
     3472  HDC hdc,hdcCompatible;
     3473  HBITMAP bitmap,oldbmp;
     3474  RECT rect;
     3475
     3476  //CB: original controls redraws many times, cache drawing
     3477  if (es->flags & EF_FOCUSED) HideCaret(hwnd);
     3478  GetClientRect(hwnd,&rect);
     3479  hdc = GetDC(hwnd);
     3480  hdcCompatible = CreateCompatibleDC(hdc);
     3481  bitmap = CreateCompatibleBitmap(hdc,rect.right,rect.bottom);
     3482  oldbmp = SelectObject(hdcCompatible,bitmap);
     3483  EDIT_Draw(hwnd,es,hdcCompatible,TRUE);
     3484  SelectClipRgn(hdcCompatible,0);
     3485  BitBlt(hdc,0,0,rect.right,rect.bottom,hdcCompatible,0,0,SRCCOPY);
     3486  SelectObject(hdcCompatible,oldbmp);
     3487  DeleteObject(bitmap);
     3488  DeleteDC(hdcCompatible);
     3489  ReleaseDC(hwnd,hdc);
     3490  if (es->flags & EF_FOCUSED) ShowCaret(hwnd);
     3491}
     3492
    33283493/*********************************************************************
    33293494 *
     
    33333498static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam)
    33343499{
    3335         PAINTSTRUCT ps;
    3336         INT i;
    3337         HDC dc;
    3338         HFONT old_font = 0;
    3339         RECT rc;
    3340         RECT rcLine;
    3341         RECT rcRgn;
    3342         BOOL rev = es->bEnableState &&
    3343                                 ((es->flags & EF_FOCUSED) ||
    3344                                         (es->style & ES_NOHIDESEL));
    3345 
    3346         if (es->flags & EF_UPDATE)
    3347                 EDIT_NOTIFY_PARENT(hwnd, EN_UPDATE);
    3348 
    3349         if (!wParam)
    3350             dc = BeginPaint(hwnd, &ps);
    3351         else
    3352             dc = (HDC) wParam;
    3353 
    3354         if(es->style & WS_BORDER) {
    3355                 GetClientRect(hwnd, &rc);
    3356                 if(es->style & ES_MULTILINE) {
    3357                         if(es->style & WS_HSCROLL) rc.bottom++;
    3358                         if(es->style & WS_VSCROLL) rc.right++;
    3359                 }
    3360                 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
    3361         }
    3362         IntersectClipRect(dc, es->format_rect.left,
    3363                                 es->format_rect.top,
    3364                                 es->format_rect.right,
    3365                                 es->format_rect.bottom);
    3366         if (es->style & ES_MULTILINE) {
    3367                 GetClientRect(hwnd, &rc);
    3368                 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
    3369         }
    3370         if (es->font)
    3371                 old_font = SelectObject(dc, es->font);
    3372         if (!es->bEnableState || (es->style & ES_READONLY))
    3373                 EDIT_SEND_CTLCOLORSTATIC(hwnd, dc);
    3374         else
    3375                 EDIT_SEND_CTLCOLOR(hwnd, dc);
    3376         if (!es->bEnableState)
    3377                 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
    3378         GetClipBox(dc, &rcRgn);
    3379         if (es->style & ES_MULTILINE) {
    3380                 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
    3381                 for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
    3382                         EDIT_GetLineRect(hwnd, es, i, 0, -1, &rcLine);
    3383                         if (IntersectRect(&rc, &rcRgn, &rcLine))
    3384                                 EDIT_PaintLine(hwnd, es, dc, i, rev);
    3385                 }
    3386         } else {
    3387                 EDIT_GetLineRect(hwnd, es, 0, 0, -1, &rcLine);
    3388                 if (IntersectRect(&rc, &rcRgn, &rcLine))
    3389                         EDIT_PaintLine(hwnd, es, dc, 0, rev);
    3390         }
    3391         if (es->font)
    3392                 SelectObject(dc, old_font);
    3393         if (es->flags & EF_FOCUSED)
    3394                 EDIT_SetCaretPos(hwnd, es, es->selection_end,
    3395                                  es->flags & EF_AFTER_WRAP);
    3396         if (!wParam) EndPaint(hwnd, &ps);
    3397         if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) {
    3398                 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
    3399                 SCROLLINFO si;
    3400                 si.cbSize       = sizeof(SCROLLINFO);
    3401                 si.fMask        = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
    3402                 si.nMin         = 0;
    3403                 si.nMax         = es->line_count + vlc - 2;
    3404                 si.nPage        = vlc;
    3405                 si.nPos         = es->y_offset;
    3406                 SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
    3407         }
    3408         if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) {
    3409                 SCROLLINFO si;
    3410                 INT fw = es->format_rect.right - es->format_rect.left;
    3411                 si.cbSize       = sizeof(SCROLLINFO);
    3412                 si.fMask        = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
    3413                 si.nMin         = 0;
    3414                 si.nMax         = es->text_width + fw - 1;
    3415                 si.nPage        = fw;
    3416                 si.nPos         = es->x_offset;
    3417                 SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
    3418         }
    3419 
    3420         if (es->flags & EF_UPDATE) {
    3421                 es->flags &= ~EF_UPDATE;
    3422                 EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
    3423         }
     3500  PAINTSTRUCT ps;
     3501  HDC hdc;
     3502
     3503  if (!wParam) hdc = BeginPaint(hwnd, &ps);
     3504  else hdc = (HDC) wParam;
     3505
     3506  EDIT_Draw(hwnd,es,hdc,FALSE);
     3507
     3508  if (!wParam) EndPaint(hwnd, &ps);
    34243509}
    34253510
     
    34623547        EDIT_NOTIFY_PARENT(hwnd, EN_SETFOCUS);
    34633548}
    3464 
    34653549
    34663550/*********************************************************************
     
    35053589
    35063590        if (redraw)
    3507                 InvalidateRect(hwnd, NULL, TRUE);
     3591                EDIT_Refresh(hwnd,es);
    35083592        if (es->flags & EF_FOCUSED) {
    35093593                DestroyCaret();
     
    35473631        EDIT_EM_SetSel(hwnd, es, 0, 0, FALSE);
    35483632        EDIT_EM_ScrollCaret(hwnd, es);
     3633        EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
    35493634}
    35503635
     
    35613646                SetRect(&rc, 0, 0, width, height);
    35623647                EDIT_SetRectNP(hwnd, es, &rc);
    3563                 InvalidateRect(hwnd, NULL, TRUE);
     3648                EDIT_Refresh(hwnd,es);
    35643649        }
    35653650}
  • trunk/src/user32/scroll.cpp

    r1693 r1717  
    1 /* $Id: scroll.cpp,v 1.20 1999-11-10 17:11:30 cbratschi Exp $ */
     1/* $Id: scroll.cpp,v 1.21 1999-11-12 17:16:37 cbratschi Exp $ */
    22/*
    33 * Scrollbar control
     
    701701    static POINT prevPt;       /* Previous mouse position for timer events */
    702702    static UINT trackThumbPos; /* Thumb position when tracking started. */
     703    static BOOL thumbTrackSent;
    703704    static INT lastClickPos;   /* Position in the scroll-bar of the last button-down event. */
    704705    static INT lastMousePos;   /* Position in the scroll-bar of the last mouse event. */
     
    942943            SCROLL_TrackingVal = infoPtr->CurVal;
    943944            SCROLL_MovingThumb = TRUE;
     945            thumbTrackSent = FALSE;
    944946            SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
    945947        } else if (msg == WM_LBUTTONUP || msg == WM_CAPTURECHANGED)
     
    954956                                    trackThumbPos + lastMousePos - lastClickPos );
    955957
    956           if (val != infoPtr->CurVal)
     958          if (val != infoPtr->CurVal || thumbTrackSent)
    957959            SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
    958960                          MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
     
    991993                                MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
    992994                                hwndCtl );
     995                thumbTrackSent = TRUE;
    993996            }
    994997        }
Note: See TracChangeset for help on using the changeset viewer.