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)
17 #include "wine/winbase16.h"
21 #include "debugtools.h"
25 DECLARE_DEBUG_CHANNEL(combo)
26 DECLARE_DEBUG_CHANNEL(edit)
27 DECLARE_DEBUG_CHANNEL(relay)
29 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
30 FIXME: BTW, new specs say 65535 (do you dare ???) */
31 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
32 #define BUFSTART_MULTI 1024 /* starting size */
33 #define BUFSTART_SINGLE 256 /* starting size */
34 #define GROWLENGTH 64 /* buffers grow by this much */
35 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
38 * extra flags for EDITSTATE.flags field
40 #define EF_MODIFIED 0x0001 /* text has been modified */
41 #define EF_FOCUSED 0x0002 /* we have input focus */
42 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
43 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
44 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
45 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
46 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
47 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
48 wrapped line, instead of in front of the next character */
49 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
53 END_0 = 0, /* line ends with terminating '\0' character */
54 END_WRAP, /* line is wrapped */
55 END_HARD, /* line ends with a hard return '\r\n' */
56 END_SOFT /* line ends with a soft return '\r\r\n' */
59 typedef struct tagLINEDEF {
60 INT length; /* bruto length of a line in bytes */
61 INT net_length; /* netto length of a line in visible characters */
63 INT width; /* width of the line in pixels */
64 struct tagLINEDEF *next;
69 HANDLE heap; /* our own heap */
70 LPSTR text; /* the actual contents of the control */
71 INT buffer_size; /* the size of the buffer */
72 INT buffer_limit; /* the maximum size to which the buffer may grow */
73 HFONT font; /* NULL means standard system font */
74 INT x_offset; /* scroll offset for multi lines this is in pixels
75 for single lines it's in characters */
76 INT line_height; /* height of a screen line in pixels */
77 INT char_width; /* average character width in pixels */
78 DWORD style; /* sane version of wnd->dwStyle */
79 WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
80 INT undo_insert_count; /* number of characters inserted in sequence */
81 INT undo_position; /* character index of the insertion and deletion */
82 LPSTR undo_text; /* deleted text */
83 INT undo_buffer_size; /* size of the deleted text buffer */
84 INT selection_start; /* == selection_end if no selection */
85 INT selection_end; /* == current caret position */
86 CHAR password_char; /* == 0 if no password char, and for multi line controls */
87 INT left_margin; /* in pixels */
88 INT right_margin; /* in pixels */
90 INT region_posx; /* Position of cursor relative to region: */
91 INT region_posy; /* -1: to left, 0: within, 1: to right */
92 EDITWORDBREAKPROC16 word_break_proc16;
93 EDITWORDBREAKPROCA word_break_proc32A;
94 INT line_count; /* number of lines */
95 INT y_offset; /* scroll offset in number of lines */
97 * only for multi line controls
99 INT lock_count; /* amount of re-entries in the EditWndProc */
102 INT text_width; /* width of the widest line in pixels */
103 LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
104 HLOCAL16 hloc16; /* for controls receiving EM_GETHANDLE16 */
105 HLOCAL hloc32; /* for controls receiving EM_GETHANDLE */
109 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
110 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
112 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
113 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
115 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
116 ({TRACE_(edit)("notification " str " sent to hwnd=%08x\n", \
118 /* used for disabled or read-only edit control */
119 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
120 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
121 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
122 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
123 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
124 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
125 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
126 (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \
127 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
128 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
129 (LPARAM)(wnd)->hwndSelf))
130 #define DPRINTF_EDIT_MSG16(str) \
132 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
133 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
134 #define DPRINTF_EDIT_MSG32(str) \
136 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
137 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
139 /*********************************************************************
146 * These functions have trivial implementations
147 * We still like to call them internally
148 * "static __inline__" makes them more like macro's
150 static __inline__ BOOL EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es);
151 static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es);
152 static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es);
153 static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es);
155 * This is the only exported function
157 LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg,
158 WPARAM wParam, LPARAM lParam );
160 * Helper functions only valid for one type of control
162 static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es);
163 static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es);
164 static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL extend);
165 static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL extend);
166 static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL extend);
167 static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL extend);
169 * Helper functions valid for both single line _and_ multi line controls
171 static INT EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT start, INT index, INT count, INT action);
172 static INT EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
173 static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y);
174 static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
175 static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end);
176 static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es);
177 static BOOL EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT size);
178 static BOOL EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT size);
179 static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL extend);
180 static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL extend);
181 static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL extend);
182 static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL extend);
183 static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL extend);
184 static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL extend);
185 static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC hdc, INT line, BOOL rev);
186 static INT EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev);
187 static void EDIT_SetCaretPos(WND *wnd, EDITSTATE *es, INT pos, BOOL after_wrap);
188 static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT lprc);
189 static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL force);
190 static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action);
192 * EM_XXX message handlers
194 static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y);
195 static BOOL EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL add_eol);
196 static HLOCAL EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es);
197 static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es);
198 static INT EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT line, LPSTR lpch);
199 static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT start, LPUINT end);
200 static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es);
201 static INT EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT index);
202 static INT EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT line);
203 static INT EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT index);
204 static BOOL EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT dx, INT dy);
205 static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT index, BOOL after_wrap);
206 static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace);
207 static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT action);
208 static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es);
209 static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL hloc);
210 static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc);
211 static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT limit);
212 static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT action, INT left, INT right);
213 static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c);
214 static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap);
215 static BOOL EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT count, LPINT tabs);
216 static BOOL EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT count, LPINT16 tabs);
217 static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp);
218 static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp);
219 static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es);
221 * WM_XXX message handlers
223 static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data);
224 static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT code, INT id, HWND conrtol);
225 static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND hwnd, INT x, INT y);
226 static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es);
227 static LRESULT EDIT_WM_Create(WND *wnd, EDITSTATE *es, LPCREATESTRUCTA cs);
228 static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es);
229 static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC dc);
230 static INT EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT count, LPSTR text);
231 static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar);
232 static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data);
233 static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND window_getting_focus);
234 static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
235 static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
236 static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
237 static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y);
238 static LRESULT EDIT_WM_NCCreate(WND *wnd, LPCREATESTRUCTA cs);
239 static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es);
240 static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es);
241 static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND window_losing_focus);
242 static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT font, BOOL redraw);
243 static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text);
244 static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT action, INT width, INT height);
245 static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data);
246 static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT id, TIMERPROC timer_proc);
247 static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar);
250 /*********************************************************************
255 static __inline__ BOOL EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es)
257 return (es->undo_insert_count || lstrlenA(es->undo_text));
261 /*********************************************************************
266 static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es)
268 es->undo_insert_count = 0;
269 *es->undo_text = '\0';
273 /*********************************************************************
278 static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es)
280 EDIT_EM_ReplaceSel(wnd, es, TRUE, "");
284 /*********************************************************************
289 static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es)
291 EDIT_WM_Copy(wnd, es);
292 EDIT_WM_Clear(wnd, es);
296 /*********************************************************************
300 * The messages are in the order of the actual integer values
301 * (which can be found in include/windows.h)
302 * Whereever possible the 16 bit versions are converted to
303 * the 32 bit ones, so that we can 'fall through' to the
304 * helper functions. These are mostly 32 bit (with a few
305 * exceptions, clearly indicated by a '16' extension to their
309 LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg,
310 WPARAM wParam, LPARAM lParam )
312 WND *wnd = WIN_FindWndPtr(hwnd);
313 EDITSTATE *es = *(EDITSTATE **)((wnd)->wExtra);
318 DPRINTF_EDIT_MSG32("WM_DESTROY");
319 EDIT_WM_Destroy(wnd, es);
324 DPRINTF_EDIT_MSG32("WM_NCCREATE");
325 result = EDIT_WM_NCCreate(wnd, (LPCREATESTRUCTA)lParam);
331 result = DefWindowProcA(hwnd, msg, wParam, lParam);
336 EDIT_LockBuffer(wnd, es);
339 DPRINTF_EDIT_MSG16("EM_GETSEL");
344 DPRINTF_EDIT_MSG32("EM_GETSEL");
345 result = EDIT_EM_GetSel(wnd, es, (LPUINT)wParam, (LPUINT)lParam);
349 DPRINTF_EDIT_MSG16("EM_SETSEL");
350 if (SLOWORD(lParam) == -1)
351 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
353 EDIT_EM_SetSel(wnd, es, LOWORD(lParam), HIWORD(lParam), FALSE);
355 EDIT_EM_ScrollCaret(wnd, es);
359 DPRINTF_EDIT_MSG32("EM_SETSEL");
360 EDIT_EM_SetSel(wnd, es, wParam, lParam, FALSE);
365 DPRINTF_EDIT_MSG16("EM_GETRECT");
367 CONV_RECT32TO16(&es->format_rect, (LPRECT16)PTR_SEG_TO_LIN(lParam));
370 DPRINTF_EDIT_MSG32("EM_GETRECT");
372 CopyRect((LPRECT)lParam, &es->format_rect);
376 DPRINTF_EDIT_MSG16("EM_SETRECT");
377 if ((es->style & ES_MULTILINE) && lParam) {
379 CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc);
380 EDIT_SetRectNP(wnd, es, &rc);
381 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
385 DPRINTF_EDIT_MSG32("EM_SETRECT");
386 if ((es->style & ES_MULTILINE) && lParam) {
387 EDIT_SetRectNP(wnd, es, (LPRECT)lParam);
388 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
393 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
394 if ((es->style & ES_MULTILINE) && lParam) {
396 CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc);
397 EDIT_SetRectNP(wnd, es, &rc);
401 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
402 if ((es->style & ES_MULTILINE) && lParam)
403 EDIT_SetRectNP(wnd, es, (LPRECT)lParam);
407 DPRINTF_EDIT_MSG16("EM_SCROLL");
410 DPRINTF_EDIT_MSG32("EM_SCROLL");
411 result = EDIT_EM_Scroll(wnd, es, (INT)wParam);
414 case EM_LINESCROLL16:
415 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
416 wParam = (WPARAM)(INT)SHIWORD(lParam);
417 lParam = (LPARAM)(INT)SLOWORD(lParam);
420 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
421 result = (LRESULT)EDIT_EM_LineScroll(wnd, es, (INT)wParam, (INT)lParam);
424 case EM_SCROLLCARET16:
425 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
428 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
429 EDIT_EM_ScrollCaret(wnd, es);
434 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
437 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
438 result = ((es->flags & EF_MODIFIED) != 0);
442 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
445 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
447 es->flags |= EF_MODIFIED;
449 es->flags &= ~EF_MODIFIED;
452 case EM_GETLINECOUNT16:
453 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
455 case EM_GETLINECOUNT:
456 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
457 result = (es->style & ES_MULTILINE) ? es->line_count : 1;
461 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
462 if ((INT16)wParam == -1)
466 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
467 result = (LRESULT)EDIT_EM_LineIndex(wnd, es, (INT)wParam);
471 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
472 EDIT_EM_SetHandle16(wnd, es, (HLOCAL16)wParam);
475 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
476 EDIT_EM_SetHandle(wnd, es, (HLOCAL)wParam);
480 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
481 result = (LRESULT)EDIT_EM_GetHandle16(wnd, es);
484 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
485 result = (LRESULT)EDIT_EM_GetHandle(wnd, es);
489 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
492 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
493 result = EDIT_EM_GetThumb(wnd, es);
496 /* messages 0x00bf and 0x00c0 missing from specs */
499 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
502 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
503 result = DefWindowProcA(hwnd, msg, wParam, lParam);
507 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
510 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
511 result = DefWindowProcA(hwnd, msg, wParam, lParam);
514 case EM_LINELENGTH16:
515 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
518 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
519 result = (LRESULT)EDIT_EM_LineLength(wnd, es, (INT)wParam);
522 case EM_REPLACESEL16:
523 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
524 lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam);
527 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
528 EDIT_EM_ReplaceSel(wnd, es, (BOOL)wParam, (LPCSTR)lParam);
532 /* message 0x00c3 missing from specs */
535 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
538 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
539 result = DefWindowProcA(hwnd, msg, wParam, lParam);
543 DPRINTF_EDIT_MSG16("EM_GETLINE");
544 lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam);
547 DPRINTF_EDIT_MSG32("EM_GETLINE");
548 result = (LRESULT)EDIT_EM_GetLine(wnd, es, (INT)wParam, (LPSTR)lParam);
552 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
554 case EM_SETLIMITTEXT:
555 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
556 EDIT_EM_SetLimitText(wnd, es, (INT)wParam);
560 DPRINTF_EDIT_MSG16("EM_CANUNDO");
563 DPRINTF_EDIT_MSG32("EM_CANUNDO");
564 result = (LRESULT)EDIT_EM_CanUndo(wnd, es);
568 DPRINTF_EDIT_MSG16("EM_UNDO");
573 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
574 result = (LRESULT)EDIT_EM_Undo(wnd, es);
578 DPRINTF_EDIT_MSG16("EM_FMTLINES");
581 DPRINTF_EDIT_MSG32("EM_FMTLINES");
582 result = (LRESULT)EDIT_EM_FmtLines(wnd, es, (BOOL)wParam);
585 case EM_LINEFROMCHAR16:
586 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
588 case EM_LINEFROMCHAR:
589 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
590 result = (LRESULT)EDIT_EM_LineFromChar(wnd, es, (INT)wParam);
593 /* message 0x00ca missing from specs */
596 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
599 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
600 result = DefWindowProcA(hwnd, msg, wParam, lParam);
603 case EM_SETTABSTOPS16:
604 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
605 result = (LRESULT)EDIT_EM_SetTabStops16(wnd, es, (INT)wParam, (LPINT16)PTR_SEG_TO_LIN((SEGPTR)lParam));
608 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
609 result = (LRESULT)EDIT_EM_SetTabStops(wnd, es, (INT)wParam, (LPINT)lParam);
612 case EM_SETPASSWORDCHAR16:
613 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
615 case EM_SETPASSWORDCHAR:
616 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
617 EDIT_EM_SetPasswordChar(wnd, es, (CHAR)wParam);
620 case EM_EMPTYUNDOBUFFER16:
621 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
623 case EM_EMPTYUNDOBUFFER:
624 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
625 EDIT_EM_EmptyUndoBuffer(wnd, es);
628 case EM_GETFIRSTVISIBLELINE16:
629 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
630 result = es->y_offset;
632 case EM_GETFIRSTVISIBLELINE:
633 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
634 result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
637 case EM_SETREADONLY16:
638 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
641 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
643 wnd->dwStyle |= ES_READONLY;
644 es->style |= ES_READONLY;
646 wnd->dwStyle &= ~ES_READONLY;
647 es->style &= ~ES_READONLY;
652 case EM_SETWORDBREAKPROC16:
653 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
654 EDIT_EM_SetWordBreakProc16(wnd, es, (EDITWORDBREAKPROC16)lParam);
656 case EM_SETWORDBREAKPROC:
657 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
658 EDIT_EM_SetWordBreakProc(wnd, es, (EDITWORDBREAKPROCA)lParam);
661 case EM_GETWORDBREAKPROC16:
662 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
663 result = (LRESULT)es->word_break_proc16;
665 case EM_GETWORDBREAKPROC:
666 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
667 result = (LRESULT)es->word_break_proc32A;
670 case EM_GETPASSWORDCHAR16:
671 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
673 case EM_GETPASSWORDCHAR:
674 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
675 result = es->password_char;
678 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
681 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
682 EDIT_EM_SetMargins(wnd, es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam));
686 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
687 result = MAKELONG(es->left_margin, es->right_margin);
690 case EM_GETLIMITTEXT:
691 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
692 result = es->buffer_limit;
696 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
697 result = EDIT_EM_PosFromChar(wnd, es, (INT)wParam, FALSE);
701 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
702 result = EDIT_EM_CharFromPos(wnd, es, SLOWORD(lParam), SHIWORD(lParam));
706 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
707 result = (es->style & ES_MULTILINE) ?
708 DLGC_WANTALLKEYS | DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS :
709 DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
713 DPRINTF_EDIT_MSG32("WM_CHAR");
714 EDIT_WM_Char(wnd, es, (CHAR)wParam, (DWORD)lParam);
718 DPRINTF_EDIT_MSG32("WM_CLEAR");
719 EDIT_WM_Clear(wnd, es);
723 DPRINTF_EDIT_MSG32("WM_COMMAND");
724 EDIT_WM_Command(wnd, es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
728 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
729 EDIT_WM_ContextMenu(wnd, es, (HWND)wParam, SLOWORD(lParam), SHIWORD(lParam));
733 DPRINTF_EDIT_MSG32("WM_COPY");
734 EDIT_WM_Copy(wnd, es);
738 DPRINTF_EDIT_MSG32("WM_CREATE");
739 result = EDIT_WM_Create(wnd, es, (LPCREATESTRUCTA)lParam);
743 DPRINTF_EDIT_MSG32("WM_CUT");
744 EDIT_WM_Cut(wnd, es);
748 DPRINTF_EDIT_MSG32("WM_ENABLE");
749 InvalidateRect(hwnd, NULL, TRUE);
753 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
754 result = EDIT_WM_EraseBkGnd(wnd, es, (HDC)wParam);
758 DPRINTF_EDIT_MSG32("WM_GETFONT");
759 result = (LRESULT)es->font;
763 DPRINTF_EDIT_MSG32("WM_GETTEXT");
764 result = (LRESULT)EDIT_WM_GetText(wnd, es, (INT)wParam, (LPSTR)lParam);
767 case WM_GETTEXTLENGTH:
768 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
769 result = lstrlenA(es->text);
773 DPRINTF_EDIT_MSG32("WM_HSCROLL");
774 result = EDIT_WM_HScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)lParam);
778 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
779 result = EDIT_WM_KeyDown(wnd, es, (INT)wParam, (DWORD)lParam);
783 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
784 result = EDIT_WM_KillFocus(wnd, es, (HWND)wParam);
787 case WM_LBUTTONDBLCLK:
788 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
789 result = EDIT_WM_LButtonDblClk(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
793 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
794 result = EDIT_WM_LButtonDown(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
798 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
799 result = EDIT_WM_LButtonUp(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
802 case WM_MOUSEACTIVATE:
804 * FIXME: maybe DefWindowProc() screws up, but it seems that
805 * modalless dialog boxes need this. If we don't do this, the focus
806 * will _not_ be set by DefWindowProc() for edit controls in a
807 * modalless dialog box ???
809 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
810 SetFocus(wnd->hwndSelf);
811 result = MA_ACTIVATE;
816 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
818 result = EDIT_WM_MouseMove(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
822 DPRINTF_EDIT_MSG32("WM_PAINT");
823 EDIT_WM_Paint(wnd, es);
827 DPRINTF_EDIT_MSG32("WM_PASTE");
828 EDIT_WM_Paste(wnd, es);
832 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
833 EDIT_WM_SetFocus(wnd, es, (HWND)wParam);
837 DPRINTF_EDIT_MSG32("WM_SETFONT");
838 EDIT_WM_SetFont(wnd, es, (HFONT)wParam, LOWORD(lParam) != 0);
842 DPRINTF_EDIT_MSG32("WM_SETTEXT");
843 EDIT_WM_SetText(wnd, es, (LPCSTR)lParam);
848 DPRINTF_EDIT_MSG32("WM_SIZE");
849 EDIT_WM_Size(wnd, es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam));
853 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
854 result = EDIT_WM_SysKeyDown(wnd, es, (INT)wParam, (DWORD)lParam);
858 DPRINTF_EDIT_MSG32("WM_TIMER");
859 EDIT_WM_Timer(wnd, es, (INT)wParam, (TIMERPROC)lParam);
863 DPRINTF_EDIT_MSG32("WM_VSCROLL");
864 result = EDIT_WM_VScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)(lParam));
868 result = DefWindowProcA(hwnd, msg, wParam, lParam);
871 EDIT_UnlockBuffer(wnd, es, FALSE);
873 WIN_ReleaseWndPtr(wnd);
879 /*********************************************************************
881 * EDIT_BuildLineDefs_ML
883 * Build linked list of text lines.
884 * Lines can end with '\0' (last line), a character (if it is wrapped),
885 * a soft return '\r\r\n' or a hard return '\r\n'
888 static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es)
894 LINEDEF *current_def;
895 LINEDEF **previous_next;
897 current_def = es->first_line_def;
899 LINEDEF *next_def = current_def->next;
900 HeapFree(es->heap, 0, current_def);
901 current_def = next_def;
902 } while (current_def);
906 dc = GetDC(wnd->hwndSelf);
908 old_font = SelectObject(dc, es->font);
910 fw = es->format_rect.right - es->format_rect.left;
912 previous_next = &es->first_line_def;
914 current_def = HeapAlloc(es->heap, 0, sizeof(LINEDEF));
915 current_def->next = NULL;
918 if ((*cp == '\r') && (*(cp + 1) == '\n'))
923 current_def->ending = END_0;
924 current_def->net_length = lstrlenA(start);
925 } else if ((cp > start) && (*(cp - 1) == '\r')) {
926 current_def->ending = END_SOFT;
927 current_def->net_length = cp - start - 1;
929 current_def->ending = END_HARD;
930 current_def->net_length = cp - start;
932 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
933 start, current_def->net_length,
934 es->tabs_count, es->tabs));
935 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
936 if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) {
941 next = EDIT_CallWordBreakProc(wnd, es, start - es->text,
942 prev + 1, current_def->net_length, WB_RIGHT);
943 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
944 start, next, es->tabs_count, es->tabs));
945 } while (current_def->width <= fw);
951 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc,
952 start, next, es->tabs_count, es->tabs));
953 } while (current_def->width <= fw);
957 current_def->net_length = prev;
958 current_def->ending = END_WRAP;
959 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, start,
960 current_def->net_length, es->tabs_count, es->tabs));
962 switch (current_def->ending) {
964 current_def->length = current_def->net_length + 3;
967 current_def->length = current_def->net_length + 2;
971 current_def->length = current_def->net_length;
974 es->text_width = MAX(es->text_width, current_def->width);
975 start += current_def->length;
976 *previous_next = current_def;
977 previous_next = ¤t_def->next;
979 } while (current_def->ending != END_0);
981 SelectObject(dc, old_font);
982 ReleaseDC(wnd->hwndSelf, dc);
986 /*********************************************************************
988 * EDIT_CallWordBreakProc
990 * Call appropriate WordBreakProc (internal or external).
992 * Note: The "start" argument should always be an index refering
993 * to es->text. The actual wordbreak proc might be
994 * 16 bit, so we can't always pass any 32 bit LPSTR.
995 * Hence we assume that es->text is the buffer that holds
996 * the string under examination (we can decide this for ourselves).
999 static INT EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT start, INT index, INT count, INT action)
1001 if (es->word_break_proc16) {
1002 HLOCAL16 hloc16 = EDIT_EM_GetHandle16(wnd, es);
1003 SEGPTR segptr = LocalLock16(hloc16);
1004 INT ret = (INT)Callbacks->CallWordBreakProc(es->word_break_proc16,
1005 segptr + start, index, count, action);
1006 LocalUnlock16(hloc16);
1009 else if (es->word_break_proc32A)
1011 TRACE_(relay)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1012 es->word_break_proc32A, es->text + start, index,
1014 return (INT)es->word_break_proc32A( es->text + start, index,
1018 return EDIT_WordBreakProc(es->text + start, index, count, action);
1022 /*********************************************************************
1026 * Beware: This is not the function called on EM_CHARFROMPOS
1027 * The position _can_ be outside the formatting / client
1029 * The return value is only the character index
1032 static INT EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
1038 if (es->style & ES_MULTILINE) {
1039 INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1041 LINEDEF *line_def = es->first_line_def;
1043 while ((line > 0) && line_def->next) {
1044 line_index += line_def->length;
1045 line_def = line_def->next;
1048 x += es->x_offset - es->format_rect.left;
1049 if (x >= line_def->width) {
1051 *after_wrap = (line_def->ending == END_WRAP);
1052 return line_index + line_def->net_length;
1056 *after_wrap = FALSE;
1059 dc = GetDC(wnd->hwndSelf);
1061 old_font = SelectObject(dc, es->font);
1062 low = line_index + 1;
1063 high = line_index + line_def->net_length + 1;
1064 while (low < high - 1)
1066 INT mid = (low + high) / 2;
1067 if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
1073 *after_wrap = ((index == line_index + line_def->net_length) &&
1074 (line_def->ending == END_WRAP));
1079 *after_wrap = FALSE;
1080 x -= es->format_rect.left;
1082 return es->x_offset;
1083 text = EDIT_GetPasswordPointer_SL(wnd, es);
1084 dc = GetDC(wnd->hwndSelf);
1086 old_font = SelectObject(dc, es->font);
1090 INT high = es->x_offset;
1091 while (low < high - 1)
1093 INT mid = (low + high) / 2;
1094 GetTextExtentPoint32A( dc, text + mid,
1095 es->x_offset - mid, &size );
1096 if (size.cx > -x) low = mid;
1103 INT low = es->x_offset;
1104 INT high = lstrlenA(es->text) + 1;
1105 while (low < high - 1)
1107 INT mid = (low + high) / 2;
1108 GetTextExtentPoint32A( dc, text + es->x_offset,
1109 mid - es->x_offset, &size );
1110 if (size.cx > x) high = mid;
1115 if (es->style & ES_PASSWORD)
1116 HeapFree(es->heap, 0 ,text);
1119 SelectObject(dc, old_font);
1120 ReleaseDC(wnd->hwndSelf, dc);
1125 /*********************************************************************
1129 * adjusts the point to be within the formatting rectangle
1130 * (so CharFromPos returns the nearest _visible_ character)
1133 static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y)
1135 *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1);
1136 *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1);
1140 /*********************************************************************
1144 * Calculates the bounding rectangle for a line from a starting
1145 * column to an ending column.
1148 static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
1150 INT line_index = EDIT_EM_LineIndex(wnd, es, line);
1152 if (es->style & ES_MULTILINE)
1153 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1155 rc->top = es->format_rect.top;
1156 rc->bottom = rc->top + es->line_height;
1157 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE));
1158 rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + ecol, TRUE));
1162 /*********************************************************************
1164 * EDIT_GetPasswordPointer_SL
1166 * note: caller should free the (optionally) allocated buffer
1169 static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es)
1171 if (es->style & ES_PASSWORD) {
1172 INT len = lstrlenA(es->text);
1173 LPSTR text = HeapAlloc(es->heap, 0, len + 1);
1174 RtlFillMemory(text, len, es->password_char);
1182 /*********************************************************************
1186 * This acts as a LOCAL_Lock(), but it locks only once. This way
1187 * you can call it whenever you like, without unlocking.
1190 static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es)
1193 ERR_(edit)("no EDITSTATE ... please report\n");
1196 if (!(es->style & ES_MULTILINE))
1200 es->text = LocalLock(es->hloc32);
1201 else if (es->hloc16)
1202 es->text = LOCAL_Lock(wnd->hInstance, es->hloc16);
1204 ERR_(edit)("no buffer ... please report\n");
1212 /*********************************************************************
1214 * EDIT_SL_InvalidateText
1216 * Called from EDIT_InvalidateText().
1217 * Does the job for single-line controls only.
1220 static void EDIT_SL_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end)
1225 EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect);
1226 if (IntersectRect(&rc, &line_rect, &es->format_rect))
1227 InvalidateRect(wnd->hwndSelf, &rc, FALSE);
1231 /*********************************************************************
1233 * EDIT_ML_InvalidateText
1235 * Called from EDIT_InvalidateText().
1236 * Does the job for multi-line controls only.
1239 static void EDIT_ML_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end)
1241 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1242 INT sl = EDIT_EM_LineFromChar(wnd, es, start);
1243 INT el = EDIT_EM_LineFromChar(wnd, es, end);
1252 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1255 sc = start - EDIT_EM_LineIndex(wnd, es, sl);
1256 ec = end - EDIT_EM_LineIndex(wnd, es, el);
1257 if (sl < es->y_offset) {
1261 if (el > es->y_offset + vlc) {
1262 el = es->y_offset + vlc;
1263 ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el));
1265 GetClientRect(wnd->hwndSelf, &rc1);
1266 IntersectRect(&rcWnd, &rc1, &es->format_rect);
1268 EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine);
1269 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1270 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1272 EDIT_GetLineRect(wnd, es, sl, sc,
1273 EDIT_EM_LineLength(wnd, es,
1274 EDIT_EM_LineIndex(wnd, es, sl)),
1276 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1277 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1278 for (l = sl + 1 ; l < el ; l++) {
1279 EDIT_GetLineRect(wnd, es, l, 0,
1280 EDIT_EM_LineLength(wnd, es,
1281 EDIT_EM_LineIndex(wnd, es, l)),
1283 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1284 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1286 EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine);
1287 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1288 InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE);
1293 /*********************************************************************
1295 * EDIT_InvalidateText
1297 * Invalidate the text from offset start upto, but not including,
1298 * offset end. Useful for (re)painting the selection.
1299 * Regions outside the linewidth are not invalidated.
1300 * end == -1 means end == TextLength.
1301 * start and end need not be ordered.
1304 static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end)
1310 end = lstrlenA(es->text);
1312 ORDER_INT(start, end);
1314 if (es->style & ES_MULTILINE)
1315 EDIT_ML_InvalidateText(wnd, es, start, end);
1317 EDIT_SL_InvalidateText(wnd, es, start, end);
1321 /*********************************************************************
1325 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1328 static BOOL EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT size)
1333 if (size <= es->buffer_size)
1335 if (size > es->buffer_limit) {
1336 EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT");
1339 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
1340 if (size > es->buffer_limit)
1341 size = es->buffer_limit;
1343 TRACE_(edit)("trying to ReAlloc to %d+1\n", size);
1345 EDIT_UnlockBuffer(wnd, es, TRUE);
1347 if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1)))
1348 es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
1350 es->buffer_size = 0;
1351 } else if (es->hloc32) {
1352 if ((hNew32 = LocalReAlloc(es->hloc32, size + 1, 0))) {
1353 TRACE_(edit)("Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32);
1354 es->hloc32 = hNew32;
1355 es->buffer_size = MIN(LocalSize(es->hloc32) - 1, es->buffer_limit);
1357 } else if (es->hloc16) {
1358 if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) {
1359 TRACE_(edit)("Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16);
1360 es->hloc16 = hNew16;
1361 es->buffer_size = MIN(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit);
1364 if (es->buffer_size < size) {
1365 EDIT_LockBuffer(wnd, es);
1366 WARN_(edit)("FAILED ! We now have %d+1\n", es->buffer_size);
1367 EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE");
1370 EDIT_LockBuffer(wnd, es);
1371 TRACE_(edit)("We now have %d+1\n", es->buffer_size);
1377 /*********************************************************************
1381 * Try to fit size + 1 bytes in the undo buffer.
1384 static BOOL EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT size)
1386 if (size <= es->undo_buffer_size)
1388 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
1390 TRACE_(edit)("trying to ReAlloc to %d+1\n", size);
1392 if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) {
1393 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
1394 if (es->undo_buffer_size < size) {
1395 WARN_(edit)("FAILED ! We now have %d+1\n", es->undo_buffer_size);
1404 /*********************************************************************
1409 static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL extend)
1411 INT e = es->selection_end;
1415 if ((es->style & ES_MULTILINE) && e &&
1416 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1418 if (e && (es->text[e - 1] == '\r'))
1422 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1423 EDIT_EM_ScrollCaret(wnd, es);
1427 /*********************************************************************
1431 * Only for multi line controls
1432 * Move the caret one line down, on a column with the nearest
1433 * x coordinate on the screen (might be a different column).
1436 static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1438 INT s = es->selection_start;
1439 INT e = es->selection_end;
1440 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1441 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1442 INT x = SLOWORD(pos);
1443 INT y = SHIWORD(pos);
1445 e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap);
1448 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1449 EDIT_EM_ScrollCaret(wnd, es);
1453 /*********************************************************************
1458 static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL extend)
1460 BOOL after_wrap = FALSE;
1463 if (es->style & ES_MULTILINE)
1464 e = EDIT_CharFromPos(wnd, es, 0x7fffffff,
1465 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1467 e = lstrlenA(es->text);
1468 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap);
1469 EDIT_EM_ScrollCaret(wnd, es);
1473 /*********************************************************************
1478 static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL extend)
1480 INT e = es->selection_end;
1484 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1485 if (es->text[e] == '\n')
1487 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1491 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1492 EDIT_EM_ScrollCaret(wnd, es);
1496 /*********************************************************************
1500 * Home key: move to beginning of line.
1503 static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL extend)
1507 if (es->style & ES_MULTILINE)
1508 e = EDIT_CharFromPos(wnd, es, 0x80000000,
1509 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1512 EDIT_EM_SetSel(wnd, es, e, extend ? es->selection_start : e, FALSE);
1513 EDIT_EM_ScrollCaret(wnd, es);
1517 /*********************************************************************
1519 * EDIT_MovePageDown_ML
1521 * Only for multi line controls
1522 * Move the caret one page down, on a column with the nearest
1523 * x coordinate on the screen (might be a different column).
1526 static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1528 INT s = es->selection_start;
1529 INT e = es->selection_end;
1530 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1531 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1532 INT x = SLOWORD(pos);
1533 INT y = SHIWORD(pos);
1535 e = EDIT_CharFromPos(wnd, es, x,
1536 y + (es->format_rect.bottom - es->format_rect.top),
1540 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1541 EDIT_EM_ScrollCaret(wnd, es);
1545 /*********************************************************************
1547 * EDIT_MovePageUp_ML
1549 * Only for multi line controls
1550 * Move the caret one page up, on a column with the nearest
1551 * x coordinate on the screen (might be a different column).
1554 static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1556 INT s = es->selection_start;
1557 INT e = es->selection_end;
1558 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1559 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1560 INT x = SLOWORD(pos);
1561 INT y = SHIWORD(pos);
1563 e = EDIT_CharFromPos(wnd, es, x,
1564 y - (es->format_rect.bottom - es->format_rect.top),
1568 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1569 EDIT_EM_ScrollCaret(wnd, es);
1573 /*********************************************************************
1577 * Only for multi line controls
1578 * Move the caret one line up, on a column with the nearest
1579 * x coordinate on the screen (might be a different column).
1582 static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL extend)
1584 INT s = es->selection_start;
1585 INT e = es->selection_end;
1586 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1587 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1588 INT x = SLOWORD(pos);
1589 INT y = SHIWORD(pos);
1591 e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap);
1594 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1595 EDIT_EM_ScrollCaret(wnd, es);
1599 /*********************************************************************
1601 * EDIT_MoveWordBackward
1604 static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL extend)
1606 INT s = es->selection_start;
1607 INT e = es->selection_end;
1612 l = EDIT_EM_LineFromChar(wnd, es, e);
1613 ll = EDIT_EM_LineLength(wnd, es, e);
1614 li = EDIT_EM_LineIndex(wnd, es, l);
1617 li = EDIT_EM_LineIndex(wnd, es, l - 1);
1618 e = li + EDIT_EM_LineLength(wnd, es, li);
1621 e = li + (INT)EDIT_CallWordBreakProc(wnd, es,
1622 li, e - li, ll, WB_LEFT);
1626 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1627 EDIT_EM_ScrollCaret(wnd, es);
1631 /*********************************************************************
1633 * EDIT_MoveWordForward
1636 static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL extend)
1638 INT s = es->selection_start;
1639 INT e = es->selection_end;
1644 l = EDIT_EM_LineFromChar(wnd, es, e);
1645 ll = EDIT_EM_LineLength(wnd, es, e);
1646 li = EDIT_EM_LineIndex(wnd, es, l);
1648 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
1649 e = EDIT_EM_LineIndex(wnd, es, l + 1);
1651 e = li + EDIT_CallWordBreakProc(wnd, es,
1652 li, e - li + 1, ll, WB_RIGHT);
1656 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1657 EDIT_EM_ScrollCaret(wnd, es);
1661 /*********************************************************************
1666 static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC dc, INT line, BOOL rev)
1668 INT s = es->selection_start;
1669 INT e = es->selection_end;
1676 if (es->style & ES_MULTILINE) {
1677 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1678 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
1683 TRACE_(edit)("line=%d\n", line);
1685 pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE);
1688 li = EDIT_EM_LineIndex(wnd, es, line);
1689 ll = EDIT_EM_LineLength(wnd, es, li);
1690 s = es->selection_start;
1691 e = es->selection_end;
1693 s = MIN(li + ll, MAX(li, s));
1694 e = MIN(li + ll, MAX(li, e));
1695 if (rev && (s != e) &&
1696 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
1697 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE);
1698 x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE);
1699 x += EDIT_PaintText(wnd, es, dc, x, y, line, e - li, li + ll - e, FALSE);
1701 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE);
1705 /*********************************************************************
1710 static INT EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
1720 BkColor = GetBkColor(dc);
1721 TextColor = GetTextColor(dc);
1723 SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
1724 SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1726 li = EDIT_EM_LineIndex(wnd, es, line);
1727 if (es->style & ES_MULTILINE) {
1728 ret = (INT)LOWORD(TabbedTextOutA(dc, x, y, es->text + li + col, count,
1729 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
1731 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
1732 TextOutA(dc, x, y, text + li + col, count);
1733 GetTextExtentPoint32A(dc, text + li + col, count, &size);
1735 if (es->style & ES_PASSWORD)
1736 HeapFree(es->heap, 0, text);
1739 SetBkColor(dc, BkColor);
1740 SetTextColor(dc, TextColor);
1746 /*********************************************************************
1751 static void EDIT_SetCaretPos(WND *wnd, EDITSTATE *es, INT pos,
1754 LRESULT res = EDIT_EM_PosFromChar(wnd, es, pos, after_wrap);
1755 INT x = SLOWORD(res);
1756 INT y = SHIWORD(res);
1758 if(x < es->format_rect.left)
1759 x = es->format_rect.left;
1760 if(x > es->format_rect.right - 2)
1761 x = es->format_rect.right - 2;
1762 if(y > es->format_rect.bottom)
1763 y = es->format_rect.bottom;
1764 if(y < es->format_rect.top)
1765 y = es->format_rect.top;
1771 /*********************************************************************
1775 * note: this is not (exactly) the handler called on EM_SETRECTNP
1776 * it is also used to set the rect of a single line control
1779 static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT rc)
1781 CopyRect(&es->format_rect, rc);
1782 if (es->style & WS_BORDER) {
1783 INT bw = GetSystemMetrics(SM_CXBORDER) + 1;
1784 if(TWEAK_WineLook == WIN31_LOOK)
1786 es->format_rect.left += bw;
1787 es->format_rect.top += bw;
1788 es->format_rect.right -= bw;
1789 es->format_rect.bottom -= bw;
1791 es->format_rect.left += es->left_margin;
1792 es->format_rect.right -= es->right_margin;
1793 es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width);
1794 if (es->style & ES_MULTILINE)
1795 es->format_rect.bottom = es->format_rect.top +
1796 MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
1798 es->format_rect.bottom = es->format_rect.top + es->line_height;
1799 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
1800 EDIT_BuildLineDefs_ML(wnd, es);
1804 /*********************************************************************
1809 static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL force)
1812 ERR_(edit)("no EDITSTATE ... please report\n");
1815 if (!(es->style & ES_MULTILINE))
1817 if (!es->lock_count) {
1818 ERR_(edit)("lock_count == 0 ... please report\n");
1822 ERR_(edit)("es->text == 0 ... please report\n");
1825 if (force || (es->lock_count == 1)) {
1827 LocalUnlock(es->hloc32);
1829 } else if (es->hloc16) {
1830 LOCAL_Unlock(wnd->hInstance, es->hloc16);
1838 /*********************************************************************
1840 * EDIT_WordBreakProc
1842 * Find the beginning of words.
1843 * Note: unlike the specs for a WordBreakProc, this function only
1844 * allows to be called without linebreaks between s[0] upto
1845 * s[count - 1]. Remember it is only called
1846 * internally, so we can decide this for ourselves.
1849 static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action)
1853 TRACE_(edit)("s=%p, index=%u, count=%u, action=%d\n",
1854 s, index, count, action);
1862 if (s[index] == ' ') {
1863 while (index && (s[index] == ' '))
1866 while (index && (s[index] != ' '))
1868 if (s[index] == ' ')
1872 while (index && (s[index] != ' '))
1874 if (s[index] == ' ')
1884 if (s[index] == ' ')
1885 while ((index < count) && (s[index] == ' ')) index++;
1887 while (s[index] && (s[index] != ' ') && (index < count))
1889 while ((s[index] == ' ') && (index < count)) index++;
1893 case WB_ISDELIMITER:
1894 ret = (s[index] == ' ');
1897 ERR_(edit)("unknown action code, please report !\n");
1904 /*********************************************************************
1908 * returns line number (not index) in high-order word of result.
1909 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1910 * to Richedit, not to the edit control. Original documentation is valid.
1911 * FIXME: do the specs mean to return -1 if outside client area or
1912 * if outside formatting rectangle ???
1915 static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y)
1923 GetClientRect(wnd->hwndSelf, &rc);
1924 if (!PtInRect(&rc, pt))
1927 index = EDIT_CharFromPos(wnd, es, x, y, NULL);
1928 return MAKELONG(index, EDIT_EM_LineFromChar(wnd, es, index));
1932 /*********************************************************************
1936 * Enable or disable soft breaks.
1938 static BOOL EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL add_eol)
1940 es->flags &= ~EF_USE_SOFTBRK;
1942 es->flags |= EF_USE_SOFTBRK;
1943 FIXME_(edit)("soft break enabled, not implemented\n");
1949 /*********************************************************************
1953 * Hopefully this won't fire back at us.
1954 * We always start with a fixed buffer in our own heap.
1955 * However, with this message a 32 bit application requests
1956 * a handle to 32 bit moveable local heap memory, where it expects
1958 * It's a pity that from this moment on we have to use this
1959 * local heap, because applications may rely on the handle
1962 * In this function we'll try to switch to local heap.
1965 static HLOCAL EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es)
1971 if (!(es->style & ES_MULTILINE))
1976 else if (es->hloc16)
1977 return (HLOCAL)es->hloc16;
1979 if (!(newBuf = LocalAlloc(LMEM_MOVEABLE, lstrlenA(es->text) + 1))) {
1980 ERR_(edit)("could not allocate new 32 bit buffer\n");
1983 newSize = MIN(LocalSize(newBuf) - 1, es->buffer_limit);
1984 if (!(newText = LocalLock(newBuf))) {
1985 ERR_(edit)("could not lock new 32 bit buffer\n");
1989 lstrcpyA(newText, es->text);
1990 EDIT_UnlockBuffer(wnd, es, TRUE);
1992 HeapFree(es->heap, 0, es->text);
1993 es->hloc32 = newBuf;
1994 es->hloc16 = (HLOCAL16)NULL;
1995 es->buffer_size = newSize;
1997 EDIT_LockBuffer(wnd, es);
1998 TRACE_(edit)("switched to 32 bit local heap\n");
2004 /*********************************************************************
2008 * Hopefully this won't fire back at us.
2009 * We always start with a buffer in 32 bit linear memory.
2010 * However, with this message a 16 bit application requests
2011 * a handle of 16 bit local heap memory, where it expects to find
2013 * It's a pitty that from this moment on we have to use this
2014 * local heap, because applications may rely on the handle
2017 * In this function we'll try to switch to local heap.
2019 static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es)
2025 if (!(es->style & ES_MULTILINE))
2031 if (!LOCAL_HeapSize(wnd->hInstance)) {
2032 if (!LocalInit16(wnd->hInstance, 0,
2033 GlobalSize16(wnd->hInstance))) {
2034 ERR_(edit)("could not initialize local heap\n");
2037 TRACE_(edit)("local heap initialized\n");
2039 if (!(newBuf = LOCAL_Alloc(wnd->hInstance, LMEM_MOVEABLE, lstrlenA(es->text) + 1))) {
2040 ERR_(edit)("could not allocate new 16 bit buffer\n");
2043 newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit);
2044 if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) {
2045 ERR_(edit)("could not lock new 16 bit buffer\n");
2046 LOCAL_Free(wnd->hInstance, newBuf);
2049 lstrcpyA(newText, es->text);
2050 EDIT_UnlockBuffer(wnd, es, TRUE);
2052 HeapFree(es->heap, 0, es->text);
2053 else if (es->hloc32) {
2054 while (LocalFree(es->hloc32)) ;
2055 LocalFree(es->hloc32);
2057 es->hloc32 = (HLOCAL)NULL;
2058 es->hloc16 = newBuf;
2059 es->buffer_size = newSize;
2061 EDIT_LockBuffer(wnd, es);
2062 TRACE_(edit)("switched to 16 bit buffer\n");
2068 /*********************************************************************
2073 static INT EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT line, LPSTR lpch)
2079 if (es->style & ES_MULTILINE) {
2080 if (line >= es->line_count)
2084 i = EDIT_EM_LineIndex(wnd, es, line);
2086 len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, i));
2087 for (i = 0 ; i < len ; i++) {
2092 return (LRESULT)len;
2096 /*********************************************************************
2101 static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT start, LPUINT end)
2103 UINT s = es->selection_start;
2104 UINT e = es->selection_end;
2111 return MAKELONG(s, e);
2115 /*********************************************************************
2119 * FIXME: is this right ? (or should it be only VSCROLL)
2120 * (and maybe only for edit controls that really have their
2121 * own scrollbars) (and maybe only for multiline controls ?)
2122 * All in all: very poorly documented
2124 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2125 * WM_VSCROLL handlers
2128 static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es)
2130 return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB16, 0, 0),
2131 EDIT_WM_HScroll(wnd, es, EM_GETTHUMB16, 0, 0));
2135 /*********************************************************************
2140 static INT EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT index)
2145 if (!(es->style & ES_MULTILINE))
2147 if (index > lstrlenA(es->text))
2148 return es->line_count - 1;
2150 index = MIN(es->selection_start, es->selection_end);
2153 line_def = es->first_line_def;
2154 index -= line_def->length;
2155 while ((index >= 0) && line_def->next) {
2157 line_def = line_def->next;
2158 index -= line_def->length;
2164 /*********************************************************************
2169 static INT EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT line)
2174 if (!(es->style & ES_MULTILINE))
2176 if (line >= es->line_count)
2180 line_def = es->first_line_def;
2182 INT index = es->selection_end - line_def->length;
2183 while ((index >= 0) && line_def->next) {
2184 line_index += line_def->length;
2185 line_def = line_def->next;
2186 index -= line_def->length;
2190 line_index += line_def->length;
2191 line_def = line_def->next;
2199 /*********************************************************************
2204 static INT EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT index)
2208 if (!(es->style & ES_MULTILINE))
2209 return lstrlenA(es->text);
2213 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2214 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2215 return es->selection_start - es->line_defs[sl].offset +
2216 es->line_defs[el].offset +
2217 es->line_defs[el].length - es->selection_end;
2221 line_def = es->first_line_def;
2222 index -= line_def->length;
2223 while ((index >= 0) && line_def->next) {
2224 line_def = line_def->next;
2225 index -= line_def->length;
2227 return line_def->net_length;
2231 /*********************************************************************
2235 * FIXME: dx is in average character widths
2236 * However, we assume it is in pixels when we use this
2237 * function internally
2240 static BOOL EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT dx, INT dy)
2244 if (!(es->style & ES_MULTILINE))
2247 if (-dx > es->x_offset)
2249 if (dx > es->text_width - es->x_offset)
2250 dx = es->text_width - es->x_offset;
2251 nyoff = MAX(0, es->y_offset + dy);
2252 if (nyoff >= es->line_count)
2253 nyoff = es->line_count - 1;
2254 dy = (es->y_offset - nyoff) * es->line_height;
2258 GetClientRect(wnd->hwndSelf, &rc1);
2259 IntersectRect(&rc, &rc1, &es->format_rect);
2260 ScrollWindowEx(wnd->hwndSelf, -dx, dy,
2261 NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE);
2262 es->y_offset = nyoff;
2265 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2266 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
2267 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2268 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
2273 /*********************************************************************
2278 static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT index, BOOL after_wrap)
2280 INT len = lstrlenA(es->text);
2289 index = MIN(index, len);
2290 dc = GetDC(wnd->hwndSelf);
2292 old_font = SelectObject(dc, es->font);
2293 if (es->style & ES_MULTILINE) {
2294 l = EDIT_EM_LineFromChar(wnd, es, index);
2295 y = (l - es->y_offset) * es->line_height;
2296 li = EDIT_EM_LineIndex(wnd, es, l);
2297 if (after_wrap && (li == index) && l) {
2299 LINEDEF *line_def = es->first_line_def;
2301 line_def = line_def->next;
2304 if (line_def->ending == END_WRAP) {
2306 y -= es->line_height;
2307 li = EDIT_EM_LineIndex(wnd, es, l);
2310 x = LOWORD(GetTabbedTextExtentA(dc, es->text + li, index - li,
2311 es->tabs_count, es->tabs)) - es->x_offset;
2313 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
2314 if (index < es->x_offset) {
2315 GetTextExtentPoint32A(dc, text + index,
2316 es->x_offset - index, &size);
2319 GetTextExtentPoint32A(dc, text + es->x_offset,
2320 index - es->x_offset, &size);
2324 if (es->style & ES_PASSWORD)
2325 HeapFree(es->heap, 0 ,text);
2327 x += es->format_rect.left;
2328 y += es->format_rect.top;
2330 SelectObject(dc, old_font);
2331 ReleaseDC(wnd->hwndSelf, dc);
2332 return MAKELONG((INT16)x, (INT16)y);
2336 /*********************************************************************
2340 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2343 static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace)
2345 INT strl = lstrlenA(lpsz_replace);
2346 INT tl = lstrlenA(es->text);
2353 s = es->selection_start;
2354 e = es->selection_end;
2356 if ((s == e) && !strl)
2361 if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl))
2365 /* there is something to be deleted */
2367 utl = lstrlenA(es->undo_text);
2368 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
2369 /* undo-buffer is extended to the right */
2370 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2371 lstrcpynA(es->undo_text + utl, es->text + s, e - s + 1);
2372 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
2373 /* undo-buffer is extended to the left */
2374 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2375 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
2377 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2378 p[i] = (es->text + s)[i];
2379 es->undo_position = s;
2381 /* new undo-buffer */
2382 EDIT_MakeUndoFit(wnd, es, e - s);
2383 lstrcpynA(es->undo_text, es->text + s, e - s + 1);
2384 es->undo_position = s;
2386 /* any deletion makes the old insertion-undo invalid */
2387 es->undo_insert_count = 0;
2389 EDIT_EM_EmptyUndoBuffer(wnd, es);
2392 lstrcpyA(es->text + s, es->text + e);
2395 /* there is an insertion */
2397 if ((s == es->undo_position) ||
2398 ((es->undo_insert_count) &&
2399 (s == es->undo_position + es->undo_insert_count)))
2401 * insertion is new and at delete position or
2402 * an extension to either left or right
2404 es->undo_insert_count += strl;
2406 /* new insertion undo */
2407 es->undo_position = s;
2408 es->undo_insert_count = strl;
2409 /* new insertion makes old delete-buffer invalid */
2410 *es->undo_text = '\0';
2413 EDIT_EM_EmptyUndoBuffer(wnd, es);
2416 tl = lstrlenA(es->text);
2417 for (p = es->text + tl ; p >= es->text + s ; p--)
2419 for (i = 0 , p = es->text + s ; i < strl ; i++)
2420 p[i] = lpsz_replace[i];
2421 if(es->style & ES_UPPERCASE)
2422 CharUpperBuffA(p, strl);
2423 else if(es->style & ES_LOWERCASE)
2424 CharLowerBuffA(p, strl);
2427 /* FIXME: really inefficient */
2428 if (es->style & ES_MULTILINE)
2429 EDIT_BuildLineDefs_ML(wnd, es);
2431 EDIT_EM_SetSel(wnd, es, s, s, FALSE);
2432 es->flags |= EF_MODIFIED;
2433 es->flags |= EF_UPDATE;
2434 EDIT_EM_ScrollCaret(wnd, es);
2436 /* FIXME: really inefficient */
2437 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2441 /*********************************************************************
2446 static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT action)
2450 if (!(es->style & ES_MULTILINE))
2451 return (LRESULT)FALSE;
2461 if (es->y_offset < es->line_count - 1)
2466 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
2469 if (es->y_offset < es->line_count - 1)
2470 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2473 return (LRESULT)FALSE;
2476 EDIT_EM_LineScroll(wnd, es, 0, dy);
2477 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
2479 return MAKELONG((INT16)dy, (BOOL16)TRUE);
2483 /*********************************************************************
2488 static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es)
2490 if (es->style & ES_MULTILINE) {
2495 INT cw = es->char_width;
2500 l = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2501 li = EDIT_EM_LineIndex(wnd, es, l);
2502 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP));
2503 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2504 if (l >= es->y_offset + vlc)
2505 dy = l - vlc + 1 - es->y_offset;
2506 if (l < es->y_offset)
2507 dy = l - es->y_offset;
2508 ww = es->format_rect.right - es->format_rect.left;
2509 if (x < es->format_rect.left)
2510 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
2511 if (x > es->format_rect.right)
2512 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
2514 EDIT_EM_LineScroll(wnd, es, dx, dy);
2520 if (!(es->style & ES_AUTOHSCROLL))
2523 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
2524 format_width = es->format_rect.right - es->format_rect.left;
2525 if (x < es->format_rect.left) {
2526 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
2529 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
2530 } while ((x < goal) && es->x_offset);
2531 /* FIXME: use ScrollWindow() somehow to improve performance */
2532 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2533 } else if (x > es->format_rect.right) {
2535 INT len = lstrlenA(es->text);
2536 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
2539 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
2540 x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE));
2541 } while ((x > goal) && (x_last > es->format_rect.right));
2542 /* FIXME: use ScrollWindow() somehow to improve performance */
2543 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2549 /*********************************************************************
2553 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2556 static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL hloc)
2558 if (!(es->style & ES_MULTILINE))
2562 WARN_(edit)("called with NULL handle\n");
2566 EDIT_UnlockBuffer(wnd, es, TRUE);
2568 * old buffer is freed by caller, unless
2569 * it is still in our own heap. (in that case
2570 * we free it, correcting the buggy caller.)
2573 HeapFree(es->heap, 0, es->text);
2575 es->hloc16 = (HLOCAL16)NULL;
2578 es->buffer_size = LocalSize(es->hloc32) - 1;
2579 EDIT_LockBuffer(wnd, es);
2581 es->x_offset = es->y_offset = 0;
2582 es->selection_start = es->selection_end = 0;
2583 EDIT_EM_EmptyUndoBuffer(wnd, es);
2584 es->flags &= ~EF_MODIFIED;
2585 es->flags &= ~EF_UPDATE;
2586 EDIT_BuildLineDefs_ML(wnd, es);
2587 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2588 EDIT_EM_ScrollCaret(wnd, es);
2592 /*********************************************************************
2596 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2599 static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc)
2601 if (!(es->style & ES_MULTILINE))
2605 WARN_(edit)("called with NULL handle\n");
2609 EDIT_UnlockBuffer(wnd, es, TRUE);
2611 * old buffer is freed by caller, unless
2612 * it is still in our own heap. (in that case
2613 * we free it, correcting the buggy caller.)
2616 HeapFree(es->heap, 0, es->text);
2619 es->hloc32 = (HLOCAL)NULL;
2621 es->buffer_size = LOCAL_Size(wnd->hInstance, es->hloc16) - 1;
2622 EDIT_LockBuffer(wnd, es);
2624 es->x_offset = es->y_offset = 0;
2625 es->selection_start = es->selection_end = 0;
2626 EDIT_EM_EmptyUndoBuffer(wnd, es);
2627 es->flags &= ~EF_MODIFIED;
2628 es->flags &= ~EF_UPDATE;
2629 EDIT_BuildLineDefs_ML(wnd, es);
2630 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2631 EDIT_EM_ScrollCaret(wnd, es);
2635 /*********************************************************************
2639 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2640 * However, the windows version is not complied to yet in all of edit.c
2643 static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT limit)
2645 if (es->style & ES_MULTILINE) {
2647 es->buffer_limit = MIN(limit, BUFLIMIT_MULTI);
2649 es->buffer_limit = BUFLIMIT_MULTI;
2652 es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE);
2654 es->buffer_limit = BUFLIMIT_SINGLE;
2659 /*********************************************************************
2663 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2664 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2665 * of the char's width, according to the new docs.
2668 static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT action,
2669 INT left, INT right)
2671 if (action & EC_LEFTMARGIN) {
2672 if (left != EC_USEFONTINFO)
2673 es->left_margin = left;
2675 es->left_margin = es->char_width / 3;
2678 if (action & EC_RIGHTMARGIN) {
2679 if (right != EC_USEFONTINFO)
2680 es->right_margin = right;
2682 es->right_margin = es->char_width / 3;
2684 TRACE_(edit)("left=%d, right=%d\n", es->left_margin, es->right_margin);
2688 /*********************************************************************
2690 * EM_SETPASSWORDCHAR
2693 static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c)
2695 if (es->style & ES_MULTILINE)
2698 if (es->password_char == c)
2701 es->password_char = c;
2703 wnd->dwStyle |= ES_PASSWORD;
2704 es->style |= ES_PASSWORD;
2706 wnd->dwStyle &= ~ES_PASSWORD;
2707 es->style &= ~ES_PASSWORD;
2709 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2713 /*********************************************************************
2717 * note: unlike the specs say: the order of start and end
2718 * _is_ preserved in Windows. (i.e. start can be > end)
2719 * In other words: this handler is OK
2722 static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
2724 UINT old_start = es->selection_start;
2725 UINT old_end = es->selection_end;
2726 UINT len = lstrlenA(es->text);
2729 start = es->selection_end;
2730 end = es->selection_end;
2732 start = MIN(start, len);
2733 end = MIN(end, len);
2735 es->selection_start = start;
2736 es->selection_end = end;
2738 es->flags |= EF_AFTER_WRAP;
2740 es->flags &= ~EF_AFTER_WRAP;
2741 if (es->flags & EF_FOCUSED)
2742 EDIT_SetCaretPos(wnd, es, end, after_wrap);
2743 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2744 ORDER_UINT(start, end);
2745 ORDER_UINT(end, old_end);
2746 ORDER_UINT(start, old_start);
2747 ORDER_UINT(old_start, old_end);
2748 if (end != old_start)
2752 * ORDER_UINT32(end, old_start);
2753 * EDIT_InvalidateText(wnd, es, start, end);
2754 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2755 * in place of the following if statement.
2757 if (old_start > end )
2759 EDIT_InvalidateText(wnd, es, start, end);
2760 EDIT_InvalidateText(wnd, es, old_start, old_end);
2764 EDIT_InvalidateText(wnd, es, start, old_start);
2765 EDIT_InvalidateText(wnd, es, end, old_end);
2768 else EDIT_InvalidateText(wnd, es, start, old_end);
2772 /*********************************************************************
2777 static BOOL EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT count, LPINT tabs)
2779 if (!(es->style & ES_MULTILINE))
2782 HeapFree(es->heap, 0, es->tabs);
2783 es->tabs_count = count;
2787 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT));
2788 memcpy(es->tabs, tabs, count * sizeof(INT));
2794 /*********************************************************************
2799 static BOOL EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT count, LPINT16 tabs)
2801 if (!(es->style & ES_MULTILINE))
2804 HeapFree(es->heap, 0, es->tabs);
2805 es->tabs_count = count;
2810 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT));
2811 for (i = 0 ; i < count ; i++)
2812 es->tabs[i] = *tabs++;
2818 /*********************************************************************
2820 * EM_SETWORDBREAKPROC
2823 static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp)
2825 if (es->word_break_proc32A == wbp)
2828 es->word_break_proc32A = wbp;
2829 es->word_break_proc16 = NULL;
2830 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2831 EDIT_BuildLineDefs_ML(wnd, es);
2832 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2837 /*********************************************************************
2839 * EM_SETWORDBREAKPROC16
2842 static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
2844 if (es->word_break_proc16 == wbp)
2847 es->word_break_proc32A = NULL;
2848 es->word_break_proc16 = wbp;
2849 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2850 EDIT_BuildLineDefs_ML(wnd, es);
2851 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
2856 /*********************************************************************
2861 static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es)
2863 INT ulength = lstrlenA(es->undo_text);
2864 LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1);
2866 lstrcpyA(utext, es->undo_text);
2868 TRACE_(edit)("before UNDO:insertion length = %d, deletion buffer = %s\n",
2869 es->undo_insert_count, utext);
2871 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2872 EDIT_EM_EmptyUndoBuffer(wnd, es);
2873 EDIT_EM_ReplaceSel(wnd, es, TRUE, utext);
2874 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2875 HeapFree(es->heap, 0, utext);
2877 TRACE_(edit)("after UNDO:insertion length = %d, deletion buffer = %s\n",
2878 es->undo_insert_count, es->undo_text);
2884 /*********************************************************************
2889 static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data)
2894 if (es->style & ES_MULTILINE) {
2895 if (es->style & ES_READONLY) {
2896 EDIT_MoveHome(wnd, es, FALSE);
2897 EDIT_MoveDown_ML(wnd, es, FALSE);
2899 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n");
2903 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
2904 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t");
2907 if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) {
2911 EDIT_EM_ReplaceSel(wnd, es, TRUE, str);
2918 /*********************************************************************
2923 static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT code, INT id, HWND control)
2925 if (code || control)
2930 EDIT_EM_Undo(wnd, es);
2933 EDIT_WM_Cut(wnd, es);
2936 EDIT_WM_Copy(wnd, es);
2939 EDIT_WM_Paste(wnd, es);
2942 EDIT_WM_Clear(wnd, es);
2945 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
2946 EDIT_EM_ScrollCaret(wnd, es);
2949 ERR_(edit)("unknown menu item, please report\n");
2955 /*********************************************************************
2959 * Note: the resource files resource/sysres_??.rc cannot define a
2960 * single popup menu. Hence we use a (dummy) menubar
2961 * containing the single popup menu as its first item.
2963 * FIXME: the message identifiers have been chosen arbitrarily,
2964 * hence we use MF_BYPOSITION.
2965 * We might as well use the "real" values (anybody knows ?)
2966 * The menu definition is in resources/sysres_??.rc.
2967 * Once these are OK, we better use MF_BYCOMMAND here
2968 * (as we do in EDIT_WM_Command()).
2971 static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND hwnd, INT x, INT y)
2973 HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
2974 HMENU popup = GetSubMenu(menu, 0);
2975 UINT start = es->selection_start;
2976 UINT end = es->selection_end;
2978 ORDER_UINT(start, end);
2981 EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(wnd, es) ? MF_ENABLED : MF_GRAYED));
2983 EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
2985 EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
2987 EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
2989 EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED));
2991 EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != lstrlenA(es->text)) ? MF_ENABLED : MF_GRAYED));
2993 TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL);
2998 /*********************************************************************
3003 static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es)
3005 INT s = es->selection_start;
3006 INT e = es->selection_end;
3013 hdst = GlobalAlloc(GMEM_MOVEABLE, (DWORD)(e - s + 1));
3014 dst = GlobalLock(hdst);
3015 lstrcpynA(dst, es->text + s, e - s + 1);
3017 OpenClipboard(wnd->hwndSelf);
3019 SetClipboardData(CF_TEXT, hdst);
3024 /*********************************************************************
3029 static LRESULT EDIT_WM_Create(WND *wnd, EDITSTATE *es, LPCREATESTRUCTA cs)
3032 * To initialize some final structure members, we call some helper
3033 * functions. However, since the EDITSTATE is not consistent (i.e.
3034 * not fully initialized), we should be very careful which
3035 * functions can be called, and in what order.
3037 EDIT_WM_SetFont(wnd, es, 0, FALSE);
3038 EDIT_EM_EmptyUndoBuffer(wnd, es);
3040 if (cs->lpszName && *(cs->lpszName) != '\0') {
3041 EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName);
3042 /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */
3043 es->selection_start = es->selection_end = 0;
3044 EDIT_EM_ScrollCaret(wnd, es);
3050 /*********************************************************************
3055 static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es)
3058 while (LocalUnlock(es->hloc32)) ;
3059 LocalFree(es->hloc32);
3062 while (LOCAL_Unlock(wnd->hInstance, es->hloc16)) ;
3063 LOCAL_Free(wnd->hInstance, es->hloc16);
3065 HeapDestroy(es->heap);
3066 HeapFree(GetProcessHeap(), 0, es);
3067 *(EDITSTATE **)wnd->wExtra = NULL;
3071 /*********************************************************************
3076 static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC dc)
3081 if (!IsWindowEnabled(wnd->hwndSelf) || (es->style & ES_READONLY))
3082 brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(wnd, dc);
3084 brush = (HBRUSH)EDIT_SEND_CTLCOLOR(wnd, dc);
3087 brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
3089 GetClientRect(wnd->hwndSelf, &rc);
3090 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
3091 GetClipBox(dc, &rc);
3093 * FIXME: specs say that we should UnrealizeObject() the brush,
3094 * but the specs of UnrealizeObject() say that we shouldn't
3095 * unrealize a stock object. The default brush that
3096 * DefWndProc() returns is ... a stock object.
3098 FillRect(dc, &rc, brush);
3103 /*********************************************************************
3108 static INT EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT count, LPSTR text)
3110 INT len = lstrlenA(es->text);
3113 lstrcpyA(text, es->text);
3120 /*********************************************************************
3124 * 16 bit notepad needs this. Actually it is not _our_ hack,
3125 * it is notepad's. Notepad is sending us scrollbar messages with
3126 * undocumented parameters without us even having a scrollbar ... !?!?
3129 static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3132 INT fw = es->format_rect.right - es->format_rect.left;
3135 if (!(es->flags & EF_HSCROLL_HACK)) {
3136 ERR_(edit)("hacked WM_HSCROLL handler invoked\n");
3137 ERR_(edit)(" if you are _not_ running 16 bit notepad, please report\n");
3138 ERR_(edit)(" (this message is only displayed once per edit control)\n");
3139 es->flags |= EF_HSCROLL_HACK;
3145 dx = -es->char_width;
3148 if (es->x_offset < es->text_width)
3149 dx = es->char_width;
3153 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3156 if (es->x_offset < es->text_width)
3157 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3164 if (es->x_offset < es->text_width)
3165 dx = es->text_width - es->x_offset;
3168 es->flags |= EF_HSCROLL_TRACK;
3169 dx = pos * es->text_width / 100 - es->x_offset;
3171 case SB_THUMBPOSITION:
3172 es->flags &= ~EF_HSCROLL_TRACK;
3173 if (!(dx = pos * es->text_width / 100 - es->x_offset))
3174 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3180 * FIXME : the next two are undocumented !
3181 * Are we doing the right thing ?
3182 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3183 * although it's also a regular control message.
3186 ret = es->text_width ? es->x_offset * 100 / es->text_width : 0;
3188 case EM_LINESCROLL16:
3193 ERR_(edit)("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3197 EDIT_EM_LineScroll(wnd, es, dx, 0);
3202 /*********************************************************************
3207 static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3212 if (!(es->style & ES_MULTILINE))
3215 if (!(es->style & ES_AUTOHSCROLL))
3218 if (!(es->style & WS_HSCROLL))
3219 return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar);
3222 fw = es->format_rect.right - es->format_rect.left;
3226 dx = -es->char_width;
3229 if (es->x_offset < es->text_width)
3230 dx = es->char_width;
3234 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3237 if (es->x_offset < es->text_width)
3238 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3245 if (es->x_offset < es->text_width)
3246 dx = es->text_width - es->x_offset;
3249 es->flags |= EF_HSCROLL_TRACK;
3250 dx = pos - es->x_offset;
3252 case SB_THUMBPOSITION:
3253 es->flags &= ~EF_HSCROLL_TRACK;
3254 if (!(dx = pos - es->x_offset)) {
3255 SetScrollPos(wnd->hwndSelf, SB_HORZ, pos, TRUE);
3256 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3263 ERR_(edit)("undocumented WM_HSCROLL parameter, please report\n");
3267 EDIT_EM_LineScroll(wnd, es, dx, 0);
3272 /*********************************************************************
3277 static BOOL EDIT_CheckCombo(WND *wnd, UINT msg, INT key, DWORD key_data)
3281 if (WIDGETS_IsControl(wnd->parent, BIC32_COMBO) &&
3282 (hLBox = COMBO_GetLBWindow(wnd->parent))) {
3283 HWND hCombo = wnd->parent->hwndSelf;
3284 BOOL bUIFlip = TRUE;
3286 TRACE_(combo)("[%04x]: handling msg %04x (%04x)\n",
3287 wnd->hwndSelf, (UINT16)msg, (UINT16)key);
3290 case WM_KEYDOWN: /* Handle F4 and arrow keys */
3292 bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0);
3293 if (SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0))
3297 SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
3299 /* make sure ComboLBox pops up */
3300 SendMessageA(hCombo, CB_SETEXTENDEDUI, 0, 0);
3301 SendMessageA(hLBox, WM_KEYDOWN, VK_F4, 0);
3302 SendMessageA(hCombo, CB_SETEXTENDEDUI, 1, 0);
3305 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
3306 bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0);
3308 bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0);
3309 SendMessageA(hCombo, CB_SHOWDROPDOWN, (bUIFlip) ? FALSE : TRUE, 0);
3311 SendMessageA(hLBox, WM_KEYDOWN, VK_F4, 0);
3320 /*********************************************************************
3324 * Handling of special keys that don't produce a WM_CHAR
3325 * (i.e. non-printable keys) & Backspace & Delete
3328 static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data)
3333 if (GetKeyState(VK_MENU) & 0x8000)
3336 shift = GetKeyState(VK_SHIFT) & 0x8000;
3337 control = GetKeyState(VK_CONTROL) & 0x8000;
3342 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3348 if ((es->style & ES_MULTILINE) && (key == VK_UP))
3349 EDIT_MoveUp_ML(wnd, es, shift);
3352 EDIT_MoveWordBackward(wnd, es, shift);
3354 EDIT_MoveBackward(wnd, es, shift);
3357 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3361 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
3362 EDIT_MoveDown_ML(wnd, es, shift);
3364 EDIT_MoveWordForward(wnd, es, shift);
3366 EDIT_MoveForward(wnd, es, shift);
3369 EDIT_MoveHome(wnd, es, shift);
3372 EDIT_MoveEnd(wnd, es, shift);
3375 if (es->style & ES_MULTILINE)
3376 EDIT_MovePageUp_ML(wnd, es, shift);
3379 if (es->style & ES_MULTILINE)
3380 EDIT_MovePageDown_ML(wnd, es, shift);
3383 if (!(es->style & ES_READONLY) && !control) {
3384 if (es->selection_start != es->selection_end)
3385 EDIT_WM_Clear(wnd, es);
3387 /* delete character left of caret */
3388 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3389 EDIT_MoveBackward(wnd, es, TRUE);
3390 EDIT_WM_Clear(wnd, es);
3395 if (!(es->style & ES_READONLY) && !(shift && control)) {
3396 if (es->selection_start != es->selection_end) {
3398 EDIT_WM_Cut(wnd, es);
3400 EDIT_WM_Clear(wnd, es);
3403 /* delete character left of caret */
3404 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3405 EDIT_MoveBackward(wnd, es, TRUE);
3406 EDIT_WM_Clear(wnd, es);
3407 } else if (control) {
3408 /* delete to end of line */
3409 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3410 EDIT_MoveEnd(wnd, es, TRUE);
3411 EDIT_WM_Clear(wnd, es);
3413 /* delete character right of caret */
3414 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3415 EDIT_MoveForward(wnd, es, TRUE);
3416 EDIT_WM_Clear(wnd, es);
3423 if (!(es->style & ES_READONLY))
3424 EDIT_WM_Paste(wnd, es);
3426 EDIT_WM_Copy(wnd, es);
3433 /*********************************************************************
3438 static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND window_getting_focus)
3440 es->flags &= ~EF_FOCUSED;
3442 if(!(es->style & ES_NOHIDESEL))
3443 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3444 EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS");
3449 /*********************************************************************
3453 * The caret position has been set on the WM_LBUTTONDOWN message
3456 static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3459 INT e = es->selection_end;
3464 if (!(es->flags & EF_FOCUSED))
3467 l = EDIT_EM_LineFromChar(wnd, es, e);
3468 li = EDIT_EM_LineIndex(wnd, es, l);
3469 ll = EDIT_EM_LineLength(wnd, es, e);
3470 s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT);
3471 e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT);
3472 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
3473 EDIT_EM_ScrollCaret(wnd, es);
3478 /*********************************************************************
3483 static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3488 if (!(es->flags & EF_FOCUSED))
3491 SetCapture(wnd->hwndSelf);
3492 EDIT_ConfinePoint(wnd, es, &x, &y);
3493 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3494 EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
3495 EDIT_EM_ScrollCaret(wnd, es);
3496 es->region_posx = es->region_posy = 0;
3497 SetTimer(wnd->hwndSelf, 0, 100, NULL);
3502 /*********************************************************************
3507 static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3509 if (GetCapture() == wnd->hwndSelf) {
3510 KillTimer(wnd->hwndSelf, 0);
3517 /*********************************************************************
3522 static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y)
3528 if (GetCapture() != wnd->hwndSelf)
3532 * FIXME: gotta do some scrolling if outside client
3533 * area. Maybe reset the timer ?
3536 EDIT_ConfinePoint(wnd, es, &x, &y);
3537 es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
3538 es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
3539 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3540 EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap);
3545 /*********************************************************************
3550 static LRESULT EDIT_WM_NCCreate(WND *wnd, LPCREATESTRUCTA cs)
3554 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
3556 *(EDITSTATE **)wnd->wExtra = es;
3559 * Note: since the EDITSTATE has not been fully initialized yet,
3560 * we can't use any API calls that may send
3561 * WM_XXX messages before WM_NCCREATE is completed.
3564 if (!(es->heap = HeapCreate(0, 0x10000, 0)))
3566 es->style = cs->style;
3568 if ((es->style & WS_BORDER) && !(es->style & WS_DLGFRAME))
3569 wnd->dwStyle &= ~WS_BORDER;
3571 if (es->style & ES_MULTILINE) {
3572 es->buffer_size = BUFSTART_MULTI;
3573 es->buffer_limit = BUFLIMIT_MULTI;
3574 if (es->style & WS_VSCROLL)
3575 es->style |= ES_AUTOVSCROLL;
3576 if (es->style & WS_HSCROLL)
3577 es->style |= ES_AUTOHSCROLL;
3578 es->style &= ~ES_PASSWORD;
3579 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
3580 if (es->style & ES_RIGHT)
3581 es->style &= ~ES_CENTER;
3582 es->style &= ~WS_HSCROLL;
3583 es->style &= ~ES_AUTOHSCROLL;
3586 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3587 es->style |= ES_AUTOVSCROLL;
3589 es->buffer_size = BUFSTART_SINGLE;
3590 es->buffer_limit = BUFLIMIT_SINGLE;
3591 es->style &= ~ES_CENTER;
3592 es->style &= ~ES_RIGHT;
3593 es->style &= ~WS_HSCROLL;
3594 es->style &= ~WS_VSCROLL;
3595 es->style &= ~ES_AUTOVSCROLL;
3596 es->style &= ~ES_WANTRETURN;
3597 if (es->style & ES_UPPERCASE) {
3598 es->style &= ~ES_LOWERCASE;
3599 es->style &= ~ES_NUMBER;
3600 } else if (es->style & ES_LOWERCASE)
3601 es->style &= ~ES_NUMBER;
3602 if (es->style & ES_PASSWORD)
3603 es->password_char = '*';
3605 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3606 es->style |= ES_AUTOHSCROLL;
3608 if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3610 es->buffer_size = HeapSize(es->heap, 0, es->text) - 1;
3611 if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3613 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
3615 if (es->style & ES_MULTILINE)
3616 if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
3623 /*********************************************************************
3628 static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es)
3637 BOOL rev = IsWindowEnabled(wnd->hwndSelf) &&
3638 ((es->flags & EF_FOCUSED) ||
3639 (es->style & ES_NOHIDESEL));
3641 if (es->flags & EF_UPDATE)
3642 EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE");
3644 dc = BeginPaint(wnd->hwndSelf, &ps);
3645 if(es->style & WS_BORDER) {
3646 GetClientRect(wnd->hwndSelf, &rc);
3647 if(es->style & ES_MULTILINE) {
3648 if(es->style & WS_HSCROLL) rc.bottom++;
3649 if(es->style & WS_VSCROLL) rc.right++;
3651 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
3653 IntersectClipRect(dc, es->format_rect.left,
3654 es->format_rect.top,
3655 es->format_rect.right,
3656 es->format_rect.bottom);
3657 if (es->style & ES_MULTILINE) {
3658 GetClientRect(wnd->hwndSelf, &rc);
3659 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
3662 old_font = SelectObject(dc, es->font);
3663 if (!IsWindowEnabled(wnd->hwndSelf) || (es->style & ES_READONLY))
3664 EDIT_SEND_CTLCOLORSTATIC(wnd, dc);
3666 EDIT_SEND_CTLCOLOR(wnd, dc);
3667 if (!IsWindowEnabled(wnd->hwndSelf))
3668 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
3669 GetClipBox(dc, &rcRgn);
3670 if (es->style & ES_MULTILINE) {
3671 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3672 for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
3673 EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine);
3674 if (IntersectRect(&rc, &rcRgn, &rcLine))
3675 EDIT_PaintLine(wnd, es, dc, i, rev);
3678 EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine);
3679 if (IntersectRect(&rc, &rcRgn, &rcLine))
3680 EDIT_PaintLine(wnd, es, dc, 0, rev);
3683 SelectObject(dc, old_font);
3684 if (es->flags & EF_FOCUSED)
3685 EDIT_SetCaretPos(wnd, es, es->selection_end,
3686 es->flags & EF_AFTER_WRAP);
3687 EndPaint(wnd->hwndSelf, &ps);
3688 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) {
3689 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3691 si.cbSize = sizeof(SCROLLINFO);
3692 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3694 si.nMax = es->line_count + vlc - 2;
3696 si.nPos = es->y_offset;
3697 SetScrollInfo(wnd->hwndSelf, SB_VERT, &si, TRUE);
3699 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) {
3701 INT fw = es->format_rect.right - es->format_rect.left;
3702 si.cbSize = sizeof(SCROLLINFO);
3703 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3705 si.nMax = es->text_width + fw - 1;
3707 si.nPos = es->x_offset;
3708 SetScrollInfo(wnd->hwndSelf, SB_HORZ, &si, TRUE);
3711 if (es->flags & EF_UPDATE) {
3712 es->flags &= ~EF_UPDATE;
3713 EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE");
3718 /*********************************************************************
3723 static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es)
3728 OpenClipboard(wnd->hwndSelf);
3729 if ((hsrc = GetClipboardData(CF_TEXT))) {
3730 src = (LPSTR)GlobalLock(hsrc);
3731 EDIT_EM_ReplaceSel(wnd, es, TRUE, src);
3738 /*********************************************************************
3743 static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND window_losing_focus)
3745 es->flags |= EF_FOCUSED;
3746 CreateCaret(wnd->hwndSelf, 0, 2, es->line_height);
3747 EDIT_SetCaretPos(wnd, es, es->selection_end,
3748 es->flags & EF_AFTER_WRAP);
3749 if(!(es->style & ES_NOHIDESEL))
3750 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3751 ShowCaret(wnd->hwndSelf);
3752 EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS");
3756 /*********************************************************************
3760 * With Win95 look the margins are set to default font value unless
3761 * the system font (font == 0) is being set, in which case they are left
3765 static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT font, BOOL redraw)
3772 dc = GetDC(wnd->hwndSelf);
3774 old_font = SelectObject(dc, font);
3775 GetTextMetricsA(dc, &tm);
3776 es->line_height = tm.tmHeight;
3777 es->char_width = tm.tmAveCharWidth;
3779 SelectObject(dc, old_font);
3780 ReleaseDC(wnd->hwndSelf, dc);
3781 if (font && (TWEAK_WineLook > WIN31_LOOK))
3782 EDIT_EM_SetMargins(wnd, es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
3783 EC_USEFONTINFO, EC_USEFONTINFO);
3784 if (es->style & ES_MULTILINE)
3785 EDIT_BuildLineDefs_ML(wnd, es);
3788 GetClientRect(wnd->hwndSelf, &r);
3789 EDIT_SetRectNP(wnd, es, &r);
3792 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
3793 if (es->flags & EF_FOCUSED) {
3795 CreateCaret(wnd->hwndSelf, 0, 2, es->line_height);
3796 EDIT_SetCaretPos(wnd, es, es->selection_end,
3797 es->flags & EF_AFTER_WRAP);
3798 ShowCaret(wnd->hwndSelf);
3803 /*********************************************************************
3808 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3809 * The modified flag is reset. No notifications are sent.
3811 * For single-line controls, reception of WM_SETTEXT triggers:
3812 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3815 static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text)
3817 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
3819 TRACE_(edit)("\t'%s'\n", text);
3820 EDIT_EM_ReplaceSel(wnd, es, FALSE, text);
3822 TRACE_(edit)("\t<NULL>\n");
3823 EDIT_EM_ReplaceSel(wnd, es, FALSE, "");
3826 if (es->style & ES_MULTILINE) {
3827 es->flags &= ~EF_UPDATE;
3829 es->flags |= EF_UPDATE;
3831 es->flags &= ~EF_MODIFIED;
3832 EDIT_EM_SetSel(wnd, es, 0, 0, FALSE);
3833 EDIT_EM_ScrollCaret(wnd, es);
3837 /*********************************************************************
3842 static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT action, INT width, INT height)
3844 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
3846 SetRect(&rc, 0, 0, width, height);
3847 EDIT_SetRectNP(wnd, es, &rc);
3848 InvalidateRect(wnd->hwndSelf, NULL, TRUE);
3853 /*********************************************************************
3858 static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data)
3860 if ((key == VK_BACK) && (key_data & 0x2000)) {
3861 if (EDIT_EM_CanUndo(wnd, es))
3862 EDIT_EM_Undo(wnd, es);
3864 } else if (key == VK_UP || key == VK_DOWN)
3865 if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data))
3867 return DefWindowProcA(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
3871 /*********************************************************************
3876 static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT id, TIMERPROC timer_proc)
3878 if (es->region_posx < 0) {
3879 EDIT_MoveBackward(wnd, es, TRUE);
3880 } else if (es->region_posx > 0) {
3881 EDIT_MoveForward(wnd, es, TRUE);
3884 * FIXME: gotta do some vertical scrolling here, like
3885 * EDIT_EM_LineScroll(wnd, 0, 1);
3890 /*********************************************************************
3894 * 16 bit notepad needs this. Actually it is not _our_ hack,
3895 * it is notepad's. Notepad is sending us scrollbar messages with
3896 * undocumented parameters without us even having a scrollbar ... !?!?
3899 static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3904 if (!(es->flags & EF_VSCROLL_HACK)) {
3905 ERR_(edit)("hacked WM_VSCROLL handler invoked\n");
3906 ERR_(edit)(" if you are _not_ running 16 bit notepad, please report\n");
3907 ERR_(edit)(" (this message is only displayed once per edit control)\n");
3908 es->flags |= EF_VSCROLL_HACK;
3916 EDIT_EM_Scroll(wnd, es, action);
3922 dy = es->line_count - 1 - es->y_offset;
3925 es->flags |= EF_VSCROLL_TRACK;
3926 dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset;
3928 case SB_THUMBPOSITION:
3929 es->flags &= ~EF_VSCROLL_TRACK;
3930 if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset))
3931 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
3937 * FIXME : the next two are undocumented !
3938 * Are we doing the right thing ?
3939 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3940 * although it's also a regular control message.
3943 ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0;
3945 case EM_LINESCROLL16:
3950 ERR_(edit)("undocumented (hacked) WM_VSCROLL parameter, please report\n");
3954 EDIT_EM_LineScroll(wnd, es, 0, dy);
3959 /*********************************************************************
3964 static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
3968 if (!(es->style & ES_MULTILINE))
3971 if (!(es->style & ES_AUTOVSCROLL))
3974 if (!(es->style & WS_VSCROLL))
3975 return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar);
3983 EDIT_EM_Scroll(wnd, es, action);
3990 dy = es->line_count - 1 - es->y_offset;
3993 es->flags |= EF_VSCROLL_TRACK;
3994 dy = pos - es->y_offset;
3996 case SB_THUMBPOSITION:
3997 es->flags &= ~EF_VSCROLL_TRACK;
3998 if (!(dy = pos - es->y_offset)) {
3999 SetScrollPos(wnd->hwndSelf, SB_VERT, pos, TRUE);
4000 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
4007 ERR_(edit)("undocumented WM_VSCROLL action %d, please report\n",
4012 EDIT_EM_LineScroll(wnd, es, 0, dy);