Ignore:
Timestamp:
Oct 8, 1999, 11:26:08 PM (26 years ago)
Author:
cbratschi
Message:

merged with WINE, other fixes

File:
1 edited

Legend:

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

    r949 r1203  
    1 /* $Id: edit.cpp,v 1.1 1999-09-15 23:18:50 sandervl Exp $ */
     1/* $Id: edit.cpp,v 1.2 1999-10-08 21:24:07 cbratschi Exp $ */
    22/*
    33 *      Edit control
     
    99 *      Copyright  1999 Christoph Bratschi (ported from WINE)
    1010 *
     11 * WINE version: 990923
    1112 */
    1213
     
    9091        INT y_offset;                   /* scroll offset in number of lines */
    9192        BOOL bCaptureState; /* flag indicating whether mouse was captured */
     93        BOOL bEnableState;             /* flag keeping the enable state */
    9294        /*
    9395         *      only for multi line controls
     
    214216static LRESULT  EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y);
    215217static LRESULT  EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTA cs);
    216 static void     EDIT_WM_Paint(HWND hwnd, EDITSTATE *es);
     218static void     EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam);
    217219static void     EDIT_WM_Paste(HWND hwnd, EDITSTATE *es);
    218220static void     EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es, HWND window_losing_focus);
     
    320322                //DPRINTF_EDIT_MSG32("EM_SETSEL");
    321323                EDIT_EM_SetSel(hwnd, es, wParam, lParam, FALSE);
     324                EDIT_EM_ScrollCaret(hwnd,es);
    322325                result = 1;
    323326                break;
     
    598601        case WM_ENABLE:
    599602                //DPRINTF_EDIT_MSG32("WM_ENABLE");
     603                es->bEnableState = (BOOL)wParam;
    600604                InvalidateRect(hwnd, NULL, TRUE);
    601605                break;
     
    672676        case WM_PAINT:
    673677                //DPRINTF_EDIT_MSG32("WM_PAINT");
    674                 EDIT_WM_Paint(hwnd, es);
     678                EDIT_WM_Paint(hwnd, es,wParam);
    675679                break;
    676680
     
    12971301        INT e;
    12981302
    1299         if (es->style & ES_MULTILINE)
    1300                 e = EDIT_CharFromPos(hwnd, es, 0x7fffffff,
    1301                         HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
     1303        /* Pass a high value in x to make sure of receiving the en of the line */
     1304        if (es->style & ES_MULTILINE)
     1305                e = EDIT_CharFromPos(hwnd, es, 0x3fffffff,
     1306                        HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
    13021307        else
    13031308                e = lstrlenA(es->text);
     
    13411346        INT e;
    13421347
    1343         if (es->style & ES_MULTILINE)
    1344                 e = EDIT_CharFromPos(hwnd, es, 0x80000000,
    1345                         HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
    1346         else
    1347                 e = 0;
    1348         EDIT_EM_SetSel(hwnd, es, e, extend ? es->selection_start : e, FALSE);
     1348        /* Pass the x_offset in x to make sure of receiving the first position of the line */
     1349        if (es->style & ES_MULTILINE)
     1350                e = EDIT_CharFromPos(hwnd, es, -es->x_offset,
     1351                        HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
     1352        else
     1353                e = 0;
     1354        EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE);
    13491355        EDIT_EM_ScrollCaret(hwnd, es);
    13501356}
     
    25632569static void EDIT_WM_Char(HWND hwnd, EDITSTATE *es, CHAR c, DWORD key_data)
    25642570{
     2571        BOOL control = GetKeyState(VK_CONTROL) & 0x8000;
    25652572        switch (c) {
    25662573        case '\r':
     2574            /* If the edit doesn't want the return, do nothing */
     2575            if(!(es->style & ES_WANTRETURN))
     2576                break;
    25672577        case '\n':
    25682578                if (es->style & ES_MULTILINE) {
     
    25782588                        EDIT_EM_ReplaceSel(hwnd, es, TRUE, "\t");
    25792589                break;
     2590        case VK_BACK:
     2591                if (!(es->style & ES_READONLY) && !control) {
     2592                        if (es->selection_start != es->selection_end)
     2593                                EDIT_WM_Clear(hwnd, es);
     2594                        else {
     2595                                /* delete character left of caret */
     2596                                EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE);
     2597                                EDIT_MoveBackward(hwnd, es, TRUE);
     2598                                EDIT_WM_Clear(hwnd, es);
     2599                        }
     2600                }
     2601                break;
    25802602        default:
    25812603                if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) {
     
    26992721/*********************************************************************
    27002722 *
    2701  *      WM_CREATE
     2723 *      WM_CREATE
    27022724 *
    27032725 */
    27042726static LRESULT EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCREATESTRUCTA cs)
    27052727{
    2706         /*
    2707          *      To initialize some final structure members, we call some helper
    2708          *      functions.  However, since the EDITSTATE is not consistent (i.e.
    2709          *      not fully initialized), we should be very careful which
    2710          *      functions can be called, and in what order.
    2711          */
     2728       /*
     2729        *       To initialize some final structure members, we call some helper
     2730        *       functions.  However, since the EDITSTATE is not consistent (i.e.
     2731        *       not fully initialized), we should be very careful which
     2732        *       functions can be called, and in what order.
     2733        */
    27122734        EDIT_WM_SetFont(hwnd, es, 0, FALSE);
    2713     EDIT_EM_EmptyUndoBuffer(hwnd, es);
    2714 
    2715         if (cs->lpszName && *(cs->lpszName) != '\0') {
    2716                 EDIT_EM_ReplaceSel(hwnd, es, FALSE, cs->lpszName);
    2717                 /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */
    2718                 es->selection_start = es->selection_end = 0;
    2719                 EDIT_EM_ScrollCaret(hwnd, es);
    2720         }
    2721         return 0;
     2735        EDIT_EM_EmptyUndoBuffer(hwnd, es);
     2736       if (cs->lpszName && *(cs->lpszName) != '\0') {
     2737           EDIT_EM_ReplaceSel(hwnd, es, FALSE, cs->lpszName);
     2738           /* if we insert text to the editline, the text scrolls out
     2739            * of the window, as the caret is placed after the insert
     2740            * pos normally; thus we reset es->selection... to 0 and
     2741            * update caret
     2742            */
     2743           es->selection_start = es->selection_end = 0;
     2744           EDIT_EM_ScrollCaret(hwnd, es);
     2745       }
     2746       return 0;
    27222747}
    27232748
     
    27512776        RECT rc;
    27522777
    2753         if (!IsWindowEnabled(hwnd) || (es->style & ES_READONLY))
     2778        if (!es->bEnableState || (es->style & ES_READONLY))
    27542779                brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, dc);
    27552780        else
     
    30393064                        EDIT_MovePageDown_ML(hwnd, es, shift);
    30403065                break;
    3041         case VK_BACK:
    3042                 if (!(es->style & ES_READONLY) && !control) {
    3043                         if (es->selection_start != es->selection_end)
    3044                                 EDIT_WM_Clear(hwnd, es);
    3045                         else {
    3046                                 /* delete character left of caret */
    3047                                 EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE);
    3048                                 EDIT_MoveBackward(hwnd, es, TRUE);
    3049                                 EDIT_WM_Clear(hwnd, es);
    3050                         }
    3051                 }
    3052                 break;
    30533066        case VK_DELETE:
    30543067                if (!(es->style & ES_READONLY) && !(shift && control)) {
     
    30853098                        EDIT_WM_Copy(hwnd, es);
    30863099                break;
     3100        case VK_RETURN:
     3101            /* If the edit doesn't want the return send a message to the default object */
     3102            if(!(es->style & ES_WANTRETURN))
     3103            {
     3104                HWND hwndParent = GetParent(hwnd);
     3105                DWORD dw = SendMessageA( hwndParent, DM_GETDEFID, 0, 0 );
     3106                if (HIWORD(dw) == DC_HASDEFID)
     3107                {
     3108                    SendMessageA( hwndParent, WM_COMMAND,
     3109                                  MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
     3110                              (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
     3111                }
     3112            }
     3113            break;
    30873114        }
    30883115        return 0;
     
    31673194static LRESULT EDIT_WM_LButtonUp(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y)
    31683195{
    3169         if (es->bCaptureState && GetCapture() == hwnd) {
    3170                 KillTimer(hwnd, 0);
    3171                 ReleaseCapture();
    3172         }
    3173         es->bCaptureState = FALSE;
    3174 
    3175         return 0;
     3196        if (es->bCaptureState && GetCapture() == hwnd) {
     3197                KillTimer(hwnd, 0);
     3198                ReleaseCapture();
     3199        }
     3200        es->bCaptureState = FALSE;
     3201
     3202        return 0;
    31763203}
    31773204
     
    32283255        es->style = cs->style;
    32293256
    3230 
    3231         /*
    3232          * In Win95 look and feel, the WS_BORDER style is replaced by the
    3233          * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
    3234          * control a non client area.
    3235          */
     3257        es->bEnableState = !(cs->style & WS_DISABLED);
     3258
     3259        /*
     3260         * In Win95 look and feel, the WS_BORDER style is replaced by the
     3261         * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
     3262         * control a non client area.
     3263         */
    32363264        if (es->style & WS_BORDER)
    3237         {
    3238           es->style      &= ~WS_BORDER;
    3239           SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~WS_BORDER);
    3240           SetWindowLongA(hwnd,GWL_EXSTYLE,GetWindowLongA(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE);
    3241         }
    3242        
     3265        {
     3266          es->style      &= ~WS_BORDER;
     3267          SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~WS_BORDER);
     3268          SetWindowLongA(hwnd,GWL_EXSTYLE,GetWindowLongA(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE);
     3269        }
     3270
    32433271        if (es->style & ES_MULTILINE) {
    32443272                es->buffer_size = BUFSTART_MULTI;
     
    32983326 *
    32993327 */
    3300 static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es)
     3328static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam)
    33013329{
    33023330        PAINTSTRUCT ps;
     
    33073335        RECT rcLine;
    33083336        RECT rcRgn;
    3309         BOOL rev = IsWindowEnabled(hwnd) &&
     3337        BOOL rev = es->bEnableState &&
    33103338                                ((es->flags & EF_FOCUSED) ||
    33113339                                        (es->style & ES_NOHIDESEL));
     
    33143342                EDIT_NOTIFY_PARENT(hwnd, EN_UPDATE, "EN_UPDATE");
    33153343
    3316         dc = BeginPaint(hwnd, &ps);
     3344        if (!wParam)
     3345            dc = BeginPaint(hwnd, &ps);
     3346        else
     3347            dc = (HDC) wParam;
     3348
    33173349        if(es->style & WS_BORDER) {
    33183350                GetClientRect(hwnd, &rc);
     
    33333365        if (es->font)
    33343366                old_font = SelectObject(dc, es->font);
    3335         if (!IsWindowEnabled(hwnd) || (es->style & ES_READONLY))
     3367        if (!es->bEnableState || (es->style & ES_READONLY))
    33363368                EDIT_SEND_CTLCOLORSTATIC(hwnd, dc);
    33373369        else
    33383370                EDIT_SEND_CTLCOLOR(hwnd, dc);
    3339         if (!IsWindowEnabled(hwnd))
     3371        if (!es->bEnableState)
    33403372                SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
    33413373        GetClipBox(dc, &rcRgn);
     
    33573389                EDIT_SetCaretPos(hwnd, es, es->selection_end,
    33583390                                 es->flags & EF_AFTER_WRAP);
    3359         EndPaint(hwnd, &ps);
     3391        if (!wParam) EndPaint(hwnd, &ps);
    33603392        if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) {
    33613393                INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
     
    34413473        HDC dc;
    34423474        HFONT old_font = 0;
     3475        RECT r;
    34433476
    34443477        es->font = font;
     
    34553488                EDIT_EM_SetMargins(hwnd, es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
    34563489                                   EC_USEFONTINFO, EC_USEFONTINFO);
     3490        /* Force the recalculation of the format rect for each font change */
     3491        GetClientRect(hwnd, &r);
     3492        EDIT_SetRectNP(hwnd, es, &r);
    34573493        if (es->style & ES_MULTILINE)
    34583494                EDIT_BuildLineDefs_ML(hwnd, es);
    3459         else {
    3460                 RECT r;
    3461                 GetClientRect(hwnd, &r);
    3462                 EDIT_SetRectNP(hwnd, es, &r);
    3463         }
     3495
    34643496        if (redraw)
    34653497                InvalidateRect(hwnd, NULL, TRUE);
Note: See TracChangeset for help on using the changeset viewer.