4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
11 * please read EDIT.TODO (and update it when you change things)
19 #include "wine/winbase16.h"
22 #include "debugtools.h"
25 #include "winversion.h"
27 DEFAULT_DEBUG_CHANNEL(edit)
28 DECLARE_DEBUG_CHANNEL(combo)
29 DECLARE_DEBUG_CHANNEL(relay)
31 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
32 FIXME: BTW, new specs say 65535 (do you dare ???) */
33 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
34 #define BUFSTART_MULTI 1024 /* starting size */
35 #define BUFSTART_SINGLE 256 /* starting size */
36 #define GROWLENGTH 64 /* buffers grow by this much */
37 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
40 * extra flags for EDITSTATE.flags field
42 #define EF_MODIFIED 0x0001 /* text has been modified */
43 #define EF_FOCUSED 0x0002 /* we have input focus */
44 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
45 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
46 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
47 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
48 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
49 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
50 wrapped line, instead of in front of the next character */
51 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
55 END_0 = 0, /* line ends with terminating '\0' character */
56 END_WRAP, /* line is wrapped */
57 END_HARD, /* line ends with a hard return '\r\n' */
58 END_SOFT /* line ends with a soft return '\r\r\n' */
61 typedef struct tagLINEDEF {
62 INT length; /* bruto length of a line in bytes */
63 INT net_length; /* netto length of a line in visible characters */
65 INT width; /* width of the line in pixels */
66 struct tagLINEDEF *next;
71 HANDLE heap; /* our own heap */
72 LPSTR text; /* the actual contents of the control */
73 INT buffer_size; /* the size of the buffer */
74 INT buffer_limit; /* the maximum size to which the buffer may grow */
75 HFONT font; /* NULL means standard system font */
76 INT x_offset; /* scroll offset for multi lines this is in pixels
77 for single lines it's in characters */
78 INT line_height; /* height of a screen line in pixels */
79 INT char_width; /* average character width in pixels */
80 DWORD style; /* sane version of wnd->dwStyle */
81 WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
82 INT undo_insert_count; /* number of characters inserted in sequence */
83 INT undo_position; /* character index of the insertion and deletion */
84 LPSTR undo_text; /* deleted text */
85 INT undo_buffer_size; /* size of the deleted text buffer */
86 INT selection_start; /* == selection_end if no selection */
87 INT selection_end; /* == current caret position */
88 CHAR password_char; /* == 0 if no password char, and for multi line controls */
89 INT left_margin; /* in pixels */
90 INT right_margin; /* in pixels */
92 INT region_posx; /* Position of cursor relative to region: */
93 INT region_posy; /* -1: to left, 0: within, 1: to right */
94 EDITWORDBREAKPROC16 word_break_proc16;
95 EDITWORDBREAKPROCA word_break_proc32A;
96 INT line_count; /* number of lines */
97 INT y_offset; /* scroll offset in number of lines */
98 BOOL bCaptureState; /* flag indicating whether mouse was captured */
99 BOOL bEnableState; /* flag keeping the enable state */
101 * only for multi line controls
103 INT lock_count; /* amount of re-entries in the EditWndProc */
106 INT text_width; /* width of the widest line in pixels */
107 LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
108 HLOCAL16 hloc16; /* for controls receiving EM_GETHANDLE16 */
109 HLOCAL hloc32; /* for controls receiving EM_GETHANDLE */
113 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
114 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
116 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
117 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
119 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
120 do {TRACE("notification " str " sent to hwnd=%08x\n", \
121 (UINT)(hwnd));} while(0)
123 /* used for disabled or read-only edit control */
124 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
125 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
126 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
127 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
128 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
129 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
130 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
131 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
132 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
133 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
134 (LPARAM)(wnd)->hwndSelf);} while(0)
135 #define DPRINTF_EDIT_MSG16(str) \
137 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
138 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
139 #define DPRINTF_EDIT_MSG32(str) \
141 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
142 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
144 /*********************************************************************
151 * These functions have trivial implementations
152 * We still like to call them internally
153 * "static inline" makes them more like macro's
155 static inline BOOL EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es);
156 static inline void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es);
157 static inline void EDIT_WM_Clear(WND *wnd, EDITSTATE *es);
158 static inline void EDIT_WM_Cut(WND *wnd, EDITSTATE *es);
161 * Helper functions only valid for one type of control
163 static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es);
164 static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es);
165 static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL extend);
166 static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL extend);
167 static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL extend);
168 static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL extend);
170 * Helper functions valid for both single line _and_ multi line controls
172 static INT EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT start, INT index, INT count, INT action);
173 static INT EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
174 static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y);
175 static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
176 static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end);
177 static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es);
178 static BOOL EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT size);
179 static BOOL EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT size);
180 static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL extend);
181 static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL extend);
182 static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL extend);
183 static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL extend);
184 static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL extend);
185 static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL extend);
186 static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC hdc, INT line, BOOL rev);
187 static INT EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev);
188 static void EDIT_SetCaretPos(WND *wnd, EDITSTATE *es, INT pos, BOOL after_wrap);
189 static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT lprc);
190 static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL force);
191 static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action);
193 * EM_XXX message handlers
195 static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y);
196 static BOOL EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL add_eol);
197 static HLOCAL EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es);
198 static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es);
199 static INT EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT line, LPSTR lpch);
200 static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT start, LPUINT end);
201 static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es);
202 static INT EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT index);
203 static INT EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT line);
204 static INT EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT index);
205 static BOOL EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT dx, INT dy);
206 static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT index, BOOL after_wrap);
207 static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace);
208 static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT action);
209 static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es);
210 static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL hloc);
211 static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc);
212 static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT limit);
213 static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT action, INT left, INT right);
214 static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c);
215 static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap);
216 static BOOL EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT count, LPINT tabs);
217 static BOOL EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT count, LPINT16 tabs);
218 static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp);
219 static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp);
220 static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es);
222 * WM_XXX message handlers
224 static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data);
225 static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT code, INT id, HWND conrtol);
226 static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND hwnd, INT x, INT y);
227 static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es);
228 static LRESULT EDIT_WM_Create(WND *wnd, EDITSTATE *es, LPCREATESTRUCTA cs);
229 static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es);
230 static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC dc);
231 static INT EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT count, LPSTR text);
232 static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar);
233 static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data);
234 static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND window_getting_focus);
235 static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
236 static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
237 static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
238 static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
239 static LRESULT EDIT_WM_NCCreate(WND *wnd, LPCREATESTRUCTA cs);
240 static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es, WPARAM wParam);
241 static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es);
242 static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND window_losing_focus);
243 static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT font, BOOL redraw);
244 static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text);
245 static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT action, INT width, INT height);
246 static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data);
247 static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT id, TIMERPROC timer_proc);
248 static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar);
251 /*********************************************************************
256 static inline BOOL EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es)
258 return (es->undo_insert_count || lstrlenA(es->undo_text));
262 /*********************************************************************
267 static inline void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es)
269 es->undo_insert_count = 0;
270 *es->undo_text = '\0';
274 /*********************************************************************
279 static inline void EDIT_WM_Clear(WND *wnd, EDITSTATE *es)
281 EDIT_EM_ReplaceSel(wnd, es, TRUE, "");
285 /*********************************************************************
290 static inline void EDIT_WM_Cut(WND *wnd, EDITSTATE *es)
292 EDIT_WM_Copy(wnd, es);
293 EDIT_WM_Clear(wnd, es);
297 /*********************************************************************
301 * The messages are in the order of the actual integer values
302 * (which can be found in include/windows.h)
303 * Whereever possible the 16 bit versions are converted to
304 * the 32 bit ones, so that we can 'fall through' to the
305 * helper functions. These are mostly 32 bit (with a few
306 * exceptions, clearly indicated by a '16' extension to their
310 LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg,
311 WPARAM wParam, LPARAM lParam )
313 WND *wnd = WIN_FindWndPtr(hwnd);
314 EDITSTATE *es = *(EDITSTATE **)((wnd)->wExtra);
319 DPRINTF_EDIT_MSG32("WM_DESTROY");
320 EDIT_WM_Destroy(wnd, es);
325 DPRINTF_EDIT_MSG32("WM_NCCREATE");
326 result = EDIT_WM_NCCreate(wnd, (LPCREATESTRUCTA)lParam);
332 result = DefWindowProcA(hwnd, msg, wParam, lParam);
337 EDIT_LockBuffer(wnd, es);
340 DPRINTF_EDIT_MSG16("EM_GETSEL");
345 DPRINTF_EDIT_MSG32("EM_GETSEL");
346 result = EDIT_EM_GetSel(wnd, es, (LPUINT)wParam, (LPUINT)lParam);
350 DPRINTF_EDIT_MSG16("EM_SETSEL");
351 if (SLOWORD(lParam) == -1)
352 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
354 EDIT_EM_SetSel(wnd, es, LOWORD(lParam), HIWORD(lParam), FALSE);
356 EDIT_EM_ScrollCaret(wnd, es);
360 DPRINTF_EDIT_MSG32("EM_SETSEL");
361 EDIT_EM_SetSel(wnd, es, wParam, lParam, FALSE);
362 EDIT_EM_ScrollCaret(wnd, es);
367 DPRINTF_EDIT_MSG16("EM_GETRECT");
369 CONV_RECT32TO16(&es->format_rect, (LPRECT16)PTR_SEG_TO_LIN(lParam));
372 DPRINTF_EDIT_MSG32("EM_GETRECT");
374 CopyRect((LPRECT)lParam, &es->format_rect);
378 DPRINTF_EDIT_MSG16("EM_SETRECT");
379 if ((es->style & ES_MULTILINE) && lParam) {
381 CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc);
382 EDIT_SetRectNP(wnd, es, &rc);
383 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
387 DPRINTF_EDIT_MSG32("EM_SETRECT");
388 if ((es->style & ES_MULTILINE) && lParam) {
389 EDIT_SetRectNP(wnd, es, (LPRECT)lParam);
390 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
395 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
396 if ((es->style & ES_MULTILINE) && lParam) {
398 CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc);
399 EDIT_SetRectNP(wnd, es, &rc);
403 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
404 if ((es->style & ES_MULTILINE) && lParam)
405 EDIT_SetRectNP(wnd, es, (LPRECT)lParam);
409 DPRINTF_EDIT_MSG16("EM_SCROLL");
412 DPRINTF_EDIT_MSG32("EM_SCROLL");
413 result = EDIT_EM_Scroll(wnd, es, (INT)wParam);
416 case EM_LINESCROLL16:
417 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
418 wParam = (WPARAM)(INT)SHIWORD(lParam);
419 lParam = (LPARAM)(INT)SLOWORD(lParam);
422 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
423 result = (LRESULT)EDIT_EM_LineScroll(wnd, es, (INT)wParam, (INT)lParam);
426 case EM_SCROLLCARET16:
427 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
430 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
431 EDIT_EM_ScrollCaret(wnd, es);
436 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
439 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
440 result = ((es->flags & EF_MODIFIED) != 0);
444 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
447 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
449 es->flags |= EF_MODIFIED;
451 es->flags &= ~(EF_MODIFIED | EF_UPDATE); /* reset pending updates */
454 case EM_GETLINECOUNT16:
455 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
457 case EM_GETLINECOUNT:
458 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
459 result = (es->style & ES_MULTILINE) ? es->line_count : 1;
463 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
464 if ((INT16)wParam == -1)
468 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
469 result = (LRESULT)EDIT_EM_LineIndex(wnd, es, (INT)wParam);
473 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
474 EDIT_EM_SetHandle16(wnd, es, (HLOCAL16)wParam);
477 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
478 EDIT_EM_SetHandle(wnd, es, (HLOCAL)wParam);
482 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
483 result = (LRESULT)EDIT_EM_GetHandle16(wnd, es);
486 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
487 result = (LRESULT)EDIT_EM_GetHandle(wnd, es);
491 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
494 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
495 result = EDIT_EM_GetThumb(wnd, es);
498 /* messages 0x00bf and 0x00c0 missing from specs */
501 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
504 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
505 result = DefWindowProcA(hwnd, msg, wParam, lParam);
509 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
512 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
513 result = DefWindowProcA(hwnd, msg, wParam, lParam);
516 case EM_LINELENGTH16:
517 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
520 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
521 result = (LRESULT)EDIT_EM_LineLength(wnd, es, (INT)wParam);
524 case EM_REPLACESEL16:
525 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
526 lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam);
529 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
530 EDIT_EM_ReplaceSel(wnd, es, (BOOL)wParam, (LPCSTR)lParam);
534 /* message 0x00c3 missing from specs */
537 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
540 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
541 result = DefWindowProcA(hwnd, msg, wParam, lParam);
545 DPRINTF_EDIT_MSG16("EM_GETLINE");
546 lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam);
549 DPRINTF_EDIT_MSG32("EM_GETLINE");
550 result = (LRESULT)EDIT_EM_GetLine(wnd, es, (INT)wParam, (LPSTR)lParam);
554 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
556 case EM_SETLIMITTEXT:
557 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
558 EDIT_EM_SetLimitText(wnd, es, (INT)wParam);
562 DPRINTF_EDIT_MSG16("EM_CANUNDO");
565 DPRINTF_EDIT_MSG32("EM_CANUNDO");
566 result = (LRESULT)EDIT_EM_CanUndo(wnd, es);
570 DPRINTF_EDIT_MSG16("EM_UNDO");
575 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
576 result = (LRESULT)EDIT_EM_Undo(wnd, es);
580 DPRINTF_EDIT_MSG16("EM_FMTLINES");
583 DPRINTF_EDIT_MSG32("EM_FMTLINES");
584 result = (LRESULT)EDIT_EM_FmtLines(wnd, es, (BOOL)wParam);
587 case EM_LINEFROMCHAR16:
588 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
590 case EM_LINEFROMCHAR:
591 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
592 result = (LRESULT)EDIT_EM_LineFromChar(wnd, es, (INT)wParam);
595 /* message 0x00ca missing from specs */
598 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
601 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
602 result = DefWindowProcA(hwnd, msg, wParam, lParam);
605 case EM_SETTABSTOPS16:
606 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
607 result = (LRESULT)EDIT_EM_SetTabStops16(wnd, es, (INT)wParam, (LPINT16)PTR_SEG_TO_LIN((SEGPTR)lParam));
610 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
611 result = (LRESULT)EDIT_EM_SetTabStops(wnd, es, (INT)wParam, (LPINT)lParam);
614 case EM_SETPASSWORDCHAR16:
615 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
617 case EM_SETPASSWORDCHAR:
618 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
619 EDIT_EM_SetPasswordChar(wnd, es, (CHAR)wParam);
622 case EM_EMPTYUNDOBUFFER16:
623 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
625 case EM_EMPTYUNDOBUFFER:
626 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
627 EDIT_EM_EmptyUndoBuffer(wnd, es);
630 case EM_GETFIRSTVISIBLELINE16:
631 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
632 result = es->y_offset;
634 case EM_GETFIRSTVISIBLELINE:
635 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
636 result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
639 case EM_SETREADONLY16:
640 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
643 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
645 wnd->dwStyle |= ES_READONLY;
646 es->style |= ES_READONLY;
648 wnd->dwStyle &= ~ES_READONLY;
649 es->style &= ~ES_READONLY;
654 case EM_SETWORDBREAKPROC16:
655 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
656 EDIT_EM_SetWordBreakProc16(wnd, es, (EDITWORDBREAKPROC16)lParam);
658 case EM_SETWORDBREAKPROC:
659 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
660 EDIT_EM_SetWordBreakProc(wnd, es, (EDITWORDBREAKPROCA)lParam);
663 case EM_GETWORDBREAKPROC16:
664 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
665 result = (LRESULT)es->word_break_proc16;
667 case EM_GETWORDBREAKPROC:
668 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
669 result = (LRESULT)es->word_break_proc32A;
672 case EM_GETPASSWORDCHAR16:
673 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
675 case EM_GETPASSWORDCHAR:
676 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
677 result = es->password_char;
680 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
683 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
684 EDIT_EM_SetMargins(wnd, es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam));
688 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
689 result = MAKELONG(es->left_margin, es->right_margin);
692 case EM_GETLIMITTEXT:
693 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
694 result = es->buffer_limit;
698 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
699 result = EDIT_EM_PosFromChar(wnd, es, (INT)wParam, FALSE);
703 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
704 result = EDIT_EM_CharFromPos(wnd, es, SLOWORD(lParam), SHIWORD(lParam));
708 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
709 result = (es->style & ES_MULTILINE) ?
710 DLGC_WANTALLKEYS | DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS :
711 DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
715 DPRINTF_EDIT_MSG32("WM_CHAR");
716 EDIT_WM_Char(wnd, es, (CHAR)wParam, (DWORD)lParam);
720 DPRINTF_EDIT_MSG32("WM_CLEAR");
721 EDIT_WM_Clear(wnd, es);
725 DPRINTF_EDIT_MSG32("WM_COMMAND");
726 EDIT_WM_Command(wnd, es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
730 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
731 EDIT_WM_ContextMenu(wnd, es, (HWND)wParam, SLOWORD(lParam), SHIWORD(lParam));
735 DPRINTF_EDIT_MSG32("WM_COPY");
736 EDIT_WM_Copy(wnd, es);
740 DPRINTF_EDIT_MSG32("WM_CREATE");
741 result = EDIT_WM_Create(wnd, es, (LPCREATESTRUCTA)lParam);
745 DPRINTF_EDIT_MSG32("WM_CUT");
746 EDIT_WM_Cut(wnd, es);
750 DPRINTF_EDIT_MSG32("WM_ENABLE");
751 es->bEnableState = (BOOL) wParam;
752 InvalidateRect(hwnd, NULL, TRUE);
756 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
757 result = EDIT_WM_EraseBkGnd(wnd, es, (HDC)wParam);
761 DPRINTF_EDIT_MSG32("WM_GETFONT");
762 result = (LRESULT)es->font;
766 DPRINTF_EDIT_MSG32("WM_GETTEXT");
767 result = (LRESULT)EDIT_WM_GetText(wnd, es, (INT)wParam, (LPSTR)lParam);
770 case WM_GETTEXTLENGTH:
771 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
772 result = lstrlenA(es->text);
776 DPRINTF_EDIT_MSG32("WM_HSCROLL");
777 result = EDIT_WM_HScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)lParam);
781 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
782 result = EDIT_WM_KeyDown(wnd, es, (INT)wParam, (DWORD)lParam);
786 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
787 result = EDIT_WM_KillFocus(wnd, es, (HWND)wParam);
790 case WM_LBUTTONDBLCLK:
791 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
792 result = EDIT_WM_LButtonDblClk(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
796 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
797 result = EDIT_WM_LButtonDown(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
801 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
802 result = EDIT_WM_LButtonUp(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
805 case WM_MOUSEACTIVATE:
807 * FIXME: maybe DefWindowProc() screws up, but it seems that
808 * modalless dialog boxes need this. If we don't do this, the focus
809 * will _not_ be set by DefWindowProc() for edit controls in a
810 * modalless dialog box ???
812 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
813 SetFocus(wnd->hwndSelf);
814 result = MA_ACTIVATE;
819 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
821 result = EDIT_WM_MouseMove(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
825 DPRINTF_EDIT_MSG32("WM_PAINT");
826 EDIT_WM_Paint(wnd, es, wParam);
830 DPRINTF_EDIT_MSG32("WM_PASTE");
831 EDIT_WM_Paste(wnd, es);
835 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
836 EDIT_WM_SetFocus(wnd, es, (HWND)wParam);
840 DPRINTF_EDIT_MSG32("WM_SETFONT");
841 EDIT_WM_SetFont(wnd, es, (HFONT)wParam, LOWORD(lParam) != 0);
845 DPRINTF_EDIT_MSG32("WM_SETTEXT");
846 EDIT_WM_SetText(wnd, es, (LPCSTR)lParam);
851 DPRINTF_EDIT_MSG32("WM_SIZE");
852 EDIT_WM_Size(wnd, es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam));
856 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
857 result = EDIT_WM_SysKeyDown(wnd, es, (INT)wParam, (DWORD)lParam);
861 DPRINTF_EDIT_MSG32("WM_TIMER");
862 EDIT_WM_Timer(wnd, es, (INT)wParam, (TIMERPROC)lParam);
866 DPRINTF_EDIT_MSG32("WM_VSCROLL");
867 result = EDIT_WM_VScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)(lParam));
871 result = DefWindowProcA(hwnd, msg, wParam, lParam);
874 EDIT_UnlockBuffer(wnd, es, FALSE);
876 WIN_ReleaseWndPtr(wnd);
882 /*********************************************************************
884 * EDIT_BuildLineDefs_ML
886 * Build linked list of text lines.
887 * Lines can end with '\0' (last line), a character (if it is wrapped),
888 * a soft return '\r\r\n' or a hard return '\r\n'
891 static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es)
897 LINEDEF *current_def;
898 LINEDEF **previous_next;
900 current_def = es->first_line_def;
902 LINEDEF *next_def = current_def->next;
903 HeapFree(es->heap, 0, current_def);
904 current_def = next_def;
905 } while (current_def);
909 dc = GetDC(wnd->hwndSelf);
911 old_font = SelectObject(dc, es->font);
913 fw = es->format_rect.right - es->format_rect.left;
915 previous_next = &es->first_line_def;
917 current_def = HeapAlloc(es->heap, 0, sizeof(LINEDEF));
918 current_def->next = NULL;
921 if ((*cp == '\r') && (*(cp + 1) == '\n'))
926 current_def->ending = END_0;
927 current_def->net_length = lstrlenA(start);
928 } else if ((cp > start) && (*(cp - 1) == '\r')) {
929 current_def->ending = END_SOFT;
930 current_def->net_length = cp - start - 1;
932 current_def->ending = END_HARD;
933 current_def->net_length = cp - start;
935 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
936 start, current_def->net_length,
937 es->tabs_count, es->tabs));
938 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
939 if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) {
944 next = EDIT_CallWordBreakProc(wnd, es, start - es->text,
945 prev + 1, current_def->net_length, WB_RIGHT);
946 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
947 start, next, es->tabs_count, es->tabs));
948 } while (current_def->width <= fw);
954 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
955 start, next, es->tabs_count, es->tabs));
956 } while (current_def->width <= fw);
960 current_def->net_length = prev;
961 current_def->ending = END_WRAP;
962 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, start,
963 current_def->net_length, es->tabs_count, es->tabs));
965 switch (current_def->ending) {
967 current_def->length = current_def->net_length + 3;
970 current_def->length = current_def->net_length + 2;
974 current_def->length = current_def->net_length;
977 es->text_width = MAX(es->text_width, current_def->width);
978 start += current_def->length;
979 *previous_next = current_def;
980 previous_next = ¤t_def->next;
982 } while (current_def->ending != END_0);
984 SelectObject(dc, old_font);
985 ReleaseDC(wnd->hwndSelf, dc);
989 /*********************************************************************
991 * EDIT_CallWordBreakProc
993 * Call appropriate WordBreakProc (internal or external).
995 * Note: The "start" argument should always be an index refering
996 * to es->text. The actual wordbreak proc might be
997 * 16 bit, so we can't always pass any 32 bit LPSTR.
998 * Hence we assume that es->text is the buffer that holds
999 * the string under examination (we can decide this for ourselves).
1002 static INT EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT start, INT index, INT count, INT action)
1004 if (es->word_break_proc16) {
1005 HLOCAL16 hloc16 = EDIT_EM_GetHandle16(wnd, es);
1006 SEGPTR segptr = LocalLock16(hloc16);
1007 INT ret = (INT)Callbacks->CallWordBreakProc(es->word_break_proc16,
1008 segptr + start, index, count, action);
1009 LocalUnlock16(hloc16);
1012 else if (es->word_break_proc32A)
1014 TRACE_(relay)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1015 es->word_break_proc32A, es->text + start, index,
1017 return (INT)es->word_break_proc32A( es->text + start, index,
1021 return EDIT_WordBreakProc(es->text + start, index, count, action);
1025 /*********************************************************************
1029 * Beware: This is not the function called on EM_CHARFROMPOS
1030 * The position _can_ be outside the formatting / client
1032 * The return value is only the character index
1035 static INT EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
1041 if (es->style & ES_MULTILINE) {
1042 INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1044 LINEDEF *line_def = es->first_line_def;
1046 while ((line > 0) && line_def->next) {
1047 line_index += line_def->length;
1048 line_def = line_def->next;
1051 x += es->x_offset - es->format_rect.left;
1052 if (x >= line_def->width) {
1054 *after_wrap = (line_def->ending == END_WRAP);
1055 return line_index + line_def->net_length;
1059 *after_wrap = FALSE;
1062 dc = GetDC(wnd->hwndSelf);
1064 old_font = SelectObject(dc, es->font);
1065 low = line_index + 1;
1066 high = line_index + line_def->net_length + 1;
1067 while (low < high - 1)
1069 INT mid = (low + high) / 2;
1070 if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
1076 *after_wrap = ((index == line_index + line_def->net_length) &&
1077 (line_def->ending == END_WRAP));
1082 *after_wrap = FALSE;
1083 x -= es->format_rect.left;
1085 return es->x_offset;
1086 text = EDIT_GetPasswordPointer_SL(wnd, es);
1087 dc = GetDC(wnd->hwndSelf);
1089 old_font = SelectObject(dc, es->font);
1093 INT high = es->x_offset;
1094 while (low < high - 1)
1096 INT mid = (low + high) / 2;
1097 GetTextExtentPoint32A( dc, text + mid,
1098 es->x_offset - mid, &size );
1099 if (size.cx > -x) low = mid;
1106 INT low = es->x_offset;
1107 INT high = lstrlenA(es->text) + 1;
1108 while (low < high - 1)
1110 INT mid = (low + high) / 2;
1111 GetTextExtentPoint32A( dc, text + es->x_offset,
1112 mid - es->x_offset, &size );
1113 if (size.cx > x) high = mid;
1118 if (es->style & ES_PASSWORD)
1119 HeapFree(es->heap, 0 ,text);
1122 SelectObject(dc, old_font);
1123 ReleaseDC(wnd->hwndSelf, dc);
1128 /*********************************************************************
1132 * adjusts the point to be within the formatting rectangle
1133 * (so CharFromPos returns the nearest _visible_ character)
1136 static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y)
1138 *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1);
1139 *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1);
1143 /*********************************************************************
1147 * Calculates the bounding rectangle for a line from a starting
1148 * column to an ending column.
1151 static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
1153 INT line_index = EDIT_EM_LineIndex(wnd, es, line);
1155 if (es->style & ES_MULTILINE)
1156 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1158 rc->top = es->format_rect.top;
1159 rc->bottom = rc->top + es->line_height;
1160 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE));
1161 rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + ecol, TRUE));
1165 /*********************************************************************
1167 * EDIT_GetPasswordPointer_SL
1169 * note: caller should free the (optionally) allocated buffer
1172 static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es)
1174 if (es->style & ES_PASSWORD) {
1175 INT len = lstrlenA(es->text);
1176 LPSTR text = HeapAlloc(es->heap, 0, len + 1);
1177 RtlFillMemory(text, len, es->password_char);
1185 /*********************************************************************
1189 * This acts as a LOCAL_Lock(), but it locks only once. This way
1190 * you can call it whenever you like, without unlocking.
1193 static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es)
1196 ERR("no EDITSTATE ... please report\n");
1199 if (!(es->style & ES_MULTILINE))
1203 es->text = LocalLock(es->hloc32);
1204 else if (es->hloc16)
1205 es->text = LOCAL_Lock(wnd->hInstance, es->hloc16);
1207 ERR("no buffer ... please report\n");
1215 /*********************************************************************
1217 * EDIT_SL_InvalidateText
1219 * Called from EDIT_InvalidateText().
1220 * Does the job for single-line controls only.
1223 static void EDIT_SL_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end)
1228 EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect);
1229 if (IntersectRect(&rc, &line_rect, &es->format_rect))
1230 InvalidateRect(wnd->hwndSelf, &rc, FALSE);
1234 /*********************************************************************
1236 * EDIT_ML_InvalidateText
1238 * Called from EDIT_InvalidateText().
1239 * Does the job for multi-line controls only.
1242 static void EDIT_ML_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end)
1244 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1245 INT sl = EDIT_EM_LineFromChar(wnd, es, start);
1246 INT el = EDIT_EM_LineFromChar(wnd, es, end);
1255 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1258 sc = start - EDIT_EM_LineIndex(wnd, es, sl);
1259 ec = end - EDIT_EM_LineIndex(wnd, es, el);
1260 if (sl < es->y_offset) {
1264 if (el > es->y_offset + vlc) {
1265 el = es->y_offset + vlc;
1266 ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el));
1268 GetClientRect(wnd->hwndSelf, &rc1);
1269 IntersectRect(&rcWnd, &rc1, &es->format_rect);
1271 EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine);
1272 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1273 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1275 EDIT_GetLineRect(wnd, es, sl, sc,
1276 EDIT_EM_LineLength(wnd, es,
1277 EDIT_EM_LineIndex(wnd, es, sl)),
1279 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1280 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1281 for (l = sl + 1 ; l < el ; l++) {
1282 EDIT_GetLineRect(wnd, es, l, 0,
1283 EDIT_EM_LineLength(wnd, es,
1284 EDIT_EM_LineIndex(wnd, es, l)),
1286 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1287 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1289 EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine);
1290 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1291 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1296 /*********************************************************************
1298 * EDIT_InvalidateText
1300 * Invalidate the text from offset start upto, but not including,
1301 * offset end. Useful for (re)painting the selection.
1302 * Regions outside the linewidth are not invalidated.
1303 * end == -1 means end == TextLength.
1304 * start and end need not be ordered.
1307 static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end)
1313 end = lstrlenA(es->text);
1315 ORDER_INT(start, end);
1317 if (es->style & ES_MULTILINE)
1318 EDIT_ML_InvalidateText(wnd, es, start, end);
1320 EDIT_SL_InvalidateText(wnd, es, start, end);
1324 /*********************************************************************
1328 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1331 static BOOL EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT size)
1336 if (size <= es->buffer_size)
1338 if (size > es->buffer_limit) {
1339 EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT");
1342 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
1343 if (size > es->buffer_limit)
1344 size = es->buffer_limit;
1346 TRACE("trying to ReAlloc to %d+1\n", size);
1348 EDIT_UnlockBuffer(wnd, es, TRUE);
1350 if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1)))
1351 es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
1353 es->buffer_size = 0;
1354 } else if (es->hloc32) {
1355 if ((hNew32 = LocalReAlloc(es->hloc32, size + 1, 0))) {
1356 TRACE("Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32);
1357 es->hloc32 = hNew32;
1358 es->buffer_size = MIN(LocalSize(es->hloc32) - 1, es->buffer_limit);
1360 } else if (es->hloc16) {
1361 if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) {
1362 TRACE("Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16);
1363 es->hloc16 = hNew16;
1364 es->buffer_size = MIN(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit);
1367 if (es->buffer_size < size) {
1368 EDIT_LockBuffer(wnd, es);
1369 WARN("FAILED ! We now have %d+1\n", es->buffer_size);
1370 EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE");
1373 EDIT_LockBuffer(wnd, es);
1374 TRACE("We now have %d+1\n", es->buffer_size);
1380 /*********************************************************************
1384 * Try to fit size + 1 bytes in the undo buffer.
1387 static BOOL EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT size)
1389 if (size <= es->undo_buffer_size)
1391 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
1393 TRACE("trying to ReAlloc to %d+1\n", size);
1395 if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) {
1396 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
1397 if (es->undo_buffer_size < size) {
1398 WARN("FAILED ! We now have %d+1\n", es->undo_buffer_size);
1407 /*********************************************************************
1412 static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL extend)
1414 INT e = es->selection_end;
1418 if ((es->style & ES_MULTILINE) && e &&
1419 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1421 if (e && (es->text[e - 1] == '\r'))
1425 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1426 EDIT_EM_ScrollCaret(wnd, es);
1430 /*********************************************************************
1434 * Only for multi line controls
1435 * Move the caret one line down, on a column with the nearest
1436 * x coordinate on the screen (might be a different column).
1439 static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1441 INT s = es->selection_start;
1442 INT e = es->selection_end;
1443 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1444 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1445 INT x = SLOWORD(pos);
1446 INT y = SHIWORD(pos);
1448 e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap);
1451 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1452 EDIT_EM_ScrollCaret(wnd, es);
1456 /*********************************************************************
1461 static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL extend)
1463 BOOL after_wrap = FALSE;
1466 /* Pass a high value in x to make sure of receiving the en of the line */
1467 if (es->style & ES_MULTILINE)
1468 e = EDIT_CharFromPos(wnd, es, 0x3fffffff,
1469 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1471 e = lstrlenA(es->text);
1472 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap);
1473 EDIT_EM_ScrollCaret(wnd, es);
1477 /*********************************************************************
1482 static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL extend)
1484 INT e = es->selection_end;
1488 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1489 if (es->text[e] == '\n')
1491 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1495 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1496 EDIT_EM_ScrollCaret(wnd, es);
1500 /*********************************************************************
1504 * Home key: move to beginning of line.
1507 static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL extend)
1511 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1512 if (es->style & ES_MULTILINE)
1513 e = EDIT_CharFromPos(wnd, es, -es->x_offset,
1514 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1517 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1518 EDIT_EM_ScrollCaret(wnd, es);
1522 /*********************************************************************
1524 * EDIT_MovePageDown_ML
1526 * Only for multi line controls
1527 * Move the caret one page down, on a column with the nearest
1528 * x coordinate on the screen (might be a different column).
1531 static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1533 INT s = es->selection_start;
1534 INT e = es->selection_end;
1535 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1536 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1537 INT x = SLOWORD(pos);
1538 INT y = SHIWORD(pos);
1540 e = EDIT_CharFromPos(wnd, es, x,
1541 y + (es->format_rect.bottom - es->format_rect.top),
1545 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1546 EDIT_EM_ScrollCaret(wnd, es);
1550 /*********************************************************************
1552 * EDIT_MovePageUp_ML
1554 * Only for multi line controls
1555 * Move the caret one page up, on a column with the nearest
1556 * x coordinate on the screen (might be a different column).
1559 static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1561 INT s = es->selection_start;
1562 INT e = es->selection_end;
1563 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1564 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1565 INT x = SLOWORD(pos);
1566 INT y = SHIWORD(pos);
1568 e = EDIT_CharFromPos(wnd, es, x,
1569 y - (es->format_rect.bottom - es->format_rect.top),
1573 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1574 EDIT_EM_ScrollCaret(wnd, es);
1578 /*********************************************************************
1582 * Only for multi line controls
1583 * Move the caret one line up, on a column with the nearest
1584 * x coordinate on the screen (might be a different column).
1587 static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1589 INT s = es->selection_start;
1590 INT e = es->selection_end;
1591 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1592 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1593 INT x = SLOWORD(pos);
1594 INT y = SHIWORD(pos);
1596 e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap);
1599 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1600 EDIT_EM_ScrollCaret(wnd, es);
1604 /*********************************************************************
1606 * EDIT_MoveWordBackward
1609 static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL extend)
1611 INT s = es->selection_start;
1612 INT e = es->selection_end;
1617 l = EDIT_EM_LineFromChar(wnd, es, e);
1618 ll = EDIT_EM_LineLength(wnd, es, e);
1619 li = EDIT_EM_LineIndex(wnd, es, l);
1622 li = EDIT_EM_LineIndex(wnd, es, l - 1);
1623 e = li + EDIT_EM_LineLength(wnd, es, li);
1626 e = li + (INT)EDIT_CallWordBreakProc(wnd, es,
1627 li, e - li, ll, WB_LEFT);
1631 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1632 EDIT_EM_ScrollCaret(wnd, es);
1636 /*********************************************************************
1638 * EDIT_MoveWordForward
1641 static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL extend)
1643 INT s = es->selection_start;
1644 INT e = es->selection_end;
1649 l = EDIT_EM_LineFromChar(wnd, es, e);
1650 ll = EDIT_EM_LineLength(wnd, es, e);
1651 li = EDIT_EM_LineIndex(wnd, es, l);
1653 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
1654 e = EDIT_EM_LineIndex(wnd, es, l + 1);
1656 e = li + EDIT_CallWordBreakProc(wnd, es,
1657 li, e - li + 1, ll, WB_RIGHT);
1661 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1662 EDIT_EM_ScrollCaret(wnd, es);
1666 /*********************************************************************
1671 static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC dc, INT line, BOOL rev)
1673 INT s = es->selection_start;
1674 INT e = es->selection_end;
1681 if (es->style & ES_MULTILINE) {
1682 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1683 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
1688 TRACE("line=%d\n", line);
1690 pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE);
1693 li = EDIT_EM_LineIndex(wnd, es, line);
1694 ll = EDIT_EM_LineLength(wnd, es, li);
1695 s = es->selection_start;
1696 e = es->selection_end;
1698 s = MIN(li + ll, MAX(li, s));
1699 e = MIN(li + ll, MAX(li, e));
1700 if (rev && (s != e) &&
1701 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
1702 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE);
1703 x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE);
1704 x += EDIT_PaintText(wnd, es, dc, x, y, line, e - li, li + ll - e, FALSE);
1706 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE);
1710 /*********************************************************************
1715 static INT EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
1725 BkColor = GetBkColor(dc);
1726 TextColor = GetTextColor(dc);
1728 SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
1729 SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1731 li = EDIT_EM_LineIndex(wnd, es, line);
1732 if (es->style & ES_MULTILINE) {
1733 ret = (INT)LOWORD(TabbedTextOutA(dc, x, y, es->text + li + col, count,
1734 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
1736 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
1737 TextOutA(dc, x, y, text + li + col, count);
1738 GetTextExtentPoint32A(dc, text + li + col, count, &size);
1740 if (es->style & ES_PASSWORD)
1741 HeapFree(es->heap, 0, text);
1744 SetBkColor(dc, BkColor);
1745 SetTextColor(dc, TextColor);
1751 /*********************************************************************
1756 static void EDIT_SetCaretPos(WND *wnd, EDITSTATE *es, INT pos,
1759 LRESULT res = EDIT_EM_PosFromChar(wnd, es, pos, after_wrap);
1760 INT x = SLOWORD(res);
1761 INT y = SHIWORD(res);
1763 if(x < es->format_rect.left)
1764 x = es->format_rect.left;
1765 if(x > es->format_rect.right - 2)
1766 x = es->format_rect.right - 2;
1767 if(y > es->format_rect.bottom)
1768 y = es->format_rect.bottom;
1769 if(y < es->format_rect.top)
1770 y = es->format_rect.top;
1776 /*********************************************************************
1780 * note: this is not (exactly) the handler called on EM_SETRECTNP
1781 * it is also used to set the rect of a single line control
1784 static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT rc)
1786 CopyRect(&es->format_rect, rc);
1787 if (es->style & WS_BORDER) {
1788 INT bw = GetSystemMetrics(SM_CXBORDER) + 1;
1789 if(TWEAK_WineLook == WIN31_LOOK)
1791 es->format_rect.left += bw;
1792 es->format_rect.top += bw;
1793 es->format_rect.right -= bw;
1794 es->format_rect.bottom -= bw;
1796 es->format_rect.left += es->left_margin;
1797 es->format_rect.right -= es->right_margin;
1798 es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width);
1799 if (es->style & ES_MULTILINE)
1800 es->format_rect.bottom = es->format_rect.top +
1801 MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
1803 es->format_rect.bottom = es->format_rect.top + es->line_height;
1804 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
1805 EDIT_BuildLineDefs_ML(wnd, es);
1809 /*********************************************************************
1814 static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL force)
1817 ERR("no EDITSTATE ... please report\n");
1820 if (!(es->style & ES_MULTILINE))
1822 if (!es->lock_count) {
1823 ERR("lock_count == 0 ... please report\n");
1827 ERR("es->text == 0 ... please report\n");
1830 if (force || (es->lock_count == 1)) {
1832 LocalUnlock(es->hloc32);
1834 } else if (es->hloc16) {
1835 LOCAL_Unlock(wnd->hInstance, es->hloc16);
1843 /*********************************************************************
1845 * EDIT_WordBreakProc
1847 * Find the beginning of words.
1848 * Note: unlike the specs for a WordBreakProc, this function only
1849 * allows to be called without linebreaks between s[0] upto
1850 * s[count - 1]. Remember it is only called
1851 * internally, so we can decide this for ourselves.
1854 static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action)
1858 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1859 s, index, count, action);
1867 if (s[index] == ' ') {
1868 while (index && (s[index] == ' '))
1871 while (index && (s[index] != ' '))
1873 if (s[index] == ' ')
1877 while (index && (s[index] != ' '))
1879 if (s[index] == ' ')
1889 if (s[index] == ' ')
1890 while ((index < count) && (s[index] == ' ')) index++;
1892 while (s[index] && (s[index] != ' ') && (index < count))
1894 while ((s[index] == ' ') && (index < count)) index++;
1898 case WB_ISDELIMITER:
1899 ret = (s[index] == ' ');
1902 ERR("unknown action code, please report !\n");
1909 /*********************************************************************
1913 * returns line number (not index) in high-order word of result.
1914 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1915 * to Richedit, not to the edit control. Original documentation is valid.
1916 * FIXME: do the specs mean to return -1 if outside client area or
1917 * if outside formatting rectangle ???
1920 static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y)
1928 GetClientRect(wnd->hwndSelf, &rc);
1929 if (!PtInRect(&rc, pt))
1932 index = EDIT_CharFromPos(wnd, es, x, y, NULL);
1933 return MAKELONG(index, EDIT_EM_LineFromChar(wnd, es, index));
1937 /*********************************************************************
1941 * Enable or disable soft breaks.
1943 static BOOL EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL add_eol)
1945 es->flags &= ~EF_USE_SOFTBRK;
1947 es->flags |= EF_USE_SOFTBRK;
1948 FIXME("soft break enabled, not implemented\n");
1954 /*********************************************************************
1958 * Hopefully this won't fire back at us.
1959 * We always start with a fixed buffer in our own heap.
1960 * However, with this message a 32 bit application requests
1961 * a handle to 32 bit moveable local heap memory, where it expects
1963 * It's a pity that from this moment on we have to use this
1964 * local heap, because applications may rely on the handle
1967 * In this function we'll try to switch to local heap.
1970 static HLOCAL EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es)
1976 if (!(es->style & ES_MULTILINE))
1981 else if (es->hloc16)
1982 return (HLOCAL)es->hloc16;
1984 if (!(newBuf = LocalAlloc(LMEM_MOVEABLE, lstrlenA(es->text) + 1))) {
1985 ERR("could not allocate new 32 bit buffer\n");
1988 newSize = MIN(LocalSize(newBuf) - 1, es->buffer_limit);
1989 if (!(newText = LocalLock(newBuf))) {
1990 ERR("could not lock new 32 bit buffer\n");
1994 lstrcpyA(newText, es->text);
1995 EDIT_UnlockBuffer(wnd, es, TRUE);
1997 HeapFree(es->heap, 0, es->text);
1998 es->hloc32 = newBuf;
1999 es->hloc16 = (HLOCAL16)NULL;
2000 es->buffer_size = newSize;
2002 EDIT_LockBuffer(wnd, es);
2003 TRACE("switched to 32 bit local heap\n");
2009 /*********************************************************************
2013 * Hopefully this won't fire back at us.
2014 * We always start with a buffer in 32 bit linear memory.
2015 * However, with this message a 16 bit application requests
2016 * a handle of 16 bit local heap memory, where it expects to find
2018 * It's a pitty that from this moment on we have to use this
2019 * local heap, because applications may rely on the handle
2022 * In this function we'll try to switch to local heap.
2024 static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es)
2030 if (!(es->style & ES_MULTILINE))
2036 if (!LOCAL_HeapSize(wnd->hInstance)) {
2037 if (!LocalInit16(wnd->hInstance, 0,
2038 GlobalSize16(wnd->hInstance))) {
2039 ERR("could not initialize local heap\n");
2042 TRACE("local heap initialized\n");
2044 if (!(newBuf = LOCAL_Alloc(wnd->hInstance, LMEM_MOVEABLE, lstrlenA(es->text) + 1))) {
2045 ERR("could not allocate new 16 bit buffer\n");
2048 newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit);
2049 if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) {
2050 ERR("could not lock new 16 bit buffer\n");
2051 LOCAL_Free(wnd->hInstance, newBuf);
2054 lstrcpyA(newText, es->text);
2055 EDIT_UnlockBuffer(wnd, es, TRUE);
2057 HeapFree(es->heap, 0, es->text);
2058 else if (es->hloc32) {
2059 while (LocalFree(es->hloc32)) ;
2060 LocalFree(es->hloc32);
2062 es->hloc32 = (HLOCAL)NULL;
2063 es->hloc16 = newBuf;
2064 es->buffer_size = newSize;
2066 EDIT_LockBuffer(wnd, es);
2067 TRACE("switched to 16 bit buffer\n");
2073 /*********************************************************************
2078 static INT EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT line, LPSTR lpch)
2084 if (es->style & ES_MULTILINE) {
2085 if (line >= es->line_count)
2089 i = EDIT_EM_LineIndex(wnd, es, line);
2091 len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, i));
2092 for (i = 0 ; i < len ; i++) {
2097 return (LRESULT)len;
2101 /*********************************************************************
2106 static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT start, LPUINT end)
2108 UINT s = es->selection_start;
2109 UINT e = es->selection_end;
2116 return MAKELONG(s, e);
2120 /*********************************************************************
2124 * FIXME: is this right ? (or should it be only VSCROLL)
2125 * (and maybe only for edit controls that really have their
2126 * own scrollbars) (and maybe only for multiline controls ?)
2127 * All in all: very poorly documented
2129 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2130 * WM_VSCROLL handlers
2133 static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es)
2135 return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB16, 0, 0),
2136 EDIT_WM_HScroll(wnd, es, EM_GETTHUMB16, 0, 0));
2140 /*********************************************************************
2145 static INT EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT index)
2150 if (!(es->style & ES_MULTILINE))
2152 if (index > lstrlenA(es->text))
2153 return es->line_count - 1;
2155 index = MIN(es->selection_start, es->selection_end);
2158 line_def = es->first_line_def;
2159 index -= line_def->length;
2160 while ((index >= 0) && line_def->next) {
2162 line_def = line_def->next;
2163 index -= line_def->length;
2169 /*********************************************************************
2174 static INT EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT line)
2179 if (!(es->style & ES_MULTILINE))
2181 if (line >= es->line_count)
2185 line_def = es->first_line_def;
2187 INT index = es->selection_end - line_def->length;
2188 while ((index >= 0) && line_def->next) {
2189 line_index += line_def->length;
2190 line_def = line_def->next;
2191 index -= line_def->length;
2195 line_index += line_def->length;
2196 line_def = line_def->next;
2204 /*********************************************************************
2209 static INT EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT index)
2213 if (!(es->style & ES_MULTILINE))
2214 return lstrlenA(es->text);
2218 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2219 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2220 return es->selection_start - es->line_defs[sl].offset +
2221 es->line_defs[el].offset +
2222 es->line_defs[el].length - es->selection_end;
2226 line_def = es->first_line_def;
2227 index -= line_def->length;
2228 while ((index >= 0) && line_def->next) {
2229 line_def = line_def->next;
2230 index -= line_def->length;
2232 return line_def->net_length;
2236 /*********************************************************************
2240 * FIXME: dx is in average character widths
2241 * However, we assume it is in pixels when we use this
2242 * function internally
2245 static BOOL EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT dx, INT dy)
2249 if (!(es->style & ES_MULTILINE))
2252 if (-dx > es->x_offset)
2254 if (dx > es->text_width - es->x_offset)
2255 dx = es->text_width - es->x_offset;
2256 nyoff = MAX(0, es->y_offset + dy);
2257 if (nyoff >= es->line_count)
2258 nyoff = es->line_count - 1;
2259 dy = (es->y_offset - nyoff) * es->line_height;
2263 GetClientRect(wnd->hwndSelf, &rc1);
2264 IntersectRect(&rc, &rc1, &es->format_rect);
2265 ScrollWindowEx(wnd->hwndSelf, -dx, dy,
2266 NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE);
2267 es->y_offset = nyoff;
2270 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2271 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
2272 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2273 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
2278 /*********************************************************************
2283 static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT index, BOOL after_wrap)
2285 INT len = lstrlenA(es->text);
2294 index = MIN(index, len);
2295 dc = GetDC(wnd->hwndSelf);
2297 old_font = SelectObject(dc, es->font);
2298 if (es->style & ES_MULTILINE) {
2299 l = EDIT_EM_LineFromChar(wnd, es, index);
2300 y = (l - es->y_offset) * es->line_height;
2301 li = EDIT_EM_LineIndex(wnd, es, l);
2302 if (after_wrap && (li == index) && l) {
2304 LINEDEF *line_def = es->first_line_def;
2306 line_def = line_def->next;
2309 if (line_def->ending == END_WRAP) {
2311 y -= es->line_height;
2312 li = EDIT_EM_LineIndex(wnd, es, l);
2315 x = LOWORD(GetTabbedTextExtentA(dc, es->text + li, index - li,
2316 es->tabs_count, es->tabs)) - es->x_offset;
2318 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
2319 if (index < es->x_offset) {
2320 GetTextExtentPoint32A(dc, text + index,
2321 es->x_offset - index, &size);
2324 GetTextExtentPoint32A(dc, text + es->x_offset,
2325 index - es->x_offset, &size);
2329 if (es->style & ES_PASSWORD)
2330 HeapFree(es->heap, 0 ,text);
2332 x += es->format_rect.left;
2333 y += es->format_rect.top;
2335 SelectObject(dc, old_font);
2336 ReleaseDC(wnd->hwndSelf, dc);
2337 return MAKELONG((INT16)x, (INT16)y);
2341 /*********************************************************************
2345 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2348 static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace)
2350 INT strl = lstrlenA(lpsz_replace);
2351 INT tl = lstrlenA(es->text);
2358 s = es->selection_start;
2359 e = es->selection_end;
2361 if ((s == e) && !strl)
2366 if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl))
2370 /* there is something to be deleted */
2372 utl = lstrlenA(es->undo_text);
2373 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
2374 /* undo-buffer is extended to the right */
2375 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2376 lstrcpynA(es->undo_text + utl, es->text + s, e - s + 1);
2377 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
2378 /* undo-buffer is extended to the left */
2379 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2380 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
2382 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2383 p[i] = (es->text + s)[i];
2384 es->undo_position = s;
2386 /* new undo-buffer */
2387 EDIT_MakeUndoFit(wnd, es, e - s);
2388 lstrcpynA(es->undo_text, es->text + s, e - s + 1);
2389 es->undo_position = s;
2391 /* any deletion makes the old insertion-undo invalid */
2392 es->undo_insert_count = 0;
2394 EDIT_EM_EmptyUndoBuffer(wnd, es);
2397 lstrcpyA(es->text + s, es->text + e);
2400 /* there is an insertion */
2402 if ((s == es->undo_position) ||
2403 ((es->undo_insert_count) &&
2404 (s == es->undo_position + es->undo_insert_count)))
2406 * insertion is new and at delete position or
2407 * an extension to either left or right
2409 es->undo_insert_count += strl;
2411 /* new insertion undo */
2412 es->undo_position = s;
2413 es->undo_insert_count = strl;
2414 /* new insertion makes old delete-buffer invalid */
2415 *es->undo_text = '\0';
2418 EDIT_EM_EmptyUndoBuffer(wnd, es);
2421 tl = lstrlenA(es->text);
2422 for (p = es->text + tl ; p >= es->text + s ; p--)
2424 for (i = 0 , p = es->text + s ; i < strl ; i++)
2425 p[i] = lpsz_replace[i];
2426 if(es->style & ES_UPPERCASE)
2427 CharUpperBuffA(p, strl);
2428 else if(es->style & ES_LOWERCASE)
2429 CharLowerBuffA(p, strl);
2432 /* FIXME: really inefficient */
2433 if (es->style & ES_MULTILINE)
2434 EDIT_BuildLineDefs_ML(wnd, es);
2436 EDIT_EM_SetSel(wnd, es, s, s, FALSE);
2437 es->flags |= EF_MODIFIED;
2438 es->flags |= EF_UPDATE;
2439 EDIT_EM_ScrollCaret(wnd, es);
2441 EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE");
2443 /* FIXME: really inefficient */
2444 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2448 /*********************************************************************
2453 static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT action)
2457 if (!(es->style & ES_MULTILINE))
2458 return (LRESULT)FALSE;
2468 if (es->y_offset < es->line_count - 1)
2473 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
2476 if (es->y_offset < es->line_count - 1)
2477 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2480 return (LRESULT)FALSE;
2483 EDIT_EM_LineScroll(wnd, es, 0, dy);
2484 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
2486 return MAKELONG((INT16)dy, (BOOL16)TRUE);
2490 /*********************************************************************
2495 static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es)
2497 if (es->style & ES_MULTILINE) {
2502 INT cw = es->char_width;
2507 l = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2508 li = EDIT_EM_LineIndex(wnd, es, l);
2509 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP));
2510 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2511 if (l >= es->y_offset + vlc)
2512 dy = l - vlc + 1 - es->y_offset;
2513 if (l < es->y_offset)
2514 dy = l - es->y_offset;
2515 ww = es->format_rect.right - es->format_rect.left;
2516 if (x < es->format_rect.left)
2517 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
2518 if (x > es->format_rect.right)
2519 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
2521 EDIT_EM_LineScroll(wnd, es, dx, dy);
2527 if (!(es->style & ES_AUTOHSCROLL))
2530 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
2531 format_width = es->format_rect.right - es->format_rect.left;
2532 if (x < es->format_rect.left) {
2533 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
2536 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
2537 } while ((x < goal) && es->x_offset);
2538 /* FIXME: use ScrollWindow() somehow to improve performance */
2539 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2540 } else if (x > es->format_rect.right) {
2542 INT len = lstrlenA(es->text);
2543 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
2546 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
2547 x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE));
2548 } while ((x > goal) && (x_last > es->format_rect.right));
2549 /* FIXME: use ScrollWindow() somehow to improve performance */
2550 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2556 /*********************************************************************
2560 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2563 static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL hloc)
2565 if (!(es->style & ES_MULTILINE))
2569 WARN("called with NULL handle\n");
2573 EDIT_UnlockBuffer(wnd, es, TRUE);
2575 * old buffer is freed by caller, unless
2576 * it is still in our own heap. (in that case
2577 * we free it, correcting the buggy caller.)
2580 HeapFree(es->heap, 0, es->text);
2582 es->hloc16 = (HLOCAL16)NULL;
2585 es->buffer_size = LocalSize(es->hloc32) - 1;
2586 EDIT_LockBuffer(wnd, es);
2588 es->x_offset = es->y_offset = 0;
2589 es->selection_start = es->selection_end = 0;
2590 EDIT_EM_EmptyUndoBuffer(wnd, es);
2591 es->flags &= ~EF_MODIFIED;
2592 es->flags &= ~EF_UPDATE;
2593 EDIT_BuildLineDefs_ML(wnd, es);
2594 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2595 EDIT_EM_ScrollCaret(wnd, es);
2599 /*********************************************************************
2603 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2606 static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc)
2608 if (!(es->style & ES_MULTILINE))
2612 WARN("called with NULL handle\n");
2616 EDIT_UnlockBuffer(wnd, es, TRUE);
2618 * old buffer is freed by caller, unless
2619 * it is still in our own heap. (in that case
2620 * we free it, correcting the buggy caller.)
2623 HeapFree(es->heap, 0, es->text);
2626 es->hloc32 = (HLOCAL)NULL;
2628 es->buffer_size = LOCAL_Size(wnd->hInstance, es->hloc16) - 1;
2629 EDIT_LockBuffer(wnd, es);
2631 es->x_offset = es->y_offset = 0;
2632 es->selection_start = es->selection_end = 0;
2633 EDIT_EM_EmptyUndoBuffer(wnd, es);
2634 es->flags &= ~EF_MODIFIED;
2635 es->flags &= ~EF_UPDATE;
2636 EDIT_BuildLineDefs_ML(wnd, es);
2637 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2638 EDIT_EM_ScrollCaret(wnd, es);
2642 /*********************************************************************
2646 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2647 * However, the windows version is not complied to yet in all of edit.c
2650 static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT limit)
2652 if (es->style & ES_MULTILINE) {
2654 es->buffer_limit = MIN(limit, BUFLIMIT_MULTI);
2656 es->buffer_limit = BUFLIMIT_MULTI;
2659 es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE);
2661 es->buffer_limit = BUFLIMIT_SINGLE;
2666 /*********************************************************************
2670 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2671 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2672 * of the char's width, according to the new docs.
2675 static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT action,
2676 INT left, INT right)
2678 if (action & EC_LEFTMARGIN) {
2679 if (left != EC_USEFONTINFO)
2680 es->left_margin = left;
2682 es->left_margin = es->char_width / 3;
2685 if (action & EC_RIGHTMARGIN) {
2686 if (right != EC_USEFONTINFO)
2687 es->right_margin = right;
2689 es->right_margin = es->char_width / 3;
2691 TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin);
2695 /*********************************************************************
2697 * EM_SETPASSWORDCHAR
2700 static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c)
2702 if (es->style & ES_MULTILINE)
2705 if (es->password_char == c)
2708 es->password_char = c;
2710 wnd->dwStyle |= ES_PASSWORD;
2711 es->style |= ES_PASSWORD;
2713 wnd->dwStyle &= ~ES_PASSWORD;
2714 es->style &= ~ES_PASSWORD;
2716 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2720 /*********************************************************************
2724 * note: unlike the specs say: the order of start and end
2725 * _is_ preserved in Windows. (i.e. start can be > end)
2726 * In other words: this handler is OK
2729 static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
2731 UINT old_start = es->selection_start;
2732 UINT old_end = es->selection_end;
2733 UINT len = lstrlenA(es->text);
2736 start = es->selection_end;
2737 end = es->selection_end;
2739 start = MIN(start, len);
2740 end = MIN(end, len);
2742 es->selection_start = start;
2743 es->selection_end = end;
2745 es->flags |= EF_AFTER_WRAP;
2747 es->flags &= ~EF_AFTER_WRAP;
2748 if (es->flags & EF_FOCUSED)
2749 EDIT_SetCaretPos(wnd, es, end, after_wrap);
2750 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2751 ORDER_UINT(start, end);
2752 ORDER_UINT(end, old_end);
2753 ORDER_UINT(start, old_start);
2754 ORDER_UINT(old_start, old_end);
2755 if (end != old_start)
2759 * ORDER_UINT32(end, old_start);
2760 * EDIT_InvalidateText(wnd, es, start, end);
2761 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2762 * in place of the following if statement.
2764 if (old_start > end )
2766 EDIT_InvalidateText(wnd, es, start, end);
2767 EDIT_InvalidateText(wnd, es, old_start, old_end);
2771 EDIT_InvalidateText(wnd, es, start, old_start);
2772 EDIT_InvalidateText(wnd, es, end, old_end);
2775 else EDIT_InvalidateText(wnd, es, start, old_end);
2779 /*********************************************************************
2784 static BOOL EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT count, LPINT tabs)
2786 if (!(es->style & ES_MULTILINE))
2789 HeapFree(es->heap, 0, es->tabs);
2790 es->tabs_count = count;
2794 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT));
2795 memcpy(es->tabs, tabs, count * sizeof(INT));
2801 /*********************************************************************
2806 static BOOL EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT count, LPINT16 tabs)
2808 if (!(es->style & ES_MULTILINE))
2811 HeapFree(es->heap, 0, es->tabs);
2812 es->tabs_count = count;
2817 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT));
2818 for (i = 0 ; i < count ; i++)
2819 es->tabs[i] = *tabs++;
2825 /*********************************************************************
2827 * EM_SETWORDBREAKPROC
2830 static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp)
2832 if (es->word_break_proc32A == wbp)
2835 es->word_break_proc32A = wbp;
2836 es->word_break_proc16 = NULL;
2837 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2838 EDIT_BuildLineDefs_ML(wnd, es);
2839 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2844 /*********************************************************************
2846 * EM_SETWORDBREAKPROC16
2849 static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
2851 if (es->word_break_proc16 == wbp)
2854 es->word_break_proc32A = NULL;
2855 es->word_break_proc16 = wbp;
2856 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2857 EDIT_BuildLineDefs_ML(wnd, es);
2858 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2863 /*********************************************************************
2868 static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es)
2870 INT ulength = lstrlenA(es->undo_text);
2871 LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1);
2873 lstrcpyA(utext, es->undo_text);
2875 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2876 es->undo_insert_count, utext);
2878 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2879 EDIT_EM_EmptyUndoBuffer(wnd, es);
2880 EDIT_EM_ReplaceSel(wnd, es, TRUE, utext);
2881 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2882 HeapFree(es->heap, 0, utext);
2884 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2885 es->undo_insert_count, es->undo_text);
2891 /*********************************************************************
2896 static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data)
2898 BOOL control = GetKeyState(VK_CONTROL) & 0x8000;
2901 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2902 if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
2905 if (es->style & ES_MULTILINE) {
2906 if (es->style & ES_READONLY) {
2907 EDIT_MoveHome(wnd, es, FALSE);
2908 EDIT_MoveDown_ML(wnd, es, FALSE);
2910 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n");
2914 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
2915 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t");
2918 if (!(es->style & ES_READONLY) && !control) {
2919 if (es->selection_start != es->selection_end)
2920 EDIT_WM_Clear(wnd, es);
2922 /* delete character left of caret */
2923 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
2924 EDIT_MoveBackward(wnd, es, TRUE);
2925 EDIT_WM_Clear(wnd, es);
2930 if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) {
2934 EDIT_EM_ReplaceSel(wnd, es, TRUE, str);
2941 /*********************************************************************
2946 static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT code, INT id, HWND control)
2948 if (code || control)
2953 EDIT_EM_Undo(wnd, es);
2956 EDIT_WM_Cut(wnd, es);
2959 EDIT_WM_Copy(wnd, es);
2962 EDIT_WM_Paste(wnd, es);
2965 EDIT_WM_Clear(wnd, es);
2968 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
2969 EDIT_EM_ScrollCaret(wnd, es);
2972 ERR("unknown menu item, please report\n");
2978 /*********************************************************************
2982 * Note: the resource files resource/sysres_??.rc cannot define a
2983 * single popup menu. Hence we use a (dummy) menubar
2984 * containing the single popup menu as its first item.
2986 * FIXME: the message identifiers have been chosen arbitrarily,
2987 * hence we use MF_BYPOSITION.
2988 * We might as well use the "real" values (anybody knows ?)
2989 * The menu definition is in resources/sysres_??.rc.
2990 * Once these are OK, we better use MF_BYCOMMAND here
2991 * (as we do in EDIT_WM_Command()).
2994 static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND hwnd, INT x, INT y)
2996 HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
2997 HMENU popup = GetSubMenu(menu, 0);
2998 UINT start = es->selection_start;
2999 UINT end = es->selection_end;
3001 ORDER_UINT(start, end);
3004 EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(wnd, es) ? MF_ENABLED : MF_GRAYED));
3006 EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
3008 EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
3010 EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
3012 EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED));
3014 EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != lstrlenA(es->text)) ? MF_ENABLED : MF_GRAYED));
3016 TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL);
3021 /*********************************************************************
3026 static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es)
3028 INT s = es->selection_start;
3029 INT e = es->selection_end;
3036 hdst = GlobalAlloc(GMEM_MOVEABLE, (DWORD)(e - s + 1));
3037 dst = GlobalLock(hdst);
3038 lstrcpynA(dst, es->text + s, e - s + 1);
3040 OpenClipboard(wnd->hwndSelf);
3042 SetClipboardData(CF_TEXT, hdst);
3047 /*********************************************************************
3052 static LRESULT EDIT_WM_Create(WND *wnd, EDITSTATE *es, LPCREATESTRUCTA cs)
3055 * To initialize some final structure members, we call some helper
3056 * functions. However, since the EDITSTATE is not consistent (i.e.
3057 * not fully initialized), we should be very careful which
3058 * functions can be called, and in what order.
3060 EDIT_WM_SetFont(wnd, es, 0, FALSE);
3061 EDIT_EM_EmptyUndoBuffer(wnd, es);
3063 if (cs->lpszName && *(cs->lpszName) != '\0') {
3064 EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName);
3065 /* if we insert text to the editline, the text scrolls out
3066 * of the window, as the caret is placed after the insert
3067 * pos normally; thus we reset es->selection... to 0 and
3070 es->selection_start = es->selection_end = 0;
3071 EDIT_EM_ScrollCaret(wnd, es);
3077 /*********************************************************************
3082 static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es)
3085 while (LocalUnlock(es->hloc32)) ;
3086 LocalFree(es->hloc32);
3089 while (LOCAL_Unlock(wnd->hInstance, es->hloc16)) ;
3090 LOCAL_Free(wnd->hInstance, es->hloc16);
3092 HeapDestroy(es->heap);
3093 HeapFree(GetProcessHeap(), 0, es);
3094 *(EDITSTATE **)wnd->wExtra = NULL;
3098 /*********************************************************************
3103 static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC dc)
3108 if ( VERSION_AppWinVer() >= 0x40000 &&(
3109 !es->bEnableState || (es->style & ES_READONLY)))
3110 brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(wnd, dc);
3112 brush = (HBRUSH)EDIT_SEND_CTLCOLOR(wnd, dc);
3115 brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
3117 GetClientRect(wnd->hwndSelf, &rc);
3118 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
3119 GetClipBox(dc, &rc);
3121 * FIXME: specs say that we should UnrealizeObject() the brush,
3122 * but the specs of UnrealizeObject() say that we shouldn't
3123 * unrealize a stock object. The default brush that
3124 * DefWndProc() returns is ... a stock object.
3126 FillRect(dc, &rc, brush);
3131 /*********************************************************************
3136 static INT EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT count, LPSTR text)
3138 INT len = lstrlenA(es->text);
3141 lstrcpyA(text, es->text);
3148 /*********************************************************************
3152 * 16 bit notepad needs this. Actually it is not _our_ hack,
3153 * it is notepad's. Notepad is sending us scrollbar messages with
3154 * undocumented parameters without us even having a scrollbar ... !?!?
3157 static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3160 INT fw = es->format_rect.right - es->format_rect.left;
3163 if (!(es->flags & EF_HSCROLL_HACK)) {
3164 ERR("hacked WM_HSCROLL handler invoked\n");
3165 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3166 ERR(" (this message is only displayed once per edit control)\n");
3167 es->flags |= EF_HSCROLL_HACK;
3173 dx = -es->char_width;
3176 if (es->x_offset < es->text_width)
3177 dx = es->char_width;
3181 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3184 if (es->x_offset < es->text_width)
3185 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3192 if (es->x_offset < es->text_width)
3193 dx = es->text_width - es->x_offset;
3196 es->flags |= EF_HSCROLL_TRACK;
3197 dx = pos * es->text_width / 100 - es->x_offset;
3199 case SB_THUMBPOSITION:
3200 es->flags &= ~EF_HSCROLL_TRACK;
3201 if (!(dx = pos * es->text_width / 100 - es->x_offset))
3202 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3208 * FIXME : the next two are undocumented !
3209 * Are we doing the right thing ?
3210 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3211 * although it's also a regular control message.
3214 ret = es->text_width ? es->x_offset * 100 / es->text_width : 0;
3216 case EM_LINESCROLL16:
3221 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3225 EDIT_EM_LineScroll(wnd, es, dx, 0);
3230 /*********************************************************************
3235 static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3240 if (!(es->style & ES_MULTILINE))
3243 if (!(es->style & ES_AUTOHSCROLL))
3246 if (!(es->style & WS_HSCROLL))
3247 return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar);
3250 fw = es->format_rect.right - es->format_rect.left;
3254 dx = -es->char_width;
3257 if (es->x_offset < es->text_width)
3258 dx = es->char_width;
3262 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3265 if (es->x_offset < es->text_width)
3266 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3273 if (es->x_offset < es->text_width)
3274 dx = es->text_width - es->x_offset;
3277 es->flags |= EF_HSCROLL_TRACK;
3278 dx = pos - es->x_offset;
3280 case SB_THUMBPOSITION:
3281 es->flags &= ~EF_HSCROLL_TRACK;
3282 if (!(dx = pos - es->x_offset)) {
3283 SetScrollPos(wnd->hwndSelf, SB_HORZ, pos, TRUE);
3284 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3291 ERR("undocumented WM_HSCROLL parameter, please report\n");
3295 EDIT_EM_LineScroll(wnd, es, dx, 0);
3300 /*********************************************************************
3305 static BOOL EDIT_CheckCombo(WND *wnd, UINT msg, INT key, DWORD key_data)
3309 if (WIDGETS_IsControl(wnd->parent, BIC32_COMBO) &&
3310 (hLBox = COMBO_GetLBWindow(wnd->parent))) {
3311 HWND hCombo = wnd->parent->hwndSelf;
3312 BOOL bUIFlip = TRUE;
3314 TRACE_(combo)("[%04x]: handling msg %04x (%04x)\n",
3315 wnd->hwndSelf, (UINT16)msg, (UINT16)key);
3318 case WM_KEYDOWN: /* Handle F4 and arrow keys */
3320 bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0);
3321 if (SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0))
3325 SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
3327 /* make sure ComboLBox pops up */
3328 SendMessageA(hCombo, CB_SETEXTENDEDUI, 0, 0);
3329 SendMessageA(hLBox, WM_KEYDOWN, VK_F4, 0);
3330 SendMessageA(hCombo, CB_SETEXTENDEDUI, 1, 0);
3333 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
3334 bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0);
3336 bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0);
3337 SendMessageA(hCombo, CB_SHOWDROPDOWN, (bUIFlip) ? FALSE : TRUE, 0);
3339 SendMessageA(hLBox, WM_KEYDOWN, VK_F4, 0);
3348 /*********************************************************************
3352 * Handling of special keys that don't produce a WM_CHAR
3353 * (i.e. non-printable keys) & Backspace & Delete
3356 static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data)
3361 if (GetKeyState(VK_MENU) & 0x8000)
3364 shift = GetKeyState(VK_SHIFT) & 0x8000;
3365 control = GetKeyState(VK_CONTROL) & 0x8000;
3370 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3376 if ((es->style & ES_MULTILINE) && (key == VK_UP))
3377 EDIT_MoveUp_ML(wnd, es, shift);
3380 EDIT_MoveWordBackward(wnd, es, shift);
3382 EDIT_MoveBackward(wnd, es, shift);
3385 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3389 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
3390 EDIT_MoveDown_ML(wnd, es, shift);
3392 EDIT_MoveWordForward(wnd, es, shift);
3394 EDIT_MoveForward(wnd, es, shift);
3397 EDIT_MoveHome(wnd, es, shift);
3400 EDIT_MoveEnd(wnd, es, shift);
3403 if (es->style & ES_MULTILINE)
3404 EDIT_MovePageUp_ML(wnd, es, shift);
3407 if (es->style & ES_MULTILINE)
3408 EDIT_MovePageDown_ML(wnd, es, shift);
3411 if (!(es->style & ES_READONLY) && !(shift && control)) {
3412 if (es->selection_start != es->selection_end) {
3414 EDIT_WM_Cut(wnd, es);
3416 EDIT_WM_Clear(wnd, es);
3419 /* delete character left of caret */
3420 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3421 EDIT_MoveBackward(wnd, es, TRUE);
3422 EDIT_WM_Clear(wnd, es);
3423 } else if (control) {
3424 /* delete to end of line */
3425 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3426 EDIT_MoveEnd(wnd, es, TRUE);
3427 EDIT_WM_Clear(wnd, es);
3429 /* delete character right of caret */
3430 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3431 EDIT_MoveForward(wnd, es, TRUE);
3432 EDIT_WM_Clear(wnd, es);
3439 if (!(es->style & ES_READONLY))
3440 EDIT_WM_Paste(wnd, es);
3442 EDIT_WM_Copy(wnd, es);
3445 /* If the edit doesn't want the return send a message to the default object */
3446 if(!(es->style & ES_WANTRETURN))
3448 HWND hwndParent = GetParent(wnd->hwndSelf);
3449 DWORD dw = SendMessage16( hwndParent, DM_GETDEFID, 0, 0 );
3450 if (HIWORD(dw) == DC_HASDEFID)
3452 SendMessageA( hwndParent, WM_COMMAND,
3453 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
3454 (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
3463 /*********************************************************************
3468 static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND window_getting_focus)
3470 es->flags &= ~EF_FOCUSED;
3472 if(!(es->style & ES_NOHIDESEL))
3473 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3474 EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS");
3479 /*********************************************************************
3483 * The caret position has been set on the WM_LBUTTONDOWN message
3486 static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3489 INT e = es->selection_end;
3494 if (!(es->flags & EF_FOCUSED))
3497 l = EDIT_EM_LineFromChar(wnd, es, e);
3498 li = EDIT_EM_LineIndex(wnd, es, l);
3499 ll = EDIT_EM_LineLength(wnd, es, e);
3500 s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT);
3501 e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT);
3502 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
3503 EDIT_EM_ScrollCaret(wnd, es);
3508 /*********************************************************************
3513 static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3518 if (!(es->flags & EF_FOCUSED))
3521 es->bCaptureState = TRUE;
3522 SetCapture(wnd->hwndSelf);
3523 EDIT_ConfinePoint(wnd, es, &x, &y);
3524 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3525 EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
3526 EDIT_EM_ScrollCaret(wnd, es);
3527 es->region_posx = es->region_posy = 0;
3528 SetTimer(wnd->hwndSelf, 0, 100, NULL);
3533 /*********************************************************************
3538 static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3540 if (es->bCaptureState && GetCapture() == wnd->hwndSelf) {
3541 KillTimer(wnd->hwndSelf, 0);
3544 es->bCaptureState = FALSE;
3549 /*********************************************************************
3554 static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3560 if (GetCapture() != wnd->hwndSelf)
3564 * FIXME: gotta do some scrolling if outside client
3565 * area. Maybe reset the timer ?
3568 EDIT_ConfinePoint(wnd, es, &x, &y);
3569 es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
3570 es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
3571 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3572 EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap);
3577 /*********************************************************************
3582 static LRESULT EDIT_WM_NCCreate(WND *wnd, LPCREATESTRUCTA cs)
3586 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
3588 *(EDITSTATE **)wnd->wExtra = es;
3591 * Note: since the EDITSTATE has not been fully initialized yet,
3592 * we can't use any API calls that may send
3593 * WM_XXX messages before WM_NCCREATE is completed.
3596 if (!(es->heap = HeapCreate(0, 0x10000, 0)))
3598 es->style = cs->style;
3600 es->bEnableState = !(cs->style & WS_DISABLED);
3603 * In Win95 look and feel, the WS_BORDER style is replaced by the
3604 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3605 * control a non client area.
3607 if (TWEAK_WineLook != WIN31_LOOK)
3609 if (es->style & WS_BORDER)
3611 es->style &= ~WS_BORDER;
3612 wnd->dwStyle &= ~WS_BORDER;
3613 wnd->dwExStyle |= WS_EX_CLIENTEDGE;
3618 if ((es->style & WS_BORDER) && !(es->style & WS_DLGFRAME))
3619 wnd->dwStyle &= ~WS_BORDER;
3622 if (es->style & ES_MULTILINE) {
3623 es->buffer_size = BUFSTART_MULTI;
3624 es->buffer_limit = BUFLIMIT_MULTI;
3625 if (es->style & WS_VSCROLL)
3626 es->style |= ES_AUTOVSCROLL;
3627 if (es->style & WS_HSCROLL)
3628 es->style |= ES_AUTOHSCROLL;
3629 es->style &= ~ES_PASSWORD;
3630 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
3631 if (es->style & ES_RIGHT)
3632 es->style &= ~ES_CENTER;
3633 es->style &= ~WS_HSCROLL;
3634 es->style &= ~ES_AUTOHSCROLL;
3637 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3638 es->style |= ES_AUTOVSCROLL;
3640 es->buffer_size = BUFSTART_SINGLE;
3641 es->buffer_limit = BUFLIMIT_SINGLE;
3642 es->style &= ~ES_CENTER;
3643 es->style &= ~ES_RIGHT;
3644 es->style &= ~WS_HSCROLL;
3645 es->style &= ~WS_VSCROLL;
3646 es->style &= ~ES_AUTOVSCROLL;
3647 es->style &= ~ES_WANTRETURN;
3648 if (es->style & ES_UPPERCASE) {
3649 es->style &= ~ES_LOWERCASE;
3650 es->style &= ~ES_NUMBER;
3651 } else if (es->style & ES_LOWERCASE)
3652 es->style &= ~ES_NUMBER;
3653 if (es->style & ES_PASSWORD)
3654 es->password_char = '*';
3656 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3657 es->style |= ES_AUTOHSCROLL;
3659 if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3661 es->buffer_size = HeapSize(es->heap, 0, es->text) - 1;
3662 if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3664 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
3666 if (es->style & ES_MULTILINE)
3667 if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
3674 /*********************************************************************
3679 static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es, WPARAM wParam)
3688 BOOL rev = es->bEnableState &&
3689 ((es->flags & EF_FOCUSED) ||
3690 (es->style & ES_NOHIDESEL));
3692 dc = BeginPaint(wnd->hwndSelf, &ps);
3695 if(es->style & WS_BORDER) {
3696 GetClientRect(wnd->hwndSelf, &rc);
3697 if(es->style & ES_MULTILINE) {
3698 if(es->style & WS_HSCROLL) rc.bottom++;
3699 if(es->style & WS_VSCROLL) rc.right++;
3701 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
3703 IntersectClipRect(dc, es->format_rect.left,
3704 es->format_rect.top,
3705 es->format_rect.right,
3706 es->format_rect.bottom);
3707 if (es->style & ES_MULTILINE) {
3708 GetClientRect(wnd->hwndSelf, &rc);
3709 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
3712 old_font = SelectObject(dc, es->font);
3713 if ( VERSION_AppWinVer() >= 0x40000 &&(
3714 !es->bEnableState || (es->style & ES_READONLY)))
3715 EDIT_SEND_CTLCOLORSTATIC(wnd, dc);
3717 EDIT_SEND_CTLCOLOR(wnd, dc);
3719 if (!es->bEnableState)
3720 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
3721 GetClipBox(dc, &rcRgn);
3722 if (es->style & ES_MULTILINE) {
3723 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3724 for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
3725 EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine);
3726 if (IntersectRect(&rc, &rcRgn, &rcLine))
3727 EDIT_PaintLine(wnd, es, dc, i, rev);
3730 EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine);
3731 if (IntersectRect(&rc, &rcRgn, &rcLine))
3732 EDIT_PaintLine(wnd, es, dc, 0, rev);
3735 SelectObject(dc, old_font);
3736 if (es->flags & EF_FOCUSED)
3737 EDIT_SetCaretPos(wnd, es, es->selection_end,
3738 es->flags & EF_AFTER_WRAP);
3740 EndPaint(wnd->hwndSelf, &ps);
3741 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) {
3742 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3744 si.cbSize = sizeof(SCROLLINFO);
3745 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3747 si.nMax = es->line_count + vlc - 2;
3749 si.nPos = es->y_offset;
3750 SetScrollInfo(wnd->hwndSelf, SB_VERT, &si, TRUE);
3752 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) {
3754 INT fw = es->format_rect.right - es->format_rect.left;
3755 si.cbSize = sizeof(SCROLLINFO);
3756 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3758 si.nMax = es->text_width + fw - 1;
3760 si.nPos = es->x_offset;
3761 SetScrollInfo(wnd->hwndSelf, SB_HORZ, &si, TRUE);
3764 if (es->flags & EF_UPDATE) {
3765 es->flags &= ~EF_UPDATE;
3766 EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE");
3771 /*********************************************************************
3776 static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es)
3781 OpenClipboard(wnd->hwndSelf);
3782 if ((hsrc = GetClipboardData(CF_TEXT))) {
3783 src = (LPSTR)GlobalLock(hsrc);
3784 EDIT_EM_ReplaceSel(wnd, es, TRUE, src);
3791 /*********************************************************************
3796 static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND window_losing_focus)
3798 es->flags |= EF_FOCUSED;
3799 CreateCaret(wnd->hwndSelf, 0, 2, es->line_height);
3800 EDIT_SetCaretPos(wnd, es, es->selection_end,
3801 es->flags & EF_AFTER_WRAP);
3802 if(!(es->style & ES_NOHIDESEL))
3803 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3804 ShowCaret(wnd->hwndSelf);
3805 EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS");
3809 /*********************************************************************
3813 * With Win95 look the margins are set to default font value unless
3814 * the system font (font == 0) is being set, in which case they are left
3818 static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT font, BOOL redraw)
3826 dc = GetDC(wnd->hwndSelf);
3828 old_font = SelectObject(dc, font);
3829 GetTextMetricsA(dc, &tm);
3830 es->line_height = tm.tmHeight;
3831 es->char_width = tm.tmAveCharWidth;
3833 SelectObject(dc, old_font);
3834 ReleaseDC(wnd->hwndSelf, dc);
3835 if (font && (TWEAK_WineLook > WIN31_LOOK))
3836 EDIT_EM_SetMargins(wnd, es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
3837 EC_USEFONTINFO, EC_USEFONTINFO);
3839 /* Force the recalculation of the format rect for each font change */
3840 GetClientRect(wnd->hwndSelf, &r);
3841 EDIT_SetRectNP(wnd, es, &r);
3843 if (es->style & ES_MULTILINE)
3844 EDIT_BuildLineDefs_ML(wnd, es);
3847 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
3848 if (es->flags & EF_FOCUSED) {
3850 CreateCaret(wnd->hwndSelf, 0, 2, es->line_height);
3851 EDIT_SetCaretPos(wnd, es, es->selection_end,
3852 es->flags & EF_AFTER_WRAP);
3853 ShowCaret(wnd->hwndSelf);
3858 /*********************************************************************
3863 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3864 * The modified flag is reset. No notifications are sent.
3866 * For single-line controls, reception of WM_SETTEXT triggers:
3867 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3870 static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text)
3872 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
3874 TRACE("\t'%s'\n", text);
3875 EDIT_EM_ReplaceSel(wnd, es, FALSE, text);
3877 TRACE("\t<NULL>\n");
3878 EDIT_EM_ReplaceSel(wnd, es, FALSE, "");
3881 if (es->style & ES_MULTILINE) {
3882 es->flags &= ~EF_UPDATE;
3884 es->flags |= EF_UPDATE;
3886 es->flags &= ~EF_MODIFIED;
3887 EDIT_EM_SetSel(wnd, es, 0, 0, FALSE);
3888 EDIT_EM_ScrollCaret(wnd, es);
3890 if (es->flags & EF_UPDATE)
3891 EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE");
3895 /*********************************************************************
3900 static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT action, INT width, INT height)
3902 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
3904 SetRect(&rc, 0, 0, width, height);
3905 EDIT_SetRectNP(wnd, es, &rc);
3906 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
3911 /*********************************************************************
3916 static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data)
3918 if ((key == VK_BACK) && (key_data & 0x2000)) {
3919 if (EDIT_EM_CanUndo(wnd, es))
3920 EDIT_EM_Undo(wnd, es);
3922 } else if (key == VK_UP || key == VK_DOWN)
3923 if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data))
3925 return DefWindowProcA(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
3929 /*********************************************************************
3934 static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT id, TIMERPROC timer_proc)
3936 if (es->region_posx < 0) {
3937 EDIT_MoveBackward(wnd, es, TRUE);
3938 } else if (es->region_posx > 0) {
3939 EDIT_MoveForward(wnd, es, TRUE);
3942 * FIXME: gotta do some vertical scrolling here, like
3943 * EDIT_EM_LineScroll(wnd, 0, 1);
3948 /*********************************************************************
3952 * 16 bit notepad needs this. Actually it is not _our_ hack,
3953 * it is notepad's. Notepad is sending us scrollbar messages with
3954 * undocumented parameters without us even having a scrollbar ... !?!?
3957 static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3962 if (!(es->flags & EF_VSCROLL_HACK)) {
3963 ERR("hacked WM_VSCROLL handler invoked\n");
3964 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3965 ERR(" (this message is only displayed once per edit control)\n");
3966 es->flags |= EF_VSCROLL_HACK;
3974 EDIT_EM_Scroll(wnd, es, action);
3980 dy = es->line_count - 1 - es->y_offset;
3983 es->flags |= EF_VSCROLL_TRACK;
3984 dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset;
3986 case SB_THUMBPOSITION:
3987 es->flags &= ~EF_VSCROLL_TRACK;
3988 if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset))
3989 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
3995 * FIXME : the next two are undocumented !
3996 * Are we doing the right thing ?
3997 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3998 * although it's also a regular control message.
4001 ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0;
4003 case EM_LINESCROLL16:
4008 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4012 EDIT_EM_LineScroll(wnd, es, 0, dy);
4017 /*********************************************************************
4022 static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
4026 if (!(es->style & ES_MULTILINE))
4029 if (!(es->style & ES_AUTOVSCROLL))
4032 if (!(es->style & WS_VSCROLL))
4033 return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar);
4041 EDIT_EM_Scroll(wnd, es, action);
4048 dy = es->line_count - 1 - es->y_offset;
4051 es->flags |= EF_VSCROLL_TRACK;
4052 dy = pos - es->y_offset;
4054 case SB_THUMBPOSITION:
4055 es->flags &= ~EF_VSCROLL_TRACK;
4056 if (!(dy = pos - es->y_offset)) {
4057 SetScrollPos(wnd->hwndSelf, SB_VERT, pos, TRUE);
4058 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
4065 ERR("undocumented WM_VSCROLL action %d, please report\n",
4070 EDIT_EM_LineScroll(wnd, es, 0, dy);