| 1 | /* | 
|---|
| 2 | *  Edit control | 
|---|
| 3 | * | 
|---|
| 4 | *  Copyright  David W. Metcalfe, 1994 | 
|---|
| 5 | *  Copyright  William Magro, 1995, 1996 | 
|---|
| 6 | *  Copyright  Frans van Dorsselaer, 1996, 1997 | 
|---|
| 7 | * | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | /* | 
|---|
| 11 | *  please read EDIT.TODO (and update it when you change things) | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #include "config.h" | 
|---|
| 15 |  | 
|---|
| 16 | #include <string.h> | 
|---|
| 17 | #include <stdlib.h> | 
|---|
| 18 |  | 
|---|
| 19 | #include "winbase.h" | 
|---|
| 20 | #include "winnt.h" | 
|---|
| 21 | #include "win.h" | 
|---|
| 22 | #include "wine/winbase16.h" | 
|---|
| 23 | #include "wine/winuser16.h" | 
|---|
| 24 | #include "wine/unicode.h" | 
|---|
| 25 | #include "controls.h" | 
|---|
| 26 | #include "local.h" | 
|---|
| 27 | #include "user.h" | 
|---|
| 28 | #include "debugtools.h" | 
|---|
| 29 |  | 
|---|
| 30 | #ifdef __WIN32OS2__ | 
|---|
| 31 | #include "ctrlconf.h" | 
|---|
| 32 | #include <heapstring.h> | 
|---|
| 33 | #include <imm.h> | 
|---|
| 34 | #endif | 
|---|
| 35 |  | 
|---|
| 36 | DEFAULT_DEBUG_CHANNEL(edit); | 
|---|
| 37 | DECLARE_DEBUG_CHANNEL(combo); | 
|---|
| 38 | #ifndef __WIN32OS2__ | 
|---|
| 39 | DECLARE_DEBUG_CHANNEL(relay); | 
|---|
| 40 |  | 
|---|
| 41 | #define BUFLIMIT_MULTI      0x7FFFFFF   /* maximum buffer size (not including '\0') | 
|---|
| 42 | #define BUFLIMIT_SINGLE     0x7FFFFFF   /* maximum buffer size (not including '\0') */ | 
|---|
| 43 | #else | 
|---|
| 44 | #define BUFLIMIT_MULTI      65534   /* maximum buffer size (not including '\0') | 
|---|
| 45 | FIXME: BTW, new specs say 65535 (do you dare ???) */ | 
|---|
| 46 | #define BUFLIMIT_SINGLE     32766   /* maximum buffer size (not including '\0') */ | 
|---|
| 47 | #endif | 
|---|
| 48 |  | 
|---|
| 49 | #define GROWLENGTH      32  /* buffers granularity in bytes: must be power of 2 */ | 
|---|
| 50 | #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1)) | 
|---|
| 51 | #define HSCROLL_FRACTION    3   /* scroll window by 1/3 width */ | 
|---|
| 52 |  | 
|---|
| 53 | /* | 
|---|
| 54 | *  extra flags for EDITSTATE.flags field | 
|---|
| 55 | */ | 
|---|
| 56 | #define EF_MODIFIED     0x0001  /* text has been modified */ | 
|---|
| 57 | #define EF_FOCUSED      0x0002  /* we have input focus */ | 
|---|
| 58 | #define EF_UPDATE       0x0004  /* notify parent of changed state */ | 
|---|
| 59 | #define EF_VSCROLL_TRACK    0x0008  /* don't SetScrollPos() since we are tracking the thumb */ | 
|---|
| 60 | #define EF_HSCROLL_TRACK    0x0010  /* don't SetScrollPos() since we are tracking the thumb */ | 
|---|
| 61 | #define EF_AFTER_WRAP       0x0080  /* the caret is displayed after the last character of a | 
|---|
| 62 | wrapped line, instead of in front of the next character */ | 
|---|
| 63 | #define EF_USE_SOFTBRK      0x0100  /* Enable soft breaks in text. */ | 
|---|
| 64 |  | 
|---|
| 65 | typedef enum | 
|---|
| 66 | { | 
|---|
| 67 | END_0 = 0,  /* line ends with terminating '\0' character */ | 
|---|
| 68 | END_WRAP,   /* line is wrapped */ | 
|---|
| 69 | END_HARD,   /* line ends with a hard return '\r\n' */ | 
|---|
| 70 | END_SOFT    /* line ends with a soft return '\r\r\n' */ | 
|---|
| 71 | } LINE_END; | 
|---|
| 72 |  | 
|---|
| 73 | typedef struct tagLINEDEF { | 
|---|
| 74 | INT length;     /* bruto length of a line in bytes */ | 
|---|
| 75 | INT net_length; /* netto length of a line in visible characters */ | 
|---|
| 76 | LINE_END ending; | 
|---|
| 77 | INT width;      /* width of the line in pixels */ | 
|---|
| 78 | INT index; /* line index into the buffer */ | 
|---|
| 79 | struct tagLINEDEF *next; | 
|---|
| 80 | } LINEDEF; | 
|---|
| 81 |  | 
|---|
| 82 | typedef struct | 
|---|
| 83 | { | 
|---|
| 84 | BOOL is_unicode;        /* how the control was created */ | 
|---|
| 85 | LPWSTR text;            /* the actual contents of the control */ | 
|---|
| 86 | UINT buffer_size;       /* the size of the buffer in characters */ | 
|---|
| 87 | UINT buffer_limit;      /* the maximum size to which the buffer may grow in characters */ | 
|---|
| 88 | HFONT font;         /* NULL means standard system font */ | 
|---|
| 89 | INT x_offset;           /* scroll offset    for multi lines this is in pixels | 
|---|
| 90 | for single lines it's in characters */ | 
|---|
| 91 | INT line_height;        /* height of a screen line in pixels */ | 
|---|
| 92 | INT char_width;     /* average character width in pixels */ | 
|---|
| 93 | DWORD style;            /* sane version of wnd->dwStyle */ | 
|---|
| 94 | WORD flags;         /* flags that are not in es->style or wnd->flags (EF_XXX) */ | 
|---|
| 95 | INT undo_insert_count;  /* number of characters inserted in sequence */ | 
|---|
| 96 | UINT undo_position;     /* character index of the insertion and deletion */ | 
|---|
| 97 | LPWSTR undo_text;       /* deleted text */ | 
|---|
| 98 | UINT undo_buffer_size;      /* size of the deleted text buffer */ | 
|---|
| 99 | INT selection_start;        /* == selection_end if no selection */ | 
|---|
| 100 | INT selection_end;      /* == current caret position */ | 
|---|
| 101 | WCHAR password_char;        /* == 0 if no password char, and for multi line controls */ | 
|---|
| 102 | INT left_margin;        /* in pixels */ | 
|---|
| 103 | INT right_margin;       /* in pixels */ | 
|---|
| 104 | RECT format_rect; | 
|---|
| 105 | INT text_width;         /* width of the widest line in pixels for multi line controls | 
|---|
| 106 | and just line width for single line controls */ | 
|---|
| 107 | INT region_posx;        /* Position of cursor relative to region: */ | 
|---|
| 108 | INT region_posy;        /* -1: to left, 0: within, 1: to right */ | 
|---|
| 109 | EDITWORDBREAKPROC16 word_break_proc16; | 
|---|
| 110 | void *word_break_proc;      /* 32-bit word break proc: ANSI or Unicode */ | 
|---|
| 111 | INT line_count;     /* number of lines */ | 
|---|
| 112 | INT y_offset;           /* scroll offset in number of lines */ | 
|---|
| 113 | BOOL bCaptureState; /* flag indicating whether mouse was captured */ | 
|---|
| 114 | BOOL bEnableState;             /* flag keeping the enable state */ | 
|---|
| 115 | HWND hwndParent;               /* Handle of parent for sending EN_* messages. | 
|---|
| 116 | Even if parent will change, EN_* messages | 
|---|
| 117 | should be sent to the first parent. */ | 
|---|
| 118 | HWND hwndListBox;              /* handle of ComboBox's listbox or NULL */ | 
|---|
| 119 | /* | 
|---|
| 120 | *  only for multi line controls | 
|---|
| 121 | */ | 
|---|
| 122 | INT lock_count;     /* amount of re-entries in the EditWndProc */ | 
|---|
| 123 | INT tabs_count; | 
|---|
| 124 | LPINT tabs; | 
|---|
| 125 | LINEDEF *first_line_def;    /* linked list of (soft) linebreaks */ | 
|---|
| 126 | HLOCAL hloc32W;     /* our unicode local memory block */ | 
|---|
| 127 | HLOCAL16 hloc16;    /* alias for 16-bit control receiving EM_GETHANDLE16 | 
|---|
| 128 | or EM_SETHANDLE16 */ | 
|---|
| 129 | HLOCAL hloc32A;     /* alias for ANSI control receiving EM_GETHANDLE | 
|---|
| 130 | or EM_SETHANDLE */ | 
|---|
| 131 | #ifdef __WIN32OS2__ | 
|---|
| 132 | LPWSTR  compStr; | 
|---|
| 133 | INT     compStrLen; | 
|---|
| 134 | BOOL    moveCaret; | 
|---|
| 135 | DWORD   sentenceMode; | 
|---|
| 136 | #endif | 
|---|
| 137 | } EDITSTATE; | 
|---|
| 138 |  | 
|---|
| 139 |  | 
|---|
| 140 | #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0) | 
|---|
| 141 | #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0) | 
|---|
| 142 |  | 
|---|
| 143 | #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0) | 
|---|
| 144 | #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0) | 
|---|
| 145 |  | 
|---|
| 146 | #define DPRINTF_EDIT_NOTIFY(hwnd, str) \ | 
|---|
| 147 | do {TRACE("notification " str " sent to hwnd=%08x\n", \ | 
|---|
| 148 | (UINT)(hwnd));} while(0) | 
|---|
| 149 |  | 
|---|
| 150 | /* used for disabled or read-only edit control */ | 
|---|
| 151 | #define EDIT_SEND_CTLCOLORSTATIC(hwnd,hdc) \ | 
|---|
| 152 | (SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC, \ | 
|---|
| 153 | (WPARAM)(hdc), (LPARAM)(hwnd))) | 
|---|
| 154 | #define EDIT_SEND_CTLCOLOR(hwnd,hdc) \ | 
|---|
| 155 | (SendMessageW(GetParent(hwnd), WM_CTLCOLOREDIT, \ | 
|---|
| 156 | (WPARAM)(hdc), (LPARAM)(hwnd))) | 
|---|
| 157 | #define EDIT_NOTIFY_PARENT(hwnd, es, wNotifyCode, str) \ | 
|---|
| 158 | do \ | 
|---|
| 159 | { /* Notify parent which has created this edit control */ \ | 
|---|
| 160 | DPRINTF_EDIT_NOTIFY((es)->hwndParent, str); \ | 
|---|
| 161 | SendMessageW((es)->hwndParent, WM_COMMAND, \ | 
|---|
| 162 | MAKEWPARAM(GetWindowLongA((hwnd),GWL_ID), wNotifyCode), \ | 
|---|
| 163 | (LPARAM)(hwnd)); \ | 
|---|
| 164 | } while(0) | 
|---|
| 165 | #define DPRINTF_EDIT_MSG16(str) \ | 
|---|
| 166 | TRACE(\ | 
|---|
| 167 | "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \ | 
|---|
| 168 | hwnd, (UINT)wParam, (UINT)lParam) | 
|---|
| 169 | #define DPRINTF_EDIT_MSG32(str) \ | 
|---|
| 170 | TRACE(\ | 
|---|
| 171 | "32 bit %c : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \ | 
|---|
| 172 | unicode ? 'W' : 'A', \ | 
|---|
| 173 | hwnd, (UINT)wParam, (UINT)lParam) | 
|---|
| 174 |  | 
|---|
| 175 | /********************************************************************* | 
|---|
| 176 | * | 
|---|
| 177 | *  Declarations | 
|---|
| 178 | * | 
|---|
| 179 | */ | 
|---|
| 180 |  | 
|---|
| 181 | /* | 
|---|
| 182 | *  These functions have trivial implementations | 
|---|
| 183 | *  We still like to call them internally | 
|---|
| 184 | *  "static inline" makes them more like macro's | 
|---|
| 185 | */ | 
|---|
| 186 | static inline BOOL  EDIT_EM_CanUndo(EDITSTATE *es); | 
|---|
| 187 | static inline void  EDIT_EM_EmptyUndoBuffer(EDITSTATE *es); | 
|---|
| 188 | static inline void  EDIT_WM_Clear(HWND hwnd, EDITSTATE *es); | 
|---|
| 189 | static inline void  EDIT_WM_Cut(HWND hwnd, EDITSTATE *es); | 
|---|
| 190 |  | 
|---|
| 191 | /* | 
|---|
| 192 | *  Helper functions only valid for one type of control | 
|---|
| 193 | */ | 
|---|
| 194 | static void EDIT_BuildLineDefs_ML(HWND hwnd, EDITSTATE *es, INT iStart, INT iEnd, INT delta, HRGN hrgn); | 
|---|
| 195 | static void EDIT_CalcLineWidth_SL(HWND hwnd, EDITSTATE *es); | 
|---|
| 196 | static LPWSTR   EDIT_GetPasswordPointer_SL(EDITSTATE *es); | 
|---|
| 197 | static void EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 198 | static void EDIT_MovePageDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 199 | static void EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 200 | static void EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 201 | /* | 
|---|
| 202 | *  Helper functions valid for both single line _and_ multi line controls | 
|---|
| 203 | */ | 
|---|
| 204 | static INT  EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action); | 
|---|
| 205 | static INT  EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap); | 
|---|
| 206 | static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y); | 
|---|
| 207 | static void EDIT_GetLineRect(HWND hwnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc); | 
|---|
| 208 | static void EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end); | 
|---|
| 209 | static void EDIT_LockBuffer(HWND hwnd, EDITSTATE *es); | 
|---|
| 210 | static BOOL EDIT_MakeFit(HWND hwnd, EDITSTATE *es, UINT size); | 
|---|
| 211 | static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size); | 
|---|
| 212 | static void EDIT_MoveBackward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 213 | static void EDIT_MoveEnd(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 214 | static void EDIT_MoveForward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 215 | static void EDIT_MoveHome(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 216 | static void EDIT_MoveWordBackward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 217 | static void EDIT_MoveWordForward(HWND hwnd, EDITSTATE *es, BOOL extend); | 
|---|
| 218 | static void EDIT_PaintLine(HWND hwnd, EDITSTATE *es, HDC hdc, INT line, BOOL rev); | 
|---|
| 219 | static INT  EDIT_PaintText(EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev); | 
|---|
| 220 | static void EDIT_SetCaretPos(HWND hwnd, EDITSTATE *es, INT pos, BOOL after_wrap); | 
|---|
| 221 | static void EDIT_SetRectNP(HWND hwnd, EDITSTATE *es, LPRECT lprc); | 
|---|
| 222 | static void EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force); | 
|---|
| 223 | static void EDIT_UpdateScrollInfo(HWND hwnd, EDITSTATE *es); | 
|---|
| 224 | static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action); | 
|---|
| 225 | /* | 
|---|
| 226 | *  EM_XXX message handlers | 
|---|
| 227 | */ | 
|---|
| 228 | static LRESULT  EDIT_EM_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y); | 
|---|
| 229 | static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol); | 
|---|
| 230 | static HLOCAL   EDIT_EM_GetHandle(EDITSTATE *es); | 
|---|
| 231 | #ifndef __WIN32OS2__ | 
|---|
| 232 | static HLOCAL16 EDIT_EM_GetHandle16(HWND hwnd, EDITSTATE *es); | 
|---|
| 233 | #endif | 
|---|
| 234 | static INT  EDIT_EM_GetLine(EDITSTATE *es, INT line, LPARAM lParam, BOOL unicode); | 
|---|
| 235 | static LRESULT  EDIT_EM_GetSel(EDITSTATE *es, LPUINT start, LPUINT end); | 
|---|
| 236 | static LRESULT  EDIT_EM_GetThumb(HWND hwnd, EDITSTATE *es); | 
|---|
| 237 | static INT  EDIT_EM_LineFromChar(EDITSTATE *es, INT index); | 
|---|
| 238 | static INT  EDIT_EM_LineIndex(EDITSTATE *es, INT line); | 
|---|
| 239 | static INT  EDIT_EM_LineLength(EDITSTATE *es, INT index); | 
|---|
| 240 | #ifdef __WIN32OS2__ | 
|---|
| 241 | static INT  EDIT_EM_LineLengthA(EDITSTATE *es, INT index); | 
|---|
| 242 | #endif | 
|---|
| 243 | static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy); | 
|---|
| 244 | static BOOL EDIT_EM_LineScroll_internal(HWND hwnd, EDITSTATE *es, INT dx, INT dy); | 
|---|
| 245 | static LRESULT  EDIT_EM_PosFromChar(HWND hwnd, EDITSTATE *es, INT index, BOOL after_wrap); | 
|---|
| 246 | static void EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update); | 
|---|
| 247 | static LRESULT  EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action); | 
|---|
| 248 | static void EDIT_EM_ScrollCaret(HWND hwnd, EDITSTATE *es); | 
|---|
| 249 | static void EDIT_EM_SetHandle(HWND hwnd, EDITSTATE *es, HLOCAL hloc); | 
|---|
| 250 | #ifndef __WIN32OS2__ | 
|---|
| 251 | static void EDIT_EM_SetHandle16(HWND hwnd, EDITSTATE *es, HLOCAL16 hloc); | 
|---|
| 252 | #endif | 
|---|
| 253 | static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit); | 
|---|
| 254 | static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, INT left, INT right); | 
|---|
| 255 | static void EDIT_EM_SetPasswordChar(HWND hwnd, EDITSTATE *es, WCHAR c); | 
|---|
| 256 | static void EDIT_EM_SetSel(HWND hwnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap); | 
|---|
| 257 | static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs); | 
|---|
| 258 | static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs); | 
|---|
| 259 | static void EDIT_EM_SetWordBreakProc(HWND hwnd, EDITSTATE *es, LPARAM lParam); | 
|---|
| 260 | #ifndef __WIN32OS2__ | 
|---|
| 261 | static void EDIT_EM_SetWordBreakProc16(HWND hwnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp); | 
|---|
| 262 | #endif | 
|---|
| 263 | static BOOL EDIT_EM_Undo(HWND hwnd, EDITSTATE *es); | 
|---|
| 264 | /* | 
|---|
| 265 | *  WM_XXX message handlers | 
|---|
| 266 | */ | 
|---|
| 267 | static void EDIT_WM_Char(HWND hwnd, EDITSTATE *es, WCHAR c); | 
|---|
| 268 | static void EDIT_WM_Command(HWND hwnd, EDITSTATE *es, INT code, INT id, HWND conrtol); | 
|---|
| 269 | static void EDIT_WM_ContextMenu(HWND hwnd, EDITSTATE *es, INT x, INT y); | 
|---|
| 270 | static void EDIT_WM_Copy(HWND hwnd, EDITSTATE *es); | 
|---|
| 271 | static LRESULT  EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCWSTR name); | 
|---|
| 272 | static void EDIT_WM_Destroy(HWND hwnd, EDITSTATE *es); | 
|---|
| 273 | static LRESULT  EDIT_WM_EraseBkGnd(HWND hwnd, EDITSTATE *es, HDC dc); | 
|---|
| 274 | static INT  EDIT_WM_GetText(EDITSTATE *es, INT count, LPARAM lParam, BOOL unicode); | 
|---|
| 275 | static LRESULT  EDIT_WM_HScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos); | 
|---|
| 276 | static LRESULT  EDIT_WM_KeyDown(HWND hwnd, EDITSTATE *es, INT key); | 
|---|
| 277 | static LRESULT  EDIT_WM_KillFocus(HWND hwnd, EDITSTATE *es); | 
|---|
| 278 | static LRESULT  EDIT_WM_LButtonDblClk(HWND hwnd, EDITSTATE *es); | 
|---|
| 279 | static LRESULT  EDIT_WM_LButtonDown(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y); | 
|---|
| 280 | static LRESULT  EDIT_WM_LButtonUp(HWND hwndSelf, EDITSTATE *es); | 
|---|
| 281 | static LRESULT  EDIT_WM_MButtonDown(HWND hwnd); | 
|---|
| 282 | static LRESULT  EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, INT x, INT y); | 
|---|
| 283 | static LRESULT  EDIT_WM_NCCreate(HWND hwnd, DWORD style, HWND hwndParent, BOOL unicode); | 
|---|
| 284 | static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es, WPARAM wParam); | 
|---|
| 285 | static void EDIT_WM_Paste(HWND hwnd, EDITSTATE *es); | 
|---|
| 286 | static void EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es); | 
|---|
| 287 | static void EDIT_WM_SetFont(HWND hwnd, EDITSTATE *es, HFONT font, BOOL redraw); | 
|---|
| 288 | static void EDIT_WM_SetText(HWND hwnd, EDITSTATE *es, LPARAM lParam, BOOL unicode); | 
|---|
| 289 | static void EDIT_WM_Size(HWND hwnd, EDITSTATE *es, UINT action, INT width, INT height); | 
|---|
| 290 | static LRESULT  EDIT_WM_StyleChanged (HWND hwnd, EDITSTATE *es, WPARAM which, const STYLESTRUCT *style); | 
|---|
| 291 | static LRESULT  EDIT_WM_SysKeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data); | 
|---|
| 292 | static void EDIT_WM_Timer(HWND hwnd, EDITSTATE *es); | 
|---|
| 293 | static LRESULT  EDIT_WM_VScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos); | 
|---|
| 294 | static void EDIT_UpdateText(HWND hwnd, EDITSTATE *es, LPRECT rc, BOOL bErase); | 
|---|
| 295 | static void EDIT_UpdateTextRegion(HWND hwnd, EDITSTATE *es, HRGN hrgn, BOOL bErase); | 
|---|
| 296 |  | 
|---|
| 297 | LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 
|---|
| 298 | LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 
|---|
| 299 |  | 
|---|
| 300 | /********************************************************************* | 
|---|
| 301 | * edit class descriptor | 
|---|
| 302 | */ | 
|---|
| 303 | const struct builtin_class_descr EDIT_builtin_class = | 
|---|
| 304 | { | 
|---|
| 305 | "Edit",               /* name */ | 
|---|
| 306 | CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/,   /* style */ | 
|---|
| 307 | EditWndProcA,         /* procA */ | 
|---|
| 308 | EditWndProcW,         /* procW */ | 
|---|
| 309 | sizeof(EDITSTATE *),  /* extra */ | 
|---|
| 310 | IDC_IBEAMA,           /* cursor */ | 
|---|
| 311 | 0                     /* brush */ | 
|---|
| 312 | }; | 
|---|
| 313 |  | 
|---|
| 314 |  | 
|---|
| 315 | /********************************************************************* | 
|---|
| 316 | * | 
|---|
| 317 | *  EM_CANUNDO | 
|---|
| 318 | * | 
|---|
| 319 | */ | 
|---|
| 320 | static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es) | 
|---|
| 321 | { | 
|---|
| 322 | return (es->undo_insert_count || strlenW(es->undo_text)); | 
|---|
| 323 | } | 
|---|
| 324 |  | 
|---|
| 325 |  | 
|---|
| 326 | /********************************************************************* | 
|---|
| 327 | * | 
|---|
| 328 | *  EM_EMPTYUNDOBUFFER | 
|---|
| 329 | * | 
|---|
| 330 | */ | 
|---|
| 331 | static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es) | 
|---|
| 332 | { | 
|---|
| 333 | es->undo_insert_count = 0; | 
|---|
| 334 | *es->undo_text = '\0'; | 
|---|
| 335 | } | 
|---|
| 336 |  | 
|---|
| 337 |  | 
|---|
| 338 | /********************************************************************* | 
|---|
| 339 | * | 
|---|
| 340 | *  WM_CLEAR | 
|---|
| 341 | * | 
|---|
| 342 | */ | 
|---|
| 343 | static inline void EDIT_WM_Clear(HWND hwnd, EDITSTATE *es) | 
|---|
| 344 | { | 
|---|
| 345 | static const WCHAR empty_stringW[] = {0}; | 
|---|
| 346 |  | 
|---|
| 347 | /* Protect read-only edit control from modification */ | 
|---|
| 348 | if(es->style & ES_READONLY) | 
|---|
| 349 | return; | 
|---|
| 350 |  | 
|---|
| 351 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, empty_stringW, TRUE); | 
|---|
| 352 | } | 
|---|
| 353 |  | 
|---|
| 354 |  | 
|---|
| 355 | /********************************************************************* | 
|---|
| 356 | * | 
|---|
| 357 | *  WM_CUT | 
|---|
| 358 | * | 
|---|
| 359 | */ | 
|---|
| 360 | static inline void EDIT_WM_Cut(HWND hwnd, EDITSTATE *es) | 
|---|
| 361 | { | 
|---|
| 362 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 363 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 364 | } | 
|---|
| 365 |  | 
|---|
| 366 |  | 
|---|
| 367 | /********************************************************************** | 
|---|
| 368 | *         get_app_version | 
|---|
| 369 | * | 
|---|
| 370 | * Returns the window version in case Wine emulates a later version | 
|---|
| 371 | * of windows then the application expects. | 
|---|
| 372 | * | 
|---|
| 373 | * In a number of cases when windows runs an application that was | 
|---|
| 374 | * designed for an earlier windows version, windows reverts | 
|---|
| 375 | * to "old" behaviour of that earlier version. | 
|---|
| 376 | * | 
|---|
| 377 | * An example is a disabled  edit control that needs to be painted. | 
|---|
| 378 | * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was | 
|---|
| 379 | * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for | 
|---|
| 380 | * applications with an expected version 0f 4.0 or higher. | 
|---|
| 381 | * | 
|---|
| 382 | */ | 
|---|
| 383 | static DWORD get_app_version(void) | 
|---|
| 384 | { | 
|---|
| 385 | static DWORD version; | 
|---|
| 386 | if (!version) | 
|---|
| 387 | { | 
|---|
| 388 | DWORD dwEmulatedVersion; | 
|---|
| 389 | OSVERSIONINFOW info; | 
|---|
| 390 | DWORD dwProcVersion = GetProcessVersion(0); | 
|---|
| 391 |  | 
|---|
| 392 | info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); | 
|---|
| 393 | GetVersionExW( &info ); | 
|---|
| 394 | dwEmulatedVersion = MAKELONG( info.dwMinorVersion, info.dwMajorVersion ); | 
|---|
| 395 | /* FIXME: this may not be 100% correct; see discussion on the | 
|---|
| 396 | * wine developer list in Nov 1999 */ | 
|---|
| 397 | version = dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion; | 
|---|
| 398 | } | 
|---|
| 399 | return version; | 
|---|
| 400 | } | 
|---|
| 401 |  | 
|---|
| 402 |  | 
|---|
| 403 | /********************************************************************* | 
|---|
| 404 | * | 
|---|
| 405 | *  EditWndProc_common | 
|---|
| 406 | * | 
|---|
| 407 | *  The messages are in the order of the actual integer values | 
|---|
| 408 | *  (which can be found in include/windows.h) | 
|---|
| 409 | *  Wherever possible the 16 bit versions are converted to | 
|---|
| 410 | *  the 32 bit ones, so that we can 'fall through' to the | 
|---|
| 411 | *  helper functions.  These are mostly 32 bit (with a few | 
|---|
| 412 | *  exceptions, clearly indicated by a '16' extension to their | 
|---|
| 413 | *  names). | 
|---|
| 414 | * | 
|---|
| 415 | */ | 
|---|
| 416 | static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg, | 
|---|
| 417 | WPARAM wParam, LPARAM lParam, BOOL unicode ) | 
|---|
| 418 | { | 
|---|
| 419 | EDITSTATE *es = (EDITSTATE *)GetWindowLongA( hwnd, 0 ); | 
|---|
| 420 | LRESULT result = 0; | 
|---|
| 421 |  | 
|---|
| 422 | switch (msg) { | 
|---|
| 423 | case WM_DESTROY: | 
|---|
| 424 | DPRINTF_EDIT_MSG32("WM_DESTROY"); | 
|---|
| 425 | if (es) EDIT_WM_Destroy(hwnd, es); | 
|---|
| 426 | result = 0; | 
|---|
| 427 | goto END; | 
|---|
| 428 |  | 
|---|
| 429 | case WM_NCCREATE: | 
|---|
| 430 | DPRINTF_EDIT_MSG32("WM_NCCREATE"); | 
|---|
| 431 | if(unicode) | 
|---|
| 432 | { | 
|---|
| 433 | LPCREATESTRUCTW cs = (LPCREATESTRUCTW)lParam; | 
|---|
| 434 | result = EDIT_WM_NCCreate(hwnd, cs->style, cs->hwndParent, TRUE); | 
|---|
| 435 | } | 
|---|
| 436 | else | 
|---|
| 437 | { | 
|---|
| 438 | LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam; | 
|---|
| 439 | result = EDIT_WM_NCCreate(hwnd, cs->style, cs->hwndParent, FALSE); | 
|---|
| 440 | } | 
|---|
| 441 | goto END; | 
|---|
| 442 | } | 
|---|
| 443 |  | 
|---|
| 444 | if (!es) | 
|---|
| 445 | { | 
|---|
| 446 | if(unicode) | 
|---|
| 447 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 448 | else | 
|---|
| 449 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 450 | goto END; | 
|---|
| 451 | } | 
|---|
| 452 |  | 
|---|
| 453 |  | 
|---|
| 454 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 455 | switch (msg) { | 
|---|
| 456 | case EM_GETSEL16: | 
|---|
| 457 | DPRINTF_EDIT_MSG16("EM_GETSEL"); | 
|---|
| 458 | wParam = 0; | 
|---|
| 459 | lParam = 0; | 
|---|
| 460 | /* fall through */ | 
|---|
| 461 | case EM_GETSEL: | 
|---|
| 462 | DPRINTF_EDIT_MSG32("EM_GETSEL"); | 
|---|
| 463 | result = EDIT_EM_GetSel(es, (LPUINT)wParam, (LPUINT)lParam); | 
|---|
| 464 | break; | 
|---|
| 465 |  | 
|---|
| 466 | case EM_SETSEL16: | 
|---|
| 467 | DPRINTF_EDIT_MSG16("EM_SETSEL"); | 
|---|
| 468 | if (SLOWORD(lParam) == -1) | 
|---|
| 469 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 470 | else | 
|---|
| 471 | #ifdef __WIN32OS2__ | 
|---|
| 472 | if( IsDBCSEnv() && SHIWORD( lParam ) != -1 ) | 
|---|
| 473 | { | 
|---|
| 474 | INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 ); | 
|---|
| 475 | LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA ); | 
|---|
| 476 | WORD wLo, wHi; | 
|---|
| 477 |  | 
|---|
| 478 | if( textA ) | 
|---|
| 479 | { | 
|---|
| 480 | WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 ); | 
|---|
| 481 |  | 
|---|
| 482 | wLo = LOWORD( lParam ); | 
|---|
| 483 | wHi = HIWORD( lParam ); | 
|---|
| 484 |  | 
|---|
| 485 | if( wLo > countA ) | 
|---|
| 486 | wLo = countA; | 
|---|
| 487 | wLo = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, wLo, 0, 0 ); | 
|---|
| 488 |  | 
|---|
| 489 | if( wHi > countA ) | 
|---|
| 490 | wHi = countA; | 
|---|
| 491 | wHi = ( LPARAM )MultiByteToWideChar( CP_ACP, 0, textA, wHi, 0, 0 ); | 
|---|
| 492 |  | 
|---|
| 493 | lParam = MAKELPARAM( wLo, wHi ); | 
|---|
| 494 |  | 
|---|
| 495 | HeapFree( GetProcessHeap(), 0, textA ); | 
|---|
| 496 | } | 
|---|
| 497 | #endif | 
|---|
| 498 | EDIT_EM_SetSel(hwnd, es, LOWORD(lParam), HIWORD(lParam), FALSE); | 
|---|
| 499 | #ifdef __WIN32OS2__ | 
|---|
| 500 | } | 
|---|
| 501 | #endif | 
|---|
| 502 | if (!wParam) | 
|---|
| 503 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 504 | result = 1; | 
|---|
| 505 | break; | 
|---|
| 506 | case EM_SETSEL: | 
|---|
| 507 | DPRINTF_EDIT_MSG32("EM_SETSEL"); | 
|---|
| 508 | #ifdef __WIN32OS2__ | 
|---|
| 509 | if( !unicode && IsDBCSEnv() && ( INT )wParam != -1 && ( INT )lParam != -1 ) | 
|---|
| 510 | { | 
|---|
| 511 | INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 ); | 
|---|
| 512 | LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA ); | 
|---|
| 513 |  | 
|---|
| 514 | if( textA ) | 
|---|
| 515 | { | 
|---|
| 516 | WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 ); | 
|---|
| 517 |  | 
|---|
| 518 | if(( INT )wParam > countA ) | 
|---|
| 519 | wParam = ( WPARAM ) countA; | 
|---|
| 520 | wParam = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )wParam, 0, 0 ); | 
|---|
| 521 |  | 
|---|
| 522 | if(( INT )lParam > countA ) | 
|---|
| 523 | lParam = ( LPARAM ) countA; | 
|---|
| 524 | lParam = ( LPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )lParam, 0, 0 ); | 
|---|
| 525 |  | 
|---|
| 526 | HeapFree( GetProcessHeap(), 0, textA ); | 
|---|
| 527 | } | 
|---|
| 528 | } | 
|---|
| 529 | #endif | 
|---|
| 530 | EDIT_EM_SetSel(hwnd, es, wParam, lParam, FALSE); | 
|---|
| 531 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 532 | result = 1; | 
|---|
| 533 | break; | 
|---|
| 534 |  | 
|---|
| 535 | case EM_GETRECT16: | 
|---|
| 536 | DPRINTF_EDIT_MSG16("EM_GETRECT"); | 
|---|
| 537 | if (lParam) | 
|---|
| 538 | CONV_RECT32TO16(&es->format_rect, MapSL(lParam)); | 
|---|
| 539 | break; | 
|---|
| 540 | case EM_GETRECT: | 
|---|
| 541 | DPRINTF_EDIT_MSG32("EM_GETRECT"); | 
|---|
| 542 | if (lParam) | 
|---|
| 543 | CopyRect((LPRECT)lParam, &es->format_rect); | 
|---|
| 544 | break; | 
|---|
| 545 |  | 
|---|
| 546 | case EM_SETRECT16: | 
|---|
| 547 | DPRINTF_EDIT_MSG16("EM_SETRECT"); | 
|---|
| 548 | if ((es->style & ES_MULTILINE) && lParam) { | 
|---|
| 549 | RECT rc; | 
|---|
| 550 | CONV_RECT16TO32(MapSL(lParam), &rc); | 
|---|
| 551 | EDIT_SetRectNP(hwnd, es, &rc); | 
|---|
| 552 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 553 | } | 
|---|
| 554 | break; | 
|---|
| 555 | case EM_SETRECT: | 
|---|
| 556 | DPRINTF_EDIT_MSG32("EM_SETRECT"); | 
|---|
| 557 | if ((es->style & ES_MULTILINE) && lParam) { | 
|---|
| 558 | EDIT_SetRectNP(hwnd, es, (LPRECT)lParam); | 
|---|
| 559 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 560 | } | 
|---|
| 561 | break; | 
|---|
| 562 |  | 
|---|
| 563 | case EM_SETRECTNP16: | 
|---|
| 564 | DPRINTF_EDIT_MSG16("EM_SETRECTNP"); | 
|---|
| 565 | if ((es->style & ES_MULTILINE) && lParam) { | 
|---|
| 566 | RECT rc; | 
|---|
| 567 | CONV_RECT16TO32(MapSL(lParam), &rc); | 
|---|
| 568 | EDIT_SetRectNP(hwnd, es, &rc); | 
|---|
| 569 | } | 
|---|
| 570 | break; | 
|---|
| 571 | case EM_SETRECTNP: | 
|---|
| 572 | DPRINTF_EDIT_MSG32("EM_SETRECTNP"); | 
|---|
| 573 | if ((es->style & ES_MULTILINE) && lParam) | 
|---|
| 574 | EDIT_SetRectNP(hwnd, es, (LPRECT)lParam); | 
|---|
| 575 | break; | 
|---|
| 576 |  | 
|---|
| 577 | case EM_SCROLL16: | 
|---|
| 578 | DPRINTF_EDIT_MSG16("EM_SCROLL"); | 
|---|
| 579 | /* fall through */ | 
|---|
| 580 | case EM_SCROLL: | 
|---|
| 581 | DPRINTF_EDIT_MSG32("EM_SCROLL"); | 
|---|
| 582 | result = EDIT_EM_Scroll(hwnd, es, (INT)wParam); | 
|---|
| 583 | break; | 
|---|
| 584 |  | 
|---|
| 585 | case EM_LINESCROLL16: | 
|---|
| 586 | DPRINTF_EDIT_MSG16("EM_LINESCROLL"); | 
|---|
| 587 | wParam = (WPARAM)(INT)SHIWORD(lParam); | 
|---|
| 588 | lParam = (LPARAM)(INT)SLOWORD(lParam); | 
|---|
| 589 | /* fall through */ | 
|---|
| 590 | case EM_LINESCROLL: | 
|---|
| 591 | DPRINTF_EDIT_MSG32("EM_LINESCROLL"); | 
|---|
| 592 | result = (LRESULT)EDIT_EM_LineScroll(hwnd, es, (INT)wParam, (INT)lParam); | 
|---|
| 593 | break; | 
|---|
| 594 |  | 
|---|
| 595 | case EM_SCROLLCARET16: | 
|---|
| 596 | DPRINTF_EDIT_MSG16("EM_SCROLLCARET"); | 
|---|
| 597 | /* fall through */ | 
|---|
| 598 | case EM_SCROLLCARET: | 
|---|
| 599 | DPRINTF_EDIT_MSG32("EM_SCROLLCARET"); | 
|---|
| 600 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 601 | result = 1; | 
|---|
| 602 | break; | 
|---|
| 603 |  | 
|---|
| 604 | case EM_GETMODIFY16: | 
|---|
| 605 | DPRINTF_EDIT_MSG16("EM_GETMODIFY"); | 
|---|
| 606 | /* fall through */ | 
|---|
| 607 | case EM_GETMODIFY: | 
|---|
| 608 | DPRINTF_EDIT_MSG32("EM_GETMODIFY"); | 
|---|
| 609 | result = ((es->flags & EF_MODIFIED) != 0); | 
|---|
| 610 | break; | 
|---|
| 611 |  | 
|---|
| 612 | case EM_SETMODIFY16: | 
|---|
| 613 | DPRINTF_EDIT_MSG16("EM_SETMODIFY"); | 
|---|
| 614 | /* fall through */ | 
|---|
| 615 | case EM_SETMODIFY: | 
|---|
| 616 | DPRINTF_EDIT_MSG32("EM_SETMODIFY"); | 
|---|
| 617 | if (wParam) | 
|---|
| 618 | es->flags |= EF_MODIFIED; | 
|---|
| 619 | else | 
|---|
| 620 | es->flags &= ~(EF_MODIFIED | EF_UPDATE);  /* reset pending updates */ | 
|---|
| 621 | break; | 
|---|
| 622 |  | 
|---|
| 623 | case EM_GETLINECOUNT16: | 
|---|
| 624 | DPRINTF_EDIT_MSG16("EM_GETLINECOUNT"); | 
|---|
| 625 | /* fall through */ | 
|---|
| 626 | case EM_GETLINECOUNT: | 
|---|
| 627 | DPRINTF_EDIT_MSG32("EM_GETLINECOUNT"); | 
|---|
| 628 | result = (es->style & ES_MULTILINE) ? es->line_count : 1; | 
|---|
| 629 | break; | 
|---|
| 630 |  | 
|---|
| 631 | case EM_LINEINDEX16: | 
|---|
| 632 | DPRINTF_EDIT_MSG16("EM_LINEINDEX"); | 
|---|
| 633 | if ((INT16)wParam == -1) | 
|---|
| 634 | wParam = (WPARAM)-1; | 
|---|
| 635 | /* fall through */ | 
|---|
| 636 | case EM_LINEINDEX: | 
|---|
| 637 | DPRINTF_EDIT_MSG32("EM_LINEINDEX"); | 
|---|
| 638 | result = (LRESULT)EDIT_EM_LineIndex(es, (INT)wParam); | 
|---|
| 639 | #ifdef __WIN32OS2__ | 
|---|
| 640 | if( !unicode ) | 
|---|
| 641 | result = WideCharToMultiByte( CP_ACP, 0, es->text, result, 0, 0, 0, 0 ); | 
|---|
| 642 | #endif | 
|---|
| 643 | break; | 
|---|
| 644 |  | 
|---|
| 645 | #ifndef __WIN32OS2__ | 
|---|
| 646 | case EM_SETHANDLE16: | 
|---|
| 647 | DPRINTF_EDIT_MSG16("EM_SETHANDLE"); | 
|---|
| 648 | EDIT_EM_SetHandle16(hwnd, es, (HLOCAL16)wParam); | 
|---|
| 649 | break; | 
|---|
| 650 | #endif | 
|---|
| 651 | case EM_SETHANDLE: | 
|---|
| 652 | DPRINTF_EDIT_MSG32("EM_SETHANDLE"); | 
|---|
| 653 | EDIT_EM_SetHandle(hwnd, es, (HLOCAL)wParam); | 
|---|
| 654 | break; | 
|---|
| 655 |  | 
|---|
| 656 | #ifndef __WIN32OS2__ | 
|---|
| 657 | case EM_GETHANDLE16: | 
|---|
| 658 | DPRINTF_EDIT_MSG16("EM_GETHANDLE"); | 
|---|
| 659 | result = (LRESULT)EDIT_EM_GetHandle16(hwnd, es); | 
|---|
| 660 | break; | 
|---|
| 661 | #endif | 
|---|
| 662 | case EM_GETHANDLE: | 
|---|
| 663 | DPRINTF_EDIT_MSG32("EM_GETHANDLE"); | 
|---|
| 664 | result = (LRESULT)EDIT_EM_GetHandle(es); | 
|---|
| 665 | break; | 
|---|
| 666 |  | 
|---|
| 667 | case EM_GETTHUMB16: | 
|---|
| 668 | DPRINTF_EDIT_MSG16("EM_GETTHUMB"); | 
|---|
| 669 | /* fall through */ | 
|---|
| 670 | case EM_GETTHUMB: | 
|---|
| 671 | DPRINTF_EDIT_MSG32("EM_GETTHUMB"); | 
|---|
| 672 | result = EDIT_EM_GetThumb(hwnd, es); | 
|---|
| 673 | break; | 
|---|
| 674 |  | 
|---|
| 675 | /* messages 0x00bf and 0x00c0 missing from specs */ | 
|---|
| 676 |  | 
|---|
| 677 | case WM_USER+15: | 
|---|
| 678 | DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report"); | 
|---|
| 679 | /* fall through */ | 
|---|
| 680 | case 0x00bf: | 
|---|
| 681 | DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report"); | 
|---|
| 682 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 683 | break; | 
|---|
| 684 |  | 
|---|
| 685 | case WM_USER+16: | 
|---|
| 686 | DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report"); | 
|---|
| 687 | /* fall through */ | 
|---|
| 688 | case 0x00c0: | 
|---|
| 689 | DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report"); | 
|---|
| 690 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 691 | break; | 
|---|
| 692 |  | 
|---|
| 693 | case EM_LINELENGTH16: | 
|---|
| 694 | DPRINTF_EDIT_MSG16("EM_LINELENGTH"); | 
|---|
| 695 | /* fall through */ | 
|---|
| 696 | case EM_LINELENGTH: | 
|---|
| 697 | DPRINTF_EDIT_MSG32("EM_LINELENGTH"); | 
|---|
| 698 | #ifdef __WIN32OS2__ | 
|---|
| 699 | if( !unicode ) | 
|---|
| 700 | result = ( LRESULT )EDIT_EM_LineLengthA(es, (INT)wParam); | 
|---|
| 701 | else | 
|---|
| 702 | #endif | 
|---|
| 703 | result = (LRESULT)EDIT_EM_LineLength(es, (INT)wParam); | 
|---|
| 704 | break; | 
|---|
| 705 |  | 
|---|
| 706 | case EM_REPLACESEL16: | 
|---|
| 707 | DPRINTF_EDIT_MSG16("EM_REPLACESEL"); | 
|---|
| 708 | lParam = (LPARAM)MapSL(lParam); | 
|---|
| 709 | unicode = FALSE;  /* 16-bit message is always ascii */ | 
|---|
| 710 | /* fall through */ | 
|---|
| 711 | case EM_REPLACESEL: | 
|---|
| 712 | { | 
|---|
| 713 | LPWSTR textW; | 
|---|
| 714 | DPRINTF_EDIT_MSG32("EM_REPLACESEL"); | 
|---|
| 715 |  | 
|---|
| 716 | if(unicode) | 
|---|
| 717 | textW = (LPWSTR)lParam; | 
|---|
| 718 | else | 
|---|
| 719 | { | 
|---|
| 720 | LPSTR textA = (LPSTR)lParam; | 
|---|
| 721 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); | 
|---|
| 722 | if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))) != NULL) | 
|---|
| 723 | MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); | 
|---|
| 724 | } | 
|---|
| 725 |  | 
|---|
| 726 | EDIT_EM_ReplaceSel(hwnd, es, (BOOL)wParam, textW, TRUE); | 
|---|
| 727 | result = 1; | 
|---|
| 728 |  | 
|---|
| 729 | if(!unicode) | 
|---|
| 730 | HeapFree(GetProcessHeap(), 0, textW); | 
|---|
| 731 | break; | 
|---|
| 732 | } | 
|---|
| 733 | /* message 0x00c3 missing from specs */ | 
|---|
| 734 |  | 
|---|
| 735 | case WM_USER+19: | 
|---|
| 736 | DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report"); | 
|---|
| 737 | /* fall through */ | 
|---|
| 738 | case 0x00c3: | 
|---|
| 739 | DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report"); | 
|---|
| 740 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 741 | break; | 
|---|
| 742 |  | 
|---|
| 743 | case EM_GETLINE16: | 
|---|
| 744 | DPRINTF_EDIT_MSG16("EM_GETLINE"); | 
|---|
| 745 | lParam = (LPARAM)MapSL(lParam); | 
|---|
| 746 | unicode = FALSE;  /* 16-bit message is always ascii */ | 
|---|
| 747 | /* fall through */ | 
|---|
| 748 | case EM_GETLINE: | 
|---|
| 749 | DPRINTF_EDIT_MSG32("EM_GETLINE"); | 
|---|
| 750 | result = (LRESULT)EDIT_EM_GetLine(es, (INT)wParam, lParam, unicode); | 
|---|
| 751 | break; | 
|---|
| 752 |  | 
|---|
| 753 | case EM_LIMITTEXT16: | 
|---|
| 754 | DPRINTF_EDIT_MSG16("EM_LIMITTEXT"); | 
|---|
| 755 | /* fall through */ | 
|---|
| 756 | case EM_SETLIMITTEXT: | 
|---|
| 757 | DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT"); | 
|---|
| 758 | EDIT_EM_SetLimitText(es, (INT)wParam); | 
|---|
| 759 | break; | 
|---|
| 760 |  | 
|---|
| 761 | case EM_CANUNDO16: | 
|---|
| 762 | DPRINTF_EDIT_MSG16("EM_CANUNDO"); | 
|---|
| 763 | /* fall through */ | 
|---|
| 764 | case EM_CANUNDO: | 
|---|
| 765 | DPRINTF_EDIT_MSG32("EM_CANUNDO"); | 
|---|
| 766 | result = (LRESULT)EDIT_EM_CanUndo(es); | 
|---|
| 767 | break; | 
|---|
| 768 |  | 
|---|
| 769 | case EM_UNDO16: | 
|---|
| 770 | DPRINTF_EDIT_MSG16("EM_UNDO"); | 
|---|
| 771 | /* fall through */ | 
|---|
| 772 | case EM_UNDO: | 
|---|
| 773 | /* fall through */ | 
|---|
| 774 | case WM_UNDO: | 
|---|
| 775 | DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO"); | 
|---|
| 776 | result = (LRESULT)EDIT_EM_Undo(hwnd, es); | 
|---|
| 777 | break; | 
|---|
| 778 |  | 
|---|
| 779 | case EM_FMTLINES16: | 
|---|
| 780 | DPRINTF_EDIT_MSG16("EM_FMTLINES"); | 
|---|
| 781 | /* fall through */ | 
|---|
| 782 | case EM_FMTLINES: | 
|---|
| 783 | DPRINTF_EDIT_MSG32("EM_FMTLINES"); | 
|---|
| 784 | result = (LRESULT)EDIT_EM_FmtLines(es, (BOOL)wParam); | 
|---|
| 785 | break; | 
|---|
| 786 |  | 
|---|
| 787 | case EM_LINEFROMCHAR16: | 
|---|
| 788 | DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR"); | 
|---|
| 789 | /* fall through */ | 
|---|
| 790 | case EM_LINEFROMCHAR: | 
|---|
| 791 | DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR"); | 
|---|
| 792 | #ifdef __WIN32OS2__ | 
|---|
| 793 | if( !unicode && IsDBCSEnv() && ( INT )wParam != -1 ) | 
|---|
| 794 | { | 
|---|
| 795 | INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 ); | 
|---|
| 796 | LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA ); | 
|---|
| 797 |  | 
|---|
| 798 | if( textA ) | 
|---|
| 799 | { | 
|---|
| 800 | WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 ); | 
|---|
| 801 |  | 
|---|
| 802 | if(( INT )wParam > countA ) | 
|---|
| 803 | wParam = ( WPARAM )countA; | 
|---|
| 804 |  | 
|---|
| 805 | wParam = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )wParam, 0, 0 ); | 
|---|
| 806 |  | 
|---|
| 807 | HeapFree( GetProcessHeap(), 0, textA ); | 
|---|
| 808 | } | 
|---|
| 809 | } | 
|---|
| 810 | #endif | 
|---|
| 811 | result = (LRESULT)EDIT_EM_LineFromChar(es, (INT)wParam); | 
|---|
| 812 | break; | 
|---|
| 813 |  | 
|---|
| 814 | /* message 0x00ca missing from specs */ | 
|---|
| 815 |  | 
|---|
| 816 | case WM_USER+26: | 
|---|
| 817 | DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report"); | 
|---|
| 818 | /* fall through */ | 
|---|
| 819 | case 0x00ca: | 
|---|
| 820 | DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report"); | 
|---|
| 821 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 822 | break; | 
|---|
| 823 |  | 
|---|
| 824 | case EM_SETTABSTOPS16: | 
|---|
| 825 | DPRINTF_EDIT_MSG16("EM_SETTABSTOPS"); | 
|---|
| 826 | result = (LRESULT)EDIT_EM_SetTabStops16(es, (INT)wParam, (LPINT16)MapSL(lParam)); | 
|---|
| 827 | break; | 
|---|
| 828 | case EM_SETTABSTOPS: | 
|---|
| 829 | DPRINTF_EDIT_MSG32("EM_SETTABSTOPS"); | 
|---|
| 830 | result = (LRESULT)EDIT_EM_SetTabStops(es, (INT)wParam, (LPINT)lParam); | 
|---|
| 831 | break; | 
|---|
| 832 |  | 
|---|
| 833 | case EM_SETPASSWORDCHAR16: | 
|---|
| 834 | DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR"); | 
|---|
| 835 | unicode = FALSE;  /* 16-bit message is always ascii */ | 
|---|
| 836 | /* fall through */ | 
|---|
| 837 | case EM_SETPASSWORDCHAR: | 
|---|
| 838 | { | 
|---|
| 839 | WCHAR charW = 0; | 
|---|
| 840 | DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR"); | 
|---|
| 841 |  | 
|---|
| 842 | if(unicode) | 
|---|
| 843 | charW = (WCHAR)wParam; | 
|---|
| 844 | else | 
|---|
| 845 | { | 
|---|
| 846 | CHAR charA = wParam; | 
|---|
| 847 | MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1); | 
|---|
| 848 | } | 
|---|
| 849 |  | 
|---|
| 850 | EDIT_EM_SetPasswordChar(hwnd, es, charW); | 
|---|
| 851 | break; | 
|---|
| 852 | } | 
|---|
| 853 |  | 
|---|
| 854 | case EM_EMPTYUNDOBUFFER16: | 
|---|
| 855 | DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER"); | 
|---|
| 856 | /* fall through */ | 
|---|
| 857 | case EM_EMPTYUNDOBUFFER: | 
|---|
| 858 | DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER"); | 
|---|
| 859 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 860 | break; | 
|---|
| 861 |  | 
|---|
| 862 | case EM_GETFIRSTVISIBLELINE16: | 
|---|
| 863 | DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE"); | 
|---|
| 864 | result = es->y_offset; | 
|---|
| 865 | break; | 
|---|
| 866 | case EM_GETFIRSTVISIBLELINE: | 
|---|
| 867 | DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE"); | 
|---|
| 868 | result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset; | 
|---|
| 869 | break; | 
|---|
| 870 |  | 
|---|
| 871 | case EM_SETREADONLY16: | 
|---|
| 872 | DPRINTF_EDIT_MSG16("EM_SETREADONLY"); | 
|---|
| 873 | /* fall through */ | 
|---|
| 874 | case EM_SETREADONLY: | 
|---|
| 875 | DPRINTF_EDIT_MSG32("EM_SETREADONLY"); | 
|---|
| 876 | if (wParam) { | 
|---|
| 877 | SetWindowLongA( hwnd, GWL_STYLE, | 
|---|
| 878 | GetWindowLongA( hwnd, GWL_STYLE ) | ES_READONLY ); | 
|---|
| 879 | es->style |= ES_READONLY; | 
|---|
| 880 | } else { | 
|---|
| 881 | SetWindowLongA( hwnd, GWL_STYLE, | 
|---|
| 882 | GetWindowLongA( hwnd, GWL_STYLE ) & ~ES_READONLY ); | 
|---|
| 883 | es->style &= ~ES_READONLY; | 
|---|
| 884 | } | 
|---|
| 885 | result = 1; | 
|---|
| 886 | break; | 
|---|
| 887 | #ifndef __WIN32OS2__ | 
|---|
| 888 | case EM_SETWORDBREAKPROC16: | 
|---|
| 889 | DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC"); | 
|---|
| 890 | EDIT_EM_SetWordBreakProc16(hwnd, es, (EDITWORDBREAKPROC16)lParam); | 
|---|
| 891 | break; | 
|---|
| 892 | #endif | 
|---|
| 893 | case EM_SETWORDBREAKPROC: | 
|---|
| 894 | DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC"); | 
|---|
| 895 | EDIT_EM_SetWordBreakProc(hwnd, es, lParam); | 
|---|
| 896 | break; | 
|---|
| 897 |  | 
|---|
| 898 | case EM_GETWORDBREAKPROC16: | 
|---|
| 899 | DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC"); | 
|---|
| 900 | result = (LRESULT)es->word_break_proc16; | 
|---|
| 901 | break; | 
|---|
| 902 | case EM_GETWORDBREAKPROC: | 
|---|
| 903 | DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC"); | 
|---|
| 904 | result = (LRESULT)es->word_break_proc; | 
|---|
| 905 | break; | 
|---|
| 906 |  | 
|---|
| 907 | case EM_GETPASSWORDCHAR16: | 
|---|
| 908 | DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR"); | 
|---|
| 909 | unicode = FALSE;  /* 16-bit message is always ascii */ | 
|---|
| 910 | /* fall through */ | 
|---|
| 911 | case EM_GETPASSWORDCHAR: | 
|---|
| 912 | { | 
|---|
| 913 | DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR"); | 
|---|
| 914 |  | 
|---|
| 915 | if(unicode) | 
|---|
| 916 | result = es->password_char; | 
|---|
| 917 | else | 
|---|
| 918 | { | 
|---|
| 919 | WCHAR charW = es->password_char; | 
|---|
| 920 | CHAR charA = 0; | 
|---|
| 921 | WideCharToMultiByte(CP_ACP, 0, &charW, 1, &charA, 1, NULL, NULL); | 
|---|
| 922 | result = charA; | 
|---|
| 923 | } | 
|---|
| 924 | break; | 
|---|
| 925 | } | 
|---|
| 926 |  | 
|---|
| 927 | /* The following EM_xxx are new to win95 and don't exist for 16 bit */ | 
|---|
| 928 |  | 
|---|
| 929 | case EM_SETMARGINS: | 
|---|
| 930 | DPRINTF_EDIT_MSG32("EM_SETMARGINS"); | 
|---|
| 931 | EDIT_EM_SetMargins(es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 932 | break; | 
|---|
| 933 |  | 
|---|
| 934 | case EM_GETMARGINS: | 
|---|
| 935 | DPRINTF_EDIT_MSG32("EM_GETMARGINS"); | 
|---|
| 936 | result = MAKELONG(es->left_margin, es->right_margin); | 
|---|
| 937 | break; | 
|---|
| 938 |  | 
|---|
| 939 | case EM_GETLIMITTEXT: | 
|---|
| 940 | DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT"); | 
|---|
| 941 | result = es->buffer_limit; | 
|---|
| 942 | break; | 
|---|
| 943 |  | 
|---|
| 944 | case EM_POSFROMCHAR: | 
|---|
| 945 | DPRINTF_EDIT_MSG32("EM_POSFROMCHAR"); | 
|---|
| 946 | #ifdef __WIN32OS2__ | 
|---|
| 947 | if( !unicode && IsDBCSEnv() ) | 
|---|
| 948 | { | 
|---|
| 949 | INT countA = WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 ); | 
|---|
| 950 | LPSTR textA = HeapAlloc( GetProcessHeap(), 0, countA ); | 
|---|
| 951 |  | 
|---|
| 952 | if( textA ) | 
|---|
| 953 | { | 
|---|
| 954 | WideCharToMultiByte( CP_ACP, 0, es->text, -1, textA, countA, 0, 0 ); | 
|---|
| 955 |  | 
|---|
| 956 | if(( INT )wParam > countA ) | 
|---|
| 957 | wParam = ( WPARAM ) countA; | 
|---|
| 958 | wParam = ( WPARAM )MultiByteToWideChar( CP_ACP, 0, textA, ( INT )wParam, 0, 0 ); | 
|---|
| 959 |  | 
|---|
| 960 | HeapFree( GetProcessHeap(), 0, textA ); | 
|---|
| 961 | } | 
|---|
| 962 | } | 
|---|
| 963 | #endif | 
|---|
| 964 | result = EDIT_EM_PosFromChar(hwnd, es, (INT)wParam, FALSE); | 
|---|
| 965 | break; | 
|---|
| 966 |  | 
|---|
| 967 | case EM_CHARFROMPOS: | 
|---|
| 968 | DPRINTF_EDIT_MSG32("EM_CHARFROMPOS"); | 
|---|
| 969 | result = EDIT_EM_CharFromPos(hwnd, es, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 970 | #ifdef __WIN32OS2__ | 
|---|
| 971 | if( !unicode ) | 
|---|
| 972 | { | 
|---|
| 973 | WORD wLo = LOWORD( result ); | 
|---|
| 974 | WORD wHi = HIWORD( result ); | 
|---|
| 975 |  | 
|---|
| 976 | wLo = WideCharToMultiByte( CP_ACP, 0, es->text, wLo, 0, 0, 0, 0 ); | 
|---|
| 977 | wHi = WideCharToMultiByte( CP_ACP, 0, es->text, wHi, 0, 0, 0, 0 ); | 
|---|
| 978 | result = ( LRESULT )MAKELONG( wLo, wHi ); | 
|---|
| 979 | } | 
|---|
| 980 | #endif | 
|---|
| 981 | break; | 
|---|
| 982 |  | 
|---|
| 983 | /* End of the EM_ messages which were in numerical order; what order | 
|---|
| 984 | * are these in?  vaguely alphabetical? | 
|---|
| 985 | */ | 
|---|
| 986 |  | 
|---|
| 987 | case WM_GETDLGCODE: | 
|---|
| 988 | DPRINTF_EDIT_MSG32("WM_GETDLGCODE"); | 
|---|
| 989 | result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS; | 
|---|
| 990 |  | 
|---|
| 991 | if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN)) | 
|---|
| 992 | { | 
|---|
| 993 | int vk = (int)((LPMSG)lParam)->wParam; | 
|---|
| 994 |  | 
|---|
| 995 | if (vk == VK_RETURN && (GetWindowLongA( hwnd, GWL_STYLE ) & ES_WANTRETURN)) | 
|---|
| 996 | { | 
|---|
| 997 | result |= DLGC_WANTMESSAGE; | 
|---|
| 998 | } | 
|---|
| 999 | else if (es->hwndListBox && (vk == VK_RETURN || vk == VK_ESCAPE)) | 
|---|
| 1000 | { | 
|---|
| 1001 | if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0)) | 
|---|
| 1002 | result |= DLGC_WANTMESSAGE; | 
|---|
| 1003 | } | 
|---|
| 1004 | } | 
|---|
| 1005 | break; | 
|---|
| 1006 |  | 
|---|
| 1007 | case WM_CHAR: | 
|---|
| 1008 | { | 
|---|
| 1009 | WCHAR charW; | 
|---|
| 1010 | DPRINTF_EDIT_MSG32("WM_CHAR"); | 
|---|
| 1011 |  | 
|---|
| 1012 | if(unicode) | 
|---|
| 1013 | charW = wParam; | 
|---|
| 1014 | else | 
|---|
| 1015 | { | 
|---|
| 1016 | CHAR charA = wParam; | 
|---|
| 1017 | MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1); | 
|---|
| 1018 | } | 
|---|
| 1019 |  | 
|---|
| 1020 | if ((charW == VK_RETURN || charW == VK_ESCAPE) && es->hwndListBox) | 
|---|
| 1021 | { | 
|---|
| 1022 | if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0)) | 
|---|
| 1023 | SendMessageW(GetParent(hwnd), WM_KEYDOWN, charW, 0); | 
|---|
| 1024 | break; | 
|---|
| 1025 | } | 
|---|
| 1026 | EDIT_WM_Char(hwnd, es, charW); | 
|---|
| 1027 | break; | 
|---|
| 1028 | } | 
|---|
| 1029 |  | 
|---|
| 1030 | case WM_CLEAR: | 
|---|
| 1031 | DPRINTF_EDIT_MSG32("WM_CLEAR"); | 
|---|
| 1032 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 1033 | break; | 
|---|
| 1034 |  | 
|---|
| 1035 | case WM_COMMAND: | 
|---|
| 1036 | DPRINTF_EDIT_MSG32("WM_COMMAND"); | 
|---|
| 1037 | EDIT_WM_Command(hwnd, es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam); | 
|---|
| 1038 | break; | 
|---|
| 1039 |  | 
|---|
| 1040 | case WM_CONTEXTMENU: | 
|---|
| 1041 | DPRINTF_EDIT_MSG32("WM_CONTEXTMENU"); | 
|---|
| 1042 | EDIT_WM_ContextMenu(hwnd, es, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 1043 | break; | 
|---|
| 1044 |  | 
|---|
| 1045 | case WM_COPY: | 
|---|
| 1046 | DPRINTF_EDIT_MSG32("WM_COPY"); | 
|---|
| 1047 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 1048 | break; | 
|---|
| 1049 |  | 
|---|
| 1050 | case WM_CREATE: | 
|---|
| 1051 | DPRINTF_EDIT_MSG32("WM_CREATE"); | 
|---|
| 1052 | if(unicode) | 
|---|
| 1053 | result = EDIT_WM_Create(hwnd, es, ((LPCREATESTRUCTW)lParam)->lpszName); | 
|---|
| 1054 | else | 
|---|
| 1055 | { | 
|---|
| 1056 | LPCSTR nameA = ((LPCREATESTRUCTA)lParam)->lpszName; | 
|---|
| 1057 | LPWSTR nameW = NULL; | 
|---|
| 1058 | if(nameA) | 
|---|
| 1059 | { | 
|---|
| 1060 | INT countW = MultiByteToWideChar(CP_ACP, 0, nameA, -1, NULL, 0); | 
|---|
| 1061 | if((nameW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))) != NULL) | 
|---|
| 1062 | MultiByteToWideChar(CP_ACP, 0, nameA, -1, nameW, countW); | 
|---|
| 1063 | } | 
|---|
| 1064 | result = EDIT_WM_Create(hwnd, es, nameW); | 
|---|
| 1065 | if(nameW) | 
|---|
| 1066 | HeapFree(GetProcessHeap(), 0, nameW); | 
|---|
| 1067 | } | 
|---|
| 1068 | break; | 
|---|
| 1069 |  | 
|---|
| 1070 | case WM_CUT: | 
|---|
| 1071 | DPRINTF_EDIT_MSG32("WM_CUT"); | 
|---|
| 1072 | EDIT_WM_Cut(hwnd, es); | 
|---|
| 1073 | break; | 
|---|
| 1074 |  | 
|---|
| 1075 | case WM_ENABLE: | 
|---|
| 1076 | DPRINTF_EDIT_MSG32("WM_ENABLE"); | 
|---|
| 1077 | es->bEnableState = (BOOL) wParam; | 
|---|
| 1078 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 1079 | break; | 
|---|
| 1080 |  | 
|---|
| 1081 | case WM_ERASEBKGND: | 
|---|
| 1082 | DPRINTF_EDIT_MSG32("WM_ERASEBKGND"); | 
|---|
| 1083 | result = EDIT_WM_EraseBkGnd(hwnd, es, (HDC)wParam); | 
|---|
| 1084 | break; | 
|---|
| 1085 |  | 
|---|
| 1086 | case WM_GETFONT: | 
|---|
| 1087 | DPRINTF_EDIT_MSG32("WM_GETFONT"); | 
|---|
| 1088 | result = (LRESULT)es->font; | 
|---|
| 1089 | break; | 
|---|
| 1090 |  | 
|---|
| 1091 | case WM_GETTEXT: | 
|---|
| 1092 | DPRINTF_EDIT_MSG32("WM_GETTEXT"); | 
|---|
| 1093 | result = (LRESULT)EDIT_WM_GetText(es, (INT)wParam, lParam, unicode); | 
|---|
| 1094 | break; | 
|---|
| 1095 |  | 
|---|
| 1096 | case WM_GETTEXTLENGTH: | 
|---|
| 1097 | DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH"); | 
|---|
| 1098 | result = strlenW(es->text); | 
|---|
| 1099 | #ifdef __WIN32OS2__ | 
|---|
| 1100 | if( !unicode ) | 
|---|
| 1101 | result = WideCharToMultiByte( CP_ACP, 0, es->text, result, 0, 0, 0, 0 ); | 
|---|
| 1102 | #endif | 
|---|
| 1103 | break; | 
|---|
| 1104 |  | 
|---|
| 1105 | case WM_HSCROLL: | 
|---|
| 1106 | DPRINTF_EDIT_MSG32("WM_HSCROLL"); | 
|---|
| 1107 | result = EDIT_WM_HScroll(hwnd, es, LOWORD(wParam), SHIWORD(wParam)); | 
|---|
| 1108 | break; | 
|---|
| 1109 |  | 
|---|
| 1110 | #ifdef __WIN32OS2__ | 
|---|
| 1111 | case WM_IME_CHAR: | 
|---|
| 1112 | { | 
|---|
| 1113 | WCHAR charW; | 
|---|
| 1114 | DPRINTF_EDIT_MSG32("WM_IME_CHAR"); | 
|---|
| 1115 |  | 
|---|
| 1116 | if(unicode) | 
|---|
| 1117 | charW = wParam; | 
|---|
| 1118 | else | 
|---|
| 1119 | { | 
|---|
| 1120 | // always DBCS char | 
|---|
| 1121 | CHAR charA[ 2 ]; | 
|---|
| 1122 | INT  lenA = 1; | 
|---|
| 1123 |  | 
|---|
| 1124 | if( IsDBCSLeadByte(( CHAR )( wParam >> 8 ))) | 
|---|
| 1125 | { | 
|---|
| 1126 | charA[ 0 ] = ( CHAR )( wParam >> 8 ); | 
|---|
| 1127 | charA[ 1 ] = ( CHAR )wParam; | 
|---|
| 1128 | lenA = 2; | 
|---|
| 1129 | } | 
|---|
| 1130 | else | 
|---|
| 1131 | charA[ 0 ] = ( CHAR )wParam; | 
|---|
| 1132 |  | 
|---|
| 1133 | MultiByteToWideChar( CP_ACP, 0, ( LPSTR )charA, lenA, ( LPWSTR )&charW, 1); | 
|---|
| 1134 | } | 
|---|
| 1135 |  | 
|---|
| 1136 | EDIT_WM_Char(hwnd, es, charW); | 
|---|
| 1137 | break; | 
|---|
| 1138 | } | 
|---|
| 1139 |  | 
|---|
| 1140 | case WM_IME_COMPOSITION: | 
|---|
| 1141 | { | 
|---|
| 1142 | HIMC    himc; | 
|---|
| 1143 | LONG    bufSize; | 
|---|
| 1144 | INT     i; | 
|---|
| 1145 | BOOL    passToDefWnd = FALSE; | 
|---|
| 1146 | #ifdef DEBUG | 
|---|
| 1147 | LPSTR   strA; | 
|---|
| 1148 | INT     lenA; | 
|---|
| 1149 | #endif | 
|---|
| 1150 |  | 
|---|
| 1151 | DPRINTF_EDIT_MSG32("WM_IME_COMPOSITION"); | 
|---|
| 1152 |  | 
|---|
| 1153 | himc = ImmGetContext( hwnd ); | 
|---|
| 1154 |  | 
|---|
| 1155 | if( es->sentenceMode ) | 
|---|
| 1156 | passToDefWnd = TRUE; | 
|---|
| 1157 | else if( lParam & GCS_RESULTSTR ) | 
|---|
| 1158 | { | 
|---|
| 1159 | LPWSTR  resultStr = NULL; | 
|---|
| 1160 | INT     resultStrLen = 0; | 
|---|
| 1161 |  | 
|---|
| 1162 | dprintf(("WM_IME_COMPOSITION : GCS_RESULTSTR")); | 
|---|
| 1163 |  | 
|---|
| 1164 | bufSize = ImmGetCompositionStringW( himc, GCS_RESULTSTR, NULL, 0 ); | 
|---|
| 1165 | if( bufSize > 0 ) | 
|---|
| 1166 | { | 
|---|
| 1167 | INT i; | 
|---|
| 1168 |  | 
|---|
| 1169 | resultStrLen = bufSize / sizeof( WCHAR ); | 
|---|
| 1170 | resultStr = malloc( bufSize + sizeof( WCHAR )); | 
|---|
| 1171 | resultStr[ resultStrLen ] = 0; | 
|---|
| 1172 |  | 
|---|
| 1173 | ImmGetCompositionStringW( himc, GCS_RESULTSTR, resultStr, bufSize ); | 
|---|
| 1174 |  | 
|---|
| 1175 | #ifdef DEBUG | 
|---|
| 1176 | lenA = WideCharToMultiByte( CP_ACP, 0, resultStr, resultStrLen, 0, 0, 0, 0 ); | 
|---|
| 1177 | strA = malloc( lenA + 1 ); | 
|---|
| 1178 | WideCharToMultiByte( CP_ACP, 0, resultStr, resultStrLen, strA, lenA, 0, 0 ); | 
|---|
| 1179 | strA[ lenA ] = 0; | 
|---|
| 1180 | dprintf(("Result String : '%s'", strA )); | 
|---|
| 1181 | free( strA ); | 
|---|
| 1182 | dprintf(("Composition Len %d", es->compStrLen )); | 
|---|
| 1183 | #endif | 
|---|
| 1184 | DestroyCaret(); | 
|---|
| 1185 | if( es->compStrLen > 0 ) | 
|---|
| 1186 | { | 
|---|
| 1187 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 1188 | for( i = 0; i < es->compStrLen; i++ ) | 
|---|
| 1189 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 1190 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 1191 | } | 
|---|
| 1192 |  | 
|---|
| 1193 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, resultStr, TRUE); | 
|---|
| 1194 |  | 
|---|
| 1195 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 1196 | EDIT_SetCaretPos(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); | 
|---|
| 1197 | ShowCaret(hwnd); | 
|---|
| 1198 |  | 
|---|
| 1199 | free( resultStr ); | 
|---|
| 1200 |  | 
|---|
| 1201 | } | 
|---|
| 1202 |  | 
|---|
| 1203 | if( es->compStr ) | 
|---|
| 1204 | free( es->compStr ); | 
|---|
| 1205 |  | 
|---|
| 1206 | es->compStr = NULL; | 
|---|
| 1207 | es->compStrLen = 0; | 
|---|
| 1208 | } | 
|---|
| 1209 | else if( lParam & GCS_COMPSTR ) | 
|---|
| 1210 | { | 
|---|
| 1211 | INT prevLen = es->compStrLen; | 
|---|
| 1212 |  | 
|---|
| 1213 | dprintf(("WM_IME_COMPOSITION : GCS_COMPSTR")); | 
|---|
| 1214 |  | 
|---|
| 1215 | if( es->compStr ) | 
|---|
| 1216 | free( es->compStr ); | 
|---|
| 1217 |  | 
|---|
| 1218 | es->compStr = NULL; | 
|---|
| 1219 | es->compStrLen = 0; | 
|---|
| 1220 |  | 
|---|
| 1221 | bufSize = ImmGetCompositionStringW( himc, GCS_COMPSTR, NULL, 0 ); | 
|---|
| 1222 | if( bufSize > 0 ) | 
|---|
| 1223 | { | 
|---|
| 1224 | HDC     hdc; | 
|---|
| 1225 | SIZE    size; | 
|---|
| 1226 | BOOL    oldMoveCaret; | 
|---|
| 1227 |  | 
|---|
| 1228 | es->compStrLen = bufSize / sizeof( WCHAR ); | 
|---|
| 1229 | es->compStr = malloc( bufSize + sizeof( WCHAR )); | 
|---|
| 1230 | es->compStr[ es->compStrLen ] = 0; | 
|---|
| 1231 |  | 
|---|
| 1232 | ImmGetCompositionStringW( himc, GCS_COMPSTR, es->compStr, bufSize ); | 
|---|
| 1233 |  | 
|---|
| 1234 | #ifdef DEBUG | 
|---|
| 1235 | lenA = WideCharToMultiByte( CP_ACP, 0, es->compStr, es->compStrLen, 0, 0, 0, 0 ); | 
|---|
| 1236 | strA = malloc( lenA + 1 ); | 
|---|
| 1237 | WideCharToMultiByte( CP_ACP, 0, es->compStr, es->compStrLen, strA, lenA, 0, 0  ); | 
|---|
| 1238 | strA[ lenA ] = 0; | 
|---|
| 1239 | dprintf(("Composition String : '%s'", strA )); | 
|---|
| 1240 | free( strA ); | 
|---|
| 1241 | #endif | 
|---|
| 1242 | hdc = GetDC( hwnd ); | 
|---|
| 1243 | GetTextExtentPoint32W( hdc, es->compStr, es->compStrLen, &size); | 
|---|
| 1244 | ReleaseDC( hwnd, hdc ); | 
|---|
| 1245 |  | 
|---|
| 1246 | oldMoveCaret = es->moveCaret; | 
|---|
| 1247 |  | 
|---|
| 1248 | es->moveCaret = FALSE; // to prevent cursor from flashing too many | 
|---|
| 1249 |  | 
|---|
| 1250 | if( prevLen > 0 ) | 
|---|
| 1251 | { | 
|---|
| 1252 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 1253 | for( i = 0; i < prevLen; i++ ) | 
|---|
| 1254 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 1255 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 1256 | } | 
|---|
| 1257 |  | 
|---|
| 1258 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, es->compStr, TRUE); | 
|---|
| 1259 |  | 
|---|
| 1260 | for( i = 0; i < es->compStrLen; i++ ) | 
|---|
| 1261 | EDIT_MoveBackward(hwnd, es, FALSE); | 
|---|
| 1262 |  | 
|---|
| 1263 | es->moveCaret = oldMoveCaret; | 
|---|
| 1264 |  | 
|---|
| 1265 | CreateCaret(hwnd, 0, size.cx, es->line_height); | 
|---|
| 1266 | EDIT_SetCaretPos(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); | 
|---|
| 1267 | ShowCaret(hwnd); | 
|---|
| 1268 | } | 
|---|
| 1269 | } | 
|---|
| 1270 | else | 
|---|
| 1271 | passToDefWnd = TRUE; | 
|---|
| 1272 |  | 
|---|
| 1273 | ImmReleaseContext( hwnd, himc ); | 
|---|
| 1274 |  | 
|---|
| 1275 | if( passToDefWnd ) | 
|---|
| 1276 | { | 
|---|
| 1277 | if( unicode ) | 
|---|
| 1278 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1279 | else | 
|---|
| 1280 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1281 | } | 
|---|
| 1282 | break; | 
|---|
| 1283 | } | 
|---|
| 1284 |  | 
|---|
| 1285 | case WM_IME_COMPOSITIONFULL: | 
|---|
| 1286 | DPRINTF_EDIT_MSG32("WM_IME_COMPOSITIONFULL"); | 
|---|
| 1287 | if( unicode ) | 
|---|
| 1288 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1289 | else | 
|---|
| 1290 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1291 | break; | 
|---|
| 1292 |  | 
|---|
| 1293 | case WM_IME_CONTROL: | 
|---|
| 1294 | DPRINTF_EDIT_MSG32("WM_IME_CONTROL"); | 
|---|
| 1295 | if( unicode ) | 
|---|
| 1296 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1297 | else | 
|---|
| 1298 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1299 | break; | 
|---|
| 1300 |  | 
|---|
| 1301 | case WM_IME_ENDCOMPOSITION: | 
|---|
| 1302 | DPRINTF_EDIT_MSG32("WM_IME_ENDCOMPOSITION"); | 
|---|
| 1303 |  | 
|---|
| 1304 | if( es->compStr ) | 
|---|
| 1305 | { | 
|---|
| 1306 | INT i; | 
|---|
| 1307 |  | 
|---|
| 1308 | DestroyCaret(); | 
|---|
| 1309 |  | 
|---|
| 1310 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 1311 | for( i = 0; i < es->compStrLen; i++ ) | 
|---|
| 1312 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 1313 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 1314 |  | 
|---|
| 1315 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 1316 | EDIT_SetCaretPos(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); | 
|---|
| 1317 | ShowCaret(hwnd); | 
|---|
| 1318 |  | 
|---|
| 1319 | free( es->compStr ); | 
|---|
| 1320 | } | 
|---|
| 1321 |  | 
|---|
| 1322 | es->compStr = NULL; | 
|---|
| 1323 | es->compStrLen = 0; | 
|---|
| 1324 |  | 
|---|
| 1325 | if( unicode ) | 
|---|
| 1326 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1327 | else | 
|---|
| 1328 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1329 | break; | 
|---|
| 1330 |  | 
|---|
| 1331 | case WM_IME_NOTIFY: | 
|---|
| 1332 | DPRINTF_EDIT_MSG32("WM_IME_NOTIFY"); | 
|---|
| 1333 |  | 
|---|
| 1334 | if( wParam == IMN_SETSENTENCEMODE ) | 
|---|
| 1335 | { | 
|---|
| 1336 | HIMC  himc; | 
|---|
| 1337 | DWORD conversionMode; | 
|---|
| 1338 |  | 
|---|
| 1339 | himc = ImmGetContext( hwnd ); | 
|---|
| 1340 |  | 
|---|
| 1341 | ImmGetConversionStatus( himc, &conversionMode, &es->sentenceMode ); | 
|---|
| 1342 |  | 
|---|
| 1343 | ImmReleaseContext( hwnd, himc ); | 
|---|
| 1344 | } | 
|---|
| 1345 |  | 
|---|
| 1346 | if( unicode ) | 
|---|
| 1347 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1348 | else | 
|---|
| 1349 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1350 | break; | 
|---|
| 1351 |  | 
|---|
| 1352 | case WM_IME_REQUEST: | 
|---|
| 1353 | DPRINTF_EDIT_MSG32("WM_IME_REQUEST"); | 
|---|
| 1354 | if( unicode ) | 
|---|
| 1355 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1356 | else | 
|---|
| 1357 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1358 | break; | 
|---|
| 1359 |  | 
|---|
| 1360 | case WM_IME_SELECT: | 
|---|
| 1361 | DPRINTF_EDIT_MSG32("WM_IME_SELECT"); | 
|---|
| 1362 | if( unicode ) | 
|---|
| 1363 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1364 | else | 
|---|
| 1365 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1366 | break; | 
|---|
| 1367 |  | 
|---|
| 1368 | case WM_IME_SETCONTEXT: | 
|---|
| 1369 | DPRINTF_EDIT_MSG32("WM_IME_SETCONTEXT"); | 
|---|
| 1370 |  | 
|---|
| 1371 | dprintf(("ImmGetProperty %08lx", ImmGetProperty( 0, IGP_CONVERSION ))); | 
|---|
| 1372 |  | 
|---|
| 1373 | if( unicode ) | 
|---|
| 1374 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1375 | else | 
|---|
| 1376 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1377 | break; | 
|---|
| 1378 |  | 
|---|
| 1379 | case WM_IME_STARTCOMPOSITION: | 
|---|
| 1380 | DPRINTF_EDIT_MSG32("WM_IME_STARTCOMPOSITION"); | 
|---|
| 1381 |  | 
|---|
| 1382 | es->compStr = NULL; | 
|---|
| 1383 | es->compStrLen = 0; | 
|---|
| 1384 |  | 
|---|
| 1385 | if( unicode ) | 
|---|
| 1386 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1387 | else | 
|---|
| 1388 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1389 | break; | 
|---|
| 1390 |  | 
|---|
| 1391 | case EM_GETIMESTATUS: | 
|---|
| 1392 | DPRINTF_EDIT_MSG32("EM_GETIMESTATUS"); | 
|---|
| 1393 | if( unicode ) | 
|---|
| 1394 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1395 | else | 
|---|
| 1396 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1397 | break; | 
|---|
| 1398 |  | 
|---|
| 1399 | case EM_SETIMESTATUS: | 
|---|
| 1400 | DPRINTF_EDIT_MSG32("EM_SETIMESTATUS"); | 
|---|
| 1401 | if( unicode ) | 
|---|
| 1402 | result = DefWindowProcW( hwnd, msg, wParam, lParam ); | 
|---|
| 1403 | else | 
|---|
| 1404 | result = DefWindowProcA( hwnd, msg, wParam, lParam ); | 
|---|
| 1405 | break; | 
|---|
| 1406 | #endif | 
|---|
| 1407 |  | 
|---|
| 1408 | case WM_KEYDOWN: | 
|---|
| 1409 | DPRINTF_EDIT_MSG32("WM_KEYDOWN"); | 
|---|
| 1410 | result = EDIT_WM_KeyDown(hwnd, es, (INT)wParam); | 
|---|
| 1411 | break; | 
|---|
| 1412 |  | 
|---|
| 1413 | case WM_KILLFOCUS: | 
|---|
| 1414 | DPRINTF_EDIT_MSG32("WM_KILLFOCUS"); | 
|---|
| 1415 | result = EDIT_WM_KillFocus(hwnd, es); | 
|---|
| 1416 | break; | 
|---|
| 1417 |  | 
|---|
| 1418 | case WM_LBUTTONDBLCLK: | 
|---|
| 1419 | DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK"); | 
|---|
| 1420 | result = EDIT_WM_LButtonDblClk(hwnd, es); | 
|---|
| 1421 | break; | 
|---|
| 1422 |  | 
|---|
| 1423 | case WM_LBUTTONDOWN: | 
|---|
| 1424 | DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN"); | 
|---|
| 1425 | result = EDIT_WM_LButtonDown(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 1426 | break; | 
|---|
| 1427 |  | 
|---|
| 1428 | case WM_LBUTTONUP: | 
|---|
| 1429 | DPRINTF_EDIT_MSG32("WM_LBUTTONUP"); | 
|---|
| 1430 | result = EDIT_WM_LButtonUp(hwnd, es); | 
|---|
| 1431 | break; | 
|---|
| 1432 |  | 
|---|
| 1433 | case WM_MBUTTONDOWN: | 
|---|
| 1434 | DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN"); | 
|---|
| 1435 | result = EDIT_WM_MButtonDown(hwnd); | 
|---|
| 1436 | break; | 
|---|
| 1437 |  | 
|---|
| 1438 | case WM_MOUSEACTIVATE: | 
|---|
| 1439 | /* | 
|---|
| 1440 | *  FIXME: maybe DefWindowProc() screws up, but it seems that | 
|---|
| 1441 | *      modeless dialog boxes need this.  If we don't do this, the focus | 
|---|
| 1442 | *      will _not_ be set by DefWindowProc() for edit controls in a | 
|---|
| 1443 | *      modeless dialog box ??? | 
|---|
| 1444 | */ | 
|---|
| 1445 | DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE"); | 
|---|
| 1446 | SetFocus(hwnd); | 
|---|
| 1447 | result = MA_ACTIVATE; | 
|---|
| 1448 | break; | 
|---|
| 1449 |  | 
|---|
| 1450 | case WM_MOUSEMOVE: | 
|---|
| 1451 | /* | 
|---|
| 1452 | *  DPRINTF_EDIT_MSG32("WM_MOUSEMOVE"); | 
|---|
| 1453 | */ | 
|---|
| 1454 | result = EDIT_WM_MouseMove(hwnd, es, SLOWORD(lParam), SHIWORD(lParam)); | 
|---|
| 1455 | break; | 
|---|
| 1456 |  | 
|---|
| 1457 | case WM_PAINT: | 
|---|
| 1458 | DPRINTF_EDIT_MSG32("WM_PAINT"); | 
|---|
| 1459 | EDIT_WM_Paint(hwnd, es, wParam); | 
|---|
| 1460 | break; | 
|---|
| 1461 |  | 
|---|
| 1462 | case WM_PASTE: | 
|---|
| 1463 | DPRINTF_EDIT_MSG32("WM_PASTE"); | 
|---|
| 1464 | EDIT_WM_Paste(hwnd, es); | 
|---|
| 1465 | break; | 
|---|
| 1466 |  | 
|---|
| 1467 | case WM_SETFOCUS: | 
|---|
| 1468 | DPRINTF_EDIT_MSG32("WM_SETFOCUS"); | 
|---|
| 1469 | EDIT_WM_SetFocus(hwnd, es); | 
|---|
| 1470 | break; | 
|---|
| 1471 |  | 
|---|
| 1472 | case WM_SETFONT: | 
|---|
| 1473 | DPRINTF_EDIT_MSG32("WM_SETFONT"); | 
|---|
| 1474 | EDIT_WM_SetFont(hwnd, es, (HFONT)wParam, LOWORD(lParam) != 0); | 
|---|
| 1475 | break; | 
|---|
| 1476 |  | 
|---|
| 1477 | case WM_SETREDRAW: | 
|---|
| 1478 | /* FIXME: actually set an internal flag and behave accordingly */ | 
|---|
| 1479 | break; | 
|---|
| 1480 |  | 
|---|
| 1481 | case WM_SETTEXT: | 
|---|
| 1482 | DPRINTF_EDIT_MSG32("WM_SETTEXT"); | 
|---|
| 1483 | EDIT_WM_SetText(hwnd, es, lParam, unicode); | 
|---|
| 1484 | result = TRUE; | 
|---|
| 1485 | break; | 
|---|
| 1486 |  | 
|---|
| 1487 | case WM_SIZE: | 
|---|
| 1488 | DPRINTF_EDIT_MSG32("WM_SIZE"); | 
|---|
| 1489 | EDIT_WM_Size(hwnd, es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam)); | 
|---|
| 1490 | break; | 
|---|
| 1491 |  | 
|---|
| 1492 | case WM_STYLECHANGED: | 
|---|
| 1493 | DPRINTF_EDIT_MSG32("WM_STYLECHANGED"); | 
|---|
| 1494 | result = EDIT_WM_StyleChanged (hwnd, es, wParam, (const STYLESTRUCT *)lParam); | 
|---|
| 1495 | break; | 
|---|
| 1496 |  | 
|---|
| 1497 | case WM_STYLECHANGING: | 
|---|
| 1498 | DPRINTF_EDIT_MSG32("WM_STYLECHANGING"); | 
|---|
| 1499 | result = 0; /* See EDIT_WM_StyleChanged */ | 
|---|
| 1500 | break; | 
|---|
| 1501 |  | 
|---|
| 1502 | case WM_SYSKEYDOWN: | 
|---|
| 1503 | DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN"); | 
|---|
| 1504 | result = EDIT_WM_SysKeyDown(hwnd, es, (INT)wParam, (DWORD)lParam); | 
|---|
| 1505 | break; | 
|---|
| 1506 |  | 
|---|
| 1507 | case WM_TIMER: | 
|---|
| 1508 | DPRINTF_EDIT_MSG32("WM_TIMER"); | 
|---|
| 1509 | EDIT_WM_Timer(hwnd, es); | 
|---|
| 1510 | break; | 
|---|
| 1511 |  | 
|---|
| 1512 | case WM_VSCROLL: | 
|---|
| 1513 | DPRINTF_EDIT_MSG32("WM_VSCROLL"); | 
|---|
| 1514 | result = EDIT_WM_VScroll(hwnd, es, LOWORD(wParam), SHIWORD(wParam)); | 
|---|
| 1515 | break; | 
|---|
| 1516 |  | 
|---|
| 1517 | case WM_MOUSEWHEEL: | 
|---|
| 1518 | { | 
|---|
| 1519 | int gcWheelDelta = 0; | 
|---|
| 1520 | UINT pulScrollLines = 3; | 
|---|
| 1521 | SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0); | 
|---|
| 1522 |  | 
|---|
| 1523 | if (wParam & (MK_SHIFT | MK_CONTROL)) { | 
|---|
| 1524 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 1525 | break; | 
|---|
| 1526 | } | 
|---|
| 1527 | gcWheelDelta -= SHIWORD(wParam); | 
|---|
| 1528 | if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines) | 
|---|
| 1529 | { | 
|---|
| 1530 | int cLineScroll= (int) min((UINT) es->line_count, pulScrollLines); | 
|---|
| 1531 | cLineScroll *= (gcWheelDelta / WHEEL_DELTA); | 
|---|
| 1532 | result = EDIT_EM_LineScroll(hwnd, es, 0, cLineScroll); | 
|---|
| 1533 | } | 
|---|
| 1534 | } | 
|---|
| 1535 | break; | 
|---|
| 1536 | default: | 
|---|
| 1537 | if(unicode) | 
|---|
| 1538 | result = DefWindowProcW(hwnd, msg, wParam, lParam); | 
|---|
| 1539 | else | 
|---|
| 1540 | result = DefWindowProcA(hwnd, msg, wParam, lParam); | 
|---|
| 1541 | break; | 
|---|
| 1542 | } | 
|---|
| 1543 | EDIT_UnlockBuffer(hwnd, es, FALSE); | 
|---|
| 1544 | END: | 
|---|
| 1545 | return result; | 
|---|
| 1546 | } | 
|---|
| 1547 |  | 
|---|
| 1548 | /********************************************************************* | 
|---|
| 1549 | * | 
|---|
| 1550 | *  EditWndProcW   (USER32.@) | 
|---|
| 1551 | */ | 
|---|
| 1552 | LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 1553 | { | 
|---|
| 1554 | if (!IsWindow( hWnd )) return 0; | 
|---|
| 1555 | return EditWndProc_common(hWnd, uMsg, wParam, lParam, TRUE); | 
|---|
| 1556 | } | 
|---|
| 1557 |  | 
|---|
| 1558 | /********************************************************************* | 
|---|
| 1559 | * | 
|---|
| 1560 | *  EditWndProc   (USER32.@) | 
|---|
| 1561 | */ | 
|---|
| 1562 | LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 1563 | { | 
|---|
| 1564 | if (!IsWindow( hWnd )) return 0; | 
|---|
| 1565 | return EditWndProc_common(hWnd, uMsg, wParam, lParam, FALSE); | 
|---|
| 1566 | } | 
|---|
| 1567 |  | 
|---|
| 1568 | /********************************************************************* | 
|---|
| 1569 | * | 
|---|
| 1570 | *  EDIT_BuildLineDefs_ML | 
|---|
| 1571 | * | 
|---|
| 1572 | *  Build linked list of text lines. | 
|---|
| 1573 | *  Lines can end with '\0' (last line), a character (if it is wrapped), | 
|---|
| 1574 | *  a soft return '\r\r\n' or a hard return '\r\n' | 
|---|
| 1575 | * | 
|---|
| 1576 | */ | 
|---|
| 1577 | static void EDIT_BuildLineDefs_ML(HWND hwnd, EDITSTATE *es, INT istart, INT iend, INT delta, HRGN hrgn) | 
|---|
| 1578 | { | 
|---|
| 1579 | HDC dc; | 
|---|
| 1580 | HFONT old_font = 0; | 
|---|
| 1581 | LPWSTR current_position, cp; | 
|---|
| 1582 | INT fw; | 
|---|
| 1583 | LINEDEF *current_line; | 
|---|
| 1584 | LINEDEF *previous_line; | 
|---|
| 1585 | LINEDEF *start_line; | 
|---|
| 1586 | INT line_index = 0, nstart_line = 0, nstart_index = 0; | 
|---|
| 1587 | INT line_count = es->line_count; | 
|---|
| 1588 | INT orig_net_length; | 
|---|
| 1589 | RECT rc; | 
|---|
| 1590 |  | 
|---|
| 1591 | if (istart == iend && delta == 0) | 
|---|
| 1592 | return; | 
|---|
| 1593 |  | 
|---|
| 1594 | dc = GetDC(hwnd); | 
|---|
| 1595 | if (es->font) | 
|---|
| 1596 | old_font = SelectObject(dc, es->font); | 
|---|
| 1597 |  | 
|---|
| 1598 | previous_line = NULL; | 
|---|
| 1599 | current_line = es->first_line_def; | 
|---|
| 1600 |  | 
|---|
| 1601 | /* Find starting line. istart must lie inside an existing line or | 
|---|
| 1602 | * at the end of buffer */ | 
|---|
| 1603 | do { | 
|---|
| 1604 | if (istart < current_line->index + current_line->length || | 
|---|
| 1605 | current_line->ending == END_0) | 
|---|
| 1606 | break; | 
|---|
| 1607 |  | 
|---|
| 1608 | previous_line = current_line; | 
|---|
| 1609 | current_line = current_line->next; | 
|---|
| 1610 | line_index++; | 
|---|
| 1611 | } while (current_line); | 
|---|
| 1612 |  | 
|---|
| 1613 | if (!current_line) /* Error occurred start is not inside previous buffer */ | 
|---|
| 1614 | { | 
|---|
| 1615 | FIXME(" modification occurred outside buffer\n"); | 
|---|
| 1616 | return; | 
|---|
| 1617 | } | 
|---|
| 1618 |  | 
|---|
| 1619 | /* Remember start of modifications in order to calculate update region */ | 
|---|
| 1620 | nstart_line = line_index; | 
|---|
| 1621 | nstart_index = current_line->index; | 
|---|
| 1622 |  | 
|---|
| 1623 | /* We must start to reformat from the previous line since the modifications | 
|---|
| 1624 | * may have caused the line to wrap upwards. */ | 
|---|
| 1625 | if (!(es->style & ES_AUTOHSCROLL) && line_index > 0) | 
|---|
| 1626 | { | 
|---|
| 1627 | line_index--; | 
|---|
| 1628 | current_line = previous_line; | 
|---|
| 1629 | } | 
|---|
| 1630 | start_line = current_line; | 
|---|
| 1631 |  | 
|---|
| 1632 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 1633 | current_position = es->text + current_line->index; | 
|---|
| 1634 | do { | 
|---|
| 1635 | if (current_line != start_line) | 
|---|
| 1636 | { | 
|---|
| 1637 | if (!current_line || current_line->index + delta > current_position - es->text) | 
|---|
| 1638 | { | 
|---|
| 1639 | /* The buffer has been expanded, create a new line and | 
|---|
| 1640 | insert it into the link list */ | 
|---|
| 1641 | LINEDEF *new_line = HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF)); | 
|---|
| 1642 | new_line->next = previous_line->next; | 
|---|
| 1643 | previous_line->next = new_line; | 
|---|
| 1644 | current_line = new_line; | 
|---|
| 1645 | es->line_count++; | 
|---|
| 1646 | } | 
|---|
| 1647 | else if (current_line->index + delta < current_position - es->text) | 
|---|
| 1648 | { | 
|---|
| 1649 | /* The previous line merged with this line so we delete this extra entry */ | 
|---|
| 1650 | previous_line->next = current_line->next; | 
|---|
| 1651 | HeapFree(GetProcessHeap(), 0, current_line); | 
|---|
| 1652 | current_line = previous_line->next; | 
|---|
| 1653 | es->line_count--; | 
|---|
| 1654 | continue; | 
|---|
| 1655 | } | 
|---|
| 1656 | else /* current_line->index + delta == current_position */ | 
|---|
| 1657 | { | 
|---|
| 1658 | if (current_position - es->text > iend) | 
|---|
| 1659 | break; /* We reached end of line modifications */ | 
|---|
| 1660 | /* else recalulate this line */ | 
|---|
| 1661 | } | 
|---|
| 1662 | } | 
|---|
| 1663 |  | 
|---|
| 1664 | current_line->index = current_position - es->text; | 
|---|
| 1665 | orig_net_length = current_line->net_length; | 
|---|
| 1666 |  | 
|---|
| 1667 | /* Find end of line */ | 
|---|
| 1668 | cp = current_position; | 
|---|
| 1669 | while (*cp) { | 
|---|
| 1670 | if ((*cp == '\r') && (*(cp + 1) == '\n')) | 
|---|
| 1671 | break; | 
|---|
| 1672 | cp++; | 
|---|
| 1673 | } | 
|---|
| 1674 |  | 
|---|
| 1675 | /* Mark type of line termination */ | 
|---|
| 1676 | if (!(*cp)) { | 
|---|
| 1677 | current_line->ending = END_0; | 
|---|
| 1678 | current_line->net_length = strlenW(current_position); | 
|---|
| 1679 | } else if ((cp > current_position) && (*(cp - 1) == '\r')) { | 
|---|
| 1680 | current_line->ending = END_SOFT; | 
|---|
| 1681 | current_line->net_length = cp - current_position - 1; | 
|---|
| 1682 | } else { | 
|---|
| 1683 | current_line->ending = END_HARD; | 
|---|
| 1684 | current_line->net_length = cp - current_position; | 
|---|
| 1685 | } | 
|---|
| 1686 |  | 
|---|
| 1687 | /* Calculate line width */ | 
|---|
| 1688 | current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, | 
|---|
| 1689 | current_position, current_line->net_length, | 
|---|
| 1690 | es->tabs_count, es->tabs)); | 
|---|
| 1691 |  | 
|---|
| 1692 | /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */ | 
|---|
| 1693 | if ((!(es->style & ES_AUTOHSCROLL)) && (current_line->width > fw)) { | 
|---|
| 1694 | INT next = 0; | 
|---|
| 1695 | INT prev; | 
|---|
| 1696 | do { | 
|---|
| 1697 | prev = next; | 
|---|
| 1698 | next = EDIT_CallWordBreakProc(es, current_position - es->text, | 
|---|
| 1699 | prev + 1, current_line->net_length, WB_RIGHT); | 
|---|
| 1700 | current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, | 
|---|
| 1701 | current_position, next, es->tabs_count, es->tabs)); | 
|---|
| 1702 | } while (current_line->width <= fw); | 
|---|
| 1703 | if (!prev) { /* Didn't find a line break so force a break */ | 
|---|
| 1704 | next = 0; | 
|---|
| 1705 | do { | 
|---|
| 1706 | prev = next; | 
|---|
| 1707 | next++; | 
|---|
| 1708 | current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, | 
|---|
| 1709 | current_position, next, es->tabs_count, es->tabs)); | 
|---|
| 1710 | } while (current_line->width <= fw); | 
|---|
| 1711 | if (!prev) | 
|---|
| 1712 | prev = 1; | 
|---|
| 1713 | } | 
|---|
| 1714 |  | 
|---|
| 1715 | /* If the first line we are calculating, wrapped before istart, we must | 
|---|
| 1716 | * adjust istart in order for this to be reflected in the update region. */ | 
|---|
| 1717 | if (current_line->index == nstart_index && istart > current_line->index + prev) | 
|---|
| 1718 | istart = current_line->index + prev; | 
|---|
| 1719 | /* else if we are updating the previous line before the first line we | 
|---|
| 1720 | * are re-calculating and it expanded */ | 
|---|
| 1721 | else if (current_line == start_line && | 
|---|
| 1722 | current_line->index != nstart_index && orig_net_length < prev) | 
|---|
| 1723 | { | 
|---|
| 1724 | /* Line expanded due to an upwards line wrap so we must partially include | 
|---|
| 1725 | * previous line in update region */ | 
|---|
| 1726 | nstart_line = line_index; | 
|---|
| 1727 | nstart_index = current_line->index; | 
|---|
| 1728 | istart = current_line->index + orig_net_length; | 
|---|
| 1729 | } | 
|---|
| 1730 |  | 
|---|
| 1731 | current_line->net_length = prev; | 
|---|
| 1732 | current_line->ending = END_WRAP; | 
|---|
| 1733 | current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, current_position, | 
|---|
| 1734 | current_line->net_length, es->tabs_count, es->tabs)); | 
|---|
| 1735 | } | 
|---|
| 1736 |  | 
|---|
| 1737 |  | 
|---|
| 1738 | /* Adjust length to include line termination */ | 
|---|
| 1739 | switch (current_line->ending) { | 
|---|
| 1740 | case END_SOFT: | 
|---|
| 1741 | current_line->length = current_line->net_length + 3; | 
|---|
| 1742 | break; | 
|---|
| 1743 | case END_HARD: | 
|---|
| 1744 | current_line->length = current_line->net_length + 2; | 
|---|
| 1745 | break; | 
|---|
| 1746 | case END_WRAP: | 
|---|
| 1747 | case END_0: | 
|---|
| 1748 | current_line->length = current_line->net_length; | 
|---|
| 1749 | break; | 
|---|
| 1750 | } | 
|---|
| 1751 | es->text_width = max(es->text_width, current_line->width); | 
|---|
| 1752 | current_position += current_line->length; | 
|---|
| 1753 | previous_line = current_line; | 
|---|
| 1754 | current_line = current_line->next; | 
|---|
| 1755 | line_index++; | 
|---|
| 1756 | } while (previous_line->ending != END_0); | 
|---|
| 1757 |  | 
|---|
| 1758 | /* Finish adjusting line indexes by delta or remove hanging lines */ | 
|---|
| 1759 | if (previous_line->ending == END_0) | 
|---|
| 1760 | { | 
|---|
| 1761 | LINEDEF *pnext = NULL; | 
|---|
| 1762 |  | 
|---|
| 1763 | previous_line->next = NULL; | 
|---|
| 1764 | while (current_line) | 
|---|
| 1765 | { | 
|---|
| 1766 | pnext = current_line->next; | 
|---|
| 1767 | HeapFree(GetProcessHeap(), 0, current_line); | 
|---|
| 1768 | current_line = pnext; | 
|---|
| 1769 | es->line_count--; | 
|---|
| 1770 | } | 
|---|
| 1771 | } | 
|---|
| 1772 | else | 
|---|
| 1773 | { | 
|---|
| 1774 | while (current_line) | 
|---|
| 1775 | { | 
|---|
| 1776 | current_line->index += delta; | 
|---|
| 1777 | current_line = current_line->next; | 
|---|
| 1778 | } | 
|---|
| 1779 | } | 
|---|
| 1780 |  | 
|---|
| 1781 | /* Calculate rest of modification rectangle */ | 
|---|
| 1782 | if (hrgn) | 
|---|
| 1783 | { | 
|---|
| 1784 | HRGN tmphrgn; | 
|---|
| 1785 | /* | 
|---|
| 1786 | * We calculate two rectangles. One for the first line which may have | 
|---|
| 1787 | * an indent with respect to the format rect. The other is a format-width | 
|---|
| 1788 | * rectangle that spans the rest of the lines that changed or moved. | 
|---|
| 1789 | */ | 
|---|
| 1790 | rc.top = es->format_rect.top + nstart_line * es->line_height - | 
|---|
| 1791 | (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */ | 
|---|
| 1792 | rc.bottom = rc.top + es->line_height; | 
|---|
| 1793 | rc.left = es->format_rect.left + (INT)LOWORD(GetTabbedTextExtentW(dc, | 
|---|
| 1794 | es->text + nstart_index, istart - nstart_index, | 
|---|
| 1795 | es->tabs_count, es->tabs)) - es->x_offset; /* Adjust for horz scroll */ | 
|---|
| 1796 | rc.right = es->format_rect.right; | 
|---|
| 1797 | SetRectRgn(hrgn, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 1798 |  | 
|---|
| 1799 | rc.top = rc.bottom; | 
|---|
| 1800 | rc.left = es->format_rect.left; | 
|---|
| 1801 | rc.right = es->format_rect.right; | 
|---|
| 1802 | /* | 
|---|
| 1803 | * If lines were added or removed we must re-paint the remainder of the | 
|---|
| 1804 | * lines since the remaining lines were either shifted up or down. | 
|---|
| 1805 | */ | 
|---|
| 1806 | if (line_count < es->line_count) /* We added lines */ | 
|---|
| 1807 | rc.bottom = es->line_count * es->line_height; | 
|---|
| 1808 | else if (line_count > es->line_count) /* We removed lines */ | 
|---|
| 1809 | rc.bottom = line_count * es->line_height; | 
|---|
| 1810 | else | 
|---|
| 1811 | rc.bottom = line_index * es->line_height; | 
|---|
| 1812 | rc.bottom -= (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */ | 
|---|
| 1813 | tmphrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 1814 | CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR); | 
|---|
| 1815 | DeleteObject(tmphrgn); | 
|---|
| 1816 | } | 
|---|
| 1817 |  | 
|---|
| 1818 | if (es->font) | 
|---|
| 1819 | SelectObject(dc, old_font); | 
|---|
| 1820 |  | 
|---|
| 1821 | ReleaseDC(hwnd, dc); | 
|---|
| 1822 | } | 
|---|
| 1823 |  | 
|---|
| 1824 | /********************************************************************* | 
|---|
| 1825 | * | 
|---|
| 1826 | *  EDIT_CalcLineWidth_SL | 
|---|
| 1827 | * | 
|---|
| 1828 | */ | 
|---|
| 1829 | static void EDIT_CalcLineWidth_SL(HWND hwnd, EDITSTATE *es) | 
|---|
| 1830 | { | 
|---|
| 1831 | es->text_width = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, strlenW(es->text), FALSE)); | 
|---|
| 1832 | } | 
|---|
| 1833 |  | 
|---|
| 1834 | /********************************************************************* | 
|---|
| 1835 | * | 
|---|
| 1836 | *  EDIT_CallWordBreakProc | 
|---|
| 1837 | * | 
|---|
| 1838 | *  Call appropriate WordBreakProc (internal or external). | 
|---|
| 1839 | * | 
|---|
| 1840 | *  Note: The "start" argument should always be an index referring | 
|---|
| 1841 | *      to es->text.  The actual wordbreak proc might be | 
|---|
| 1842 | *      16 bit, so we can't always pass any 32 bit LPSTR. | 
|---|
| 1843 | *      Hence we assume that es->text is the buffer that holds | 
|---|
| 1844 | *      the string under examination (we can decide this for ourselves). | 
|---|
| 1845 | * | 
|---|
| 1846 | */ | 
|---|
| 1847 | /* ### start build ### */ | 
|---|
| 1848 | extern WORD CALLBACK EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16,SEGPTR,WORD,WORD,WORD); | 
|---|
| 1849 | /* ### stop build ### */ | 
|---|
| 1850 | static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action) | 
|---|
| 1851 | { | 
|---|
| 1852 | INT ret, iWndsLocks; | 
|---|
| 1853 |  | 
|---|
| 1854 | /* To avoid any deadlocks, all the locks on the window structures | 
|---|
| 1855 | must be suspended before the control is passed to the application */ | 
|---|
| 1856 | iWndsLocks = WIN_SuspendWndsLock(); | 
|---|
| 1857 |  | 
|---|
| 1858 | #ifndef __WIN32OS2__ | 
|---|
| 1859 | if (es->word_break_proc16) { | 
|---|
| 1860 | HGLOBAL16 hglob16; | 
|---|
| 1861 | SEGPTR segptr; | 
|---|
| 1862 | INT countA; | 
|---|
| 1863 |  | 
|---|
| 1864 | countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL); | 
|---|
| 1865 | hglob16 = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT, countA); | 
|---|
| 1866 | segptr = K32WOWGlobalLock16(hglob16); | 
|---|
| 1867 | WideCharToMultiByte(CP_ACP, 0, es->text + start, count, MapSL(segptr), countA, NULL, NULL); | 
|---|
| 1868 | ret = (INT)EDIT_CallTo16_word_lwww(es->word_break_proc16, | 
|---|
| 1869 | segptr, index, countA, action); | 
|---|
| 1870 | GlobalUnlock16(hglob16); | 
|---|
| 1871 | GlobalFree16(hglob16); | 
|---|
| 1872 | } | 
|---|
| 1873 | else | 
|---|
| 1874 | #endif | 
|---|
| 1875 | if (es->word_break_proc) | 
|---|
| 1876 | { | 
|---|
| 1877 | if(es->is_unicode) | 
|---|
| 1878 | { | 
|---|
| 1879 | EDITWORDBREAKPROCW wbpW = (EDITWORDBREAKPROCW)es->word_break_proc; | 
|---|
| 1880 |  | 
|---|
| 1881 | TRACE_(relay)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n", | 
|---|
| 1882 | es->word_break_proc, debugstr_wn(es->text + start, count), index, count, action); | 
|---|
| 1883 | ret = wbpW(es->text + start, index, count, action); | 
|---|
| 1884 | } | 
|---|
| 1885 | else | 
|---|
| 1886 | { | 
|---|
| 1887 | EDITWORDBREAKPROCA wbpA = (EDITWORDBREAKPROCA)es->word_break_proc; | 
|---|
| 1888 | INT countA; | 
|---|
| 1889 | CHAR *textA; | 
|---|
| 1890 |  | 
|---|
| 1891 | countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL); | 
|---|
| 1892 | textA = HeapAlloc(GetProcessHeap(), 0, countA); | 
|---|
| 1893 | WideCharToMultiByte(CP_ACP, 0, es->text + start, count, textA, countA, NULL, NULL); | 
|---|
| 1894 | TRACE_(relay)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n", | 
|---|
| 1895 | es->word_break_proc, debugstr_an(textA, countA), index, countA, action); | 
|---|
| 1896 | ret = wbpA(textA, index, countA, action); | 
|---|
| 1897 | HeapFree(GetProcessHeap(), 0, textA); | 
|---|
| 1898 | } | 
|---|
| 1899 | } | 
|---|
| 1900 | else | 
|---|
| 1901 | ret = EDIT_WordBreakProc(es->text + start, index, count, action); | 
|---|
| 1902 |  | 
|---|
| 1903 | WIN_RestoreWndsLock(iWndsLocks); | 
|---|
| 1904 | return ret; | 
|---|
| 1905 | } | 
|---|
| 1906 |  | 
|---|
| 1907 |  | 
|---|
| 1908 | /********************************************************************* | 
|---|
| 1909 | * | 
|---|
| 1910 | *  EDIT_CharFromPos | 
|---|
| 1911 | * | 
|---|
| 1912 | *  Beware: This is not the function called on EM_CHARFROMPOS | 
|---|
| 1913 | *      The position _can_ be outside the formatting / client | 
|---|
| 1914 | *      rectangle | 
|---|
| 1915 | *      The return value is only the character index | 
|---|
| 1916 | * | 
|---|
| 1917 | */ | 
|---|
| 1918 | static INT EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap) | 
|---|
| 1919 | { | 
|---|
| 1920 | INT index; | 
|---|
| 1921 | HDC dc; | 
|---|
| 1922 | HFONT old_font = 0; | 
|---|
| 1923 |  | 
|---|
| 1924 | if (es->style & ES_MULTILINE) { | 
|---|
| 1925 | INT line = (y - es->format_rect.top) / es->line_height + es->y_offset; | 
|---|
| 1926 | INT line_index = 0; | 
|---|
| 1927 | LINEDEF *line_def = es->first_line_def; | 
|---|
| 1928 | INT low, high; | 
|---|
| 1929 | while ((line > 0) && line_def->next) { | 
|---|
| 1930 | line_index += line_def->length; | 
|---|
| 1931 | line_def = line_def->next; | 
|---|
| 1932 | line--; | 
|---|
| 1933 | } | 
|---|
| 1934 | x += es->x_offset - es->format_rect.left; | 
|---|
| 1935 | if (x >= line_def->width) { | 
|---|
| 1936 | if (after_wrap) | 
|---|
| 1937 | *after_wrap = (line_def->ending == END_WRAP); | 
|---|
| 1938 | return line_index + line_def->net_length; | 
|---|
| 1939 | } | 
|---|
| 1940 | if (x <= 0) { | 
|---|
| 1941 | if (after_wrap) | 
|---|
| 1942 | *after_wrap = FALSE; | 
|---|
| 1943 | return line_index; | 
|---|
| 1944 | } | 
|---|
| 1945 | dc = GetDC(hwnd); | 
|---|
| 1946 | if (es->font) | 
|---|
| 1947 | old_font = SelectObject(dc, es->font); | 
|---|
| 1948 | low = line_index + 1; | 
|---|
| 1949 | high = line_index + line_def->net_length + 1; | 
|---|
| 1950 | while (low < high - 1) | 
|---|
| 1951 | { | 
|---|
| 1952 | INT mid = (low + high) / 2; | 
|---|
| 1953 | if (LOWORD(GetTabbedTextExtentW(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid; | 
|---|
| 1954 | else low = mid; | 
|---|
| 1955 | } | 
|---|
| 1956 | index = low; | 
|---|
| 1957 |  | 
|---|
| 1958 | if (after_wrap) | 
|---|
| 1959 | *after_wrap = ((index == line_index + line_def->net_length) && | 
|---|
| 1960 | (line_def->ending == END_WRAP)); | 
|---|
| 1961 | } else { | 
|---|
| 1962 | LPWSTR text; | 
|---|
| 1963 | SIZE size; | 
|---|
| 1964 | if (after_wrap) | 
|---|
| 1965 | *after_wrap = FALSE; | 
|---|
| 1966 | x -= es->format_rect.left; | 
|---|
| 1967 | if (!x) | 
|---|
| 1968 | return es->x_offset; | 
|---|
| 1969 | text = EDIT_GetPasswordPointer_SL(es); | 
|---|
| 1970 | dc = GetDC(hwnd); | 
|---|
| 1971 | if (es->font) | 
|---|
| 1972 | old_font = SelectObject(dc, es->font); | 
|---|
| 1973 | if (x < 0) | 
|---|
| 1974 | { | 
|---|
| 1975 | INT low = 0; | 
|---|
| 1976 | INT high = es->x_offset; | 
|---|
| 1977 | while (low < high - 1) | 
|---|
| 1978 | { | 
|---|
| 1979 | INT mid = (low + high) / 2; | 
|---|
| 1980 | GetTextExtentPoint32W( dc, text + mid, | 
|---|
| 1981 | es->x_offset - mid, &size ); | 
|---|
| 1982 | if (size.cx > -x) low = mid; | 
|---|
| 1983 | else high = mid; | 
|---|
| 1984 | } | 
|---|
| 1985 | index = low; | 
|---|
| 1986 | } | 
|---|
| 1987 | else | 
|---|
| 1988 | { | 
|---|
| 1989 | INT low = es->x_offset; | 
|---|
| 1990 | INT high = strlenW(es->text) + 1; | 
|---|
| 1991 | while (low < high - 1) | 
|---|
| 1992 | { | 
|---|
| 1993 | INT mid = (low + high) / 2; | 
|---|
| 1994 | GetTextExtentPoint32W( dc, text + es->x_offset, | 
|---|
| 1995 | mid - es->x_offset, &size ); | 
|---|
| 1996 | if (size.cx > x) high = mid; | 
|---|
| 1997 | else low = mid; | 
|---|
| 1998 | } | 
|---|
| 1999 | index = low; | 
|---|
| 2000 | } | 
|---|
| 2001 | if (es->style & ES_PASSWORD) | 
|---|
| 2002 | HeapFree(GetProcessHeap(), 0, text); | 
|---|
| 2003 | } | 
|---|
| 2004 | if (es->font) | 
|---|
| 2005 | SelectObject(dc, old_font); | 
|---|
| 2006 | ReleaseDC(hwnd, dc); | 
|---|
| 2007 | return index; | 
|---|
| 2008 | } | 
|---|
| 2009 |  | 
|---|
| 2010 |  | 
|---|
| 2011 | /********************************************************************* | 
|---|
| 2012 | * | 
|---|
| 2013 | *  EDIT_ConfinePoint | 
|---|
| 2014 | * | 
|---|
| 2015 | *  adjusts the point to be within the formatting rectangle | 
|---|
| 2016 | *  (so CharFromPos returns the nearest _visible_ character) | 
|---|
| 2017 | * | 
|---|
| 2018 | */ | 
|---|
| 2019 | static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y) | 
|---|
| 2020 | { | 
|---|
| 2021 | *x = min(max(*x, es->format_rect.left), es->format_rect.right - 1); | 
|---|
| 2022 | *y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1); | 
|---|
| 2023 | } | 
|---|
| 2024 |  | 
|---|
| 2025 |  | 
|---|
| 2026 | /********************************************************************* | 
|---|
| 2027 | * | 
|---|
| 2028 | *  EDIT_GetLineRect | 
|---|
| 2029 | * | 
|---|
| 2030 | *  Calculates the bounding rectangle for a line from a starting | 
|---|
| 2031 | *  column to an ending column. | 
|---|
| 2032 | * | 
|---|
| 2033 | */ | 
|---|
| 2034 | static void EDIT_GetLineRect(HWND hwnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc) | 
|---|
| 2035 | { | 
|---|
| 2036 | INT line_index =  EDIT_EM_LineIndex(es, line); | 
|---|
| 2037 |  | 
|---|
| 2038 | if (es->style & ES_MULTILINE) | 
|---|
| 2039 | rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height; | 
|---|
| 2040 | else | 
|---|
| 2041 | rc->top = es->format_rect.top; | 
|---|
| 2042 | rc->bottom = rc->top + es->line_height; | 
|---|
| 2043 | rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd, es, line_index + scol, TRUE)); | 
|---|
| 2044 | rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd, es, line_index + ecol, TRUE)); | 
|---|
| 2045 | } | 
|---|
| 2046 |  | 
|---|
| 2047 |  | 
|---|
| 2048 | /********************************************************************* | 
|---|
| 2049 | * | 
|---|
| 2050 | *  EDIT_GetPasswordPointer_SL | 
|---|
| 2051 | * | 
|---|
| 2052 | *  note: caller should free the (optionally) allocated buffer | 
|---|
| 2053 | * | 
|---|
| 2054 | */ | 
|---|
| 2055 | static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es) | 
|---|
| 2056 | { | 
|---|
| 2057 | if (es->style & ES_PASSWORD) { | 
|---|
| 2058 | INT len = strlenW(es->text); | 
|---|
| 2059 | LPWSTR text = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); | 
|---|
| 2060 | text[len] = '\0'; | 
|---|
| 2061 | while(len) text[--len] = es->password_char; | 
|---|
| 2062 | return text; | 
|---|
| 2063 | } else | 
|---|
| 2064 | return es->text; | 
|---|
| 2065 | } | 
|---|
| 2066 |  | 
|---|
| 2067 |  | 
|---|
| 2068 | /********************************************************************* | 
|---|
| 2069 | * | 
|---|
| 2070 | *  EDIT_LockBuffer | 
|---|
| 2071 | * | 
|---|
| 2072 | *  This acts as a LOCAL_Lock(), but it locks only once.  This way | 
|---|
| 2073 | *  you can call it whenever you like, without unlocking. | 
|---|
| 2074 | * | 
|---|
| 2075 | */ | 
|---|
| 2076 | static void EDIT_LockBuffer(HWND hwnd, EDITSTATE *es) | 
|---|
| 2077 | { | 
|---|
| 2078 | HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE ); | 
|---|
| 2079 | if (!es) { | 
|---|
| 2080 | ERR("no EDITSTATE ... please report\n"); | 
|---|
| 2081 | return; | 
|---|
| 2082 | } | 
|---|
| 2083 | if (!es->text) { | 
|---|
| 2084 | CHAR *textA = NULL; | 
|---|
| 2085 | UINT countA = 0; | 
|---|
| 2086 | BOOL _16bit = FALSE; | 
|---|
| 2087 |  | 
|---|
| 2088 | if(es->hloc32W) | 
|---|
| 2089 | { | 
|---|
| 2090 | if(es->hloc32A) | 
|---|
| 2091 | { | 
|---|
| 2092 | TRACE("Synchronizing with 32-bit ANSI buffer\n"); | 
|---|
| 2093 | textA = LocalLock(es->hloc32A); | 
|---|
| 2094 | countA = strlen(textA) + 1; | 
|---|
| 2095 | } | 
|---|
| 2096 | else if(es->hloc16) | 
|---|
| 2097 | { | 
|---|
| 2098 | TRACE("Synchronizing with 16-bit ANSI buffer\n"); | 
|---|
| 2099 | textA = LOCAL_Lock(hInstance, es->hloc16); | 
|---|
| 2100 | countA = strlen(textA) + 1; | 
|---|
| 2101 | _16bit = TRUE; | 
|---|
| 2102 | } | 
|---|
| 2103 | } | 
|---|
| 2104 | else { | 
|---|
| 2105 | ERR("no buffer ... please report\n"); | 
|---|
| 2106 | return; | 
|---|
| 2107 | } | 
|---|
| 2108 |  | 
|---|
| 2109 | if(textA) | 
|---|
| 2110 | { | 
|---|
| 2111 | HLOCAL hloc32W_new; | 
|---|
| 2112 | UINT countW_new = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0); | 
|---|
| 2113 | TRACE("%d bytes translated to %d WCHARs\n", countA, countW_new); | 
|---|
| 2114 | if(countW_new > es->buffer_size + 1) | 
|---|
| 2115 | { | 
|---|
| 2116 | UINT alloc_size = ROUND_TO_GROW(countW_new * sizeof(WCHAR)); | 
|---|
| 2117 | TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es->buffer_size, countW_new); | 
|---|
| 2118 | hloc32W_new = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT); | 
|---|
| 2119 | if(hloc32W_new) | 
|---|
| 2120 | { | 
|---|
| 2121 | es->hloc32W = hloc32W_new; | 
|---|
| 2122 | es->buffer_size = LocalSize(hloc32W_new)/sizeof(WCHAR) - 1; | 
|---|
| 2123 | TRACE("Real new size %d+1 WCHARs\n", es->buffer_size); | 
|---|
| 2124 | } | 
|---|
| 2125 | else | 
|---|
| 2126 | WARN("FAILED! Will synchronize partially\n"); | 
|---|
| 2127 | } | 
|---|
| 2128 | } | 
|---|
| 2129 |  | 
|---|
| 2130 | /*TRACE("Locking 32-bit UNICODE buffer\n");*/ | 
|---|
| 2131 | es->text = LocalLock(es->hloc32W); | 
|---|
| 2132 |  | 
|---|
| 2133 | if(textA) | 
|---|
| 2134 | { | 
|---|
| 2135 | MultiByteToWideChar(CP_ACP, 0, textA, countA, es->text, es->buffer_size + 1); | 
|---|
| 2136 | if(_16bit) | 
|---|
| 2137 | LOCAL_Unlock(hInstance, es->hloc16); | 
|---|
| 2138 | else | 
|---|
| 2139 | LocalUnlock(es->hloc32A); | 
|---|
| 2140 | } | 
|---|
| 2141 | } | 
|---|
| 2142 | es->lock_count++; | 
|---|
| 2143 | } | 
|---|
| 2144 |  | 
|---|
| 2145 |  | 
|---|
| 2146 | /********************************************************************* | 
|---|
| 2147 | * | 
|---|
| 2148 | *  EDIT_SL_InvalidateText | 
|---|
| 2149 | * | 
|---|
| 2150 | *  Called from EDIT_InvalidateText(). | 
|---|
| 2151 | *  Does the job for single-line controls only. | 
|---|
| 2152 | * | 
|---|
| 2153 | */ | 
|---|
| 2154 | static void EDIT_SL_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end) | 
|---|
| 2155 | { | 
|---|
| 2156 | RECT line_rect; | 
|---|
| 2157 | RECT rc; | 
|---|
| 2158 |  | 
|---|
| 2159 | EDIT_GetLineRect(hwnd, es, 0, start, end, &line_rect); | 
|---|
| 2160 | if (IntersectRect(&rc, &line_rect, &es->format_rect)) | 
|---|
| 2161 | EDIT_UpdateText(hwnd, es, &rc, FALSE); | 
|---|
| 2162 | } | 
|---|
| 2163 |  | 
|---|
| 2164 |  | 
|---|
| 2165 | /********************************************************************* | 
|---|
| 2166 | * | 
|---|
| 2167 | *  EDIT_ML_InvalidateText | 
|---|
| 2168 | * | 
|---|
| 2169 | *  Called from EDIT_InvalidateText(). | 
|---|
| 2170 | *  Does the job for multi-line controls only. | 
|---|
| 2171 | * | 
|---|
| 2172 | */ | 
|---|
| 2173 | static void EDIT_ML_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end) | 
|---|
| 2174 | { | 
|---|
| 2175 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2176 | INT sl = EDIT_EM_LineFromChar(es, start); | 
|---|
| 2177 | INT el = EDIT_EM_LineFromChar(es, end); | 
|---|
| 2178 | INT sc; | 
|---|
| 2179 | INT ec; | 
|---|
| 2180 | RECT rc1; | 
|---|
| 2181 | RECT rcWnd; | 
|---|
| 2182 | RECT rcLine; | 
|---|
| 2183 | RECT rcUpdate; | 
|---|
| 2184 | INT l; | 
|---|
| 2185 |  | 
|---|
| 2186 | if ((el < es->y_offset) || (sl > es->y_offset + vlc)) | 
|---|
| 2187 | return; | 
|---|
| 2188 |  | 
|---|
| 2189 | sc = start - EDIT_EM_LineIndex(es, sl); | 
|---|
| 2190 | ec = end - EDIT_EM_LineIndex(es, el); | 
|---|
| 2191 | if (sl < es->y_offset) { | 
|---|
| 2192 | sl = es->y_offset; | 
|---|
| 2193 | sc = 0; | 
|---|
| 2194 | } | 
|---|
| 2195 | if (el > es->y_offset + vlc) { | 
|---|
| 2196 | el = es->y_offset + vlc; | 
|---|
| 2197 | ec = EDIT_EM_LineLength(es, EDIT_EM_LineIndex(es, el)); | 
|---|
| 2198 | } | 
|---|
| 2199 | GetClientRect(hwnd, &rc1); | 
|---|
| 2200 | IntersectRect(&rcWnd, &rc1, &es->format_rect); | 
|---|
| 2201 | if (sl == el) { | 
|---|
| 2202 | EDIT_GetLineRect(hwnd, es, sl, sc, ec, &rcLine); | 
|---|
| 2203 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 2204 | EDIT_UpdateText(hwnd, es, &rcUpdate, FALSE); | 
|---|
| 2205 | } else { | 
|---|
| 2206 | EDIT_GetLineRect(hwnd, es, sl, sc, | 
|---|
| 2207 | EDIT_EM_LineLength(es, | 
|---|
| 2208 | EDIT_EM_LineIndex(es, sl)), | 
|---|
| 2209 | &rcLine); | 
|---|
| 2210 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 2211 | EDIT_UpdateText(hwnd, es, &rcUpdate, FALSE); | 
|---|
| 2212 | for (l = sl + 1 ; l < el ; l++) { | 
|---|
| 2213 | EDIT_GetLineRect(hwnd, es, l, 0, | 
|---|
| 2214 | EDIT_EM_LineLength(es, | 
|---|
| 2215 | EDIT_EM_LineIndex(es, l)), | 
|---|
| 2216 | &rcLine); | 
|---|
| 2217 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 2218 | EDIT_UpdateText(hwnd, es, &rcUpdate, FALSE); | 
|---|
| 2219 | } | 
|---|
| 2220 | EDIT_GetLineRect(hwnd, es, el, 0, ec, &rcLine); | 
|---|
| 2221 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) | 
|---|
| 2222 | EDIT_UpdateText(hwnd, es, &rcUpdate, FALSE); | 
|---|
| 2223 | } | 
|---|
| 2224 | } | 
|---|
| 2225 |  | 
|---|
| 2226 |  | 
|---|
| 2227 | /********************************************************************* | 
|---|
| 2228 | * | 
|---|
| 2229 | *  EDIT_InvalidateText | 
|---|
| 2230 | * | 
|---|
| 2231 | *  Invalidate the text from offset start upto, but not including, | 
|---|
| 2232 | *  offset end.  Useful for (re)painting the selection. | 
|---|
| 2233 | *  Regions outside the linewidth are not invalidated. | 
|---|
| 2234 | *  end == -1 means end == TextLength. | 
|---|
| 2235 | *  start and end need not be ordered. | 
|---|
| 2236 | * | 
|---|
| 2237 | */ | 
|---|
| 2238 | static void EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end) | 
|---|
| 2239 | { | 
|---|
| 2240 | if (end == start) | 
|---|
| 2241 | return; | 
|---|
| 2242 |  | 
|---|
| 2243 | if (end == -1) | 
|---|
| 2244 | end = strlenW(es->text); | 
|---|
| 2245 |  | 
|---|
| 2246 | ORDER_INT(start, end); | 
|---|
| 2247 |  | 
|---|
| 2248 | if (es->style & ES_MULTILINE) | 
|---|
| 2249 | EDIT_ML_InvalidateText(hwnd, es, start, end); | 
|---|
| 2250 | else | 
|---|
| 2251 | EDIT_SL_InvalidateText(hwnd, es, start, end); | 
|---|
| 2252 | } | 
|---|
| 2253 |  | 
|---|
| 2254 |  | 
|---|
| 2255 | /********************************************************************* | 
|---|
| 2256 | * | 
|---|
| 2257 | *  EDIT_MakeFit | 
|---|
| 2258 | * | 
|---|
| 2259 | *  Try to fit size + 1 characters in the buffer. Constrain to limits. | 
|---|
| 2260 | * | 
|---|
| 2261 | */ | 
|---|
| 2262 | static BOOL EDIT_MakeFit(HWND hwnd, EDITSTATE *es, UINT size) | 
|---|
| 2263 | { | 
|---|
| 2264 | HLOCAL hNew32W; | 
|---|
| 2265 |  | 
|---|
| 2266 | if (size <= es->buffer_size) | 
|---|
| 2267 | return TRUE; | 
|---|
| 2268 | #ifndef __WIN32OS2__ | 
|---|
| 2269 | //SvL: EM_SETTEXTLIMIT has no effect in | 
|---|
| 2270 | //     NT4, SP6 (EM_GETTEXTLIMIT only returns that value). | 
|---|
| 2271 | //     Limits are simply ignored, no EN_MAXTEXT notification is ever sent. | 
|---|
| 2272 | //     (fixes license edit control in Microsoft Visual C++ 4.2 install) | 
|---|
| 2273 |  | 
|---|
| 2274 | if (size > es->buffer_limit) { | 
|---|
| 2275 | EDIT_NOTIFY_PARENT(hwnd, es, EN_MAXTEXT, "EN_MAXTEXT"); | 
|---|
| 2276 | return FALSE; | 
|---|
| 2277 | } | 
|---|
| 2278 | if (size > es->buffer_limit) | 
|---|
| 2279 | size = es->buffer_limit; | 
|---|
| 2280 | #endif | 
|---|
| 2281 |  | 
|---|
| 2282 | TRACE("trying to ReAlloc to %d+1 characters\n", size); | 
|---|
| 2283 |  | 
|---|
| 2284 | /* Force edit to unlock it's buffer. es->text now NULL */ | 
|---|
| 2285 | EDIT_UnlockBuffer(hwnd, es, TRUE); | 
|---|
| 2286 |  | 
|---|
| 2287 | if (es->hloc32W) { | 
|---|
| 2288 | UINT alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR)); | 
|---|
| 2289 | if ((hNew32W = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT)) != 0) { | 
|---|
| 2290 | TRACE("Old 32 bit handle %08x, new handle %08x\n", es->hloc32W, hNew32W); | 
|---|
| 2291 | es->hloc32W = hNew32W; | 
|---|
| 2292 | es->buffer_size = LocalSize(hNew32W)/sizeof(WCHAR) - 1; | 
|---|
| 2293 | } | 
|---|
| 2294 | } | 
|---|
| 2295 |  | 
|---|
| 2296 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 2297 |  | 
|---|
| 2298 | if (es->buffer_size < size) { | 
|---|
| 2299 | WARN("FAILED !  We now have %d+1\n", es->buffer_size); | 
|---|
| 2300 | EDIT_NOTIFY_PARENT(hwnd, es, EN_ERRSPACE, "EN_ERRSPACE"); | 
|---|
| 2301 | return FALSE; | 
|---|
| 2302 | } else { | 
|---|
| 2303 | TRACE("We now have %d+1\n", es->buffer_size); | 
|---|
| 2304 | return TRUE; | 
|---|
| 2305 | } | 
|---|
| 2306 | } | 
|---|
| 2307 |  | 
|---|
| 2308 |  | 
|---|
| 2309 | /********************************************************************* | 
|---|
| 2310 | * | 
|---|
| 2311 | *  EDIT_MakeUndoFit | 
|---|
| 2312 | * | 
|---|
| 2313 | *  Try to fit size + 1 bytes in the undo buffer. | 
|---|
| 2314 | * | 
|---|
| 2315 | */ | 
|---|
| 2316 | static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size) | 
|---|
| 2317 | { | 
|---|
| 2318 | UINT alloc_size; | 
|---|
| 2319 |  | 
|---|
| 2320 | if (size <= es->undo_buffer_size) | 
|---|
| 2321 | return TRUE; | 
|---|
| 2322 |  | 
|---|
| 2323 | TRACE("trying to ReAlloc to %d+1\n", size); | 
|---|
| 2324 |  | 
|---|
| 2325 | alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR)); | 
|---|
| 2326 | if ((es->undo_text = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, es->undo_text, alloc_size)) != 0) { | 
|---|
| 2327 | #ifdef __WIN32OS2__ | 
|---|
| 2328 | es->undo_buffer_size = alloc_size/sizeof(WCHAR) - 1; | 
|---|
| 2329 | #else | 
|---|
| 2330 | es->undo_buffer_size = alloc_size/sizeof(WCHAR); | 
|---|
| 2331 | #endif | 
|---|
| 2332 | return TRUE; | 
|---|
| 2333 | } | 
|---|
| 2334 | else | 
|---|
| 2335 | { | 
|---|
| 2336 | WARN("FAILED !  We now have %d+1\n", es->undo_buffer_size); | 
|---|
| 2337 | return FALSE; | 
|---|
| 2338 | } | 
|---|
| 2339 | } | 
|---|
| 2340 |  | 
|---|
| 2341 |  | 
|---|
| 2342 | /********************************************************************* | 
|---|
| 2343 | * | 
|---|
| 2344 | *  EDIT_MoveBackward | 
|---|
| 2345 | * | 
|---|
| 2346 | */ | 
|---|
| 2347 | static void EDIT_MoveBackward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2348 | { | 
|---|
| 2349 | INT e = es->selection_end; | 
|---|
| 2350 |  | 
|---|
| 2351 | if (e) { | 
|---|
| 2352 | e--; | 
|---|
| 2353 | if ((es->style & ES_MULTILINE) && e && | 
|---|
| 2354 | (es->text[e - 1] == '\r') && (es->text[e] == '\n')) { | 
|---|
| 2355 | e--; | 
|---|
| 2356 | if (e && (es->text[e - 1] == '\r')) | 
|---|
| 2357 | e--; | 
|---|
| 2358 | } | 
|---|
| 2359 | } | 
|---|
| 2360 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE); | 
|---|
| 2361 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2362 | } | 
|---|
| 2363 |  | 
|---|
| 2364 |  | 
|---|
| 2365 | /********************************************************************* | 
|---|
| 2366 | * | 
|---|
| 2367 | *  EDIT_MoveDown_ML | 
|---|
| 2368 | * | 
|---|
| 2369 | *  Only for multi line controls | 
|---|
| 2370 | *  Move the caret one line down, on a column with the nearest | 
|---|
| 2371 | *  x coordinate on the screen (might be a different column). | 
|---|
| 2372 | * | 
|---|
| 2373 | */ | 
|---|
| 2374 | static void EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2375 | { | 
|---|
| 2376 | INT s = es->selection_start; | 
|---|
| 2377 | INT e = es->selection_end; | 
|---|
| 2378 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 2379 | LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap); | 
|---|
| 2380 | INT x = SLOWORD(pos); | 
|---|
| 2381 | INT y = SHIWORD(pos); | 
|---|
| 2382 |  | 
|---|
| 2383 | e = EDIT_CharFromPos(hwnd, es, x, y + es->line_height, &after_wrap); | 
|---|
| 2384 | if (!extend) | 
|---|
| 2385 | s = e; | 
|---|
| 2386 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 2387 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2388 | } | 
|---|
| 2389 |  | 
|---|
| 2390 |  | 
|---|
| 2391 | /********************************************************************* | 
|---|
| 2392 | * | 
|---|
| 2393 | *  EDIT_MoveEnd | 
|---|
| 2394 | * | 
|---|
| 2395 | */ | 
|---|
| 2396 | static void EDIT_MoveEnd(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2397 | { | 
|---|
| 2398 | BOOL after_wrap = FALSE; | 
|---|
| 2399 | INT e; | 
|---|
| 2400 |  | 
|---|
| 2401 | /* Pass a high value in x to make sure of receiving the end of the line */ | 
|---|
| 2402 | if (es->style & ES_MULTILINE) | 
|---|
| 2403 | e = EDIT_CharFromPos(hwnd, es, 0x3fffffff, | 
|---|
| 2404 | HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap); | 
|---|
| 2405 | else | 
|---|
| 2406 | e = strlenW(es->text); | 
|---|
| 2407 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, after_wrap); | 
|---|
| 2408 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2409 | } | 
|---|
| 2410 |  | 
|---|
| 2411 |  | 
|---|
| 2412 | /********************************************************************* | 
|---|
| 2413 | * | 
|---|
| 2414 | *  EDIT_MoveForward | 
|---|
| 2415 | * | 
|---|
| 2416 | */ | 
|---|
| 2417 | static void EDIT_MoveForward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2418 | { | 
|---|
| 2419 | INT e = es->selection_end; | 
|---|
| 2420 |  | 
|---|
| 2421 | if (es->text[e]) { | 
|---|
| 2422 | e++; | 
|---|
| 2423 | if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) { | 
|---|
| 2424 | if (es->text[e] == '\n') | 
|---|
| 2425 | e++; | 
|---|
| 2426 | else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n')) | 
|---|
| 2427 | e += 2; | 
|---|
| 2428 | } | 
|---|
| 2429 | } | 
|---|
| 2430 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE); | 
|---|
| 2431 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2432 | } | 
|---|
| 2433 |  | 
|---|
| 2434 |  | 
|---|
| 2435 | /********************************************************************* | 
|---|
| 2436 | * | 
|---|
| 2437 | *  EDIT_MoveHome | 
|---|
| 2438 | * | 
|---|
| 2439 | *  Home key: move to beginning of line. | 
|---|
| 2440 | * | 
|---|
| 2441 | */ | 
|---|
| 2442 | static void EDIT_MoveHome(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2443 | { | 
|---|
| 2444 | INT e; | 
|---|
| 2445 |  | 
|---|
| 2446 | /* Pass the x_offset in x to make sure of receiving the first position of the line */ | 
|---|
| 2447 | if (es->style & ES_MULTILINE) | 
|---|
| 2448 | e = EDIT_CharFromPos(hwnd, es, -es->x_offset, | 
|---|
| 2449 | HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL); | 
|---|
| 2450 | else | 
|---|
| 2451 | e = 0; | 
|---|
| 2452 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE); | 
|---|
| 2453 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2454 | } | 
|---|
| 2455 |  | 
|---|
| 2456 |  | 
|---|
| 2457 | /********************************************************************* | 
|---|
| 2458 | * | 
|---|
| 2459 | *  EDIT_MovePageDown_ML | 
|---|
| 2460 | * | 
|---|
| 2461 | *  Only for multi line controls | 
|---|
| 2462 | *  Move the caret one page down, on a column with the nearest | 
|---|
| 2463 | *  x coordinate on the screen (might be a different column). | 
|---|
| 2464 | * | 
|---|
| 2465 | */ | 
|---|
| 2466 | static void EDIT_MovePageDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2467 | { | 
|---|
| 2468 | INT s = es->selection_start; | 
|---|
| 2469 | INT e = es->selection_end; | 
|---|
| 2470 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 2471 | LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap); | 
|---|
| 2472 | INT x = SLOWORD(pos); | 
|---|
| 2473 | INT y = SHIWORD(pos); | 
|---|
| 2474 |  | 
|---|
| 2475 | e = EDIT_CharFromPos(hwnd, es, x, | 
|---|
| 2476 | y + (es->format_rect.bottom - es->format_rect.top), | 
|---|
| 2477 | &after_wrap); | 
|---|
| 2478 | if (!extend) | 
|---|
| 2479 | s = e; | 
|---|
| 2480 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 2481 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2482 | } | 
|---|
| 2483 |  | 
|---|
| 2484 |  | 
|---|
| 2485 | /********************************************************************* | 
|---|
| 2486 | * | 
|---|
| 2487 | *  EDIT_MovePageUp_ML | 
|---|
| 2488 | * | 
|---|
| 2489 | *  Only for multi line controls | 
|---|
| 2490 | *  Move the caret one page up, on a column with the nearest | 
|---|
| 2491 | *  x coordinate on the screen (might be a different column). | 
|---|
| 2492 | * | 
|---|
| 2493 | */ | 
|---|
| 2494 | static void EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2495 | { | 
|---|
| 2496 | INT s = es->selection_start; | 
|---|
| 2497 | INT e = es->selection_end; | 
|---|
| 2498 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 2499 | LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap); | 
|---|
| 2500 | INT x = SLOWORD(pos); | 
|---|
| 2501 | INT y = SHIWORD(pos); | 
|---|
| 2502 |  | 
|---|
| 2503 | e = EDIT_CharFromPos(hwnd, es, x, | 
|---|
| 2504 | y - (es->format_rect.bottom - es->format_rect.top), | 
|---|
| 2505 | &after_wrap); | 
|---|
| 2506 | if (!extend) | 
|---|
| 2507 | s = e; | 
|---|
| 2508 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 2509 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2510 | } | 
|---|
| 2511 |  | 
|---|
| 2512 |  | 
|---|
| 2513 | /********************************************************************* | 
|---|
| 2514 | * | 
|---|
| 2515 | *  EDIT_MoveUp_ML | 
|---|
| 2516 | * | 
|---|
| 2517 | *  Only for multi line controls | 
|---|
| 2518 | *  Move the caret one line up, on a column with the nearest | 
|---|
| 2519 | *  x coordinate on the screen (might be a different column). | 
|---|
| 2520 | * | 
|---|
| 2521 | */ | 
|---|
| 2522 | static void EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2523 | { | 
|---|
| 2524 | INT s = es->selection_start; | 
|---|
| 2525 | INT e = es->selection_end; | 
|---|
| 2526 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP); | 
|---|
| 2527 | LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap); | 
|---|
| 2528 | INT x = SLOWORD(pos); | 
|---|
| 2529 | INT y = SHIWORD(pos); | 
|---|
| 2530 |  | 
|---|
| 2531 | e = EDIT_CharFromPos(hwnd, es, x, y - es->line_height, &after_wrap); | 
|---|
| 2532 | if (!extend) | 
|---|
| 2533 | s = e; | 
|---|
| 2534 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap); | 
|---|
| 2535 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2536 | } | 
|---|
| 2537 |  | 
|---|
| 2538 |  | 
|---|
| 2539 | /********************************************************************* | 
|---|
| 2540 | * | 
|---|
| 2541 | *  EDIT_MoveWordBackward | 
|---|
| 2542 | * | 
|---|
| 2543 | */ | 
|---|
| 2544 | static void EDIT_MoveWordBackward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2545 | { | 
|---|
| 2546 | INT s = es->selection_start; | 
|---|
| 2547 | INT e = es->selection_end; | 
|---|
| 2548 | INT l; | 
|---|
| 2549 | INT ll; | 
|---|
| 2550 | INT li; | 
|---|
| 2551 |  | 
|---|
| 2552 | l = EDIT_EM_LineFromChar(es, e); | 
|---|
| 2553 | ll = EDIT_EM_LineLength(es, e); | 
|---|
| 2554 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 2555 | if (e - li == 0) { | 
|---|
| 2556 | if (l) { | 
|---|
| 2557 | li = EDIT_EM_LineIndex(es, l - 1); | 
|---|
| 2558 | e = li + EDIT_EM_LineLength(es, li); | 
|---|
| 2559 | } | 
|---|
| 2560 | } else { | 
|---|
| 2561 | e = li + (INT)EDIT_CallWordBreakProc(es, | 
|---|
| 2562 | li, e - li, ll, WB_LEFT); | 
|---|
| 2563 | } | 
|---|
| 2564 | if (!extend) | 
|---|
| 2565 | s = e; | 
|---|
| 2566 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE); | 
|---|
| 2567 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2568 | } | 
|---|
| 2569 |  | 
|---|
| 2570 |  | 
|---|
| 2571 | /********************************************************************* | 
|---|
| 2572 | * | 
|---|
| 2573 | *  EDIT_MoveWordForward | 
|---|
| 2574 | * | 
|---|
| 2575 | */ | 
|---|
| 2576 | static void EDIT_MoveWordForward(HWND hwnd, EDITSTATE *es, BOOL extend) | 
|---|
| 2577 | { | 
|---|
| 2578 | INT s = es->selection_start; | 
|---|
| 2579 | INT e = es->selection_end; | 
|---|
| 2580 | INT l; | 
|---|
| 2581 | INT ll; | 
|---|
| 2582 | INT li; | 
|---|
| 2583 |  | 
|---|
| 2584 | l = EDIT_EM_LineFromChar(es, e); | 
|---|
| 2585 | ll = EDIT_EM_LineLength(es, e); | 
|---|
| 2586 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 2587 | if (e - li == ll) { | 
|---|
| 2588 | if ((es->style & ES_MULTILINE) && (l != es->line_count - 1)) | 
|---|
| 2589 | e = EDIT_EM_LineIndex(es, l + 1); | 
|---|
| 2590 | } else { | 
|---|
| 2591 | e = li + EDIT_CallWordBreakProc(es, | 
|---|
| 2592 | li, e - li + 1, ll, WB_RIGHT); | 
|---|
| 2593 | } | 
|---|
| 2594 | if (!extend) | 
|---|
| 2595 | s = e; | 
|---|
| 2596 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE); | 
|---|
| 2597 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 2598 | } | 
|---|
| 2599 |  | 
|---|
| 2600 |  | 
|---|
| 2601 | /********************************************************************* | 
|---|
| 2602 | * | 
|---|
| 2603 | *  EDIT_PaintLine | 
|---|
| 2604 | * | 
|---|
| 2605 | */ | 
|---|
| 2606 | static void EDIT_PaintLine(HWND hwnd, EDITSTATE *es, HDC dc, INT line, BOOL rev) | 
|---|
| 2607 | { | 
|---|
| 2608 | INT s = es->selection_start; | 
|---|
| 2609 | INT e = es->selection_end; | 
|---|
| 2610 | INT li; | 
|---|
| 2611 | INT ll; | 
|---|
| 2612 | INT x; | 
|---|
| 2613 | INT y; | 
|---|
| 2614 | LRESULT pos; | 
|---|
| 2615 | HBRUSH brush; | 
|---|
| 2616 | RECT rc; | 
|---|
| 2617 |  | 
|---|
| 2618 |  | 
|---|
| 2619 | if (es->style & ES_MULTILINE) { | 
|---|
| 2620 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2621 | if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count)) | 
|---|
| 2622 | return; | 
|---|
| 2623 | } else if (line) | 
|---|
| 2624 | return; | 
|---|
| 2625 |  | 
|---|
| 2626 | TRACE("line=%d\n", line); | 
|---|
| 2627 |  | 
|---|
| 2628 | pos = EDIT_EM_PosFromChar(hwnd, es, EDIT_EM_LineIndex(es, line), FALSE); | 
|---|
| 2629 | x = SLOWORD(pos); | 
|---|
| 2630 | y = SHIWORD(pos); | 
|---|
| 2631 |  | 
|---|
| 2632 | li = EDIT_EM_LineIndex(es, line); | 
|---|
| 2633 | ll = EDIT_EM_LineLength(es, li); | 
|---|
| 2634 | s = es->selection_start; | 
|---|
| 2635 | e = es->selection_end; | 
|---|
| 2636 | ORDER_INT(s, e); | 
|---|
| 2637 | s = min(li + ll, max(li, s)); | 
|---|
| 2638 | e = min(li + ll, max(li, e)); | 
|---|
| 2639 | if (rev && (s != e) && | 
|---|
| 2640 | ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) { | 
|---|
| 2641 | x += EDIT_PaintText(es, dc, x, y, line, 0, s - li, FALSE); | 
|---|
| 2642 | x += EDIT_PaintText(es, dc, x, y, line, s - li, e - s, TRUE); | 
|---|
| 2643 | x += EDIT_PaintText(es, dc, x, y, line, e - li, li + ll - e, FALSE); | 
|---|
| 2644 | } else | 
|---|
| 2645 | x += EDIT_PaintText(es, dc, x, y, line, 0, ll, FALSE); | 
|---|
| 2646 |  | 
|---|
| 2647 | #if 0 | 
|---|
| 2648 | #ifdef __WIN32OS2__ | 
|---|
| 2649 | if ( get_app_version() >= 0x40000 &&( | 
|---|
| 2650 | !es->bEnableState || (es->style & ES_READONLY))) | 
|---|
| 2651 | brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, dc); | 
|---|
| 2652 | else | 
|---|
| 2653 | brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, dc); | 
|---|
| 2654 |  | 
|---|
| 2655 | if (!brush) | 
|---|
| 2656 | brush = (HBRUSH)GetStockObject(WHITE_BRUSH); | 
|---|
| 2657 |  | 
|---|
| 2658 | rc.left = x; | 
|---|
| 2659 | rc.right = es->format_rect.right; | 
|---|
| 2660 | rc.top = y; | 
|---|
| 2661 | rc.bottom = y + es->line_height; | 
|---|
| 2662 |  | 
|---|
| 2663 | FillRect(dc, &rc, brush); | 
|---|
| 2664 | #endif | 
|---|
| 2665 | #endif | 
|---|
| 2666 | } | 
|---|
| 2667 |  | 
|---|
| 2668 |  | 
|---|
| 2669 | /********************************************************************* | 
|---|
| 2670 | * | 
|---|
| 2671 | *  EDIT_PaintText | 
|---|
| 2672 | * | 
|---|
| 2673 | */ | 
|---|
| 2674 | static INT EDIT_PaintText(EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev) | 
|---|
| 2675 | { | 
|---|
| 2676 | COLORREF BkColor; | 
|---|
| 2677 | COLORREF TextColor; | 
|---|
| 2678 | INT ret; | 
|---|
| 2679 | INT li; | 
|---|
| 2680 | INT BkMode; | 
|---|
| 2681 | SIZE size; | 
|---|
| 2682 |  | 
|---|
| 2683 | if (!count) | 
|---|
| 2684 | return 0; | 
|---|
| 2685 | BkMode = GetBkMode(dc); | 
|---|
| 2686 | BkColor = GetBkColor(dc); | 
|---|
| 2687 | TextColor = GetTextColor(dc); | 
|---|
| 2688 | if (rev) { | 
|---|
| 2689 | SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT)); | 
|---|
| 2690 | SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT)); | 
|---|
| 2691 | SetBkMode( dc, OPAQUE); | 
|---|
| 2692 | } | 
|---|
| 2693 | li = EDIT_EM_LineIndex(es, line); | 
|---|
| 2694 | if (es->style & ES_MULTILINE) { | 
|---|
| 2695 | ret = (INT)LOWORD(TabbedTextOutW(dc, x, y, es->text + li + col, count, | 
|---|
| 2696 | es->tabs_count, es->tabs, es->format_rect.left - es->x_offset)); | 
|---|
| 2697 | } else { | 
|---|
| 2698 | LPWSTR text = EDIT_GetPasswordPointer_SL(es); | 
|---|
| 2699 | TextOutW(dc, x, y, text + li + col, count); | 
|---|
| 2700 | GetTextExtentPoint32W(dc, text + li + col, count, &size); | 
|---|
| 2701 | ret = size.cx; | 
|---|
| 2702 | if (es->style & ES_PASSWORD) | 
|---|
| 2703 | HeapFree(GetProcessHeap(), 0, text); | 
|---|
| 2704 | } | 
|---|
| 2705 | if (rev) { | 
|---|
| 2706 | SetBkColor(dc, BkColor); | 
|---|
| 2707 | SetTextColor(dc, TextColor); | 
|---|
| 2708 | SetBkMode( dc, BkMode); | 
|---|
| 2709 | } | 
|---|
| 2710 | return ret; | 
|---|
| 2711 | } | 
|---|
| 2712 |  | 
|---|
| 2713 |  | 
|---|
| 2714 | /********************************************************************* | 
|---|
| 2715 | * | 
|---|
| 2716 | *  EDIT_SetCaretPos | 
|---|
| 2717 | * | 
|---|
| 2718 | */ | 
|---|
| 2719 | static void EDIT_SetCaretPos(HWND hwnd, EDITSTATE *es, INT pos, | 
|---|
| 2720 | BOOL after_wrap) | 
|---|
| 2721 | { | 
|---|
| 2722 | LRESULT res = EDIT_EM_PosFromChar(hwnd, es, pos, after_wrap); | 
|---|
| 2723 |  | 
|---|
| 2724 | #ifdef __WIN32OS2__ | 
|---|
| 2725 | if( es->moveCaret ) | 
|---|
| 2726 | { | 
|---|
| 2727 | HIMC            himc; | 
|---|
| 2728 | CANDIDATEFORM   candForm; | 
|---|
| 2729 |  | 
|---|
| 2730 | himc = ImmGetContext( hwnd ); | 
|---|
| 2731 |  | 
|---|
| 2732 | #endif | 
|---|
| 2733 |  | 
|---|
| 2734 | SetCaretPos(SLOWORD(res), SHIWORD(res)); | 
|---|
| 2735 |  | 
|---|
| 2736 | #ifdef __WIN32OS2__ | 
|---|
| 2737 | if( es->sentenceMode ) | 
|---|
| 2738 | { | 
|---|
| 2739 | COMPOSITIONFORM cf; | 
|---|
| 2740 |  | 
|---|
| 2741 | cf.dwStyle = CFS_POINT; | 
|---|
| 2742 | cf.ptCurrentPos.x = SLOWORD( res ); | 
|---|
| 2743 | cf.ptCurrentPos.y = SHIWORD( res ); | 
|---|
| 2744 |  | 
|---|
| 2745 | ImmSetCompositionWindow( himc, &cf ); | 
|---|
| 2746 | } | 
|---|
| 2747 |  | 
|---|
| 2748 | candForm.dwIndex = 0; | 
|---|
| 2749 | candForm.dwStyle = CFS_CANDIDATEPOS; | 
|---|
| 2750 | candForm.ptCurrentPos.x = SLOWORD( res ); | 
|---|
| 2751 | candForm.ptCurrentPos.y = SHIWORD( res ) + es->line_height; | 
|---|
| 2752 |  | 
|---|
| 2753 | ImmSetCandidateWindow( himc, &candForm ); | 
|---|
| 2754 |  | 
|---|
| 2755 | ImmReleaseContext( hwnd, himc ); | 
|---|
| 2756 | } | 
|---|
| 2757 | #endif | 
|---|
| 2758 | } | 
|---|
| 2759 |  | 
|---|
| 2760 |  | 
|---|
| 2761 | /********************************************************************* | 
|---|
| 2762 | * | 
|---|
| 2763 | *  EDIT_SetRectNP | 
|---|
| 2764 | * | 
|---|
| 2765 | *  note:   this is not (exactly) the handler called on EM_SETRECTNP | 
|---|
| 2766 | *      it is also used to set the rect of a single line control | 
|---|
| 2767 | * | 
|---|
| 2768 | */ | 
|---|
| 2769 | static void EDIT_SetRectNP(HWND hwnd, EDITSTATE *es, LPRECT rc) | 
|---|
| 2770 | { | 
|---|
| 2771 | CopyRect(&es->format_rect, rc); | 
|---|
| 2772 | if (es->style & WS_BORDER) { | 
|---|
| 2773 | INT bw = GetSystemMetrics(SM_CXBORDER) + 1; | 
|---|
| 2774 | if(TWEAK_WineLook == WIN31_LOOK) | 
|---|
| 2775 | bw += 2; | 
|---|
| 2776 | es->format_rect.left += bw; | 
|---|
| 2777 | es->format_rect.top += bw; | 
|---|
| 2778 | es->format_rect.right -= bw; | 
|---|
| 2779 | es->format_rect.bottom -= bw; | 
|---|
| 2780 | } | 
|---|
| 2781 | es->format_rect.left += es->left_margin; | 
|---|
| 2782 | es->format_rect.right -= es->right_margin; | 
|---|
| 2783 | es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width); | 
|---|
| 2784 | if (es->style & ES_MULTILINE) | 
|---|
| 2785 | { | 
|---|
| 2786 | INT fw, vlc, max_x_offset, max_y_offset; | 
|---|
| 2787 |  | 
|---|
| 2788 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2789 | es->format_rect.bottom = es->format_rect.top + max(1, vlc) * es->line_height; | 
|---|
| 2790 |  | 
|---|
| 2791 | /* correct es->x_offset */ | 
|---|
| 2792 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 2793 | max_x_offset = es->text_width - fw; | 
|---|
| 2794 | if(max_x_offset < 0) max_x_offset = 0; | 
|---|
| 2795 | if(es->x_offset > max_x_offset) | 
|---|
| 2796 | es->x_offset = max_x_offset; | 
|---|
| 2797 |  | 
|---|
| 2798 | /* correct es->y_offset */ | 
|---|
| 2799 | max_y_offset = es->line_count - vlc; | 
|---|
| 2800 | if(max_y_offset < 0) max_y_offset = 0; | 
|---|
| 2801 | if(es->y_offset > max_y_offset) | 
|---|
| 2802 | es->y_offset = max_y_offset; | 
|---|
| 2803 |  | 
|---|
| 2804 | /* force scroll info update */ | 
|---|
| 2805 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 2806 | } | 
|---|
| 2807 | else | 
|---|
| 2808 | /* Windows doesn't care to fix text placement for SL controls */ | 
|---|
| 2809 | es->format_rect.bottom = es->format_rect.top + es->line_height; | 
|---|
| 2810 |  | 
|---|
| 2811 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) | 
|---|
| 2812 | EDIT_BuildLineDefs_ML(hwnd, es, 0, strlenW(es->text), 0, (HRGN)0); | 
|---|
| 2813 | } | 
|---|
| 2814 |  | 
|---|
| 2815 |  | 
|---|
| 2816 | /********************************************************************* | 
|---|
| 2817 | * | 
|---|
| 2818 | *  EDIT_UnlockBuffer | 
|---|
| 2819 | * | 
|---|
| 2820 | */ | 
|---|
| 2821 | static void EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force) | 
|---|
| 2822 | { | 
|---|
| 2823 | HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE ); | 
|---|
| 2824 |  | 
|---|
| 2825 | /* Edit window might be already destroyed */ | 
|---|
| 2826 | if(!IsWindow(hwnd)) | 
|---|
| 2827 | { | 
|---|
| 2828 | WARN("edit hwnd %04x already destroyed\n", hwnd); | 
|---|
| 2829 | return; | 
|---|
| 2830 | } | 
|---|
| 2831 |  | 
|---|
| 2832 | if (!es) { | 
|---|
| 2833 | ERR("no EDITSTATE ... please report\n"); | 
|---|
| 2834 | return; | 
|---|
| 2835 | } | 
|---|
| 2836 | if (!es->lock_count) { | 
|---|
| 2837 | ERR("lock_count == 0 ... please report\n"); | 
|---|
| 2838 | return; | 
|---|
| 2839 | } | 
|---|
| 2840 | if (!es->text) { | 
|---|
| 2841 | ERR("es->text == 0 ... please report\n"); | 
|---|
| 2842 | return; | 
|---|
| 2843 | } | 
|---|
| 2844 |  | 
|---|
| 2845 | if (force || (es->lock_count == 1)) { | 
|---|
| 2846 | if (es->hloc32W) { | 
|---|
| 2847 | CHAR *textA = NULL; | 
|---|
| 2848 | BOOL _16bit = FALSE; | 
|---|
| 2849 | UINT countA = 0; | 
|---|
| 2850 | UINT countW = strlenW(es->text) + 1; | 
|---|
| 2851 |  | 
|---|
| 2852 | if(es->hloc32A) | 
|---|
| 2853 | { | 
|---|
| 2854 | UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL); | 
|---|
| 2855 | TRACE("Synchronizing with 32-bit ANSI buffer\n"); | 
|---|
| 2856 | TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new); | 
|---|
| 2857 | countA = LocalSize(es->hloc32A); | 
|---|
| 2858 | if(countA_new > countA) | 
|---|
| 2859 | { | 
|---|
| 2860 | HLOCAL hloc32A_new; | 
|---|
| 2861 | UINT alloc_size = ROUND_TO_GROW(countA_new); | 
|---|
| 2862 | TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size); | 
|---|
| 2863 | hloc32A_new = LocalReAlloc(es->hloc32A, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT); | 
|---|
| 2864 | if(hloc32A_new) | 
|---|
| 2865 | { | 
|---|
| 2866 | es->hloc32A = hloc32A_new; | 
|---|
| 2867 | countA = LocalSize(hloc32A_new); | 
|---|
| 2868 | TRACE("Real new size %d bytes\n", countA); | 
|---|
| 2869 | } | 
|---|
| 2870 | else | 
|---|
| 2871 | WARN("FAILED! Will synchronize partially\n"); | 
|---|
| 2872 | } | 
|---|
| 2873 | textA = LocalLock(es->hloc32A); | 
|---|
| 2874 | } | 
|---|
| 2875 | else if(es->hloc16) | 
|---|
| 2876 | { | 
|---|
| 2877 | UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL); | 
|---|
| 2878 | TRACE("Synchronizing with 16-bit ANSI buffer\n"); | 
|---|
| 2879 | TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new); | 
|---|
| 2880 | countA = LOCAL_Size(hInstance, es->hloc16); | 
|---|
| 2881 | if(countA_new > countA) | 
|---|
| 2882 | { | 
|---|
| 2883 | HLOCAL16 hloc16_new; | 
|---|
| 2884 | UINT alloc_size = ROUND_TO_GROW(countA_new); | 
|---|
| 2885 | TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size); | 
|---|
| 2886 | hloc16_new = LOCAL_ReAlloc(hInstance, es->hloc16, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT); | 
|---|
| 2887 | if(hloc16_new) | 
|---|
| 2888 | { | 
|---|
| 2889 | es->hloc16 = hloc16_new; | 
|---|
| 2890 | countA = LOCAL_Size(hInstance, hloc16_new); | 
|---|
| 2891 | TRACE("Real new size %d bytes\n", countA); | 
|---|
| 2892 | } | 
|---|
| 2893 | else | 
|---|
| 2894 | WARN("FAILED! Will synchronize partially\n"); | 
|---|
| 2895 | } | 
|---|
| 2896 | textA = LOCAL_Lock(hInstance, es->hloc16); | 
|---|
| 2897 | _16bit = TRUE; | 
|---|
| 2898 | } | 
|---|
| 2899 | if(textA) | 
|---|
| 2900 | { | 
|---|
| 2901 | WideCharToMultiByte(CP_ACP, 0, es->text, countW, textA, countA, NULL, NULL); | 
|---|
| 2902 | if(_16bit) | 
|---|
| 2903 | LOCAL_Unlock(hInstance, es->hloc16); | 
|---|
| 2904 | else | 
|---|
| 2905 | LocalUnlock(es->hloc32A); | 
|---|
| 2906 | } | 
|---|
| 2907 |  | 
|---|
| 2908 | LocalUnlock(es->hloc32W); | 
|---|
| 2909 | es->text = NULL; | 
|---|
| 2910 | } | 
|---|
| 2911 | else { | 
|---|
| 2912 | ERR("no buffer ... please report\n"); | 
|---|
| 2913 | return; | 
|---|
| 2914 | } | 
|---|
| 2915 | } | 
|---|
| 2916 | es->lock_count--; | 
|---|
| 2917 | } | 
|---|
| 2918 |  | 
|---|
| 2919 |  | 
|---|
| 2920 | /********************************************************************* | 
|---|
| 2921 | * | 
|---|
| 2922 | *  EDIT_UpdateScrollInfo | 
|---|
| 2923 | * | 
|---|
| 2924 | */ | 
|---|
| 2925 | static void EDIT_UpdateScrollInfo(HWND hwnd, EDITSTATE *es) | 
|---|
| 2926 | { | 
|---|
| 2927 | if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) | 
|---|
| 2928 | { | 
|---|
| 2929 | SCROLLINFO si; | 
|---|
| 2930 | si.cbSize   = sizeof(SCROLLINFO); | 
|---|
| 2931 | si.fMask    = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; | 
|---|
| 2932 | si.nMin     = 0; | 
|---|
| 2933 | si.nMax     = es->line_count - 1; | 
|---|
| 2934 | si.nPage    = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 2935 | si.nPos     = es->y_offset; | 
|---|
| 2936 | TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n", | 
|---|
| 2937 | si.nMin, si.nMax, si.nPage, si.nPos); | 
|---|
| 2938 | SetScrollInfo(hwnd, SB_VERT, &si, TRUE); | 
|---|
| 2939 | } | 
|---|
| 2940 |  | 
|---|
| 2941 | if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) | 
|---|
| 2942 | { | 
|---|
| 2943 | SCROLLINFO si; | 
|---|
| 2944 | si.cbSize   = sizeof(SCROLLINFO); | 
|---|
| 2945 | si.fMask    = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; | 
|---|
| 2946 | si.nMin     = 0; | 
|---|
| 2947 | si.nMax     = es->text_width - 1; | 
|---|
| 2948 | si.nPage    = es->format_rect.right - es->format_rect.left; | 
|---|
| 2949 | si.nPos     = es->x_offset; | 
|---|
| 2950 | TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n", | 
|---|
| 2951 | si.nMin, si.nMax, si.nPage, si.nPos); | 
|---|
| 2952 | SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); | 
|---|
| 2953 | } | 
|---|
| 2954 | } | 
|---|
| 2955 |  | 
|---|
| 2956 | /********************************************************************* | 
|---|
| 2957 | * | 
|---|
| 2958 | *  EDIT_WordBreakProc | 
|---|
| 2959 | * | 
|---|
| 2960 | *  Find the beginning of words. | 
|---|
| 2961 | *  Note:   unlike the specs for a WordBreakProc, this function only | 
|---|
| 2962 | *      allows to be called without linebreaks between s[0] upto | 
|---|
| 2963 | *      s[count - 1].  Remember it is only called | 
|---|
| 2964 | *      internally, so we can decide this for ourselves. | 
|---|
| 2965 | * | 
|---|
| 2966 | */ | 
|---|
| 2967 | static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action) | 
|---|
| 2968 | { | 
|---|
| 2969 | INT ret = 0; | 
|---|
| 2970 |  | 
|---|
| 2971 | TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action); | 
|---|
| 2972 |  | 
|---|
| 2973 | if(!s) return 0; | 
|---|
| 2974 |  | 
|---|
| 2975 | switch (action) { | 
|---|
| 2976 | case WB_LEFT: | 
|---|
| 2977 | if (!count) | 
|---|
| 2978 | break; | 
|---|
| 2979 | if (index) | 
|---|
| 2980 | index--; | 
|---|
| 2981 | if (s[index] == ' ') { | 
|---|
| 2982 | while (index && (s[index] == ' ')) | 
|---|
| 2983 | index--; | 
|---|
| 2984 | if (index) { | 
|---|
| 2985 | while (index && (s[index] != ' ')) | 
|---|
| 2986 | index--; | 
|---|
| 2987 | if (s[index] == ' ') | 
|---|
| 2988 | index++; | 
|---|
| 2989 | } | 
|---|
| 2990 | } else { | 
|---|
| 2991 | while (index && (s[index] != ' ')) | 
|---|
| 2992 | index--; | 
|---|
| 2993 | if (s[index] == ' ') | 
|---|
| 2994 | index++; | 
|---|
| 2995 | } | 
|---|
| 2996 | ret = index; | 
|---|
| 2997 | break; | 
|---|
| 2998 | case WB_RIGHT: | 
|---|
| 2999 | if (!count) | 
|---|
| 3000 | break; | 
|---|
| 3001 | if (index) | 
|---|
| 3002 | index--; | 
|---|
| 3003 | if (s[index] == ' ') | 
|---|
| 3004 | while ((index < count) && (s[index] == ' ')) index++; | 
|---|
| 3005 | else { | 
|---|
| 3006 | while (s[index] && (s[index] != ' ') && (index < count)) | 
|---|
| 3007 | index++; | 
|---|
| 3008 | while ((s[index] == ' ') && (index < count)) index++; | 
|---|
| 3009 | } | 
|---|
| 3010 | ret = index; | 
|---|
| 3011 | break; | 
|---|
| 3012 | case WB_ISDELIMITER: | 
|---|
| 3013 | ret = (s[index] == ' '); | 
|---|
| 3014 | break; | 
|---|
| 3015 | default: | 
|---|
| 3016 | ERR("unknown action code, please report !\n"); | 
|---|
| 3017 | break; | 
|---|
| 3018 | } | 
|---|
| 3019 | return ret; | 
|---|
| 3020 | } | 
|---|
| 3021 |  | 
|---|
| 3022 |  | 
|---|
| 3023 | /********************************************************************* | 
|---|
| 3024 | * | 
|---|
| 3025 | *  EM_CHARFROMPOS | 
|---|
| 3026 | * | 
|---|
| 3027 | *      returns line number (not index) in high-order word of result. | 
|---|
| 3028 | *      NB : Q137805 is unclear about this. POINT * pointer in lParam apply | 
|---|
| 3029 | *      to Richedit, not to the edit control. Original documentation is valid. | 
|---|
| 3030 | *  FIXME: do the specs mean to return -1 if outside client area or | 
|---|
| 3031 | *      if outside formatting rectangle ??? | 
|---|
| 3032 | * | 
|---|
| 3033 | */ | 
|---|
| 3034 | static LRESULT EDIT_EM_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y) | 
|---|
| 3035 | { | 
|---|
| 3036 | POINT pt; | 
|---|
| 3037 | RECT rc; | 
|---|
| 3038 | INT index; | 
|---|
| 3039 |  | 
|---|
| 3040 | pt.x = x; | 
|---|
| 3041 | pt.y = y; | 
|---|
| 3042 | GetClientRect(hwnd, &rc); | 
|---|
| 3043 | if (!PtInRect(&rc, pt)) | 
|---|
| 3044 | return -1; | 
|---|
| 3045 |  | 
|---|
| 3046 | index = EDIT_CharFromPos(hwnd, es, x, y, NULL); | 
|---|
| 3047 | return MAKELONG(index, EDIT_EM_LineFromChar(es, index)); | 
|---|
| 3048 | } | 
|---|
| 3049 |  | 
|---|
| 3050 |  | 
|---|
| 3051 | /********************************************************************* | 
|---|
| 3052 | * | 
|---|
| 3053 | *  EM_FMTLINES | 
|---|
| 3054 | * | 
|---|
| 3055 | * Enable or disable soft breaks. | 
|---|
| 3056 | */ | 
|---|
| 3057 | static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol) | 
|---|
| 3058 | { | 
|---|
| 3059 | es->flags &= ~EF_USE_SOFTBRK; | 
|---|
| 3060 | if (add_eol) { | 
|---|
| 3061 | es->flags |= EF_USE_SOFTBRK; | 
|---|
| 3062 | FIXME("soft break enabled, not implemented\n"); | 
|---|
| 3063 | } | 
|---|
| 3064 | return add_eol; | 
|---|
| 3065 | } | 
|---|
| 3066 |  | 
|---|
| 3067 |  | 
|---|
| 3068 | /********************************************************************* | 
|---|
| 3069 | * | 
|---|
| 3070 | *  EM_GETHANDLE | 
|---|
| 3071 | * | 
|---|
| 3072 | *  Hopefully this won't fire back at us. | 
|---|
| 3073 | *  We always start with a fixed buffer in the local heap. | 
|---|
| 3074 | *  Despite of the documentation says that the local heap is used | 
|---|
| 3075 | *  only if DS_LOCALEDIT flag is set, NT and 2000 always allocate | 
|---|
| 3076 | *  buffer on the local heap. | 
|---|
| 3077 | * | 
|---|
| 3078 | */ | 
|---|
| 3079 | static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es) | 
|---|
| 3080 | { | 
|---|
| 3081 | HLOCAL hLocal; | 
|---|
| 3082 |  | 
|---|
| 3083 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3084 | return 0; | 
|---|
| 3085 |  | 
|---|
| 3086 | if(es->is_unicode) | 
|---|
| 3087 | hLocal = es->hloc32W; | 
|---|
| 3088 | else | 
|---|
| 3089 | { | 
|---|
| 3090 | if(!es->hloc32A) | 
|---|
| 3091 | { | 
|---|
| 3092 | CHAR *textA; | 
|---|
| 3093 | UINT countA, alloc_size; | 
|---|
| 3094 | TRACE("Allocating 32-bit ANSI alias buffer\n"); | 
|---|
| 3095 | countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL); | 
|---|
| 3096 | alloc_size = ROUND_TO_GROW(countA); | 
|---|
| 3097 | if(!(es->hloc32A = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) | 
|---|
| 3098 | { | 
|---|
| 3099 | ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size); | 
|---|
| 3100 | return 0; | 
|---|
| 3101 | } | 
|---|
| 3102 | textA = LocalLock(es->hloc32A); | 
|---|
| 3103 | WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL); | 
|---|
| 3104 | LocalUnlock(es->hloc32A); | 
|---|
| 3105 | } | 
|---|
| 3106 | hLocal = es->hloc32A; | 
|---|
| 3107 | } | 
|---|
| 3108 |  | 
|---|
| 3109 | TRACE("Returning %04X, LocalSize() = %d\n", hLocal, LocalSize(hLocal)); | 
|---|
| 3110 | return hLocal; | 
|---|
| 3111 | } | 
|---|
| 3112 |  | 
|---|
| 3113 | #ifndef __WIN32OS2__ | 
|---|
| 3114 | /********************************************************************* | 
|---|
| 3115 | * | 
|---|
| 3116 | *  EM_GETHANDLE16 | 
|---|
| 3117 | * | 
|---|
| 3118 | *  Hopefully this won't fire back at us. | 
|---|
| 3119 | *  We always start with a buffer in 32 bit linear memory. | 
|---|
| 3120 | *  However, with this message a 16 bit application requests | 
|---|
| 3121 | *  a handle of 16 bit local heap memory, where it expects to find | 
|---|
| 3122 | *  the text. | 
|---|
| 3123 | *  It's a pitty that from this moment on we have to use this | 
|---|
| 3124 | *  local heap, because applications may rely on the handle | 
|---|
| 3125 | *  in the future. | 
|---|
| 3126 | * | 
|---|
| 3127 | *  In this function we'll try to switch to local heap. | 
|---|
| 3128 | */ | 
|---|
| 3129 | static HLOCAL16 EDIT_EM_GetHandle16(HWND hwnd, EDITSTATE *es) | 
|---|
| 3130 | { | 
|---|
| 3131 | HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE ); | 
|---|
| 3132 | CHAR *textA; | 
|---|
| 3133 | UINT countA, alloc_size; | 
|---|
| 3134 |  | 
|---|
| 3135 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3136 | return 0; | 
|---|
| 3137 |  | 
|---|
| 3138 | if (es->hloc16) | 
|---|
| 3139 | return es->hloc16; | 
|---|
| 3140 |  | 
|---|
| 3141 | if (!LOCAL_HeapSize(hInstance)) { | 
|---|
| 3142 | if (!LocalInit16(hInstance, 0, | 
|---|
| 3143 | GlobalSize16(hInstance))) { | 
|---|
| 3144 | ERR("could not initialize local heap\n"); | 
|---|
| 3145 | return 0; | 
|---|
| 3146 | } | 
|---|
| 3147 | TRACE("local heap initialized\n"); | 
|---|
| 3148 | } | 
|---|
| 3149 |  | 
|---|
| 3150 | countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL); | 
|---|
| 3151 | alloc_size = ROUND_TO_GROW(countA); | 
|---|
| 3152 |  | 
|---|
| 3153 | TRACE("Allocating 16-bit ANSI alias buffer\n"); | 
|---|
| 3154 | if (!(es->hloc16 = LOCAL_Alloc(hInstance, LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) { | 
|---|
| 3155 | ERR("could not allocate new 16 bit buffer\n"); | 
|---|
| 3156 | return 0; | 
|---|
| 3157 | } | 
|---|
| 3158 |  | 
|---|
| 3159 | if (!(textA = (LPSTR)LOCAL_Lock(hInstance, es->hloc16))) { | 
|---|
| 3160 | ERR("could not lock new 16 bit buffer\n"); | 
|---|
| 3161 | LOCAL_Free(hInstance, es->hloc16); | 
|---|
| 3162 | es->hloc16 = 0; | 
|---|
| 3163 | return 0; | 
|---|
| 3164 | } | 
|---|
| 3165 |  | 
|---|
| 3166 | WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL); | 
|---|
| 3167 | LOCAL_Unlock(hInstance, es->hloc16); | 
|---|
| 3168 |  | 
|---|
| 3169 | TRACE("Returning %04X, LocalSize() = %d\n", es->hloc16, LOCAL_Size(hInstance, es->hloc16)); | 
|---|
| 3170 | return es->hloc16; | 
|---|
| 3171 | } | 
|---|
| 3172 | #endif | 
|---|
| 3173 |  | 
|---|
| 3174 | /********************************************************************* | 
|---|
| 3175 | * | 
|---|
| 3176 | *  EM_GETLINE | 
|---|
| 3177 | * | 
|---|
| 3178 | */ | 
|---|
| 3179 | static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPARAM lParam, BOOL unicode) | 
|---|
| 3180 | { | 
|---|
| 3181 | LPWSTR src; | 
|---|
| 3182 | INT line_len, dst_len; | 
|---|
| 3183 | INT i; | 
|---|
| 3184 |  | 
|---|
| 3185 | if (es->style & ES_MULTILINE) { | 
|---|
| 3186 | if (line >= es->line_count) | 
|---|
| 3187 | return 0; | 
|---|
| 3188 | } else | 
|---|
| 3189 | line = 0; | 
|---|
| 3190 | i = EDIT_EM_LineIndex(es, line); | 
|---|
| 3191 | src = es->text + i; | 
|---|
| 3192 | line_len = EDIT_EM_LineLength(es, i); | 
|---|
| 3193 | dst_len = *(WORD *)lParam; | 
|---|
| 3194 | if(unicode) | 
|---|
| 3195 | { | 
|---|
| 3196 | LPWSTR dst = (LPWSTR)lParam; | 
|---|
| 3197 | if(dst_len <= line_len) | 
|---|
| 3198 | { | 
|---|
| 3199 | memcpy(dst, src, dst_len * sizeof(WCHAR)); | 
|---|
| 3200 | return dst_len; | 
|---|
| 3201 | } | 
|---|
| 3202 | else /* Append 0 if enough space */ | 
|---|
| 3203 | { | 
|---|
| 3204 | memcpy(dst, src, line_len * sizeof(WCHAR)); | 
|---|
| 3205 | dst[line_len] = 0; | 
|---|
| 3206 | return line_len; | 
|---|
| 3207 | } | 
|---|
| 3208 | } | 
|---|
| 3209 | else | 
|---|
| 3210 | { | 
|---|
| 3211 | LPSTR dst = (LPSTR)lParam; | 
|---|
| 3212 | INT ret; | 
|---|
| 3213 | ret = WideCharToMultiByte(CP_ACP, 0, src, line_len, dst, dst_len, NULL, NULL); | 
|---|
| 3214 | if(!ret) /* Insufficient buffer size */ | 
|---|
| 3215 | return dst_len; | 
|---|
| 3216 | if(ret < dst_len) /* Append 0 if enough space */ | 
|---|
| 3217 | dst[ret] = 0; | 
|---|
| 3218 | return ret; | 
|---|
| 3219 | } | 
|---|
| 3220 | } | 
|---|
| 3221 |  | 
|---|
| 3222 |  | 
|---|
| 3223 | /********************************************************************* | 
|---|
| 3224 | * | 
|---|
| 3225 | *  EM_GETSEL | 
|---|
| 3226 | * | 
|---|
| 3227 | */ | 
|---|
| 3228 | static LRESULT EDIT_EM_GetSel(EDITSTATE *es, LPUINT start, LPUINT end) | 
|---|
| 3229 | { | 
|---|
| 3230 | UINT s = es->selection_start; | 
|---|
| 3231 | UINT e = es->selection_end; | 
|---|
| 3232 |  | 
|---|
| 3233 | #ifdef __WIN32OS2__ | 
|---|
| 3234 | if( !es->is_unicode) | 
|---|
| 3235 | { | 
|---|
| 3236 | s = WideCharToMultiByte( CP_ACP, 0, es->text, s, 0, 0, 0, 0 ); | 
|---|
| 3237 | e = WideCharToMultiByte( CP_ACP, 0, es->text, e, 0, 0, 0, 0 ); | 
|---|
| 3238 | } | 
|---|
| 3239 | #endif | 
|---|
| 3240 |  | 
|---|
| 3241 | ORDER_UINT(s, e); | 
|---|
| 3242 | if (start) | 
|---|
| 3243 | *start = s; | 
|---|
| 3244 | if (end) | 
|---|
| 3245 | *end = e; | 
|---|
| 3246 | return MAKELONG(s, e); | 
|---|
| 3247 | } | 
|---|
| 3248 |  | 
|---|
| 3249 |  | 
|---|
| 3250 | /********************************************************************* | 
|---|
| 3251 | * | 
|---|
| 3252 | *  EM_GETTHUMB | 
|---|
| 3253 | * | 
|---|
| 3254 | *  FIXME: is this right ?  (or should it be only VSCROLL) | 
|---|
| 3255 | *  (and maybe only for edit controls that really have their | 
|---|
| 3256 | *  own scrollbars) (and maybe only for multiline controls ?) | 
|---|
| 3257 | *  All in all: very poorly documented | 
|---|
| 3258 | * | 
|---|
| 3259 | */ | 
|---|
| 3260 | static LRESULT EDIT_EM_GetThumb(HWND hwnd, EDITSTATE *es) | 
|---|
| 3261 | { | 
|---|
| 3262 | return MAKELONG(EDIT_WM_VScroll(hwnd, es, EM_GETTHUMB16, 0), | 
|---|
| 3263 | EDIT_WM_HScroll(hwnd, es, EM_GETTHUMB16, 0)); | 
|---|
| 3264 | } | 
|---|
| 3265 |  | 
|---|
| 3266 |  | 
|---|
| 3267 | /********************************************************************* | 
|---|
| 3268 | * | 
|---|
| 3269 | *  EM_LINEFROMCHAR | 
|---|
| 3270 | * | 
|---|
| 3271 | */ | 
|---|
| 3272 | static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index) | 
|---|
| 3273 | { | 
|---|
| 3274 | INT line; | 
|---|
| 3275 | LINEDEF *line_def; | 
|---|
| 3276 |  | 
|---|
| 3277 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3278 | return 0; | 
|---|
| 3279 | if (index > (INT)strlenW(es->text)) | 
|---|
| 3280 | return es->line_count - 1; | 
|---|
| 3281 | if (index == -1) | 
|---|
| 3282 | index = min(es->selection_start, es->selection_end); | 
|---|
| 3283 |  | 
|---|
| 3284 | line = 0; | 
|---|
| 3285 | line_def = es->first_line_def; | 
|---|
| 3286 | index -= line_def->length; | 
|---|
| 3287 | while ((index >= 0) && line_def->next) { | 
|---|
| 3288 | line++; | 
|---|
| 3289 | line_def = line_def->next; | 
|---|
| 3290 | index -= line_def->length; | 
|---|
| 3291 | } | 
|---|
| 3292 | return line; | 
|---|
| 3293 | } | 
|---|
| 3294 |  | 
|---|
| 3295 |  | 
|---|
| 3296 | /********************************************************************* | 
|---|
| 3297 | * | 
|---|
| 3298 | *  EM_LINEINDEX | 
|---|
| 3299 | * | 
|---|
| 3300 | */ | 
|---|
| 3301 | static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line) | 
|---|
| 3302 | { | 
|---|
| 3303 | INT line_index; | 
|---|
| 3304 | LINEDEF *line_def; | 
|---|
| 3305 |  | 
|---|
| 3306 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3307 | return 0; | 
|---|
| 3308 | if (line >= es->line_count) | 
|---|
| 3309 | return -1; | 
|---|
| 3310 |  | 
|---|
| 3311 | line_index = 0; | 
|---|
| 3312 | line_def = es->first_line_def; | 
|---|
| 3313 | if (line == -1) { | 
|---|
| 3314 | INT index = es->selection_end - line_def->length; | 
|---|
| 3315 | while ((index >= 0) && line_def->next) { | 
|---|
| 3316 | line_index += line_def->length; | 
|---|
| 3317 | line_def = line_def->next; | 
|---|
| 3318 | index -= line_def->length; | 
|---|
| 3319 | } | 
|---|
| 3320 | } else { | 
|---|
| 3321 | while (line > 0) { | 
|---|
| 3322 | line_index += line_def->length; | 
|---|
| 3323 | line_def = line_def->next; | 
|---|
| 3324 | line--; | 
|---|
| 3325 | } | 
|---|
| 3326 | } | 
|---|
| 3327 | return line_index; | 
|---|
| 3328 | } | 
|---|
| 3329 |  | 
|---|
| 3330 |  | 
|---|
| 3331 | /********************************************************************* | 
|---|
| 3332 | * | 
|---|
| 3333 | *  EM_LINELENGTH | 
|---|
| 3334 | * | 
|---|
| 3335 | */ | 
|---|
| 3336 | static INT EDIT_EM_LineLength(EDITSTATE *es, INT index) | 
|---|
| 3337 | { | 
|---|
| 3338 | LINEDEF *line_def; | 
|---|
| 3339 |  | 
|---|
| 3340 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3341 | return strlenW(es->text); | 
|---|
| 3342 |  | 
|---|
| 3343 | if (index == -1) { | 
|---|
| 3344 | /* get the number of remaining non-selected chars of selected lines */ | 
|---|
| 3345 | INT32 l; /* line number */ | 
|---|
| 3346 | INT32 li; /* index of first char in line */ | 
|---|
| 3347 | INT32 count; | 
|---|
| 3348 | l = EDIT_EM_LineFromChar(es, es->selection_start); | 
|---|
| 3349 | /* # chars before start of selection area */ | 
|---|
| 3350 | count = es->selection_start - EDIT_EM_LineIndex(es, l); | 
|---|
| 3351 | l = EDIT_EM_LineFromChar(es, es->selection_end); | 
|---|
| 3352 | /* # chars after end of selection */ | 
|---|
| 3353 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 3354 | count += li + EDIT_EM_LineLength(es, li) - es->selection_end; | 
|---|
| 3355 | return count; | 
|---|
| 3356 | } | 
|---|
| 3357 | line_def = es->first_line_def; | 
|---|
| 3358 | index -= line_def->length; | 
|---|
| 3359 | while ((index >= 0) && line_def->next) { | 
|---|
| 3360 | line_def = line_def->next; | 
|---|
| 3361 | index -= line_def->length; | 
|---|
| 3362 | } | 
|---|
| 3363 | return line_def->net_length; | 
|---|
| 3364 | } | 
|---|
| 3365 |  | 
|---|
| 3366 | #ifdef __WIN32OS2__ | 
|---|
| 3367 | /********************************************************************* | 
|---|
| 3368 | * | 
|---|
| 3369 | *  EM_LINELENGTH for ANSI | 
|---|
| 3370 | * | 
|---|
| 3371 | */ | 
|---|
| 3372 | static INT EDIT_EM_LineLengthA(EDITSTATE *es, INT index) | 
|---|
| 3373 | { | 
|---|
| 3374 | LINEDEF *line_def; | 
|---|
| 3375 |  | 
|---|
| 3376 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3377 | return ( WideCharToMultiByte( CP_ACP, 0, es->text, -1, 0, 0, 0, 0 ) - 1); | 
|---|
| 3378 |  | 
|---|
| 3379 | if (index == -1) { | 
|---|
| 3380 | /* get the number of remaining non-selected chars of selected lines */ | 
|---|
| 3381 | INT32 l; /* line number */ | 
|---|
| 3382 | INT32 li; /* index of first char in line */ | 
|---|
| 3383 | INT32 count; | 
|---|
| 3384 | l = EDIT_EM_LineFromChar(es, es->selection_start); | 
|---|
| 3385 | li = EDIT_EM_LineIndex( es, l ); | 
|---|
| 3386 | li = WideCharToMultiByte( CP_ACP, 0, es->text, li, 0, 0, 0, 0 ); | 
|---|
| 3387 | /* # chars before start of selection area */ | 
|---|
| 3388 | count = WideCharToMultiByte( CP_ACP, 0, es->text, es->selection_start, 0, 0, 0, 0 ); | 
|---|
| 3389 | count -= li; | 
|---|
| 3390 | l = EDIT_EM_LineFromChar(es, es->selection_end); | 
|---|
| 3391 | /* # chars after end of selection */ | 
|---|
| 3392 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 3393 | li = WideCharToMultiByte( CP_ACP, 0, es->text, li, 0, 0, 0, 0 ); | 
|---|
| 3394 | count += li + EDIT_EM_LineLengthA(es, li); | 
|---|
| 3395 | count -= WideCharToMultiByte( CP_ACP, 0, es->text, es->selection_end, 0, 0, 0, 0 ); | 
|---|
| 3396 | return count; | 
|---|
| 3397 | } | 
|---|
| 3398 | line_def = es->first_line_def; | 
|---|
| 3399 | index -= line_def->length; | 
|---|
| 3400 | while ((index >= 0) && line_def->next) { | 
|---|
| 3401 | line_def = line_def->next; | 
|---|
| 3402 | index -= line_def->length; | 
|---|
| 3403 | } | 
|---|
| 3404 | return WideCharToMultiByte( CP_ACP, 0, es->text + line_def->index, line_def->net_length, 0, 0, 0, 0 ); | 
|---|
| 3405 | } | 
|---|
| 3406 | #endif | 
|---|
| 3407 |  | 
|---|
| 3408 | /********************************************************************* | 
|---|
| 3409 | * | 
|---|
| 3410 | *  EM_LINESCROLL | 
|---|
| 3411 | * | 
|---|
| 3412 | *  NOTE: dx is in average character widths, dy - in lines; | 
|---|
| 3413 | * | 
|---|
| 3414 | */ | 
|---|
| 3415 | static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy) | 
|---|
| 3416 | { | 
|---|
| 3417 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3418 | return FALSE; | 
|---|
| 3419 |  | 
|---|
| 3420 | dx *= es->char_width; | 
|---|
| 3421 | return EDIT_EM_LineScroll_internal(hwnd, es, dx, dy); | 
|---|
| 3422 | } | 
|---|
| 3423 |  | 
|---|
| 3424 | /********************************************************************* | 
|---|
| 3425 | * | 
|---|
| 3426 | *  EDIT_EM_LineScroll_internal | 
|---|
| 3427 | * | 
|---|
| 3428 | *  Version of EDIT_EM_LineScroll for internal use. | 
|---|
| 3429 | *  It doesn't refuse if ES_MULTILINE is set and assumes that | 
|---|
| 3430 | *  dx is in pixels, dy - in lines. | 
|---|
| 3431 | * | 
|---|
| 3432 | */ | 
|---|
| 3433 | static BOOL EDIT_EM_LineScroll_internal(HWND hwnd, EDITSTATE *es, INT dx, INT dy) | 
|---|
| 3434 | { | 
|---|
| 3435 | INT nyoff; | 
|---|
| 3436 | INT x_offset_in_pixels; | 
|---|
| 3437 |  | 
|---|
| 3438 | if (es->style & ES_MULTILINE) | 
|---|
| 3439 | { | 
|---|
| 3440 | x_offset_in_pixels = es->x_offset; | 
|---|
| 3441 | } | 
|---|
| 3442 | else | 
|---|
| 3443 | { | 
|---|
| 3444 | dy = 0; | 
|---|
| 3445 | x_offset_in_pixels = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->x_offset, FALSE)); | 
|---|
| 3446 | } | 
|---|
| 3447 |  | 
|---|
| 3448 | if (-dx > x_offset_in_pixels) | 
|---|
| 3449 | dx = -x_offset_in_pixels; | 
|---|
| 3450 | if (dx > es->text_width - x_offset_in_pixels) | 
|---|
| 3451 | dx = es->text_width - x_offset_in_pixels; | 
|---|
| 3452 | nyoff = max(0, es->y_offset + dy); | 
|---|
| 3453 | if (nyoff >= es->line_count) | 
|---|
| 3454 | nyoff = es->line_count - 1; | 
|---|
| 3455 | dy = (es->y_offset - nyoff) * es->line_height; | 
|---|
| 3456 | if (dx || dy) { | 
|---|
| 3457 | RECT rc1; | 
|---|
| 3458 | RECT rc; | 
|---|
| 3459 |  | 
|---|
| 3460 | es->y_offset = nyoff; | 
|---|
| 3461 | if(es->style & ES_MULTILINE) | 
|---|
| 3462 | es->x_offset += dx; | 
|---|
| 3463 | else | 
|---|
| 3464 | es->x_offset += dx / es->char_width; | 
|---|
| 3465 |  | 
|---|
| 3466 | GetClientRect(hwnd, &rc1); | 
|---|
| 3467 | IntersectRect(&rc, &rc1, &es->format_rect); | 
|---|
| 3468 | ScrollWindowEx(hwnd, -dx, dy, | 
|---|
| 3469 | #ifdef __WIN32OS2__ | 
|---|
| 3470 | NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE|SW_ERASE); | 
|---|
| 3471 | #else | 
|---|
| 3472 | NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE); | 
|---|
| 3473 | #endif | 
|---|
| 3474 | /* force scroll info update */ | 
|---|
| 3475 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 3476 | } | 
|---|
| 3477 | if (dx && !(es->flags & EF_HSCROLL_TRACK)) | 
|---|
| 3478 | EDIT_NOTIFY_PARENT(hwnd, es, EN_HSCROLL, "EN_HSCROLL"); | 
|---|
| 3479 | if (dy && !(es->flags & EF_VSCROLL_TRACK)) | 
|---|
| 3480 | EDIT_NOTIFY_PARENT(hwnd, es, EN_VSCROLL, "EN_VSCROLL"); | 
|---|
| 3481 | return TRUE; | 
|---|
| 3482 | } | 
|---|
| 3483 |  | 
|---|
| 3484 |  | 
|---|
| 3485 | /********************************************************************* | 
|---|
| 3486 | * | 
|---|
| 3487 | *  EM_POSFROMCHAR | 
|---|
| 3488 | * | 
|---|
| 3489 | */ | 
|---|
| 3490 | static LRESULT EDIT_EM_PosFromChar(HWND hwnd, EDITSTATE *es, INT index, BOOL after_wrap) | 
|---|
| 3491 | { | 
|---|
| 3492 | INT len = strlenW(es->text); | 
|---|
| 3493 | INT l; | 
|---|
| 3494 | INT li; | 
|---|
| 3495 | INT x; | 
|---|
| 3496 | INT y = 0; | 
|---|
| 3497 | HDC dc; | 
|---|
| 3498 | HFONT old_font = 0; | 
|---|
| 3499 | SIZE size; | 
|---|
| 3500 |  | 
|---|
| 3501 | index = min(index, len); | 
|---|
| 3502 | dc = GetDC(hwnd); | 
|---|
| 3503 | if (es->font) | 
|---|
| 3504 | old_font = SelectObject(dc, es->font); | 
|---|
| 3505 | if (es->style & ES_MULTILINE) { | 
|---|
| 3506 | l = EDIT_EM_LineFromChar(es, index); | 
|---|
| 3507 | y = (l - es->y_offset) * es->line_height; | 
|---|
| 3508 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 3509 | if (after_wrap && (li == index) && l) { | 
|---|
| 3510 | INT l2 = l - 1; | 
|---|
| 3511 | LINEDEF *line_def = es->first_line_def; | 
|---|
| 3512 | while (l2) { | 
|---|
| 3513 | line_def = line_def->next; | 
|---|
| 3514 | l2--; | 
|---|
| 3515 | } | 
|---|
| 3516 | if (line_def->ending == END_WRAP) { | 
|---|
| 3517 | l--; | 
|---|
| 3518 | y -= es->line_height; | 
|---|
| 3519 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 3520 | } | 
|---|
| 3521 | } | 
|---|
| 3522 | x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li, | 
|---|
| 3523 | es->tabs_count, es->tabs)) - es->x_offset; | 
|---|
| 3524 | } else { | 
|---|
| 3525 | LPWSTR text = EDIT_GetPasswordPointer_SL(es); | 
|---|
| 3526 | if (index < es->x_offset) { | 
|---|
| 3527 | GetTextExtentPoint32W(dc, text + index, | 
|---|
| 3528 | es->x_offset - index, &size); | 
|---|
| 3529 | x = -size.cx; | 
|---|
| 3530 | } else { | 
|---|
| 3531 | GetTextExtentPoint32W(dc, text + es->x_offset, | 
|---|
| 3532 | index - es->x_offset, &size); | 
|---|
| 3533 | x = size.cx; | 
|---|
| 3534 | } | 
|---|
| 3535 | y = 0; | 
|---|
| 3536 | if (es->style & ES_PASSWORD) | 
|---|
| 3537 | HeapFree(GetProcessHeap(), 0, text); | 
|---|
| 3538 | } | 
|---|
| 3539 | x += es->format_rect.left; | 
|---|
| 3540 | y += es->format_rect.top; | 
|---|
| 3541 | if (es->font) | 
|---|
| 3542 | SelectObject(dc, old_font); | 
|---|
| 3543 | ReleaseDC(hwnd, dc); | 
|---|
| 3544 | return MAKELONG((INT16)x, (INT16)y); | 
|---|
| 3545 | } | 
|---|
| 3546 |  | 
|---|
| 3547 |  | 
|---|
| 3548 | /********************************************************************* | 
|---|
| 3549 | * | 
|---|
| 3550 | *  EM_REPLACESEL | 
|---|
| 3551 | * | 
|---|
| 3552 | *  FIXME: handle ES_NUMBER and ES_OEMCONVERT here | 
|---|
| 3553 | * | 
|---|
| 3554 | */ | 
|---|
| 3555 | static void EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update) | 
|---|
| 3556 | { | 
|---|
| 3557 | UINT strl = strlenW(lpsz_replace); | 
|---|
| 3558 | UINT tl = strlenW(es->text); | 
|---|
| 3559 | UINT utl; | 
|---|
| 3560 | UINT s; | 
|---|
| 3561 | UINT e; | 
|---|
| 3562 | UINT i; | 
|---|
| 3563 | LPWSTR p; | 
|---|
| 3564 | HRGN hrgn = 0; | 
|---|
| 3565 |  | 
|---|
| 3566 | TRACE("%s, can_undo %d, send_update %d\n", | 
|---|
| 3567 | debugstr_w(lpsz_replace), can_undo, send_update); | 
|---|
| 3568 |  | 
|---|
| 3569 | s = es->selection_start; | 
|---|
| 3570 | e = es->selection_end; | 
|---|
| 3571 |  | 
|---|
| 3572 | if ((s == e) && !strl) | 
|---|
| 3573 | return; | 
|---|
| 3574 |  | 
|---|
| 3575 | ORDER_UINT(s, e); | 
|---|
| 3576 |  | 
|---|
| 3577 | if (!EDIT_MakeFit(hwnd, es, tl - (e - s) + strl)) | 
|---|
| 3578 | return; | 
|---|
| 3579 |  | 
|---|
| 3580 | if (e != s) { | 
|---|
| 3581 | /* there is something to be deleted */ | 
|---|
| 3582 | TRACE("deleting stuff.\n"); | 
|---|
| 3583 | if (can_undo) { | 
|---|
| 3584 | utl = strlenW(es->undo_text); | 
|---|
| 3585 | if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) { | 
|---|
| 3586 | /* undo-buffer is extended to the right */ | 
|---|
| 3587 | EDIT_MakeUndoFit(es, utl + e - s); | 
|---|
| 3588 | strncpyW(es->undo_text + utl, es->text + s, e - s + 1); | 
|---|
| 3589 | (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */ | 
|---|
| 3590 | } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) { | 
|---|
| 3591 | /* undo-buffer is extended to the left */ | 
|---|
| 3592 | EDIT_MakeUndoFit(es, utl + e - s); | 
|---|
| 3593 | for (p = es->undo_text + utl ; p >= es->undo_text ; p--) | 
|---|
| 3594 | p[e - s] = p[0]; | 
|---|
| 3595 | for (i = 0 , p = es->undo_text ; i < e - s ; i++) | 
|---|
| 3596 | p[i] = (es->text + s)[i]; | 
|---|
| 3597 | es->undo_position = s; | 
|---|
| 3598 | } else { | 
|---|
| 3599 | /* new undo-buffer */ | 
|---|
| 3600 | EDIT_MakeUndoFit(es, e - s); | 
|---|
| 3601 | strncpyW(es->undo_text, es->text + s, e - s + 1); | 
|---|
| 3602 | es->undo_text[e - s] = 0; /* ensure 0 termination */ | 
|---|
| 3603 | es->undo_position = s; | 
|---|
| 3604 | } | 
|---|
| 3605 | /* any deletion makes the old insertion-undo invalid */ | 
|---|
| 3606 | es->undo_insert_count = 0; | 
|---|
| 3607 | } else | 
|---|
| 3608 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 3609 |  | 
|---|
| 3610 | /* now delete */ | 
|---|
| 3611 | strcpyW(es->text + s, es->text + e); | 
|---|
| 3612 | } | 
|---|
| 3613 | if (strl) { | 
|---|
| 3614 | /* there is an insertion */ | 
|---|
| 3615 | if (can_undo) { | 
|---|
| 3616 | if ((s == es->undo_position) || | 
|---|
| 3617 | ((es->undo_insert_count) && | 
|---|
| 3618 | (s == es->undo_position + es->undo_insert_count))) | 
|---|
| 3619 | /* | 
|---|
| 3620 | * insertion is new and at delete position or | 
|---|
| 3621 | * an extension to either left or right | 
|---|
| 3622 | */ | 
|---|
| 3623 | es->undo_insert_count += strl; | 
|---|
| 3624 | else { | 
|---|
| 3625 | /* new insertion undo */ | 
|---|
| 3626 | es->undo_position = s; | 
|---|
| 3627 | es->undo_insert_count = strl; | 
|---|
| 3628 | /* new insertion makes old delete-buffer invalid */ | 
|---|
| 3629 | *es->undo_text = '\0'; | 
|---|
| 3630 | } | 
|---|
| 3631 | } else | 
|---|
| 3632 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 3633 |  | 
|---|
| 3634 | /* now insert */ | 
|---|
| 3635 | tl = strlenW(es->text); | 
|---|
| 3636 | TRACE("inserting stuff (tl %d, strl %d, selstart %d ('%s'), text '%s')\n", tl, strl, s, debugstr_w(es->text + s), debugstr_w(es->text)); | 
|---|
| 3637 | for (p = es->text + tl ; p >= es->text + s ; p--) | 
|---|
| 3638 | p[strl] = p[0]; | 
|---|
| 3639 | for (i = 0 , p = es->text + s ; i < strl ; i++) | 
|---|
| 3640 | p[i] = lpsz_replace[i]; | 
|---|
| 3641 | if(es->style & ES_UPPERCASE) | 
|---|
| 3642 | CharUpperBuffW(p, strl); | 
|---|
| 3643 | else if(es->style & ES_LOWERCASE) | 
|---|
| 3644 | CharLowerBuffW(p, strl); | 
|---|
| 3645 | s += strl; | 
|---|
| 3646 | } | 
|---|
| 3647 | if (es->style & ES_MULTILINE) | 
|---|
| 3648 | { | 
|---|
| 3649 | INT s = min(es->selection_start, es->selection_end); | 
|---|
| 3650 |  | 
|---|
| 3651 | hrgn = CreateRectRgn(0, 0, 0, 0); | 
|---|
| 3652 | EDIT_BuildLineDefs_ML(hwnd, es, s, s + strl, | 
|---|
| 3653 | strl - abs(es->selection_end - es->selection_start), hrgn); | 
|---|
| 3654 | } | 
|---|
| 3655 | else | 
|---|
| 3656 | EDIT_CalcLineWidth_SL(hwnd, es); | 
|---|
| 3657 |  | 
|---|
| 3658 | EDIT_EM_SetSel(hwnd, es, s, s, FALSE); | 
|---|
| 3659 | es->flags |= EF_MODIFIED; | 
|---|
| 3660 | if (send_update) es->flags |= EF_UPDATE; | 
|---|
| 3661 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3662 |  | 
|---|
| 3663 | /* force scroll info update */ | 
|---|
| 3664 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 3665 |  | 
|---|
| 3666 | if (hrgn) | 
|---|
| 3667 | { | 
|---|
| 3668 | EDIT_UpdateTextRegion(hwnd, es, hrgn, TRUE); | 
|---|
| 3669 | DeleteObject(hrgn); | 
|---|
| 3670 | } | 
|---|
| 3671 | else | 
|---|
| 3672 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 3673 |  | 
|---|
| 3674 | if(es->flags & EF_UPDATE) | 
|---|
| 3675 | { | 
|---|
| 3676 | es->flags &= ~EF_UPDATE; | 
|---|
| 3677 | EDIT_NOTIFY_PARENT(hwnd, es, EN_CHANGE, "EN_CHANGE"); | 
|---|
| 3678 | } | 
|---|
| 3679 | } | 
|---|
| 3680 |  | 
|---|
| 3681 |  | 
|---|
| 3682 | /********************************************************************* | 
|---|
| 3683 | * | 
|---|
| 3684 | *  EM_SCROLL | 
|---|
| 3685 | * | 
|---|
| 3686 | */ | 
|---|
| 3687 | static LRESULT EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action) | 
|---|
| 3688 | { | 
|---|
| 3689 | INT dy; | 
|---|
| 3690 |  | 
|---|
| 3691 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3692 | return (LRESULT)FALSE; | 
|---|
| 3693 |  | 
|---|
| 3694 | dy = 0; | 
|---|
| 3695 |  | 
|---|
| 3696 | switch (action) { | 
|---|
| 3697 | case SB_LINEUP: | 
|---|
| 3698 | if (es->y_offset) | 
|---|
| 3699 | dy = -1; | 
|---|
| 3700 | break; | 
|---|
| 3701 | case SB_LINEDOWN: | 
|---|
| 3702 | if (es->y_offset < es->line_count - 1) | 
|---|
| 3703 | dy = 1; | 
|---|
| 3704 | break; | 
|---|
| 3705 | case SB_PAGEUP: | 
|---|
| 3706 | if (es->y_offset) | 
|---|
| 3707 | dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 3708 | break; | 
|---|
| 3709 | case SB_PAGEDOWN: | 
|---|
| 3710 | if (es->y_offset < es->line_count - 1) | 
|---|
| 3711 | dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 3712 | break; | 
|---|
| 3713 | default: | 
|---|
| 3714 | return (LRESULT)FALSE; | 
|---|
| 3715 | } | 
|---|
| 3716 | if (dy) { | 
|---|
| 3717 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 3718 | /* check if we are going to move too far */ | 
|---|
| 3719 | if(es->y_offset + dy > es->line_count - vlc) | 
|---|
| 3720 | dy = es->line_count - vlc - es->y_offset; | 
|---|
| 3721 |  | 
|---|
| 3722 | /* Notification is done in EDIT_EM_LineScroll */ | 
|---|
| 3723 | if(dy) | 
|---|
| 3724 | EDIT_EM_LineScroll(hwnd, es, 0, dy); | 
|---|
| 3725 | } | 
|---|
| 3726 | return MAKELONG((INT16)dy, (BOOL16)TRUE); | 
|---|
| 3727 | } | 
|---|
| 3728 |  | 
|---|
| 3729 |  | 
|---|
| 3730 | /********************************************************************* | 
|---|
| 3731 | * | 
|---|
| 3732 | *  EM_SCROLLCARET | 
|---|
| 3733 | * | 
|---|
| 3734 | */ | 
|---|
| 3735 | static void EDIT_EM_ScrollCaret(HWND hwnd, EDITSTATE *es) | 
|---|
| 3736 | { | 
|---|
| 3737 | if (es->style & ES_MULTILINE) { | 
|---|
| 3738 | INT l; | 
|---|
| 3739 | INT li; | 
|---|
| 3740 | INT vlc; | 
|---|
| 3741 | INT ww; | 
|---|
| 3742 | INT cw = es->char_width; | 
|---|
| 3743 | INT x; | 
|---|
| 3744 | INT dy = 0; | 
|---|
| 3745 | INT dx = 0; | 
|---|
| 3746 |  | 
|---|
| 3747 | l = EDIT_EM_LineFromChar(es, es->selection_end); | 
|---|
| 3748 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 3749 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)); | 
|---|
| 3750 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 3751 | if (l >= es->y_offset + vlc) | 
|---|
| 3752 | dy = l - vlc + 1 - es->y_offset; | 
|---|
| 3753 | if (l < es->y_offset) | 
|---|
| 3754 | dy = l - es->y_offset; | 
|---|
| 3755 | ww = es->format_rect.right - es->format_rect.left; | 
|---|
| 3756 | if (x < es->format_rect.left) | 
|---|
| 3757 | dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw; | 
|---|
| 3758 | if (x > es->format_rect.right) | 
|---|
| 3759 | dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw; | 
|---|
| 3760 | if (dy || dx) | 
|---|
| 3761 | { | 
|---|
| 3762 | /* check if we are going to move too far */ | 
|---|
| 3763 | if(es->x_offset + dx + ww > es->text_width) | 
|---|
| 3764 | dx = es->text_width - ww - es->x_offset; | 
|---|
| 3765 | if(dx || dy) | 
|---|
| 3766 | EDIT_EM_LineScroll_internal(hwnd, es, dx, dy); | 
|---|
| 3767 | } | 
|---|
| 3768 | } else { | 
|---|
| 3769 | INT x; | 
|---|
| 3770 | INT goal; | 
|---|
| 3771 | INT format_width; | 
|---|
| 3772 |  | 
|---|
| 3773 | if (!(es->style & ES_AUTOHSCROLL)) | 
|---|
| 3774 | return; | 
|---|
| 3775 |  | 
|---|
| 3776 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE)); | 
|---|
| 3777 | format_width = es->format_rect.right - es->format_rect.left; | 
|---|
| 3778 | if (x < es->format_rect.left) { | 
|---|
| 3779 | goal = es->format_rect.left + format_width / HSCROLL_FRACTION; | 
|---|
| 3780 | do { | 
|---|
| 3781 | es->x_offset--; | 
|---|
| 3782 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE)); | 
|---|
| 3783 | } while ((x < goal) && es->x_offset); | 
|---|
| 3784 | /* FIXME: use ScrollWindow() somehow to improve performance */ | 
|---|
| 3785 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 3786 | } else if (x > es->format_rect.right) { | 
|---|
| 3787 | INT x_last; | 
|---|
| 3788 | INT len = strlenW(es->text); | 
|---|
| 3789 | goal = es->format_rect.right - format_width / HSCROLL_FRACTION; | 
|---|
| 3790 | do { | 
|---|
| 3791 | es->x_offset++; | 
|---|
| 3792 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE)); | 
|---|
| 3793 | x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, len, FALSE)); | 
|---|
| 3794 | } while ((x > goal) && (x_last > es->format_rect.right)); | 
|---|
| 3795 | /* FIXME: use ScrollWindow() somehow to improve performance */ | 
|---|
| 3796 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 3797 | } | 
|---|
| 3798 | } | 
|---|
| 3799 |  | 
|---|
| 3800 | if(es->flags & EF_FOCUSED) | 
|---|
| 3801 | EDIT_SetCaretPos(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); | 
|---|
| 3802 | } | 
|---|
| 3803 |  | 
|---|
| 3804 |  | 
|---|
| 3805 | /********************************************************************* | 
|---|
| 3806 | * | 
|---|
| 3807 | *  EM_SETHANDLE | 
|---|
| 3808 | * | 
|---|
| 3809 | *  FIXME:  ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? | 
|---|
| 3810 | * | 
|---|
| 3811 | */ | 
|---|
| 3812 | static void EDIT_EM_SetHandle(HWND hwnd, EDITSTATE *es, HLOCAL hloc) | 
|---|
| 3813 | { | 
|---|
| 3814 | HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE ); | 
|---|
| 3815 |  | 
|---|
| 3816 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3817 | return; | 
|---|
| 3818 |  | 
|---|
| 3819 | if (!hloc) { | 
|---|
| 3820 | WARN("called with NULL handle\n"); | 
|---|
| 3821 | return; | 
|---|
| 3822 | } | 
|---|
| 3823 |  | 
|---|
| 3824 | EDIT_UnlockBuffer(hwnd, es, TRUE); | 
|---|
| 3825 |  | 
|---|
| 3826 | #ifndef __WIN32OS2__ | 
|---|
| 3827 | if(es->hloc16) | 
|---|
| 3828 | { | 
|---|
| 3829 | LOCAL_Free(hInstance, es->hloc16); | 
|---|
| 3830 | es->hloc16 = (HLOCAL16)NULL; | 
|---|
| 3831 | } | 
|---|
| 3832 | #endif | 
|---|
| 3833 | if(es->is_unicode) | 
|---|
| 3834 | { | 
|---|
| 3835 | if(es->hloc32A) | 
|---|
| 3836 | { | 
|---|
| 3837 | LocalFree(es->hloc32A); | 
|---|
| 3838 | es->hloc32A = (HLOCAL)NULL; | 
|---|
| 3839 | } | 
|---|
| 3840 | es->hloc32W = hloc; | 
|---|
| 3841 | } | 
|---|
| 3842 | else | 
|---|
| 3843 | { | 
|---|
| 3844 | INT countW, countA; | 
|---|
| 3845 | HLOCAL hloc32W_new; | 
|---|
| 3846 | WCHAR *textW; | 
|---|
| 3847 | CHAR *textA; | 
|---|
| 3848 |  | 
|---|
| 3849 | countA = LocalSize(hloc); | 
|---|
| 3850 | textA = LocalLock(hloc); | 
|---|
| 3851 | countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0); | 
|---|
| 3852 | if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR)))) | 
|---|
| 3853 | { | 
|---|
| 3854 | ERR("Could not allocate new unicode buffer\n"); | 
|---|
| 3855 | return; | 
|---|
| 3856 | } | 
|---|
| 3857 | textW = LocalLock(hloc32W_new); | 
|---|
| 3858 | MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW); | 
|---|
| 3859 | LocalUnlock(hloc32W_new); | 
|---|
| 3860 | LocalUnlock(hloc); | 
|---|
| 3861 |  | 
|---|
| 3862 | if(es->hloc32W) | 
|---|
| 3863 | LocalFree(es->hloc32W); | 
|---|
| 3864 |  | 
|---|
| 3865 | es->hloc32W = hloc32W_new; | 
|---|
| 3866 | es->hloc32A = hloc; | 
|---|
| 3867 | } | 
|---|
| 3868 |  | 
|---|
| 3869 | es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1; | 
|---|
| 3870 |  | 
|---|
| 3871 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 3872 |  | 
|---|
| 3873 | es->x_offset = es->y_offset = 0; | 
|---|
| 3874 | es->selection_start = es->selection_end = 0; | 
|---|
| 3875 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 3876 | es->flags &= ~EF_MODIFIED; | 
|---|
| 3877 | es->flags &= ~EF_UPDATE; | 
|---|
| 3878 | EDIT_BuildLineDefs_ML(hwnd, es, 0, strlenW(es->text), 0, (HRGN)0); | 
|---|
| 3879 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 3880 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3881 | /* force scroll info update */ | 
|---|
| 3882 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 3883 | } | 
|---|
| 3884 |  | 
|---|
| 3885 |  | 
|---|
| 3886 | #ifndef __WIN32OS2__ | 
|---|
| 3887 | /********************************************************************* | 
|---|
| 3888 | * | 
|---|
| 3889 | *  EM_SETHANDLE16 | 
|---|
| 3890 | * | 
|---|
| 3891 | *  FIXME:  ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? | 
|---|
| 3892 | * | 
|---|
| 3893 | */ | 
|---|
| 3894 | static void EDIT_EM_SetHandle16(HWND hwnd, EDITSTATE *es, HLOCAL16 hloc) | 
|---|
| 3895 | { | 
|---|
| 3896 | HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE ); | 
|---|
| 3897 | INT countW, countA; | 
|---|
| 3898 | HLOCAL hloc32W_new; | 
|---|
| 3899 | WCHAR *textW; | 
|---|
| 3900 | CHAR *textA; | 
|---|
| 3901 |  | 
|---|
| 3902 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 3903 | return; | 
|---|
| 3904 |  | 
|---|
| 3905 | if (!hloc) { | 
|---|
| 3906 | WARN("called with NULL handle\n"); | 
|---|
| 3907 | return; | 
|---|
| 3908 | } | 
|---|
| 3909 |  | 
|---|
| 3910 | EDIT_UnlockBuffer(hwnd, es, TRUE); | 
|---|
| 3911 |  | 
|---|
| 3912 | if(es->hloc32A) | 
|---|
| 3913 | { | 
|---|
| 3914 | LocalFree(es->hloc32A); | 
|---|
| 3915 | es->hloc32A = (HLOCAL)NULL; | 
|---|
| 3916 | } | 
|---|
| 3917 |  | 
|---|
| 3918 | countA = LOCAL_Size(hInstance, hloc); | 
|---|
| 3919 | textA = LOCAL_Lock(hInstance, hloc); | 
|---|
| 3920 | countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0); | 
|---|
| 3921 | if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR)))) | 
|---|
| 3922 | { | 
|---|
| 3923 | ERR("Could not allocate new unicode buffer\n"); | 
|---|
| 3924 | return; | 
|---|
| 3925 | } | 
|---|
| 3926 | textW = LocalLock(hloc32W_new); | 
|---|
| 3927 | MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW); | 
|---|
| 3928 | LocalUnlock(hloc32W_new); | 
|---|
| 3929 | LOCAL_Unlock(hInstance, hloc); | 
|---|
| 3930 |  | 
|---|
| 3931 | if(es->hloc32W) | 
|---|
| 3932 | LocalFree(es->hloc32W); | 
|---|
| 3933 |  | 
|---|
| 3934 | es->hloc32W = hloc32W_new; | 
|---|
| 3935 | es->hloc16 = hloc; | 
|---|
| 3936 |  | 
|---|
| 3937 | es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1; | 
|---|
| 3938 |  | 
|---|
| 3939 | EDIT_LockBuffer(hwnd, es); | 
|---|
| 3940 |  | 
|---|
| 3941 | es->x_offset = es->y_offset = 0; | 
|---|
| 3942 | es->selection_start = es->selection_end = 0; | 
|---|
| 3943 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 3944 | es->flags &= ~EF_MODIFIED; | 
|---|
| 3945 | es->flags &= ~EF_UPDATE; | 
|---|
| 3946 | EDIT_BuildLineDefs_ML(hwnd, es, 0, strlenW(es->text), 0, (HRGN)0); | 
|---|
| 3947 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 3948 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 3949 | /* force scroll info update */ | 
|---|
| 3950 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 3951 | } | 
|---|
| 3952 | #endif | 
|---|
| 3953 |  | 
|---|
| 3954 | /********************************************************************* | 
|---|
| 3955 | * | 
|---|
| 3956 | *  EM_SETLIMITTEXT | 
|---|
| 3957 | * | 
|---|
| 3958 | *  FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF | 
|---|
| 3959 | *  However, the windows version is not complied to yet in all of edit.c | 
|---|
| 3960 | * | 
|---|
| 3961 | */ | 
|---|
| 3962 | static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit) | 
|---|
| 3963 | { | 
|---|
| 3964 | if (es->style & ES_MULTILINE) { | 
|---|
| 3965 | if (limit) | 
|---|
| 3966 | es->buffer_limit = min(limit, BUFLIMIT_MULTI); | 
|---|
| 3967 | else | 
|---|
| 3968 | es->buffer_limit = BUFLIMIT_MULTI; | 
|---|
| 3969 | } else { | 
|---|
| 3970 | if (limit) | 
|---|
| 3971 | es->buffer_limit = min(limit, BUFLIMIT_SINGLE); | 
|---|
| 3972 | else | 
|---|
| 3973 | es->buffer_limit = BUFLIMIT_SINGLE; | 
|---|
| 3974 | } | 
|---|
| 3975 | } | 
|---|
| 3976 |  | 
|---|
| 3977 |  | 
|---|
| 3978 | /********************************************************************* | 
|---|
| 3979 | * | 
|---|
| 3980 | *  EM_SETMARGINS | 
|---|
| 3981 | * | 
|---|
| 3982 | * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an | 
|---|
| 3983 | * action wParam despite what the docs say. EC_USEFONTINFO means one third | 
|---|
| 3984 | * of the char's width, according to the new docs. | 
|---|
| 3985 | * | 
|---|
| 3986 | */ | 
|---|
| 3987 | static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, | 
|---|
| 3988 | INT left, INT right) | 
|---|
| 3989 | { | 
|---|
| 3990 | if (action & EC_LEFTMARGIN) { | 
|---|
| 3991 | if (left != EC_USEFONTINFO) | 
|---|
| 3992 | es->left_margin = left; | 
|---|
| 3993 | else | 
|---|
| 3994 | es->left_margin = es->char_width / 3; | 
|---|
| 3995 | } | 
|---|
| 3996 |  | 
|---|
| 3997 | if (action & EC_RIGHTMARGIN) { | 
|---|
| 3998 | if (right != EC_USEFONTINFO) | 
|---|
| 3999 | es->right_margin = right; | 
|---|
| 4000 | else | 
|---|
| 4001 | es->right_margin = es->char_width / 3; | 
|---|
| 4002 | } | 
|---|
| 4003 | TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin); | 
|---|
| 4004 | } | 
|---|
| 4005 |  | 
|---|
| 4006 |  | 
|---|
| 4007 | /********************************************************************* | 
|---|
| 4008 | * | 
|---|
| 4009 | *  EM_SETPASSWORDCHAR | 
|---|
| 4010 | * | 
|---|
| 4011 | */ | 
|---|
| 4012 | static void EDIT_EM_SetPasswordChar(HWND hwnd, EDITSTATE *es, WCHAR c) | 
|---|
| 4013 | { | 
|---|
| 4014 | LONG style; | 
|---|
| 4015 |  | 
|---|
| 4016 | if (es->style & ES_MULTILINE) | 
|---|
| 4017 | return; | 
|---|
| 4018 |  | 
|---|
| 4019 | if (es->password_char == c) | 
|---|
| 4020 | return; | 
|---|
| 4021 |  | 
|---|
| 4022 | style = GetWindowLongA( hwnd, GWL_STYLE ); | 
|---|
| 4023 | es->password_char = c; | 
|---|
| 4024 | if (c) { | 
|---|
| 4025 | SetWindowLongA( hwnd, GWL_STYLE, style | ES_PASSWORD ); | 
|---|
| 4026 | es->style |= ES_PASSWORD; | 
|---|
| 4027 | } else { | 
|---|
| 4028 | SetWindowLongA( hwnd, GWL_STYLE, style & ~ES_PASSWORD ); | 
|---|
| 4029 | es->style &= ~ES_PASSWORD; | 
|---|
| 4030 | } | 
|---|
| 4031 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 4032 | } | 
|---|
| 4033 |  | 
|---|
| 4034 |  | 
|---|
| 4035 | /********************************************************************* | 
|---|
| 4036 | * | 
|---|
| 4037 | *  EDIT_EM_SetSel | 
|---|
| 4038 | * | 
|---|
| 4039 | *  note:   unlike the specs say: the order of start and end | 
|---|
| 4040 | *      _is_ preserved in Windows.  (i.e. start can be > end) | 
|---|
| 4041 | *      In other words: this handler is OK | 
|---|
| 4042 | * | 
|---|
| 4043 | */ | 
|---|
| 4044 | static void EDIT_EM_SetSel(HWND hwnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap) | 
|---|
| 4045 | { | 
|---|
| 4046 | UINT old_start = es->selection_start; | 
|---|
| 4047 | UINT old_end = es->selection_end; | 
|---|
| 4048 | UINT len = strlenW(es->text); | 
|---|
| 4049 |  | 
|---|
| 4050 | if (start == (UINT)-1) { | 
|---|
| 4051 | start = es->selection_end; | 
|---|
| 4052 | end = es->selection_end; | 
|---|
| 4053 | } else { | 
|---|
| 4054 | start = min(start, len); | 
|---|
| 4055 | end = min(end, len); | 
|---|
| 4056 | } | 
|---|
| 4057 | es->selection_start = start; | 
|---|
| 4058 | es->selection_end = end; | 
|---|
| 4059 | if (after_wrap) | 
|---|
| 4060 | es->flags |= EF_AFTER_WRAP; | 
|---|
| 4061 | else | 
|---|
| 4062 | es->flags &= ~EF_AFTER_WRAP; | 
|---|
| 4063 | /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */ | 
|---|
| 4064 | ORDER_UINT(start, end); | 
|---|
| 4065 | ORDER_UINT(end, old_end); | 
|---|
| 4066 | ORDER_UINT(start, old_start); | 
|---|
| 4067 | ORDER_UINT(old_start, old_end); | 
|---|
| 4068 | if (end != old_start) | 
|---|
| 4069 | { | 
|---|
| 4070 | /* | 
|---|
| 4071 | * One can also do | 
|---|
| 4072 | *          ORDER_UINT32(end, old_start); | 
|---|
| 4073 | *          EDIT_InvalidateText(hwnd, es, start, end); | 
|---|
| 4074 | *          EDIT_InvalidateText(hwnd, es, old_start, old_end); | 
|---|
| 4075 | * in place of the following if statement. | 
|---|
| 4076 | */ | 
|---|
| 4077 | if (old_start > end ) | 
|---|
| 4078 | { | 
|---|
| 4079 | EDIT_InvalidateText(hwnd, es, start, end); | 
|---|
| 4080 | EDIT_InvalidateText(hwnd, es, old_start, old_end); | 
|---|
| 4081 | } | 
|---|
| 4082 | else | 
|---|
| 4083 | { | 
|---|
| 4084 | EDIT_InvalidateText(hwnd, es, start, old_start); | 
|---|
| 4085 | EDIT_InvalidateText(hwnd, es, end, old_end); | 
|---|
| 4086 | } | 
|---|
| 4087 | } | 
|---|
| 4088 | else EDIT_InvalidateText(hwnd, es, start, old_end); | 
|---|
| 4089 | } | 
|---|
| 4090 |  | 
|---|
| 4091 |  | 
|---|
| 4092 | /********************************************************************* | 
|---|
| 4093 | * | 
|---|
| 4094 | *  EM_SETTABSTOPS | 
|---|
| 4095 | * | 
|---|
| 4096 | */ | 
|---|
| 4097 | static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs) | 
|---|
| 4098 | { | 
|---|
| 4099 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 4100 | return FALSE; | 
|---|
| 4101 | if (es->tabs) | 
|---|
| 4102 | HeapFree(GetProcessHeap(), 0, es->tabs); | 
|---|
| 4103 | es->tabs_count = count; | 
|---|
| 4104 | if (!count) | 
|---|
| 4105 | es->tabs = NULL; | 
|---|
| 4106 | else { | 
|---|
| 4107 | es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT)); | 
|---|
| 4108 | memcpy(es->tabs, tabs, count * sizeof(INT)); | 
|---|
| 4109 | } | 
|---|
| 4110 | return TRUE; | 
|---|
| 4111 | } | 
|---|
| 4112 |  | 
|---|
| 4113 |  | 
|---|
| 4114 | /********************************************************************* | 
|---|
| 4115 | * | 
|---|
| 4116 | *  EM_SETTABSTOPS16 | 
|---|
| 4117 | * | 
|---|
| 4118 | */ | 
|---|
| 4119 | static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs) | 
|---|
| 4120 | { | 
|---|
| 4121 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 4122 | return FALSE; | 
|---|
| 4123 | if (es->tabs) | 
|---|
| 4124 | HeapFree(GetProcessHeap(), 0, es->tabs); | 
|---|
| 4125 | es->tabs_count = count; | 
|---|
| 4126 | if (!count) | 
|---|
| 4127 | es->tabs = NULL; | 
|---|
| 4128 | else { | 
|---|
| 4129 | INT i; | 
|---|
| 4130 | es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT)); | 
|---|
| 4131 | for (i = 0 ; i < count ; i++) | 
|---|
| 4132 | es->tabs[i] = *tabs++; | 
|---|
| 4133 | } | 
|---|
| 4134 | return TRUE; | 
|---|
| 4135 | } | 
|---|
| 4136 |  | 
|---|
| 4137 |  | 
|---|
| 4138 | /********************************************************************* | 
|---|
| 4139 | * | 
|---|
| 4140 | *  EM_SETWORDBREAKPROC | 
|---|
| 4141 | * | 
|---|
| 4142 | */ | 
|---|
| 4143 | static void EDIT_EM_SetWordBreakProc(HWND hwnd, EDITSTATE *es, LPARAM lParam) | 
|---|
| 4144 | { | 
|---|
| 4145 | if (es->word_break_proc == (void *)lParam) | 
|---|
| 4146 | return; | 
|---|
| 4147 |  | 
|---|
| 4148 | es->word_break_proc = (void *)lParam; | 
|---|
| 4149 | es->word_break_proc16 = NULL; | 
|---|
| 4150 |  | 
|---|
| 4151 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { | 
|---|
| 4152 | EDIT_BuildLineDefs_ML(hwnd, es, 0, strlenW(es->text), 0, (HRGN)0); | 
|---|
| 4153 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 4154 | } | 
|---|
| 4155 | } | 
|---|
| 4156 |  | 
|---|
| 4157 |  | 
|---|
| 4158 | #ifndef __WIN32OS2__ | 
|---|
| 4159 | /********************************************************************* | 
|---|
| 4160 | * | 
|---|
| 4161 | *  EM_SETWORDBREAKPROC16 | 
|---|
| 4162 | * | 
|---|
| 4163 | */ | 
|---|
| 4164 | static void EDIT_EM_SetWordBreakProc16(HWND hwnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp) | 
|---|
| 4165 | { | 
|---|
| 4166 | if (es->word_break_proc16 == wbp) | 
|---|
| 4167 | return; | 
|---|
| 4168 |  | 
|---|
| 4169 | es->word_break_proc = NULL; | 
|---|
| 4170 | es->word_break_proc16 = wbp; | 
|---|
| 4171 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { | 
|---|
| 4172 | EDIT_BuildLineDefs_ML(hwnd, es, 0, strlenW(es->text), 0, (HRGN)0); | 
|---|
| 4173 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 4174 | } | 
|---|
| 4175 | } | 
|---|
| 4176 | #endif | 
|---|
| 4177 |  | 
|---|
| 4178 | /********************************************************************* | 
|---|
| 4179 | * | 
|---|
| 4180 | *  EM_UNDO / WM_UNDO | 
|---|
| 4181 | * | 
|---|
| 4182 | */ | 
|---|
| 4183 | static BOOL EDIT_EM_Undo(HWND hwnd, EDITSTATE *es) | 
|---|
| 4184 | { | 
|---|
| 4185 | INT ulength; | 
|---|
| 4186 | LPWSTR utext; | 
|---|
| 4187 |  | 
|---|
| 4188 | /* Protect read-only edit control from modification */ | 
|---|
| 4189 | if(es->style & ES_READONLY) | 
|---|
| 4190 | return FALSE; | 
|---|
| 4191 |  | 
|---|
| 4192 | ulength = strlenW(es->undo_text); | 
|---|
| 4193 | utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR)); | 
|---|
| 4194 |  | 
|---|
| 4195 | strcpyW(utext, es->undo_text); | 
|---|
| 4196 |  | 
|---|
| 4197 | TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n", | 
|---|
| 4198 | es->undo_insert_count, debugstr_w(utext)); | 
|---|
| 4199 |  | 
|---|
| 4200 | EDIT_EM_SetSel(hwnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); | 
|---|
| 4201 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 4202 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, utext, FALSE); | 
|---|
| 4203 | EDIT_EM_SetSel(hwnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); | 
|---|
| 4204 | /* send the notification after the selection start and end are set */ | 
|---|
| 4205 | EDIT_NOTIFY_PARENT(hwnd, es, EN_CHANGE, "EN_CHANGE"); | 
|---|
| 4206 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 4207 | HeapFree(GetProcessHeap(), 0, utext); | 
|---|
| 4208 |  | 
|---|
| 4209 | TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n", | 
|---|
| 4210 | es->undo_insert_count, debugstr_w(es->undo_text)); | 
|---|
| 4211 | return TRUE; | 
|---|
| 4212 | } | 
|---|
| 4213 |  | 
|---|
| 4214 |  | 
|---|
| 4215 | /********************************************************************* | 
|---|
| 4216 | * | 
|---|
| 4217 | *  WM_CHAR | 
|---|
| 4218 | * | 
|---|
| 4219 | */ | 
|---|
| 4220 | static void EDIT_WM_Char(HWND hwnd, EDITSTATE *es, WCHAR c) | 
|---|
| 4221 | { | 
|---|
| 4222 | BOOL control; | 
|---|
| 4223 |  | 
|---|
| 4224 | /* Protect read-only edit control from modification */ | 
|---|
| 4225 | if(es->style & ES_READONLY) | 
|---|
| 4226 | return; | 
|---|
| 4227 |  | 
|---|
| 4228 | control = GetKeyState(VK_CONTROL) & 0x8000; | 
|---|
| 4229 |  | 
|---|
| 4230 | switch (c) { | 
|---|
| 4231 | case '\r': | 
|---|
| 4232 | /* If the edit doesn't want the return and it's not a multiline edit, do nothing */ | 
|---|
| 4233 | if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN)) | 
|---|
| 4234 | break; | 
|---|
| 4235 | case '\n': | 
|---|
| 4236 | if (es->style & ES_MULTILINE) { | 
|---|
| 4237 | if (es->style & ES_READONLY) { | 
|---|
| 4238 | EDIT_MoveHome(hwnd, es, FALSE); | 
|---|
| 4239 | EDIT_MoveDown_ML(hwnd, es, FALSE); | 
|---|
| 4240 | } else { | 
|---|
| 4241 | static const WCHAR cr_lfW[] = {'\r','\n',0}; | 
|---|
| 4242 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, cr_lfW, TRUE); | 
|---|
| 4243 | } | 
|---|
| 4244 | } | 
|---|
| 4245 | break; | 
|---|
| 4246 | case '\t': | 
|---|
| 4247 | if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) | 
|---|
| 4248 | { | 
|---|
| 4249 | static const WCHAR tabW[] = {'\t',0}; | 
|---|
| 4250 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, tabW, TRUE); | 
|---|
| 4251 | } | 
|---|
| 4252 | break; | 
|---|
| 4253 | case VK_BACK: | 
|---|
| 4254 | if (!(es->style & ES_READONLY) && !control) { | 
|---|
| 4255 | if (es->selection_start != es->selection_end) | 
|---|
| 4256 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4257 | else { | 
|---|
| 4258 | /* delete character left of caret */ | 
|---|
| 4259 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 4260 | EDIT_MoveBackward(hwnd, es, TRUE); | 
|---|
| 4261 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4262 | } | 
|---|
| 4263 | } | 
|---|
| 4264 | break; | 
|---|
| 4265 | case 0x03: /* ^C */ | 
|---|
| 4266 | SendMessageW(hwnd, WM_COPY, 0, 0); | 
|---|
| 4267 | break; | 
|---|
| 4268 | case 0x16: /* ^V */ | 
|---|
| 4269 | SendMessageW(hwnd, WM_PASTE, 0, 0); | 
|---|
| 4270 | break; | 
|---|
| 4271 | case 0x18: /* ^X */ | 
|---|
| 4272 | SendMessageW(hwnd, WM_CUT, 0, 0); | 
|---|
| 4273 | break; | 
|---|
| 4274 |  | 
|---|
| 4275 | default: | 
|---|
| 4276 | if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) { | 
|---|
| 4277 | WCHAR str[2]; | 
|---|
| 4278 | str[0] = c; | 
|---|
| 4279 | str[1] = '\0'; | 
|---|
| 4280 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, str, TRUE); | 
|---|
| 4281 | } | 
|---|
| 4282 | break; | 
|---|
| 4283 | } | 
|---|
| 4284 | } | 
|---|
| 4285 |  | 
|---|
| 4286 |  | 
|---|
| 4287 | /********************************************************************* | 
|---|
| 4288 | * | 
|---|
| 4289 | *  WM_COMMAND | 
|---|
| 4290 | * | 
|---|
| 4291 | */ | 
|---|
| 4292 | static void EDIT_WM_Command(HWND hwnd, EDITSTATE *es, INT code, INT id, HWND control) | 
|---|
| 4293 | { | 
|---|
| 4294 | if (code || control) | 
|---|
| 4295 | return; | 
|---|
| 4296 |  | 
|---|
| 4297 | switch (id) { | 
|---|
| 4298 | case EM_UNDO: | 
|---|
| 4299 | EDIT_EM_Undo(hwnd, es); | 
|---|
| 4300 | break; | 
|---|
| 4301 | case WM_CUT: | 
|---|
| 4302 | EDIT_WM_Cut(hwnd, es); | 
|---|
| 4303 | break; | 
|---|
| 4304 | case WM_COPY: | 
|---|
| 4305 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 4306 | break; | 
|---|
| 4307 | case WM_PASTE: | 
|---|
| 4308 | EDIT_WM_Paste(hwnd, es); | 
|---|
| 4309 | break; | 
|---|
| 4310 | case WM_CLEAR: | 
|---|
| 4311 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4312 | break; | 
|---|
| 4313 | case EM_SETSEL: | 
|---|
| 4314 | EDIT_EM_SetSel(hwnd, es, 0, (UINT)-1, FALSE); | 
|---|
| 4315 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 4316 | break; | 
|---|
| 4317 | default: | 
|---|
| 4318 | ERR("unknown menu item, please report\n"); | 
|---|
| 4319 | break; | 
|---|
| 4320 | } | 
|---|
| 4321 | } | 
|---|
| 4322 |  | 
|---|
| 4323 |  | 
|---|
| 4324 | /********************************************************************* | 
|---|
| 4325 | * | 
|---|
| 4326 | *  WM_CONTEXTMENU | 
|---|
| 4327 | * | 
|---|
| 4328 | *  Note: the resource files resource/sysres_??.rc cannot define a | 
|---|
| 4329 | *      single popup menu.  Hence we use a (dummy) menubar | 
|---|
| 4330 | *      containing the single popup menu as its first item. | 
|---|
| 4331 | * | 
|---|
| 4332 | *  FIXME: the message identifiers have been chosen arbitrarily, | 
|---|
| 4333 | *      hence we use MF_BYPOSITION. | 
|---|
| 4334 | *      We might as well use the "real" values (anybody knows ?) | 
|---|
| 4335 | *      The menu definition is in resources/sysres_??.rc. | 
|---|
| 4336 | *      Once these are OK, we better use MF_BYCOMMAND here | 
|---|
| 4337 | *      (as we do in EDIT_WM_Command()). | 
|---|
| 4338 | * | 
|---|
| 4339 | */ | 
|---|
| 4340 | static void EDIT_WM_ContextMenu(HWND hwnd, EDITSTATE *es, INT x, INT y) | 
|---|
| 4341 | { | 
|---|
| 4342 | HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU"); | 
|---|
| 4343 | HMENU popup = GetSubMenu(menu, 0); | 
|---|
| 4344 | UINT start = es->selection_start; | 
|---|
| 4345 | UINT end = es->selection_end; | 
|---|
| 4346 |  | 
|---|
| 4347 | ORDER_UINT(start, end); | 
|---|
| 4348 |  | 
|---|
| 4349 | /* undo */ | 
|---|
| 4350 | EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 4351 | /* cut */ | 
|---|
| 4352 | EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 4353 | /* copy */ | 
|---|
| 4354 | EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 4355 | /* paste */ | 
|---|
| 4356 | EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 4357 | /* delete */ | 
|---|
| 4358 | EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 4359 | /* select all */ | 
|---|
| 4360 | EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != strlenW(es->text)) ? MF_ENABLED : MF_GRAYED)); | 
|---|
| 4361 |  | 
|---|
| 4362 | TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, hwnd, NULL); | 
|---|
| 4363 | DestroyMenu(menu); | 
|---|
| 4364 | } | 
|---|
| 4365 |  | 
|---|
| 4366 |  | 
|---|
| 4367 | /********************************************************************* | 
|---|
| 4368 | * | 
|---|
| 4369 | *  WM_COPY | 
|---|
| 4370 | * | 
|---|
| 4371 | */ | 
|---|
| 4372 | static void EDIT_WM_Copy(HWND hwnd, EDITSTATE *es) | 
|---|
| 4373 | { | 
|---|
| 4374 | INT s = es->selection_start; | 
|---|
| 4375 | INT e = es->selection_end; | 
|---|
| 4376 | HGLOBAL hdst; | 
|---|
| 4377 | LPWSTR dst; | 
|---|
| 4378 |  | 
|---|
| 4379 | if (e == s) | 
|---|
| 4380 | return; | 
|---|
| 4381 | ORDER_INT(s, e); | 
|---|
| 4382 | hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR)); | 
|---|
| 4383 | dst = GlobalLock(hdst); | 
|---|
| 4384 | strncpyW(dst, es->text + s, e - s); | 
|---|
| 4385 | dst[e - s ] = 0; /* ensure 0 termination */ | 
|---|
| 4386 | TRACE("%s\n", debugstr_w(dst)); | 
|---|
| 4387 |  | 
|---|
| 4388 | GlobalUnlock(hdst); | 
|---|
| 4389 | OpenClipboard(hwnd); | 
|---|
| 4390 | EmptyClipboard(); | 
|---|
| 4391 | SetClipboardData(CF_UNICODETEXT, hdst); | 
|---|
| 4392 | CloseClipboard(); | 
|---|
| 4393 | } | 
|---|
| 4394 |  | 
|---|
| 4395 |  | 
|---|
| 4396 | /********************************************************************* | 
|---|
| 4397 | * | 
|---|
| 4398 | *  WM_CREATE | 
|---|
| 4399 | * | 
|---|
| 4400 | */ | 
|---|
| 4401 | static LRESULT EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCWSTR name) | 
|---|
| 4402 | { | 
|---|
| 4403 | TRACE("%s\n", debugstr_w(name)); | 
|---|
| 4404 | /* | 
|---|
| 4405 | *   To initialize some final structure members, we call some helper | 
|---|
| 4406 | *   functions.  However, since the EDITSTATE is not consistent (i.e. | 
|---|
| 4407 | *   not fully initialized), we should be very careful which | 
|---|
| 4408 | *   functions can be called, and in what order. | 
|---|
| 4409 | */ | 
|---|
| 4410 | EDIT_WM_SetFont(hwnd, es, 0, FALSE); | 
|---|
| 4411 | EDIT_EM_EmptyUndoBuffer(es); | 
|---|
| 4412 |  | 
|---|
| 4413 | if (name && *name) { | 
|---|
| 4414 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, name, FALSE); | 
|---|
| 4415 | /* if we insert text to the editline, the text scrolls out | 
|---|
| 4416 | * of the window, as the caret is placed after the insert | 
|---|
| 4417 | * pos normally; thus we reset es->selection... to 0 and | 
|---|
| 4418 | * update caret | 
|---|
| 4419 | */ | 
|---|
| 4420 | es->selection_start = es->selection_end = 0; | 
|---|
| 4421 | /* send the notification after the selection start and end are set */ | 
|---|
| 4422 | EDIT_NOTIFY_PARENT(hwnd, es, EN_CHANGE, "EN_CHANGE"); | 
|---|
| 4423 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 4424 | } | 
|---|
| 4425 | /* force scroll info update */ | 
|---|
| 4426 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 4427 | return 0; | 
|---|
| 4428 | } | 
|---|
| 4429 |  | 
|---|
| 4430 |  | 
|---|
| 4431 | /********************************************************************* | 
|---|
| 4432 | * | 
|---|
| 4433 | *  WM_DESTROY | 
|---|
| 4434 | * | 
|---|
| 4435 | */ | 
|---|
| 4436 | static void EDIT_WM_Destroy(HWND hwnd, EDITSTATE *es) | 
|---|
| 4437 | { | 
|---|
| 4438 | HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE ); | 
|---|
| 4439 | LINEDEF *pc, *pp; | 
|---|
| 4440 |  | 
|---|
| 4441 | if (es->hloc32W) { | 
|---|
| 4442 | while (LocalUnlock(es->hloc32W)) ; | 
|---|
| 4443 | LocalFree(es->hloc32W); | 
|---|
| 4444 | } | 
|---|
| 4445 | if (es->hloc32A) { | 
|---|
| 4446 | while (LocalUnlock(es->hloc32A)) ; | 
|---|
| 4447 | LocalFree(es->hloc32A); | 
|---|
| 4448 | } | 
|---|
| 4449 | #ifndef __WIN32OS2__ | 
|---|
| 4450 | if (es->hloc16) { | 
|---|
| 4451 | while (LOCAL_Unlock(hInstance, es->hloc16)) ; | 
|---|
| 4452 | LOCAL_Free(hInstance, es->hloc16); | 
|---|
| 4453 | } | 
|---|
| 4454 | #endif | 
|---|
| 4455 | pc = es->first_line_def; | 
|---|
| 4456 | while (pc) | 
|---|
| 4457 | { | 
|---|
| 4458 | pp = pc->next; | 
|---|
| 4459 | HeapFree(GetProcessHeap(), 0, pc); | 
|---|
| 4460 | pc = pp; | 
|---|
| 4461 | } | 
|---|
| 4462 |  | 
|---|
| 4463 | SetWindowLongA( hwnd, 0, 0 ); | 
|---|
| 4464 | HeapFree(GetProcessHeap(), 0, es); | 
|---|
| 4465 | } | 
|---|
| 4466 |  | 
|---|
| 4467 |  | 
|---|
| 4468 | /********************************************************************* | 
|---|
| 4469 | * | 
|---|
| 4470 | *  WM_ERASEBKGND | 
|---|
| 4471 | * | 
|---|
| 4472 | */ | 
|---|
| 4473 | static LRESULT EDIT_WM_EraseBkGnd(HWND hwnd, EDITSTATE *es, HDC dc) | 
|---|
| 4474 | { | 
|---|
| 4475 | HBRUSH brush; | 
|---|
| 4476 | RECT rc; | 
|---|
| 4477 |  | 
|---|
| 4478 | if ( get_app_version() >= 0x40000 &&( | 
|---|
| 4479 | !es->bEnableState || (es->style & ES_READONLY))) | 
|---|
| 4480 | brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, dc); | 
|---|
| 4481 | else | 
|---|
| 4482 | brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, dc); | 
|---|
| 4483 |  | 
|---|
| 4484 | if (!brush) | 
|---|
| 4485 | brush = (HBRUSH)GetStockObject(WHITE_BRUSH); | 
|---|
| 4486 |  | 
|---|
| 4487 | GetClientRect(hwnd, &rc); | 
|---|
| 4488 | IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 4489 | GetClipBox(dc, &rc); | 
|---|
| 4490 | /* | 
|---|
| 4491 | *  FIXME:  specs say that we should UnrealizeObject() the brush, | 
|---|
| 4492 | *      but the specs of UnrealizeObject() say that we shouldn't | 
|---|
| 4493 | *      unrealize a stock object.  The default brush that | 
|---|
| 4494 | *      DefWndProc() returns is ... a stock object. | 
|---|
| 4495 | */ | 
|---|
| 4496 | FillRect(dc, &rc, brush); | 
|---|
| 4497 | return -1; | 
|---|
| 4498 | } | 
|---|
| 4499 |  | 
|---|
| 4500 |  | 
|---|
| 4501 | /********************************************************************* | 
|---|
| 4502 | * | 
|---|
| 4503 | *  WM_GETTEXT | 
|---|
| 4504 | * | 
|---|
| 4505 | */ | 
|---|
| 4506 | static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPARAM lParam, BOOL unicode) | 
|---|
| 4507 | { | 
|---|
| 4508 | if(!count) return 0; | 
|---|
| 4509 |  | 
|---|
| 4510 | if(unicode) | 
|---|
| 4511 | { | 
|---|
| 4512 | LPWSTR textW = (LPWSTR)lParam; | 
|---|
| 4513 | strncpyW(textW, es->text, count); | 
|---|
| 4514 | textW[count - 1] = 0; /* ensure 0 termination */ | 
|---|
| 4515 | return strlenW(textW); | 
|---|
| 4516 | } | 
|---|
| 4517 | else | 
|---|
| 4518 | { | 
|---|
| 4519 | LPSTR textA = (LPSTR)lParam; | 
|---|
| 4520 | WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, count, NULL, NULL); | 
|---|
| 4521 | #ifdef __WIN32OS2__ | 
|---|
| 4522 | lstrtrunc( textA, count ); | 
|---|
| 4523 | #else | 
|---|
| 4524 | textA[count - 1] = 0; /* ensure 0 termination */ | 
|---|
| 4525 | #endif | 
|---|
| 4526 | return strlen(textA); | 
|---|
| 4527 | } | 
|---|
| 4528 | } | 
|---|
| 4529 |  | 
|---|
| 4530 | /********************************************************************* | 
|---|
| 4531 | * | 
|---|
| 4532 | *  WM_HSCROLL | 
|---|
| 4533 | * | 
|---|
| 4534 | */ | 
|---|
| 4535 | static LRESULT EDIT_WM_HScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos) | 
|---|
| 4536 | { | 
|---|
| 4537 | INT dx; | 
|---|
| 4538 | INT fw; | 
|---|
| 4539 |  | 
|---|
| 4540 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 4541 | return 0; | 
|---|
| 4542 |  | 
|---|
| 4543 | if (!(es->style & ES_AUTOHSCROLL)) | 
|---|
| 4544 | return 0; | 
|---|
| 4545 |  | 
|---|
| 4546 | dx = 0; | 
|---|
| 4547 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 4548 | switch (action) { | 
|---|
| 4549 | case SB_LINELEFT: | 
|---|
| 4550 | TRACE("SB_LINELEFT\n"); | 
|---|
| 4551 | if (es->x_offset) | 
|---|
| 4552 | dx = -es->char_width; | 
|---|
| 4553 | break; | 
|---|
| 4554 | case SB_LINERIGHT: | 
|---|
| 4555 | TRACE("SB_LINERIGHT\n"); | 
|---|
| 4556 | if (es->x_offset < es->text_width) | 
|---|
| 4557 | dx = es->char_width; | 
|---|
| 4558 | break; | 
|---|
| 4559 | case SB_PAGELEFT: | 
|---|
| 4560 | TRACE("SB_PAGELEFT\n"); | 
|---|
| 4561 | if (es->x_offset) | 
|---|
| 4562 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; | 
|---|
| 4563 | break; | 
|---|
| 4564 | case SB_PAGERIGHT: | 
|---|
| 4565 | TRACE("SB_PAGERIGHT\n"); | 
|---|
| 4566 | if (es->x_offset < es->text_width) | 
|---|
| 4567 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; | 
|---|
| 4568 | break; | 
|---|
| 4569 | case SB_LEFT: | 
|---|
| 4570 | TRACE("SB_LEFT\n"); | 
|---|
| 4571 | if (es->x_offset) | 
|---|
| 4572 | dx = -es->x_offset; | 
|---|
| 4573 | break; | 
|---|
| 4574 | case SB_RIGHT: | 
|---|
| 4575 | TRACE("SB_RIGHT\n"); | 
|---|
| 4576 | if (es->x_offset < es->text_width) | 
|---|
| 4577 | dx = es->text_width - es->x_offset; | 
|---|
| 4578 | break; | 
|---|
| 4579 | case SB_THUMBTRACK: | 
|---|
| 4580 | TRACE("SB_THUMBTRACK %d\n", pos); | 
|---|
| 4581 | es->flags |= EF_HSCROLL_TRACK; | 
|---|
| 4582 | if(es->style & WS_HSCROLL) | 
|---|
| 4583 | dx = pos - es->x_offset; | 
|---|
| 4584 | else | 
|---|
| 4585 | { | 
|---|
| 4586 | INT fw, new_x; | 
|---|
| 4587 | /* Sanity check */ | 
|---|
| 4588 | if(pos < 0 || pos > 100) return 0; | 
|---|
| 4589 | /* Assume default scroll range 0-100 */ | 
|---|
| 4590 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 4591 | new_x = pos * (es->text_width - fw) / 100; | 
|---|
| 4592 | dx = es->text_width ? (new_x - es->x_offset) : 0; | 
|---|
| 4593 | } | 
|---|
| 4594 | break; | 
|---|
| 4595 | case SB_THUMBPOSITION: | 
|---|
| 4596 | TRACE("SB_THUMBPOSITION %d\n", pos); | 
|---|
| 4597 | es->flags &= ~EF_HSCROLL_TRACK; | 
|---|
| 4598 | if(GetWindowLongA( hwnd, GWL_STYLE ) & WS_HSCROLL) | 
|---|
| 4599 | dx = pos - es->x_offset; | 
|---|
| 4600 | else | 
|---|
| 4601 | { | 
|---|
| 4602 | INT fw, new_x; | 
|---|
| 4603 | /* Sanity check */ | 
|---|
| 4604 | if(pos < 0 || pos > 100) return 0; | 
|---|
| 4605 | /* Assume default scroll range 0-100 */ | 
|---|
| 4606 | fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 4607 | new_x = pos * (es->text_width - fw) / 100; | 
|---|
| 4608 | dx = es->text_width ? (new_x - es->x_offset) : 0; | 
|---|
| 4609 | } | 
|---|
| 4610 | if (!dx) { | 
|---|
| 4611 | /* force scroll info update */ | 
|---|
| 4612 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 4613 | EDIT_NOTIFY_PARENT(hwnd, es, EN_HSCROLL, "EN_HSCROLL"); | 
|---|
| 4614 | } | 
|---|
| 4615 | break; | 
|---|
| 4616 | case SB_ENDSCROLL: | 
|---|
| 4617 | TRACE("SB_ENDSCROLL\n"); | 
|---|
| 4618 | break; | 
|---|
| 4619 | /* | 
|---|
| 4620 | *  FIXME : the next two are undocumented ! | 
|---|
| 4621 | *  Are we doing the right thing ? | 
|---|
| 4622 | *  At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, | 
|---|
| 4623 | *  although it's also a regular control message. | 
|---|
| 4624 | */ | 
|---|
| 4625 | case EM_GETTHUMB: /* this one is used by NT notepad */ | 
|---|
| 4626 | case EM_GETTHUMB16: | 
|---|
| 4627 | { | 
|---|
| 4628 | LRESULT ret; | 
|---|
| 4629 | if(GetWindowLongA( hwnd, GWL_STYLE ) & WS_HSCROLL) | 
|---|
| 4630 | ret = GetScrollPos(hwnd, SB_HORZ); | 
|---|
| 4631 | else | 
|---|
| 4632 | { | 
|---|
| 4633 | /* Assume default scroll range 0-100 */ | 
|---|
| 4634 | INT fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 4635 | ret = es->text_width ? es->x_offset * 100 / (es->text_width - fw) : 0; | 
|---|
| 4636 | } | 
|---|
| 4637 | TRACE("EM_GETTHUMB: returning %ld\n", ret); | 
|---|
| 4638 | return ret; | 
|---|
| 4639 | } | 
|---|
| 4640 | case EM_LINESCROLL16: | 
|---|
| 4641 | TRACE("EM_LINESCROLL16\n"); | 
|---|
| 4642 | dx = pos; | 
|---|
| 4643 | break; | 
|---|
| 4644 |  | 
|---|
| 4645 | default: | 
|---|
| 4646 | ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n", | 
|---|
| 4647 | action, action); | 
|---|
| 4648 | return 0; | 
|---|
| 4649 | } | 
|---|
| 4650 | if (dx) | 
|---|
| 4651 | { | 
|---|
| 4652 | INT fw = es->format_rect.right - es->format_rect.left; | 
|---|
| 4653 | /* check if we are going to move too far */ | 
|---|
| 4654 | if(es->x_offset + dx + fw > es->text_width) | 
|---|
| 4655 | dx = es->text_width - fw - es->x_offset; | 
|---|
| 4656 | if(dx) | 
|---|
| 4657 | EDIT_EM_LineScroll_internal(hwnd, es, dx, 0); | 
|---|
| 4658 | } | 
|---|
| 4659 | return 0; | 
|---|
| 4660 | } | 
|---|
| 4661 |  | 
|---|
| 4662 |  | 
|---|
| 4663 | /********************************************************************* | 
|---|
| 4664 | * | 
|---|
| 4665 | *  EDIT_CheckCombo | 
|---|
| 4666 | * | 
|---|
| 4667 | */ | 
|---|
| 4668 | static BOOL EDIT_CheckCombo(HWND hwnd, EDITSTATE *es, UINT msg, INT key) | 
|---|
| 4669 | { | 
|---|
| 4670 | HWND hLBox = es->hwndListBox; | 
|---|
| 4671 | HWND hCombo; | 
|---|
| 4672 | BOOL bDropped; | 
|---|
| 4673 | int  nEUI; | 
|---|
| 4674 |  | 
|---|
| 4675 | if (!hLBox) | 
|---|
| 4676 | return FALSE; | 
|---|
| 4677 |  | 
|---|
| 4678 | hCombo   = GetParent(hwnd); | 
|---|
| 4679 | bDropped = TRUE; | 
|---|
| 4680 | nEUI     = 0; | 
|---|
| 4681 |  | 
|---|
| 4682 | TRACE_(combo)("[%04x]: handling msg %04x (%04x)\n", | 
|---|
| 4683 | hwnd, (UINT16)msg, (UINT16)key); | 
|---|
| 4684 |  | 
|---|
| 4685 | if (key == VK_UP || key == VK_DOWN) | 
|---|
| 4686 | { | 
|---|
| 4687 | if (SendMessageW(hCombo, CB_GETEXTENDEDUI, 0, 0)) | 
|---|
| 4688 | nEUI = 1; | 
|---|
| 4689 |  | 
|---|
| 4690 | if (msg == WM_KEYDOWN || nEUI) | 
|---|
| 4691 | bDropped = (BOOL)SendMessageW(hCombo, CB_GETDROPPEDSTATE, 0, 0); | 
|---|
| 4692 | } | 
|---|
| 4693 |  | 
|---|
| 4694 | switch (msg) | 
|---|
| 4695 | { | 
|---|
| 4696 | case WM_KEYDOWN: | 
|---|
| 4697 | if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN)) | 
|---|
| 4698 | { | 
|---|
| 4699 | /* make sure ComboLBox pops up */ | 
|---|
| 4700 | SendMessageW(hCombo, CB_SETEXTENDEDUI, FALSE, 0); | 
|---|
| 4701 | key = VK_F4; | 
|---|
| 4702 | nEUI = 2; | 
|---|
| 4703 | } | 
|---|
| 4704 |  | 
|---|
| 4705 | SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)key, 0); | 
|---|
| 4706 | break; | 
|---|
| 4707 |  | 
|---|
| 4708 | case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */ | 
|---|
| 4709 | if (nEUI) | 
|---|
| 4710 | SendMessageW(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0); | 
|---|
| 4711 | else | 
|---|
| 4712 | SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0); | 
|---|
| 4713 | break; | 
|---|
| 4714 | } | 
|---|
| 4715 |  | 
|---|
| 4716 | if(nEUI == 2) | 
|---|
| 4717 | SendMessageW(hCombo, CB_SETEXTENDEDUI, TRUE, 0); | 
|---|
| 4718 |  | 
|---|
| 4719 | return TRUE; | 
|---|
| 4720 | } | 
|---|
| 4721 |  | 
|---|
| 4722 |  | 
|---|
| 4723 | /********************************************************************* | 
|---|
| 4724 | * | 
|---|
| 4725 | *  WM_KEYDOWN | 
|---|
| 4726 | * | 
|---|
| 4727 | *  Handling of special keys that don't produce a WM_CHAR | 
|---|
| 4728 | *  (i.e. non-printable keys) & Backspace & Delete | 
|---|
| 4729 | * | 
|---|
| 4730 | */ | 
|---|
| 4731 | static LRESULT EDIT_WM_KeyDown(HWND hwnd, EDITSTATE *es, INT key) | 
|---|
| 4732 | { | 
|---|
| 4733 | BOOL shift; | 
|---|
| 4734 | BOOL control; | 
|---|
| 4735 |  | 
|---|
| 4736 | if (GetKeyState(VK_MENU) & 0x8000) | 
|---|
| 4737 | return 0; | 
|---|
| 4738 |  | 
|---|
| 4739 | shift = GetKeyState(VK_SHIFT) & 0x8000; | 
|---|
| 4740 | control = GetKeyState(VK_CONTROL) & 0x8000; | 
|---|
| 4741 |  | 
|---|
| 4742 | switch (key) { | 
|---|
| 4743 | case VK_F4: | 
|---|
| 4744 | case VK_UP: | 
|---|
| 4745 | if (EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key) || key == VK_F4) | 
|---|
| 4746 | break; | 
|---|
| 4747 |  | 
|---|
| 4748 | /* fall through */ | 
|---|
| 4749 | case VK_LEFT: | 
|---|
| 4750 | if ((es->style & ES_MULTILINE) && (key == VK_UP)) | 
|---|
| 4751 | EDIT_MoveUp_ML(hwnd, es, shift); | 
|---|
| 4752 | else | 
|---|
| 4753 | if (control) | 
|---|
| 4754 | EDIT_MoveWordBackward(hwnd, es, shift); | 
|---|
| 4755 | else | 
|---|
| 4756 | EDIT_MoveBackward(hwnd, es, shift); | 
|---|
| 4757 | break; | 
|---|
| 4758 | case VK_DOWN: | 
|---|
| 4759 | if (EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key)) | 
|---|
| 4760 | break; | 
|---|
| 4761 | /* fall through */ | 
|---|
| 4762 | case VK_RIGHT: | 
|---|
| 4763 | if ((es->style & ES_MULTILINE) && (key == VK_DOWN)) | 
|---|
| 4764 | EDIT_MoveDown_ML(hwnd, es, shift); | 
|---|
| 4765 | else if (control) | 
|---|
| 4766 | EDIT_MoveWordForward(hwnd, es, shift); | 
|---|
| 4767 | else | 
|---|
| 4768 | EDIT_MoveForward(hwnd, es, shift); | 
|---|
| 4769 | break; | 
|---|
| 4770 | case VK_HOME: | 
|---|
| 4771 | EDIT_MoveHome(hwnd, es, shift); | 
|---|
| 4772 | break; | 
|---|
| 4773 | case VK_END: | 
|---|
| 4774 | EDIT_MoveEnd(hwnd, es, shift); | 
|---|
| 4775 | break; | 
|---|
| 4776 | case VK_PRIOR: | 
|---|
| 4777 | if (es->style & ES_MULTILINE) | 
|---|
| 4778 | EDIT_MovePageUp_ML(hwnd, es, shift); | 
|---|
| 4779 | else | 
|---|
| 4780 | EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key); | 
|---|
| 4781 | break; | 
|---|
| 4782 | case VK_NEXT: | 
|---|
| 4783 | if (es->style & ES_MULTILINE) | 
|---|
| 4784 | EDIT_MovePageDown_ML(hwnd, es, shift); | 
|---|
| 4785 | else | 
|---|
| 4786 | EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key); | 
|---|
| 4787 | break; | 
|---|
| 4788 | case VK_DELETE: | 
|---|
| 4789 | if (!(es->style & ES_READONLY) && !(shift && control)) { | 
|---|
| 4790 | if (es->selection_start != es->selection_end) { | 
|---|
| 4791 | if (shift) | 
|---|
| 4792 | EDIT_WM_Cut(hwnd, es); | 
|---|
| 4793 | else | 
|---|
| 4794 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4795 | } else { | 
|---|
| 4796 | if (shift) { | 
|---|
| 4797 | /* delete character left of caret */ | 
|---|
| 4798 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 4799 | EDIT_MoveBackward(hwnd, es, TRUE); | 
|---|
| 4800 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4801 | } else if (control) { | 
|---|
| 4802 | /* delete to end of line */ | 
|---|
| 4803 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 4804 | EDIT_MoveEnd(hwnd, es, TRUE); | 
|---|
| 4805 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4806 | } else { | 
|---|
| 4807 | /* delete character right of caret */ | 
|---|
| 4808 | EDIT_EM_SetSel(hwnd, es, (UINT)-1, 0, FALSE); | 
|---|
| 4809 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 4810 | EDIT_WM_Clear(hwnd, es); | 
|---|
| 4811 | } | 
|---|
| 4812 | } | 
|---|
| 4813 | } | 
|---|
| 4814 | break; | 
|---|
| 4815 | case VK_INSERT: | 
|---|
| 4816 | if (shift) { | 
|---|
| 4817 | if (!(es->style & ES_READONLY)) | 
|---|
| 4818 | EDIT_WM_Paste(hwnd, es); | 
|---|
| 4819 | } else if (control) | 
|---|
| 4820 | EDIT_WM_Copy(hwnd, es); | 
|---|
| 4821 | break; | 
|---|
| 4822 | case VK_RETURN: | 
|---|
| 4823 | /* If the edit doesn't want the return send a message to the default object */ | 
|---|
| 4824 | if(!(es->style & ES_WANTRETURN)) | 
|---|
| 4825 | { | 
|---|
| 4826 | HWND hwndParent = GetParent(hwnd); | 
|---|
| 4827 | DWORD dw = SendMessageW( hwndParent, DM_GETDEFID, 0, 0 ); | 
|---|
| 4828 | if (HIWORD(dw) == DC_HASDEFID) | 
|---|
| 4829 | { | 
|---|
| 4830 | SendMessageW( hwndParent, WM_COMMAND, | 
|---|
| 4831 | MAKEWPARAM( LOWORD(dw), BN_CLICKED ), | 
|---|
| 4832 | (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) ); | 
|---|
| 4833 | } | 
|---|
| 4834 | } | 
|---|
| 4835 | break; | 
|---|
| 4836 | } | 
|---|
| 4837 | return 0; | 
|---|
| 4838 | } | 
|---|
| 4839 |  | 
|---|
| 4840 |  | 
|---|
| 4841 | /********************************************************************* | 
|---|
| 4842 | * | 
|---|
| 4843 | *  WM_KILLFOCUS | 
|---|
| 4844 | * | 
|---|
| 4845 | */ | 
|---|
| 4846 | static LRESULT EDIT_WM_KillFocus(HWND hwnd, EDITSTATE *es) | 
|---|
| 4847 | { | 
|---|
| 4848 | es->flags &= ~EF_FOCUSED; | 
|---|
| 4849 | DestroyCaret(); | 
|---|
| 4850 | if(!(es->style & ES_NOHIDESEL)) | 
|---|
| 4851 | EDIT_InvalidateText(hwnd, es, es->selection_start, es->selection_end); | 
|---|
| 4852 | EDIT_NOTIFY_PARENT(hwnd, es, EN_KILLFOCUS, "EN_KILLFOCUS"); | 
|---|
| 4853 | return 0; | 
|---|
| 4854 | } | 
|---|
| 4855 |  | 
|---|
| 4856 |  | 
|---|
| 4857 | /********************************************************************* | 
|---|
| 4858 | * | 
|---|
| 4859 | *  WM_LBUTTONDBLCLK | 
|---|
| 4860 | * | 
|---|
| 4861 | *  The caret position has been set on the WM_LBUTTONDOWN message | 
|---|
| 4862 | * | 
|---|
| 4863 | */ | 
|---|
| 4864 | static LRESULT EDIT_WM_LButtonDblClk(HWND hwnd, EDITSTATE *es) | 
|---|
| 4865 | { | 
|---|
| 4866 | INT s; | 
|---|
| 4867 | INT e = es->selection_end; | 
|---|
| 4868 | INT l; | 
|---|
| 4869 | INT li; | 
|---|
| 4870 | INT ll; | 
|---|
| 4871 |  | 
|---|
| 4872 | if (!(es->flags & EF_FOCUSED)) | 
|---|
| 4873 | return 0; | 
|---|
| 4874 |  | 
|---|
| 4875 | l = EDIT_EM_LineFromChar(es, e); | 
|---|
| 4876 | li = EDIT_EM_LineIndex(es, l); | 
|---|
| 4877 | ll = EDIT_EM_LineLength(es, e); | 
|---|
| 4878 | s = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT); | 
|---|
| 4879 | e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_RIGHT); | 
|---|
| 4880 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE); | 
|---|
| 4881 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 4882 | return 0; | 
|---|
| 4883 | } | 
|---|
| 4884 |  | 
|---|
| 4885 |  | 
|---|
| 4886 | /********************************************************************* | 
|---|
| 4887 | * | 
|---|
| 4888 | *  WM_LBUTTONDOWN | 
|---|
| 4889 | * | 
|---|
| 4890 | */ | 
|---|
| 4891 | static LRESULT EDIT_WM_LButtonDown(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y) | 
|---|
| 4892 | { | 
|---|
| 4893 | INT e; | 
|---|
| 4894 | BOOL after_wrap; | 
|---|
| 4895 |  | 
|---|
| 4896 | if (!(es->flags & EF_FOCUSED)) | 
|---|
| 4897 | return 0; | 
|---|
| 4898 |  | 
|---|
| 4899 | es->bCaptureState = TRUE; | 
|---|
| 4900 | SetCapture(hwnd); | 
|---|
| 4901 | EDIT_ConfinePoint(es, &x, &y); | 
|---|
| 4902 | e = EDIT_CharFromPos(hwnd, es, x, y, &after_wrap); | 
|---|
| 4903 | EDIT_EM_SetSel(hwnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap); | 
|---|
| 4904 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 4905 | es->region_posx = es->region_posy = 0; | 
|---|
| 4906 | SetTimer(hwnd, 0, 100, NULL); | 
|---|
| 4907 | return 0; | 
|---|
| 4908 | } | 
|---|
| 4909 |  | 
|---|
| 4910 |  | 
|---|
| 4911 | /********************************************************************* | 
|---|
| 4912 | * | 
|---|
| 4913 | *  WM_LBUTTONUP | 
|---|
| 4914 | * | 
|---|
| 4915 | */ | 
|---|
| 4916 | static LRESULT EDIT_WM_LButtonUp(HWND hwndSelf, EDITSTATE *es) | 
|---|
| 4917 | { | 
|---|
| 4918 | #ifdef __WIN32OS2__ | 
|---|
| 4919 | if (es->bCaptureState) { | 
|---|
| 4920 | KillTimer(hwndSelf, 0); | 
|---|
| 4921 | if(GetCapture() == hwndSelf) ReleaseCapture(); | 
|---|
| 4922 | } | 
|---|
| 4923 | #else | 
|---|
| 4924 | if (es->bCaptureState && GetCapture() == hwndSelf) { | 
|---|
| 4925 | KillTimer(hwndSelf, 0); | 
|---|
| 4926 | ReleaseCapture(); | 
|---|
| 4927 | } | 
|---|
| 4928 | #endif | 
|---|
| 4929 | es->bCaptureState = FALSE; | 
|---|
| 4930 | return 0; | 
|---|
| 4931 | } | 
|---|
| 4932 |  | 
|---|
| 4933 |  | 
|---|
| 4934 | /********************************************************************* | 
|---|
| 4935 | * | 
|---|
| 4936 | *  WM_MBUTTONDOWN | 
|---|
| 4937 | * | 
|---|
| 4938 | */ | 
|---|
| 4939 | static LRESULT EDIT_WM_MButtonDown(HWND hwnd) | 
|---|
| 4940 | { | 
|---|
| 4941 | SendMessageW(hwnd,WM_PASTE,0,0); | 
|---|
| 4942 | return 0; | 
|---|
| 4943 | } | 
|---|
| 4944 |  | 
|---|
| 4945 |  | 
|---|
| 4946 | /********************************************************************* | 
|---|
| 4947 | * | 
|---|
| 4948 | *  WM_MOUSEMOVE | 
|---|
| 4949 | * | 
|---|
| 4950 | */ | 
|---|
| 4951 | static LRESULT EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, INT x, INT y) | 
|---|
| 4952 | { | 
|---|
| 4953 | INT e; | 
|---|
| 4954 | BOOL after_wrap; | 
|---|
| 4955 | INT prex, prey; | 
|---|
| 4956 |  | 
|---|
| 4957 | if (GetCapture() != hwnd) | 
|---|
| 4958 | return 0; | 
|---|
| 4959 |  | 
|---|
| 4960 | /* | 
|---|
| 4961 | *  FIXME: gotta do some scrolling if outside client | 
|---|
| 4962 | *      area.  Maybe reset the timer ? | 
|---|
| 4963 | */ | 
|---|
| 4964 | prex = x; prey = y; | 
|---|
| 4965 | EDIT_ConfinePoint(es, &x, &y); | 
|---|
| 4966 | es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0); | 
|---|
| 4967 | es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0); | 
|---|
| 4968 | e = EDIT_CharFromPos(hwnd, es, x, y, &after_wrap); | 
|---|
| 4969 | EDIT_EM_SetSel(hwnd, es, es->selection_start, e, after_wrap); | 
|---|
| 4970 | return 0; | 
|---|
| 4971 | } | 
|---|
| 4972 |  | 
|---|
| 4973 |  | 
|---|
| 4974 | /********************************************************************* | 
|---|
| 4975 | * | 
|---|
| 4976 | *  WM_NCCREATE | 
|---|
| 4977 | * | 
|---|
| 4978 | * See also EDIT_WM_StyleChanged | 
|---|
| 4979 | */ | 
|---|
| 4980 | static LRESULT EDIT_WM_NCCreate(HWND hwnd, DWORD style, HWND hwndParent, BOOL unicode) | 
|---|
| 4981 | { | 
|---|
| 4982 | EDITSTATE *es; | 
|---|
| 4983 | UINT alloc_size; | 
|---|
| 4984 |  | 
|---|
| 4985 | TRACE("Creating %s edit control, style = %08lx\n", | 
|---|
| 4986 | unicode ? "Unicode" : "ANSI", style); | 
|---|
| 4987 |  | 
|---|
| 4988 | if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es)))) | 
|---|
| 4989 | return FALSE; | 
|---|
| 4990 | SetWindowLongA( hwnd, 0, (LONG)es ); | 
|---|
| 4991 |  | 
|---|
| 4992 | /* | 
|---|
| 4993 | *      Note: since the EDITSTATE has not been fully initialized yet, | 
|---|
| 4994 | *            we can't use any API calls that may send | 
|---|
| 4995 | *            WM_XXX messages before WM_NCCREATE is completed. | 
|---|
| 4996 | */ | 
|---|
| 4997 |  | 
|---|
| 4998 | es->is_unicode = unicode; | 
|---|
| 4999 | es->style = style; | 
|---|
| 5000 |  | 
|---|
| 5001 | es->bEnableState = !(style & WS_DISABLED); | 
|---|
| 5002 |  | 
|---|
| 5003 | /* Save parent, which will be notified by EN_* messages */ | 
|---|
| 5004 | es->hwndParent = hwndParent; | 
|---|
| 5005 |  | 
|---|
| 5006 | if (es->style & ES_COMBO) | 
|---|
| 5007 | es->hwndListBox = GetDlgItem(hwndParent, ID_CB_LISTBOX); | 
|---|
| 5008 |  | 
|---|
| 5009 | /* Number overrides lowercase overrides uppercase (at least it | 
|---|
| 5010 | * does in Win95).  However I'll bet that ES_NUMBER would be | 
|---|
| 5011 | * invalid under Win 3.1. | 
|---|
| 5012 | */ | 
|---|
| 5013 | if (es->style & ES_NUMBER) { | 
|---|
| 5014 | ; /* do not override the ES_NUMBER */ | 
|---|
| 5015 | }  else if (es->style & ES_LOWERCASE) { | 
|---|
| 5016 | es->style &= ~ES_UPPERCASE; | 
|---|
| 5017 | } | 
|---|
| 5018 | if (es->style & ES_MULTILINE) { | 
|---|
| 5019 | es->buffer_limit = BUFLIMIT_MULTI; | 
|---|
| 5020 | if (es->style & WS_VSCROLL) | 
|---|
| 5021 | es->style |= ES_AUTOVSCROLL; | 
|---|
| 5022 | if (es->style & WS_HSCROLL) | 
|---|
| 5023 | es->style |= ES_AUTOHSCROLL; | 
|---|
| 5024 | es->style &= ~ES_PASSWORD; | 
|---|
| 5025 | if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) { | 
|---|
| 5026 | /* Confirmed - RIGHT overrides CENTER */ | 
|---|
| 5027 | if (es->style & ES_RIGHT) | 
|---|
| 5028 | es->style &= ~ES_CENTER; | 
|---|
| 5029 | es->style &= ~WS_HSCROLL; | 
|---|
| 5030 | es->style &= ~ES_AUTOHSCROLL; | 
|---|
| 5031 | } | 
|---|
| 5032 |  | 
|---|
| 5033 | /* FIXME: for now, all multi line controls are AUTOVSCROLL */ | 
|---|
| 5034 | es->style |= ES_AUTOVSCROLL; | 
|---|
| 5035 | } else { | 
|---|
| 5036 | es->buffer_limit = BUFLIMIT_SINGLE; | 
|---|
| 5037 | if (WIN31_LOOK == TWEAK_WineLook || | 
|---|
| 5038 | WIN95_LOOK == TWEAK_WineLook) { | 
|---|
| 5039 | es->style &= ~ES_CENTER; | 
|---|
| 5040 | es->style &= ~ES_RIGHT; | 
|---|
| 5041 | } else { | 
|---|
| 5042 | if (es->style & ES_RIGHT) | 
|---|
| 5043 | es->style &= ~ES_CENTER; | 
|---|
| 5044 | } | 
|---|
| 5045 | es->style &= ~WS_HSCROLL; | 
|---|
| 5046 | es->style &= ~WS_VSCROLL; | 
|---|
| 5047 | es->style &= ~ES_AUTOVSCROLL; | 
|---|
| 5048 | es->style &= ~ES_WANTRETURN; | 
|---|
| 5049 | if (es->style & ES_PASSWORD) | 
|---|
| 5050 | es->password_char = '*'; | 
|---|
| 5051 |  | 
|---|
| 5052 | /* FIXME: for now, all single line controls are AUTOHSCROLL */ | 
|---|
| 5053 | es->style |= ES_AUTOHSCROLL; | 
|---|
| 5054 | } | 
|---|
| 5055 |  | 
|---|
| 5056 | alloc_size = ROUND_TO_GROW((es->buffer_size + 1) * sizeof(WCHAR)); | 
|---|
| 5057 | if(!(es->hloc32W = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) | 
|---|
| 5058 | return FALSE; | 
|---|
| 5059 | es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1; | 
|---|
| 5060 |  | 
|---|
| 5061 | if (!(es->undo_text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (es->buffer_size + 1) * sizeof(WCHAR)))) | 
|---|
| 5062 | return FALSE; | 
|---|
| 5063 | es->undo_buffer_size = es->buffer_size; | 
|---|
| 5064 |  | 
|---|
| 5065 | if (es->style & ES_MULTILINE) | 
|---|
| 5066 | if (!(es->first_line_def = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINEDEF)))) | 
|---|
| 5067 | return FALSE; | 
|---|
| 5068 | es->line_count = 1; | 
|---|
| 5069 |  | 
|---|
| 5070 | /* | 
|---|
| 5071 | * In Win95 look and feel, the WS_BORDER style is replaced by the | 
|---|
| 5072 | * WS_EX_CLIENTEDGE style for the edit control. This gives the edit | 
|---|
| 5073 | * control a non client area.  Not always.  This coordinates in some | 
|---|
| 5074 | * way with the window creation code in dialog.c  When making | 
|---|
| 5075 | * modifications please ensure that the code still works for edit | 
|---|
| 5076 | * controls created directly with style 0x50800000, exStyle 0 ( | 
|---|
| 5077 | * which should have a single pixel border) | 
|---|
| 5078 | */ | 
|---|
| 5079 | if (TWEAK_WineLook != WIN31_LOOK) | 
|---|
| 5080 | { | 
|---|
| 5081 | es->style      &= ~WS_BORDER; | 
|---|
| 5082 | } | 
|---|
| 5083 | else | 
|---|
| 5084 | { | 
|---|
| 5085 | if ((es->style & WS_BORDER) && !(es->style & WS_DLGFRAME)) | 
|---|
| 5086 | SetWindowLongA( hwnd, GWL_STYLE, | 
|---|
| 5087 | GetWindowLongA( hwnd, GWL_STYLE ) & ~WS_BORDER ); | 
|---|
| 5088 | } | 
|---|
| 5089 |  | 
|---|
| 5090 | #ifdef __WIN32OS2__ | 
|---|
| 5091 | es->compStr = NULL; | 
|---|
| 5092 | es->compStrLen = 0; | 
|---|
| 5093 | es->moveCaret = TRUE; | 
|---|
| 5094 | { | 
|---|
| 5095 | HIMC  himc; | 
|---|
| 5096 | DWORD conversionMode; | 
|---|
| 5097 |  | 
|---|
| 5098 | himc = ImmGetContext( hwnd ); | 
|---|
| 5099 |  | 
|---|
| 5100 | ImmGetConversionStatus( himc, &conversionMode, &es->sentenceMode ); | 
|---|
| 5101 |  | 
|---|
| 5102 | ImmReleaseContext( hwnd, himc ); | 
|---|
| 5103 | } | 
|---|
| 5104 | #endif | 
|---|
| 5105 |  | 
|---|
| 5106 | return TRUE; | 
|---|
| 5107 | } | 
|---|
| 5108 |  | 
|---|
| 5109 | /********************************************************************* | 
|---|
| 5110 | * | 
|---|
| 5111 | *  WM_PAINT | 
|---|
| 5112 | * | 
|---|
| 5113 | */ | 
|---|
| 5114 | static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es, WPARAM wParam) | 
|---|
| 5115 | { | 
|---|
| 5116 | PAINTSTRUCT ps; | 
|---|
| 5117 | INT i; | 
|---|
| 5118 | HDC dc; | 
|---|
| 5119 | HFONT old_font = 0; | 
|---|
| 5120 | RECT rc; | 
|---|
| 5121 | RECT rcLine; | 
|---|
| 5122 | RECT rcRgn; | 
|---|
| 5123 | BOOL rev = es->bEnableState && | 
|---|
| 5124 | ((es->flags & EF_FOCUSED) || | 
|---|
| 5125 | (es->style & ES_NOHIDESEL)); | 
|---|
| 5126 | if (!wParam) | 
|---|
| 5127 | dc = BeginPaint(hwnd, &ps); | 
|---|
| 5128 | else | 
|---|
| 5129 | dc = (HDC) wParam; | 
|---|
| 5130 | if(es->style & WS_BORDER) { | 
|---|
| 5131 | GetClientRect(hwnd, &rc); | 
|---|
| 5132 | if(es->style & ES_MULTILINE) { | 
|---|
| 5133 | if(es->style & WS_HSCROLL) rc.bottom++; | 
|---|
| 5134 | if(es->style & WS_VSCROLL) rc.right++; | 
|---|
| 5135 | } | 
|---|
| 5136 | Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 5137 | } | 
|---|
| 5138 | IntersectClipRect(dc, es->format_rect.left, | 
|---|
| 5139 | es->format_rect.top, | 
|---|
| 5140 | es->format_rect.right, | 
|---|
| 5141 | es->format_rect.bottom); | 
|---|
| 5142 | if (es->style & ES_MULTILINE) { | 
|---|
| 5143 | GetClientRect(hwnd, &rc); | 
|---|
| 5144 | IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom); | 
|---|
| 5145 | } | 
|---|
| 5146 | if (es->font) | 
|---|
| 5147 | old_font = SelectObject(dc, es->font); | 
|---|
| 5148 | if ( get_app_version() >= 0x40000 &&( | 
|---|
| 5149 | !es->bEnableState || (es->style & ES_READONLY))) | 
|---|
| 5150 | EDIT_SEND_CTLCOLORSTATIC(hwnd, dc); | 
|---|
| 5151 | else | 
|---|
| 5152 | EDIT_SEND_CTLCOLOR(hwnd, dc); | 
|---|
| 5153 |  | 
|---|
| 5154 | if (!es->bEnableState) | 
|---|
| 5155 | SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT)); | 
|---|
| 5156 | GetClipBox(dc, &rcRgn); | 
|---|
| 5157 | if (es->style & ES_MULTILINE) { | 
|---|
| 5158 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 5159 | for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) { | 
|---|
| 5160 | EDIT_GetLineRect(hwnd, es, i, 0, -1, &rcLine); | 
|---|
| 5161 | if (IntersectRect(&rc, &rcRgn, &rcLine)) | 
|---|
| 5162 | EDIT_PaintLine(hwnd, es, dc, i, rev); | 
|---|
| 5163 | } | 
|---|
| 5164 | } else { | 
|---|
| 5165 | EDIT_GetLineRect(hwnd, es, 0, 0, -1, &rcLine); | 
|---|
| 5166 | if (IntersectRect(&rc, &rcRgn, &rcLine)) | 
|---|
| 5167 | EDIT_PaintLine(hwnd, es, dc, 0, rev); | 
|---|
| 5168 | } | 
|---|
| 5169 | if (es->font) | 
|---|
| 5170 | SelectObject(dc, old_font); | 
|---|
| 5171 |  | 
|---|
| 5172 | if (!wParam) | 
|---|
| 5173 | EndPaint(hwnd, &ps); | 
|---|
| 5174 | } | 
|---|
| 5175 |  | 
|---|
| 5176 |  | 
|---|
| 5177 | /********************************************************************* | 
|---|
| 5178 | * | 
|---|
| 5179 | *  WM_PASTE | 
|---|
| 5180 | * | 
|---|
| 5181 | */ | 
|---|
| 5182 | static void EDIT_WM_Paste(HWND hwnd, EDITSTATE *es) | 
|---|
| 5183 | { | 
|---|
| 5184 | HGLOBAL hsrc; | 
|---|
| 5185 | LPWSTR src; | 
|---|
| 5186 |  | 
|---|
| 5187 | /* Protect read-only edit control from modification */ | 
|---|
| 5188 | if(es->style & ES_READONLY) | 
|---|
| 5189 | return; | 
|---|
| 5190 |  | 
|---|
| 5191 | OpenClipboard(hwnd); | 
|---|
| 5192 | if ((hsrc = GetClipboardData(CF_UNICODETEXT)) != 0) { | 
|---|
| 5193 | src = (LPWSTR)GlobalLock(hsrc); | 
|---|
| 5194 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, src, TRUE); | 
|---|
| 5195 | GlobalUnlock(hsrc); | 
|---|
| 5196 | } | 
|---|
| 5197 | CloseClipboard(); | 
|---|
| 5198 | } | 
|---|
| 5199 |  | 
|---|
| 5200 |  | 
|---|
| 5201 | /********************************************************************* | 
|---|
| 5202 | * | 
|---|
| 5203 | *  WM_SETFOCUS | 
|---|
| 5204 | * | 
|---|
| 5205 | */ | 
|---|
| 5206 | static void EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es) | 
|---|
| 5207 | { | 
|---|
| 5208 | es->flags |= EF_FOCUSED; | 
|---|
| 5209 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 5210 | EDIT_SetCaretPos(hwnd, es, es->selection_end, | 
|---|
| 5211 | es->flags & EF_AFTER_WRAP); | 
|---|
| 5212 | if(!(es->style & ES_NOHIDESEL)) | 
|---|
| 5213 | EDIT_InvalidateText(hwnd, es, es->selection_start, es->selection_end); | 
|---|
| 5214 | ShowCaret(hwnd); | 
|---|
| 5215 | EDIT_NOTIFY_PARENT(hwnd, es, EN_SETFOCUS, "EN_SETFOCUS"); | 
|---|
| 5216 | } | 
|---|
| 5217 |  | 
|---|
| 5218 |  | 
|---|
| 5219 | /********************************************************************* | 
|---|
| 5220 | * | 
|---|
| 5221 | *  WM_SETFONT | 
|---|
| 5222 | * | 
|---|
| 5223 | * With Win95 look the margins are set to default font value unless | 
|---|
| 5224 | * the system font (font == 0) is being set, in which case they are left | 
|---|
| 5225 | * unchanged. | 
|---|
| 5226 | * | 
|---|
| 5227 | */ | 
|---|
| 5228 | static void EDIT_WM_SetFont(HWND hwnd, EDITSTATE *es, HFONT font, BOOL redraw) | 
|---|
| 5229 | { | 
|---|
| 5230 | TEXTMETRICW tm; | 
|---|
| 5231 | HDC dc; | 
|---|
| 5232 | HFONT old_font = 0; | 
|---|
| 5233 | RECT r; | 
|---|
| 5234 |  | 
|---|
| 5235 | es->font = font; | 
|---|
| 5236 | dc = GetDC(hwnd); | 
|---|
| 5237 | #ifdef __WIN32OS2__ | 
|---|
| 5238 | // todo : set font of IME window | 
|---|
| 5239 | #endif | 
|---|
| 5240 | if (font) | 
|---|
| 5241 | old_font = SelectObject(dc, font); | 
|---|
| 5242 | GetTextMetricsW(dc, &tm); | 
|---|
| 5243 | es->line_height = tm.tmHeight; | 
|---|
| 5244 | es->char_width = tm.tmAveCharWidth; | 
|---|
| 5245 | if (font) | 
|---|
| 5246 | SelectObject(dc, old_font); | 
|---|
| 5247 | ReleaseDC(hwnd, dc); | 
|---|
| 5248 | if (font && (TWEAK_WineLook > WIN31_LOOK)) | 
|---|
| 5249 | EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN, | 
|---|
| 5250 | EC_USEFONTINFO, EC_USEFONTINFO); | 
|---|
| 5251 |  | 
|---|
| 5252 | /* Force the recalculation of the format rect for each font change */ | 
|---|
| 5253 | GetClientRect(hwnd, &r); | 
|---|
| 5254 | EDIT_SetRectNP(hwnd, es, &r); | 
|---|
| 5255 |  | 
|---|
| 5256 | if (es->style & ES_MULTILINE) | 
|---|
| 5257 | EDIT_BuildLineDefs_ML(hwnd, es, 0, strlenW(es->text), 0, (HRGN)0); | 
|---|
| 5258 | else | 
|---|
| 5259 | EDIT_CalcLineWidth_SL(hwnd, es); | 
|---|
| 5260 |  | 
|---|
| 5261 | if (redraw) | 
|---|
| 5262 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 5263 | if (es->flags & EF_FOCUSED) { | 
|---|
| 5264 | DestroyCaret(); | 
|---|
| 5265 | CreateCaret(hwnd, 0, 2, es->line_height); | 
|---|
| 5266 | EDIT_SetCaretPos(hwnd, es, es->selection_end, | 
|---|
| 5267 | es->flags & EF_AFTER_WRAP); | 
|---|
| 5268 | ShowCaret(hwnd); | 
|---|
| 5269 | } | 
|---|
| 5270 | } | 
|---|
| 5271 |  | 
|---|
| 5272 |  | 
|---|
| 5273 | /********************************************************************* | 
|---|
| 5274 | * | 
|---|
| 5275 | *  WM_SETTEXT | 
|---|
| 5276 | * | 
|---|
| 5277 | * NOTES | 
|---|
| 5278 | *  For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers: | 
|---|
| 5279 | *  The modified flag is reset. No notifications are sent. | 
|---|
| 5280 | * | 
|---|
| 5281 | *  For single-line controls, reception of WM_SETTEXT triggers: | 
|---|
| 5282 | *  The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent. | 
|---|
| 5283 | * | 
|---|
| 5284 | */ | 
|---|
| 5285 | static void EDIT_WM_SetText(HWND hwnd, EDITSTATE *es, LPARAM lParam, BOOL unicode) | 
|---|
| 5286 | { | 
|---|
| 5287 | LPWSTR text = NULL; | 
|---|
| 5288 |  | 
|---|
| 5289 | if(unicode) | 
|---|
| 5290 | text = (LPWSTR)lParam; | 
|---|
| 5291 | else if (lParam) | 
|---|
| 5292 | { | 
|---|
| 5293 | LPCSTR textA = (LPCSTR)lParam; | 
|---|
| 5294 | INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0); | 
|---|
| 5295 | if((text = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))) != NULL) | 
|---|
| 5296 | MultiByteToWideChar(CP_ACP, 0, textA, -1, text, countW); | 
|---|
| 5297 | } | 
|---|
| 5298 |  | 
|---|
| 5299 | EDIT_EM_SetSel(hwnd, es, 0, (UINT)-1, FALSE); | 
|---|
| 5300 | if (text) { | 
|---|
| 5301 | TRACE("%s\n", debugstr_w(text)); | 
|---|
| 5302 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, text, FALSE); | 
|---|
| 5303 | if(!unicode) | 
|---|
| 5304 | HeapFree(GetProcessHeap(), 0, text); | 
|---|
| 5305 | } else { | 
|---|
| 5306 | static const WCHAR empty_stringW[] = {0}; | 
|---|
| 5307 | TRACE("<NULL>\n"); | 
|---|
| 5308 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, empty_stringW, FALSE); | 
|---|
| 5309 | } | 
|---|
| 5310 | es->x_offset = 0; | 
|---|
| 5311 | es->flags &= ~EF_MODIFIED; | 
|---|
| 5312 | EDIT_EM_SetSel(hwnd, es, 0, 0, FALSE); | 
|---|
| 5313 | /* Send the notification after the selection start and end have been set | 
|---|
| 5314 | * edit control doesn't send notification on WM_SETTEXT | 
|---|
| 5315 | * if it is multiline, or it is part of combobox | 
|---|
| 5316 | */ | 
|---|
| 5317 | if( !((es->style & ES_MULTILINE) || es->hwndListBox)) | 
|---|
| 5318 | { | 
|---|
| 5319 | EDIT_NOTIFY_PARENT(hwnd, es, EN_CHANGE, "EN_CHANGE"); | 
|---|
| 5320 | EDIT_NOTIFY_PARENT(hwnd, es, EN_UPDATE, "EN_UPDATE"); | 
|---|
| 5321 | } | 
|---|
| 5322 | EDIT_EM_ScrollCaret(hwnd, es); | 
|---|
| 5323 | } | 
|---|
| 5324 |  | 
|---|
| 5325 |  | 
|---|
| 5326 | /********************************************************************* | 
|---|
| 5327 | * | 
|---|
| 5328 | *  WM_SIZE | 
|---|
| 5329 | * | 
|---|
| 5330 | */ | 
|---|
| 5331 | static void EDIT_WM_Size(HWND hwnd, EDITSTATE *es, UINT action, INT width, INT height) | 
|---|
| 5332 | { | 
|---|
| 5333 | if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) { | 
|---|
| 5334 | RECT rc; | 
|---|
| 5335 | TRACE("width = %d, height = %d\n", width, height); | 
|---|
| 5336 | SetRect(&rc, 0, 0, width, height); | 
|---|
| 5337 | EDIT_SetRectNP(hwnd, es, &rc); | 
|---|
| 5338 | EDIT_UpdateText(hwnd, es, NULL, TRUE); | 
|---|
| 5339 | } | 
|---|
| 5340 | } | 
|---|
| 5341 |  | 
|---|
| 5342 |  | 
|---|
| 5343 | /********************************************************************* | 
|---|
| 5344 | * | 
|---|
| 5345 | *  WM_STYLECHANGED | 
|---|
| 5346 | * | 
|---|
| 5347 | * This message is sent by SetWindowLong on having changed either the Style | 
|---|
| 5348 | * or the extended style. | 
|---|
| 5349 | * | 
|---|
| 5350 | * We ensure that the window's version of the styles and the EDITSTATE's agree. | 
|---|
| 5351 | * | 
|---|
| 5352 | * See also EDIT_WM_NCCreate | 
|---|
| 5353 | * | 
|---|
| 5354 | * It appears that the Windows version of the edit control allows the style | 
|---|
| 5355 | * (as retrieved by GetWindowLong) to be any value and maintains an internal | 
|---|
| 5356 | * style variable which will generally be different.  In this function we | 
|---|
| 5357 | * update the internal style based on what changed in the externally visible | 
|---|
| 5358 | * style. | 
|---|
| 5359 | * | 
|---|
| 5360 | * Much of this content as based upon the MSDN, especially: | 
|---|
| 5361 | *  Platform SDK Documentation -> User Interface Services -> | 
|---|
| 5362 | *      Windows User Interface -> Edit Controls -> Edit Control Reference -> | 
|---|
| 5363 | *      Edit Control Styles | 
|---|
| 5364 | */ | 
|---|
| 5365 | static LRESULT  EDIT_WM_StyleChanged (HWND hwnd, | 
|---|
| 5366 | EDITSTATE *es, | 
|---|
| 5367 | WPARAM which, | 
|---|
| 5368 | const STYLESTRUCT *style) | 
|---|
| 5369 | { | 
|---|
| 5370 | if (GWL_STYLE == which) { | 
|---|
| 5371 | DWORD style_change_mask; | 
|---|
| 5372 | DWORD new_style; | 
|---|
| 5373 | /* Only a subset of changes can be applied after the control | 
|---|
| 5374 | * has been created. | 
|---|
| 5375 | */ | 
|---|
| 5376 | style_change_mask = ES_UPPERCASE | ES_LOWERCASE | | 
|---|
| 5377 | ES_NUMBER; | 
|---|
| 5378 | if (es->style & ES_MULTILINE) | 
|---|
| 5379 | style_change_mask |= ES_WANTRETURN; | 
|---|
| 5380 |  | 
|---|
| 5381 | new_style = style->styleNew & style_change_mask; | 
|---|
| 5382 |  | 
|---|
| 5383 | /* Number overrides lowercase overrides uppercase (at least it | 
|---|
| 5384 | * does in Win95).  However I'll bet that ES_NUMBER would be | 
|---|
| 5385 | * invalid under Win 3.1. | 
|---|
| 5386 | */ | 
|---|
| 5387 | if (new_style & ES_NUMBER) { | 
|---|
| 5388 | ; /* do not override the ES_NUMBER */ | 
|---|
| 5389 | }  else if (new_style & ES_LOWERCASE) { | 
|---|
| 5390 | new_style &= ~ES_UPPERCASE; | 
|---|
| 5391 | } | 
|---|
| 5392 |  | 
|---|
| 5393 | es->style = (es->style & ~style_change_mask) | new_style; | 
|---|
| 5394 | } else if (GWL_EXSTYLE == which) { | 
|---|
| 5395 | ; /* FIXME - what is needed here */ | 
|---|
| 5396 | } else { | 
|---|
| 5397 | WARN ("Invalid style change %d\n",which); | 
|---|
| 5398 | } | 
|---|
| 5399 |  | 
|---|
| 5400 | return 0; | 
|---|
| 5401 | } | 
|---|
| 5402 |  | 
|---|
| 5403 | /********************************************************************* | 
|---|
| 5404 | * | 
|---|
| 5405 | *  WM_SYSKEYDOWN | 
|---|
| 5406 | * | 
|---|
| 5407 | */ | 
|---|
| 5408 | static LRESULT EDIT_WM_SysKeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data) | 
|---|
| 5409 | { | 
|---|
| 5410 | if ((key == VK_BACK) && (key_data & 0x2000)) { | 
|---|
| 5411 | if (EDIT_EM_CanUndo(es)) | 
|---|
| 5412 | EDIT_EM_Undo(hwnd, es); | 
|---|
| 5413 | return 0; | 
|---|
| 5414 | } else if (key == VK_UP || key == VK_DOWN) { | 
|---|
| 5415 | if (EDIT_CheckCombo(hwnd, es, WM_SYSKEYDOWN, key)) | 
|---|
| 5416 | return 0; | 
|---|
| 5417 | } | 
|---|
| 5418 | return DefWindowProcW(hwnd, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data); | 
|---|
| 5419 | } | 
|---|
| 5420 |  | 
|---|
| 5421 |  | 
|---|
| 5422 | /********************************************************************* | 
|---|
| 5423 | * | 
|---|
| 5424 | *  WM_TIMER | 
|---|
| 5425 | * | 
|---|
| 5426 | */ | 
|---|
| 5427 | static void EDIT_WM_Timer(HWND hwnd, EDITSTATE *es) | 
|---|
| 5428 | { | 
|---|
| 5429 | if (es->region_posx < 0) { | 
|---|
| 5430 | EDIT_MoveBackward(hwnd, es, TRUE); | 
|---|
| 5431 | } else if (es->region_posx > 0) { | 
|---|
| 5432 | EDIT_MoveForward(hwnd, es, TRUE); | 
|---|
| 5433 | } | 
|---|
| 5434 | /* | 
|---|
| 5435 | *  FIXME: gotta do some vertical scrolling here, like | 
|---|
| 5436 | *      EDIT_EM_LineScroll(hwnd, 0, 1); | 
|---|
| 5437 | */ | 
|---|
| 5438 | } | 
|---|
| 5439 |  | 
|---|
| 5440 | /********************************************************************* | 
|---|
| 5441 | * | 
|---|
| 5442 | *  WM_VSCROLL | 
|---|
| 5443 | * | 
|---|
| 5444 | */ | 
|---|
| 5445 | static LRESULT EDIT_WM_VScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos) | 
|---|
| 5446 | { | 
|---|
| 5447 | INT dy; | 
|---|
| 5448 |  | 
|---|
| 5449 | if (!(es->style & ES_MULTILINE)) | 
|---|
| 5450 | return 0; | 
|---|
| 5451 |  | 
|---|
| 5452 | if (!(es->style & ES_AUTOVSCROLL)) | 
|---|
| 5453 | return 0; | 
|---|
| 5454 |  | 
|---|
| 5455 | dy = 0; | 
|---|
| 5456 | switch (action) { | 
|---|
| 5457 | case SB_LINEUP: | 
|---|
| 5458 | case SB_LINEDOWN: | 
|---|
| 5459 | case SB_PAGEUP: | 
|---|
| 5460 | case SB_PAGEDOWN: | 
|---|
| 5461 | TRACE("action %d\n", action); | 
|---|
| 5462 | EDIT_EM_Scroll(hwnd, es, action); | 
|---|
| 5463 | return 0; | 
|---|
| 5464 | case SB_TOP: | 
|---|
| 5465 | TRACE("SB_TOP\n"); | 
|---|
| 5466 | dy = -es->y_offset; | 
|---|
| 5467 | break; | 
|---|
| 5468 | case SB_BOTTOM: | 
|---|
| 5469 | TRACE("SB_BOTTOM\n"); | 
|---|
| 5470 | dy = es->line_count - 1 - es->y_offset; | 
|---|
| 5471 | break; | 
|---|
| 5472 | case SB_THUMBTRACK: | 
|---|
| 5473 | TRACE("SB_THUMBTRACK %d\n", pos); | 
|---|
| 5474 | es->flags |= EF_VSCROLL_TRACK; | 
|---|
| 5475 | if(es->style & WS_VSCROLL) | 
|---|
| 5476 | dy = pos - es->y_offset; | 
|---|
| 5477 | else | 
|---|
| 5478 | { | 
|---|
| 5479 | /* Assume default scroll range 0-100 */ | 
|---|
| 5480 | INT vlc, new_y; | 
|---|
| 5481 | /* Sanity check */ | 
|---|
| 5482 | if(pos < 0 || pos > 100) return 0; | 
|---|
| 5483 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 5484 | new_y = pos * (es->line_count - vlc) / 100; | 
|---|
| 5485 | dy = es->line_count ? (new_y - es->y_offset) : 0; | 
|---|
| 5486 | TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n", | 
|---|
| 5487 | es->line_count, es->y_offset, pos, dy); | 
|---|
| 5488 | } | 
|---|
| 5489 | break; | 
|---|
| 5490 | case SB_THUMBPOSITION: | 
|---|
| 5491 | TRACE("SB_THUMBPOSITION %d\n", pos); | 
|---|
| 5492 | es->flags &= ~EF_VSCROLL_TRACK; | 
|---|
| 5493 | if(es->style & WS_VSCROLL) | 
|---|
| 5494 | dy = pos - es->y_offset; | 
|---|
| 5495 | else | 
|---|
| 5496 | { | 
|---|
| 5497 | /* Assume default scroll range 0-100 */ | 
|---|
| 5498 | INT vlc, new_y; | 
|---|
| 5499 | /* Sanity check */ | 
|---|
| 5500 | if(pos < 0 || pos > 100) return 0; | 
|---|
| 5501 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 5502 | new_y = pos * (es->line_count - vlc) / 100; | 
|---|
| 5503 | dy = es->line_count ? (new_y - es->y_offset) : 0; | 
|---|
| 5504 | TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n", | 
|---|
| 5505 | es->line_count, es->y_offset, pos, dy); | 
|---|
| 5506 | } | 
|---|
| 5507 | if (!dy) | 
|---|
| 5508 | { | 
|---|
| 5509 | /* force scroll info update */ | 
|---|
| 5510 | EDIT_UpdateScrollInfo(hwnd, es); | 
|---|
| 5511 | EDIT_NOTIFY_PARENT(hwnd, es, EN_VSCROLL, "EN_VSCROLL"); | 
|---|
| 5512 | } | 
|---|
| 5513 | break; | 
|---|
| 5514 | case SB_ENDSCROLL: | 
|---|
| 5515 | TRACE("SB_ENDSCROLL\n"); | 
|---|
| 5516 | break; | 
|---|
| 5517 | /* | 
|---|
| 5518 | *  FIXME : the next two are undocumented ! | 
|---|
| 5519 | *  Are we doing the right thing ? | 
|---|
| 5520 | *  At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, | 
|---|
| 5521 | *  although it's also a regular control message. | 
|---|
| 5522 | */ | 
|---|
| 5523 | case EM_GETTHUMB: /* this one is used by NT notepad */ | 
|---|
| 5524 | case EM_GETTHUMB16: | 
|---|
| 5525 | { | 
|---|
| 5526 | LRESULT ret; | 
|---|
| 5527 | if(GetWindowLongA( hwnd, GWL_STYLE ) & WS_VSCROLL) | 
|---|
| 5528 | ret = GetScrollPos(hwnd, SB_VERT); | 
|---|
| 5529 | else | 
|---|
| 5530 | { | 
|---|
| 5531 | /* Assume default scroll range 0-100 */ | 
|---|
| 5532 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; | 
|---|
| 5533 | ret = es->line_count ? es->y_offset * 100 / (es->line_count - vlc) : 0; | 
|---|
| 5534 | } | 
|---|
| 5535 | TRACE("EM_GETTHUMB: returning %ld\n", ret); | 
|---|
| 5536 | return ret; | 
|---|
| 5537 | } | 
|---|
| 5538 | case EM_LINESCROLL16: | 
|---|
| 5539 | TRACE("EM_LINESCROLL16 %d\n", pos); | 
|---|
| 5540 | dy = pos; | 
|---|
| 5541 | break; | 
|---|
| 5542 |  | 
|---|
| 5543 | default: | 
|---|
| 5544 | ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n", | 
|---|
| 5545 | action, action); | 
|---|
| 5546 | return 0; | 
|---|
| 5547 | } | 
|---|
| 5548 | if (dy) | 
|---|
| 5549 | EDIT_EM_LineScroll(hwnd, es, 0, dy); | 
|---|
| 5550 | return 0; | 
|---|
| 5551 | } | 
|---|
| 5552 |  | 
|---|
| 5553 | /********************************************************************* | 
|---|
| 5554 | * | 
|---|
| 5555 | *  EDIT_UpdateText | 
|---|
| 5556 | * | 
|---|
| 5557 | */ | 
|---|
| 5558 | static void EDIT_UpdateTextRegion(HWND hwnd, EDITSTATE *es, HRGN hrgn, BOOL bErase) | 
|---|
| 5559 | { | 
|---|
| 5560 | if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(hwnd, es, EN_UPDATE, "EN_UPDATE"); | 
|---|
| 5561 | InvalidateRgn(hwnd, hrgn, bErase); | 
|---|
| 5562 | } | 
|---|
| 5563 |  | 
|---|
| 5564 |  | 
|---|
| 5565 | /********************************************************************* | 
|---|
| 5566 | * | 
|---|
| 5567 | *  EDIT_UpdateText | 
|---|
| 5568 | * | 
|---|
| 5569 | */ | 
|---|
| 5570 | static void EDIT_UpdateText(HWND hwnd, EDITSTATE *es, LPRECT rc, BOOL bErase) | 
|---|
| 5571 | { | 
|---|
| 5572 | if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(hwnd, es, EN_UPDATE, "EN_UPDATE"); | 
|---|
| 5573 | InvalidateRect(hwnd, rc, bErase); | 
|---|
| 5574 | } | 
|---|