| 1 | /* $Id: edit.cpp,v 1.42 2000-12-16 15:42:11 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | *      Edit control | 
|---|
| 4 | * | 
|---|
| 5 | *      Copyright  David W. Metcalfe, 1994 | 
|---|
| 6 | *      Copyright  William Magro, 1995, 1996 | 
|---|
| 7 | *      Copyright  Frans van Dorsselaer, 1996, 1997 | 
|---|
| 8 | * | 
|---|
| 9 | *      Copyright  1999 Christoph Bratschi | 
|---|
| 10 | * | 
|---|
| 11 | * Corel version: 20000513 | 
|---|
| 12 | * (WINE version: 991212) | 
|---|
| 13 | * | 
|---|
| 14 | * Status:  complete | 
|---|
| 15 | * Version: 5.00 | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 | /* CB: todo | 
|---|
| 19 | - EN_ALIGN_LTR_EC, EN_ALIGN_RTL_EC -> undocumented notifications | 
|---|
| 20 | - text alignment for single and multi line (ES_LEFT, ES_RIGHT, ES_CENTER) | 
|---|
| 21 | new in Win98, Win2k: for single line too | 
|---|
| 22 | - WinNT/Win2k: higher size limits (single: 0x7FFFFFFE, multi: none) | 
|---|
| 23 | SvL: Limits removed. EM_SETTEXTLIMIT has no effect in NT4, SP6 (EM_GETTEXTLIMIT | 
|---|
| 24 | only returns that value); limits are simply ignored, no EN_MAXTEXT is ever sent) | 
|---|
| 25 | - too many redraws and recalculations! | 
|---|
| 26 | */ | 
|---|
| 27 |  | 
|---|
| 28 | #include <stdlib.h> | 
|---|
| 29 | #include <os2win.h> | 
|---|
| 30 | #include <string.h> | 
|---|
| 31 | #include "controls.h" | 
|---|
| 32 | #include "combo.h" | 
|---|
| 33 |  | 
|---|
| 34 | #define DBG_LOCALLOG    DBG_edit | 
|---|
| 35 | #include "dbglocal.h" | 
|---|
| 36 |  | 
|---|
| 37 | #ifdef DEBUG | 
|---|
| 38 | char *GetMsgText(int Msg); | 
|---|
| 39 | #endif | 
|---|
| 40 |  | 
|---|
| 41 | #define BUFLIMIT_MULTI          65534   /* maximum buffer size (not including '\0') | 
|---|
| 42 | FIXME: BTW, Win95 specs say 65535 (do you dare ???) */ | 
|---|
| 43 | #define BUFLIMIT_SINGLE         32766   /* maximum buffer size (not including '\0') */ | 
|---|
| 44 |  | 
|---|
| 45 | #ifdef __WIN32OS2__ | 
|---|
| 46 | #define BUFLIMIT_SINGLE_NT      0x7FFFFFFF | 
|---|
| 47 | #endif | 
|---|
| 48 | //#define BUFLIMIT_MULTI  0xFFFFFFFE | 
|---|
| 49 | //#define BUFLIMIT_SINGLE 0x7FFFFFFF | 
|---|
| 50 |  | 
|---|
| 51 | #define BUFSTART_MULTI          1024    /* starting size */ | 
|---|
| 52 | #define BUFSTART_SINGLE         256     /* starting size */ | 
|---|
| 53 | #define GROWLENGTH              64      /* buffers grow by this much */ | 
|---|
| 54 | #define HSCROLL_FRACTION        3       /* scroll window by 1/3 width */ | 
|---|
| 55 |  | 
|---|
| 56 | /* | 
|---|
| 57 | *      extra flags for EDITSTATE.flags field | 
|---|
| 58 | */ | 
|---|
| 59 | #define EF_MODIFIED             0x0001  /* text has been modified */ | 
|---|
| 60 | #define EF_FOCUSED              0x0002  /* we have input focus */ | 
|---|
| 61 | #define EF_UPDATE               0x0004  /* notify parent of changed state on next WM_PAINT */ | 
|---|
| 62 | #define EF_VSCROLL_TRACK        0x0008  /* don't SetScrollPos() since we are tracking the thumb */ | 
|---|
| 63 | #define EF_HSCROLL_TRACK        0x0010  /* don't SetScrollPos() since we are tracking the thumb */ | 
|---|
| 64 | #define EF_VSCROLL_HACK         0x0020  /* we already have informed the user of the hacked handler */ | 
|---|
| 65 | #define EF_HSCROLL_HACK         0x0040  /* we already have informed the user of the hacked handler */ | 
|---|
| 66 | #define EF_AFTER_WRAP           0x0080  /* the caret is displayed after the last character of a | 
|---|
| 67 | wrapped line, instead of in front of the next character */ | 
|---|
| 68 | #define EF_USE_SOFTBRK          0x0100  /* Enable soft breaks in text. */ | 
|---|
| 69 |  | 
|---|
| 70 | typedef enum | 
|---|
| 71 | { | 
|---|
| 72 | END_0 = 0,      /* line ends with terminating '\0' character */ | 
|---|
| 73 | END_WRAP,       /* line is wrapped */ | 
|---|
| 74 | END_HARD,       /* line ends with a hard return '\r\n' */ | 
|---|
| 75 | END_SOFT        /* line ends with a soft return '\r\r\n' */ | 
|---|
| 76 | } LINE_END; | 
|---|
| 77 |  | 
|---|
| 78 | typedef struct tagLINEDEF { | 
|---|
| 79 | INT length;             /* bruto length of a line in bytes */ | 
|---|
| 80 | INT net_length; /* netto length of a line in visible characters */ | 
|---|
| 81 | LINE_END ending; | 
|---|
| 82 | INT width;              /* width of the line in pixels */ | 
|---|
| 83 | struct tagLINEDEF *next; | 
|---|
| 84 | } LINEDEF; | 
|---|
| 85 |  | 
|---|
| 86 | typedef struct | 
|---|
| 87 | { | 
|---|
| 88 | HANDLE heap;                    /* our own heap */ | 
|---|
| 89 | LPSTR text;                     /* the actual contents of the control */ | 
|---|
| 90 | INT buffer_size;                /* the size of the buffer */ | 
|---|
| 91 | INT buffer_limit;               /* the maximum size to which the buffer may grow */ | 
|---|
| 92 | HFONT font;                     /* NULL means standard system font */ | 
|---|
| 93 | INT x_offset;                   /* scroll offset        for multi lines this is in pixels | 
|---|
| 94 | for single lines it's in characters */ | 
|---|
| 95 | INT line_height;                /* height of a screen line in pixels */ | 
|---|
| 96 | INT char_width;         /* average character width in pixels */ | 
|---|
| 97 | DWORD style;                    /* sane version of wnd->dwStyle */ | 
|---|
| 98 | WORD flags;                     /* flags that are not in es->style or wnd->flags (EF_XXX) */ | 
|---|
| 99 | INT undo_insert_count;  /* number of characters inserted in sequence */ | 
|---|
| 100 | INT undo_position;              /* character index of the insertion and deletion */ | 
|---|
| 101 | LPSTR undo_text;                /* deleted text */ | 
|---|
| 102 | INT undo_buffer_size;           /* size of the deleted text buffer */ | 
|---|
| 103 | INT selection_start;            /* == selection_end if no selection */ | 
|---|
| 104 | INT selection_end;              /* == current caret position */ | 
|---|
| 105 | CHAR password_char;             /* == 0 if no password char, and for multi line controls */ | 
|---|
| 106 | INT left_margin;                /* in pixels */ | 
|---|
| 107 | INT right_margin;               /* in pixels */ | 
|---|
| 108 | RECT format_rect; | 
|---|
| 109 | INT region_posx;                /* Position of cursor relative to region: */ | 
|---|
| 110 | INT region_posy;                /* -1: to left, 0: within, 1: to right */ | 
|---|
| 111 | EDITWORDBREAKPROCA word_break_procA; | 
|---|
| 112 | INT line_count;         /* number of lines */ | 
|---|
| 113 | INT y_offset;                   /* scroll offset in number of lines */ | 
|---|
| 114 | BOOL bCaptureState; /* flag indicating whether mouse was captured */ | 
|---|
| 115 | BOOL bEnableState;             /* flag keeping the enable state */ | 
|---|
| 116 | HWND hwndListBox;              /* handle of ComboBox's listbox or NULL */ | 
|---|
| 117 | /* | 
|---|
| 118 | *      only for multi line controls | 
|---|
| 119 | */ | 
|---|
| 120 | INT lock_count;         /* amount of re-entries in the EditWndProc */ | 
|---|
| 121 | INT tabs_count; | 
|---|
| 122 | LPINT tabs; | 
|---|
| 123 | INT text_width;         /* width of the widest line in pixels */ | 
|---|
| 124 | LINEDEF *first_line_def;        /* linked list of (soft) linebreaks */ | 
|---|
| 125 | HLOCAL hloc;          /* for controls receiving EM_GETHANDLE */ | 
|---|
| 126 | } EDITSTATE; | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 | #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0) | 
|---|
| 130 | #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0) | 
|---|
| 131 |  | 
|---|
| 132 | #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0) | 
|---|
| 133 | #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0) | 
|---|
| 134 |  | 
|---|
| 135 | /* used for disabled or read-only edit control */ | 
|---|
| 136 | #define EDIT_SEND_CTLCOLORSTATIC(hwnd,hdc) \ | 
|---|
| 137 | (SendMessageA(GetParent(hwnd), WM_CTLCOLORSTATIC, \ | 
|---|
| 138 | (WPARAM)(hdc), (LPARAM)hwnd)) | 
|---|
| 139 | #define EDIT_SEND_CTLCOLOR(hwnd,hdc) \ | 
|---|
| 140 | (SendMessageA(GetParent(hwnd), WM_CTLCOLOREDIT, \ | 
|---|
| 141 | (WPARAM)(hdc), (LPARAM)hwnd)) | 
|---|
| 142 | #define EDIT_NOTIFY_PARENT(hwnd, wNotifyCode) \ | 
|---|
| 143 | (SendMessageA(GetParent(hwnd), WM_COMMAND, \ | 
|---|
| 144 | MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID), wNotifyCode), (LPARAM)hwnd)) | 
|---|
| 145 |  | 
|---|
| 146 | /********************************************************************* | 
|---|
| 147 | * | 
|---|
| 148 | *      Declarations | 
|---|
| 149 | * | 
|---|
| 150 | */ | 
|---|
| 151 |  | 
|---|
| 152 | /* | 
|---|
| 153 | *      These functions have trivial implementations | 
|---|
| 154 | *      We still like to call them internally | 
|---|
| 155 | *      "static inline" makes them more like macro's | 
|---|
| 156 | */ | 
|---|
| 157 | static inline BOOL      EDIT_EM_CanUndo(HWND hwnd, EDITSTATE *es); | 
|---|
| 158 | static inline void      EDIT_EM_EmptyUndoBuffer(HWND hwnd, EDITSTATE *es); | 
|---|
| 159 | static inline void      EDIT_WM_Clear(HWND hwnd, EDITSTATE *es); | 
|---|
| 160 | static inline void      EDIT_WM_Cut(HWND hwnd, EDITSTATE *es); | 
|---|
| 161 |  | 
|---|
| 162 | /* | 
|---|
| 163 | *      Helper functions only valid for one type of control | 
|---|
| 164 | */ | 
|---|
| 165 | static void     EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es); | 
|---|
| 166 | static LPSTR    EDIT_GetPasswordPointer_SL(HWND hwnd, EDITSTATE *es); | 
|---|
| 167 | static void     EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 168 | static void     EDIT_MovePageDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 169 | static void     EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 170 | static void     EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 171 | static VOID     EDIT_UpdateScrollBars(HWND hwnd,EDITSTATE *es,BOOL updateHorz,BOOL updateVert); | 
|---|
| 172 | /* | 
|---|
| 173 | *      Helper functions valid for both single line _and_ multi line controls | 
|---|
| 174 | */ | 
|---|
| 175 | static INT      EDIT_CallWordBreakProc(HWND hwnd, EDITSTATE *es, INT start, INT index, INT count, INT action); | 
|---|
| 176 | static INT      EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap); | 
|---|
| 177 | static void     EDIT_ConfinePoint(HWND hwnd, EDITSTATE *es, LPINT x, LPINT y); | 
|---|
| 178 | static void     EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc); | 
|---|
| 179 | static void     EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end); | 
|---|
| 180 | static void     EDIT_LockBuffer(HWND hwnd, EDITSTATE *es); | 
|---|
| 181 | static BOOL     EDIT_MakeFit(HWND hwnd, EDITSTATE *es, INT size); | 
|---|
| 182 | static BOOL     EDIT_MakeUndoFit(HWND hwnd, EDITSTATE *es, INT size); | 
|---|
| 183 | static void     EDIT_MoveBackward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 184 | static void     EDIT_MoveEnd(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 185 | static void     EDIT_MoveForward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 186 | static void     EDIT_MoveHome(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 187 | static void     EDIT_MoveWordBackward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 188 | static void     EDIT_MoveWordForward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 189 | static void     EDIT_PaintLine(HWND hwnd, EDITSTATE *es, HDC hdc, INT line, BOOL rev); | 
|---|
| 190 | static VOID     EDIT_PaintText(HWND hwnd, EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev); | 
|---|
| 191 | static void     EDIT_SetCaretPos(HWND hwnd, EDITSTATE *es, INT pos, BOOL after_wrap); | 
|---|
| 192 | static void     EDIT_SetRectNP(HWND hwnd, EDITSTATE *es, LPRECT lprc); | 
|---|
| 193 | static void     EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force); | 
|---|
| 194 | static INT      EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action); | 
|---|
| 195 | static VOID     EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc); | 
|---|
| 196 | static VOID     EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache); | 
|---|
| 197 |  | 
|---|
| 198 | /* | 
|---|
| 199 | *      EM_XXX message handlers | 
|---|
| 200 | */ | 
|---|
| 201 | static LRESULT  EDIT_EM_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y); | 
|---|
| 202 | static BOOL     EDIT_EM_FmtLines(HWND hwnd, EDITSTATE *es, BOOL add_eol); | 
|---|
| 203 | static INT      EDIT_EM_GetFirstVisibleLine(HWND hwnd,EDITSTATE *es); | 
|---|
| 204 | static HLOCAL   EDIT_EM_GetHandle(HWND hwnd, EDITSTATE *es); | 
|---|
| 205 | static INT      EDIT_EM_GetLimitText(HWND hwnd,EDITSTATE *es); | 
|---|
| 206 | static INT      EDIT_EM_GetLine(HWND hwnd, EDITSTATE *es, INT line, LPSTR lpch); | 
|---|
| 207 | static INT      EDIT_EM_GetLineCount(HWND hwnd,EDITSTATE *es); | 
|---|
| 208 | static LONG     EDIT_EM_GetMargins(HWND hwnd,EDITSTATE *es); | 
|---|
| 209 | static BOOL     EDIT_EM_GetModify(HWND hwnd,EDITSTATE *es); | 
|---|
| 210 | static CHAR     EDIT_EM_GetPasswordChar(HWND hwnd,EDITSTATE *es); | 
|---|
| 211 | static VOID     EDIT_EM_GetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc); | 
|---|
| 212 | static LRESULT  EDIT_EM_GetSel(HWND hwnd, EDITSTATE *es, LPUINT start, LPUINT end); | 
|---|
| 213 | static LRESULT  EDIT_EM_GetThumb(HWND hwnd, EDITSTATE *es); | 
|---|
| 214 | static PVOID    EDIT_EM_GetWordbreakProc(HWND hwnd,EDITSTATE *es); | 
|---|
| 215 | static INT      EDIT_EM_LineFromChar(HWND hwnd, EDITSTATE *es, INT index); | 
|---|
| 216 | static INT      EDIT_EM_LineIndex(HWND hwnd, EDITSTATE *es, INT line); | 
|---|
| 217 | static INT      EDIT_EM_LineLength(HWND hwnd, EDITSTATE *es, INT index); | 
|---|
| 218 | static BOOL     EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy); | 
|---|
| 219 | static LRESULT  EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap); | 
|---|
| 220 | static void     EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace); | 
|---|
| 221 | static LRESULT  EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action); | 
|---|
| 222 | static void     EDIT_EM_ScrollCaret(HWND hwnd, EDITSTATE *es); | 
|---|
| 223 | static void     EDIT_EM_SetHandle(HWND hwnd, EDITSTATE *es, HLOCAL hloc); | 
|---|
| 224 | static void     EDIT_EM_SetLimitText(HWND hwnd, EDITSTATE *es, INT limit); | 
|---|
| 225 | static void     EDIT_EM_SetMargins(HWND hwnd, EDITSTATE *es, INT action, INT left, INT right); | 
|---|
| 226 | static void     EDIT_EM_SetModify(HWND hwnd,EDITSTATE *es,BOOL fModified); | 
|---|
| 227 | static void     EDIT_EM_SetPasswordChar(HWND hwnd, EDITSTATE *es, CHAR c); | 
|---|
| 228 | static BOOL     EDIT_EM_SetReadOnly(HWND hwnd,EDITSTATE *es,BOOL fReadOnly); | 
|---|
| 229 | static void     EDIT_EM_SetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc); | 
|---|
| 230 | static void     EDIT_EM_SetRectNP(HWND hwnd,EDITSTATE *es,LPRECT lprc); | 
|---|
| 231 | static void     EDIT_EM_SetSel(HWND hwnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap); | 
|---|
| 232 | static BOOL     EDIT_EM_SetTabStops(HWND hwnd, EDITSTATE *es, INT count, LPINT tabs); | 
|---|
| 233 | static void     EDIT_EM_SetWordBreakProc(HWND hwnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp); | 
|---|
| 234 | static BOOL     EDIT_EM_Undo(HWND hwnd, EDITSTATE *es); | 
|---|
| 235 | static LRESULT  EDIT_EM_SetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam); | 
|---|
| 236 | static LRESULT  EDIT_EM_GetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam); | 
|---|
| 237 | /* | 
|---|
| 238 | *      WM_XXX message handlers | 
|---|
| 239 | */ | 
|---|
| 240 | static void     EDIT_WM_Char(HWND hwnd, EDITSTATE *es, CHAR c, DWORD key_data); | 
|---|
| 241 | static void     EDIT_WM_Command(HWND hwnd, EDITSTATE *es, INT code, INT id, HWND conrtol); | 
|---|
| 242 | static void     EDIT_WM_ContextMenu(HWND hwnd, EDITSTATE *es, HWND hwndBtn, INT x, INT y); | 
|---|
| 243 | static void     EDIT_WM_Copy(HWND hwnd, EDITSTATE *es); | 
|---|
| 244 | static LRESULT  EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCREATESTRUCTA cs); | 
|---|
| 245 | static void     EDIT_WM_Destroy(HWND hwnd, EDITSTATE *es); | 
|---|
| 246 | static LRESULT  EDIT_WM_EraseBkGnd(HWND hwnd, EDITSTATE *es, HDC dc); | 
|---|
| 247 | static INT      EDIT_WM_GetText(HWND hwnd, EDITSTATE *es, INT count, LPSTR text); | 
|---|
| 248 | static LRESULT  EDIT_WM_HScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar); | 
|---|
| 249 | static LRESULT  EDIT_WM_KeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data); | 
|---|
| 250 | static LRESULT  EDIT_WM_KillFocus(HWND hwnd, EDITSTATE *es, HWND window_getting_focus); | 
|---|
| 251 | static LRESULT  EDIT_WM_LButtonDblClk(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y); | 
|---|
| 252 | static LRESULT  EDIT_WM_LButtonDown(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y); | 
|---|
| 253 | static LRESULT  EDIT_WM_LButtonUp(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y); | 
|---|
| 254 | static LRESULT  EDIT_WM_CaptureChanged(HWND hwnd,EDITSTATE *es); | 
|---|
| 255 | static LRESULT  EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y); | 
|---|
| 256 | static LRESULT  EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTA cs); | 
|---|
| 257 | static void     EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam); | 
|---|
| 258 | static void     EDIT_WM_Paste(HWND hwnd, EDITSTATE *es); | 
|---|
| 259 | static void     EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es, HWND window_losing_focus); | 
|---|
| 260 | static void     EDIT_WM_SetFont(HWND hwnd, EDITSTATE *es, HFONT font, BOOL redraw); | 
|---|
| 261 | static void     EDIT_WM_SetText(HWND hwnd, EDITSTATE *es, LPCSTR text); | 
|---|
| 262 | static void     EDIT_WM_Size(HWND hwnd, EDITSTATE *es, UINT action, INT width, INT height); | 
|---|
| 263 | static LRESULT  EDIT_WM_SysKeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data); | 
|---|
| 264 | static void     EDIT_WM_Timer(HWND hwnd, EDITSTATE *es, INT id, TIMERPROC timer_proc); | 
|---|
| 265 | static LRESULT  EDIT_WM_VScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar); | 
|---|
| 266 | static LRESULT EDIT_WM_MouseWheel(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam); | 
|---|
| 267 |  | 
|---|
| 268 | /********************************************************************* | 
|---|
| 269 | * | 
|---|
| 270 | *      EM_CANUNDO | 
|---|
| 271 | * | 
|---|
| 272 | */ | 
|---|
| 273 | static inline BOOL EDIT_EM_CanUndo(HWND hwnd, EDITSTATE *es) | 
|---|
| 274 | { | 
|---|
| 275 | return (es->undo_insert_count || lstrlenA(es->undo_text)); | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 |  | 
|---|
| 279 | /********************************************************************* | 
|---|
| 280 | * | 
|---|
| 281 | *      EM_EMPTYUNDOBUFFER | 
|---|
| 282 | * | 
|---|
| 283 | */ | 
|---|
| 284 | static inline void EDIT_EM_EmptyUndoBuffer(HWND hwnd, EDITSTATE *es) | 
|---|
| 285 | { | 
|---|
| 286 | es->undo_insert_count = 0; | 
|---|
| 287 | *es->undo_text = '\0'; | 
|---|
| 288 | } | 
|---|
| 289 |  | 
|---|
| 290 |  | 
|---|
| 291 | /********************************************************************* | 
|---|
| 292 | * | 
|---|
| 293 | *      WM_CLEAR | 
|---|
| 294 | * | 
|---|
| 295 | */ | 
|---|
| 296 | static inline void EDIT_WM_Clear(HWND hwnd, EDITSTATE *es) | 
|---|
| 297 | { | 
|---|
| 298 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, ""); | 
|---|
| 299 | if (es->flags & EF_UPDATE) { | 
|---|
| 300 | es->flags &= ~EF_UPDATE; | 
|---|
| 301 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 302 | } | 
|---|
| 303 | } | 
|---|
| 304 |  | 
|---|
| 305 |  | 
|---|
| 306 | /********************************************************************* | 
|---|
| 307 | * | 
|---|
| 308 | *      WM_CUT | 
|---|
| 309 | * | 
|---|
| 310 | */ | 
|---|
| 311 | static inline void EDIT_WM_Cut(HWND hwnd, EDITSTATE *es) | 
|---|
| 312 | { | 
|---|
| 313 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 314 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 315 | } | 
|---|
| 316 |  | 
|---|
| 317 |  | 
|---|
| 318 | /********************************************************************* | 
|---|
| 319 | * | 
|---|
| 320 | *      EditWndProc() | 
|---|
| 321 | * | 
|---|
| 322 | *      The messages are in the order of the actual integer values | 
|---|
| 323 | *      (which can be found in include/windows.h) | 
|---|
| 324 | *      Whereever possible the 16 bit versions are converted to | 
|---|
| 325 | *      the 32 bit ones, so that we can 'fall through' to the | 
|---|
| 326 | *      helper functions.  These are mostly 32 bit (with a few | 
|---|
| 327 | *      exceptions, clearly indicated by a '16' extension to their | 
|---|
| 328 | *      names). | 
|---|
| 329 | * | 
|---|
| 330 | */ | 
|---|
| 331 | LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg, | 
|---|
| 332 | WPARAM wParam, LPARAM lParam ) | 
|---|
| 333 | { | 
|---|
| 334 | EDITSTATE *es = (EDITSTATE*)GetInfoPtr(hwnd); | 
|---|
| 335 | LRESULT result = 0; | 
|---|
| 336 |  | 
|---|
| 337 | //      dprintf(("EditWndProc hwnd: %04x, msg %s, wp %08x lp %08lx\n", | 
|---|
| 338 | //               hwnd, GetMsgText(msg), wParam, lParam)); | 
|---|
| 339 |  | 
|---|
| 340 | switch (msg) { | 
|---|
| 341 | case WM_DESTROY: | 
|---|
| 342 | //DPRINTF_EDIT_MSG32("WM_DESTROY"); | 
|---|
| 343 | EDIT_WM_Destroy(hwnd, es); | 
|---|
| 344 | result = 0; | 
|---|
| 345 | goto END; | 
|---|
| 346 |  | 
|---|
| 347 | case WM_NCCREATE: | 
|---|
| 348 | //DPRINTF_EDIT_MSG32("WM_NCCREATE"); | 
|---|
| 349 | result = EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTA)lParam); | 
|---|
| 350 | goto END; | 
|---|
| 351 | } | 
|---|
| 352 |  | 
|---|
| 353 | if (!es) | 
|---|
| 354 | { | 
|---|
| 355 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 356 | goto END; | 
|---|
| 357 | } | 
|---|
| 358 |  | 
|---|
| 359 |  | 
|---|
| 360 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 361 | switch (msg) { | 
|---|
| 362 | case EM_GETSEL: | 
|---|
| 363 | //DPRINTF_EDIT_MSG32("EM_GETSEL"); | 
|---|
| 364 | result = EDIT_EM_GetSel(hwnd, es, (LPUINT)wParam, (LPUINT)lParam); | 
|---|
| 365 | break; | 
|---|
| 366 |  | 
|---|
| 367 | case EM_SETSEL: | 
|---|
| 368 | //DPRINTF_EDIT_MSG32("EM_SETSEL"); | 
|---|
| 369 | EDIT_EM_SetSel(hwnd, es, wParam, lParam, FALSE); | 
|---|
| 370 | EDIT_EM_ScrollCaret(hwnd,es); | 
|---|
| 371 | result = 1; | 
|---|
| 372 | break; | 
|---|
| 373 |  | 
|---|
| 374 | case EM_GETRECT: | 
|---|
| 375 | //DPRINTF_EDIT_MSG32("EM_GETRECT"); | 
|---|
| 376 | EDIT_EM_GetRect(hwnd,es,(LPRECT)lParam); | 
|---|
| 377 | break; | 
|---|
| 378 |  | 
|---|
| 379 | case EM_SETRECT: | 
|---|
| 380 | //DPRINTF_EDIT_MSG32("EM_SETRECT"); | 
|---|
| 381 | EDIT_EM_SetRect(hwnd,es,(LPRECT)lParam); | 
|---|
| 382 | break; | 
|---|
| 383 |  | 
|---|
| 384 | case EM_SETRECTNP: | 
|---|
| 385 | //DPRINTF_EDIT_MSG32("EM_SETRECTNP"); | 
|---|
| 386 | EDIT_EM_SetRectNP(hwnd,es,(LPRECT)lParam); | 
|---|
| 387 | break; | 
|---|
| 388 |  | 
|---|
| 389 | case EM_SCROLL: | 
|---|
| 390 | //DPRINTF_EDIT_MSG32("EM_SCROLL"); | 
|---|
| 391 | result = EDIT_EM_Scroll(hwnd, es, (INT)wParam); | 
|---|
| 392 | break; | 
|---|
| 393 |  | 
|---|
| 394 | case EM_LINESCROLL: | 
|---|
| 395 | //DPRINTF_EDIT_MSG32("EM_LINESCROLL"); | 
|---|
| 396 | result = (LRESULT)EDIT_EM_LineScroll(hwnd, es, (INT)wParam, (INT)lParam); | 
|---|
| 397 | break; | 
|---|
| 398 |  | 
|---|
| 399 | case EM_SCROLLCARET: | 
|---|
| 400 | //DPRINTF_EDIT_MSG32("EM_SCROLLCARET"); | 
|---|
| 401 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 402 | result = 1; | 
|---|
| 403 | break; | 
|---|
| 404 |  | 
|---|
| 405 | case EM_GETMODIFY: | 
|---|
| 406 | //DPRINTF_EDIT_MSG32("EM_GETMODIFY"); | 
|---|
| 407 | result = (LRESULT)EDIT_EM_GetModify(hwnd,es); | 
|---|
| 408 | break; | 
|---|
| 409 |  | 
|---|
| 410 | case EM_SETMODIFY: | 
|---|
| 411 | //DPRINTF_EDIT_MSG32("EM_SETMODIFY"); | 
|---|
| 412 | EDIT_EM_SetModify(hwnd,es,(BOOL)wParam); | 
|---|
| 413 | break; | 
|---|
| 414 |  | 
|---|
| 415 | case EM_GETLINECOUNT: | 
|---|
| 416 | //DPRINTF_EDIT_MSG32("EM_GETLINECOUNT"); | 
|---|
| 417 | result = (LRESULT)EDIT_EM_GetLineCount(hwnd,es); | 
|---|
| 418 | break; | 
|---|
| 419 |  | 
|---|
| 420 | case EM_LINEINDEX: | 
|---|
| 421 | //DPRINTF_EDIT_MSG32("EM_LINEINDEX"); | 
|---|
| 422 | result = (LRESULT)EDIT_EM_LineIndex(hwnd, es, (INT)wParam); | 
|---|
| 423 | break; | 
|---|
| 424 |  | 
|---|
| 425 | case EM_SETHANDLE: | 
|---|
| 426 | //DPRINTF_EDIT_MSG32("EM_SETHANDLE"); | 
|---|
| 427 | EDIT_EM_SetHandle(hwnd, es, (HLOCAL)wParam); | 
|---|
| 428 | break; | 
|---|
| 429 |  | 
|---|
| 430 | case EM_GETHANDLE: | 
|---|
| 431 | //DPRINTF_EDIT_MSG32("EM_GETHANDLE"); | 
|---|
| 432 | result = (LRESULT)EDIT_EM_GetHandle(hwnd, es); | 
|---|
| 433 | break; | 
|---|
| 434 |  | 
|---|
| 435 | case EM_GETTHUMB: | 
|---|
| 436 | //DPRINTF_EDIT_MSG32("EM_GETTHUMB"); | 
|---|
| 437 | result = EDIT_EM_GetThumb(hwnd, es); | 
|---|
| 438 | break; | 
|---|
| 439 |  | 
|---|
| 440 | /* messages 0x00bf and 0x00c0 missing from specs */ | 
|---|
| 441 |  | 
|---|
| 442 | case WM_USER+15: | 
|---|
| 443 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report"); | 
|---|
| 444 | /* fall through */ | 
|---|
| 445 | case 0x00bf: | 
|---|
| 446 | //DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report"); | 
|---|
| 447 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 448 | break; | 
|---|
| 449 |  | 
|---|
| 450 | case WM_USER+16: | 
|---|
| 451 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report"); | 
|---|
| 452 | /* fall through */ | 
|---|
| 453 | case 0x00c0: | 
|---|
| 454 | //DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report"); | 
|---|
| 455 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 456 | break; | 
|---|
| 457 |  | 
|---|
| 458 | case EM_LINELENGTH: | 
|---|
| 459 | //DPRINTF_EDIT_MSG32("EM_LINELENGTH"); | 
|---|
| 460 | result = (LRESULT)EDIT_EM_LineLength(hwnd, es, (INT)wParam); | 
|---|
| 461 | break; | 
|---|
| 462 |  | 
|---|
| 463 | case EM_REPLACESEL: | 
|---|
| 464 | //DPRINTF_EDIT_MSG32("EM_REPLACESEL"); | 
|---|
| 465 | EDIT_EM_ReplaceSel(hwnd, es, (BOOL)wParam, (LPCSTR)lParam); | 
|---|
| 466 | result = 1; | 
|---|
| 467 | break; | 
|---|
| 468 |  | 
|---|
| 469 | /* message 0x00c3 missing from specs */ | 
|---|
| 470 |  | 
|---|
| 471 | case WM_USER+19: | 
|---|
| 472 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report"); | 
|---|
| 473 | /* fall through */ | 
|---|
| 474 | case 0x00c3: | 
|---|
| 475 | //DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report"); | 
|---|
| 476 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 477 | break; | 
|---|
| 478 |  | 
|---|
| 479 | case EM_GETLINE: | 
|---|
| 480 | //DPRINTF_EDIT_MSG32("EM_GETLINE"); | 
|---|
| 481 | result = (LRESULT)EDIT_EM_GetLine(hwnd, es, (INT)wParam, (LPSTR)lParam); | 
|---|
| 482 | break; | 
|---|
| 483 |  | 
|---|
| 484 | case EM_SETLIMITTEXT: | 
|---|
| 485 | //DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT"); | 
|---|
| 486 | EDIT_EM_SetLimitText(hwnd, es, (INT)wParam); | 
|---|
| 487 | break; | 
|---|
| 488 |  | 
|---|
| 489 | case EM_CANUNDO: | 
|---|
| 490 | //DPRINTF_EDIT_MSG32("EM_CANUNDO"); | 
|---|
| 491 | result = (LRESULT)EDIT_EM_CanUndo(hwnd, es); | 
|---|
| 492 | break; | 
|---|
| 493 |  | 
|---|
| 494 | case EM_UNDO: | 
|---|
| 495 | /* fall through */ | 
|---|
| 496 | case WM_UNDO: | 
|---|
| 497 | //DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO"); | 
|---|
| 498 | result = (LRESULT)EDIT_EM_Undo(hwnd, es); | 
|---|
| 499 | break; | 
|---|
| 500 |  | 
|---|
| 501 | case EM_FMTLINES: | 
|---|
| 502 | //DPRINTF_EDIT_MSG32("EM_FMTLINES"); | 
|---|
| 503 | result = (LRESULT)EDIT_EM_FmtLines(hwnd, es, (BOOL)wParam); | 
|---|
| 504 | break; | 
|---|
| 505 |  | 
|---|
| 506 | case EM_LINEFROMCHAR: | 
|---|
| 507 | //DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR"); | 
|---|
| 508 | result = (LRESULT)EDIT_EM_LineFromChar(hwnd, es, (INT)wParam); | 
|---|
| 509 | break; | 
|---|
| 510 |  | 
|---|
| 511 | /* message 0x00ca missing from specs */ | 
|---|
| 512 |  | 
|---|
| 513 | case WM_USER+26: | 
|---|
| 514 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report"); | 
|---|
| 515 | /* fall through */ | 
|---|
| 516 | case 0x00ca: | 
|---|
| 517 | //DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report"); | 
|---|
| 518 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 519 | break; | 
|---|
| 520 |  | 
|---|
| 521 | case EM_SETTABSTOPS: | 
|---|
| 522 | //DPRINTF_EDIT_MSG32("EM_SETTABSTOPS"); | 
|---|
| 523 | result = (LRESULT)EDIT_EM_SetTabStops(hwnd, es, (INT)wParam, (LPINT)lParam); | 
|---|
| 524 | break; | 
|---|
| 525 |  | 
|---|
| 526 | case EM_SETPASSWORDCHAR: | 
|---|
| 527 | //DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR"); | 
|---|
| 528 | EDIT_EM_SetPasswordChar(hwnd, es, (CHAR)wParam); | 
|---|
| 529 | break; | 
|---|
| 530 |  | 
|---|
| 531 | case EM_EMPTYUNDOBUFFER: | 
|---|
| 532 | //DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER"); | 
|---|
| 533 | EDIT_EM_EmptyUndoBuffer(hwnd, es); | 
|---|
| 534 | break; | 
|---|
| 535 |  | 
|---|
| 536 | case EM_GETFIRSTVISIBLELINE: | 
|---|
| 537 | //DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE"); | 
|---|
| 538 | result = (LRESULT)EDIT_EM_GetFirstVisibleLine(hwnd,es); | 
|---|
| 539 | break; | 
|---|
| 540 |  | 
|---|
| 541 | case EM_SETREADONLY: | 
|---|
| 542 | //DPRINTF_EDIT_MSG32("EM_SETREADONLY"); | 
|---|
| 543 | result = (LRESULT)EDIT_EM_SetReadOnly(hwnd,es,(BOOL)wParam); | 
|---|
| 544 | break; | 
|---|
| 545 |  | 
|---|
| 546 | case EM_SETWORDBREAKPROC: | 
|---|
| 547 | //DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC"); | 
|---|
| 548 | EDIT_EM_SetWordBreakProc(hwnd, es, (EDITWORDBREAKPROCA)lParam); | 
|---|
| 549 | break; | 
|---|
| 550 |  | 
|---|
| 551 | case EM_GETWORDBREAKPROC: | 
|---|
| 552 | //DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC"); | 
|---|
| 553 | result = (LRESULT)EDIT_EM_GetWordbreakProc(hwnd,es); | 
|---|
| 554 | break; | 
|---|
| 555 |  | 
|---|
| 556 | case EM_GETPASSWORDCHAR: | 
|---|
| 557 | //DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR"); | 
|---|
| 558 | result = (LRESULT)EDIT_EM_GetPasswordChar(hwnd,es); | 
|---|
| 559 | break; | 
|---|
| 560 |  | 
|---|
| 561 | /* The following EM_xxx are new to win95 and don't exist for 16 bit */ | 
|---|
| 562 |  | 
|---|
| 563 | case EM_SETMARGINS: | 
|---|
| 564 | //DPRINTF_EDIT_MSG32("EM_SETMARGINS"); | 
|---|
| 565 | EDIT_EM_SetMargins(hwnd, es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 566 | break; | 
|---|
| 567 |  | 
|---|
| 568 | case EM_GETMARGINS: | 
|---|
| 569 | //DPRINTF_EDIT_MSG32("EM_GETMARGINS"); | 
|---|
| 570 | result = EDIT_EM_GetMargins(hwnd,es); | 
|---|
| 571 | break; | 
|---|
| 572 |  | 
|---|
| 573 | case EM_GETLIMITTEXT: | 
|---|
| 574 | //DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT"); | 
|---|
| 575 | result = (LRESULT)EDIT_EM_GetLimitText(hwnd,es); | 
|---|
| 576 | break; | 
|---|
| 577 |  | 
|---|
| 578 | case EM_POSFROMCHAR: | 
|---|
| 579 | //DPRINTF_EDIT_MSG32("EM_POSFROMCHAR"); | 
|---|
| 580 | result = EDIT_EM_PosFromChar(hwnd,0, es, (INT)wParam, FALSE); | 
|---|
| 581 | break; | 
|---|
| 582 |  | 
|---|
| 583 | case EM_CHARFROMPOS: | 
|---|
| 584 | //DPRINTF_EDIT_MSG32("EM_CHARFROMPOS"); | 
|---|
| 585 | result = EDIT_EM_CharFromPos(hwnd, es, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 586 | break; | 
|---|
| 587 |  | 
|---|
| 588 | case EM_SETIMESTATUS: | 
|---|
| 589 | result = EDIT_EM_SetIMEStatus(hwnd,es,wParam,lParam); | 
|---|
| 590 | break; | 
|---|
| 591 |  | 
|---|
| 592 | case EM_GETIMESTATUS: | 
|---|
| 593 | result = EDIT_EM_GetIMEStatus(hwnd,es,wParam,lParam); | 
|---|
| 594 | break; | 
|---|
| 595 |  | 
|---|
| 596 | case WM_GETDLGCODE: | 
|---|
| 597 | //DPRINTF_EDIT_MSG32("WM_GETDLGCODE"); | 
|---|
| 598 | result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS; | 
|---|
| 599 |  | 
|---|
| 600 | if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN)) | 
|---|
| 601 | { | 
|---|
| 602 | int vk = (int)((LPMSG)lParam)->wParam; | 
|---|
| 603 |  | 
|---|
| 604 | if ((GetWindowLongA(hwnd,GWL_STYLE) & ES_WANTRETURN) && vk == VK_RETURN) | 
|---|
| 605 | { | 
|---|
| 606 | result |= DLGC_WANTMESSAGE; | 
|---|
| 607 | } | 
|---|
| 608 | else if (es->hwndListBox && (vk == VK_RETURN || vk == VK_ESCAPE)) | 
|---|
| 609 | { | 
|---|
| 610 | if (SendMessageA(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0)) | 
|---|
| 611 | result |= DLGC_WANTMESSAGE; | 
|---|
| 612 | } | 
|---|
| 613 | } | 
|---|
| 614 | break; | 
|---|
| 615 |  | 
|---|
| 616 | case WM_CHAR: | 
|---|
| 617 | //DPRINTF_EDIT_MSG32("WM_CHAR"); | 
|---|
| 618 | if (((CHAR)wParam == VK_RETURN || (CHAR)wParam == VK_ESCAPE) && es->hwndListBox) | 
|---|
| 619 | { | 
|---|
| 620 | HWND hwndParent = GetParent(hwnd); | 
|---|
| 621 |  | 
|---|
| 622 | if (SendMessageA(hwndParent, CB_GETDROPPEDSTATE, 0, 0)) | 
|---|
| 623 | SendMessageA(hwndParent, WM_KEYDOWN, wParam, 0); | 
|---|
| 624 | break; | 
|---|
| 625 | } | 
|---|
| 626 | EDIT_WM_Char(hwnd, es, (CHAR)wParam, (DWORD)lParam); | 
|---|
| 627 | break; | 
|---|
| 628 |  | 
|---|
| 629 | case WM_CLEAR: | 
|---|
| 630 | //DPRINTF_EDIT_MSG32("WM_CLEAR"); | 
|---|
| 631 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 632 | break; | 
|---|
| 633 |  | 
|---|
| 634 | case WM_COMMAND: | 
|---|
| 635 | //DPRINTF_EDIT_MSG32("WM_COMMAND"); | 
|---|
| 636 | EDIT_WM_Command(hwnd, es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam); | 
|---|
| 637 | break; | 
|---|
| 638 |  | 
|---|
| 639 | case WM_CONTEXTMENU: | 
|---|
| 640 | //DPRINTF_EDIT_MSG32("WM_CONTEXTMENU"); | 
|---|
| 641 | EDIT_WM_ContextMenu(hwnd, es, (HWND)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 642 | break; | 
|---|
| 643 |  | 
|---|
| 644 | case WM_COPY: | 
|---|
| 645 | //DPRINTF_EDIT_MSG32("WM_COPY"); | 
|---|
| 646 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 647 | break; | 
|---|
| 648 |  | 
|---|
| 649 | case WM_CREATE: | 
|---|
| 650 | //DPRINTF_EDIT_MSG32("WM_CREATE"); | 
|---|
| 651 | result = EDIT_WM_Create(hwnd, es, (LPCREATESTRUCTA)lParam); | 
|---|
| 652 | break; | 
|---|
| 653 |  | 
|---|
| 654 | case WM_CUT: | 
|---|
| 655 | //DPRINTF_EDIT_MSG32("WM_CUT"); | 
|---|
| 656 | EDIT_WM_Cut(hwnd, es); | 
|---|
| 657 | break; | 
|---|
| 658 |  | 
|---|
| 659 | case WM_ENABLE: | 
|---|
| 660 | //DPRINTF_EDIT_MSG32("WM_ENABLE"); | 
|---|
| 661 | es->bEnableState = (BOOL)wParam; | 
|---|
| 662 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 663 | break; | 
|---|
| 664 |  | 
|---|
| 665 | case WM_ERASEBKGND: | 
|---|
| 666 | //DPRINTF_EDIT_MSG32("WM_ERASEBKGND"); | 
|---|
| 667 | result = EDIT_WM_EraseBkGnd(hwnd, es, (HDC)wParam); | 
|---|
| 668 | break; | 
|---|
| 669 |  | 
|---|
| 670 | case WM_GETFONT: | 
|---|
| 671 | //DPRINTF_EDIT_MSG32("WM_GETFONT"); | 
|---|
| 672 | result = (LRESULT)es->font; | 
|---|
| 673 | break; | 
|---|
| 674 |  | 
|---|
| 675 | case WM_GETTEXT: | 
|---|
| 676 | //DPRINTF_EDIT_MSG32("WM_GETTEXT"); | 
|---|
| 677 | result = (LRESULT)EDIT_WM_GetText(hwnd, es, (INT)wParam, (LPSTR)lParam); | 
|---|
| 678 | break; | 
|---|
| 679 |  | 
|---|
| 680 | case WM_GETTEXTLENGTH: | 
|---|
| 681 | //DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH"); | 
|---|
| 682 | result = lstrlenA(es->text); | 
|---|
| 683 | break; | 
|---|
| 684 |  | 
|---|
| 685 | case WM_HSCROLL: | 
|---|
| 686 | //DPRINTF_EDIT_MSG32("WM_HSCROLL"); | 
|---|
| 687 | result = EDIT_WM_HScroll(hwnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)lParam); | 
|---|
| 688 | break; | 
|---|
| 689 |  | 
|---|
| 690 | case WM_KEYDOWN: | 
|---|
| 691 | //DPRINTF_EDIT_MSG32("WM_KEYDOWN"); | 
|---|
| 692 | result = EDIT_WM_KeyDown(hwnd, es, (INT)wParam, (DWORD)lParam); | 
|---|
| 693 | break; | 
|---|
| 694 |  | 
|---|
| 695 | case WM_KILLFOCUS: | 
|---|
| 696 | //DPRINTF_EDIT_MSG32("WM_KILLFOCUS"); | 
|---|
| 697 | result = EDIT_WM_KillFocus(hwnd, es, (HWND)wParam); | 
|---|
| 698 | break; | 
|---|
| 699 |  | 
|---|
| 700 | case WM_LBUTTONDBLCLK: | 
|---|
| 701 | //DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK"); | 
|---|
| 702 | result = EDIT_WM_LButtonDblClk(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 703 | break; | 
|---|
| 704 |  | 
|---|
| 705 | case WM_LBUTTONDOWN: | 
|---|
| 706 | //DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN"); | 
|---|
| 707 | result = EDIT_WM_LButtonDown(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 708 | break; | 
|---|
| 709 |  | 
|---|
| 710 | case WM_LBUTTONUP: | 
|---|
| 711 | //DPRINTF_EDIT_MSG32("WM_LBUTTONUP"); | 
|---|
| 712 | result = EDIT_WM_LButtonUp(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 713 | break; | 
|---|
| 714 |  | 
|---|
| 715 | case WM_CAPTURECHANGED: | 
|---|
| 716 | result = EDIT_WM_CaptureChanged(hwnd,es); | 
|---|
| 717 | break; | 
|---|
| 718 |  | 
|---|
| 719 | case WM_MOUSEACTIVATE: | 
|---|
| 720 | /* | 
|---|
| 721 | *      FIXME: maybe DefWindowProc() screws up, but it seems that | 
|---|
| 722 | *              modalless dialog boxes need this.  If we don't do this, the focus | 
|---|
| 723 | *              will _not_ be set by DefWindowProc() for edit controls in a | 
|---|
| 724 | *              modalless dialog box ??? | 
|---|
| 725 | */ | 
|---|
| 726 | //DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE"); | 
|---|
| 727 | result = MA_ACTIVATE; | 
|---|
| 728 | break; | 
|---|
| 729 |  | 
|---|
| 730 | case WM_MOUSEMOVE: | 
|---|
| 731 | /* | 
|---|
| 732 | *      DPRINTF_EDIT_MSG32("WM_MOUSEMOVE"); | 
|---|
| 733 | */ | 
|---|
| 734 | result = EDIT_WM_MouseMove(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 735 | break; | 
|---|
| 736 |  | 
|---|
| 737 | case WM_PAINT: | 
|---|
| 738 | //DPRINTF_EDIT_MSG32("WM_PAINT"); | 
|---|
| 739 | EDIT_WM_Paint(hwnd, es,wParam); | 
|---|
| 740 | break; | 
|---|
| 741 |  | 
|---|
| 742 | case WM_PASTE: | 
|---|
| 743 | //DPRINTF_EDIT_MSG32("WM_PASTE"); | 
|---|
| 744 | EDIT_WM_Paste(hwnd, es); | 
|---|
| 745 | break; | 
|---|
| 746 |  | 
|---|
| 747 | case WM_SETFOCUS: | 
|---|
| 748 | //DPRINTF_EDIT_MSG32("WM_SETFOCUS"); | 
|---|
| 749 | EDIT_WM_SetFocus(hwnd, es, (HWND)wParam); | 
|---|
| 750 | break; | 
|---|
| 751 |  | 
|---|
| 752 | case WM_SETFONT: | 
|---|
| 753 | //DPRINTF_EDIT_MSG32("WM_SETFONT"); | 
|---|
| 754 | EDIT_WM_SetFont(hwnd, es, (HFONT)wParam, LOWORD(lParam) != 0); | 
|---|
| 755 | break; | 
|---|
| 756 |  | 
|---|
| 757 | case WM_SETTEXT: | 
|---|
| 758 | //DPRINTF_EDIT_MSG32("WM_SETTEXT"); | 
|---|
| 759 | EDIT_WM_SetText(hwnd, es, (LPCSTR)lParam); | 
|---|
| 760 | result = TRUE; | 
|---|
| 761 | break; | 
|---|
| 762 |  | 
|---|
| 763 | case WM_SIZE: | 
|---|
| 764 | //DPRINTF_EDIT_MSG32("WM_SIZE"); | 
|---|
| 765 | EDIT_WM_Size(hwnd, es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam)); | 
|---|
| 766 | break; | 
|---|
| 767 |  | 
|---|
| 768 | case WM_SYSKEYDOWN: | 
|---|
| 769 | //DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN"); | 
|---|
| 770 | result = EDIT_WM_SysKeyDown(hwnd, es, (INT)wParam, (DWORD)lParam); | 
|---|
| 771 | break; | 
|---|
| 772 |  | 
|---|
| 773 | case WM_TIMER: | 
|---|
| 774 | //DPRINTF_EDIT_MSG32("WM_TIMER"); | 
|---|
| 775 | EDIT_WM_Timer(hwnd, es, (INT)wParam, (TIMERPROC)lParam); | 
|---|
| 776 | break; | 
|---|
| 777 |  | 
|---|
| 778 | case WM_VSCROLL: | 
|---|
| 779 | //DPRINTF_EDIT_MSG32("WM_VSCROLL"); | 
|---|
| 780 | result = EDIT_WM_VScroll(hwnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)(lParam)); | 
|---|
| 781 | break; | 
|---|
| 782 |  | 
|---|
| 783 | case WM_MOUSEWHEEL: | 
|---|
| 784 | result = EDIT_WM_MouseWheel(hwnd,es,wParam,lParam); | 
|---|
| 785 | break; | 
|---|
| 786 |  | 
|---|
| 787 | default: | 
|---|
| 788 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 789 | break; | 
|---|
| 790 | } | 
|---|
| 791 | EDIT_UnlockBuffer(hwnd, es, FALSE); | 
|---|
| 792 | END: | 
|---|
| 793 | return result; | 
|---|
| 794 |  | 
|---|
| 795 | } | 
|---|
| 796 |  | 
|---|
| 797 |  | 
|---|
| 798 | /********************************************************************* | 
|---|
| 799 | * | 
|---|
| 800 | *      EDIT_BuildLineDefs_ML | 
|---|
| 801 | * | 
|---|
| 802 | *      Build linked list of text lines. | 
|---|
| 803 | *      Lines can end with '\0' (last line), a character (if it is wrapped), | 
|---|
| 804 | *      a soft return '\r\r\n' or a hard return '\r\n' | 
|---|
| 805 | * | 
|---|
| 806 | */ | 
|---|
| 807 | static void EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es) | 
|---|
| 808 | { | 
|---|
| 809 | HDC hdc = 0; | 
|---|
| 810 | HFONT old_font = 0; | 
|---|
| 811 | LPSTR start, cp; | 
|---|
| 812 | INT fw; | 
|---|
| 813 | LINEDEF *current_def; | 
|---|
| 814 | LINEDEF **previous_next; | 
|---|
| 815 |  | 
|---|
| 816 | current_def = es->first_line_def; | 
|---|
| 817 | do { | 
|---|
| 818 | LINEDEF *next_def = current_def->next; | 
|---|
| 819 | HeapFree(es->heap, 0, current_def); | 
|---|
| 820 | current_def = next_def; | 
|---|
| 821 | } while (current_def); | 
|---|
| 822 | es->line_count = 0; | 
|---|
| 823 | es->text_width = 0; | 
|---|
| 824 |  | 
|---|
| 825 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 826 | start = es->text; | 
|---|
| 827 | previous_next = &es->first_line_def; | 
|---|
| 828 | do { | 
|---|
| 829 | current_def = (LINEDEF*)HeapAlloc(es->heap, 0, sizeof(LINEDEF)); | 
|---|
| 830 | current_def->next = NULL; | 
|---|
| 831 | cp = start; | 
|---|
| 832 | while (*cp) { | 
|---|
| 833 | if ((*cp == '\r') && (*(cp + 1) == '\n')) | 
|---|
| 834 | break; | 
|---|
| 835 | cp++; | 
|---|
| 836 | } | 
|---|
| 837 | if (!(*cp)) { | 
|---|
| 838 | current_def->ending = END_0; | 
|---|
| 839 | current_def->net_length = lstrlenA(start); | 
|---|
| 840 | } else if ((cp > start) && (*(cp - 1) == '\r')) { | 
|---|
| 841 | current_def->ending = END_SOFT; | 
|---|
| 842 | current_def->net_length = cp - start - 1; | 
|---|
| 843 | } else { | 
|---|
| 844 | current_def->ending = END_HARD; | 
|---|
| 845 | current_def->net_length = cp - start; | 
|---|
| 846 | } | 
|---|
| 847 |  | 
|---|
| 848 | if (!hdc) | 
|---|
| 849 | { | 
|---|
| 850 | hdc = GetDC(hwnd); | 
|---|
| 851 | if (es->font) | 
|---|
| 852 | old_font = SelectObject(hdc, es->font); | 
|---|
| 853 | } | 
|---|
| 854 |  | 
|---|
| 855 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, | 
|---|
| 856 | start, current_def->net_length, | 
|---|
| 857 | es->tabs_count, es->tabs)); | 
|---|
| 858 | /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */ | 
|---|
| 859 | if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) { | 
|---|
| 860 | INT next = 0; | 
|---|
| 861 | INT prev; | 
|---|
| 862 | do { | 
|---|
| 863 | prev = next; | 
|---|
| 864 | next = EDIT_CallWordBreakProc(hwnd, es, start - es->text, | 
|---|
| 865 | prev + 1, current_def->net_length, WB_RIGHT); | 
|---|
| 866 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, | 
|---|
| 867 | start, next, es->tabs_count, es->tabs)); | 
|---|
| 868 | } while (current_def->width <= fw); | 
|---|
| 869 | if (!prev) { | 
|---|
| 870 | next = 0; | 
|---|
| 871 | do { | 
|---|
| 872 | prev = next; | 
|---|
| 873 | next++; | 
|---|
| 874 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, | 
|---|
| 875 | start, next, es->tabs_count, es->tabs)); | 
|---|
| 876 | } while (current_def->width <= fw); | 
|---|
| 877 | if (!prev) | 
|---|
| 878 | prev = 1; | 
|---|
| 879 | } | 
|---|
| 880 | current_def->net_length = prev; | 
|---|
| 881 | current_def->ending = END_WRAP; | 
|---|
| 882 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, start, | 
|---|
| 883 | current_def->net_length, es->tabs_count, es->tabs)); | 
|---|
| 884 | } | 
|---|
| 885 | switch (current_def->ending) { | 
|---|
| 886 | case END_SOFT: | 
|---|
| 887 | current_def->length = current_def->net_length + 3; | 
|---|
| 888 | break; | 
|---|
| 889 | case END_HARD: | 
|---|
| 890 | current_def->length = current_def->net_length + 2; | 
|---|
| 891 | break; | 
|---|
| 892 | case END_WRAP: | 
|---|
| 893 | case END_0: | 
|---|
| 894 | current_def->length = current_def->net_length; | 
|---|
| 895 | break; | 
|---|
| 896 | } | 
|---|
| 897 | es->text_width = MAX(es->text_width, current_def->width); | 
|---|
| 898 | start += current_def->length; | 
|---|
| 899 | *previous_next = current_def; | 
|---|
| 900 | previous_next = ¤t_def->next; | 
|---|
| 901 | es->line_count++; | 
|---|
| 902 | } while (current_def->ending != END_0); | 
|---|
| 903 | if (hdc) | 
|---|
| 904 | { | 
|---|
| 905 | if (es->font) | 
|---|
| 906 | SelectObject(hdc, old_font); | 
|---|
| 907 | ReleaseDC(hwnd, hdc); | 
|---|
| 908 | } | 
|---|
| 909 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); | 
|---|
| 910 | } | 
|---|
| 911 |  | 
|---|
| 912 |  | 
|---|
| 913 | /********************************************************************* | 
|---|
| 914 | * | 
|---|
| 915 | *      EDIT_CallWordBreakProc | 
|---|
| 916 | * | 
|---|
| 917 | *      Call appropriate WordBreakProc (internal or external). | 
|---|
| 918 | * | 
|---|
| 919 | *      Note: The "start" argument should always be an index refering | 
|---|
| 920 | *              to es->text.  The actual wordbreak proc might be | 
|---|
| 921 | *              16 bit, so we can't always pass any 32 bit LPSTR. | 
|---|
| 922 | *              Hence we assume that es->text is the buffer that holds | 
|---|
| 923 | *              the string under examination (we can decide this for ourselves). | 
|---|
| 924 | * | 
|---|
| 925 | */ | 
|---|
| 926 | static INT EDIT_CallWordBreakProc(HWND hwnd, EDITSTATE *es, INT start, INT index, INT count, INT action) | 
|---|
| 927 | { | 
|---|
| 928 | if (es->word_break_procA) | 
|---|
| 929 | { | 
|---|
| 930 | //TRACE_(relay)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n", | 
|---|
| 931 | //               es->word_break_proc32A, es->text + start, index, | 
|---|
| 932 | //               count, action ); | 
|---|
| 933 | return (INT)es->word_break_procA( es->text + start, index, | 
|---|
| 934 | count, action ); | 
|---|
| 935 | } | 
|---|
| 936 | else | 
|---|
| 937 | return EDIT_WordBreakProc(es->text + start, index, count, action); | 
|---|
| 938 | } | 
|---|
| 939 |  | 
|---|
| 940 |  | 
|---|
| 941 | /********************************************************************* | 
|---|
| 942 | * | 
|---|
| 943 | *      EDIT_CharFromPos | 
|---|
| 944 | * | 
|---|
| 945 | *      Beware: This is not the function called on EM_CHARFROMPOS | 
|---|
| 946 | *              The position _can_ be outside the formatting / client | 
|---|
| 947 | *              rectangle | 
|---|
| 948 | *              The return value is only the character index | 
|---|
| 949 | * | 
|---|
| 950 | */ | 
|---|
| 951 | static INT EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap) | 
|---|
| 952 | { | 
|---|
| 953 | INT index; | 
|---|
| 954 | HDC dc = 0; | 
|---|
| 955 | HFONT old_font = 0; | 
|---|
| 956 |  | 
|---|
| 957 | if (es->style & ES_MULTILINE) { | 
|---|
| 958 | INT line = (y - es->format_rect.top) / es->line_height + es->y_offset; | 
|---|
| 959 | INT line_index = 0; | 
|---|
| 960 | LINEDEF *line_def = es->first_line_def; | 
|---|
| 961 | INT low, high; | 
|---|
| 962 | while ((line > 0) && line_def->next) { | 
|---|
| 963 | line_index += line_def->length; | 
|---|
| 964 | line_def = line_def->next; | 
|---|
| 965 | line--; | 
|---|
| 966 | } | 
|---|
| 967 | x += es->x_offset - es->format_rect.left; | 
|---|
| 968 | if (x >= line_def->width) { | 
|---|
| 969 | if (after_wrap) | 
|---|
| 970 | *after_wrap = (line_def->ending == END_WRAP); | 
|---|
| 971 | return line_index + line_def->net_length; | 
|---|
| 972 | } | 
|---|
| 973 | if (x <= 0) { | 
|---|
| 974 | if (after_wrap) | 
|---|
| 975 | *after_wrap = FALSE; | 
|---|
| 976 | return line_index; | 
|---|
| 977 | } | 
|---|
| 978 | low = line_index + 1; | 
|---|
| 979 | high = line_index + line_def->net_length + 1; | 
|---|
| 980 | if (low < high-1) | 
|---|
| 981 | { | 
|---|
| 982 | if (!dc) | 
|---|
| 983 | { | 
|---|
| 984 | dc = GetDC(hwnd); | 
|---|
| 985 | if (es->font) | 
|---|
| 986 | old_font = SelectObject(dc, es->font); | 
|---|
| 987 | } | 
|---|
| 988 |  | 
|---|
| 989 | while (low < high-1) | 
|---|
| 990 | { | 
|---|
| 991 | INT mid = (low + high) / 2; | 
|---|
| 992 | if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid; | 
|---|
| 993 | else low = mid; | 
|---|
| 994 | } | 
|---|
| 995 | } | 
|---|
| 996 | index = low; | 
|---|
| 997 |  | 
|---|
| 998 | if (after_wrap) | 
|---|
| 999 | *after_wrap = ((index == line_index + line_def->net_length) && | 
|---|
| 1000 | (line_def->ending == END_WRAP)); | 
|---|
| 1001 | } else { | 
|---|
| 1002 | LPSTR text; | 
|---|
| 1003 | SIZE size; | 
|---|
| 1004 | if (after_wrap) | 
|---|
| 1005 | *after_wrap = FALSE; | 
|---|
| 1006 | x -= es->format_rect.left; | 
|---|
| 1007 | if (!x) | 
|---|
| 1008 | return es->x_offset; | 
|---|
| 1009 | text = EDIT_GetPasswordPointer_SL(hwnd, es); | 
|---|
| 1010 | if (x < 0) | 
|---|
| 1011 | { | 
|---|
| 1012 | INT low = 0; | 
|---|
| 1013 | INT high = es->x_offset; | 
|---|
| 1014 |  | 
|---|
| 1015 | if (low < high-1) | 
|---|
| 1016 | { | 
|---|
| 1017 | if (!dc) | 
|---|
| 1018 | { | 
|---|
| 1019 | dc = GetDC(hwnd); | 
|---|
| 1020 | if (es->font) | 
|---|
| 1021 | old_font = SelectObject(dc, es->font); | 
|---|
| 1022 | } | 
|---|
| 1023 |  | 
|---|
| 1024 | while (low < high-1) | 
|---|
| 1025 | { | 
|---|
| 1026 | INT mid = (low + high) / 2; | 
|---|
| 1027 |  | 
|---|
| 1028 | GetTextExtentPoint32A( dc, text + mid, | 
|---|
| 1029 | es->x_offset - mid, &size ); | 
|---|
| 1030 | if (size.cx > -x) low = mid; | 
|---|
| 1031 | else high = mid; | 
|---|
| 1032 | } | 
|---|
| 1033 | } | 
|---|
| 1034 | index = low; | 
|---|
| 1035 | } else | 
|---|
| 1036 | { | 
|---|
| 1037 | INT low = es->x_offset; | 
|---|
| 1038 | INT high = lstrlenA(es->text) + 1; | 
|---|
| 1039 |  | 
|---|
| 1040 | if (low < high-1) | 
|---|
| 1041 | { | 
|---|
| 1042 | if (!dc) | 
|---|
| 1043 | { | 
|---|
| 1044 | dc = GetDC(hwnd); | 
|---|
| 1045 | if (es->font) | 
|---|
| 1046 | old_font = SelectObject(dc, es->font); | 
|---|
| 1047 | } | 
|---|
| 1048 |  | 
|---|
| 1049 | while (low < high-1) | 
|---|
| 1050 | { | 
|---|
| 1051 | INT mid = (low + high) / 2; | 
|---|
| 1052 |  | 
|---|
| 1053 | GetTextExtentPoint32A( dc, text + es->x_offset, | 
|---|
| 1054 | mid - es->x_offset, &size ); | 
|---|
| 1055 | if (size.cx > x) high = mid; | 
|---|
| 1056 | else low = mid; | 
|---|
| 1057 | } | 
|---|
| 1058 | } | 
|---|
| 1059 | index = low; | 
|---|
| 1060 | } | 
|---|
| 1061 | if (es->style & ES_PASSWORD) | 
|---|
| 1062 | HeapFree(es->heap, 0 ,text); | 
|---|
| 1063 | } | 
|---|
| 1064 | if (dc) | 
|---|
| 1065 | { | 
|---|
| 1066 | if (es->font) | 
|---|
| 1067 | SelectObject(dc, old_font); | 
|---|
| 1068 | ReleaseDC(hwnd, dc); | 
|---|
| 1069 | } | 
|---|
| 1070 | return index; | 
|---|
| 1071 | } | 
|---|
| 1072 |  | 
|---|
| 1073 |  | 
|---|
| 1074 | /********************************************************************* | 
|---|
| 1075 | * | 
|---|
| 1076 | *      EDIT_ConfinePoint | 
|---|
| 1077 | * | 
|---|
| 1078 | *      adjusts the point to be within the formatting rectangle | 
|---|
| 1079 | *      (so CharFromPos returns the nearest _visible_ character) | 
|---|
| 1080 | * | 
|---|
| 1081 | */ | 
|---|
| 1082 | static void EDIT_ConfinePoint(HWND hwnd, EDITSTATE *es, LPINT x, LPINT y) | 
|---|
| 1083 | { | 
|---|
| 1084 | *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1); | 
|---|
| 1085 | *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1); | 
|---|
| 1086 | } | 
|---|
| 1087 |  | 
|---|
| 1088 |  | 
|---|
| 1089 | /********************************************************************* | 
|---|
| 1090 | * | 
|---|
| 1091 | *      EDIT_GetLineRect | 
|---|
| 1092 | * | 
|---|
| 1093 | *      Calculates the bounding rectangle for a line from a starting | 
|---|
| 1094 | *      column to an ending column. | 
|---|
| 1095 | * | 
|---|
| 1096 | */ | 
|---|
| 1097 | static void EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc) | 
|---|
| 1098 | { | 
|---|
| 1099 | INT line_index =  EDIT_EM_LineIndex(hwnd, es, line); | 
|---|
| 1100 |  | 
|---|
| 1101 | if (es->style & ES_MULTILINE) | 
|---|
| 1102 | rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height; | 
|---|
| 1103 | else | 
|---|
| 1104 | rc->top = es->format_rect.top; | 
|---|
| 1105 | rc->bottom = rc->top + es->line_height; | 
|---|
| 1106 |  | 
|---|
| 1107 | rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + scol, TRUE)); | 
|---|
| 1108 | rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + ecol, TRUE))+1; | 
|---|
| 1109 | } | 
|---|
| 1110 |  | 
|---|
| 1111 |  | 
|---|
| 1112 | /********************************************************************* | 
|---|
| 1113 | * | 
|---|
| 1114 | *      EDIT_GetPasswordPointer_SL | 
|---|
| 1115 | * | 
|---|
| 1116 | *      note: caller should free the (optionally) allocated buffer | 
|---|
| 1117 | * | 
|---|
| 1118 | */ | 
|---|
| 1119 | static LPSTR EDIT_GetPasswordPointer_SL(HWND hwnd, EDITSTATE *es) | 
|---|
| 1120 | { | 
|---|
| 1121 | if (es->style & ES_PASSWORD) { | 
|---|
| 1122 | INT len = lstrlenA(es->text); | 
|---|
| 1123 | LPSTR text = (LPSTR)HeapAlloc(es->heap, 0, len + 1); | 
|---|
| 1124 | RtlFillMemory(text, len, es->password_char); | 
|---|
| 1125 | text[len] = '\0'; | 
|---|
| 1126 | return text; | 
|---|
| 1127 | } else | 
|---|
| 1128 | return es->text; | 
|---|
| 1129 | } | 
|---|
| 1130 |  | 
|---|
| 1131 |  | 
|---|
| 1132 | /********************************************************************* | 
|---|
| 1133 | * | 
|---|
| 1134 | *      EDIT_LockBuffer | 
|---|
| 1135 | * | 
|---|
| 1136 | *      This acts as a LOCAL_Lock(), but it locks only once.  This way | 
|---|
| 1137 | *      you can call it whenever you like, without unlocking. | 
|---|
| 1138 | * | 
|---|
| 1139 | */ | 
|---|
| 1140 | static void EDIT_LockBuffer(HWND hwnd, EDITSTATE *es) | 
|---|
| 1141 | { | 
|---|
| 1142 | if (!es) { | 
|---|
| 1143 | //ERR_(edit)("no EDITSTATE ... please report\n"); | 
|---|
| 1144 | return; | 
|---|
| 1145 | } | 
|---|
| 1146 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 1147 | return; | 
|---|
| 1148 | if (!es->text) { | 
|---|
| 1149 | if (es->hloc) | 
|---|
| 1150 | es->text = (char*)LocalLock(es->hloc); | 
|---|
| 1151 | else { | 
|---|
| 1152 | //ERR_(edit)("no buffer ... please report\n"); | 
|---|
| 1153 | return; | 
|---|
| 1154 | } | 
|---|
| 1155 | } | 
|---|
| 1156 | es->lock_count++; | 
|---|
| 1157 | } | 
|---|
| 1158 |  | 
|---|
| 1159 |  | 
|---|
| 1160 | /********************************************************************* | 
|---|
| 1161 | * | 
|---|
| 1162 | *      EDIT_SL_InvalidateText | 
|---|
| 1163 | * | 
|---|
| 1164 | *      Called from EDIT_InvalidateText(). | 
|---|
| 1165 | *      Does the job for single-line controls only. | 
|---|
| 1166 | * | 
|---|
| 1167 | */ | 
|---|
| 1168 | static void EDIT_SL_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end) | 
|---|
| 1169 | { | 
|---|
| 1170 | RECT line_rect; | 
|---|
| 1171 | RECT rc; | 
|---|
| 1172 |  | 
|---|
| 1173 | EDIT_GetLineRect(hwnd,0, es, 0, start, end, &line_rect); | 
|---|
| 1174 |  | 
|---|
| 1175 | if (IntersectRect(&rc, &line_rect, &es->format_rect)) | 
|---|
| 1176 | { | 
|---|
| 1177 | HideCaret(hwnd); | 
|---|
| 1178 | InvalidateRect(hwnd, &rc, TRUE); | 
|---|
| 1179 | ShowCaret(hwnd); | 
|---|
| 1180 | } | 
|---|
| 1181 | } | 
|---|
| 1182 |  | 
|---|
| 1183 |  | 
|---|
| 1184 | /********************************************************************* | 
|---|
| 1185 | * | 
|---|
| 1186 | *      EDIT_ML_InvalidateText | 
|---|
| 1187 | * | 
|---|
| 1188 | *      Called from EDIT_InvalidateText(). | 
|---|
| 1189 | *      Does the job for multi-line controls only. | 
|---|
| 1190 | * | 
|---|
| 1191 | */ | 
|---|
| 1192 | static void EDIT_ML_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end) | 
|---|
| 1193 | { | 
|---|
| 1194 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 1195 | INT sl = EDIT_EM_LineFromChar(hwnd, es, start); | 
|---|
| 1196 | INT el = EDIT_EM_LineFromChar(hwnd, es, end); | 
|---|
| 1197 | INT sc; | 
|---|
| 1198 | INT ec; | 
|---|
| 1199 | RECT rc1; | 
|---|
| 1200 | RECT rcWnd; | 
|---|
| 1201 | RECT rcLine; | 
|---|
| 1202 | RECT rcUpdate; | 
|---|
| 1203 | INT l; | 
|---|
| 1204 |  | 
|---|
| 1205 | if ((el < es->y_offset) || (sl > es->y_offset + vlc)) | 
|---|
| 1206 | return; | 
|---|
| 1207 |  | 
|---|
| 1208 | sc = start - EDIT_EM_LineIndex(hwnd, es, sl); | 
|---|
| 1209 | ec = end - EDIT_EM_LineIndex(hwnd, es, el); | 
|---|
| 1210 | if (sl < es->y_offset) { | 
|---|
| 1211 | sl = es->y_offset; | 
|---|
| 1212 | sc = 0; | 
|---|
| 1213 | } | 
|---|
| 1214 | if (el > es->y_offset + vlc) { | 
|---|
| 1215 | el = es->y_offset + vlc; | 
|---|
| 1216 | ec = EDIT_EM_LineLength(hwnd, es, EDIT_EM_LineIndex(hwnd, es, el)); | 
|---|
| 1217 | } | 
|---|
| 1218 | GetClientRect(hwnd, &rc1); | 
|---|
| 1219 | IntersectRect(&rcWnd, &rc1, &es->format_rect); | 
|---|
| 1220 | HideCaret(hwnd); | 
|---|
| 1221 | if (sl == el) { | 
|---|
| 1222 | EDIT_GetLineRect(hwnd,0, es, sl, sc, ec, &rcLine); | 
|---|
| 1223 |  | 
|---|
| 1224 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 1225 | InvalidateRect(hwnd, &rcUpdate, TRUE); | 
|---|
| 1226 | } else { | 
|---|
| 1227 | EDIT_GetLineRect(hwnd,0, es, sl, sc, | 
|---|
| 1228 | EDIT_EM_LineLength(hwnd, es, | 
|---|
| 1229 | EDIT_EM_LineIndex(hwnd, es, sl)), | 
|---|
| 1230 | &rcLine); | 
|---|
| 1231 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 1232 | InvalidateRect(hwnd, &rcUpdate, TRUE); | 
|---|
| 1233 | for (l = sl + 1 ; l < el ; l++) { | 
|---|
| 1234 | EDIT_GetLineRect(hwnd,0, es, l, 0, | 
|---|
| 1235 | EDIT_EM_LineLength(hwnd, es, | 
|---|
| 1236 | EDIT_EM_LineIndex(hwnd, es, l)), | 
|---|
| 1237 | &rcLine); | 
|---|
| 1238 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 1239 | InvalidateRect(hwnd, &rcUpdate, TRUE); | 
|---|
| 1240 | } | 
|---|
| 1241 | EDIT_GetLineRect(hwnd,0, es, el, 0, ec, &rcLine); | 
|---|
| 1242 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 1243 | InvalidateRect(hwnd, &rcUpdate, TRUE); | 
|---|
| 1244 | } | 
|---|
| 1245 | ShowCaret(hwnd); | 
|---|
| 1246 | } | 
|---|
| 1247 |  | 
|---|
| 1248 |  | 
|---|
| 1249 | /********************************************************************* | 
|---|
| 1250 | * | 
|---|
| 1251 | *      EDIT_InvalidateText | 
|---|
| 1252 | * | 
|---|
| 1253 | *      Invalidate the text from offset start upto, but not including, | 
|---|
| 1254 | *      offset end.  Useful for (re)painting the selection. | 
|---|
| 1255 | *      Regions outside the linewidth are not invalidated. | 
|---|
| 1256 | *      end == -1 means end == TextLength. | 
|---|
| 1257 | *      start and end need not be ordered. | 
|---|
| 1258 | * | 
|---|
| 1259 | */ | 
|---|
| 1260 | static void EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end) | 
|---|
| 1261 | { | 
|---|
| 1262 | if (end == start) | 
|---|
| 1263 | return; | 
|---|
| 1264 |  | 
|---|
| 1265 | if (end == -1) | 
|---|
| 1266 | end = lstrlenA(es->text); | 
|---|
| 1267 |  | 
|---|
| 1268 | ORDER_INT(start, end); | 
|---|
| 1269 |  | 
|---|
| 1270 | if (es->style & ES_MULTILINE) | 
|---|
| 1271 | EDIT_ML_InvalidateText(hwnd, es, start, end); | 
|---|
| 1272 | else | 
|---|
| 1273 | EDIT_SL_InvalidateText(hwnd, es, start, end); | 
|---|
| 1274 | } | 
|---|
| 1275 |  | 
|---|
| 1276 |  | 
|---|
| 1277 | /********************************************************************* | 
|---|
| 1278 | * | 
|---|
| 1279 | *      EDIT_MakeFit | 
|---|
| 1280 | * | 
|---|
| 1281 | *      Try to fit size + 1 bytes in the buffer.  Constrain to limits. | 
|---|
| 1282 | * | 
|---|
| 1283 | */ | 
|---|
| 1284 | static BOOL EDIT_MakeFit(HWND hwnd, EDITSTATE *es, INT size) | 
|---|
| 1285 | { | 
|---|
| 1286 | HLOCAL hNew32; | 
|---|
| 1287 |  | 
|---|
| 1288 | #ifndef __WIN32OS2__ | 
|---|
| 1289 | if (size > es->buffer_limit) { | 
|---|
| 1290 | EDIT_NOTIFY_PARENT(hwnd, EN_MAXTEXT); | 
|---|
| 1291 | return FALSE; | 
|---|
| 1292 | } | 
|---|
| 1293 | #endif | 
|---|
| 1294 |  | 
|---|
| 1295 | if (size <= es->buffer_size) | 
|---|
| 1296 | return TRUE; | 
|---|
| 1297 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH; | 
|---|
| 1298 |  | 
|---|
| 1299 | #ifndef __WIN32OS2__ | 
|---|
| 1300 | if (size > es->buffer_limit) | 
|---|
| 1301 | size = es->buffer_limit; | 
|---|
| 1302 | #endif | 
|---|
| 1303 |  | 
|---|
| 1304 | //TRACE_(edit)("trying to ReAlloc to %d+1\n", size); | 
|---|
| 1305 |  | 
|---|
| 1306 | EDIT_UnlockBuffer(hwnd, es, TRUE); | 
|---|
| 1307 | if (es->text) { | 
|---|
| 1308 | es->text = (char*)HeapReAlloc(es->heap, 0, es->text, size + 1); | 
|---|
| 1309 | if (es->text) | 
|---|
| 1310 | #ifdef __WIN32OS2__ | 
|---|
| 1311 | es->buffer_size = HeapSize(es->heap, 0, es->text) - 1; | 
|---|
| 1312 | #else | 
|---|
| 1313 | es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit); | 
|---|
| 1314 | #endif | 
|---|
| 1315 | else | 
|---|
| 1316 | es->buffer_size = 0; | 
|---|
| 1317 | } else if (es->hloc) { | 
|---|
| 1318 | hNew32 = LocalReAlloc(es->hloc, size + 1, 0); | 
|---|
| 1319 | if (hNew32) { | 
|---|
| 1320 | //TRACE_(edit)("Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32); | 
|---|
| 1321 | es->hloc = hNew32; | 
|---|
| 1322 | #ifdef __WIN32OS2__ | 
|---|
| 1323 | es->buffer_size = LocalSize(es->hloc) - 1; | 
|---|
| 1324 | #else | 
|---|
| 1325 | es->buffer_size = MIN(LocalSize(es->hloc) - 1, es->buffer_limit); | 
|---|
| 1326 | #endif | 
|---|
| 1327 | } | 
|---|
| 1328 | } | 
|---|
| 1329 | if (es->buffer_size < size) { | 
|---|
| 1330 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 1331 | //WARN_(edit)("FAILED !  We now have %d+1\n", es->buffer_size); | 
|---|
| 1332 | EDIT_NOTIFY_PARENT(hwnd, EN_ERRSPACE); | 
|---|
| 1333 | return FALSE; | 
|---|
| 1334 | } else { | 
|---|
| 1335 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 1336 | //TRACE_(edit)("We now have %d+1\n", es->buffer_size); | 
|---|
| 1337 | return TRUE; | 
|---|
| 1338 | } | 
|---|
| 1339 | } | 
|---|
| 1340 |  | 
|---|
| 1341 |  | 
|---|
| 1342 | /********************************************************************* | 
|---|
| 1343 | * | 
|---|
| 1344 | *      EDIT_MakeUndoFit | 
|---|
| 1345 | * | 
|---|
| 1346 | *      Try to fit size + 1 bytes in the undo buffer. | 
|---|
| 1347 | * | 
|---|
| 1348 | */ | 
|---|
| 1349 | static BOOL EDIT_MakeUndoFit(HWND hwnd, EDITSTATE *es, INT size) | 
|---|
| 1350 | { | 
|---|
| 1351 | if (size <= es->undo_buffer_size) | 
|---|
| 1352 | return TRUE; | 
|---|
| 1353 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH; | 
|---|
| 1354 |  | 
|---|
| 1355 | //TRACE_(edit)("trying to ReAlloc to %d+1\n", size); | 
|---|
| 1356 | es->undo_text = (char*)HeapReAlloc(es->heap, 0, es->undo_text, size + 1); | 
|---|
| 1357 | if (es->undo_text) { | 
|---|
| 1358 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; | 
|---|
| 1359 | if (es->undo_buffer_size < size) { | 
|---|
| 1360 | //WARN_(edit)("FAILED !  We now have %d+1\n", es->undo_buffer_size); | 
|---|
| 1361 | return FALSE; | 
|---|
| 1362 | } | 
|---|
| 1363 | return TRUE; | 
|---|
| 1364 | } | 
|---|
| 1365 | return FALSE; | 
|---|
| 1366 | } | 
|---|
| 1367 |  | 
|---|
| 1368 |  | 
|---|
| 1369 | /********************************************************************* | 
|---|
| 1370 | * | 
|---|
| 1371 | *      EDIT_MoveBackward | 
|---|
| 1372 | * | 
|---|
| 1373 | */ | 
|---|
| 1374 | static void EDIT_MoveBackward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1375 | { | 
|---|
| 1376 | INT e = es->selection_end; | 
|---|
| 1377 |  | 
|---|
| 1378 | if (e) { | 
|---|
| 1379 | e--; | 
|---|
| 1380 | if ((es->style & ES_MULTILINE) && e && | 
|---|
| 1381 | (es->text[e - 1] == '\r') && (es->text[e] == '\n')) { | 
|---|
| 1382 | e--; | 
|---|
| 1383 | if (e && (es->text[e - 1] == '\r')) | 
|---|
| 1384 | e--; | 
|---|
| 1385 | } | 
|---|
| 1386 | } | 
|---|
| 1387 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE); | 
|---|
| 1388 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1389 | } | 
|---|
| 1390 |  | 
|---|
| 1391 |  | 
|---|
| 1392 | /********************************************************************* | 
|---|
| 1393 | * | 
|---|
| 1394 | *      EDIT_MoveDown_ML | 
|---|
| 1395 | * | 
|---|
| 1396 | *      Only for multi line controls | 
|---|
| 1397 | *      Move the caret one line down, on a column with the nearest | 
|---|
| 1398 | *      x coordinate on the screen (might be a different column). | 
|---|
| 1399 | * | 
|---|
| 1400 | */ | 
|---|
| 1401 | static void EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1402 | { | 
|---|
| 1403 | INT s = es->selection_start; | 
|---|
| 1404 | INT e = es->selection_end; | 
|---|
| 1405 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 1406 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); | 
|---|
| 1407 | INT x = SLOWORD(pos); | 
|---|
| 1408 | INT y = SHIWORD(pos); | 
|---|
| 1409 |  | 
|---|
| 1410 | e = EDIT_CharFromPos(hwnd, es, x, y + es->line_height, &after_wrap); | 
|---|
| 1411 | if (!extend) | 
|---|
| 1412 | s = e; | 
|---|
| 1413 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 1414 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1415 | } | 
|---|
| 1416 |  | 
|---|
| 1417 |  | 
|---|
| 1418 | /********************************************************************* | 
|---|
| 1419 | * | 
|---|
| 1420 | *      EDIT_MoveEnd | 
|---|
| 1421 | * | 
|---|
| 1422 | */ | 
|---|
| 1423 | static void EDIT_MoveEnd(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1424 | { | 
|---|
| 1425 | BOOL after_wrap = FALSE; | 
|---|
| 1426 | INT e; | 
|---|
| 1427 |  | 
|---|
| 1428 | /* Pass a high value in x to make sure of receiving the en of the line */ | 
|---|
| 1429 | if (es->style & ES_MULTILINE) | 
|---|
| 1430 | e = EDIT_CharFromPos(hwnd, es, 0x3fffffff, | 
|---|
| 1431 | HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap); | 
|---|
| 1432 | else | 
|---|
| 1433 | e = lstrlenA(es->text); | 
|---|
| 1434 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, after_wrap); | 
|---|
| 1435 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1436 | } | 
|---|
| 1437 |  | 
|---|
| 1438 |  | 
|---|
| 1439 | /********************************************************************* | 
|---|
| 1440 | * | 
|---|
| 1441 | *      EDIT_MoveForward | 
|---|
| 1442 | * | 
|---|
| 1443 | */ | 
|---|
| 1444 | static void EDIT_MoveForward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1445 | { | 
|---|
| 1446 | INT e = es->selection_end; | 
|---|
| 1447 |  | 
|---|
| 1448 | if (es->text[e]) { | 
|---|
| 1449 | e++; | 
|---|
| 1450 | if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) { | 
|---|
| 1451 | if (es->text[e] == '\n') | 
|---|
| 1452 | e++; | 
|---|
| 1453 | else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n')) | 
|---|
| 1454 | e += 2; | 
|---|
| 1455 | } | 
|---|
| 1456 | } | 
|---|
| 1457 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE); | 
|---|
| 1458 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1459 | } | 
|---|
| 1460 |  | 
|---|
| 1461 |  | 
|---|
| 1462 | /********************************************************************* | 
|---|
| 1463 | * | 
|---|
| 1464 | *      EDIT_MoveHome | 
|---|
| 1465 | * | 
|---|
| 1466 | *      Home key: move to beginning of line. | 
|---|
| 1467 | * | 
|---|
| 1468 | */ | 
|---|
| 1469 | static void EDIT_MoveHome(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1470 | { | 
|---|
| 1471 | INT e; | 
|---|
| 1472 |  | 
|---|
| 1473 | /* Pass the x_offset in x to make sure of receiving the first position of the line */ | 
|---|
| 1474 | if (es->style & ES_MULTILINE) | 
|---|
| 1475 | e = EDIT_CharFromPos(hwnd, es, -es->x_offset, | 
|---|
| 1476 | HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL); | 
|---|
| 1477 | else | 
|---|
| 1478 | e = 0; | 
|---|
| 1479 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE); | 
|---|
| 1480 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1481 | } | 
|---|
| 1482 |  | 
|---|
| 1483 |  | 
|---|
| 1484 | /********************************************************************* | 
|---|
| 1485 | * | 
|---|
| 1486 | *      EDIT_MovePageDown_ML | 
|---|
| 1487 | * | 
|---|
| 1488 | *      Only for multi line controls | 
|---|
| 1489 | *      Move the caret one page down, on a column with the nearest | 
|---|
| 1490 | *      x coordinate on the screen (might be a different column). | 
|---|
| 1491 | * | 
|---|
| 1492 | */ | 
|---|
| 1493 | static void EDIT_MovePageDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1494 | { | 
|---|
| 1495 | INT s = es->selection_start; | 
|---|
| 1496 | INT e = es->selection_end; | 
|---|
| 1497 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 1498 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); | 
|---|
| 1499 | INT x = SLOWORD(pos); | 
|---|
| 1500 | INT y = SHIWORD(pos); | 
|---|
| 1501 |  | 
|---|
| 1502 | e = EDIT_CharFromPos(hwnd, es, x, | 
|---|
| 1503 | y + (es->format_rect.bottom - es->format_rect.top), | 
|---|
| 1504 | &after_wrap); | 
|---|
| 1505 | if (!extend) | 
|---|
| 1506 | s = e; | 
|---|
| 1507 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 1508 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1509 | } | 
|---|
| 1510 |  | 
|---|
| 1511 |  | 
|---|
| 1512 | /********************************************************************* | 
|---|
| 1513 | * | 
|---|
| 1514 | *      EDIT_MovePageUp_ML | 
|---|
| 1515 | * | 
|---|
| 1516 | *      Only for multi line controls | 
|---|
| 1517 | *      Move the caret one page up, on a column with the nearest | 
|---|
| 1518 | *      x coordinate on the screen (might be a different column). | 
|---|
| 1519 | * | 
|---|
| 1520 | */ | 
|---|
| 1521 | static void EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1522 | { | 
|---|
| 1523 | INT s = es->selection_start; | 
|---|
| 1524 | INT e = es->selection_end; | 
|---|
| 1525 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 1526 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); | 
|---|
| 1527 | INT x = SLOWORD(pos); | 
|---|
| 1528 | INT y = SHIWORD(pos); | 
|---|
| 1529 |  | 
|---|
| 1530 | e = EDIT_CharFromPos(hwnd, es, x, | 
|---|
| 1531 | y - (es->format_rect.bottom - es->format_rect.top), | 
|---|
| 1532 | &after_wrap); | 
|---|
| 1533 | if (!extend) | 
|---|
| 1534 | s = e; | 
|---|
| 1535 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 1536 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1537 | } | 
|---|
| 1538 |  | 
|---|
| 1539 |  | 
|---|
| 1540 | /********************************************************************* | 
|---|
| 1541 | * | 
|---|
| 1542 | *      EDIT_MoveUp_ML | 
|---|
| 1543 | * | 
|---|
| 1544 | *      Only for multi line controls | 
|---|
| 1545 | *      Move the caret one line up, on a column with the nearest | 
|---|
| 1546 | *      x coordinate on the screen (might be a different column). | 
|---|
| 1547 | * | 
|---|
| 1548 | */ | 
|---|
| 1549 | static void EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1550 | { | 
|---|
| 1551 | INT s = es->selection_start; | 
|---|
| 1552 | INT e = es->selection_end; | 
|---|
| 1553 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 1554 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); | 
|---|
| 1555 | INT x = SLOWORD(pos); | 
|---|
| 1556 | INT y = SHIWORD(pos); | 
|---|
| 1557 |  | 
|---|
| 1558 | e = EDIT_CharFromPos(hwnd, es, x, y - es->line_height, &after_wrap); | 
|---|
| 1559 | if (!extend) | 
|---|
| 1560 | s = e; | 
|---|
| 1561 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 1562 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1563 | } | 
|---|
| 1564 |  | 
|---|
| 1565 |  | 
|---|
| 1566 | /********************************************************************* | 
|---|
| 1567 | * | 
|---|
| 1568 | *      EDIT_MoveWordBackward | 
|---|
| 1569 | * | 
|---|
| 1570 | */ | 
|---|
| 1571 | static void EDIT_MoveWordBackward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1572 | { | 
|---|
| 1573 | INT s = es->selection_start; | 
|---|
| 1574 | INT e = es->selection_end; | 
|---|
| 1575 | INT l; | 
|---|
| 1576 | INT ll; | 
|---|
| 1577 | INT li; | 
|---|
| 1578 |  | 
|---|
| 1579 | l = EDIT_EM_LineFromChar(hwnd, es, e); | 
|---|
| 1580 | ll = EDIT_EM_LineLength(hwnd, es, e); | 
|---|
| 1581 | li = EDIT_EM_LineIndex(hwnd, es, l); | 
|---|
| 1582 | if (e - li == 0) { | 
|---|
| 1583 | if (l) { | 
|---|
| 1584 | li = EDIT_EM_LineIndex(hwnd, es, l - 1); | 
|---|
| 1585 | e = li + EDIT_EM_LineLength(hwnd, es, li); | 
|---|
| 1586 | } | 
|---|
| 1587 | } else { | 
|---|
| 1588 | e = li + (INT)EDIT_CallWordBreakProc(hwnd, es, | 
|---|
| 1589 | li, e - li, ll, WB_LEFT); | 
|---|
| 1590 | } | 
|---|
| 1591 | if (!extend) | 
|---|
| 1592 | s = e; | 
|---|
| 1593 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE); | 
|---|
| 1594 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1595 | } | 
|---|
| 1596 |  | 
|---|
| 1597 |  | 
|---|
| 1598 | /********************************************************************* | 
|---|
| 1599 | * | 
|---|
| 1600 | *      EDIT_MoveWordForward | 
|---|
| 1601 | * | 
|---|
| 1602 | */ | 
|---|
| 1603 | static void EDIT_MoveWordForward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 1604 | { | 
|---|
| 1605 | INT s = es->selection_start; | 
|---|
| 1606 | INT e = es->selection_end; | 
|---|
| 1607 | INT l; | 
|---|
| 1608 | INT ll; | 
|---|
| 1609 | INT li; | 
|---|
| 1610 |  | 
|---|
| 1611 | l = EDIT_EM_LineFromChar(hwnd, es, e); | 
|---|
| 1612 | ll = EDIT_EM_LineLength(hwnd, es, e); | 
|---|
| 1613 | li = EDIT_EM_LineIndex(hwnd, es, l); | 
|---|
| 1614 | if (e - li == ll) { | 
|---|
| 1615 | if ((es->style & ES_MULTILINE) && (l != es->line_count - 1)) | 
|---|
| 1616 | e = EDIT_EM_LineIndex(hwnd, es, l + 1); | 
|---|
| 1617 | } else { | 
|---|
| 1618 | e = li + EDIT_CallWordBreakProc(hwnd, es, | 
|---|
| 1619 | li, e - li + 1, ll, WB_RIGHT); | 
|---|
| 1620 | } | 
|---|
| 1621 | if (!extend) | 
|---|
| 1622 | s = e; | 
|---|
| 1623 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE); | 
|---|
| 1624 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 1625 | } | 
|---|
| 1626 |  | 
|---|
| 1627 |  | 
|---|
| 1628 | /********************************************************************* | 
|---|
| 1629 | * | 
|---|
| 1630 | *      EDIT_PaintLine | 
|---|
| 1631 | * | 
|---|
| 1632 | */ | 
|---|
| 1633 | static void EDIT_PaintLine(HWND hwnd, EDITSTATE *es, HDC dc, INT line, BOOL rev) | 
|---|
| 1634 | { | 
|---|
| 1635 | INT s = es->selection_start; | 
|---|
| 1636 | INT e = es->selection_end; | 
|---|
| 1637 | INT li; | 
|---|
| 1638 | INT ll; | 
|---|
| 1639 | INT x; | 
|---|
| 1640 | INT y; | 
|---|
| 1641 | LRESULT pos; | 
|---|
| 1642 |  | 
|---|
| 1643 | if (es->style & ES_MULTILINE) { | 
|---|
| 1644 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 1645 | if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count)) | 
|---|
| 1646 | return; | 
|---|
| 1647 | } else if (line) | 
|---|
| 1648 | return; | 
|---|
| 1649 |  | 
|---|
| 1650 | //TRACE_(edit)("line=%d\n", line); | 
|---|
| 1651 |  | 
|---|
| 1652 | pos = EDIT_EM_PosFromChar(hwnd,dc, es, EDIT_EM_LineIndex(hwnd, es, line), FALSE); | 
|---|
| 1653 | x = SLOWORD(pos); | 
|---|
| 1654 | y = SHIWORD(pos); | 
|---|
| 1655 | li = EDIT_EM_LineIndex(hwnd, es, line); | 
|---|
| 1656 | ll = EDIT_EM_LineLength(hwnd, es, li); | 
|---|
| 1657 | s = es->selection_start; | 
|---|
| 1658 | e = es->selection_end; | 
|---|
| 1659 | ORDER_INT(s, e); | 
|---|
| 1660 | s = MIN(li + ll, MAX(li, s)); | 
|---|
| 1661 | e = MIN(li + ll, MAX(li, e)); | 
|---|
| 1662 |  | 
|---|
| 1663 | if (rev && (s != e) && ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) | 
|---|
| 1664 | { | 
|---|
| 1665 | HRGN oldRgn,newRgn,combRgn; | 
|---|
| 1666 | RECT rect; | 
|---|
| 1667 | //CB: OS/2 has problems with relative string positions (i.e. Communicator) | 
|---|
| 1668 | //    fix: always calculate string from starting point, tab bugs fixed too | 
|---|
| 1669 | //    otherwise we have 'dancing characters' | 
|---|
| 1670 |  | 
|---|
| 1671 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 1672 | { | 
|---|
| 1673 | SIZE size; | 
|---|
| 1674 |  | 
|---|
| 1675 | rect.top = y; | 
|---|
| 1676 | rect.bottom = y+es->line_height; | 
|---|
| 1677 | GetTextExtentPoint32A(dc,es->text+li,s-li,&size); | 
|---|
| 1678 | rect.left = x+size.cx; | 
|---|
| 1679 | GetTextExtentPoint32A(dc,es->text+li,e-li,&size); | 
|---|
| 1680 | rect.right = x+size.cx; | 
|---|
| 1681 |  | 
|---|
| 1682 | oldRgn = CreateRectRgnIndirect(&rect); //dummy parameter | 
|---|
| 1683 | GetClipRgn(dc,oldRgn); | 
|---|
| 1684 | newRgn = CreateRectRgnIndirect(&rect); | 
|---|
| 1685 | combRgn = CreateRectRgnIndirect(&rect); //dummy parameter | 
|---|
| 1686 | CombineRgn(combRgn,oldRgn,newRgn,RGN_XOR); | 
|---|
| 1687 | SelectClipRgn(dc,combRgn); | 
|---|
| 1688 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,ll,FALSE); | 
|---|
| 1689 | CombineRgn(combRgn,oldRgn,newRgn,RGN_AND); | 
|---|
| 1690 | SelectClipRgn(dc,combRgn); | 
|---|
| 1691 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,e-li,TRUE); | 
|---|
| 1692 | DeleteObject(oldRgn); | 
|---|
| 1693 | DeleteObject(newRgn); | 
|---|
| 1694 | DeleteObject(combRgn); | 
|---|
| 1695 | } else | 
|---|
| 1696 | { | 
|---|
| 1697 | rect.top = y; | 
|---|
| 1698 | rect.bottom = y+es->line_height; | 
|---|
| 1699 | rect.left = x+LOWORD(TabbedTextOutA(dc,x,y,es->text+li,s-li,es->tabs_count,es->tabs,es->format_rect.left-es->x_offset)); | 
|---|
| 1700 | rect.right = x+LOWORD(TabbedTextOutA(dc,x,y,es->text+li,e-li,es->tabs_count,es->tabs,es->format_rect.left-es->x_offset)); | 
|---|
| 1701 |  | 
|---|
| 1702 | oldRgn = CreateRectRgnIndirect(&rect); //dummy parameter | 
|---|
| 1703 | GetClipRgn(dc,oldRgn); | 
|---|
| 1704 | newRgn = CreateRectRgnIndirect(&rect); | 
|---|
| 1705 | combRgn = CreateRectRgnIndirect(&rect); //dummy parameter | 
|---|
| 1706 | CombineRgn(combRgn,oldRgn,newRgn,RGN_XOR); | 
|---|
| 1707 | SelectClipRgn(dc,combRgn); | 
|---|
| 1708 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,ll,FALSE); | 
|---|
| 1709 | CombineRgn(combRgn,oldRgn,newRgn,RGN_AND); | 
|---|
| 1710 | SelectClipRgn(dc,combRgn); | 
|---|
| 1711 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,e-li,TRUE); | 
|---|
| 1712 | SelectClipRgn(dc,oldRgn); | 
|---|
| 1713 | DeleteObject(oldRgn); | 
|---|
| 1714 | DeleteObject(newRgn); | 
|---|
| 1715 | DeleteObject(combRgn); | 
|---|
| 1716 | } | 
|---|
| 1717 | } else  EDIT_PaintText(hwnd, es, dc, x, y, line, 0, ll, FALSE); | 
|---|
| 1718 | } | 
|---|
| 1719 |  | 
|---|
| 1720 |  | 
|---|
| 1721 | /********************************************************************* | 
|---|
| 1722 | * | 
|---|
| 1723 | *      EDIT_PaintText | 
|---|
| 1724 | * | 
|---|
| 1725 | */ | 
|---|
| 1726 | static VOID EDIT_PaintText(HWND hwnd, EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev) | 
|---|
| 1727 | { | 
|---|
| 1728 | COLORREF BkColor; | 
|---|
| 1729 | COLORREF TextColor; | 
|---|
| 1730 | INT li; | 
|---|
| 1731 |  | 
|---|
| 1732 | if (!count) | 
|---|
| 1733 | return; | 
|---|
| 1734 | BkColor = GetBkColor(dc); | 
|---|
| 1735 | TextColor = GetTextColor(dc); | 
|---|
| 1736 | if (rev) | 
|---|
| 1737 | { | 
|---|
| 1738 | SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT)); | 
|---|
| 1739 | SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT)); | 
|---|
| 1740 | } | 
|---|
| 1741 | li = EDIT_EM_LineIndex(hwnd, es, line); | 
|---|
| 1742 | if (es->style & ES_MULTILINE) | 
|---|
| 1743 | { | 
|---|
| 1744 | TabbedTextOutA(dc, x, y, es->text + li + col, count, | 
|---|
| 1745 | es->tabs_count, es->tabs, es->format_rect.left - es->x_offset); | 
|---|
| 1746 | } else | 
|---|
| 1747 | { | 
|---|
| 1748 | LPSTR text = EDIT_GetPasswordPointer_SL(hwnd, es); | 
|---|
| 1749 | POINT pt; | 
|---|
| 1750 |  | 
|---|
| 1751 | TextOutA(dc,x,y,text+li+col,count); | 
|---|
| 1752 | if (es->style & ES_PASSWORD) | 
|---|
| 1753 | HeapFree(es->heap, 0, text); | 
|---|
| 1754 | } | 
|---|
| 1755 | if (rev) | 
|---|
| 1756 | { | 
|---|
| 1757 | SetBkColor(dc, BkColor); | 
|---|
| 1758 | SetTextColor(dc, TextColor); | 
|---|
| 1759 | } | 
|---|
| 1760 | } | 
|---|
| 1761 |  | 
|---|
| 1762 |  | 
|---|
| 1763 | /********************************************************************* | 
|---|
| 1764 | * | 
|---|
| 1765 | *      EDIT_SetCaretPos | 
|---|
| 1766 | * | 
|---|
| 1767 | */ | 
|---|
| 1768 | static void EDIT_SetCaretPos(HWND hwnd, EDITSTATE *es, INT pos, | 
|---|
| 1769 | BOOL after_wrap) | 
|---|
| 1770 | { | 
|---|
| 1771 | LRESULT res = EDIT_EM_PosFromChar(hwnd,0, es, pos, after_wrap); | 
|---|
| 1772 | INT x = SLOWORD(res); | 
|---|
| 1773 | INT y = SHIWORD(res); | 
|---|
| 1774 |  | 
|---|
| 1775 | if(x < es->format_rect.left) | 
|---|
| 1776 | x = es->format_rect.left; | 
|---|
| 1777 | if(x > es->format_rect.right - 2) | 
|---|
| 1778 | x = es->format_rect.right - 2; | 
|---|
| 1779 | if(y > es->format_rect.bottom) | 
|---|
| 1780 | y = es->format_rect.bottom; | 
|---|
| 1781 | if(y < es->format_rect.top) | 
|---|
| 1782 | y = es->format_rect.top; | 
|---|
| 1783 | SetCaretPos(x, y); | 
|---|
| 1784 | return; | 
|---|
| 1785 | } | 
|---|
| 1786 |  | 
|---|
| 1787 |  | 
|---|
| 1788 | /********************************************************************* | 
|---|
| 1789 | * | 
|---|
| 1790 | *      EDIT_SetRectNP | 
|---|
| 1791 | * | 
|---|
| 1792 | *      note:   this is not (exactly) the handler called on EM_SETRECTNP | 
|---|
| 1793 | *              it is also used to set the rect of a single line control | 
|---|
| 1794 | * | 
|---|
| 1795 | */ | 
|---|
| 1796 | static void EDIT_SetRectNP(HWND hwnd, EDITSTATE *es, LPRECT rc) | 
|---|
| 1797 | { | 
|---|
| 1798 | CopyRect(&es->format_rect, rc); | 
|---|
| 1799 | if (es->style & WS_BORDER) | 
|---|
| 1800 | { | 
|---|
| 1801 | INT bw = GetSystemMetrics(SM_CXBORDER)+1,bh = GetSystemMetrics(SM_CYBORDER)+1; | 
|---|
| 1802 |  | 
|---|
| 1803 | es->format_rect.left += bw; | 
|---|
| 1804 | es->format_rect.top += bh; | 
|---|
| 1805 | es->format_rect.right -= bw; | 
|---|
| 1806 | es->format_rect.bottom -= bh; | 
|---|
| 1807 | } | 
|---|
| 1808 | es->format_rect.left += es->left_margin; | 
|---|
| 1809 | es->format_rect.right -= es->right_margin; | 
|---|
| 1810 | es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width); | 
|---|
| 1811 | if (es->style & ES_MULTILINE) | 
|---|
| 1812 | es->format_rect.bottom = es->format_rect.top + | 
|---|
| 1813 | MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height; | 
|---|
| 1814 | else | 
|---|
| 1815 | es->format_rect.bottom = es->format_rect.top + es->line_height; | 
|---|
| 1816 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) | 
|---|
| 1817 | EDIT_BuildLineDefs_ML(hwnd,es); | 
|---|
| 1818 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); | 
|---|
| 1819 | } | 
|---|
| 1820 |  | 
|---|
| 1821 |  | 
|---|
| 1822 | /********************************************************************* | 
|---|
| 1823 | * | 
|---|
| 1824 | *      EDIT_UnlockBuffer | 
|---|
| 1825 | * | 
|---|
| 1826 | */ | 
|---|
| 1827 | static void EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force) | 
|---|
| 1828 | { | 
|---|
| 1829 | if (!es) { | 
|---|
| 1830 | //ERR_(edit)("no EDITSTATE ... please report\n"); | 
|---|
| 1831 | return; | 
|---|
| 1832 | } | 
|---|
| 1833 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 1834 | return; | 
|---|
| 1835 | if (!es->lock_count) { | 
|---|
| 1836 | //ERR_(edit)("lock_count == 0 ... please report\n"); | 
|---|
| 1837 | return; | 
|---|
| 1838 | } | 
|---|
| 1839 | if (!es->text) { | 
|---|
| 1840 | //ERR_(edit)("es->text == 0 ... please report\n"); | 
|---|
| 1841 | return; | 
|---|
| 1842 | } | 
|---|
| 1843 | if (force || (es->lock_count == 1)) { | 
|---|
| 1844 | if (es->hloc) { | 
|---|
| 1845 | LocalUnlock(es->hloc); | 
|---|
| 1846 | es->text = NULL; | 
|---|
| 1847 | } | 
|---|
| 1848 | } | 
|---|
| 1849 | es->lock_count--; | 
|---|
| 1850 | } | 
|---|
| 1851 |  | 
|---|
| 1852 |  | 
|---|
| 1853 | /********************************************************************* | 
|---|
| 1854 | * | 
|---|
| 1855 | *      EDIT_WordBreakProc | 
|---|
| 1856 | * | 
|---|
| 1857 | *      Find the beginning of words. | 
|---|
| 1858 | *      Note:   unlike the specs for a WordBreakProc, this function only | 
|---|
| 1859 | *              allows to be called without linebreaks between s[0] upto | 
|---|
| 1860 | *              s[count - 1].  Remember it is only called | 
|---|
| 1861 | *              internally, so we can decide this for ourselves. | 
|---|
| 1862 | * | 
|---|
| 1863 | */ | 
|---|
| 1864 | static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action) | 
|---|
| 1865 | { | 
|---|
| 1866 | INT ret = 0; | 
|---|
| 1867 |  | 
|---|
| 1868 | //TRACE_(edit)("s=%p, index=%u, count=%u, action=%d\n", | 
|---|
| 1869 | //             s, index, count, action); | 
|---|
| 1870 |  | 
|---|
| 1871 | switch (action) { | 
|---|
| 1872 | case WB_LEFT: | 
|---|
| 1873 | if (!count) | 
|---|
| 1874 | break; | 
|---|
| 1875 | if (index) | 
|---|
| 1876 | index--; | 
|---|
| 1877 | if (s[index] == ' ') { | 
|---|
| 1878 | while (index && (s[index] == ' ')) | 
|---|
| 1879 | index--; | 
|---|
| 1880 | if (index) { | 
|---|
| 1881 | while (index && (s[index] != ' ')) | 
|---|
| 1882 | index--; | 
|---|
| 1883 | if (s[index] == ' ') | 
|---|
| 1884 | index++; | 
|---|
| 1885 | } | 
|---|
| 1886 | } else { | 
|---|
| 1887 | while (index && (s[index] != ' ')) | 
|---|
| 1888 | index--; | 
|---|
| 1889 | if (s[index] == ' ') | 
|---|
| 1890 | index++; | 
|---|
| 1891 | } | 
|---|
| 1892 | ret = index; | 
|---|
| 1893 | break; | 
|---|
| 1894 | case WB_RIGHT: | 
|---|
| 1895 | if (!count) | 
|---|
| 1896 | break; | 
|---|
| 1897 | if (index) | 
|---|
| 1898 | index--; | 
|---|
| 1899 | if (s[index] == ' ') | 
|---|
| 1900 | while ((index < count) && (s[index] == ' ')) index++; | 
|---|
| 1901 | else { | 
|---|
| 1902 | while (s[index] && (s[index] != ' ') && (index < count)) | 
|---|
| 1903 | index++; | 
|---|
| 1904 | while ((s[index] == ' ') && (index < count)) index++; | 
|---|
| 1905 | } | 
|---|
| 1906 | ret = index; | 
|---|
| 1907 | break; | 
|---|
| 1908 | case WB_ISDELIMITER: | 
|---|
| 1909 | ret = (s[index] == ' '); | 
|---|
| 1910 | break; | 
|---|
| 1911 | default: | 
|---|
| 1912 | //ERR_(edit)("unknown action code, please report !\n"); | 
|---|
| 1913 | break; | 
|---|
| 1914 | } | 
|---|
| 1915 | return ret; | 
|---|
| 1916 | } | 
|---|
| 1917 |  | 
|---|
| 1918 |  | 
|---|
| 1919 | /********************************************************************* | 
|---|
| 1920 | * | 
|---|
| 1921 | *      EM_CHARFROMPOS | 
|---|
| 1922 | * | 
|---|
| 1923 | *      returns line number (not index) in high-order word of result. | 
|---|
| 1924 | *      NB : Q137805 is unclear about this. POINT * pointer in lParam apply | 
|---|
| 1925 | *      to Richedit, not to the edit control. Original documentation is valid. | 
|---|
| 1926 | * | 
|---|
| 1927 | */ | 
|---|
| 1928 | static LRESULT EDIT_EM_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y) | 
|---|
| 1929 | { | 
|---|
| 1930 | POINT pt; | 
|---|
| 1931 | INT index; | 
|---|
| 1932 |  | 
|---|
| 1933 | pt.x = x; | 
|---|
| 1934 | pt.y = y; | 
|---|
| 1935 |  | 
|---|
| 1936 | if (!PtInRect(&es->format_rect,pt)) return -1; | 
|---|
| 1937 |  | 
|---|
| 1938 | index = EDIT_CharFromPos(hwnd, es, x, y, NULL); | 
|---|
| 1939 | return MAKELONG(index, EDIT_EM_LineFromChar(hwnd, es, index)); | 
|---|
| 1940 | } | 
|---|
| 1941 |  | 
|---|
| 1942 |  | 
|---|
| 1943 | /********************************************************************* | 
|---|
| 1944 | * | 
|---|
| 1945 | *      EM_FMTLINES | 
|---|
| 1946 | * | 
|---|
| 1947 | * Enable or disable soft breaks. | 
|---|
| 1948 | */ | 
|---|
| 1949 | static BOOL EDIT_EM_FmtLines(HWND hwnd, EDITSTATE *es, BOOL add_eol) | 
|---|
| 1950 | { | 
|---|
| 1951 | es->flags &= ~EF_USE_SOFTBRK; | 
|---|
| 1952 | if (add_eol) { | 
|---|
| 1953 | es->flags |= EF_USE_SOFTBRK; | 
|---|
| 1954 | dprintf(("EDIT: EM_FMTLINES: soft break enabled, not implemented\n")); | 
|---|
| 1955 | } | 
|---|
| 1956 | return add_eol; | 
|---|
| 1957 | } | 
|---|
| 1958 |  | 
|---|
| 1959 | static INT EDIT_EM_GetFirstVisibleLine(HWND hwnd,EDITSTATE *es) | 
|---|
| 1960 | { | 
|---|
| 1961 | return (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset; | 
|---|
| 1962 | } | 
|---|
| 1963 |  | 
|---|
| 1964 | /********************************************************************* | 
|---|
| 1965 | * | 
|---|
| 1966 | *      EM_GETHANDLE | 
|---|
| 1967 | * | 
|---|
| 1968 | *      Hopefully this won't fire back at us. | 
|---|
| 1969 | *      We always start with a fixed buffer in our own heap. | 
|---|
| 1970 | *      However, with this message a 32 bit application requests | 
|---|
| 1971 | *      a handle to 32 bit moveable local heap memory, where it expects | 
|---|
| 1972 | *      to find the text. | 
|---|
| 1973 | *      It's a pity that from this moment on we have to use this | 
|---|
| 1974 | *      local heap, because applications may rely on the handle | 
|---|
| 1975 | *      in the future. | 
|---|
| 1976 | * | 
|---|
| 1977 | *      In this function we'll try to switch to local heap. | 
|---|
| 1978 | * | 
|---|
| 1979 | */ | 
|---|
| 1980 | static HLOCAL EDIT_EM_GetHandle(HWND hwnd, EDITSTATE *es) | 
|---|
| 1981 | { | 
|---|
| 1982 | HLOCAL newBuf; | 
|---|
| 1983 | LPSTR newText; | 
|---|
| 1984 | INT newSize; | 
|---|
| 1985 |  | 
|---|
| 1986 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 1987 | return 0; | 
|---|
| 1988 |  | 
|---|
| 1989 | if (es->hloc) | 
|---|
| 1990 | return es->hloc; | 
|---|
| 1991 |  | 
|---|
| 1992 | if (!(newBuf = LocalAlloc(LMEM_MOVEABLE, lstrlenA(es->text) + 1))) { | 
|---|
| 1993 | //ERR_(edit)("could not allocate new 32 bit buffer\n"); | 
|---|
| 1994 | return 0; | 
|---|
| 1995 | } | 
|---|
| 1996 | #ifdef __WIN32OS2__ | 
|---|
| 1997 | newSize = LocalSize(newBuf) - 1; | 
|---|
| 1998 | #else | 
|---|
| 1999 | newSize = MIN(LocalSize(newBuf) - 1, es->buffer_limit); | 
|---|
| 2000 | #endif | 
|---|
| 2001 | if (!(newText = (char*)LocalLock(newBuf))) { | 
|---|
| 2002 | //ERR_(edit)("could not lock new 32 bit buffer\n"); | 
|---|
| 2003 | LocalFree(newBuf); | 
|---|
| 2004 | return 0; | 
|---|
| 2005 | } | 
|---|
| 2006 | lstrcpyA(newText, es->text); | 
|---|
| 2007 | EDIT_UnlockBuffer(hwnd, es, TRUE); | 
|---|
| 2008 | if (es->text) | 
|---|
| 2009 | HeapFree(es->heap, 0, es->text); | 
|---|
| 2010 | es->hloc = newBuf; | 
|---|
| 2011 | es->buffer_size = newSize; | 
|---|
| 2012 | es->text = newText; | 
|---|
| 2013 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 2014 | //TRACE_(edit)("switched to 32 bit local heap\n"); | 
|---|
| 2015 |  | 
|---|
| 2016 | return es->hloc; | 
|---|
| 2017 | } | 
|---|
| 2018 |  | 
|---|
| 2019 | static INT EDIT_EM_GetLimitText(HWND hwnd,EDITSTATE *es) | 
|---|
| 2020 | { | 
|---|
| 2021 | return es->buffer_limit; | 
|---|
| 2022 | } | 
|---|
| 2023 |  | 
|---|
| 2024 | /********************************************************************* | 
|---|
| 2025 | * | 
|---|
| 2026 | *      EM_GETLINE | 
|---|
| 2027 | * | 
|---|
| 2028 | */ | 
|---|
| 2029 | static INT EDIT_EM_GetLine(HWND hwnd, EDITSTATE *es, INT line, LPSTR lpch) | 
|---|
| 2030 | { | 
|---|
| 2031 | LPSTR src; | 
|---|
| 2032 | INT len; | 
|---|
| 2033 | INT i; | 
|---|
| 2034 |  | 
|---|
| 2035 | if (!lpch || (*(WORD*)lpch == 0)) return 0; | 
|---|
| 2036 |  | 
|---|
| 2037 | if (es->style & ES_MULTILINE) { | 
|---|
| 2038 | if (line >= es->line_count) | 
|---|
| 2039 | return 0; | 
|---|
| 2040 | } else | 
|---|
| 2041 | line = 0; | 
|---|
| 2042 | i = EDIT_EM_LineIndex(hwnd, es, line); | 
|---|
| 2043 | src = es->text + i; | 
|---|
| 2044 | len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(hwnd, es, i)); | 
|---|
| 2045 | for (i = 0 ; i < len ; i++) { | 
|---|
| 2046 | *lpch = *src; | 
|---|
| 2047 | src++; | 
|---|
| 2048 | lpch++; | 
|---|
| 2049 | } | 
|---|
| 2050 | //SvL: Terminate string | 
|---|
| 2051 | *lpch = 0; | 
|---|
| 2052 | return (LRESULT)len; | 
|---|
| 2053 | } | 
|---|
| 2054 |  | 
|---|
| 2055 | static INT EDIT_EM_GetLineCount(HWND hwnd,EDITSTATE *es) | 
|---|
| 2056 | { | 
|---|
| 2057 | return (es->style & ES_MULTILINE) ? es->line_count : 1; | 
|---|
| 2058 | } | 
|---|
| 2059 |  | 
|---|
| 2060 | static LONG EDIT_EM_GetMargins(HWND hwnd,EDITSTATE *es) | 
|---|
| 2061 | { | 
|---|
| 2062 | return MAKELONG(es->left_margin, es->right_margin); | 
|---|
| 2063 | } | 
|---|
| 2064 |  | 
|---|
| 2065 | static BOOL EDIT_EM_GetModify(HWND hwnd,EDITSTATE *es) | 
|---|
| 2066 | { | 
|---|
| 2067 | return ((es->flags & EF_MODIFIED) != 0); | 
|---|
| 2068 | } | 
|---|
| 2069 |  | 
|---|
| 2070 | static CHAR EDIT_EM_GetPasswordChar(HWND hwnd,EDITSTATE *es) | 
|---|
| 2071 | { | 
|---|
| 2072 | return es->password_char; | 
|---|
| 2073 | } | 
|---|
| 2074 |  | 
|---|
| 2075 | static VOID EDIT_EM_GetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc) | 
|---|
| 2076 | { | 
|---|
| 2077 | if (lprc) CopyRect(lprc,&es->format_rect); | 
|---|
| 2078 | } | 
|---|
| 2079 |  | 
|---|
| 2080 | /********************************************************************* | 
|---|
| 2081 | * | 
|---|
| 2082 | *      EM_GETSEL | 
|---|
| 2083 | * | 
|---|
| 2084 | */ | 
|---|
| 2085 | static LRESULT EDIT_EM_GetSel(HWND hwnd, EDITSTATE *es, LPUINT start, LPUINT end) | 
|---|
| 2086 | { | 
|---|
| 2087 | UINT s = es->selection_start; | 
|---|
| 2088 | UINT e = es->selection_end; | 
|---|
| 2089 |  | 
|---|
| 2090 | ORDER_UINT(s, e); | 
|---|
| 2091 |  | 
|---|
| 2092 | if (start) | 
|---|
| 2093 | *start = s; | 
|---|
| 2094 | if (end) | 
|---|
| 2095 | *end = e; | 
|---|
| 2096 | return MAKELONG(s, e); | 
|---|
| 2097 | } | 
|---|
| 2098 |  | 
|---|
| 2099 | /********************************************************************* | 
|---|
| 2100 | * | 
|---|
| 2101 | *      EM_GETTHUMB | 
|---|
| 2102 | */ | 
|---|
| 2103 | static LRESULT EDIT_EM_GetThumb(HWND hwnd, EDITSTATE *es) | 
|---|
| 2104 | { | 
|---|
| 2105 | SCROLLINFO si; | 
|---|
| 2106 |  | 
|---|
| 2107 | if (!(es->style & ES_MULTILINE)) return 0; | 
|---|
| 2108 |  | 
|---|
| 2109 | si.cbSize = sizeof(si); | 
|---|
| 2110 | si.fMask  = SIF_TRACKPOS; | 
|---|
| 2111 | return GetScrollInfo(hwnd,SB_VERT,&si) ? si.nTrackPos:0; | 
|---|
| 2112 | } | 
|---|
| 2113 |  | 
|---|
| 2114 | static PVOID EDIT_EM_GetWordbreakProc(HWND hwnd,EDITSTATE *es) | 
|---|
| 2115 | { | 
|---|
| 2116 | return es->word_break_procA; | 
|---|
| 2117 | } | 
|---|
| 2118 |  | 
|---|
| 2119 | /********************************************************************* | 
|---|
| 2120 | * | 
|---|
| 2121 | *      EM_LINEFROMCHAR | 
|---|
| 2122 | * | 
|---|
| 2123 | */ | 
|---|
| 2124 | static INT EDIT_EM_LineFromChar(HWND hwnd, EDITSTATE *es, INT index) | 
|---|
| 2125 | { | 
|---|
| 2126 | INT line; | 
|---|
| 2127 | LINEDEF *line_def; | 
|---|
| 2128 |  | 
|---|
| 2129 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2130 | return 0; | 
|---|
| 2131 | if (index > lstrlenA(es->text)) | 
|---|
| 2132 | return es->line_count - 1; | 
|---|
| 2133 | if (index == -1) | 
|---|
| 2134 | index = MIN(es->selection_start, es->selection_end); //selection_end == caret pos | 
|---|
| 2135 |  | 
|---|
| 2136 | line = 0; | 
|---|
| 2137 | line_def = es->first_line_def; | 
|---|
| 2138 | index -= line_def->length; | 
|---|
| 2139 | while ((index >= 0) && line_def->next) { | 
|---|
| 2140 | line++; | 
|---|
| 2141 | line_def = line_def->next; | 
|---|
| 2142 | index -= line_def->length; | 
|---|
| 2143 | } | 
|---|
| 2144 | return line; | 
|---|
| 2145 | } | 
|---|
| 2146 |  | 
|---|
| 2147 |  | 
|---|
| 2148 | /********************************************************************* | 
|---|
| 2149 | * | 
|---|
| 2150 | *      EM_LINEINDEX | 
|---|
| 2151 | * | 
|---|
| 2152 | */ | 
|---|
| 2153 | static INT EDIT_EM_LineIndex(HWND hwnd, EDITSTATE *es, INT line) | 
|---|
| 2154 | { | 
|---|
| 2155 | INT line_index; | 
|---|
| 2156 | LINEDEF *line_def; | 
|---|
| 2157 |  | 
|---|
| 2158 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2159 | return 0; | 
|---|
| 2160 | if (line >= es->line_count) | 
|---|
| 2161 | return -1; | 
|---|
| 2162 |  | 
|---|
| 2163 | line_index = 0; | 
|---|
| 2164 | line_def = es->first_line_def; | 
|---|
| 2165 | if (line == -1) { | 
|---|
| 2166 | INT index = es->selection_end - line_def->length; | 
|---|
| 2167 | while ((index >= 0) && line_def->next) { | 
|---|
| 2168 | line_index += line_def->length; | 
|---|
| 2169 | line_def = line_def->next; | 
|---|
| 2170 | index -= line_def->length; | 
|---|
| 2171 | } | 
|---|
| 2172 | } else { | 
|---|
| 2173 | while (line > 0) { | 
|---|
| 2174 | line_index += line_def->length; | 
|---|
| 2175 | line_def = line_def->next; | 
|---|
| 2176 | line--; | 
|---|
| 2177 | } | 
|---|
| 2178 | } | 
|---|
| 2179 | return line_index; | 
|---|
| 2180 | } | 
|---|
| 2181 |  | 
|---|
| 2182 |  | 
|---|
| 2183 | /********************************************************************* | 
|---|
| 2184 | * | 
|---|
| 2185 | *      EM_LINELENGTH | 
|---|
| 2186 | * | 
|---|
| 2187 | */ | 
|---|
| 2188 | static INT EDIT_EM_LineLength(HWND hwnd, EDITSTATE *es, INT index) | 
|---|
| 2189 | { | 
|---|
| 2190 | LINEDEF *line_def; | 
|---|
| 2191 |  | 
|---|
| 2192 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2193 | return lstrlenA(es->text); | 
|---|
| 2194 |  | 
|---|
| 2195 | if (index == -1) | 
|---|
| 2196 | { | 
|---|
| 2197 | INT sl = EDIT_EM_LineFromChar(hwnd,es,MIN(es->selection_start,es->selection_end)); | 
|---|
| 2198 | INT el = EDIT_EM_LineFromChar(hwnd,es,MAX(es->selection_start,es->selection_end)); | 
|---|
| 2199 |  | 
|---|
| 2200 | if (sl == el) | 
|---|
| 2201 | return EDIT_EM_LineLength(hwnd,es,sl)+es->selection_start-es->selection_end; | 
|---|
| 2202 | else | 
|---|
| 2203 | return es->selection_start+EDIT_EM_LineLength(hwnd,es,el)-es->selection_end; | 
|---|
| 2204 | } | 
|---|
| 2205 | line_def = es->first_line_def; | 
|---|
| 2206 | index -= line_def->length; | 
|---|
| 2207 | while ((index >= 0) && line_def->next) { | 
|---|
| 2208 | line_def = line_def->next; | 
|---|
| 2209 | index -= line_def->length; | 
|---|
| 2210 | } | 
|---|
| 2211 | return line_def->net_length; | 
|---|
| 2212 | } | 
|---|
| 2213 |  | 
|---|
| 2214 | static VOID EDIT_UpdateScrollBars(HWND hwnd,EDITSTATE *es,BOOL updateHorz,BOOL updateVert) | 
|---|
| 2215 | { | 
|---|
| 2216 | if (updateHorz && (es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) | 
|---|
| 2217 | { | 
|---|
| 2218 | SCROLLINFO si; | 
|---|
| 2219 | INT fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 2220 |  | 
|---|
| 2221 | si.cbSize       = sizeof(SCROLLINFO); | 
|---|
| 2222 | si.fMask        = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; | 
|---|
| 2223 | si.nMin         = 0; | 
|---|
| 2224 | si.nMax         = es->text_width + fw - 1; | 
|---|
| 2225 | si.nPage        = fw; | 
|---|
| 2226 | si.nPos         = es->x_offset; | 
|---|
| 2227 | SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); | 
|---|
| 2228 | } | 
|---|
| 2229 |  | 
|---|
| 2230 | if (updateVert && (es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) | 
|---|
| 2231 | { | 
|---|
| 2232 | INT vlc = (es->format_rect.bottom-es->format_rect.top)/es->line_height; | 
|---|
| 2233 | SCROLLINFO si; | 
|---|
| 2234 |  | 
|---|
| 2235 | si.cbSize       = sizeof(SCROLLINFO); | 
|---|
| 2236 | si.fMask        = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; | 
|---|
| 2237 | si.nMin         = 0; | 
|---|
| 2238 | si.nMax         = es->line_count + vlc - 2; | 
|---|
| 2239 | si.nPage        = vlc; | 
|---|
| 2240 | si.nPos         = es->y_offset; | 
|---|
| 2241 | SetScrollInfo(hwnd, SB_VERT, &si, TRUE); | 
|---|
| 2242 | } | 
|---|
| 2243 | } | 
|---|
| 2244 |  | 
|---|
| 2245 |  | 
|---|
| 2246 | /********************************************************************* | 
|---|
| 2247 | * | 
|---|
| 2248 | *      EM_LINESCROLL | 
|---|
| 2249 | * | 
|---|
| 2250 | *      FIXME: dx is in average character widths | 
|---|
| 2251 | *              However, we assume it is in pixels when we use this | 
|---|
| 2252 | *              function internally | 
|---|
| 2253 | * | 
|---|
| 2254 | */ | 
|---|
| 2255 | static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy) | 
|---|
| 2256 | { | 
|---|
| 2257 | INT nyoff; | 
|---|
| 2258 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2259 |  | 
|---|
| 2260 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2261 | return FALSE; | 
|---|
| 2262 |  | 
|---|
| 2263 | if (-dx > es->x_offset) | 
|---|
| 2264 | dx = -es->x_offset; | 
|---|
| 2265 | if (dx > es->text_width - es->x_offset) | 
|---|
| 2266 | dx = es->text_width - es->x_offset; | 
|---|
| 2267 | nyoff = MAX(0, es->y_offset + dy); | 
|---|
| 2268 |  | 
|---|
| 2269 | //SvL: If nyoff > nr lines in control -> last line in control | 
|---|
| 2270 | //     window should show last line of control | 
|---|
| 2271 | //     Wine code shows last line at the top of the control | 
|---|
| 2272 | //     (Quake 3 startup edit control shows the problem) | 
|---|
| 2273 | if (nyoff >= es->line_count) { | 
|---|
| 2274 | if(es->line_count <= vlc) { | 
|---|
| 2275 | nyoff = es->y_offset;   //no need to scroll | 
|---|
| 2276 | } | 
|---|
| 2277 | else    nyoff = es->line_count - vlc - 1; | 
|---|
| 2278 | } | 
|---|
| 2279 | dy = (es->y_offset - nyoff) * es->line_height; | 
|---|
| 2280 | if (dx || dy) | 
|---|
| 2281 | { | 
|---|
| 2282 | RECT rc1; | 
|---|
| 2283 | RECT rc; | 
|---|
| 2284 |  | 
|---|
| 2285 | if (dx && !(es->flags & EF_HSCROLL_TRACK)) | 
|---|
| 2286 | EDIT_NOTIFY_PARENT(hwnd, EN_HSCROLL); | 
|---|
| 2287 | if (dy && !(es->flags & EF_VSCROLL_TRACK)) | 
|---|
| 2288 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL); | 
|---|
| 2289 |  | 
|---|
| 2290 | GetClientRect(hwnd, &rc1); | 
|---|
| 2291 | IntersectRect(&rc, &rc1, &es->format_rect); | 
|---|
| 2292 |  | 
|---|
| 2293 | ScrollWindowEx(hwnd,-dx,dy,NULL,&rc,(HRGN)NULL,NULL,SW_INVALIDATE); | 
|---|
| 2294 | es->y_offset = nyoff; | 
|---|
| 2295 | es->x_offset += dx; | 
|---|
| 2296 | EDIT_UpdateScrollBars(hwnd,es,dx,dy); | 
|---|
| 2297 | } | 
|---|
| 2298 |  | 
|---|
| 2299 | return TRUE; | 
|---|
| 2300 | } | 
|---|
| 2301 |  | 
|---|
| 2302 |  | 
|---|
| 2303 | /********************************************************************* | 
|---|
| 2304 | * | 
|---|
| 2305 | *      EM_POSFROMCHAR | 
|---|
| 2306 | * | 
|---|
| 2307 | */ | 
|---|
| 2308 | static LRESULT EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap) | 
|---|
| 2309 | { | 
|---|
| 2310 | INT len = lstrlenA(es->text); | 
|---|
| 2311 | INT l; | 
|---|
| 2312 | INT li; | 
|---|
| 2313 | INT x; | 
|---|
| 2314 | INT y = 0; | 
|---|
| 2315 | BOOL createdDC = FALSE; | 
|---|
| 2316 | HFONT old_font = 0; | 
|---|
| 2317 | SIZE size; | 
|---|
| 2318 |  | 
|---|
| 2319 | index = MIN(index, len); | 
|---|
| 2320 | if (!dc) | 
|---|
| 2321 | { | 
|---|
| 2322 | dc = GetDC(hwnd); | 
|---|
| 2323 | if (es->font) | 
|---|
| 2324 | old_font = SelectObject(dc, es->font); | 
|---|
| 2325 | createdDC = TRUE; | 
|---|
| 2326 | } | 
|---|
| 2327 | if (es->style & ES_MULTILINE) { | 
|---|
| 2328 | l = EDIT_EM_LineFromChar(hwnd, es, index); | 
|---|
| 2329 | y = (l - es->y_offset) * es->line_height; | 
|---|
| 2330 | li = EDIT_EM_LineIndex(hwnd, es, l); | 
|---|
| 2331 | if (after_wrap && (li == index) && l) { | 
|---|
| 2332 | INT l2 = l - 1; | 
|---|
| 2333 | LINEDEF *line_def = es->first_line_def; | 
|---|
| 2334 | while (l2) { | 
|---|
| 2335 | line_def = line_def->next; | 
|---|
| 2336 | l2--; | 
|---|
| 2337 | } | 
|---|
| 2338 | if (line_def->ending == END_WRAP) { | 
|---|
| 2339 | l--; | 
|---|
| 2340 | y -= es->line_height; | 
|---|
| 2341 | li = EDIT_EM_LineIndex(hwnd, es, l); | 
|---|
| 2342 | } | 
|---|
| 2343 | } | 
|---|
| 2344 | x = LOWORD(GetTabbedTextExtentA(dc, es->text + li, index - li, | 
|---|
| 2345 | es->tabs_count, es->tabs)) - es->x_offset; | 
|---|
| 2346 | } else | 
|---|
| 2347 | { | 
|---|
| 2348 | LPSTR text = EDIT_GetPasswordPointer_SL(hwnd, es); | 
|---|
| 2349 |  | 
|---|
| 2350 | GetTextExtentPoint32A(dc,text,index,&size); | 
|---|
| 2351 | x = size.cx; | 
|---|
| 2352 | if (es->x_offset) | 
|---|
| 2353 | { | 
|---|
| 2354 | GetTextExtentPoint32A(dc,text,es->x_offset,&size); | 
|---|
| 2355 | x -= size.cx; | 
|---|
| 2356 | } | 
|---|
| 2357 | y = 0; | 
|---|
| 2358 | if (es->style & ES_PASSWORD) | 
|---|
| 2359 | HeapFree(es->heap, 0 ,text); | 
|---|
| 2360 | } | 
|---|
| 2361 | x += es->format_rect.left; | 
|---|
| 2362 | y += es->format_rect.top; | 
|---|
| 2363 | if (createdDC) | 
|---|
| 2364 | { | 
|---|
| 2365 | if (es->font) | 
|---|
| 2366 | SelectObject(dc, old_font); | 
|---|
| 2367 | ReleaseDC(hwnd, dc); | 
|---|
| 2368 | } | 
|---|
| 2369 | return MAKELONG((INT16)x, (INT16)y); | 
|---|
| 2370 | } | 
|---|
| 2371 |  | 
|---|
| 2372 | BOOL EDIT_CheckNumber(CHAR *text) | 
|---|
| 2373 | { | 
|---|
| 2374 | if (!text) return TRUE; | 
|---|
| 2375 |  | 
|---|
| 2376 | while (text[0] != 0) | 
|---|
| 2377 | { | 
|---|
| 2378 | if ((BYTE)text[0] < '0' || (BYTE)text[0] > '9') return FALSE; | 
|---|
| 2379 | text++; | 
|---|
| 2380 | } | 
|---|
| 2381 |  | 
|---|
| 2382 | return TRUE; | 
|---|
| 2383 | } | 
|---|
| 2384 |  | 
|---|
| 2385 | /********************************************************************* | 
|---|
| 2386 | * | 
|---|
| 2387 | *      EM_REPLACESEL | 
|---|
| 2388 | * | 
|---|
| 2389 | */ | 
|---|
| 2390 | static void EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace) | 
|---|
| 2391 | { | 
|---|
| 2392 | INT strl = lstrlenA(lpsz_replace); | 
|---|
| 2393 | INT tl = lstrlenA(es->text); | 
|---|
| 2394 | INT utl; | 
|---|
| 2395 | UINT s; | 
|---|
| 2396 | UINT e; | 
|---|
| 2397 | INT i; | 
|---|
| 2398 | LPSTR p; | 
|---|
| 2399 |  | 
|---|
| 2400 | s = es->selection_start; | 
|---|
| 2401 | e = es->selection_end; | 
|---|
| 2402 |  | 
|---|
| 2403 | if ((s == e) && !strl) | 
|---|
| 2404 | return; | 
|---|
| 2405 |  | 
|---|
| 2406 | ORDER_UINT(s, e); | 
|---|
| 2407 |  | 
|---|
| 2408 | if (!EDIT_MakeFit(hwnd, es, tl - (e - s) + strl)) | 
|---|
| 2409 | return; | 
|---|
| 2410 |  | 
|---|
| 2411 | if (e != s) { | 
|---|
| 2412 | /* there is something to be deleted */ | 
|---|
| 2413 | if (can_undo) { | 
|---|
| 2414 | utl = lstrlenA(es->undo_text); | 
|---|
| 2415 | if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) { | 
|---|
| 2416 | /* undo-buffer is extended to the right */ | 
|---|
| 2417 | EDIT_MakeUndoFit(hwnd, es, utl + e - s); | 
|---|
| 2418 | lstrcpynA(es->undo_text + utl, es->text + s, e - s + 1); | 
|---|
| 2419 | } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) { | 
|---|
| 2420 | /* undo-buffer is extended to the left */ | 
|---|
| 2421 | EDIT_MakeUndoFit(hwnd, es, utl + e - s); | 
|---|
| 2422 | for (p = es->undo_text + utl ; p >= es->undo_text ; p--) | 
|---|
| 2423 | p[e - s] = p[0]; | 
|---|
| 2424 | for (i = 0 , p = es->undo_text ; i < e - s ; i++) | 
|---|
| 2425 | p[i] = (es->text + s)[i]; | 
|---|
| 2426 | es->undo_position = s; | 
|---|
| 2427 | } else { | 
|---|
| 2428 | /* new undo-buffer */ | 
|---|
| 2429 | EDIT_MakeUndoFit(hwnd, es, e - s); | 
|---|
| 2430 | lstrcpynA(es->undo_text, es->text + s, e - s + 1); | 
|---|
| 2431 | es->undo_position = s; | 
|---|
| 2432 | } | 
|---|
| 2433 | /* any deletion makes the old insertion-undo invalid */ | 
|---|
| 2434 | es->undo_insert_count = 0; | 
|---|
| 2435 | } else | 
|---|
| 2436 | EDIT_EM_EmptyUndoBuffer(hwnd, es); | 
|---|
| 2437 |  | 
|---|
| 2438 | /* now delete */ | 
|---|
| 2439 | lstrcpyA(es->text + s, es->text + e); | 
|---|
| 2440 | } | 
|---|
| 2441 | if (strl) | 
|---|
| 2442 | { | 
|---|
| 2443 | if ((es->style & ES_NUMBER) && !EDIT_CheckNumber((CHAR*)lpsz_replace)) | 
|---|
| 2444 | MessageBeep(MB_ICONEXCLAMATION); | 
|---|
| 2445 | else | 
|---|
| 2446 | { | 
|---|
| 2447 | /* there is an insertion */ | 
|---|
| 2448 | if (can_undo) { | 
|---|
| 2449 | if ((s == es->undo_position) || | 
|---|
| 2450 | ((es->undo_insert_count) && | 
|---|
| 2451 | (s == es->undo_position + es->undo_insert_count))) | 
|---|
| 2452 | /* | 
|---|
| 2453 | * insertion is new and at delete position or | 
|---|
| 2454 | * an extension to either left or right | 
|---|
| 2455 | */ | 
|---|
| 2456 | es->undo_insert_count += strl; | 
|---|
| 2457 | else { | 
|---|
| 2458 | /* new insertion undo */ | 
|---|
| 2459 | es->undo_position = s; | 
|---|
| 2460 | es->undo_insert_count = strl; | 
|---|
| 2461 | /* new insertion makes old delete-buffer invalid */ | 
|---|
| 2462 | *es->undo_text = '\0'; | 
|---|
| 2463 | } | 
|---|
| 2464 | } else | 
|---|
| 2465 | EDIT_EM_EmptyUndoBuffer(hwnd, es); | 
|---|
| 2466 |  | 
|---|
| 2467 |  | 
|---|
| 2468 | /* now insert */ | 
|---|
| 2469 | tl = lstrlenA(es->text); | 
|---|
| 2470 | for (p = es->text + tl ; p >= es->text + s ; p--) | 
|---|
| 2471 | p[strl] = p[0]; | 
|---|
| 2472 | for (i = 0 , p = es->text + s ; i < strl ; i++) | 
|---|
| 2473 | p[i] = lpsz_replace[i]; | 
|---|
| 2474 |  | 
|---|
| 2475 | if (es->style & ES_OEMCONVERT) | 
|---|
| 2476 | { | 
|---|
| 2477 | CHAR *text = (LPSTR)HeapAlloc(es->heap,0,strl); | 
|---|
| 2478 |  | 
|---|
| 2479 | CharToOemBuffA(lpsz_replace,text,strl); | 
|---|
| 2480 | OemToCharBuffA(text,p,strl); | 
|---|
| 2481 | HeapFree(es->heap,0,text); | 
|---|
| 2482 | } | 
|---|
| 2483 |  | 
|---|
| 2484 | if(es->style & ES_UPPERCASE) | 
|---|
| 2485 | CharUpperBuffA(p, strl); | 
|---|
| 2486 | else if(es->style & ES_LOWERCASE) | 
|---|
| 2487 | CharLowerBuffA(p, strl); | 
|---|
| 2488 |  | 
|---|
| 2489 | s += strl; | 
|---|
| 2490 | } | 
|---|
| 2491 | } | 
|---|
| 2492 | /* FIXME: really inefficient */ | 
|---|
| 2493 | if (es->style & ES_MULTILINE) | 
|---|
| 2494 | EDIT_BuildLineDefs_ML(hwnd,es); | 
|---|
| 2495 |  | 
|---|
| 2496 | EDIT_EM_SetSel(hwnd, es, s, s, FALSE); | 
|---|
| 2497 |  | 
|---|
| 2498 | es->flags |= EF_MODIFIED; | 
|---|
| 2499 | es->flags |= EF_UPDATE; | 
|---|
| 2500 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2501 |  | 
|---|
| 2502 | /* FIXME: really inefficient */ | 
|---|
| 2503 | EDIT_Refresh(hwnd,es,TRUE); | 
|---|
| 2504 | } | 
|---|
| 2505 |  | 
|---|
| 2506 |  | 
|---|
| 2507 | /********************************************************************* | 
|---|
| 2508 | * | 
|---|
| 2509 | *      EM_SCROLL | 
|---|
| 2510 | * | 
|---|
| 2511 | */ | 
|---|
| 2512 | static LRESULT EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action) | 
|---|
| 2513 | { | 
|---|
| 2514 | INT dy; | 
|---|
| 2515 |  | 
|---|
| 2516 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2517 | return (LRESULT)FALSE; | 
|---|
| 2518 |  | 
|---|
| 2519 | dy = 0; | 
|---|
| 2520 |  | 
|---|
| 2521 | switch (action) { | 
|---|
| 2522 | case SB_LINEUP: | 
|---|
| 2523 | if (es->y_offset) | 
|---|
| 2524 | dy = -1; | 
|---|
| 2525 | break; | 
|---|
| 2526 | case SB_LINEDOWN: | 
|---|
| 2527 | if (es->y_offset < es->line_count - 1) | 
|---|
| 2528 | dy = 1; | 
|---|
| 2529 | break; | 
|---|
| 2530 | case SB_PAGEUP: | 
|---|
| 2531 | if (es->y_offset) | 
|---|
| 2532 | dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2533 | break; | 
|---|
| 2534 | case SB_PAGEDOWN: | 
|---|
| 2535 | if (es->y_offset < es->line_count - 1) | 
|---|
| 2536 | dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2537 | break; | 
|---|
| 2538 | default: | 
|---|
| 2539 | return (LRESULT)FALSE; | 
|---|
| 2540 | } | 
|---|
| 2541 | if (dy) { | 
|---|
| 2542 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL); | 
|---|
| 2543 | EDIT_EM_LineScroll(hwnd, es, 0, dy); | 
|---|
| 2544 | } | 
|---|
| 2545 | return MAKELONG((INT16)dy, (BOOL16)TRUE); | 
|---|
| 2546 | } | 
|---|
| 2547 |  | 
|---|
| 2548 |  | 
|---|
| 2549 | /********************************************************************* | 
|---|
| 2550 | * | 
|---|
| 2551 | *      EM_SCROLLCARET | 
|---|
| 2552 | * | 
|---|
| 2553 | */ | 
|---|
| 2554 | static void EDIT_EM_ScrollCaret(HWND hwnd, EDITSTATE *es) | 
|---|
| 2555 | { | 
|---|
| 2556 | if (es->style & ES_MULTILINE) { | 
|---|
| 2557 | INT l; | 
|---|
| 2558 | INT li; | 
|---|
| 2559 | INT vlc; | 
|---|
| 2560 | INT ww; | 
|---|
| 2561 | INT cw = es->char_width; | 
|---|
| 2562 | INT x; | 
|---|
| 2563 | INT dy = 0; | 
|---|
| 2564 | INT dx = 0; | 
|---|
| 2565 |  | 
|---|
| 2566 | l = EDIT_EM_LineFromChar(hwnd, es, es->selection_end); | 
|---|
| 2567 | li = EDIT_EM_LineIndex(hwnd, es, l); | 
|---|
| 2568 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)); | 
|---|
| 2569 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2570 | if (l >= es->y_offset + vlc) | 
|---|
| 2571 | dy = l - vlc + 1 - es->y_offset; | 
|---|
| 2572 | if (l < es->y_offset) | 
|---|
| 2573 | dy = l - es->y_offset; | 
|---|
| 2574 | ww = es->format_rect.right - es->format_rect.left; | 
|---|
| 2575 | if (x < es->format_rect.left) | 
|---|
| 2576 | dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw; | 
|---|
| 2577 | if (x > es->format_rect.right) | 
|---|
| 2578 | dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw; | 
|---|
| 2579 | if (dy || dx) | 
|---|
| 2580 | EDIT_EM_LineScroll(hwnd, es, dx, dy); | 
|---|
| 2581 | } else { | 
|---|
| 2582 | INT x; | 
|---|
| 2583 | INT goal; | 
|---|
| 2584 | INT format_width; | 
|---|
| 2585 |  | 
|---|
| 2586 | if (!(es->style & ES_AUTOHSCROLL)) | 
|---|
| 2587 | return; | 
|---|
| 2588 |  | 
|---|
| 2589 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE)); | 
|---|
| 2590 | format_width = es->format_rect.right - es->format_rect.left; | 
|---|
| 2591 | if (x < es->format_rect.left) | 
|---|
| 2592 | { | 
|---|
| 2593 | goal = es->format_rect.left + format_width / HSCROLL_FRACTION; | 
|---|
| 2594 | do { | 
|---|
| 2595 | es->x_offset--; | 
|---|
| 2596 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE)); | 
|---|
| 2597 | } while ((x < goal) && es->x_offset); | 
|---|
| 2598 | /* FIXME: use ScrollWindow() somehow to improve performance */ | 
|---|
| 2599 | EDIT_Refresh(hwnd,es,TRUE); | 
|---|
| 2600 | EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE); | 
|---|
| 2601 | } else if (x > es->format_rect.right) | 
|---|
| 2602 | { | 
|---|
| 2603 | INT x_last; | 
|---|
| 2604 | INT len = lstrlenA(es->text); | 
|---|
| 2605 | goal = es->format_rect.right - format_width / HSCROLL_FRACTION; | 
|---|
| 2606 | do { | 
|---|
| 2607 | es->x_offset++; | 
|---|
| 2608 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE)); | 
|---|
| 2609 | x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, len, FALSE)); | 
|---|
| 2610 | } while ((x > goal) && (x_last > es->format_rect.right)); | 
|---|
| 2611 | /* FIXME: use ScrollWindow() somehow to improve performance */ | 
|---|
| 2612 | EDIT_Refresh(hwnd,es,TRUE); | 
|---|
| 2613 | EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE); | 
|---|
| 2614 | } | 
|---|
| 2615 | } | 
|---|
| 2616 | } | 
|---|
| 2617 |  | 
|---|
| 2618 |  | 
|---|
| 2619 | /********************************************************************* | 
|---|
| 2620 | * | 
|---|
| 2621 | *      EM_SETHANDLE | 
|---|
| 2622 | * | 
|---|
| 2623 | */ | 
|---|
| 2624 | static void EDIT_EM_SetHandle(HWND hwnd, EDITSTATE *es, HLOCAL hloc) | 
|---|
| 2625 | { | 
|---|
| 2626 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2627 | return; | 
|---|
| 2628 |  | 
|---|
| 2629 | if (!hloc) { | 
|---|
| 2630 | //WARN_(edit)("called with NULL handle\n"); | 
|---|
| 2631 | return; | 
|---|
| 2632 | } | 
|---|
| 2633 |  | 
|---|
| 2634 | EDIT_UnlockBuffer(hwnd, es, TRUE); | 
|---|
| 2635 | /* | 
|---|
| 2636 | *      old buffer is freed by caller, unless | 
|---|
| 2637 | *      it is still in our own heap.  (in that case | 
|---|
| 2638 | *      we free it, correcting the buggy caller.) | 
|---|
| 2639 | */ | 
|---|
| 2640 | if (es->text) | 
|---|
| 2641 | HeapFree(es->heap, 0, es->text); | 
|---|
| 2642 |  | 
|---|
| 2643 | es->hloc = hloc; | 
|---|
| 2644 | es->text = NULL; | 
|---|
| 2645 | es->buffer_size = LocalSize(es->hloc) - 1; | 
|---|
| 2646 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 2647 |  | 
|---|
| 2648 | if (es->text && (es->text[0] != 0)) | 
|---|
| 2649 | { | 
|---|
| 2650 | if (es->style & ES_NUMBER) | 
|---|
| 2651 | { | 
|---|
| 2652 | //CB: todo | 
|---|
| 2653 | } | 
|---|
| 2654 |  | 
|---|
| 2655 | if (es->style & ES_OEMCONVERT) | 
|---|
| 2656 | { | 
|---|
| 2657 | INT len = lstrlenA(es->text); | 
|---|
| 2658 | CHAR *text = (LPSTR)HeapAlloc(es->heap,0,len); | 
|---|
| 2659 |  | 
|---|
| 2660 | CharToOemBuffA(es->text,text,len); | 
|---|
| 2661 | OemToCharBuffA(text,es->text,len); | 
|---|
| 2662 | HeapFree(es->heap,0,text); | 
|---|
| 2663 | } | 
|---|
| 2664 |  | 
|---|
| 2665 | if(es->style & ES_UPPERCASE) | 
|---|
| 2666 | CharUpperA(es->text); | 
|---|
| 2667 | else if(es->style & ES_LOWERCASE) | 
|---|
| 2668 | CharLowerA(es->text); | 
|---|
| 2669 | } | 
|---|
| 2670 |  | 
|---|
| 2671 | es->x_offset = es->y_offset = 0; | 
|---|
| 2672 | es->selection_start = es->selection_end = 0; | 
|---|
| 2673 | EDIT_EM_EmptyUndoBuffer(hwnd, es); | 
|---|
| 2674 | es->flags &= ~EF_MODIFIED; | 
|---|
| 2675 | es->flags &= ~EF_UPDATE; | 
|---|
| 2676 | EDIT_BuildLineDefs_ML(hwnd,es); | 
|---|
| 2677 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 2678 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2679 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); | 
|---|
| 2680 | } | 
|---|
| 2681 |  | 
|---|
| 2682 | /********************************************************************* | 
|---|
| 2683 | * | 
|---|
| 2684 | *      EM_SETLIMITTEXT | 
|---|
| 2685 | * | 
|---|
| 2686 | *      FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF | 
|---|
| 2687 | *      However, the windows version is not complied to yet in all of edit.c | 
|---|
| 2688 | * | 
|---|
| 2689 | */ | 
|---|
| 2690 | static void EDIT_EM_SetLimitText(HWND hwnd, EDITSTATE *es, INT limit) | 
|---|
| 2691 | { | 
|---|
| 2692 | if (es->style & ES_MULTILINE) { | 
|---|
| 2693 | if (limit) | 
|---|
| 2694 | #ifdef __WIN32OS2__ | 
|---|
| 2695 | es->buffer_limit = limit; | 
|---|
| 2696 | #else | 
|---|
| 2697 | es->buffer_limit = MIN(limit, BUFLIMIT_MULTI); | 
|---|
| 2698 | #endif | 
|---|
| 2699 | else | 
|---|
| 2700 | es->buffer_limit = BUFLIMIT_MULTI; | 
|---|
| 2701 | } else { | 
|---|
| 2702 | if (limit) | 
|---|
| 2703 | #ifdef __WIN32OS2__ | 
|---|
| 2704 | es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE_NT); | 
|---|
| 2705 | #else | 
|---|
| 2706 | es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE); | 
|---|
| 2707 | #endif | 
|---|
| 2708 | else | 
|---|
| 2709 | es->buffer_limit = BUFLIMIT_SINGLE; | 
|---|
| 2710 | } | 
|---|
| 2711 | } | 
|---|
| 2712 |  | 
|---|
| 2713 |  | 
|---|
| 2714 | /********************************************************************* | 
|---|
| 2715 | * | 
|---|
| 2716 | *      EM_SETMARGINS | 
|---|
| 2717 | * | 
|---|
| 2718 | * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an | 
|---|
| 2719 | * action wParam despite what the docs say. EC_USEFONTINFO means one third | 
|---|
| 2720 | * of the char's width, according to the new docs. | 
|---|
| 2721 | * | 
|---|
| 2722 | */ | 
|---|
| 2723 | static void EDIT_EM_SetMargins(HWND hwnd, EDITSTATE *es, INT action, | 
|---|
| 2724 | INT left, INT right) | 
|---|
| 2725 | { | 
|---|
| 2726 | RECT r; | 
|---|
| 2727 | INT oldLeft = es->left_margin,oldRight = es->right_margin; | 
|---|
| 2728 |  | 
|---|
| 2729 | if (action & EC_LEFTMARGIN) { | 
|---|
| 2730 | if (left != EC_USEFONTINFO) | 
|---|
| 2731 | es->left_margin = left; | 
|---|
| 2732 | else | 
|---|
| 2733 | es->left_margin = es->char_width / 3; | 
|---|
| 2734 | } | 
|---|
| 2735 |  | 
|---|
| 2736 | if (action & EC_RIGHTMARGIN) { | 
|---|
| 2737 | if (right != EC_USEFONTINFO) | 
|---|
| 2738 | es->right_margin = right; | 
|---|
| 2739 | else | 
|---|
| 2740 | es->right_margin = es->char_width / 3; | 
|---|
| 2741 | } | 
|---|
| 2742 | //TRACE_(edit)("left=%d, right=%d\n", es->left_margin, es->right_margin); | 
|---|
| 2743 |  | 
|---|
| 2744 | if ((oldLeft != es->left_margin) || (oldRight != es->right_margin)) | 
|---|
| 2745 | { | 
|---|
| 2746 | GetClientRect(hwnd, &r); | 
|---|
| 2747 | EDIT_SetRectNP(hwnd, es, &r); | 
|---|
| 2748 | if (es->style & ES_MULTILINE) | 
|---|
| 2749 | EDIT_BuildLineDefs_ML(hwnd,es); | 
|---|
| 2750 |  | 
|---|
| 2751 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 2752 | if (es->flags & EF_FOCUSED) { | 
|---|
| 2753 | DestroyCaret(); | 
|---|
| 2754 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 2755 | EDIT_SetCaretPos(hwnd, es, es->selection_end, | 
|---|
| 2756 | es->flags & EF_AFTER_WRAP); | 
|---|
| 2757 | ShowCaret(hwnd); | 
|---|
| 2758 | } | 
|---|
| 2759 | } | 
|---|
| 2760 | } | 
|---|
| 2761 |  | 
|---|
| 2762 | static void EDIT_EM_SetModify(HWND hwnd,EDITSTATE *es,BOOL fModified) | 
|---|
| 2763 | { | 
|---|
| 2764 | if (fModified) | 
|---|
| 2765 | es->flags |= EF_MODIFIED; | 
|---|
| 2766 | else | 
|---|
| 2767 | es->flags &= ~(EF_MODIFIED | EF_UPDATE);  /* reset pending updates */ | 
|---|
| 2768 | } | 
|---|
| 2769 |  | 
|---|
| 2770 | /********************************************************************* | 
|---|
| 2771 | * | 
|---|
| 2772 | *      EM_SETPASSWORDCHAR | 
|---|
| 2773 | * | 
|---|
| 2774 | */ | 
|---|
| 2775 | static void EDIT_EM_SetPasswordChar(HWND hwnd, EDITSTATE *es, CHAR c) | 
|---|
| 2776 | { | 
|---|
| 2777 | if (es->style & ES_MULTILINE) | 
|---|
| 2778 | return; | 
|---|
| 2779 |  | 
|---|
| 2780 | if (es->password_char == c) | 
|---|
| 2781 | return; | 
|---|
| 2782 |  | 
|---|
| 2783 | es->password_char = c; | 
|---|
| 2784 | if (c) { | 
|---|
| 2785 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) | ES_PASSWORD); | 
|---|
| 2786 | es->style |= ES_PASSWORD; | 
|---|
| 2787 | } else { | 
|---|
| 2788 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~ES_PASSWORD); | 
|---|
| 2789 | es->style &= ~ES_PASSWORD; | 
|---|
| 2790 | } | 
|---|
| 2791 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 2792 | } | 
|---|
| 2793 |  | 
|---|
| 2794 | static BOOL EDIT_EM_SetReadOnly(HWND hwnd,EDITSTATE *es,BOOL fReadOnly) | 
|---|
| 2795 | { | 
|---|
| 2796 | if (fReadOnly) | 
|---|
| 2797 | { | 
|---|
| 2798 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) | ES_READONLY); | 
|---|
| 2799 | es->style |= ES_READONLY; | 
|---|
| 2800 | } else | 
|---|
| 2801 | { | 
|---|
| 2802 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~ES_READONLY); | 
|---|
| 2803 | es->style &= ~ES_READONLY; | 
|---|
| 2804 | } | 
|---|
| 2805 |  | 
|---|
| 2806 | return TRUE; | 
|---|
| 2807 | } | 
|---|
| 2808 |  | 
|---|
| 2809 | static void EDIT_EM_SetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc) | 
|---|
| 2810 | { | 
|---|
| 2811 | if ((es->style & ES_MULTILINE) && lprc) | 
|---|
| 2812 | { | 
|---|
| 2813 | EDIT_SetRectNP(hwnd,es,lprc); | 
|---|
| 2814 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 2815 | } | 
|---|
| 2816 | } | 
|---|
| 2817 |  | 
|---|
| 2818 | static void EDIT_EM_SetRectNP(HWND hwnd,EDITSTATE *es,LPRECT lprc) | 
|---|
| 2819 | { | 
|---|
| 2820 | if ((es->style & ES_MULTILINE) && lprc) | 
|---|
| 2821 | EDIT_SetRectNP(hwnd,es,lprc); | 
|---|
| 2822 | } | 
|---|
| 2823 |  | 
|---|
| 2824 | /********************************************************************* | 
|---|
| 2825 | * | 
|---|
| 2826 | *      EDIT_EM_SetSel | 
|---|
| 2827 | * | 
|---|
| 2828 | *      note:   unlike the specs say: the order of start and end | 
|---|
| 2829 | *              _is_ preserved in Windows.  (i.e. start can be > end) | 
|---|
| 2830 | *              In other words: this handler is OK | 
|---|
| 2831 | * | 
|---|
| 2832 | */ | 
|---|
| 2833 | static void EDIT_EM_SetSel(HWND hwnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap) | 
|---|
| 2834 | { | 
|---|
| 2835 | UINT old_start = es->selection_start; | 
|---|
| 2836 | UINT old_end = es->selection_end; | 
|---|
| 2837 | UINT len = lstrlenA(es->text); | 
|---|
| 2838 |  | 
|---|
| 2839 | if (start == -1) { | 
|---|
| 2840 | start = es->selection_end; | 
|---|
| 2841 | end = es->selection_end; | 
|---|
| 2842 | } else { | 
|---|
| 2843 | start = MIN(start, len); | 
|---|
| 2844 | end = MIN(end, len); | 
|---|
| 2845 | } | 
|---|
| 2846 | es->selection_start = start; | 
|---|
| 2847 | es->selection_end = end; | 
|---|
| 2848 | if (after_wrap) | 
|---|
| 2849 | es->flags |= EF_AFTER_WRAP; | 
|---|
| 2850 | else | 
|---|
| 2851 | es->flags &= ~EF_AFTER_WRAP; | 
|---|
| 2852 | if (es->flags & EF_FOCUSED) | 
|---|
| 2853 | EDIT_SetCaretPos(hwnd, es, end, after_wrap); | 
|---|
| 2854 | /* This is little  bit more efficient than before, not sure if it can be improved. FIXME? */ | 
|---|
| 2855 | ORDER_UINT(start, end); | 
|---|
| 2856 | ORDER_UINT(end, old_end); | 
|---|
| 2857 | ORDER_UINT(start, old_start); | 
|---|
| 2858 | ORDER_UINT(old_start, old_end); | 
|---|
| 2859 | if ((start == old_start) && (end == old_end)) return; | 
|---|
| 2860 | if (end != old_start) | 
|---|
| 2861 | { | 
|---|
| 2862 | /* | 
|---|
| 2863 | * One can also do | 
|---|
| 2864 | *          ORDER_UINT32(end, old_start); | 
|---|
| 2865 | *          EDIT_InvalidateText(wnd, es, start, end); | 
|---|
| 2866 | *          EDIT_InvalidateText(wnd, es, old_start, old_end); | 
|---|
| 2867 | * in place of the following if statement. | 
|---|
| 2868 | */ | 
|---|
| 2869 | if (old_start > end ) | 
|---|
| 2870 | { | 
|---|
| 2871 | EDIT_InvalidateText(hwnd, es, start, end); | 
|---|
| 2872 | EDIT_InvalidateText(hwnd, es, old_start, old_end); | 
|---|
| 2873 | } | 
|---|
| 2874 | else | 
|---|
| 2875 | { | 
|---|
| 2876 | EDIT_InvalidateText(hwnd, es, start, old_start); | 
|---|
| 2877 | EDIT_InvalidateText(hwnd, es, end, old_end); | 
|---|
| 2878 | } | 
|---|
| 2879 | } | 
|---|
| 2880 | else EDIT_InvalidateText(hwnd, es, start, old_end); | 
|---|
| 2881 | } | 
|---|
| 2882 |  | 
|---|
| 2883 |  | 
|---|
| 2884 | /********************************************************************* | 
|---|
| 2885 | * | 
|---|
| 2886 | *      EM_SETTABSTOPS | 
|---|
| 2887 | * | 
|---|
| 2888 | */ | 
|---|
| 2889 | static BOOL EDIT_EM_SetTabStops(HWND hwnd, EDITSTATE *es, INT count, LPINT tabs) | 
|---|
| 2890 | { | 
|---|
| 2891 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 2892 | return FALSE; | 
|---|
| 2893 | if (es->tabs) | 
|---|
| 2894 | HeapFree(es->heap, 0, es->tabs); | 
|---|
| 2895 | es->tabs_count = count; | 
|---|
| 2896 | if (!count) | 
|---|
| 2897 | es->tabs = NULL; | 
|---|
| 2898 | else { | 
|---|
| 2899 | es->tabs = (INT*)HeapAlloc(es->heap, 0, count * sizeof(INT)); | 
|---|
| 2900 | memcpy(es->tabs, tabs, count * sizeof(INT)); | 
|---|
| 2901 | } | 
|---|
| 2902 | return TRUE; | 
|---|
| 2903 | } | 
|---|
| 2904 |  | 
|---|
| 2905 |  | 
|---|
| 2906 | /********************************************************************* | 
|---|
| 2907 | * | 
|---|
| 2908 | *      EM_SETWORDBREAKPROC | 
|---|
| 2909 | * | 
|---|
| 2910 | */ | 
|---|
| 2911 | static void EDIT_EM_SetWordBreakProc(HWND hwnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp) | 
|---|
| 2912 | { | 
|---|
| 2913 | if (es->word_break_procA == wbp) | 
|---|
| 2914 | return; | 
|---|
| 2915 |  | 
|---|
| 2916 | es->word_break_procA = wbp; | 
|---|
| 2917 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { | 
|---|
| 2918 | EDIT_BuildLineDefs_ML(hwnd,es); | 
|---|
| 2919 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 2920 | } | 
|---|
| 2921 | } | 
|---|
| 2922 |  | 
|---|
| 2923 |  | 
|---|
| 2924 | /********************************************************************* | 
|---|
| 2925 | * | 
|---|
| 2926 | *      EM_UNDO / WM_UNDO | 
|---|
| 2927 | * | 
|---|
| 2928 | */ | 
|---|
| 2929 | static BOOL EDIT_EM_Undo(HWND hwnd, EDITSTATE *es) | 
|---|
| 2930 | { | 
|---|
| 2931 | INT ulength = lstrlenA(es->undo_text); | 
|---|
| 2932 | LPSTR utext = (LPSTR)HeapAlloc(es->heap, 0, ulength + 1); | 
|---|
| 2933 |  | 
|---|
| 2934 | lstrcpyA(utext, es->undo_text); | 
|---|
| 2935 |  | 
|---|
| 2936 | //TRACE_(edit)("before UNDO:insertion length = %d, deletion buffer = %s\n", | 
|---|
| 2937 | //             es->undo_insert_count, utext); | 
|---|
| 2938 |  | 
|---|
| 2939 | EDIT_EM_SetSel(hwnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); | 
|---|
| 2940 | EDIT_EM_EmptyUndoBuffer(hwnd, es); | 
|---|
| 2941 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, utext); | 
|---|
| 2942 | EDIT_EM_SetSel(hwnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); | 
|---|
| 2943 | HeapFree(es->heap, 0, utext); | 
|---|
| 2944 |  | 
|---|
| 2945 | //TRACE_(edit)("after UNDO:insertion length = %d, deletion buffer = %s\n", | 
|---|
| 2946 | //                es->undo_insert_count, es->undo_text); | 
|---|
| 2947 |  | 
|---|
| 2948 | if (es->flags & EF_UPDATE) { | 
|---|
| 2949 | es->flags &= ~EF_UPDATE; | 
|---|
| 2950 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 2951 | } | 
|---|
| 2952 |  | 
|---|
| 2953 | return TRUE; | 
|---|
| 2954 | } | 
|---|
| 2955 |  | 
|---|
| 2956 | static LRESULT EDIT_EM_SetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam) | 
|---|
| 2957 | { | 
|---|
| 2958 | if (wParam == EMSIS_COMPOSITIONSTRING) | 
|---|
| 2959 | { | 
|---|
| 2960 | //CB: todo | 
|---|
| 2961 | } | 
|---|
| 2962 |  | 
|---|
| 2963 | return 0; | 
|---|
| 2964 | } | 
|---|
| 2965 |  | 
|---|
| 2966 | static LRESULT EDIT_EM_GetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam) | 
|---|
| 2967 | { | 
|---|
| 2968 | //CB: todo | 
|---|
| 2969 |  | 
|---|
| 2970 | return 0; //default | 
|---|
| 2971 | } | 
|---|
| 2972 |  | 
|---|
| 2973 | /********************************************************************* | 
|---|
| 2974 | * | 
|---|
| 2975 | *      WM_CHAR | 
|---|
| 2976 | * | 
|---|
| 2977 | */ | 
|---|
| 2978 | static void EDIT_WM_Char(HWND hwnd, EDITSTATE *es, CHAR c, DWORD key_data) | 
|---|
| 2979 | { | 
|---|
| 2980 | BOOL control = GetKeyState(VK_CONTROL) & 0x8000; | 
|---|
| 2981 | switch (c) { | 
|---|
| 2982 | case '\r': | 
|---|
| 2983 | /* If the edit doesn't want the return and it's not a multiline edit, do nothing */ | 
|---|
| 2984 | if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN)) | 
|---|
| 2985 | { | 
|---|
| 2986 | MessageBeep(MB_ICONEXCLAMATION); | 
|---|
| 2987 | break; | 
|---|
| 2988 | } | 
|---|
| 2989 | case '\n': | 
|---|
| 2990 | if (es->style & ES_MULTILINE) { | 
|---|
| 2991 | if (es->style & ES_READONLY) { | 
|---|
| 2992 | EDIT_MoveHome(hwnd, es, FALSE); | 
|---|
| 2993 | EDIT_MoveDown_ML(hwnd, es, FALSE); | 
|---|
| 2994 | } else | 
|---|
| 2995 | { | 
|---|
| 2996 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, "\r\n"); | 
|---|
| 2997 | if (es->flags & EF_UPDATE) { | 
|---|
| 2998 | es->flags &= ~EF_UPDATE; | 
|---|
| 2999 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 3000 | } | 
|---|
| 3001 | } | 
|---|
| 3002 | } | 
|---|
| 3003 | break; | 
|---|
| 3004 | case '\t': | 
|---|
| 3005 | if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) | 
|---|
| 3006 | { | 
|---|
| 3007 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, "\t"); | 
|---|
| 3008 | if (es->flags & EF_UPDATE) { | 
|---|
| 3009 | es->flags &= ~EF_UPDATE; | 
|---|
| 3010 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 3011 | } | 
|---|
| 3012 | } | 
|---|
| 3013 | break; | 
|---|
| 3014 | case VK_BACK: | 
|---|
| 3015 | if (!(es->style & ES_READONLY) && !control) { | 
|---|
| 3016 | if (es->selection_start != es->selection_end) | 
|---|
| 3017 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3018 | else { | 
|---|
| 3019 | /* delete character left of caret */ | 
|---|
| 3020 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE); | 
|---|
| 3021 | EDIT_MoveBackward(hwnd, es, TRUE); | 
|---|
| 3022 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3023 | } | 
|---|
| 3024 | } | 
|---|
| 3025 | break; | 
|---|
| 3026 | //CB: are these three keys documented or Linux style??? | 
|---|
| 3027 | case 0x03: /* ^C */ | 
|---|
| 3028 | SendMessageA(hwnd, WM_COPY, 0, 0); | 
|---|
| 3029 | break; | 
|---|
| 3030 | case 0x16: /* ^V */ | 
|---|
| 3031 | SendMessageA(hwnd, WM_PASTE, 0, 0); | 
|---|
| 3032 | break; | 
|---|
| 3033 | case 0x18: /* ^X */ | 
|---|
| 3034 | SendMessageA(hwnd, WM_CUT, 0, 0); | 
|---|
| 3035 | break; | 
|---|
| 3036 |  | 
|---|
| 3037 | default: | 
|---|
| 3038 | if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) | 
|---|
| 3039 | { | 
|---|
| 3040 | char str[2]; | 
|---|
| 3041 |  | 
|---|
| 3042 | if (es->style & ES_NUMBER) | 
|---|
| 3043 | { | 
|---|
| 3044 | if (((BYTE)c < '0') || ((BYTE)c > '9')) { | 
|---|
| 3045 | MessageBeep(MB_ICONEXCLAMATION); | 
|---|
| 3046 | return; | 
|---|
| 3047 | } | 
|---|
| 3048 | } | 
|---|
| 3049 | str[0] = c; | 
|---|
| 3050 | str[1] = '\0'; | 
|---|
| 3051 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, str); | 
|---|
| 3052 | if (es->flags & EF_UPDATE) | 
|---|
| 3053 | { | 
|---|
| 3054 | es->flags &= ~EF_UPDATE; | 
|---|
| 3055 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 3056 | } | 
|---|
| 3057 | } else MessageBeep(MB_ICONEXCLAMATION); | 
|---|
| 3058 | break; | 
|---|
| 3059 | } | 
|---|
| 3060 | } | 
|---|
| 3061 |  | 
|---|
| 3062 |  | 
|---|
| 3063 | /********************************************************************* | 
|---|
| 3064 | * | 
|---|
| 3065 | *      WM_COMMAND | 
|---|
| 3066 | * | 
|---|
| 3067 | */ | 
|---|
| 3068 | static void EDIT_WM_Command(HWND hwnd, EDITSTATE *es, INT code, INT id, HWND control) | 
|---|
| 3069 | { | 
|---|
| 3070 | if (code || control) | 
|---|
| 3071 | return; | 
|---|
| 3072 |  | 
|---|
| 3073 | switch (id) { | 
|---|
| 3074 | case EM_UNDO: | 
|---|
| 3075 | EDIT_EM_Undo(hwnd, es); | 
|---|
| 3076 | break; | 
|---|
| 3077 | case WM_CUT: | 
|---|
| 3078 | EDIT_WM_Cut(hwnd, es); | 
|---|
| 3079 | break; | 
|---|
| 3080 | case WM_COPY: | 
|---|
| 3081 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 3082 | break; | 
|---|
| 3083 | case WM_PASTE: | 
|---|
| 3084 | EDIT_WM_Paste(hwnd, es); | 
|---|
| 3085 | break; | 
|---|
| 3086 | case WM_CLEAR: | 
|---|
| 3087 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3088 | break; | 
|---|
| 3089 | case EM_SETSEL: | 
|---|
| 3090 | EDIT_EM_SetSel(hwnd, es, 0, -1, FALSE); | 
|---|
| 3091 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3092 | break; | 
|---|
| 3093 | default: | 
|---|
| 3094 | //ERR_(edit)("unknown menu item, please report\n"); | 
|---|
| 3095 | break; | 
|---|
| 3096 | } | 
|---|
| 3097 | } | 
|---|
| 3098 |  | 
|---|
| 3099 |  | 
|---|
| 3100 | /********************************************************************* | 
|---|
| 3101 | * | 
|---|
| 3102 | *      WM_CONTEXTMENU | 
|---|
| 3103 | * | 
|---|
| 3104 | *      Note: the resource files resource/sysres_??.rc cannot define a | 
|---|
| 3105 | *              single popup menu.  Hence we use a (dummy) menubar | 
|---|
| 3106 | *              containing the single popup menu as its first item. | 
|---|
| 3107 | * | 
|---|
| 3108 | *      FIXME: the message identifiers have been chosen arbitrarily, | 
|---|
| 3109 | *              hence we use MF_BYPOSITION. | 
|---|
| 3110 | *              We might as well use the "real" values (anybody knows ?) | 
|---|
| 3111 | *              The menu definition is in resources/sysres_??.rc. | 
|---|
| 3112 | *              Once these are OK, we better use MF_BYCOMMAND here | 
|---|
| 3113 | *              (as we do in EDIT_WM_Command()). | 
|---|
| 3114 | * | 
|---|
| 3115 | */ | 
|---|
| 3116 | static void EDIT_WM_ContextMenu(HWND hwnd, EDITSTATE *es, HWND hwndBtn, INT x, INT y) | 
|---|
| 3117 | { | 
|---|
| 3118 | HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU"); | 
|---|
| 3119 | HMENU popup = GetSubMenu(menu, 0); | 
|---|
| 3120 | UINT start = es->selection_start; | 
|---|
| 3121 | UINT end = es->selection_end; | 
|---|
| 3122 |  | 
|---|
| 3123 | ORDER_UINT(start, end); | 
|---|
| 3124 |  | 
|---|
| 3125 | /* undo */ | 
|---|
| 3126 | EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(hwnd, es) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 3127 | /* cut */ | 
|---|
| 3128 | EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & (ES_PASSWORD | ES_READONLY)) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 3129 | /* copy */ | 
|---|
| 3130 | EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 3131 | /* paste */ | 
|---|
| 3132 | EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_TEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 3133 | /* delete */ | 
|---|
| 3134 | EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 3135 | /* select all */ | 
|---|
| 3136 | EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != lstrlenA(es->text)) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 3137 |  | 
|---|
| 3138 | TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, hwnd, NULL); | 
|---|
| 3139 | DestroyMenu(menu); | 
|---|
| 3140 | } | 
|---|
| 3141 |  | 
|---|
| 3142 |  | 
|---|
| 3143 | /********************************************************************* | 
|---|
| 3144 | * | 
|---|
| 3145 | *      WM_COPY | 
|---|
| 3146 | * | 
|---|
| 3147 | */ | 
|---|
| 3148 | static void EDIT_WM_Copy(HWND hwnd, EDITSTATE *es) | 
|---|
| 3149 | { | 
|---|
| 3150 | INT s = es->selection_start; | 
|---|
| 3151 | INT e = es->selection_end; | 
|---|
| 3152 | HGLOBAL hdst; | 
|---|
| 3153 | LPSTR dst; | 
|---|
| 3154 |  | 
|---|
| 3155 | if (e == s) | 
|---|
| 3156 | return; | 
|---|
| 3157 | ORDER_INT(s, e); | 
|---|
| 3158 | hdst = GlobalAlloc(GMEM_MOVEABLE, (DWORD)(e - s + 1)); | 
|---|
| 3159 | dst = (LPSTR)GlobalLock(hdst); | 
|---|
| 3160 | lstrcpynA(dst, es->text + s, e - s + 1); | 
|---|
| 3161 | GlobalUnlock(hdst); | 
|---|
| 3162 | OpenClipboard(hwnd); | 
|---|
| 3163 | EmptyClipboard(); | 
|---|
| 3164 | SetClipboardData(CF_TEXT, hdst); | 
|---|
| 3165 | CloseClipboard(); | 
|---|
| 3166 | } | 
|---|
| 3167 |  | 
|---|
| 3168 |  | 
|---|
| 3169 | /********************************************************************* | 
|---|
| 3170 | * | 
|---|
| 3171 | *      WM_CREATE | 
|---|
| 3172 | * | 
|---|
| 3173 | */ | 
|---|
| 3174 | static LRESULT EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCREATESTRUCTA cs) | 
|---|
| 3175 | { | 
|---|
| 3176 | /* | 
|---|
| 3177 | *       To initialize some final structure members, we call some helper | 
|---|
| 3178 | *       functions.  However, since the EDITSTATE is not consistent (i.e. | 
|---|
| 3179 | *       not fully initialized), we should be very careful which | 
|---|
| 3180 | *       functions can be called, and in what order. | 
|---|
| 3181 | */ | 
|---|
| 3182 | EDIT_WM_SetFont(hwnd, es, 0, FALSE); | 
|---|
| 3183 | EDIT_EM_EmptyUndoBuffer(hwnd, es); | 
|---|
| 3184 | if (cs->lpszName && *(cs->lpszName) != '\0') { | 
|---|
| 3185 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, cs->lpszName); | 
|---|
| 3186 | /* if we insert text to the editline, the text scrolls out | 
|---|
| 3187 | * of the window, as the caret is placed after the insert | 
|---|
| 3188 | * pos normally; thus we reset es->selection... to 0 and | 
|---|
| 3189 | * update caret | 
|---|
| 3190 | */ | 
|---|
| 3191 | es->selection_start = es->selection_end = 0; | 
|---|
| 3192 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3193 | if (es->flags & EF_UPDATE) { | 
|---|
| 3194 | es->flags &= ~EF_UPDATE; | 
|---|
| 3195 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 3196 | } | 
|---|
| 3197 | } | 
|---|
| 3198 | return 0; | 
|---|
| 3199 | } | 
|---|
| 3200 |  | 
|---|
| 3201 |  | 
|---|
| 3202 | /********************************************************************* | 
|---|
| 3203 | * | 
|---|
| 3204 | *      WM_DESTROY | 
|---|
| 3205 | * | 
|---|
| 3206 | */ | 
|---|
| 3207 | static void EDIT_WM_Destroy(HWND hwnd, EDITSTATE *es) | 
|---|
| 3208 | { | 
|---|
| 3209 | if (!es) /* Protect against multiple destroy messages */ | 
|---|
| 3210 | return; | 
|---|
| 3211 |  | 
|---|
| 3212 | if (es->hloc) { | 
|---|
| 3213 | while (LocalUnlock(es->hloc)) ; | 
|---|
| 3214 | LocalFree(es->hloc); | 
|---|
| 3215 | } | 
|---|
| 3216 |  | 
|---|
| 3217 | HeapDestroy(es->heap); | 
|---|
| 3218 | HeapFree(GetProcessHeap(), 0, es); | 
|---|
| 3219 | SetInfoPtr(hwnd,0); | 
|---|
| 3220 | } | 
|---|
| 3221 |  | 
|---|
| 3222 |  | 
|---|
| 3223 | /********************************************************************* | 
|---|
| 3224 | * | 
|---|
| 3225 | *      WM_ERASEBKGND | 
|---|
| 3226 | * | 
|---|
| 3227 | */ | 
|---|
| 3228 | static LRESULT EDIT_WM_EraseBkGnd(HWND hwnd, EDITSTATE *es, HDC dc) | 
|---|
| 3229 | { | 
|---|
| 3230 | HBRUSH brush; | 
|---|
| 3231 | RECT rc; | 
|---|
| 3232 |  | 
|---|
| 3233 | HideCaret(hwnd); | 
|---|
| 3234 |  | 
|---|
| 3235 | if (!es->bEnableState || (es->style & ES_READONLY)) | 
|---|
| 3236 | brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, dc); | 
|---|
| 3237 | else | 
|---|
| 3238 | brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, dc); | 
|---|
| 3239 |  | 
|---|
| 3240 | if (!brush) | 
|---|
| 3241 | brush = (HBRUSH)GetStockObject(WHITE_BRUSH); | 
|---|
| 3242 |  | 
|---|
| 3243 | GetClientRect(hwnd, &rc); | 
|---|
| 3244 | IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 3245 | GetClipBox(dc, &rc); | 
|---|
| 3246 | /* | 
|---|
| 3247 | *      FIXME:  specs say that we should UnrealizeObject() the brush, | 
|---|
| 3248 | *              but the specs of UnrealizeObject() say that we shouldn't | 
|---|
| 3249 | *              unrealize a stock object.  The default brush that | 
|---|
| 3250 | *              DefWndProc() returns is ... a stock object. | 
|---|
| 3251 | */ | 
|---|
| 3252 | FillRect(dc, &rc, brush); | 
|---|
| 3253 |  | 
|---|
| 3254 | ShowCaret(hwnd); | 
|---|
| 3255 |  | 
|---|
| 3256 | return -1; | 
|---|
| 3257 | } | 
|---|
| 3258 |  | 
|---|
| 3259 |  | 
|---|
| 3260 | /********************************************************************* | 
|---|
| 3261 | * | 
|---|
| 3262 | *      WM_GETTEXT | 
|---|
| 3263 | * | 
|---|
| 3264 | */ | 
|---|
| 3265 | static INT EDIT_WM_GetText(HWND hwnd, EDITSTATE *es, INT count, LPSTR text) | 
|---|
| 3266 | { | 
|---|
| 3267 | INT len; | 
|---|
| 3268 |  | 
|---|
| 3269 | if (es->text == NULL)  // the only case of failure i can imagine | 
|---|
| 3270 | return 0; | 
|---|
| 3271 |  | 
|---|
| 3272 | len = min(count, lstrlenA(es->text)+1); // determine length | 
|---|
| 3273 | lstrcpynA(text, es->text, len);       // copy as much as possible | 
|---|
| 3274 | return len; | 
|---|
| 3275 | } | 
|---|
| 3276 |  | 
|---|
| 3277 |  | 
|---|
| 3278 | /********************************************************************* | 
|---|
| 3279 | * | 
|---|
| 3280 | *      EDIT_HScroll_Hack | 
|---|
| 3281 | * | 
|---|
| 3282 | *      16 bit notepad needs this.  Actually it is not _our_ hack, | 
|---|
| 3283 | *      it is notepad's.  Notepad is sending us scrollbar messages with | 
|---|
| 3284 | *      undocumented parameters without us even having a scrollbar ... !?!? | 
|---|
| 3285 | * | 
|---|
| 3286 | */ | 
|---|
| 3287 | static LRESULT EDIT_HScroll_Hack(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) | 
|---|
| 3288 | { | 
|---|
| 3289 | INT dx = 0; | 
|---|
| 3290 | INT fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 3291 | LRESULT ret = 0; | 
|---|
| 3292 |  | 
|---|
| 3293 | if (!(es->flags & EF_HSCROLL_HACK)) { | 
|---|
| 3294 | //ERR_(edit)("hacked WM_HSCROLL handler invoked\n"); | 
|---|
| 3295 | //ERR_(edit)("      if you are _not_ running 16 bit notepad, please report\n"); | 
|---|
| 3296 | //ERR_(edit)("      (this message is only displayed once per edit control)\n"); | 
|---|
| 3297 | es->flags |= EF_HSCROLL_HACK; | 
|---|
| 3298 | } | 
|---|
| 3299 |  | 
|---|
| 3300 | switch (action) { | 
|---|
| 3301 | case SB_LINELEFT: | 
|---|
| 3302 | if (es->x_offset) | 
|---|
| 3303 | dx = -es->char_width; | 
|---|
| 3304 | break; | 
|---|
| 3305 | case SB_LINERIGHT: | 
|---|
| 3306 | if (es->x_offset < es->text_width) | 
|---|
| 3307 | dx = es->char_width; | 
|---|
| 3308 | break; | 
|---|
| 3309 | case SB_PAGELEFT: | 
|---|
| 3310 | if (es->x_offset) | 
|---|
| 3311 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; | 
|---|
| 3312 | break; | 
|---|
| 3313 | case SB_PAGERIGHT: | 
|---|
| 3314 | if (es->x_offset < es->text_width) | 
|---|
| 3315 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; | 
|---|
| 3316 | break; | 
|---|
| 3317 | case SB_LEFT: | 
|---|
| 3318 | if (es->x_offset) | 
|---|
| 3319 | dx = -es->x_offset; | 
|---|
| 3320 | break; | 
|---|
| 3321 | case SB_RIGHT: | 
|---|
| 3322 | if (es->x_offset < es->text_width) | 
|---|
| 3323 | dx = es->text_width - es->x_offset; | 
|---|
| 3324 | break; | 
|---|
| 3325 | case SB_THUMBTRACK: | 
|---|
| 3326 | es->flags |= EF_HSCROLL_TRACK; | 
|---|
| 3327 | dx = pos * es->text_width / 100 - es->x_offset; | 
|---|
| 3328 | break; | 
|---|
| 3329 | case SB_THUMBPOSITION: | 
|---|
| 3330 | es->flags &= ~EF_HSCROLL_TRACK; | 
|---|
| 3331 | if (!(dx = pos * es->text_width / 100 - es->x_offset)) | 
|---|
| 3332 | EDIT_NOTIFY_PARENT(hwnd, EN_HSCROLL); | 
|---|
| 3333 | break; | 
|---|
| 3334 | case SB_ENDSCROLL: | 
|---|
| 3335 | break; | 
|---|
| 3336 |  | 
|---|
| 3337 | default: | 
|---|
| 3338 | //ERR_(edit)("undocumented (hacked) WM_HSCROLL parameter, please report\n"); | 
|---|
| 3339 | return 0; | 
|---|
| 3340 | } | 
|---|
| 3341 | if (dx) | 
|---|
| 3342 | EDIT_EM_LineScroll(hwnd, es, dx, 0); | 
|---|
| 3343 | return ret; | 
|---|
| 3344 | } | 
|---|
| 3345 |  | 
|---|
| 3346 |  | 
|---|
| 3347 | /********************************************************************* | 
|---|
| 3348 | * | 
|---|
| 3349 | *      WM_HSCROLL | 
|---|
| 3350 | * | 
|---|
| 3351 | */ | 
|---|
| 3352 | static LRESULT EDIT_WM_HScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) | 
|---|
| 3353 | { | 
|---|
| 3354 | INT dx; | 
|---|
| 3355 | INT fw; | 
|---|
| 3356 |  | 
|---|
| 3357 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3358 | return 0; | 
|---|
| 3359 |  | 
|---|
| 3360 | if (!(es->style & ES_AUTOHSCROLL)) | 
|---|
| 3361 | return 0; | 
|---|
| 3362 |  | 
|---|
| 3363 | if (!(es->style & WS_HSCROLL)) | 
|---|
| 3364 | return EDIT_HScroll_Hack(hwnd, es, action, pos, scroll_bar); | 
|---|
| 3365 |  | 
|---|
| 3366 | dx = 0; | 
|---|
| 3367 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 3368 | switch (action) { | 
|---|
| 3369 | case SB_LINELEFT: | 
|---|
| 3370 | if (es->x_offset) | 
|---|
| 3371 | dx = -es->char_width; | 
|---|
| 3372 | break; | 
|---|
| 3373 | case SB_LINERIGHT: | 
|---|
| 3374 | if (es->x_offset < es->text_width) | 
|---|
| 3375 | dx = es->char_width; | 
|---|
| 3376 | break; | 
|---|
| 3377 | case SB_PAGELEFT: | 
|---|
| 3378 | if (es->x_offset) | 
|---|
| 3379 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; | 
|---|
| 3380 | break; | 
|---|
| 3381 | case SB_PAGERIGHT: | 
|---|
| 3382 | if (es->x_offset < es->text_width) | 
|---|
| 3383 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; | 
|---|
| 3384 | break; | 
|---|
| 3385 | case SB_LEFT: | 
|---|
| 3386 | if (es->x_offset) | 
|---|
| 3387 | dx = -es->x_offset; | 
|---|
| 3388 | break; | 
|---|
| 3389 | case SB_RIGHT: | 
|---|
| 3390 | if (es->x_offset < es->text_width) | 
|---|
| 3391 | dx = es->text_width - es->x_offset; | 
|---|
| 3392 | break; | 
|---|
| 3393 | case SB_THUMBTRACK: | 
|---|
| 3394 | es->flags |= EF_HSCROLL_TRACK; | 
|---|
| 3395 | dx = pos - es->x_offset; | 
|---|
| 3396 | break; | 
|---|
| 3397 | case SB_THUMBPOSITION: | 
|---|
| 3398 | es->flags &= ~EF_HSCROLL_TRACK; | 
|---|
| 3399 | if (!(dx = pos - es->x_offset)) { | 
|---|
| 3400 | SetScrollPos(hwnd, SB_HORZ, pos, TRUE); | 
|---|
| 3401 | EDIT_NOTIFY_PARENT(hwnd, EN_HSCROLL); | 
|---|
| 3402 | } | 
|---|
| 3403 | break; | 
|---|
| 3404 | case SB_ENDSCROLL: | 
|---|
| 3405 | break; | 
|---|
| 3406 |  | 
|---|
| 3407 | default: | 
|---|
| 3408 | //ERR_(edit)("undocumented WM_HSCROLL parameter, please report\n"); | 
|---|
| 3409 | return 0; | 
|---|
| 3410 | } | 
|---|
| 3411 | if (dx) | 
|---|
| 3412 | EDIT_EM_LineScroll(hwnd, es, dx, 0); | 
|---|
| 3413 | return 0; | 
|---|
| 3414 | } | 
|---|
| 3415 |  | 
|---|
| 3416 |  | 
|---|
| 3417 | /********************************************************************* | 
|---|
| 3418 | * | 
|---|
| 3419 | *      EDIT_CheckCombo | 
|---|
| 3420 | * | 
|---|
| 3421 | */ | 
|---|
| 3422 | static BOOL EDIT_CheckCombo(HWND hwnd, EDITSTATE *es, UINT msg, INT key, DWORD key_data) | 
|---|
| 3423 | { | 
|---|
| 3424 | HWND hLBox = es->hwndListBox; | 
|---|
| 3425 | HWND hCombo; | 
|---|
| 3426 | BOOL bDropped; | 
|---|
| 3427 | int  nEUI; | 
|---|
| 3428 |  | 
|---|
| 3429 | if (!hLBox) | 
|---|
| 3430 | return FALSE; | 
|---|
| 3431 |  | 
|---|
| 3432 | hCombo   = GetParent(hwnd); | 
|---|
| 3433 | bDropped = TRUE; | 
|---|
| 3434 | nEUI     = 0; | 
|---|
| 3435 |  | 
|---|
| 3436 | //TRACE_(combo)("[%04x]: handling msg %04x (%04x)\n", | 
|---|
| 3437 | //                        wnd->hwndSelf, (UINT16)msg, (UINT16)key); | 
|---|
| 3438 |  | 
|---|
| 3439 | if (key == VK_UP || key == VK_DOWN) | 
|---|
| 3440 | { | 
|---|
| 3441 | if (SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0)) | 
|---|
| 3442 | nEUI = 1; | 
|---|
| 3443 |  | 
|---|
| 3444 | if (msg == WM_KEYDOWN || nEUI) | 
|---|
| 3445 | bDropped = (BOOL)SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0); | 
|---|
| 3446 | } | 
|---|
| 3447 |  | 
|---|
| 3448 | switch (msg) | 
|---|
| 3449 | { | 
|---|
| 3450 | case WM_KEYDOWN: | 
|---|
| 3451 | if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN)) | 
|---|
| 3452 | { | 
|---|
| 3453 | /* make sure ComboLBox pops up */ | 
|---|
| 3454 | SendMessageA(hCombo, CB_SETEXTENDEDUI, FALSE, 0); | 
|---|
| 3455 | key = VK_F4; | 
|---|
| 3456 | nEUI = 2; | 
|---|
| 3457 | } | 
|---|
| 3458 |  | 
|---|
| 3459 | SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)key, 0); | 
|---|
| 3460 | break; | 
|---|
| 3461 |  | 
|---|
| 3462 | case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */ | 
|---|
| 3463 | if (nEUI) | 
|---|
| 3464 | SendMessageA(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0); | 
|---|
| 3465 | else | 
|---|
| 3466 | SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0); | 
|---|
| 3467 | break; | 
|---|
| 3468 | } | 
|---|
| 3469 |  | 
|---|
| 3470 | if(nEUI == 2) | 
|---|
| 3471 | SendMessageA(hCombo, CB_SETEXTENDEDUI, TRUE, 0); | 
|---|
| 3472 |  | 
|---|
| 3473 | return TRUE; | 
|---|
| 3474 | } | 
|---|
| 3475 |  | 
|---|
| 3476 | /********************************************************************* | 
|---|
| 3477 | * | 
|---|
| 3478 | *      WM_KEYDOWN | 
|---|
| 3479 | * | 
|---|
| 3480 | *      Handling of special keys that don't produce a WM_CHAR | 
|---|
| 3481 | *      (i.e. non-printable keys) & Backspace & Delete | 
|---|
| 3482 | * | 
|---|
| 3483 | */ | 
|---|
| 3484 | static LRESULT EDIT_WM_KeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data) | 
|---|
| 3485 | { | 
|---|
| 3486 | BOOL shift; | 
|---|
| 3487 | BOOL control; | 
|---|
| 3488 |  | 
|---|
| 3489 | if (GetKeyState(VK_MENU) & 0x8000) | 
|---|
| 3490 | return 0; | 
|---|
| 3491 |  | 
|---|
| 3492 | shift = GetKeyState(VK_SHIFT) & 0x8000; | 
|---|
| 3493 | control = GetKeyState(VK_CONTROL) & 0x8000; | 
|---|
| 3494 |  | 
|---|
| 3495 | switch (key) { | 
|---|
| 3496 | case VK_F4: | 
|---|
| 3497 | case VK_UP: | 
|---|
| 3498 | if (EDIT_CheckCombo(hwnd,es, WM_KEYDOWN, key, key_data) || key == VK_F4) | 
|---|
| 3499 | break; | 
|---|
| 3500 | /* fall through */ | 
|---|
| 3501 | case VK_LEFT: | 
|---|
| 3502 | if ((es->style & ES_MULTILINE) && (key == VK_UP)) | 
|---|
| 3503 | EDIT_MoveUp_ML(hwnd, es, shift); | 
|---|
| 3504 | else | 
|---|
| 3505 | if (control) | 
|---|
| 3506 | EDIT_MoveWordBackward(hwnd, es, shift); | 
|---|
| 3507 | else | 
|---|
| 3508 | EDIT_MoveBackward(hwnd, es, shift); | 
|---|
| 3509 | break; | 
|---|
| 3510 | case VK_DOWN: | 
|---|
| 3511 | if (EDIT_CheckCombo(hwnd,es, WM_KEYDOWN, key, key_data)) | 
|---|
| 3512 | break; | 
|---|
| 3513 | /* fall through */ | 
|---|
| 3514 | case VK_RIGHT: | 
|---|
| 3515 | if ((es->style & ES_MULTILINE) && (key == VK_DOWN)) | 
|---|
| 3516 | EDIT_MoveDown_ML(hwnd, es, shift); | 
|---|
| 3517 | else if (control) | 
|---|
| 3518 | EDIT_MoveWordForward(hwnd, es, shift); | 
|---|
| 3519 | else | 
|---|
| 3520 | EDIT_MoveForward(hwnd, es, shift); | 
|---|
| 3521 | break; | 
|---|
| 3522 | case VK_HOME: | 
|---|
| 3523 | EDIT_MoveHome(hwnd, es, shift); | 
|---|
| 3524 | break; | 
|---|
| 3525 | case VK_END: | 
|---|
| 3526 | EDIT_MoveEnd(hwnd, es, shift); | 
|---|
| 3527 | break; | 
|---|
| 3528 | case VK_PRIOR: | 
|---|
| 3529 | if (es->style & ES_MULTILINE) | 
|---|
| 3530 | EDIT_MovePageUp_ML(hwnd, es, shift); | 
|---|
| 3531 | else | 
|---|
| 3532 | EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key, key_data); | 
|---|
| 3533 | break; | 
|---|
| 3534 | case VK_NEXT: | 
|---|
| 3535 | if (es->style & ES_MULTILINE) | 
|---|
| 3536 | EDIT_MovePageDown_ML(hwnd, es, shift); | 
|---|
| 3537 | else | 
|---|
| 3538 | EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key, key_data); | 
|---|
| 3539 | break; | 
|---|
| 3540 | case VK_DELETE: | 
|---|
| 3541 | if (!(es->style & ES_READONLY) && !(shift && control)) { | 
|---|
| 3542 | if (es->selection_start != es->selection_end) { | 
|---|
| 3543 | if (shift) | 
|---|
| 3544 | EDIT_WM_Cut(hwnd, es); | 
|---|
| 3545 | else | 
|---|
| 3546 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3547 | } else { | 
|---|
| 3548 | if (shift) { | 
|---|
| 3549 | /* delete character left of caret */ | 
|---|
| 3550 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE); | 
|---|
| 3551 | EDIT_MoveBackward(hwnd, es, TRUE); | 
|---|
| 3552 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3553 | } else if (control) { | 
|---|
| 3554 | /* delete to end of line */ | 
|---|
| 3555 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE); | 
|---|
| 3556 | EDIT_MoveEnd(hwnd, es, TRUE); | 
|---|
| 3557 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3558 | } else { | 
|---|
| 3559 | /* delete character right of caret */ | 
|---|
| 3560 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE); | 
|---|
| 3561 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 3562 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 3563 | } | 
|---|
| 3564 | } | 
|---|
| 3565 | } | 
|---|
| 3566 | break; | 
|---|
| 3567 | case VK_INSERT: | 
|---|
| 3568 | if (shift) { | 
|---|
| 3569 | if (!(es->style & ES_READONLY)) | 
|---|
| 3570 | EDIT_WM_Paste(hwnd, es); | 
|---|
| 3571 | } else if (control) | 
|---|
| 3572 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 3573 | break; | 
|---|
| 3574 | case VK_RETURN: | 
|---|
| 3575 | /* If the edit doesn't want the return send a message to the default object */ | 
|---|
| 3576 | if(!(es->style & ES_WANTRETURN)) | 
|---|
| 3577 | { | 
|---|
| 3578 | HWND hwndParent = GetParent(hwnd); | 
|---|
| 3579 | DWORD dw = SendMessageA( hwndParent, DM_GETDEFID, 0, 0 ); | 
|---|
| 3580 | if (HIWORD(dw) == DC_HASDEFID) | 
|---|
| 3581 | { | 
|---|
| 3582 | SendMessageA( hwndParent, WM_COMMAND, | 
|---|
| 3583 | MAKEWPARAM( LOWORD(dw), BN_CLICKED ), | 
|---|
| 3584 | (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) ); | 
|---|
| 3585 | } | 
|---|
| 3586 | } | 
|---|
| 3587 | break; | 
|---|
| 3588 | } | 
|---|
| 3589 | return 0; | 
|---|
| 3590 | } | 
|---|
| 3591 |  | 
|---|
| 3592 |  | 
|---|
| 3593 | /********************************************************************* | 
|---|
| 3594 | * | 
|---|
| 3595 | *      WM_KILLFOCUS | 
|---|
| 3596 | * | 
|---|
| 3597 | */ | 
|---|
| 3598 | static LRESULT EDIT_WM_KillFocus(HWND hwnd, EDITSTATE *es, HWND window_getting_focus) | 
|---|
| 3599 | { | 
|---|
| 3600 | es->flags &= ~EF_FOCUSED; | 
|---|
| 3601 | DestroyCaret(); | 
|---|
| 3602 | if(!(es->style & ES_NOHIDESEL)) | 
|---|
| 3603 | EDIT_InvalidateText(hwnd, es, es->selection_start, es->selection_end); | 
|---|
| 3604 | EDIT_NOTIFY_PARENT(hwnd, EN_KILLFOCUS); | 
|---|
| 3605 | return 0; | 
|---|
| 3606 | } | 
|---|
| 3607 |  | 
|---|
| 3608 |  | 
|---|
| 3609 | /********************************************************************* | 
|---|
| 3610 | * | 
|---|
| 3611 | *      WM_LBUTTONDBLCLK | 
|---|
| 3612 | * | 
|---|
| 3613 | *      The caret position has been set on the WM_LBUTTONDOWN message | 
|---|
| 3614 | * | 
|---|
| 3615 | */ | 
|---|
| 3616 | static LRESULT EDIT_WM_LButtonDblClk(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y) | 
|---|
| 3617 | { | 
|---|
| 3618 | INT s; | 
|---|
| 3619 | INT e = es->selection_end; | 
|---|
| 3620 | INT l; | 
|---|
| 3621 | INT li; | 
|---|
| 3622 | INT ll; | 
|---|
| 3623 |  | 
|---|
| 3624 | if (!(es->flags & EF_FOCUSED)) | 
|---|
| 3625 | return 0; | 
|---|
| 3626 |  | 
|---|
| 3627 | l = EDIT_EM_LineFromChar(hwnd, es, e); | 
|---|
| 3628 | li = EDIT_EM_LineIndex(hwnd, es, l); | 
|---|
| 3629 | ll = EDIT_EM_LineLength(hwnd, es, e); | 
|---|
| 3630 | s = li + EDIT_CallWordBreakProc (hwnd, es, li, e - li, ll, WB_LEFT); | 
|---|
| 3631 | e = li + EDIT_CallWordBreakProc(hwnd, es, li, e - li, ll, WB_RIGHT); | 
|---|
| 3632 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE); | 
|---|
| 3633 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3634 | return 0; | 
|---|
| 3635 | } | 
|---|
| 3636 |  | 
|---|
| 3637 |  | 
|---|
| 3638 | /********************************************************************* | 
|---|
| 3639 | * | 
|---|
| 3640 | *      WM_LBUTTONDOWN | 
|---|
| 3641 | * | 
|---|
| 3642 | */ | 
|---|
| 3643 | static LRESULT EDIT_WM_LButtonDown(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y) | 
|---|
| 3644 | { | 
|---|
| 3645 | INT e; | 
|---|
| 3646 | BOOL after_wrap; | 
|---|
| 3647 |  | 
|---|
| 3648 | if (!(es->flags & EF_FOCUSED)) | 
|---|
| 3649 | SetFocus(hwnd); | 
|---|
| 3650 |  | 
|---|
| 3651 | es->bCaptureState = TRUE; | 
|---|
| 3652 | SetCapture(hwnd); | 
|---|
| 3653 | EDIT_ConfinePoint(hwnd, es, &x, &y); | 
|---|
| 3654 | e = EDIT_CharFromPos(hwnd, es, x, y, &after_wrap); | 
|---|
| 3655 | EDIT_EM_SetSel(hwnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap); | 
|---|
| 3656 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3657 | es->region_posx = es->region_posy = 0; | 
|---|
| 3658 | SetTimer(hwnd, 0, 100, NULL); | 
|---|
| 3659 | return 0; | 
|---|
| 3660 | } | 
|---|
| 3661 |  | 
|---|
| 3662 |  | 
|---|
| 3663 | /********************************************************************* | 
|---|
| 3664 | * | 
|---|
| 3665 | *      WM_LBUTTONUP | 
|---|
| 3666 | * | 
|---|
| 3667 | */ | 
|---|
| 3668 | static LRESULT EDIT_WM_LButtonUp(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y) | 
|---|
| 3669 | { | 
|---|
| 3670 | if (es->bCaptureState) | 
|---|
| 3671 | { | 
|---|
| 3672 | KillTimer(hwnd,0); | 
|---|
| 3673 | ReleaseCapture(); | 
|---|
| 3674 | } | 
|---|
| 3675 | es->bCaptureState = FALSE; | 
|---|
| 3676 |  | 
|---|
| 3677 | return 0; | 
|---|
| 3678 | } | 
|---|
| 3679 |  | 
|---|
| 3680 | static LRESULT EDIT_WM_CaptureChanged(HWND hwnd,EDITSTATE *es) | 
|---|
| 3681 | { | 
|---|
| 3682 | if (es->bCaptureState) KillTimer(hwnd,0); | 
|---|
| 3683 | es->bCaptureState = FALSE; | 
|---|
| 3684 |  | 
|---|
| 3685 | return 0; | 
|---|
| 3686 | } | 
|---|
| 3687 |  | 
|---|
| 3688 | /********************************************************************* | 
|---|
| 3689 | * | 
|---|
| 3690 | *      WM_MOUSEMOVE | 
|---|
| 3691 | * | 
|---|
| 3692 | */ | 
|---|
| 3693 | static LRESULT EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y) | 
|---|
| 3694 | { | 
|---|
| 3695 | INT e; | 
|---|
| 3696 | BOOL after_wrap; | 
|---|
| 3697 | INT prex, prey; | 
|---|
| 3698 |  | 
|---|
| 3699 | if (!es->bCaptureState) return 0; | 
|---|
| 3700 |  | 
|---|
| 3701 | /* | 
|---|
| 3702 | *      FIXME: gotta do some scrolling if outside client | 
|---|
| 3703 | *              area.  Maybe reset the timer ? | 
|---|
| 3704 | */ | 
|---|
| 3705 | prex = x; prey = y; | 
|---|
| 3706 | EDIT_ConfinePoint(hwnd, es, &x, &y); | 
|---|
| 3707 | es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0); | 
|---|
| 3708 | es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0); | 
|---|
| 3709 | e = EDIT_CharFromPos(hwnd, es, x, y, &after_wrap); | 
|---|
| 3710 | EDIT_EM_SetSel(hwnd, es, es->selection_start, e, after_wrap); | 
|---|
| 3711 |  | 
|---|
| 3712 | return 0; | 
|---|
| 3713 | } | 
|---|
| 3714 |  | 
|---|
| 3715 |  | 
|---|
| 3716 | /********************************************************************* | 
|---|
| 3717 | * | 
|---|
| 3718 | *      WM_NCCREATE | 
|---|
| 3719 | * | 
|---|
| 3720 | */ | 
|---|
| 3721 | static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTA cs) | 
|---|
| 3722 | { | 
|---|
| 3723 | EDITSTATE *es; | 
|---|
| 3724 |  | 
|---|
| 3725 | if (!(es = (EDITSTATE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es)))) | 
|---|
| 3726 | return FALSE; | 
|---|
| 3727 | SetInfoPtr(hwnd,(DWORD)es); | 
|---|
| 3728 |  | 
|---|
| 3729 | /* | 
|---|
| 3730 | *      Note: since the EDITSTATE has not been fully initialized yet, | 
|---|
| 3731 | *            we can't use any API calls that may send | 
|---|
| 3732 | *            WM_XXX messages before WM_NCCREATE is completed. | 
|---|
| 3733 | */ | 
|---|
| 3734 |  | 
|---|
| 3735 | if (!(es->heap = HeapCreate(0, 0x10000, 0))) | 
|---|
| 3736 | return FALSE; | 
|---|
| 3737 | es->style = cs->style; | 
|---|
| 3738 |  | 
|---|
| 3739 | es->bEnableState = !(cs->style & WS_DISABLED); | 
|---|
| 3740 |  | 
|---|
| 3741 | /* | 
|---|
| 3742 | * In Win95 look and feel, the WS_BORDER style is replaced by the | 
|---|
| 3743 | * WS_EX_CLIENTEDGE style for the edit control. This gives the edit | 
|---|
| 3744 | * control a non client area. | 
|---|
| 3745 | */ | 
|---|
| 3746 | if (es->style & WS_BORDER) | 
|---|
| 3747 | { | 
|---|
| 3748 | es->style      &= ~WS_BORDER; | 
|---|
| 3749 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~WS_BORDER); | 
|---|
| 3750 | SetWindowLongA(hwnd,GWL_EXSTYLE,GetWindowLongA(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE); | 
|---|
| 3751 | } | 
|---|
| 3752 |  | 
|---|
| 3753 | if (es->style & ES_COMBO) | 
|---|
| 3754 | es->hwndListBox = GetDlgItem(cs->hwndParent, ID_CB_LISTBOX); | 
|---|
| 3755 |  | 
|---|
| 3756 | if (es->style & ES_MULTILINE) { | 
|---|
| 3757 | es->buffer_size = BUFSTART_MULTI; | 
|---|
| 3758 | es->buffer_limit = BUFLIMIT_MULTI; | 
|---|
| 3759 | if (es->style & WS_VSCROLL) | 
|---|
| 3760 | es->style |= ES_AUTOVSCROLL; | 
|---|
| 3761 | if (es->style & WS_HSCROLL) | 
|---|
| 3762 | es->style |= ES_AUTOHSCROLL; | 
|---|
| 3763 | es->style &= ~ES_PASSWORD; | 
|---|
| 3764 | if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) { | 
|---|
| 3765 | if (es->style & ES_RIGHT) | 
|---|
| 3766 | es->style &= ~ES_CENTER; | 
|---|
| 3767 | es->style &= ~WS_HSCROLL; | 
|---|
| 3768 | es->style &= ~ES_AUTOHSCROLL; | 
|---|
| 3769 | } | 
|---|
| 3770 |  | 
|---|
| 3771 | /* FIXME: for now, all multi line controls are AUTOVSCROLL */ | 
|---|
| 3772 | es->style |= ES_AUTOVSCROLL; | 
|---|
| 3773 | } else { | 
|---|
| 3774 | es->buffer_size = BUFSTART_SINGLE; | 
|---|
| 3775 | es->buffer_limit = BUFLIMIT_SINGLE; | 
|---|
| 3776 | es->style &= ~ES_CENTER; | 
|---|
| 3777 | es->style &= ~ES_RIGHT; | 
|---|
| 3778 | es->style &= ~WS_HSCROLL; | 
|---|
| 3779 | es->style &= ~WS_VSCROLL; | 
|---|
| 3780 | es->style &= ~ES_AUTOVSCROLL; | 
|---|
| 3781 | es->style &= ~ES_WANTRETURN; | 
|---|
| 3782 | if (es->style & ES_UPPERCASE) { | 
|---|
| 3783 | es->style &= ~ES_LOWERCASE; | 
|---|
| 3784 | es->style &= ~ES_NUMBER; | 
|---|
| 3785 | } else if (es->style & ES_LOWERCASE) | 
|---|
| 3786 | es->style &= ~ES_NUMBER; | 
|---|
| 3787 | if (es->style & ES_PASSWORD) | 
|---|
| 3788 | es->password_char = '*'; | 
|---|
| 3789 |  | 
|---|
| 3790 | /* FIXME: for now, all single line controls are AUTOHSCROLL */ | 
|---|
| 3791 | es->style |= ES_AUTOHSCROLL; | 
|---|
| 3792 | } | 
|---|
| 3793 | if (!(es->text = (char*)HeapAlloc(es->heap, 0, es->buffer_size + 1))) | 
|---|
| 3794 | return FALSE; | 
|---|
| 3795 | es->buffer_size = HeapSize(es->heap, 0, es->text) - 1; | 
|---|
| 3796 | if (!(es->undo_text = (char*)HeapAlloc(es->heap, 0, es->buffer_size + 1))) | 
|---|
| 3797 | return FALSE; | 
|---|
| 3798 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; | 
|---|
| 3799 | *es->text = '\0'; | 
|---|
| 3800 | if (es->style & ES_MULTILINE) | 
|---|
| 3801 | if (!(es->first_line_def = (LINEDEF*)HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF)))) | 
|---|
| 3802 | return FALSE; | 
|---|
| 3803 | es->line_count = 1; | 
|---|
| 3804 |  | 
|---|
| 3805 | return TRUE; | 
|---|
| 3806 | } | 
|---|
| 3807 |  | 
|---|
| 3808 | static VOID EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc,BOOL eraseBkGnd) | 
|---|
| 3809 | { | 
|---|
| 3810 | INT i; | 
|---|
| 3811 | HFONT old_font = 0; | 
|---|
| 3812 | RECT rc; | 
|---|
| 3813 | RECT rcLine; | 
|---|
| 3814 | RECT rcRgn; | 
|---|
| 3815 | BOOL rev = es->bEnableState && ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL)); | 
|---|
| 3816 |  | 
|---|
| 3817 | HideCaret(hwnd); | 
|---|
| 3818 |  | 
|---|
| 3819 | if (eraseBkGnd) | 
|---|
| 3820 | { | 
|---|
| 3821 | HBRUSH brush; | 
|---|
| 3822 |  | 
|---|
| 3823 | if (!es->bEnableState || (es->style & ES_READONLY)) | 
|---|
| 3824 | brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, hdc); | 
|---|
| 3825 | else | 
|---|
| 3826 | brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, hdc); | 
|---|
| 3827 |  | 
|---|
| 3828 | if (!brush) | 
|---|
| 3829 | brush = (HBRUSH)GetStockObject(WHITE_BRUSH); | 
|---|
| 3830 |  | 
|---|
| 3831 | GetClientRect(hwnd, &rc); | 
|---|
| 3832 | /* | 
|---|
| 3833 | *      FIXME:  specs say that we should UnrealizeObject() the brush, | 
|---|
| 3834 | *              but the specs of UnrealizeObject() say that we shouldn't | 
|---|
| 3835 | *              unrealize a stock object.  The default brush that | 
|---|
| 3836 | *              DefWndProc() returns is ... a stock object. | 
|---|
| 3837 | */ | 
|---|
| 3838 | FillRect(hdc, &rc, brush); | 
|---|
| 3839 | } | 
|---|
| 3840 |  | 
|---|
| 3841 | if(es->style & WS_BORDER) | 
|---|
| 3842 | { | 
|---|
| 3843 | GetClientRect(hwnd, &rc); | 
|---|
| 3844 | if(es->style & ES_MULTILINE) | 
|---|
| 3845 | { | 
|---|
| 3846 | if(es->style & WS_HSCROLL) rc.bottom++; | 
|---|
| 3847 | if(es->style & WS_VSCROLL) rc.right++; | 
|---|
| 3848 | } | 
|---|
| 3849 | Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 3850 | } | 
|---|
| 3851 |  | 
|---|
| 3852 | IntersectClipRect(hdc, es->format_rect.left, | 
|---|
| 3853 | es->format_rect.top, | 
|---|
| 3854 | es->format_rect.right, | 
|---|
| 3855 | es->format_rect.bottom); | 
|---|
| 3856 | if (es->style & ES_MULTILINE) | 
|---|
| 3857 | { | 
|---|
| 3858 | GetClientRect(hwnd, &rc); | 
|---|
| 3859 | IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 3860 | } | 
|---|
| 3861 | if (es->font) old_font = SelectObject(hdc, es->font); | 
|---|
| 3862 | if (!es->bEnableState || (es->style & ES_READONLY)) | 
|---|
| 3863 | EDIT_SEND_CTLCOLORSTATIC(hwnd, hdc); | 
|---|
| 3864 | else | 
|---|
| 3865 | EDIT_SEND_CTLCOLOR(hwnd, hdc); | 
|---|
| 3866 | if (!es->bEnableState) | 
|---|
| 3867 | SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); | 
|---|
| 3868 | GetClipBox(hdc, &rcRgn); | 
|---|
| 3869 | if (es->style & ES_MULTILINE) | 
|---|
| 3870 | { | 
|---|
| 3871 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 3872 |  | 
|---|
| 3873 | for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) | 
|---|
| 3874 | { | 
|---|
| 3875 | EDIT_GetLineRect(hwnd,hdc, es, i, 0, -1, &rcLine); | 
|---|
| 3876 | if (IntersectRect(&rc, &rcRgn, &rcLine)) | 
|---|
| 3877 | EDIT_PaintLine(hwnd, es, hdc, i, rev); | 
|---|
| 3878 | } | 
|---|
| 3879 | } else | 
|---|
| 3880 | { | 
|---|
| 3881 | EDIT_GetLineRect(hwnd,hdc, es, 0, 0, -1, &rcLine); | 
|---|
| 3882 | if (IntersectRect(&rc, &rcRgn, &rcLine)) | 
|---|
| 3883 | EDIT_PaintLine(hwnd, es, hdc, 0, rev); | 
|---|
| 3884 | } | 
|---|
| 3885 | if (es->font) SelectObject(hdc, old_font); | 
|---|
| 3886 | if (es->flags & EF_FOCUSED) | 
|---|
| 3887 | EDIT_SetCaretPos(hwnd, es, es->selection_end,es->flags & EF_AFTER_WRAP); | 
|---|
| 3888 |  | 
|---|
| 3889 | ShowCaret(hwnd); | 
|---|
| 3890 | } | 
|---|
| 3891 |  | 
|---|
| 3892 | static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache) | 
|---|
| 3893 | { | 
|---|
| 3894 | HDC hdc,hdcCompatible; | 
|---|
| 3895 | HBITMAP bitmap,oldbmp; | 
|---|
| 3896 | RECT rect; | 
|---|
| 3897 |  | 
|---|
| 3898 | if (es->flags & EF_UPDATE) | 
|---|
| 3899 | { | 
|---|
| 3900 | //CB: don't reset flag or EN_CHANGE is lost! | 
|---|
| 3901 | //es->flags &= ~EF_UPDATE; | 
|---|
| 3902 | EDIT_NOTIFY_PARENT(hwnd,EN_UPDATE); | 
|---|
| 3903 | } | 
|---|
| 3904 |  | 
|---|
| 3905 | if (!IsWindowVisible(hwnd)) return; | 
|---|
| 3906 |  | 
|---|
| 3907 | if (!useCache) | 
|---|
| 3908 | { | 
|---|
| 3909 | InvalidateRect(hwnd,NULL,TRUE); | 
|---|
| 3910 | return; | 
|---|
| 3911 | } | 
|---|
| 3912 |  | 
|---|
| 3913 | //CB: original control redraws many times, cache drawing | 
|---|
| 3914 | HideCaret(hwnd); | 
|---|
| 3915 | GetClientRect(hwnd,&rect); | 
|---|
| 3916 | hdc = GetDC(hwnd); | 
|---|
| 3917 | hdcCompatible = CreateCompatibleDC(hdc); | 
|---|
| 3918 | bitmap = CreateCompatibleBitmap(hdc,rect.right,rect.bottom); | 
|---|
| 3919 | oldbmp = SelectObject(hdcCompatible,bitmap); | 
|---|
| 3920 | EDIT_Draw(hwnd,es,hdcCompatible,TRUE); | 
|---|
| 3921 | SelectClipRgn(hdcCompatible,0); | 
|---|
| 3922 | BitBlt(hdc,0,0,rect.right,rect.bottom,hdcCompatible,0,0,SRCCOPY); | 
|---|
| 3923 | SelectObject(hdcCompatible,oldbmp); | 
|---|
| 3924 | DeleteObject(bitmap); | 
|---|
| 3925 | DeleteDC(hdcCompatible); | 
|---|
| 3926 | ReleaseDC(hwnd,hdc); | 
|---|
| 3927 | ShowCaret(hwnd); | 
|---|
| 3928 | } | 
|---|
| 3929 |  | 
|---|
| 3930 | /********************************************************************* | 
|---|
| 3931 | * | 
|---|
| 3932 | *      WM_PAINT | 
|---|
| 3933 | * | 
|---|
| 3934 | */ | 
|---|
| 3935 | static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam) | 
|---|
| 3936 | { | 
|---|
| 3937 | PAINTSTRUCT ps; | 
|---|
| 3938 | HDC hdc; | 
|---|
| 3939 |  | 
|---|
| 3940 | if (!wParam) hdc = BeginPaint(hwnd, &ps); | 
|---|
| 3941 | else hdc = (HDC) wParam; | 
|---|
| 3942 |  | 
|---|
| 3943 | EDIT_Draw(hwnd,es,hdc,FALSE); | 
|---|
| 3944 |  | 
|---|
| 3945 | if (!wParam) EndPaint(hwnd, &ps); | 
|---|
| 3946 | } | 
|---|
| 3947 |  | 
|---|
| 3948 |  | 
|---|
| 3949 | /********************************************************************* | 
|---|
| 3950 | * | 
|---|
| 3951 | *      WM_PASTE | 
|---|
| 3952 | * | 
|---|
| 3953 | */ | 
|---|
| 3954 | static void EDIT_WM_Paste(HWND hwnd, EDITSTATE *es) | 
|---|
| 3955 | { | 
|---|
| 3956 | HGLOBAL hsrc; | 
|---|
| 3957 | LPSTR src; | 
|---|
| 3958 |  | 
|---|
| 3959 | OpenClipboard(hwnd); | 
|---|
| 3960 | hsrc = GetClipboardData(CF_TEXT); | 
|---|
| 3961 | if (hsrc) { | 
|---|
| 3962 | src = (LPSTR)GlobalLock(hsrc); | 
|---|
| 3963 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, src); | 
|---|
| 3964 | GlobalUnlock(hsrc); | 
|---|
| 3965 |  | 
|---|
| 3966 | if (es->flags & EF_UPDATE) { | 
|---|
| 3967 | es->flags &= ~EF_UPDATE; | 
|---|
| 3968 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 3969 | } | 
|---|
| 3970 | } | 
|---|
| 3971 | CloseClipboard(); | 
|---|
| 3972 | } | 
|---|
| 3973 |  | 
|---|
| 3974 |  | 
|---|
| 3975 | /********************************************************************* | 
|---|
| 3976 | * | 
|---|
| 3977 | *      WM_SETFOCUS | 
|---|
| 3978 | * | 
|---|
| 3979 | */ | 
|---|
| 3980 | static void EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es, HWND window_losing_focus) | 
|---|
| 3981 | { | 
|---|
| 3982 | es->flags |= EF_FOCUSED; | 
|---|
| 3983 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 3984 | EDIT_SetCaretPos(hwnd, es, es->selection_end, | 
|---|
| 3985 | es->flags & EF_AFTER_WRAP); | 
|---|
| 3986 | if(!(es->style & ES_NOHIDESEL)) | 
|---|
| 3987 | EDIT_InvalidateText(hwnd, es, es->selection_start, es->selection_end); | 
|---|
| 3988 | ShowCaret(hwnd); | 
|---|
| 3989 | EDIT_NOTIFY_PARENT(hwnd, EN_SETFOCUS); | 
|---|
| 3990 | } | 
|---|
| 3991 |  | 
|---|
| 3992 | /********************************************************************* | 
|---|
| 3993 | * | 
|---|
| 3994 | *      WM_SETFONT | 
|---|
| 3995 | * | 
|---|
| 3996 | * With Win95 look the margins are set to default font value unless | 
|---|
| 3997 | * the system font (font == 0) is being set, in which case they are left | 
|---|
| 3998 | * unchanged. | 
|---|
| 3999 | * | 
|---|
| 4000 | */ | 
|---|
| 4001 | static void EDIT_WM_SetFont(HWND hwnd, EDITSTATE *es, HFONT font, BOOL redraw) | 
|---|
| 4002 | { | 
|---|
| 4003 | TEXTMETRICA tm; | 
|---|
| 4004 | HDC dc; | 
|---|
| 4005 | HFONT old_font = 0; | 
|---|
| 4006 | RECT r; | 
|---|
| 4007 |  | 
|---|
| 4008 | dc = GetDC(hwnd); | 
|---|
| 4009 | if (font) | 
|---|
| 4010 | old_font = SelectObject(dc, font); | 
|---|
| 4011 | if (!GetTextMetricsA(dc, &tm)) | 
|---|
| 4012 | { | 
|---|
| 4013 | if (font) SelectObject(dc,old_font); | 
|---|
| 4014 | ReleaseDC(hwnd,dc); | 
|---|
| 4015 |  | 
|---|
| 4016 | return; | 
|---|
| 4017 | } | 
|---|
| 4018 | es->font = font; | 
|---|
| 4019 | es->line_height = tm.tmHeight; | 
|---|
| 4020 |  | 
|---|
| 4021 | es->char_width = tm.tmAveCharWidth; | 
|---|
| 4022 | if (font) | 
|---|
| 4023 | SelectObject(dc, old_font); | 
|---|
| 4024 | ReleaseDC(hwnd, dc); | 
|---|
| 4025 | if (font) | 
|---|
| 4026 | EDIT_EM_SetMargins(hwnd, es, EC_LEFTMARGIN | EC_RIGHTMARGIN, | 
|---|
| 4027 | EC_USEFONTINFO, EC_USEFONTINFO); | 
|---|
| 4028 | /* Force the recalculation of the format rect for each font change */ | 
|---|
| 4029 | GetClientRect(hwnd, &r); | 
|---|
| 4030 | EDIT_SetRectNP(hwnd, es, &r); | 
|---|
| 4031 | if (es->style & ES_MULTILINE) | 
|---|
| 4032 | EDIT_BuildLineDefs_ML(hwnd,es); | 
|---|
| 4033 |  | 
|---|
| 4034 | if (redraw) | 
|---|
| 4035 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 4036 | if (es->flags & EF_FOCUSED) { | 
|---|
| 4037 | DestroyCaret(); | 
|---|
| 4038 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 4039 | EDIT_SetCaretPos(hwnd, es, es->selection_end, | 
|---|
| 4040 | es->flags & EF_AFTER_WRAP); | 
|---|
| 4041 | ShowCaret(hwnd); | 
|---|
| 4042 | } | 
|---|
| 4043 | } | 
|---|
| 4044 |  | 
|---|
| 4045 |  | 
|---|
| 4046 | /********************************************************************* | 
|---|
| 4047 | * | 
|---|
| 4048 | *      WM_SETTEXT | 
|---|
| 4049 | * | 
|---|
| 4050 | * NOTES | 
|---|
| 4051 | *  For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers: | 
|---|
| 4052 | *  The modified flag is reset. No notifications are sent. | 
|---|
| 4053 | * | 
|---|
| 4054 | *  For single-line controls, reception of WM_SETTEXT triggers: | 
|---|
| 4055 | *  The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent. | 
|---|
| 4056 | * | 
|---|
| 4057 | */ | 
|---|
| 4058 | static void EDIT_WM_SetText(HWND hwnd, EDITSTATE *es, LPCSTR text) | 
|---|
| 4059 | { | 
|---|
| 4060 | #ifdef __WIN32OS2__ | 
|---|
| 4061 | //SvL: Acrobat Distiller keeps on sending WM_SETTEXT with the same | 
|---|
| 4062 | //     string in responds to a WM_COMMAND with EN_UPDATE -> stack | 
|---|
| 4063 | //     overflow (TODO: Need to check if this behaviour is correct compared to NT) | 
|---|
| 4064 | if(text && es->text) { | 
|---|
| 4065 | if(!strcmp(es->text, text)) { | 
|---|
| 4066 | return; | 
|---|
| 4067 | } | 
|---|
| 4068 | } | 
|---|
| 4069 | #endif | 
|---|
| 4070 | es->selection_start = 0; | 
|---|
| 4071 | es->selection_end = lstrlenA(es->text); | 
|---|
| 4072 | if (es->flags & EF_FOCUSED) | 
|---|
| 4073 | EDIT_SetCaretPos(hwnd, es, es->selection_end, FALSE); | 
|---|
| 4074 |  | 
|---|
| 4075 | if (text) { | 
|---|
| 4076 | //TRACE_(edit)("\t'%s'\n", text); | 
|---|
| 4077 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, text); | 
|---|
| 4078 | } else { | 
|---|
| 4079 | //TRACE_(edit)("\t<NULL>\n"); | 
|---|
| 4080 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, ""); | 
|---|
| 4081 | } | 
|---|
| 4082 | es->x_offset = 0; | 
|---|
| 4083 | if (es->style & ES_MULTILINE) { | 
|---|
| 4084 | es->flags &= ~EF_UPDATE; | 
|---|
| 4085 | } else { | 
|---|
| 4086 | es->flags |= EF_UPDATE; | 
|---|
| 4087 | } | 
|---|
| 4088 | es->flags &= ~EF_MODIFIED; | 
|---|
| 4089 | EDIT_EM_SetSel(hwnd, es, 0, 0, FALSE); | 
|---|
| 4090 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 4091 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); | 
|---|
| 4092 | if (es->flags & EF_UPDATE) | 
|---|
| 4093 | { | 
|---|
| 4094 | EDIT_NOTIFY_PARENT(hwnd,EN_UPDATE); | 
|---|
| 4095 | /* EN_CHANGE notification need to be sent too | 
|---|
| 4096 | Windows doc says it's only done after the display, | 
|---|
| 4097 | the doc is WRONG. EN_CHANGE notification is sent | 
|---|
| 4098 | while processing WM_SETTEXT */ | 
|---|
| 4099 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE); | 
|---|
| 4100 | es->flags &= ~EF_UPDATE; | 
|---|
| 4101 | } | 
|---|
| 4102 | } | 
|---|
| 4103 |  | 
|---|
| 4104 |  | 
|---|
| 4105 | /********************************************************************* | 
|---|
| 4106 | * | 
|---|
| 4107 | *      WM_SIZE | 
|---|
| 4108 | * | 
|---|
| 4109 | */ | 
|---|
| 4110 | static void EDIT_WM_Size(HWND hwnd, EDITSTATE *es, UINT action, INT width, INT height) | 
|---|
| 4111 | { | 
|---|
| 4112 | if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) { | 
|---|
| 4113 | RECT rc; | 
|---|
| 4114 | SetRect(&rc, 0, 0, width, height); | 
|---|
| 4115 | EDIT_SetRectNP(hwnd, es, &rc); | 
|---|
| 4116 | EDIT_Refresh(hwnd,es,FALSE); | 
|---|
| 4117 | } | 
|---|
| 4118 | } | 
|---|
| 4119 |  | 
|---|
| 4120 |  | 
|---|
| 4121 | /********************************************************************* | 
|---|
| 4122 | * | 
|---|
| 4123 | *      WM_SYSKEYDOWN | 
|---|
| 4124 | * | 
|---|
| 4125 | */ | 
|---|
| 4126 | static LRESULT EDIT_WM_SysKeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data) | 
|---|
| 4127 | { | 
|---|
| 4128 | if ((key == VK_BACK) && (key_data & 0x2000)) { | 
|---|
| 4129 | if (EDIT_EM_CanUndo(hwnd, es)) | 
|---|
| 4130 | EDIT_EM_Undo(hwnd, es); | 
|---|
| 4131 | return 0; | 
|---|
| 4132 | } else if ((key == VK_UP) || (key == VK_DOWN)) | 
|---|
| 4133 | { | 
|---|
| 4134 | if (EDIT_CheckCombo(hwnd,es, WM_SYSKEYDOWN, key, key_data)) | 
|---|
| 4135 | return 0; | 
|---|
| 4136 | } | 
|---|
| 4137 | return DefWindowProcA(hwnd, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data); | 
|---|
| 4138 | } | 
|---|
| 4139 |  | 
|---|
| 4140 |  | 
|---|
| 4141 | /********************************************************************* | 
|---|
| 4142 | * | 
|---|
| 4143 | *      WM_TIMER | 
|---|
| 4144 | * | 
|---|
| 4145 | */ | 
|---|
| 4146 | static void EDIT_WM_Timer(HWND hwnd, EDITSTATE *es, INT id, TIMERPROC timer_proc) | 
|---|
| 4147 | { | 
|---|
| 4148 | if (es->region_posx < 0) { | 
|---|
| 4149 | EDIT_MoveBackward(hwnd, es, TRUE); | 
|---|
| 4150 | } else if (es->region_posx > 0) { | 
|---|
| 4151 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 4152 | } | 
|---|
| 4153 |  | 
|---|
| 4154 | if (!(es->style & ES_MULTILINE)) return; | 
|---|
| 4155 |  | 
|---|
| 4156 | if (es->region_posy < 0) | 
|---|
| 4157 | { | 
|---|
| 4158 | EDIT_MoveUp_ML(hwnd,es,TRUE); | 
|---|
| 4159 | } else if (es->region_posy > 0) | 
|---|
| 4160 | { | 
|---|
| 4161 | EDIT_MoveDown_ML(hwnd,es,TRUE); | 
|---|
| 4162 | } | 
|---|
| 4163 | } | 
|---|
| 4164 |  | 
|---|
| 4165 |  | 
|---|
| 4166 | /********************************************************************* | 
|---|
| 4167 | * | 
|---|
| 4168 | *      EDIT_VScroll_Hack | 
|---|
| 4169 | * | 
|---|
| 4170 | *      16 bit notepad needs this.  Actually it is not _our_ hack, | 
|---|
| 4171 | *      it is notepad's.  Notepad is sending us scrollbar messages with | 
|---|
| 4172 | *      undocumented parameters without us even having a scrollbar ... !?!? | 
|---|
| 4173 | * | 
|---|
| 4174 | */ | 
|---|
| 4175 | static LRESULT EDIT_VScroll_Hack(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) | 
|---|
| 4176 | { | 
|---|
| 4177 | INT dy = 0; | 
|---|
| 4178 | LRESULT ret = 0; | 
|---|
| 4179 |  | 
|---|
| 4180 | if (!(es->flags & EF_VSCROLL_HACK)) { | 
|---|
| 4181 | //ERR_(edit)("hacked WM_VSCROLL handler invoked\n"); | 
|---|
| 4182 | //ERR_(edit)("      if you are _not_ running 16 bit notepad, please report\n"); | 
|---|
| 4183 | //ERR_(edit)("      (this message is only displayed once per edit control)\n"); | 
|---|
| 4184 | es->flags |= EF_VSCROLL_HACK; | 
|---|
| 4185 | } | 
|---|
| 4186 |  | 
|---|
| 4187 | switch (action) { | 
|---|
| 4188 | case SB_LINEUP: | 
|---|
| 4189 | case SB_LINEDOWN: | 
|---|
| 4190 | case SB_PAGEUP: | 
|---|
| 4191 | case SB_PAGEDOWN: | 
|---|
| 4192 | EDIT_EM_Scroll(hwnd, es, action); | 
|---|
| 4193 | return 0; | 
|---|
| 4194 | case SB_TOP: | 
|---|
| 4195 | dy = -es->y_offset; | 
|---|
| 4196 | break; | 
|---|
| 4197 | case SB_BOTTOM: | 
|---|
| 4198 | dy = es->line_count - 1 - es->y_offset; | 
|---|
| 4199 | break; | 
|---|
| 4200 | case SB_THUMBTRACK: | 
|---|
| 4201 | es->flags |= EF_VSCROLL_TRACK; | 
|---|
| 4202 | dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset; | 
|---|
| 4203 | break; | 
|---|
| 4204 | case SB_THUMBPOSITION: | 
|---|
| 4205 | es->flags &= ~EF_VSCROLL_TRACK; | 
|---|
| 4206 | if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset)) | 
|---|
| 4207 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL); | 
|---|
| 4208 | break; | 
|---|
| 4209 | case SB_ENDSCROLL: | 
|---|
| 4210 | break; | 
|---|
| 4211 |  | 
|---|
| 4212 | default: | 
|---|
| 4213 | //ERR_(edit)("undocumented (hacked) WM_VSCROLL parameter, please report\n"); | 
|---|
| 4214 | return 0; | 
|---|
| 4215 | } | 
|---|
| 4216 | if (dy) | 
|---|
| 4217 | EDIT_EM_LineScroll(hwnd, es, 0, dy); | 
|---|
| 4218 | return ret; | 
|---|
| 4219 | } | 
|---|
| 4220 |  | 
|---|
| 4221 |  | 
|---|
| 4222 | /********************************************************************* | 
|---|
| 4223 | * | 
|---|
| 4224 | *      WM_VSCROLL | 
|---|
| 4225 | * | 
|---|
| 4226 | */ | 
|---|
| 4227 | static LRESULT EDIT_WM_VScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) | 
|---|
| 4228 | { | 
|---|
| 4229 | INT dy; | 
|---|
| 4230 |  | 
|---|
| 4231 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 4232 | return 0; | 
|---|
| 4233 |  | 
|---|
| 4234 | if (!(es->style & ES_AUTOVSCROLL)) | 
|---|
| 4235 | return 0; | 
|---|
| 4236 |  | 
|---|
| 4237 | if (!(es->style & WS_VSCROLL)) | 
|---|
| 4238 | return EDIT_VScroll_Hack(hwnd, es, action, pos, scroll_bar); | 
|---|
| 4239 |  | 
|---|
| 4240 | dy = 0; | 
|---|
| 4241 | switch (action) { | 
|---|
| 4242 | case SB_LINEUP: | 
|---|
| 4243 | case SB_LINEDOWN: | 
|---|
| 4244 | case SB_PAGEUP: | 
|---|
| 4245 | case SB_PAGEDOWN: | 
|---|
| 4246 | EDIT_EM_Scroll(hwnd, es, action); | 
|---|
| 4247 | return 0; | 
|---|
| 4248 |  | 
|---|
| 4249 | case SB_TOP: | 
|---|
| 4250 | dy = -es->y_offset; | 
|---|
| 4251 | break; | 
|---|
| 4252 | case SB_BOTTOM: | 
|---|
| 4253 | dy = es->line_count - 1 - es->y_offset; | 
|---|
| 4254 | break; | 
|---|
| 4255 | case SB_THUMBTRACK: | 
|---|
| 4256 | es->flags |= EF_VSCROLL_TRACK; | 
|---|
| 4257 | dy = pos - es->y_offset; | 
|---|
| 4258 | break; | 
|---|
| 4259 | case SB_THUMBPOSITION: | 
|---|
| 4260 | es->flags &= ~EF_VSCROLL_TRACK; | 
|---|
| 4261 | if (!(dy = pos - es->y_offset)) { | 
|---|
| 4262 | SetScrollPos(hwnd, SB_VERT, pos, TRUE); | 
|---|
| 4263 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL); | 
|---|
| 4264 | } | 
|---|
| 4265 | break; | 
|---|
| 4266 | case SB_ENDSCROLL: | 
|---|
| 4267 | break; | 
|---|
| 4268 |  | 
|---|
| 4269 | default: | 
|---|
| 4270 | //ERR_(edit)("undocumented WM_VSCROLL action %d, please report\n", | 
|---|
| 4271 | //        action); | 
|---|
| 4272 | return 0; | 
|---|
| 4273 | } | 
|---|
| 4274 | if (dy) | 
|---|
| 4275 | EDIT_EM_LineScroll(hwnd, es, 0, dy); | 
|---|
| 4276 | return 0; | 
|---|
| 4277 | } | 
|---|
| 4278 |  | 
|---|
| 4279 | static LRESULT EDIT_WM_MouseWheel(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam) | 
|---|
| 4280 | { | 
|---|
| 4281 | short gcWheelDelta = 0; | 
|---|
| 4282 | UINT pulScrollLines = 3; | 
|---|
| 4283 | SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0); | 
|---|
| 4284 |  | 
|---|
| 4285 | if (wParam & (MK_SHIFT | MK_CONTROL)) | 
|---|
| 4286 | return DefWindowProcA(hwnd,WM_MOUSEWHEEL, wParam, lParam); | 
|---|
| 4287 | gcWheelDelta -= (short) HIWORD(wParam); | 
|---|
| 4288 | if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines) | 
|---|
| 4289 | { | 
|---|
| 4290 | int cLineScroll= (int) min((UINT) es->line_count, pulScrollLines); | 
|---|
| 4291 |  | 
|---|
| 4292 | cLineScroll *= (gcWheelDelta / WHEEL_DELTA); | 
|---|
| 4293 | return EDIT_EM_LineScroll(hwnd, es, 0, cLineScroll); | 
|---|
| 4294 | } | 
|---|
| 4295 |  | 
|---|
| 4296 | return 0; | 
|---|
| 4297 | } | 
|---|
| 4298 |  | 
|---|
| 4299 | BOOL EDIT_Register() | 
|---|
| 4300 | { | 
|---|
| 4301 | WNDCLASSA wndClass; | 
|---|
| 4302 |  | 
|---|
| 4303 | //SvL: Don't check this now | 
|---|
| 4304 | //    if (GlobalFindAtomA(EDITCLASSNAME)) return FALSE; | 
|---|
| 4305 |  | 
|---|
| 4306 | ZeroMemory(&wndClass,sizeof(WNDCLASSA)); | 
|---|
| 4307 | wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS; | 
|---|
| 4308 | wndClass.lpfnWndProc   = (WNDPROC)EditWndProc; | 
|---|
| 4309 | wndClass.cbClsExtra    = 0; | 
|---|
| 4310 | wndClass.cbWndExtra    = sizeof(VOID*); | 
|---|
| 4311 | wndClass.hCursor       = LoadCursorA(0,IDC_IBEAMA); | 
|---|
| 4312 | wndClass.hbrBackground = (HBRUSH)0; | 
|---|
| 4313 | wndClass.lpszClassName = EDITCLASSNAME; | 
|---|
| 4314 |  | 
|---|
| 4315 | return RegisterClassA(&wndClass); | 
|---|
| 4316 | } | 
|---|
| 4317 |  | 
|---|
| 4318 | BOOL EDIT_Unregister() | 
|---|
| 4319 | { | 
|---|
| 4320 | if (GlobalFindAtomA(EDITCLASSNAME)) | 
|---|
| 4321 | return UnregisterClassA(EDITCLASSNAME,(HINSTANCE)NULL); | 
|---|
| 4322 | else return FALSE; | 
|---|
| 4323 | } | 
|---|