4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
45 * -!ES_AUTOVSCROLL (every multi line control *is* auto vscroll)
46 * -!ES_AUTOHSCROLL (every single line control *is* auto hscroll)
48 * When there is no autoscrolling, the control should first check whether
49 * the new text would fit. If not, an EN_MAXTEXT should be sent.
50 * However, currently this would require the actual change to be made,
51 * then call EDIT_BuildLineDefs() and then find out that the new text doesn't
52 * fit. After all this, things should be put back in the state before the
53 * changes. Note that for multi line controls !ES_AUTOHSCROLL works : wordwrap.
68 #include "wine/winbase16.h"
69 #include "wine/winuser16.h"
70 #include "wine/unicode.h"
74 #include "user_private.h"
75 #include "wine/debug.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(edit);
78 WINE_DECLARE_DEBUG_CHANNEL(combo);
79 WINE_DECLARE_DEBUG_CHANNEL(relay);
81 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
82 FIXME: BTW, new specs say 65535 (do you dare ???) */
83 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
84 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
85 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
86 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
89 * extra flags for EDITSTATE.flags field
91 #define EF_MODIFIED 0x0001 /* text has been modified */
92 #define EF_FOCUSED 0x0002 /* we have input focus */
93 #define EF_UPDATE 0x0004 /* notify parent of changed state */
94 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
95 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
96 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
97 wrapped line, instead of in front of the next character */
98 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
102 END_0 = 0, /* line ends with terminating '\0' character */
103 END_WRAP, /* line is wrapped */
104 END_HARD, /* line ends with a hard return '\r\n' */
105 END_SOFT, /* line ends with a soft return '\r\r\n' */
106 END_RICH /* line ends with a single '\n' */
109 typedef struct tagLINEDEF {
110 INT length; /* bruto length of a line in bytes */
111 INT net_length; /* netto length of a line in visible characters */
113 INT width; /* width of the line in pixels */
114 INT index; /* line index into the buffer */
115 struct tagLINEDEF *next;
120 BOOL is_unicode; /* how the control was created */
121 LPWSTR text; /* the actual contents of the control */
122 UINT buffer_size; /* the size of the buffer in characters */
123 UINT buffer_limit; /* the maximum size to which the buffer may grow in characters */
124 HFONT font; /* NULL means standard system font */
125 INT x_offset; /* scroll offset for multi lines this is in pixels
126 for single lines it's in characters */
127 INT line_height; /* height of a screen line in pixels */
128 INT char_width; /* average character width in pixels */
129 DWORD style; /* sane version of wnd->dwStyle */
130 WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
131 INT undo_insert_count; /* number of characters inserted in sequence */
132 UINT undo_position; /* character index of the insertion and deletion */
133 LPWSTR undo_text; /* deleted text */
134 UINT undo_buffer_size; /* size of the deleted text buffer */
135 INT selection_start; /* == selection_end if no selection */
136 INT selection_end; /* == current caret position */
137 WCHAR password_char; /* == 0 if no password char, and for multi line controls */
138 INT left_margin; /* in pixels */
139 INT right_margin; /* in pixels */
141 INT text_width; /* width of the widest line in pixels for multi line controls
142 and just line width for single line controls */
143 INT region_posx; /* Position of cursor relative to region: */
144 INT region_posy; /* -1: to left, 0: within, 1: to right */
145 EDITWORDBREAKPROC16 word_break_proc16;
146 void *word_break_proc; /* 32-bit word break proc: ANSI or Unicode */
147 INT line_count; /* number of lines */
148 INT y_offset; /* scroll offset in number of lines */
149 BOOL bCaptureState; /* flag indicating whether mouse was captured */
150 BOOL bEnableState; /* flag keeping the enable state */
151 HWND hwndSelf; /* the our window handle */
152 HWND hwndParent; /* Handle of parent for sending EN_* messages.
153 Even if parent will change, EN_* messages
154 should be sent to the first parent. */
155 HWND hwndListBox; /* handle of ComboBox's listbox or NULL */
157 * only for multi line controls
159 INT lock_count; /* amount of re-entries in the EditWndProc */
162 LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
163 HLOCAL hloc32W; /* our unicode local memory block */
164 HLOCAL16 hloc16; /* alias for 16-bit control receiving EM_GETHANDLE16
166 HLOCAL hloc32A; /* alias for ANSI control receiving EM_GETHANDLE
171 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
172 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
174 /* used for disabled or read-only edit control */
175 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
177 { /* Notify parent which has created this edit control */ \
178 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
179 SendMessageW(es->hwndParent, WM_COMMAND, \
180 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
181 (LPARAM)(es->hwndSelf)); \
184 /*********************************************************************
191 * These functions have trivial implementations
192 * We still like to call them internally
193 * "static inline" makes them more like macro's
195 static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es);
196 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es);
197 static inline void EDIT_WM_Clear(EDITSTATE *es);
198 static inline void EDIT_WM_Cut(EDITSTATE *es);
201 * Helper functions only valid for one type of control
203 static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT iStart, INT iEnd, INT delta, HRGN hrgn);
204 static void EDIT_CalcLineWidth_SL(EDITSTATE *es);
205 static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es);
206 static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend);
207 static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend);
208 static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend);
209 static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend);
211 * Helper functions valid for both single line _and_ multi line controls
213 static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action);
214 static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
215 static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y);
216 static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
217 static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end);
218 static void EDIT_LockBuffer(EDITSTATE *es);
219 static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size);
220 static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size);
221 static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend);
222 static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend);
223 static void EDIT_MoveForward(EDITSTATE *es, BOOL extend);
224 static void EDIT_MoveHome(EDITSTATE *es, BOOL extend);
225 static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend);
226 static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend);
227 static void EDIT_PaintLine(EDITSTATE *es, HDC hdc, INT line, BOOL rev);
228 static INT EDIT_PaintText(EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev);
229 static void EDIT_SetCaretPos(EDITSTATE *es, INT pos, BOOL after_wrap);
230 static void EDIT_SetRectNP(EDITSTATE *es, LPRECT lprc);
231 static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force);
232 static void EDIT_UpdateScrollInfo(EDITSTATE *es);
233 static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action);
235 * EM_XXX message handlers
237 static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y);
238 static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol);
239 static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es);
240 static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es);
241 static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPWSTR dst, BOOL unicode);
242 static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end);
243 static LRESULT EDIT_EM_GetThumb(EDITSTATE *es);
244 static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index);
245 static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line);
246 static INT EDIT_EM_LineLength(EDITSTATE *es, INT index);
247 static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy);
248 static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy);
249 static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap);
250 static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit);
251 static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action);
252 static void EDIT_EM_ScrollCaret(EDITSTATE *es);
253 static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc);
254 static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc);
255 static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit);
256 static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, INT left, INT right);
257 static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c);
258 static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap);
259 static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs);
260 static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs);
261 static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, void *wbp);
262 static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp);
263 static BOOL EDIT_EM_Undo(EDITSTATE *es);
265 * WM_XXX message handlers
267 static void EDIT_WM_Char(EDITSTATE *es, WCHAR c);
268 static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND conrtol);
269 static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y);
270 static void EDIT_WM_Copy(EDITSTATE *es);
271 static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name);
272 static LRESULT EDIT_WM_Destroy(EDITSTATE *es);
273 static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc);
274 static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPWSTR dst, BOOL unicode);
275 static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos);
276 static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key);
277 static LRESULT EDIT_WM_KillFocus(EDITSTATE *es);
278 static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es);
279 static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y);
280 static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es);
281 static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es);
282 static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y);
283 static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode);
284 static void EDIT_WM_Paint(EDITSTATE *es, HDC hdc);
285 static void EDIT_WM_Paste(EDITSTATE *es);
286 static void EDIT_WM_SetFocus(EDITSTATE *es);
287 static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw);
288 static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text, BOOL unicode);
289 static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height);
290 static LRESULT EDIT_WM_StyleChanged(EDITSTATE *es, WPARAM which, const STYLESTRUCT *style);
291 static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data);
292 static void EDIT_WM_Timer(EDITSTATE *es);
293 static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos);
294 static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase);
295 static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase);
297 LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
298 LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
300 /*********************************************************************
301 * edit class descriptor
303 const struct builtin_class_descr EDIT_builtin_class =
306 CS_DBLCLKS | CS_PARENTDC, /* style */
307 EditWndProcA, /* procA */
308 EditWndProcW, /* procW */
309 sizeof(EDITSTATE *), /* extra */
310 IDC_IBEAM, /* cursor */
315 /*********************************************************************
320 static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es)
322 return (es->undo_insert_count || strlenW(es->undo_text));
326 /*********************************************************************
331 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es)
333 es->undo_insert_count = 0;
334 *es->undo_text = '\0';
338 /*********************************************************************
343 static inline void EDIT_WM_Clear(EDITSTATE *es)
345 static const WCHAR empty_stringW[] = {0};
347 /* Protect read-only edit control from modification */
348 if(es->style & ES_READONLY)
351 EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE, TRUE);
355 /*********************************************************************
360 static inline void EDIT_WM_Cut(EDITSTATE *es)
367 /**********************************************************************
370 * Returns the window version in case Wine emulates a later version
371 * of windows than the application expects.
373 * In a number of cases when windows runs an application that was
374 * designed for an earlier windows version, windows reverts
375 * to "old" behaviour of that earlier version.
377 * An example is a disabled edit control that needs to be painted.
378 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
379 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
380 * applications with an expected version 0f 4.0 or higher.
383 static DWORD get_app_version(void)
385 static DWORD version;
388 DWORD dwEmulatedVersion;
390 DWORD dwProcVersion = GetProcessVersion(0);
392 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
393 GetVersionExW( &info );
394 dwEmulatedVersion = MAKELONG( info.dwMinorVersion, info.dwMajorVersion );
395 /* FIXME: this may not be 100% correct; see discussion on the
396 * wine developer list in Nov 1999 */
397 version = dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion;
403 static HBRUSH EDIT_NotifyCtlColor(EDITSTATE *es, HDC hdc)
407 if ( get_app_version() >= 0x40000 && (!es->bEnableState || (es->style & ES_READONLY)))
408 msg = WM_CTLCOLORSTATIC;
410 msg = WM_CTLCOLOREDIT;
412 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
413 return (HBRUSH)SendMessageW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf);
416 static inline LRESULT DefWindowProcT(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
419 return DefWindowProcW(hwnd, msg, wParam, lParam);
421 return DefWindowProcA(hwnd, msg, wParam, lParam);
424 /*********************************************************************
428 * The messages are in the order of the actual integer values
429 * (which can be found in include/windows.h)
430 * Wherever possible the 16 bit versions are converted to
431 * the 32 bit ones, so that we can 'fall through' to the
432 * helper functions. These are mostly 32 bit (with a few
433 * exceptions, clearly indicated by a '16' extension to their
437 static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg,
438 WPARAM wParam, LPARAM lParam, BOOL unicode )
440 EDITSTATE *es = (EDITSTATE *)GetWindowLongW( hwnd, 0 );
443 TRACE("hwnd=%p msg=%x (%s) wparam=%x lparam=%lx\n", hwnd, msg, SPY_GetMsgName(msg, hwnd), wParam, lParam);
445 if (!es && msg != WM_NCCREATE)
446 return DefWindowProcT(hwnd, msg, wParam, lParam, unicode);
447 else if (msg == WM_NCCREATE)
448 return EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTW)lParam, unicode);
449 else if (msg == WM_DESTROY)
450 return EDIT_WM_Destroy(es);
453 if (es) EDIT_LockBuffer(es);
461 result = EDIT_EM_GetSel(es, (PUINT)wParam, (PUINT)lParam);
465 if ((short)LOWORD(lParam) == -1)
466 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
468 EDIT_EM_SetSel(es, LOWORD(lParam), HIWORD(lParam), FALSE);
470 EDIT_EM_ScrollCaret(es);
474 EDIT_EM_SetSel(es, wParam, lParam, FALSE);
475 EDIT_EM_ScrollCaret(es);
482 RECT16 *r16 = MapSL(lParam);
483 r16->left = es->format_rect.left;
484 r16->top = es->format_rect.top;
485 r16->right = es->format_rect.right;
486 r16->bottom = es->format_rect.bottom;
491 CopyRect((LPRECT)lParam, &es->format_rect);
495 if ((es->style & ES_MULTILINE) && lParam) {
497 RECT16 *r16 = MapSL(lParam);
500 rc.right = r16->right;
501 rc.bottom = r16->bottom;
502 EDIT_SetRectNP(es, &rc);
503 EDIT_UpdateText(es, NULL, TRUE);
507 if ((es->style & ES_MULTILINE) && lParam) {
508 EDIT_SetRectNP(es, (LPRECT)lParam);
509 EDIT_UpdateText(es, NULL, TRUE);
514 if ((es->style & ES_MULTILINE) && lParam) {
516 RECT16 *r16 = MapSL(lParam);
519 rc.right = r16->right;
520 rc.bottom = r16->bottom;
521 EDIT_SetRectNP(es, &rc);
525 if ((es->style & ES_MULTILINE) && lParam)
526 EDIT_SetRectNP(es, (LPRECT)lParam);
531 result = EDIT_EM_Scroll(es, (INT)wParam);
534 case EM_LINESCROLL16:
535 wParam = (WPARAM)(INT)(SHORT)HIWORD(lParam);
536 lParam = (LPARAM)(INT)(SHORT)LOWORD(lParam);
539 result = (LRESULT)EDIT_EM_LineScroll(es, (INT)wParam, (INT)lParam);
542 case EM_SCROLLCARET16:
544 EDIT_EM_ScrollCaret(es);
550 result = ((es->flags & EF_MODIFIED) != 0);
556 es->flags |= EF_MODIFIED;
558 es->flags &= ~(EF_MODIFIED | EF_UPDATE); /* reset pending updates */
561 case EM_GETLINECOUNT16:
562 case EM_GETLINECOUNT:
563 result = (es->style & ES_MULTILINE) ? es->line_count : 1;
567 if ((INT16)wParam == -1)
571 result = (LRESULT)EDIT_EM_LineIndex(es, (INT)wParam);
575 EDIT_EM_SetHandle16(es, (HLOCAL16)wParam);
578 EDIT_EM_SetHandle(es, (HLOCAL)wParam);
582 result = (LRESULT)EDIT_EM_GetHandle16(es);
585 result = (LRESULT)EDIT_EM_GetHandle(es);
590 result = EDIT_EM_GetThumb(es);
593 /* these messages missing from specs */
602 FIXME("undocumented message 0x%x, please report\n", msg);
603 result = DefWindowProcW(hwnd, msg, wParam, lParam);
606 case EM_LINELENGTH16:
608 result = (LRESULT)EDIT_EM_LineLength(es, (INT)wParam);
611 case EM_REPLACESEL16:
612 lParam = (LPARAM)MapSL(lParam);
613 unicode = FALSE; /* 16-bit message is always ascii */
620 textW = (LPWSTR)lParam;
623 LPSTR textA = (LPSTR)lParam;
624 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
625 if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
626 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
629 EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, TRUE, TRUE);
633 HeapFree(GetProcessHeap(), 0, textW);
638 lParam = (LPARAM)MapSL(lParam);
639 unicode = FALSE; /* 16-bit message is always ascii */
642 result = (LRESULT)EDIT_EM_GetLine(es, (INT)wParam, (LPWSTR)lParam, unicode);
646 case EM_SETLIMITTEXT:
647 EDIT_EM_SetLimitText(es, (INT)wParam);
652 result = (LRESULT)EDIT_EM_CanUndo(es);
658 result = (LRESULT)EDIT_EM_Undo(es);
663 result = (LRESULT)EDIT_EM_FmtLines(es, (BOOL)wParam);
666 case EM_LINEFROMCHAR16:
667 case EM_LINEFROMCHAR:
668 result = (LRESULT)EDIT_EM_LineFromChar(es, (INT)wParam);
671 case EM_SETTABSTOPS16:
672 result = (LRESULT)EDIT_EM_SetTabStops16(es, (INT)wParam, MapSL(lParam));
675 result = (LRESULT)EDIT_EM_SetTabStops(es, (INT)wParam, (LPINT)lParam);
678 case EM_SETPASSWORDCHAR16:
679 unicode = FALSE; /* 16-bit message is always ascii */
681 case EM_SETPASSWORDCHAR:
686 charW = (WCHAR)wParam;
690 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
693 EDIT_EM_SetPasswordChar(es, charW);
697 case EM_EMPTYUNDOBUFFER16:
698 case EM_EMPTYUNDOBUFFER:
699 EDIT_EM_EmptyUndoBuffer(es);
702 case EM_GETFIRSTVISIBLELINE16:
703 result = es->y_offset;
705 case EM_GETFIRSTVISIBLELINE:
706 result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
709 case EM_SETREADONLY16:
712 SetWindowLongW( hwnd, GWL_STYLE,
713 GetWindowLongW( hwnd, GWL_STYLE ) | ES_READONLY );
714 es->style |= ES_READONLY;
716 SetWindowLongW( hwnd, GWL_STYLE,
717 GetWindowLongW( hwnd, GWL_STYLE ) & ~ES_READONLY );
718 es->style &= ~ES_READONLY;
723 case EM_SETWORDBREAKPROC16:
724 EDIT_EM_SetWordBreakProc16(es, (EDITWORDBREAKPROC16)lParam);
726 case EM_SETWORDBREAKPROC:
727 EDIT_EM_SetWordBreakProc(es, (void *)lParam);
730 case EM_GETWORDBREAKPROC16:
731 result = (LRESULT)es->word_break_proc16;
733 case EM_GETWORDBREAKPROC:
734 result = (LRESULT)es->word_break_proc;
737 case EM_GETPASSWORDCHAR16:
738 unicode = FALSE; /* 16-bit message is always ascii */
740 case EM_GETPASSWORDCHAR:
743 result = es->password_char;
746 WCHAR charW = es->password_char;
748 WideCharToMultiByte(CP_ACP, 0, &charW, 1, &charA, 1, NULL, NULL);
754 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
757 EDIT_EM_SetMargins(es, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
761 result = MAKELONG(es->left_margin, es->right_margin);
764 case EM_GETLIMITTEXT:
765 result = es->buffer_limit;
769 result = EDIT_EM_PosFromChar(es, (INT)wParam, FALSE);
773 result = EDIT_EM_CharFromPos(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
776 /* End of the EM_ messages which were in numerical order; what order
777 * are these in? vaguely alphabetical?
781 result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
783 if (es->style & ES_MULTILINE)
785 result |= DLGC_WANTALLKEYS;
789 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
791 int vk = (int)((LPMSG)lParam)->wParam;
793 if (es->hwndListBox && (vk == VK_RETURN || vk == VK_ESCAPE))
795 if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
796 result |= DLGC_WANTMESSAGE;
807 strng[0] = wParam >> 8;
808 strng[1] = wParam & 0xff;
809 if (strng[0]) MultiByteToWideChar(CP_ACP, 0, strng, 2, &charW, 1);
810 else MultiByteToWideChar(CP_ACP, 0, &strng[1], 1, &charW, 1);
811 EDIT_WM_Char(es, charW);
824 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
827 if ((charW == VK_RETURN || charW == VK_ESCAPE) && es->hwndListBox)
829 if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
830 SendMessageW(GetParent(hwnd), WM_KEYDOWN, charW, 0);
833 EDIT_WM_Char(es, charW);
842 EDIT_WM_Command(es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
846 EDIT_WM_ContextMenu(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
855 result = EDIT_WM_Create(es, ((LPCREATESTRUCTW)lParam)->lpszName);
858 LPCSTR nameA = ((LPCREATESTRUCTA)lParam)->lpszName;
862 INT countW = MultiByteToWideChar(CP_ACP, 0, nameA, -1, NULL, 0);
863 if((nameW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
864 MultiByteToWideChar(CP_ACP, 0, nameA, -1, nameW, countW);
866 result = EDIT_WM_Create(es, nameW);
867 HeapFree(GetProcessHeap(), 0, nameW);
876 es->bEnableState = (BOOL) wParam;
877 EDIT_UpdateText(es, NULL, TRUE);
881 result = EDIT_WM_EraseBkGnd(es, (HDC)wParam);
885 result = (LRESULT)es->font;
889 result = (LRESULT)EDIT_WM_GetText(es, (INT)wParam, (LPWSTR)lParam, unicode);
892 case WM_GETTEXTLENGTH:
893 if (unicode) result = strlenW(es->text);
894 else result = WideCharToMultiByte( CP_ACP, 0, es->text, strlenW(es->text),
895 NULL, 0, NULL, NULL );
899 result = EDIT_WM_HScroll(es, LOWORD(wParam), (short)HIWORD(wParam));
903 result = EDIT_WM_KeyDown(es, (INT)wParam);
907 result = EDIT_WM_KillFocus(es);
910 case WM_LBUTTONDBLCLK:
911 result = EDIT_WM_LButtonDblClk(es);
915 result = EDIT_WM_LButtonDown(es, wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
919 result = EDIT_WM_LButtonUp(es);
923 result = EDIT_WM_MButtonDown(es);
926 case WM_MOUSEACTIVATE:
927 result = MA_ACTIVATE;
931 result = EDIT_WM_MouseMove(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
935 EDIT_WM_Paint(es, (HDC)wParam);
943 EDIT_WM_SetFocus(es);
947 EDIT_WM_SetFont(es, (HFONT)wParam, LOWORD(lParam) != 0);
951 /* FIXME: actually set an internal flag and behave accordingly */
955 EDIT_WM_SetText(es, (LPCWSTR)lParam, unicode);
960 EDIT_WM_Size(es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam));
963 case WM_STYLECHANGED:
964 result = EDIT_WM_StyleChanged(es, wParam, (const STYLESTRUCT *)lParam);
967 case WM_STYLECHANGING:
968 result = 0; /* See EDIT_WM_StyleChanged */
972 result = EDIT_WM_SysKeyDown(es, (INT)wParam, (DWORD)lParam);
980 result = EDIT_WM_VScroll(es, LOWORD(wParam), (short)HIWORD(wParam));
985 int gcWheelDelta = 0;
986 UINT pulScrollLines = 3;
987 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
989 if (wParam & (MK_SHIFT | MK_CONTROL)) {
990 result = DefWindowProcW(hwnd, msg, wParam, lParam);
993 gcWheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
994 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
996 int cLineScroll= (int) min((UINT) es->line_count, pulScrollLines);
997 cLineScroll *= (gcWheelDelta / WHEEL_DELTA);
998 result = EDIT_EM_LineScroll(es, 0, cLineScroll);
1003 result = DefWindowProcT(hwnd, msg, wParam, lParam, unicode);
1007 if (es) EDIT_UnlockBuffer(es, FALSE);
1009 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd, msg, SPY_GetMsgName(msg, hwnd), result);
1014 /*********************************************************************
1016 * EditWndProcW (USER32.@)
1018 LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1020 return EditWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
1023 /*********************************************************************
1025 * EditWndProc (USER32.@)
1027 LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1029 return EditWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
1032 /*********************************************************************
1034 * EDIT_BuildLineDefs_ML
1036 * Build linked list of text lines.
1037 * Lines can end with '\0' (last line), a character (if it is wrapped),
1038 * a soft return '\r\r\n' or a hard return '\r\n'
1041 static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT istart, INT iend, INT delta, HRGN hrgn)
1045 LPWSTR current_position, cp;
1047 LINEDEF *current_line;
1048 LINEDEF *previous_line;
1049 LINEDEF *start_line;
1050 INT line_index = 0, nstart_line = 0, nstart_index = 0;
1051 INT line_count = es->line_count;
1052 INT orig_net_length;
1055 if (istart == iend && delta == 0)
1058 dc = GetDC(es->hwndSelf);
1060 old_font = SelectObject(dc, es->font);
1062 previous_line = NULL;
1063 current_line = es->first_line_def;
1065 /* Find starting line. istart must lie inside an existing line or
1066 * at the end of buffer */
1068 if (istart < current_line->index + current_line->length ||
1069 current_line->ending == END_0)
1072 previous_line = current_line;
1073 current_line = current_line->next;
1075 } while (current_line);
1077 if (!current_line) /* Error occurred start is not inside previous buffer */
1079 FIXME(" modification occurred outside buffer\n");
1080 ReleaseDC(es->hwndSelf, dc);
1084 /* Remember start of modifications in order to calculate update region */
1085 nstart_line = line_index;
1086 nstart_index = current_line->index;
1088 /* We must start to reformat from the previous line since the modifications
1089 * may have caused the line to wrap upwards. */
1090 if (!(es->style & ES_AUTOHSCROLL) && line_index > 0)
1093 current_line = previous_line;
1095 start_line = current_line;
1097 fw = es->format_rect.right - es->format_rect.left;
1098 current_position = es->text + current_line->index;
1100 if (current_line != start_line)
1102 if (!current_line || current_line->index + delta > current_position - es->text)
1104 /* The buffer has been expanded, create a new line and
1105 insert it into the link list */
1106 LINEDEF *new_line = HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF));
1107 new_line->next = previous_line->next;
1108 previous_line->next = new_line;
1109 current_line = new_line;
1112 else if (current_line->index + delta < current_position - es->text)
1114 /* The previous line merged with this line so we delete this extra entry */
1115 previous_line->next = current_line->next;
1116 HeapFree(GetProcessHeap(), 0, current_line);
1117 current_line = previous_line->next;
1121 else /* current_line->index + delta == current_position */
1123 if (current_position - es->text > iend)
1124 break; /* We reached end of line modifications */
1125 /* else recalulate this line */
1129 current_line->index = current_position - es->text;
1130 orig_net_length = current_line->net_length;
1132 /* Find end of line */
1133 cp = current_position;
1135 if (*cp == '\n') break;
1136 if ((*cp == '\r') && (*(cp + 1) == '\n'))
1141 /* Mark type of line termination */
1143 current_line->ending = END_0;
1144 current_line->net_length = strlenW(current_position);
1145 } else if ((cp > current_position) && (*(cp - 1) == '\r')) {
1146 current_line->ending = END_SOFT;
1147 current_line->net_length = cp - current_position - 1;
1148 } else if (*cp == '\n') {
1149 current_line->ending = END_RICH;
1150 current_line->net_length = cp - current_position;
1152 current_line->ending = END_HARD;
1153 current_line->net_length = cp - current_position;
1156 /* Calculate line width */
1157 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1158 current_position, current_line->net_length,
1159 es->tabs_count, es->tabs));
1161 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1162 if (!(es->style & ES_AUTOHSCROLL)) {
1163 if (current_line->width > fw) {
1168 next = EDIT_CallWordBreakProc(es, current_position - es->text,
1169 prev + 1, current_line->net_length, WB_RIGHT);
1170 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1171 current_position, next, es->tabs_count, es->tabs));
1172 } while (current_line->width <= fw);
1173 if (!prev) { /* Didn't find a line break so force a break */
1178 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1179 current_position, next, es->tabs_count, es->tabs));
1180 } while (current_line->width <= fw);
1185 /* If the first line we are calculating, wrapped before istart, we must
1186 * adjust istart in order for this to be reflected in the update region. */
1187 if (current_line->index == nstart_index && istart > current_line->index + prev)
1188 istart = current_line->index + prev;
1189 /* else if we are updating the previous line before the first line we
1190 * are re-calculating and it expanded */
1191 else if (current_line == start_line &&
1192 current_line->index != nstart_index && orig_net_length < prev)
1194 /* Line expanded due to an upwards line wrap so we must partially include
1195 * previous line in update region */
1196 nstart_line = line_index;
1197 nstart_index = current_line->index;
1198 istart = current_line->index + orig_net_length;
1201 current_line->net_length = prev;
1202 current_line->ending = END_WRAP;
1203 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, current_position,
1204 current_line->net_length, es->tabs_count, es->tabs));
1206 else if (orig_net_length < current_line->net_length &&
1207 current_line == start_line &&
1208 current_line->index != nstart_index) {
1209 /* The previous line expanded but it's still not as wide as the client rect */
1210 /* The expansion is due to an upwards line wrap so we must partially include
1211 it in the update region */
1212 nstart_line = line_index;
1213 nstart_index = current_line->index;
1214 istart = current_line->index + orig_net_length;
1219 /* Adjust length to include line termination */
1220 switch (current_line->ending) {
1222 current_line->length = current_line->net_length + 3;
1225 current_line->length = current_line->net_length + 1;
1228 current_line->length = current_line->net_length + 2;
1232 current_line->length = current_line->net_length;
1235 es->text_width = max(es->text_width, current_line->width);
1236 current_position += current_line->length;
1237 previous_line = current_line;
1238 current_line = current_line->next;
1240 } while (previous_line->ending != END_0);
1242 /* Finish adjusting line indexes by delta or remove hanging lines */
1243 if (previous_line->ending == END_0)
1245 LINEDEF *pnext = NULL;
1247 previous_line->next = NULL;
1248 while (current_line)
1250 pnext = current_line->next;
1251 HeapFree(GetProcessHeap(), 0, current_line);
1252 current_line = pnext;
1258 while (current_line)
1260 current_line->index += delta;
1261 current_line = current_line->next;
1265 /* Calculate rest of modification rectangle */
1270 * We calculate two rectangles. One for the first line which may have
1271 * an indent with respect to the format rect. The other is a format-width
1272 * rectangle that spans the rest of the lines that changed or moved.
1274 rc.top = es->format_rect.top + nstart_line * es->line_height -
1275 (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
1276 rc.bottom = rc.top + es->line_height;
1277 rc.left = es->format_rect.left + (INT)LOWORD(GetTabbedTextExtentW(dc,
1278 es->text + nstart_index, istart - nstart_index,
1279 es->tabs_count, es->tabs)) - es->x_offset; /* Adjust for horz scroll */
1280 rc.right = es->format_rect.right;
1281 SetRectRgn(hrgn, rc.left, rc.top, rc.right, rc.bottom);
1284 rc.left = es->format_rect.left;
1285 rc.right = es->format_rect.right;
1287 * If lines were added or removed we must re-paint the remainder of the
1288 * lines since the remaining lines were either shifted up or down.
1290 if (line_count < es->line_count) /* We added lines */
1291 rc.bottom = es->line_count * es->line_height;
1292 else if (line_count > es->line_count) /* We removed lines */
1293 rc.bottom = line_count * es->line_height;
1295 rc.bottom = line_index * es->line_height;
1296 rc.bottom -= (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
1297 tmphrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
1298 CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR);
1299 DeleteObject(tmphrgn);
1303 SelectObject(dc, old_font);
1305 ReleaseDC(es->hwndSelf, dc);
1308 /*********************************************************************
1310 * EDIT_CalcLineWidth_SL
1313 static void EDIT_CalcLineWidth_SL(EDITSTATE *es)
1315 es->text_width = (short)LOWORD(EDIT_EM_PosFromChar(es, strlenW(es->text), FALSE));
1318 /*********************************************************************
1320 * EDIT_CallWordBreakProc
1322 * Call appropriate WordBreakProc (internal or external).
1324 * Note: The "start" argument should always be an index referring
1325 * to es->text. The actual wordbreak proc might be
1326 * 16 bit, so we can't always pass any 32 bit LPSTR.
1327 * Hence we assume that es->text is the buffer that holds
1328 * the string under examination (we can decide this for ourselves).
1331 static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action)
1335 if (es->word_break_proc16) {
1342 countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
1343 hglob16 = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT, countA);
1344 segptr = K32WOWGlobalLock16(hglob16);
1345 WideCharToMultiByte(CP_ACP, 0, es->text + start, count, MapSL(segptr), countA, NULL, NULL);
1346 args[4] = SELECTOROF(segptr);
1347 args[3] = OFFSETOF(segptr);
1351 WOWCallback16Ex((DWORD)es->word_break_proc16, WCB16_PASCAL, sizeof(args), args, &result);
1352 ret = LOWORD(result);
1353 GlobalUnlock16(hglob16);
1354 GlobalFree16(hglob16);
1356 else if (es->word_break_proc)
1360 EDITWORDBREAKPROCW wbpW = (EDITWORDBREAKPROCW)es->word_break_proc;
1362 TRACE_(relay)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1363 es->word_break_proc, debugstr_wn(es->text + start, count), index, count, action);
1364 ret = wbpW(es->text + start, index, count, action);
1368 EDITWORDBREAKPROCA wbpA = (EDITWORDBREAKPROCA)es->word_break_proc;
1372 countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
1373 textA = HeapAlloc(GetProcessHeap(), 0, countA);
1374 WideCharToMultiByte(CP_ACP, 0, es->text + start, count, textA, countA, NULL, NULL);
1375 TRACE_(relay)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1376 es->word_break_proc, debugstr_an(textA, countA), index, countA, action);
1377 ret = wbpA(textA, index, countA, action);
1378 HeapFree(GetProcessHeap(), 0, textA);
1382 ret = EDIT_WordBreakProc(es->text + start, index, count, action);
1388 /*********************************************************************
1392 * Beware: This is not the function called on EM_CHARFROMPOS
1393 * The position _can_ be outside the formatting / client
1395 * The return value is only the character index
1398 static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
1404 if (es->style & ES_MULTILINE) {
1405 INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1407 LINEDEF *line_def = es->first_line_def;
1409 while ((line > 0) && line_def->next) {
1410 line_index += line_def->length;
1411 line_def = line_def->next;
1414 x += es->x_offset - es->format_rect.left;
1415 if (x >= line_def->width) {
1417 *after_wrap = (line_def->ending == END_WRAP);
1418 return line_index + line_def->net_length;
1422 *after_wrap = FALSE;
1425 dc = GetDC(es->hwndSelf);
1427 old_font = SelectObject(dc, es->font);
1428 low = line_index + 1;
1429 high = line_index + line_def->net_length + 1;
1430 while (low < high - 1)
1432 INT mid = (low + high) / 2;
1433 if (LOWORD(GetTabbedTextExtentW(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
1439 *after_wrap = ((index == line_index + line_def->net_length) &&
1440 (line_def->ending == END_WRAP));
1445 *after_wrap = FALSE;
1446 x -= es->format_rect.left;
1448 return es->x_offset;
1449 text = EDIT_GetPasswordPointer_SL(es);
1450 dc = GetDC(es->hwndSelf);
1452 old_font = SelectObject(dc, es->font);
1456 INT high = es->x_offset;
1457 while (low < high - 1)
1459 INT mid = (low + high) / 2;
1460 GetTextExtentPoint32W( dc, text + mid,
1461 es->x_offset - mid, &size );
1462 if (size.cx > -x) low = mid;
1469 INT low = es->x_offset;
1470 INT high = strlenW(es->text) + 1;
1471 while (low < high - 1)
1473 INT mid = (low + high) / 2;
1474 GetTextExtentPoint32W( dc, text + es->x_offset,
1475 mid - es->x_offset, &size );
1476 if (size.cx > x) high = mid;
1481 if (es->style & ES_PASSWORD)
1482 HeapFree(GetProcessHeap(), 0, text);
1485 SelectObject(dc, old_font);
1486 ReleaseDC(es->hwndSelf, dc);
1491 /*********************************************************************
1495 * adjusts the point to be within the formatting rectangle
1496 * (so CharFromPos returns the nearest _visible_ character)
1499 static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y)
1501 *x = min(max(*x, es->format_rect.left), es->format_rect.right - 1);
1502 *y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1);
1506 /*********************************************************************
1510 * Calculates the bounding rectangle for a line from a starting
1511 * column to an ending column.
1514 static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
1516 INT line_index = EDIT_EM_LineIndex(es, line);
1518 if (es->style & ES_MULTILINE)
1519 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1521 rc->top = es->format_rect.top;
1522 rc->bottom = rc->top + es->line_height;
1523 rc->left = (scol == 0) ? es->format_rect.left : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + scol, TRUE));
1524 rc->right = (ecol == -1) ? es->format_rect.right : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + ecol, TRUE));
1528 /*********************************************************************
1530 * EDIT_GetPasswordPointer_SL
1532 * note: caller should free the (optionally) allocated buffer
1535 static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es)
1537 if (es->style & ES_PASSWORD) {
1538 INT len = strlenW(es->text);
1539 LPWSTR text = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
1541 while(len) text[--len] = es->password_char;
1548 /*********************************************************************
1552 * This acts as a LOCAL_Lock(), but it locks only once. This way
1553 * you can call it whenever you like, without unlocking.
1555 * Initially the edit control allocates a HLOCAL32 buffer
1556 * (32 bit linear memory handler). However, 16 bit application
1557 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1558 * handler). From that moment on we have to keep using this 16 bit memory
1559 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1560 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1564 static void EDIT_LockBuffer(EDITSTATE *es)
1566 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
1570 BOOL _16bit = FALSE;
1576 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1577 textA = LocalLock(es->hloc32A);
1578 countA = strlen(textA) + 1;
1582 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1583 textA = LOCAL_Lock(hInstance, es->hloc16);
1584 countA = strlen(textA) + 1;
1589 ERR("no buffer ... please report\n");
1596 UINT countW_new = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
1597 TRACE("%d bytes translated to %d WCHARs\n", countA, countW_new);
1598 if(countW_new > es->buffer_size + 1)
1600 UINT alloc_size = ROUND_TO_GROW(countW_new * sizeof(WCHAR));
1601 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es->buffer_size, countW_new);
1602 hloc32W_new = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
1605 es->hloc32W = hloc32W_new;
1606 es->buffer_size = LocalSize(hloc32W_new)/sizeof(WCHAR) - 1;
1607 TRACE("Real new size %d+1 WCHARs\n", es->buffer_size);
1610 WARN("FAILED! Will synchronize partially\n");
1614 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1615 es->text = LocalLock(es->hloc32W);
1619 MultiByteToWideChar(CP_ACP, 0, textA, countA, es->text, es->buffer_size + 1);
1621 LOCAL_Unlock(hInstance, es->hloc16);
1623 LocalUnlock(es->hloc32A);
1630 /*********************************************************************
1632 * EDIT_SL_InvalidateText
1634 * Called from EDIT_InvalidateText().
1635 * Does the job for single-line controls only.
1638 static void EDIT_SL_InvalidateText(EDITSTATE *es, INT start, INT end)
1643 EDIT_GetLineRect(es, 0, start, end, &line_rect);
1644 if (IntersectRect(&rc, &line_rect, &es->format_rect))
1645 EDIT_UpdateText(es, &rc, TRUE);
1649 /*********************************************************************
1651 * EDIT_ML_InvalidateText
1653 * Called from EDIT_InvalidateText().
1654 * Does the job for multi-line controls only.
1657 static void EDIT_ML_InvalidateText(EDITSTATE *es, INT start, INT end)
1659 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1660 INT sl = EDIT_EM_LineFromChar(es, start);
1661 INT el = EDIT_EM_LineFromChar(es, end);
1670 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1673 sc = start - EDIT_EM_LineIndex(es, sl);
1674 ec = end - EDIT_EM_LineIndex(es, el);
1675 if (sl < es->y_offset) {
1679 if (el > es->y_offset + vlc) {
1680 el = es->y_offset + vlc;
1681 ec = EDIT_EM_LineLength(es, EDIT_EM_LineIndex(es, el));
1683 GetClientRect(es->hwndSelf, &rc1);
1684 IntersectRect(&rcWnd, &rc1, &es->format_rect);
1686 EDIT_GetLineRect(es, sl, sc, ec, &rcLine);
1687 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1688 EDIT_UpdateText(es, &rcUpdate, TRUE);
1690 EDIT_GetLineRect(es, sl, sc,
1691 EDIT_EM_LineLength(es,
1692 EDIT_EM_LineIndex(es, sl)),
1694 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1695 EDIT_UpdateText(es, &rcUpdate, TRUE);
1696 for (l = sl + 1 ; l < el ; l++) {
1697 EDIT_GetLineRect(es, l, 0,
1698 EDIT_EM_LineLength(es,
1699 EDIT_EM_LineIndex(es, l)),
1701 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1702 EDIT_UpdateText(es, &rcUpdate, TRUE);
1704 EDIT_GetLineRect(es, el, 0, ec, &rcLine);
1705 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1706 EDIT_UpdateText(es, &rcUpdate, TRUE);
1711 /*********************************************************************
1713 * EDIT_InvalidateText
1715 * Invalidate the text from offset start upto, but not including,
1716 * offset end. Useful for (re)painting the selection.
1717 * Regions outside the linewidth are not invalidated.
1718 * end == -1 means end == TextLength.
1719 * start and end need not be ordered.
1722 static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end)
1728 end = strlenW(es->text);
1736 if (es->style & ES_MULTILINE)
1737 EDIT_ML_InvalidateText(es, start, end);
1739 EDIT_SL_InvalidateText(es, start, end);
1743 /*********************************************************************
1747 * Try to fit size + 1 characters in the buffer.
1749 static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size)
1753 if (size <= es->buffer_size)
1756 TRACE("trying to ReAlloc to %d+1 characters\n", size);
1758 /* Force edit to unlock it's buffer. es->text now NULL */
1759 EDIT_UnlockBuffer(es, TRUE);
1762 UINT alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
1763 if ((hNew32W = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT))) {
1764 TRACE("Old 32 bit handle %p, new handle %p\n", es->hloc32W, hNew32W);
1765 es->hloc32W = hNew32W;
1766 es->buffer_size = LocalSize(hNew32W)/sizeof(WCHAR) - 1;
1770 EDIT_LockBuffer(es);
1772 if (es->buffer_size < size) {
1773 WARN("FAILED ! We now have %d+1\n", es->buffer_size);
1774 EDIT_NOTIFY_PARENT(es, EN_ERRSPACE, "EN_ERRSPACE");
1777 TRACE("We now have %d+1\n", es->buffer_size);
1783 /*********************************************************************
1787 * Try to fit size + 1 bytes in the undo buffer.
1790 static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size)
1794 if (size <= es->undo_buffer_size)
1797 TRACE("trying to ReAlloc to %d+1\n", size);
1799 alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
1800 if ((es->undo_text = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, es->undo_text, alloc_size))) {
1801 es->undo_buffer_size = alloc_size/sizeof(WCHAR) - 1;
1806 WARN("FAILED ! We now have %d+1\n", es->undo_buffer_size);
1812 /*********************************************************************
1817 static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend)
1819 INT e = es->selection_end;
1823 if ((es->style & ES_MULTILINE) && e &&
1824 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1826 if (e && (es->text[e - 1] == '\r'))
1830 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1831 EDIT_EM_ScrollCaret(es);
1835 /*********************************************************************
1839 * Only for multi line controls
1840 * Move the caret one line down, on a column with the nearest
1841 * x coordinate on the screen (might be a different column).
1844 static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend)
1846 INT s = es->selection_start;
1847 INT e = es->selection_end;
1848 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1849 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1850 INT x = (short)LOWORD(pos);
1851 INT y = (short)HIWORD(pos);
1853 e = EDIT_CharFromPos(es, x, y + es->line_height, &after_wrap);
1856 EDIT_EM_SetSel(es, s, e, after_wrap);
1857 EDIT_EM_ScrollCaret(es);
1861 /*********************************************************************
1866 static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend)
1868 BOOL after_wrap = FALSE;
1871 /* Pass a high value in x to make sure of receiving the end of the line */
1872 if (es->style & ES_MULTILINE)
1873 e = EDIT_CharFromPos(es, 0x3fffffff,
1874 HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1876 e = strlenW(es->text);
1877 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, after_wrap);
1878 EDIT_EM_ScrollCaret(es);
1882 /*********************************************************************
1887 static void EDIT_MoveForward(EDITSTATE *es, BOOL extend)
1889 INT e = es->selection_end;
1893 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1894 if (es->text[e] == '\n')
1896 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1900 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1901 EDIT_EM_ScrollCaret(es);
1905 /*********************************************************************
1909 * Home key: move to beginning of line.
1912 static void EDIT_MoveHome(EDITSTATE *es, BOOL extend)
1916 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1917 if (es->style & ES_MULTILINE)
1918 e = EDIT_CharFromPos(es, -es->x_offset,
1919 HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1922 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1923 EDIT_EM_ScrollCaret(es);
1927 /*********************************************************************
1929 * EDIT_MovePageDown_ML
1931 * Only for multi line controls
1932 * Move the caret one page down, on a column with the nearest
1933 * x coordinate on the screen (might be a different column).
1936 static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend)
1938 INT s = es->selection_start;
1939 INT e = es->selection_end;
1940 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1941 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1942 INT x = (short)LOWORD(pos);
1943 INT y = (short)HIWORD(pos);
1945 e = EDIT_CharFromPos(es, x,
1946 y + (es->format_rect.bottom - es->format_rect.top),
1950 EDIT_EM_SetSel(es, s, e, after_wrap);
1951 EDIT_EM_ScrollCaret(es);
1955 /*********************************************************************
1957 * EDIT_MovePageUp_ML
1959 * Only for multi line controls
1960 * Move the caret one page up, on a column with the nearest
1961 * x coordinate on the screen (might be a different column).
1964 static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend)
1966 INT s = es->selection_start;
1967 INT e = es->selection_end;
1968 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1969 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1970 INT x = (short)LOWORD(pos);
1971 INT y = (short)HIWORD(pos);
1973 e = EDIT_CharFromPos(es, x,
1974 y - (es->format_rect.bottom - es->format_rect.top),
1978 EDIT_EM_SetSel(es, s, e, after_wrap);
1979 EDIT_EM_ScrollCaret(es);
1983 /*********************************************************************
1987 * Only for multi line controls
1988 * Move the caret one line up, on a column with the nearest
1989 * x coordinate on the screen (might be a different column).
1992 static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend)
1994 INT s = es->selection_start;
1995 INT e = es->selection_end;
1996 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1997 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1998 INT x = (short)LOWORD(pos);
1999 INT y = (short)HIWORD(pos);
2001 e = EDIT_CharFromPos(es, x, y - es->line_height, &after_wrap);
2004 EDIT_EM_SetSel(es, s, e, after_wrap);
2005 EDIT_EM_ScrollCaret(es);
2009 /*********************************************************************
2011 * EDIT_MoveWordBackward
2014 static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend)
2016 INT s = es->selection_start;
2017 INT e = es->selection_end;
2022 l = EDIT_EM_LineFromChar(es, e);
2023 ll = EDIT_EM_LineLength(es, e);
2024 li = EDIT_EM_LineIndex(es, l);
2027 li = EDIT_EM_LineIndex(es, l - 1);
2028 e = li + EDIT_EM_LineLength(es, li);
2031 e = li + (INT)EDIT_CallWordBreakProc(es,
2032 li, e - li, ll, WB_LEFT);
2036 EDIT_EM_SetSel(es, s, e, FALSE);
2037 EDIT_EM_ScrollCaret(es);
2041 /*********************************************************************
2043 * EDIT_MoveWordForward
2046 static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend)
2048 INT s = es->selection_start;
2049 INT e = es->selection_end;
2054 l = EDIT_EM_LineFromChar(es, e);
2055 ll = EDIT_EM_LineLength(es, e);
2056 li = EDIT_EM_LineIndex(es, l);
2058 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
2059 e = EDIT_EM_LineIndex(es, l + 1);
2061 e = li + EDIT_CallWordBreakProc(es,
2062 li, e - li + 1, ll, WB_RIGHT);
2066 EDIT_EM_SetSel(es, s, e, FALSE);
2067 EDIT_EM_ScrollCaret(es);
2071 /*********************************************************************
2076 static void EDIT_PaintLine(EDITSTATE *es, HDC dc, INT line, BOOL rev)
2078 INT s = es->selection_start;
2079 INT e = es->selection_end;
2086 if (es->style & ES_MULTILINE) {
2087 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2088 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
2093 TRACE("line=%d\n", line);
2095 pos = EDIT_EM_PosFromChar(es, EDIT_EM_LineIndex(es, line), FALSE);
2096 x = (short)LOWORD(pos);
2097 y = (short)HIWORD(pos);
2098 li = EDIT_EM_LineIndex(es, line);
2099 ll = EDIT_EM_LineLength(es, li);
2100 s = min(es->selection_start, es->selection_end);
2101 e = max(es->selection_start, es->selection_end);
2102 s = min(li + ll, max(li, s));
2103 e = min(li + ll, max(li, e));
2104 if (rev && (s != e) &&
2105 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
2106 x += EDIT_PaintText(es, dc, x, y, line, 0, s - li, FALSE);
2107 x += EDIT_PaintText(es, dc, x, y, line, s - li, e - s, TRUE);
2108 x += EDIT_PaintText(es, dc, x, y, line, e - li, li + ll - e, FALSE);
2110 x += EDIT_PaintText(es, dc, x, y, line, 0, ll, FALSE);
2114 /*********************************************************************
2119 static INT EDIT_PaintText(EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
2130 BkMode = GetBkMode(dc);
2131 BkColor = GetBkColor(dc);
2132 TextColor = GetTextColor(dc);
2134 SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
2135 SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2136 SetBkMode( dc, OPAQUE);
2138 li = EDIT_EM_LineIndex(es, line);
2139 if (es->style & ES_MULTILINE) {
2140 ret = (INT)LOWORD(TabbedTextOutW(dc, x, y, es->text + li + col, count,
2141 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
2143 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
2144 TextOutW(dc, x, y, text + li + col, count);
2145 GetTextExtentPoint32W(dc, text + li + col, count, &size);
2147 if (es->style & ES_PASSWORD)
2148 HeapFree(GetProcessHeap(), 0, text);
2151 SetBkColor(dc, BkColor);
2152 SetTextColor(dc, TextColor);
2153 SetBkMode( dc, BkMode);
2159 /*********************************************************************
2164 static void EDIT_SetCaretPos(EDITSTATE *es, INT pos,
2167 LRESULT res = EDIT_EM_PosFromChar(es, pos, after_wrap);
2168 TRACE("%d - %dx%d\n", pos, (short)LOWORD(res), (short)HIWORD(res));
2169 SetCaretPos((short)LOWORD(res), (short)HIWORD(res));
2173 /*********************************************************************
2177 * note: this is not (exactly) the handler called on EM_SETRECTNP
2178 * it is also used to set the rect of a single line control
2181 static void EDIT_SetRectNP(EDITSTATE *es, LPRECT rc)
2186 CopyRect(&es->format_rect, rc);
2187 if (es->style & ES_MULTILINE)
2189 if (es->style & WS_BORDER) {
2190 INT bw = GetSystemMetrics(SM_CXBORDER) + 1;
2191 es->format_rect.left += bw;
2192 es->format_rect.right -= bw;
2193 es->format_rect.top += bw;
2194 es->format_rect.bottom -= bw;
2199 ExStyle = GetWindowLongPtrW(es->hwndSelf, GWL_EXSTYLE);
2200 if (ExStyle & WS_EX_CLIENTEDGE) {
2201 if (es->line_height + 2 <=
2202 es->format_rect.bottom - es->format_rect.top) {
2203 es->format_rect.top++;
2204 es->format_rect.bottom--;
2206 } else if (es->style & WS_BORDER) {
2207 INT bw = GetSystemMetrics(SM_CXBORDER) + 1;
2208 es->format_rect.left += bw;
2209 es->format_rect.right -= bw;
2210 if (es->line_height + 2 * bw <=
2211 es->format_rect.bottom - es->format_rect.top) {
2212 es->format_rect.top += bw;
2213 es->format_rect.bottom -= bw;
2217 es->format_rect.left += es->left_margin;
2218 es->format_rect.right -= es->right_margin;
2219 es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width);
2220 if (es->style & ES_MULTILINE)
2222 INT fw, vlc, max_x_offset, max_y_offset;
2224 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2225 es->format_rect.bottom = es->format_rect.top + max(1, vlc) * es->line_height;
2227 /* correct es->x_offset */
2228 fw = es->format_rect.right - es->format_rect.left;
2229 max_x_offset = es->text_width - fw;
2230 if(max_x_offset < 0) max_x_offset = 0;
2231 if(es->x_offset > max_x_offset)
2232 es->x_offset = max_x_offset;
2234 /* correct es->y_offset */
2235 max_y_offset = es->line_count - vlc;
2236 if(max_y_offset < 0) max_y_offset = 0;
2237 if(es->y_offset > max_y_offset)
2238 es->y_offset = max_y_offset;
2240 /* force scroll info update */
2241 EDIT_UpdateScrollInfo(es);
2244 /* Windows doesn't care to fix text placement for SL controls */
2245 es->format_rect.bottom = es->format_rect.top + es->line_height;
2247 /* Always stay within the client area */
2248 GetClientRect(es->hwndSelf, &ClientRect);
2249 es->format_rect.bottom = min(es->format_rect.bottom, ClientRect.bottom);
2251 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
2252 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
2256 /*********************************************************************
2261 static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force)
2263 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
2265 /* Edit window might be already destroyed */
2266 if(!IsWindow(es->hwndSelf))
2268 WARN("edit hwnd %p already destroyed\n", es->hwndSelf);
2272 if (!es->lock_count) {
2273 ERR("lock_count == 0 ... please report\n");
2277 ERR("es->text == 0 ... please report\n");
2281 if (force || (es->lock_count == 1)) {
2284 BOOL _16bit = FALSE;
2286 UINT countW = strlenW(es->text) + 1;
2290 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
2291 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2292 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
2293 countA = LocalSize(es->hloc32A);
2294 if(countA_new > countA)
2297 UINT alloc_size = ROUND_TO_GROW(countA_new);
2298 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2299 hloc32A_new = LocalReAlloc(es->hloc32A, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2302 es->hloc32A = hloc32A_new;
2303 countA = LocalSize(hloc32A_new);
2304 TRACE("Real new size %d bytes\n", countA);
2307 WARN("FAILED! Will synchronize partially\n");
2309 textA = LocalLock(es->hloc32A);
2313 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
2314 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2315 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
2316 countA = LOCAL_Size(hInstance, es->hloc16);
2317 if(countA_new > countA)
2319 HLOCAL16 hloc16_new;
2320 UINT alloc_size = ROUND_TO_GROW(countA_new);
2321 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2322 hloc16_new = LOCAL_ReAlloc(hInstance, es->hloc16, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2325 es->hloc16 = hloc16_new;
2326 countA = LOCAL_Size(hInstance, hloc16_new);
2327 TRACE("Real new size %d bytes\n", countA);
2330 WARN("FAILED! Will synchronize partially\n");
2332 textA = LOCAL_Lock(hInstance, es->hloc16);
2338 WideCharToMultiByte(CP_ACP, 0, es->text, countW, textA, countA, NULL, NULL);
2340 LOCAL_Unlock(hInstance, es->hloc16);
2342 LocalUnlock(es->hloc32A);
2345 LocalUnlock(es->hloc32W);
2349 ERR("no buffer ... please report\n");
2357 /*********************************************************************
2359 * EDIT_UpdateScrollInfo
2362 static void EDIT_UpdateScrollInfo(EDITSTATE *es)
2364 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
2367 si.cbSize = sizeof(SCROLLINFO);
2368 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2370 si.nMax = es->line_count - 1;
2371 si.nPage = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2372 si.nPos = es->y_offset;
2373 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2374 si.nMin, si.nMax, si.nPage, si.nPos);
2375 SetScrollInfo(es->hwndSelf, SB_VERT, &si, TRUE);
2378 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
2381 si.cbSize = sizeof(SCROLLINFO);
2382 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2384 si.nMax = es->text_width - 1;
2385 si.nPage = es->format_rect.right - es->format_rect.left;
2386 si.nPos = es->x_offset;
2387 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2388 si.nMin, si.nMax, si.nPage, si.nPos);
2389 SetScrollInfo(es->hwndSelf, SB_HORZ, &si, TRUE);
2393 /*********************************************************************
2395 * EDIT_WordBreakProc
2397 * Find the beginning of words.
2398 * Note: unlike the specs for a WordBreakProc, this function only
2399 * allows to be called without linebreaks between s[0] upto
2400 * s[count - 1]. Remember it is only called
2401 * internally, so we can decide this for ourselves.
2404 static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action)
2408 TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action);
2418 if (s[index] == ' ') {
2419 while (index && (s[index] == ' '))
2422 while (index && (s[index] != ' '))
2424 if (s[index] == ' ')
2428 while (index && (s[index] != ' '))
2430 if (s[index] == ' ')
2440 if (s[index] == ' ')
2441 while ((index < count) && (s[index] == ' ')) index++;
2443 while (s[index] && (s[index] != ' ') && (index < count))
2445 while ((s[index] == ' ') && (index < count)) index++;
2449 case WB_ISDELIMITER:
2450 ret = (s[index] == ' ');
2453 ERR("unknown action code, please report !\n");
2460 /*********************************************************************
2464 * returns line number (not index) in high-order word of result.
2465 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2466 * to Richedit, not to the edit control. Original documentation is valid.
2467 * FIXME: do the specs mean to return -1 if outside client area or
2468 * if outside formatting rectangle ???
2471 static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y)
2479 GetClientRect(es->hwndSelf, &rc);
2480 if (!PtInRect(&rc, pt))
2483 index = EDIT_CharFromPos(es, x, y, NULL);
2484 return MAKELONG(index, EDIT_EM_LineFromChar(es, index));
2488 /*********************************************************************
2492 * Enable or disable soft breaks.
2494 * This means: insert or remove the soft linebreak character (\r\r\n).
2495 * Take care to check if the text still fits the buffer after insertion.
2496 * If not, notify with EN_ERRSPACE.
2499 static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol)
2501 es->flags &= ~EF_USE_SOFTBRK;
2503 es->flags |= EF_USE_SOFTBRK;
2504 FIXME("soft break enabled, not implemented\n");
2510 /*********************************************************************
2514 * Hopefully this won't fire back at us.
2515 * We always start with a fixed buffer in the local heap.
2516 * Despite of the documentation says that the local heap is used
2517 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2518 * buffer on the local heap.
2521 static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es)
2525 if (!(es->style & ES_MULTILINE))
2529 hLocal = es->hloc32W;
2535 UINT countA, alloc_size;
2536 TRACE("Allocating 32-bit ANSI alias buffer\n");
2537 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
2538 alloc_size = ROUND_TO_GROW(countA);
2539 if(!(es->hloc32A = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2541 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size);
2544 textA = LocalLock(es->hloc32A);
2545 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
2546 LocalUnlock(es->hloc32A);
2548 hLocal = es->hloc32A;
2551 TRACE("Returning %p, LocalSize() = %ld\n", hLocal, LocalSize(hLocal));
2556 /*********************************************************************
2560 * Hopefully this won't fire back at us.
2561 * We always start with a buffer in 32 bit linear memory.
2562 * However, with this message a 16 bit application requests
2563 * a handle of 16 bit local heap memory, where it expects to find
2565 * It's a pitty that from this moment on we have to use this
2566 * local heap, because applications may rely on the handle
2569 * In this function we'll try to switch to local heap.
2571 static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es)
2573 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
2575 UINT countA, alloc_size;
2577 if (!(es->style & ES_MULTILINE))
2583 if (!LOCAL_HeapSize(hInstance)) {
2584 if (!LocalInit16(hInstance, 0,
2585 GlobalSize16(hInstance))) {
2586 ERR("could not initialize local heap\n");
2589 TRACE("local heap initialized\n");
2592 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
2593 alloc_size = ROUND_TO_GROW(countA);
2595 TRACE("Allocating 16-bit ANSI alias buffer\n");
2596 if (!(es->hloc16 = LOCAL_Alloc(hInstance, LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) {
2597 ERR("could not allocate new 16 bit buffer\n");
2601 if (!(textA = (LPSTR)LOCAL_Lock(hInstance, es->hloc16))) {
2602 ERR("could not lock new 16 bit buffer\n");
2603 LOCAL_Free(hInstance, es->hloc16);
2608 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
2609 LOCAL_Unlock(hInstance, es->hloc16);
2611 TRACE("Returning %04X, LocalSize() = %d\n", es->hloc16, LOCAL_Size(hInstance, es->hloc16));
2616 /*********************************************************************
2621 static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPWSTR dst, BOOL unicode)
2624 INT line_len, dst_len;
2627 if (es->style & ES_MULTILINE) {
2628 if (line >= es->line_count)
2632 i = EDIT_EM_LineIndex(es, line);
2634 line_len = EDIT_EM_LineLength(es, i);
2635 dst_len = *(WORD *)dst;
2638 if(dst_len <= line_len)
2640 memcpy(dst, src, dst_len * sizeof(WCHAR));
2643 else /* Append 0 if enough space */
2645 memcpy(dst, src, line_len * sizeof(WCHAR));
2652 INT ret = WideCharToMultiByte(CP_ACP, 0, src, line_len, (LPSTR)dst, dst_len, NULL, NULL);
2653 if(!ret) /* Insufficient buffer size */
2655 if(ret < dst_len) /* Append 0 if enough space */
2656 ((LPSTR)dst)[ret] = 0;
2662 /*********************************************************************
2667 static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end)
2669 UINT s = es->selection_start;
2670 UINT e = es->selection_end;
2677 return MAKELONG(s, e);
2681 /*********************************************************************
2685 * FIXME: is this right ? (or should it be only VSCROLL)
2686 * (and maybe only for edit controls that really have their
2687 * own scrollbars) (and maybe only for multiline controls ?)
2688 * All in all: very poorly documented
2691 static LRESULT EDIT_EM_GetThumb(EDITSTATE *es)
2693 return MAKELONG(EDIT_WM_VScroll(es, EM_GETTHUMB16, 0),
2694 EDIT_WM_HScroll(es, EM_GETTHUMB16, 0));
2698 /*********************************************************************
2703 static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index)
2708 if (!(es->style & ES_MULTILINE))
2710 if (index > (INT)strlenW(es->text))
2711 return es->line_count - 1;
2713 index = min(es->selection_start, es->selection_end);
2716 line_def = es->first_line_def;
2717 index -= line_def->length;
2718 while ((index >= 0) && line_def->next) {
2720 line_def = line_def->next;
2721 index -= line_def->length;
2727 /*********************************************************************
2732 static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line)
2737 if (!(es->style & ES_MULTILINE))
2739 if (line >= es->line_count)
2743 line_def = es->first_line_def;
2745 INT index = es->selection_end - line_def->length;
2746 while ((index >= 0) && line_def->next) {
2747 line_index += line_def->length;
2748 line_def = line_def->next;
2749 index -= line_def->length;
2753 line_index += line_def->length;
2754 line_def = line_def->next;
2762 /*********************************************************************
2767 static INT EDIT_EM_LineLength(EDITSTATE *es, INT index)
2771 if (!(es->style & ES_MULTILINE))
2772 return strlenW(es->text);
2775 /* get the number of remaining non-selected chars of selected lines */
2776 INT32 l; /* line number */
2777 INT32 li; /* index of first char in line */
2779 l = EDIT_EM_LineFromChar(es, es->selection_start);
2780 /* # chars before start of selection area */
2781 count = es->selection_start - EDIT_EM_LineIndex(es, l);
2782 l = EDIT_EM_LineFromChar(es, es->selection_end);
2783 /* # chars after end of selection */
2784 li = EDIT_EM_LineIndex(es, l);
2785 count += li + EDIT_EM_LineLength(es, li) - es->selection_end;
2788 line_def = es->first_line_def;
2789 index -= line_def->length;
2790 while ((index >= 0) && line_def->next) {
2791 line_def = line_def->next;
2792 index -= line_def->length;
2794 return line_def->net_length;
2798 /*********************************************************************
2802 * NOTE: dx is in average character widths, dy - in lines;
2805 static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy)
2807 if (!(es->style & ES_MULTILINE))
2810 dx *= es->char_width;
2811 return EDIT_EM_LineScroll_internal(es, dx, dy);
2814 /*********************************************************************
2816 * EDIT_EM_LineScroll_internal
2818 * Version of EDIT_EM_LineScroll for internal use.
2819 * It doesn't refuse if ES_MULTILINE is set and assumes that
2820 * dx is in pixels, dy - in lines.
2823 static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy)
2826 INT x_offset_in_pixels;
2827 INT lines_per_page = (es->format_rect.bottom - es->format_rect.top) /
2830 if (es->style & ES_MULTILINE)
2832 x_offset_in_pixels = es->x_offset;
2837 x_offset_in_pixels = (short)LOWORD(EDIT_EM_PosFromChar(es, es->x_offset, FALSE));
2840 if (-dx > x_offset_in_pixels)
2841 dx = -x_offset_in_pixels;
2842 if (dx > es->text_width - x_offset_in_pixels)
2843 dx = es->text_width - x_offset_in_pixels;
2844 nyoff = max(0, es->y_offset + dy);
2845 if (nyoff >= es->line_count - lines_per_page)
2846 nyoff = max(0, es->line_count - lines_per_page);
2847 dy = (es->y_offset - nyoff) * es->line_height;
2852 es->y_offset = nyoff;
2853 if(es->style & ES_MULTILINE)
2856 es->x_offset += dx / es->char_width;
2858 GetClientRect(es->hwndSelf, &rc1);
2859 IntersectRect(&rc, &rc1, &es->format_rect);
2860 ScrollWindowEx(es->hwndSelf, -dx, dy,
2861 NULL, &rc, NULL, NULL, SW_INVALIDATE);
2862 /* force scroll info update */
2863 EDIT_UpdateScrollInfo(es);
2865 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2866 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
2867 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2868 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
2873 /*********************************************************************
2878 static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap)
2880 INT len = strlenW(es->text);
2889 index = min(index, len);
2890 dc = GetDC(es->hwndSelf);
2892 old_font = SelectObject(dc, es->font);
2893 if (es->style & ES_MULTILINE) {
2894 l = EDIT_EM_LineFromChar(es, index);
2895 y = (l - es->y_offset) * es->line_height;
2896 li = EDIT_EM_LineIndex(es, l);
2897 if (after_wrap && (li == index) && l) {
2899 LINEDEF *line_def = es->first_line_def;
2901 line_def = line_def->next;
2904 if (line_def->ending == END_WRAP) {
2906 y -= es->line_height;
2907 li = EDIT_EM_LineIndex(es, l);
2910 x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li,
2911 es->tabs_count, es->tabs)) - es->x_offset;
2913 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
2914 if (index < es->x_offset) {
2915 GetTextExtentPoint32W(dc, text + index,
2916 es->x_offset - index, &size);
2919 GetTextExtentPoint32W(dc, text + es->x_offset,
2920 index - es->x_offset, &size);
2924 if (es->style & ES_PASSWORD)
2925 HeapFree(GetProcessHeap(), 0, text);
2927 x += es->format_rect.left;
2928 y += es->format_rect.top;
2930 SelectObject(dc, old_font);
2931 ReleaseDC(es->hwndSelf, dc);
2932 return MAKELONG((INT16)x, (INT16)y);
2936 /*********************************************************************
2940 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2943 static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit)
2945 UINT strl = strlenW(lpsz_replace);
2946 UINT tl = strlenW(es->text);
2955 TRACE("%s, can_undo %d, send_update %d\n",
2956 debugstr_w(lpsz_replace), can_undo, send_update);
2958 s = es->selection_start;
2959 e = es->selection_end;
2961 if ((s == e) && !strl)
2966 /* Issue the EN_MAXTEXT notification and continue with replacing text
2967 * such that buffer limit is honored. */
2968 size = tl - (e - s) + strl;
2969 if ((honor_limit) && (es->buffer_limit > 0) && (size > es->buffer_limit)) {
2970 EDIT_NOTIFY_PARENT(es, EN_MAXTEXT, "EN_MAXTEXT");
2971 strl = es->buffer_limit - (tl - (e-s));
2974 if (!EDIT_MakeFit(es, tl - (e - s) + strl))
2978 /* there is something to be deleted */
2979 TRACE("deleting stuff.\n");
2981 utl = strlenW(es->undo_text);
2982 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
2983 /* undo-buffer is extended to the right */
2984 EDIT_MakeUndoFit(es, utl + e - s);
2985 strncpyW(es->undo_text + utl, es->text + s, e - s + 1);
2986 (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */
2987 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
2988 /* undo-buffer is extended to the left */
2989 EDIT_MakeUndoFit(es, utl + e - s);
2990 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
2992 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2993 p[i] = (es->text + s)[i];
2994 es->undo_position = s;
2996 /* new undo-buffer */
2997 EDIT_MakeUndoFit(es, e - s);
2998 strncpyW(es->undo_text, es->text + s, e - s + 1);
2999 es->undo_text[e - s] = 0; /* ensure 0 termination */
3000 es->undo_position = s;
3002 /* any deletion makes the old insertion-undo invalid */
3003 es->undo_insert_count = 0;
3005 EDIT_EM_EmptyUndoBuffer(es);
3008 strcpyW(es->text + s, es->text + e);
3011 /* there is an insertion */
3013 if ((s == es->undo_position) ||
3014 ((es->undo_insert_count) &&
3015 (s == es->undo_position + es->undo_insert_count)))
3017 * insertion is new and at delete position or
3018 * an extension to either left or right
3020 es->undo_insert_count += strl;
3022 /* new insertion undo */
3023 es->undo_position = s;
3024 es->undo_insert_count = strl;
3025 /* new insertion makes old delete-buffer invalid */
3026 *es->undo_text = '\0';
3029 EDIT_EM_EmptyUndoBuffer(es);
3032 tl = strlenW(es->text);
3033 TRACE("inserting stuff (tl %d, strl %d, selstart %d ('%s'), text '%s')\n", tl, strl, s, debugstr_w(es->text + s), debugstr_w(es->text));
3034 for (p = es->text + tl ; p >= es->text + s ; p--)
3036 for (i = 0 , p = es->text + s ; i < strl ; i++)
3037 p[i] = lpsz_replace[i];
3038 if(es->style & ES_UPPERCASE)
3039 CharUpperBuffW(p, strl);
3040 else if(es->style & ES_LOWERCASE)
3041 CharLowerBuffW(p, strl);
3044 if (es->style & ES_MULTILINE)
3046 INT s = min(es->selection_start, es->selection_end);
3048 hrgn = CreateRectRgn(0, 0, 0, 0);
3049 EDIT_BuildLineDefs_ML(es, s, s + strl,
3050 strl - abs(es->selection_end - es->selection_start), hrgn);
3053 EDIT_CalcLineWidth_SL(es);
3055 EDIT_EM_SetSel(es, s, s, FALSE);
3056 es->flags |= EF_MODIFIED;
3057 if (send_update) es->flags |= EF_UPDATE;
3060 EDIT_UpdateTextRegion(es, hrgn, TRUE);
3064 EDIT_UpdateText(es, NULL, TRUE);
3066 EDIT_EM_ScrollCaret(es);
3068 /* force scroll info update */
3069 EDIT_UpdateScrollInfo(es);
3072 if(es->flags & EF_UPDATE)
3074 es->flags &= ~EF_UPDATE;
3075 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3080 /*********************************************************************
3085 static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
3089 if (!(es->style & ES_MULTILINE))
3090 return (LRESULT)FALSE;
3100 if (es->y_offset < es->line_count - 1)
3105 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
3108 if (es->y_offset < es->line_count - 1)
3109 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3112 return (LRESULT)FALSE;
3115 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3116 /* check if we are going to move too far */
3117 if(es->y_offset + dy > es->line_count - vlc)
3118 dy = es->line_count - vlc - es->y_offset;
3120 /* Notification is done in EDIT_EM_LineScroll */
3122 EDIT_EM_LineScroll(es, 0, dy);
3124 return MAKELONG((INT16)dy, (BOOL16)TRUE);
3128 /*********************************************************************
3133 static void EDIT_EM_ScrollCaret(EDITSTATE *es)
3135 if (es->style & ES_MULTILINE) {
3140 INT cw = es->char_width;
3145 l = EDIT_EM_LineFromChar(es, es->selection_end);
3146 li = EDIT_EM_LineIndex(es, l);
3147 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP));
3148 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3149 if (l >= es->y_offset + vlc)
3150 dy = l - vlc + 1 - es->y_offset;
3151 if (l < es->y_offset)
3152 dy = l - es->y_offset;
3153 ww = es->format_rect.right - es->format_rect.left;
3154 if (x < es->format_rect.left)
3155 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
3156 if (x > es->format_rect.right)
3157 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
3160 /* check if we are going to move too far */
3161 if(es->x_offset + dx + ww > es->text_width)
3162 dx = es->text_width - ww - es->x_offset;
3164 EDIT_EM_LineScroll_internal(es, dx, dy);
3171 if (!(es->style & ES_AUTOHSCROLL))
3174 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3175 format_width = es->format_rect.right - es->format_rect.left;
3176 if (x < es->format_rect.left) {
3177 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
3180 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3181 } while ((x < goal) && es->x_offset);
3182 /* FIXME: use ScrollWindow() somehow to improve performance */
3183 EDIT_UpdateText(es, NULL, TRUE);
3184 } else if (x > es->format_rect.right) {
3186 INT len = strlenW(es->text);
3187 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
3190 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3191 x_last = (short)LOWORD(EDIT_EM_PosFromChar(es, len, FALSE));
3192 } while ((x > goal) && (x_last > es->format_rect.right));
3193 /* FIXME: use ScrollWindow() somehow to improve performance */
3194 EDIT_UpdateText(es, NULL, TRUE);
3198 if(es->flags & EF_FOCUSED)
3199 EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
3203 /*********************************************************************
3207 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3210 static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc)
3212 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
3214 if (!(es->style & ES_MULTILINE))
3218 WARN("called with NULL handle\n");
3222 EDIT_UnlockBuffer(es, TRUE);
3226 LOCAL_Free(hInstance, es->hloc16);
3227 es->hloc16 = (HLOCAL16)NULL;
3234 LocalFree(es->hloc32A);
3246 countA = LocalSize(hloc);
3247 textA = LocalLock(hloc);
3248 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3249 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3251 ERR("Could not allocate new unicode buffer\n");
3254 textW = LocalLock(hloc32W_new);
3255 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3256 LocalUnlock(hloc32W_new);
3260 LocalFree(es->hloc32W);
3262 es->hloc32W = hloc32W_new;
3266 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3268 EDIT_LockBuffer(es);
3270 es->x_offset = es->y_offset = 0;
3271 es->selection_start = es->selection_end = 0;
3272 EDIT_EM_EmptyUndoBuffer(es);
3273 es->flags &= ~EF_MODIFIED;
3274 es->flags &= ~EF_UPDATE;
3275 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3276 EDIT_UpdateText(es, NULL, TRUE);
3277 EDIT_EM_ScrollCaret(es);
3278 /* force scroll info update */
3279 EDIT_UpdateScrollInfo(es);
3283 /*********************************************************************
3287 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3290 static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc)
3292 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
3298 if (!(es->style & ES_MULTILINE))
3302 WARN("called with NULL handle\n");
3306 EDIT_UnlockBuffer(es, TRUE);
3310 LocalFree(es->hloc32A);
3314 countA = LOCAL_Size(hInstance, hloc);
3315 textA = LOCAL_Lock(hInstance, hloc);
3316 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3317 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3319 ERR("Could not allocate new unicode buffer\n");
3322 textW = LocalLock(hloc32W_new);
3323 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3324 LocalUnlock(hloc32W_new);
3325 LOCAL_Unlock(hInstance, hloc);
3328 LocalFree(es->hloc32W);
3330 es->hloc32W = hloc32W_new;
3333 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3335 EDIT_LockBuffer(es);
3337 es->x_offset = es->y_offset = 0;
3338 es->selection_start = es->selection_end = 0;
3339 EDIT_EM_EmptyUndoBuffer(es);
3340 es->flags &= ~EF_MODIFIED;
3341 es->flags &= ~EF_UPDATE;
3342 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3343 EDIT_UpdateText(es, NULL, TRUE);
3344 EDIT_EM_ScrollCaret(es);
3345 /* force scroll info update */
3346 EDIT_UpdateScrollInfo(es);
3350 /*********************************************************************
3354 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3355 * However, the windows version is not complied to yet in all of edit.c
3357 * Additionally as the wrapper for RichEdit controls we need larger buffers
3358 * at present -1 will represent nolimit
3360 static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit)
3362 if (limit == 0xFFFFFFFF)
3363 es->buffer_limit = -1;
3364 else if (es->style & ES_MULTILINE) {
3366 es->buffer_limit = min(limit, BUFLIMIT_MULTI);
3368 es->buffer_limit = BUFLIMIT_MULTI;
3371 es->buffer_limit = min(limit, BUFLIMIT_SINGLE);
3373 es->buffer_limit = BUFLIMIT_SINGLE;
3378 /*********************************************************************
3382 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3383 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3384 * margin according to the textmetrics of the current font.
3386 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3387 * of the char's width as the margin, but this is not how Windows handles this.
3388 * For all other fonts Windows sets the margins to zero.
3391 static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
3392 INT left, INT right)
3395 INT default_left_margin = 0; /* in pixels */
3396 INT default_right_margin = 0; /* in pixels */
3398 /* Set the default margins depending on the font */
3399 if (es->font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO)) {
3400 HDC dc = GetDC(es->hwndSelf);
3401 HFONT old_font = SelectObject(dc, es->font);
3402 GetTextMetricsW(dc, &tm);
3403 /* The default margins are only non zero for TrueType or Vector fonts */
3404 if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) {
3405 /* This must be calculated more exactly! But how? */
3406 default_left_margin = tm.tmAveCharWidth / 3;
3407 default_right_margin = tm.tmAveCharWidth / 3;
3409 SelectObject(dc, old_font);
3410 ReleaseDC(es->hwndSelf, dc);
3413 if (action & EC_LEFTMARGIN) {
3414 if (left != EC_USEFONTINFO)
3415 es->left_margin = left;
3417 es->left_margin = default_left_margin;
3420 if (action & EC_RIGHTMARGIN) {
3421 if (right != EC_USEFONTINFO)
3422 es->right_margin = right;
3424 es->right_margin = default_right_margin;
3426 TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin);
3430 /*********************************************************************
3432 * EM_SETPASSWORDCHAR
3435 static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c)
3439 if (es->style & ES_MULTILINE)
3442 if (es->password_char == c)
3445 style = GetWindowLongW( es->hwndSelf, GWL_STYLE );
3446 es->password_char = c;
3448 SetWindowLongW( es->hwndSelf, GWL_STYLE, style | ES_PASSWORD );
3449 es->style |= ES_PASSWORD;
3451 SetWindowLongW( es->hwndSelf, GWL_STYLE, style & ~ES_PASSWORD );
3452 es->style &= ~ES_PASSWORD;
3454 EDIT_UpdateText(es, NULL, TRUE);
3458 /*********************************************************************
3462 * note: unlike the specs say: the order of start and end
3463 * _is_ preserved in Windows. (i.e. start can be > end)
3464 * In other words: this handler is OK
3467 static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
3469 UINT old_start = es->selection_start;
3470 UINT old_end = es->selection_end;
3471 UINT len = strlenW(es->text);
3473 if (start == (UINT)-1) {
3474 start = es->selection_end;
3475 end = es->selection_end;
3477 start = min(start, len);
3478 end = min(end, len);
3480 es->selection_start = start;
3481 es->selection_end = end;
3483 es->flags |= EF_AFTER_WRAP;
3485 es->flags &= ~EF_AFTER_WRAP;
3486 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3487 ORDER_UINT(start, end);
3488 ORDER_UINT(end, old_end);
3489 ORDER_UINT(start, old_start);
3490 ORDER_UINT(old_start, old_end);
3491 if (end != old_start)
3495 * ORDER_UINT32(end, old_start);
3496 * EDIT_InvalidateText(es, start, end);
3497 * EDIT_InvalidateText(es, old_start, old_end);
3498 * in place of the following if statement.
3500 if (old_start > end )
3502 EDIT_InvalidateText(es, start, end);
3503 EDIT_InvalidateText(es, old_start, old_end);
3507 EDIT_InvalidateText(es, start, old_start);
3508 EDIT_InvalidateText(es, end, old_end);
3511 else EDIT_InvalidateText(es, start, old_end);
3515 /*********************************************************************
3520 static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs)
3522 if (!(es->style & ES_MULTILINE))
3524 HeapFree(GetProcessHeap(), 0, es->tabs);
3525 es->tabs_count = count;
3529 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
3530 memcpy(es->tabs, tabs, count * sizeof(INT));
3536 /*********************************************************************
3541 static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs)
3543 if (!(es->style & ES_MULTILINE))
3545 HeapFree(GetProcessHeap(), 0, es->tabs);
3546 es->tabs_count = count;
3551 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
3552 for (i = 0 ; i < count ; i++)
3553 es->tabs[i] = *tabs++;
3559 /*********************************************************************
3561 * EM_SETWORDBREAKPROC
3564 static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, void *wbp)
3566 if (es->word_break_proc == wbp)
3569 es->word_break_proc = wbp;
3570 es->word_break_proc16 = NULL;
3572 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
3573 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3574 EDIT_UpdateText(es, NULL, TRUE);
3579 /*********************************************************************
3581 * EM_SETWORDBREAKPROC16
3584 static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
3586 if (es->word_break_proc16 == wbp)
3589 es->word_break_proc = NULL;
3590 es->word_break_proc16 = wbp;
3591 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
3592 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3593 EDIT_UpdateText(es, NULL, TRUE);
3598 /*********************************************************************
3603 static BOOL EDIT_EM_Undo(EDITSTATE *es)
3608 /* As per MSDN spec, for a single-line edit control,
3609 the return value is always TRUE */
3610 if( es->style & ES_READONLY )
3611 return !(es->style & ES_MULTILINE);
3613 ulength = strlenW(es->undo_text);
3615 utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR));
3617 strcpyW(utext, es->undo_text);
3619 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3620 es->undo_insert_count, debugstr_w(utext));
3622 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
3623 EDIT_EM_EmptyUndoBuffer(es);
3624 EDIT_EM_ReplaceSel(es, TRUE, utext, TRUE, TRUE);
3625 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
3626 /* send the notification after the selection start and end are set */
3627 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3628 EDIT_EM_ScrollCaret(es);
3629 HeapFree(GetProcessHeap(), 0, utext);
3631 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3632 es->undo_insert_count, debugstr_w(es->undo_text));
3637 /*********************************************************************
3642 static void EDIT_WM_Char(EDITSTATE *es, WCHAR c)
3646 control = GetKeyState(VK_CONTROL) & 0x8000;
3650 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3651 if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
3654 if (es->style & ES_MULTILINE) {
3655 if (es->style & ES_READONLY) {
3656 EDIT_MoveHome(es, FALSE);
3657 EDIT_MoveDown_ML(es, FALSE);
3659 static const WCHAR cr_lfW[] = {'\r','\n',0};
3660 EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, TRUE, TRUE);
3665 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
3667 static const WCHAR tabW[] = {'\t',0};
3668 EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE, TRUE);
3672 if (!(es->style & ES_READONLY) && !control) {
3673 if (es->selection_start != es->selection_end)
3676 /* delete character left of caret */
3677 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
3678 EDIT_MoveBackward(es, TRUE);
3684 SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
3687 if (!(es->style & ES_READONLY))
3688 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
3691 if (!(es->style & ES_READONLY))
3692 SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
3696 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3697 if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') )
3700 if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) {
3704 EDIT_EM_ReplaceSel(es, TRUE, str, TRUE, TRUE);
3711 /*********************************************************************
3716 static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND control)
3718 if (code || control)
3738 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
3739 EDIT_EM_ScrollCaret(es);
3742 ERR("unknown menu item, please report\n");
3748 /*********************************************************************
3752 * Note: the resource files resource/sysres_??.rc cannot define a
3753 * single popup menu. Hence we use a (dummy) menubar
3754 * containing the single popup menu as its first item.
3756 * FIXME: the message identifiers have been chosen arbitrarily,
3757 * hence we use MF_BYPOSITION.
3758 * We might as well use the "real" values (anybody knows ?)
3759 * The menu definition is in resources/sysres_??.rc.
3760 * Once these are OK, we better use MF_BYCOMMAND here
3761 * (as we do in EDIT_WM_Command()).
3764 static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
3766 HMENU menu = LoadMenuA(user32_module, "EDITMENU");
3767 HMENU popup = GetSubMenu(menu, 0);
3768 UINT start = es->selection_start;
3769 UINT end = es->selection_end;
3771 ORDER_UINT(start, end);
3774 EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3776 EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3778 EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
3780 EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3782 EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3784 EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != strlenW(es->text)) ? MF_ENABLED : MF_GRAYED));
3786 TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, es->hwndSelf, NULL);
3791 /*********************************************************************
3796 static void EDIT_WM_Copy(EDITSTATE *es)
3798 INT s = min(es->selection_start, es->selection_end);
3799 INT e = max(es->selection_start, es->selection_end);
3805 hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR));
3806 dst = GlobalLock(hdst);
3807 strncpyW(dst, es->text + s, e - s);
3808 dst[e - s] = 0; /* ensure 0 termination */
3809 TRACE("%s\n", debugstr_w(dst));
3811 OpenClipboard(es->hwndSelf);
3813 SetClipboardData(CF_UNICODETEXT, hdst);
3818 /*********************************************************************
3823 static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name)
3825 TRACE("%s\n", debugstr_w(name));
3827 * To initialize some final structure members, we call some helper
3828 * functions. However, since the EDITSTATE is not consistent (i.e.
3829 * not fully initialized), we should be very careful which
3830 * functions can be called, and in what order.
3832 EDIT_WM_SetFont(es, 0, FALSE);
3833 EDIT_EM_EmptyUndoBuffer(es);
3835 if (name && *name) {
3836 EDIT_EM_ReplaceSel(es, FALSE, name, FALSE, TRUE);
3837 /* if we insert text to the editline, the text scrolls out
3838 * of the window, as the caret is placed after the insert
3839 * pos normally; thus we reset es->selection... to 0 and
3842 es->selection_start = es->selection_end = 0;
3843 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3844 * Messages are only to be sent when the USER does something to
3845 * change the contents. So I am removing this EN_CHANGE
3847 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3849 EDIT_EM_ScrollCaret(es);
3851 /* force scroll info update */
3852 EDIT_UpdateScrollInfo(es);
3853 /* The rule seems to return 1 here for success */
3854 /* Power Builder masked edit controls will crash */
3856 /* FIXME: is that in all cases so ? */
3861 /*********************************************************************
3866 static LRESULT EDIT_WM_Destroy(EDITSTATE *es)
3871 while (LocalUnlock(es->hloc32W)) ;
3872 LocalFree(es->hloc32W);
3875 while (LocalUnlock(es->hloc32A)) ;
3876 LocalFree(es->hloc32A);
3879 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
3880 while (LOCAL_Unlock(hInstance, es->hloc16)) ;
3881 LOCAL_Free(hInstance, es->hloc16);
3884 pc = es->first_line_def;
3888 HeapFree(GetProcessHeap(), 0, pc);
3892 SetWindowLongW( es->hwndSelf, 0, 0 );
3893 HeapFree(GetProcessHeap(), 0, es);
3899 /*********************************************************************
3904 static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc)
3906 /* we do the proper erase in EDIT_WM_Paint */
3911 /*********************************************************************
3916 static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPWSTR dst, BOOL unicode)
3918 if(!count) return 0;
3922 lstrcpynW(dst, es->text, count);
3923 return strlenW(dst);
3927 LPSTR textA = (LPSTR)dst;
3928 if (!WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, count, NULL, NULL))
3929 textA[count - 1] = 0; /* ensure 0 termination */
3930 return strlen(textA);
3934 /*********************************************************************
3939 static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos)
3944 if (!(es->style & ES_MULTILINE))
3947 if (!(es->style & ES_AUTOHSCROLL))
3951 fw = es->format_rect.right - es->format_rect.left;
3954 TRACE("SB_LINELEFT\n");
3956 dx = -es->char_width;
3959 TRACE("SB_LINERIGHT\n");
3960 if (es->x_offset < es->text_width)
3961 dx = es->char_width;
3964 TRACE("SB_PAGELEFT\n");
3966 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3969 TRACE("SB_PAGERIGHT\n");
3970 if (es->x_offset < es->text_width)
3971 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3979 TRACE("SB_RIGHT\n");
3980 if (es->x_offset < es->text_width)
3981 dx = es->text_width - es->x_offset;
3984 TRACE("SB_THUMBTRACK %d\n", pos);
3985 es->flags |= EF_HSCROLL_TRACK;
3986 if(es->style & WS_HSCROLL)
3987 dx = pos - es->x_offset;
3992 if(pos < 0 || pos > 100) return 0;
3993 /* Assume default scroll range 0-100 */
3994 fw = es->format_rect.right - es->format_rect.left;
3995 new_x = pos * (es->text_width - fw) / 100;
3996 dx = es->text_width ? (new_x - es->x_offset) : 0;
3999 case SB_THUMBPOSITION:
4000 TRACE("SB_THUMBPOSITION %d\n", pos);
4001 es->flags &= ~EF_HSCROLL_TRACK;
4002 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
4003 dx = pos - es->x_offset;
4008 if(pos < 0 || pos > 100) return 0;
4009 /* Assume default scroll range 0-100 */
4010 fw = es->format_rect.right - es->format_rect.left;
4011 new_x = pos * (es->text_width - fw) / 100;
4012 dx = es->text_width ? (new_x - es->x_offset) : 0;
4015 /* force scroll info update */
4016 EDIT_UpdateScrollInfo(es);
4017 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
4021 TRACE("SB_ENDSCROLL\n");
4024 * FIXME : the next two are undocumented !
4025 * Are we doing the right thing ?
4026 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4027 * although it's also a regular control message.
4029 case EM_GETTHUMB: /* this one is used by NT notepad */
4033 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
4034 ret = GetScrollPos(es->hwndSelf, SB_HORZ);
4037 /* Assume default scroll range 0-100 */
4038 INT fw = es->format_rect.right - es->format_rect.left;
4039 ret = es->text_width ? es->x_offset * 100 / (es->text_width - fw) : 0;
4041 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4044 case EM_LINESCROLL16:
4045 TRACE("EM_LINESCROLL16\n");
4050 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4056 INT fw = es->format_rect.right - es->format_rect.left;
4057 /* check if we are going to move too far */
4058 if(es->x_offset + dx + fw > es->text_width)
4059 dx = es->text_width - fw - es->x_offset;
4061 EDIT_EM_LineScroll_internal(es, dx, 0);
4067 /*********************************************************************
4072 static BOOL EDIT_CheckCombo(EDITSTATE *es, UINT msg, INT key)
4074 HWND hLBox = es->hwndListBox;
4082 hCombo = GetParent(es->hwndSelf);
4086 TRACE_(combo)("[%p]: handling msg %x (%x)\n", es->hwndSelf, msg, key);
4088 if (key == VK_UP || key == VK_DOWN)
4090 if (SendMessageW(hCombo, CB_GETEXTENDEDUI, 0, 0))
4093 if (msg == WM_KEYDOWN || nEUI)
4094 bDropped = (BOOL)SendMessageW(hCombo, CB_GETDROPPEDSTATE, 0, 0);
4100 if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN))
4102 /* make sure ComboLBox pops up */
4103 SendMessageW(hCombo, CB_SETEXTENDEDUI, FALSE, 0);
4108 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
4111 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
4113 SendMessageW(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0);
4115 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0);
4120 SendMessageW(hCombo, CB_SETEXTENDEDUI, TRUE, 0);
4126 /*********************************************************************
4130 * Handling of special keys that don't produce a WM_CHAR
4131 * (i.e. non-printable keys) & Backspace & Delete
4134 static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key)
4139 if (GetKeyState(VK_MENU) & 0x8000)
4142 shift = GetKeyState(VK_SHIFT) & 0x8000;
4143 control = GetKeyState(VK_CONTROL) & 0x8000;
4148 if (EDIT_CheckCombo(es, WM_KEYDOWN, key) || key == VK_F4)
4153 if ((es->style & ES_MULTILINE) && (key == VK_UP))
4154 EDIT_MoveUp_ML(es, shift);
4157 EDIT_MoveWordBackward(es, shift);
4159 EDIT_MoveBackward(es, shift);
4162 if (EDIT_CheckCombo(es, WM_KEYDOWN, key))
4166 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
4167 EDIT_MoveDown_ML(es, shift);
4169 EDIT_MoveWordForward(es, shift);
4171 EDIT_MoveForward(es, shift);
4174 EDIT_MoveHome(es, shift);
4177 EDIT_MoveEnd(es, shift);
4180 if (es->style & ES_MULTILINE)
4181 EDIT_MovePageUp_ML(es, shift);
4183 EDIT_CheckCombo(es, WM_KEYDOWN, key);
4186 if (es->style & ES_MULTILINE)
4187 EDIT_MovePageDown_ML(es, shift);
4189 EDIT_CheckCombo(es, WM_KEYDOWN, key);
4192 if (!(es->style & ES_READONLY) && !(shift && control)) {
4193 if (es->selection_start != es->selection_end) {
4200 /* delete character left of caret */
4201 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4202 EDIT_MoveBackward(es, TRUE);
4204 } else if (control) {
4205 /* delete to end of line */
4206 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4207 EDIT_MoveEnd(es, TRUE);
4210 /* delete character right of caret */
4211 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4212 EDIT_MoveForward(es, TRUE);
4220 if (!(es->style & ES_READONLY))
4226 /* If the edit doesn't want the return send a message to the default object */
4227 if(!(es->style & ES_WANTRETURN))
4229 HWND hwndParent = GetParent(es->hwndSelf);
4230 DWORD dw = SendMessageW( hwndParent, DM_GETDEFID, 0, 0 );
4231 if (HIWORD(dw) == DC_HASDEFID)
4233 SendMessageW( hwndParent, WM_COMMAND,
4234 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
4235 (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
4244 /*********************************************************************
4249 static LRESULT EDIT_WM_KillFocus(EDITSTATE *es)
4251 es->flags &= ~EF_FOCUSED;
4253 if(!(es->style & ES_NOHIDESEL))
4254 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4255 EDIT_NOTIFY_PARENT(es, EN_KILLFOCUS, "EN_KILLFOCUS");
4260 /*********************************************************************
4264 * The caret position has been set on the WM_LBUTTONDOWN message
4267 static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es)
4270 INT e = es->selection_end;
4275 if (!(es->flags & EF_FOCUSED))
4278 l = EDIT_EM_LineFromChar(es, e);
4279 li = EDIT_EM_LineIndex(es, l);
4280 ll = EDIT_EM_LineLength(es, e);
4281 s = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT);
4282 e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_RIGHT);
4283 EDIT_EM_SetSel(es, s, e, FALSE);
4284 EDIT_EM_ScrollCaret(es);
4289 /*********************************************************************
4294 static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y)
4299 SetFocus(es->hwndSelf);
4300 if (!(es->flags & EF_FOCUSED))
4303 es->bCaptureState = TRUE;
4304 SetCapture(es->hwndSelf);
4305 EDIT_ConfinePoint(es, &x, &y);
4306 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4307 EDIT_EM_SetSel(es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
4308 EDIT_EM_ScrollCaret(es);
4309 es->region_posx = es->region_posy = 0;
4310 SetTimer(es->hwndSelf, 0, 100, NULL);
4315 /*********************************************************************
4320 static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es)
4322 if (es->bCaptureState) {
4323 KillTimer(es->hwndSelf, 0);
4324 if (GetCapture() == es->hwndSelf) ReleaseCapture();
4326 es->bCaptureState = FALSE;
4331 /*********************************************************************
4336 static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es)
4338 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
4343 /*********************************************************************
4348 static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y)
4354 if (GetCapture() != es->hwndSelf)
4358 * FIXME: gotta do some scrolling if outside client
4359 * area. Maybe reset the timer ?
4362 EDIT_ConfinePoint(es, &x, &y);
4363 es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
4364 es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
4365 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4366 EDIT_EM_SetSel(es, es->selection_start, e, after_wrap);
4367 EDIT_SetCaretPos(es,es->selection_end,es->flags & EF_AFTER_WRAP);
4372 /*********************************************************************
4376 * See also EDIT_WM_StyleChanged
4378 static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode)
4383 TRACE("Creating %s edit control, style = %08lx\n",
4384 unicode ? "Unicode" : "ANSI", lpcs->style);
4386 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
4388 SetWindowLongW( hwnd, 0, (LONG)es );
4391 * Note: since the EDITSTATE has not been fully initialized yet,
4392 * we can't use any API calls that may send
4393 * WM_XXX messages before WM_NCCREATE is completed.
4396 es->is_unicode = unicode;
4397 es->style = lpcs->style;
4399 es->bEnableState = !(es->style & WS_DISABLED);
4401 es->hwndSelf = hwnd;
4402 /* Save parent, which will be notified by EN_* messages */
4403 es->hwndParent = lpcs->hwndParent;
4405 if (es->style & ES_COMBO)
4406 es->hwndListBox = GetDlgItem(es->hwndParent, ID_CB_LISTBOX);
4408 /* Number overrides lowercase overrides uppercase (at least it
4409 * does in Win95). However I'll bet that ES_NUMBER would be
4410 * invalid under Win 3.1.
4412 if (es->style & ES_NUMBER) {
4413 ; /* do not override the ES_NUMBER */
4414 } else if (es->style & ES_LOWERCASE) {
4415 es->style &= ~ES_UPPERCASE;
4417 if (es->style & ES_MULTILINE) {
4418 es->buffer_limit = BUFLIMIT_MULTI;
4419 if (es->style & WS_VSCROLL)
4420 es->style |= ES_AUTOVSCROLL;
4421 if (es->style & WS_HSCROLL)
4422 es->style |= ES_AUTOHSCROLL;
4423 es->style &= ~ES_PASSWORD;
4424 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
4425 /* Confirmed - RIGHT overrides CENTER */
4426 if (es->style & ES_RIGHT)
4427 es->style &= ~ES_CENTER;
4428 es->style &= ~WS_HSCROLL;
4431 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4432 es->style |= ES_AUTOVSCROLL;
4434 es->buffer_limit = BUFLIMIT_SINGLE;
4435 es->style &= ~ES_CENTER;
4436 es->style &= ~ES_RIGHT;
4437 es->style &= ~WS_HSCROLL;
4438 es->style &= ~WS_VSCROLL;
4439 if (es->style & ES_PASSWORD)
4440 es->password_char = '*';
4442 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4443 es->style |= ES_AUTOHSCROLL;
4446 alloc_size = ROUND_TO_GROW((es->buffer_size + 1) * sizeof(WCHAR));
4447 if(!(es->hloc32W = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
4449 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
4451 if (!(es->undo_text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (es->buffer_size + 1) * sizeof(WCHAR))))
4453 es->undo_buffer_size = es->buffer_size;
4455 if (es->style & ES_MULTILINE)
4456 if (!(es->first_line_def = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
4461 * In Win95 look and feel, the WS_BORDER style is replaced by the
4462 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4463 * control a nonclient area so we don't need to draw the border.
4464 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4465 * a nonclient area and we should handle painting the border ourselves.
4467 * When making modifications please ensure that the code still works
4468 * for edit controls created directly with style 0x50800000, exStyle 0
4469 * (which should have a single pixel border)
4471 if (lpcs->dwExStyle & WS_EX_CLIENTEDGE)
4472 es->style &= ~WS_BORDER;
4473 else if (es->style & WS_BORDER)
4474 SetWindowLongW(hwnd, GWL_STYLE, es->style & ~WS_BORDER);
4479 /*********************************************************************
4484 static void EDIT_WM_Paint(EDITSTATE *es, HDC hdc)
4495 BOOL rev = es->bEnableState &&
4496 ((es->flags & EF_FOCUSED) ||
4497 (es->style & ES_NOHIDESEL));
4498 dc = hdc ? hdc : BeginPaint(es->hwndSelf, &ps);
4500 GetClientRect(es->hwndSelf, &rcClient);
4502 /* paint the background */
4503 if (!(brush = EDIT_NotifyCtlColor(es, dc)))
4504 brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
4505 IntersectClipRect(dc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
4506 GetClipBox(dc, &rc);
4507 FillRect(dc, &rc, brush);
4509 /* draw the border */
4510 if(es->style & WS_BORDER) {
4512 if(es->style & ES_MULTILINE) {
4513 if(es->style & WS_HSCROLL) rc.bottom++;
4514 if(es->style & WS_VSCROLL) rc.right++;
4516 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
4518 IntersectClipRect(dc, es->format_rect.left,
4519 es->format_rect.top,
4520 es->format_rect.right,
4521 es->format_rect.bottom);
4522 if (es->style & ES_MULTILINE) {
4524 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
4527 old_font = SelectObject(dc, es->font);
4528 EDIT_NotifyCtlColor(es, dc);
4530 if (!es->bEnableState)
4531 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
4532 GetClipBox(dc, &rcRgn);
4533 if (es->style & ES_MULTILINE) {
4534 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4535 for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
4536 EDIT_GetLineRect(es, i, 0, -1, &rcLine);
4537 if (IntersectRect(&rc, &rcRgn, &rcLine))
4538 EDIT_PaintLine(es, dc, i, rev);
4541 EDIT_GetLineRect(es, 0, 0, -1, &rcLine);
4542 if (IntersectRect(&rc, &rcRgn, &rcLine))
4543 EDIT_PaintLine(es, dc, 0, rev);
4546 SelectObject(dc, old_font);
4549 EndPaint(es->hwndSelf, &ps);
4553 /*********************************************************************
4558 static void EDIT_WM_Paste(EDITSTATE *es)
4563 /* Protect read-only edit control from modification */
4564 if(es->style & ES_READONLY)
4567 OpenClipboard(es->hwndSelf);
4568 if ((hsrc = GetClipboardData(CF_UNICODETEXT))) {
4569 src = (LPWSTR)GlobalLock(hsrc);
4570 EDIT_EM_ReplaceSel(es, TRUE, src, TRUE, TRUE);
4577 /*********************************************************************
4582 static void EDIT_WM_SetFocus(EDITSTATE *es)
4584 es->flags |= EF_FOCUSED;
4585 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4586 EDIT_SetCaretPos(es, es->selection_end,
4587 es->flags & EF_AFTER_WRAP);
4588 if(!(es->style & ES_NOHIDESEL))
4589 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4590 ShowCaret(es->hwndSelf);
4591 EDIT_NOTIFY_PARENT(es, EN_SETFOCUS, "EN_SETFOCUS");
4595 /*********************************************************************
4599 * With Win95 look the margins are set to default font value unless
4600 * the system font (font == 0) is being set, in which case they are left
4604 static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
4612 dc = GetDC(es->hwndSelf);
4614 old_font = SelectObject(dc, font);
4615 GetTextMetricsW(dc, &tm);
4616 es->line_height = tm.tmHeight;
4617 es->char_width = tm.tmAveCharWidth;
4619 SelectObject(dc, old_font);
4620 ReleaseDC(es->hwndSelf, dc);
4621 EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
4622 EC_USEFONTINFO, EC_USEFONTINFO);
4624 /* Force the recalculation of the format rect for each font change */
4625 GetClientRect(es->hwndSelf, &r);
4626 EDIT_SetRectNP(es, &r);
4628 if (es->style & ES_MULTILINE)
4629 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
4631 EDIT_CalcLineWidth_SL(es);
4634 EDIT_UpdateText(es, NULL, TRUE);
4635 if (es->flags & EF_FOCUSED) {
4637 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4638 EDIT_SetCaretPos(es, es->selection_end,
4639 es->flags & EF_AFTER_WRAP);
4640 ShowCaret(es->hwndSelf);
4645 /*********************************************************************
4650 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4651 * The modified flag is reset. No notifications are sent.
4653 * For single-line controls, reception of WM_SETTEXT triggers:
4654 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4657 static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text, BOOL unicode)
4659 if (!unicode && text)
4661 LPCSTR textA = (LPCSTR)text;
4662 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
4663 LPWSTR textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR));
4665 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
4669 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
4672 TRACE("%s\n", debugstr_w(text));
4673 EDIT_EM_ReplaceSel(es, FALSE, text, FALSE, FALSE);
4675 HeapFree(GetProcessHeap(), 0, (LPWSTR)text);
4679 static const WCHAR empty_stringW[] = {0};
4681 EDIT_EM_ReplaceSel(es, FALSE, empty_stringW, FALSE, FALSE);
4684 es->flags &= ~EF_MODIFIED;
4685 EDIT_EM_SetSel(es, 0, 0, FALSE);
4687 /* Send the notification after the selection start and end have been set
4688 * edit control doesn't send notification on WM_SETTEXT
4689 * if it is multiline, or it is part of combobox
4691 if( !((es->style & ES_MULTILINE) || es->hwndListBox))
4693 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
4694 EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4696 EDIT_EM_ScrollCaret(es);
4700 /*********************************************************************
4705 static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height)
4707 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
4709 TRACE("width = %d, height = %d\n", width, height);
4710 SetRect(&rc, 0, 0, width, height);
4711 EDIT_SetRectNP(es, &rc);
4712 EDIT_UpdateText(es, NULL, TRUE);
4717 /*********************************************************************
4721 * This message is sent by SetWindowLong on having changed either the Style
4722 * or the extended style.
4724 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4726 * See also EDIT_WM_NCCreate
4728 * It appears that the Windows version of the edit control allows the style
4729 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4730 * style variable which will generally be different. In this function we
4731 * update the internal style based on what changed in the externally visible
4734 * Much of this content as based upon the MSDN, especially:
4735 * Platform SDK Documentation -> User Interface Services ->
4736 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4737 * Edit Control Styles
4739 static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLESTRUCT *style)
4741 if (GWL_STYLE == which) {
4742 DWORD style_change_mask;
4744 /* Only a subset of changes can be applied after the control
4747 style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
4749 if (es->style & ES_MULTILINE)
4750 style_change_mask |= ES_WANTRETURN;
4752 new_style = style->styleNew & style_change_mask;
4754 /* Number overrides lowercase overrides uppercase (at least it
4755 * does in Win95). However I'll bet that ES_NUMBER would be
4756 * invalid under Win 3.1.
4758 if (new_style & ES_NUMBER) {
4759 ; /* do not override the ES_NUMBER */
4760 } else if (new_style & ES_LOWERCASE) {
4761 new_style &= ~ES_UPPERCASE;
4764 es->style = (es->style & ~style_change_mask) | new_style;
4765 } else if (GWL_EXSTYLE == which) {
4766 ; /* FIXME - what is needed here */
4768 WARN ("Invalid style change %d\n",which);
4774 /*********************************************************************
4779 static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data)
4781 if ((key == VK_BACK) && (key_data & 0x2000)) {
4782 if (EDIT_EM_CanUndo(es))
4785 } else if (key == VK_UP || key == VK_DOWN) {
4786 if (EDIT_CheckCombo(es, WM_SYSKEYDOWN, key))
4789 return DefWindowProcW(es->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
4793 /*********************************************************************
4798 static void EDIT_WM_Timer(EDITSTATE *es)
4800 if (es->region_posx < 0) {
4801 EDIT_MoveBackward(es, TRUE);
4802 } else if (es->region_posx > 0) {
4803 EDIT_MoveForward(es, TRUE);
4806 * FIXME: gotta do some vertical scrolling here, like
4807 * EDIT_EM_LineScroll(hwnd, 0, 1);
4811 /*********************************************************************
4816 static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos)
4820 if (!(es->style & ES_MULTILINE))
4823 if (!(es->style & ES_AUTOVSCROLL))
4832 TRACE("action %d (%s)\n", action, (action == SB_LINEUP ? "SB_LINEUP" :
4833 (action == SB_LINEDOWN ? "SB_LINEDOWN" :
4834 (action == SB_PAGEUP ? "SB_PAGEUP" :
4836 EDIT_EM_Scroll(es, action);
4843 TRACE("SB_BOTTOM\n");
4844 dy = es->line_count - 1 - es->y_offset;
4847 TRACE("SB_THUMBTRACK %d\n", pos);
4848 es->flags |= EF_VSCROLL_TRACK;
4849 if(es->style & WS_VSCROLL)
4850 dy = pos - es->y_offset;
4853 /* Assume default scroll range 0-100 */
4856 if(pos < 0 || pos > 100) return 0;
4857 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4858 new_y = pos * (es->line_count - vlc) / 100;
4859 dy = es->line_count ? (new_y - es->y_offset) : 0;
4860 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4861 es->line_count, es->y_offset, pos, dy);
4864 case SB_THUMBPOSITION:
4865 TRACE("SB_THUMBPOSITION %d\n", pos);
4866 es->flags &= ~EF_VSCROLL_TRACK;
4867 if(es->style & WS_VSCROLL)
4868 dy = pos - es->y_offset;
4871 /* Assume default scroll range 0-100 */
4874 if(pos < 0 || pos > 100) return 0;
4875 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4876 new_y = pos * (es->line_count - vlc) / 100;
4877 dy = es->line_count ? (new_y - es->y_offset) : 0;
4878 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4879 es->line_count, es->y_offset, pos, dy);
4883 /* force scroll info update */
4884 EDIT_UpdateScrollInfo(es);
4885 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
4889 TRACE("SB_ENDSCROLL\n");
4892 * FIXME : the next two are undocumented !
4893 * Are we doing the right thing ?
4894 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4895 * although it's also a regular control message.
4897 case EM_GETTHUMB: /* this one is used by NT notepad */
4901 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_VSCROLL)
4902 ret = GetScrollPos(es->hwndSelf, SB_VERT);
4905 /* Assume default scroll range 0-100 */
4906 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4907 ret = es->line_count ? es->y_offset * 100 / (es->line_count - vlc) : 0;
4909 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4912 case EM_LINESCROLL16:
4913 TRACE("EM_LINESCROLL16 %d\n", pos);
4918 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4923 EDIT_EM_LineScroll(es, 0, dy);
4927 /*********************************************************************
4932 static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase)
4934 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4935 InvalidateRgn(es->hwndSelf, hrgn, bErase);
4939 /*********************************************************************
4944 static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase)
4946 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4947 InvalidateRect(es->hwndSelf, rc, bErase);