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;
1256 else if (delta != 0)
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);
2254 EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
2258 /*********************************************************************
2263 static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force)
2265 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
2267 /* Edit window might be already destroyed */
2268 if(!IsWindow(es->hwndSelf))
2270 WARN("edit hwnd %p already destroyed\n", es->hwndSelf);
2274 if (!es->lock_count) {
2275 ERR("lock_count == 0 ... please report\n");
2279 ERR("es->text == 0 ... please report\n");
2283 if (force || (es->lock_count == 1)) {
2286 BOOL _16bit = FALSE;
2288 UINT countW = strlenW(es->text) + 1;
2292 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
2293 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2294 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
2295 countA = LocalSize(es->hloc32A);
2296 if(countA_new > countA)
2299 UINT alloc_size = ROUND_TO_GROW(countA_new);
2300 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2301 hloc32A_new = LocalReAlloc(es->hloc32A, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2304 es->hloc32A = hloc32A_new;
2305 countA = LocalSize(hloc32A_new);
2306 TRACE("Real new size %d bytes\n", countA);
2309 WARN("FAILED! Will synchronize partially\n");
2311 textA = LocalLock(es->hloc32A);
2315 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
2316 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2317 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
2318 countA = LOCAL_Size(hInstance, es->hloc16);
2319 if(countA_new > countA)
2321 HLOCAL16 hloc16_new;
2322 UINT alloc_size = ROUND_TO_GROW(countA_new);
2323 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2324 hloc16_new = LOCAL_ReAlloc(hInstance, es->hloc16, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2327 es->hloc16 = hloc16_new;
2328 countA = LOCAL_Size(hInstance, hloc16_new);
2329 TRACE("Real new size %d bytes\n", countA);
2332 WARN("FAILED! Will synchronize partially\n");
2334 textA = LOCAL_Lock(hInstance, es->hloc16);
2340 WideCharToMultiByte(CP_ACP, 0, es->text, countW, textA, countA, NULL, NULL);
2342 LOCAL_Unlock(hInstance, es->hloc16);
2344 LocalUnlock(es->hloc32A);
2347 LocalUnlock(es->hloc32W);
2351 ERR("no buffer ... please report\n");
2359 /*********************************************************************
2361 * EDIT_UpdateScrollInfo
2364 static void EDIT_UpdateScrollInfo(EDITSTATE *es)
2366 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
2369 si.cbSize = sizeof(SCROLLINFO);
2370 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2372 si.nMax = es->line_count - 1;
2373 si.nPage = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2374 si.nPos = es->y_offset;
2375 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2376 si.nMin, si.nMax, si.nPage, si.nPos);
2377 SetScrollInfo(es->hwndSelf, SB_VERT, &si, TRUE);
2380 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
2383 si.cbSize = sizeof(SCROLLINFO);
2384 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2386 si.nMax = es->text_width - 1;
2387 si.nPage = es->format_rect.right - es->format_rect.left;
2388 si.nPos = es->x_offset;
2389 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2390 si.nMin, si.nMax, si.nPage, si.nPos);
2391 SetScrollInfo(es->hwndSelf, SB_HORZ, &si, TRUE);
2395 /*********************************************************************
2397 * EDIT_WordBreakProc
2399 * Find the beginning of words.
2400 * Note: unlike the specs for a WordBreakProc, this function only
2401 * allows to be called without linebreaks between s[0] upto
2402 * s[count - 1]. Remember it is only called
2403 * internally, so we can decide this for ourselves.
2406 static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action)
2410 TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action);
2420 if (s[index] == ' ') {
2421 while (index && (s[index] == ' '))
2424 while (index && (s[index] != ' '))
2426 if (s[index] == ' ')
2430 while (index && (s[index] != ' '))
2432 if (s[index] == ' ')
2442 if (s[index] == ' ')
2443 while ((index < count) && (s[index] == ' ')) index++;
2445 while (s[index] && (s[index] != ' ') && (index < count))
2447 while ((s[index] == ' ') && (index < count)) index++;
2451 case WB_ISDELIMITER:
2452 ret = (s[index] == ' ');
2455 ERR("unknown action code, please report !\n");
2462 /*********************************************************************
2466 * returns line number (not index) in high-order word of result.
2467 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2468 * to Richedit, not to the edit control. Original documentation is valid.
2469 * FIXME: do the specs mean to return -1 if outside client area or
2470 * if outside formatting rectangle ???
2473 static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y)
2481 GetClientRect(es->hwndSelf, &rc);
2482 if (!PtInRect(&rc, pt))
2485 index = EDIT_CharFromPos(es, x, y, NULL);
2486 return MAKELONG(index, EDIT_EM_LineFromChar(es, index));
2490 /*********************************************************************
2494 * Enable or disable soft breaks.
2496 * This means: insert or remove the soft linebreak character (\r\r\n).
2497 * Take care to check if the text still fits the buffer after insertion.
2498 * If not, notify with EN_ERRSPACE.
2501 static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol)
2503 es->flags &= ~EF_USE_SOFTBRK;
2505 es->flags |= EF_USE_SOFTBRK;
2506 FIXME("soft break enabled, not implemented\n");
2512 /*********************************************************************
2516 * Hopefully this won't fire back at us.
2517 * We always start with a fixed buffer in the local heap.
2518 * Despite of the documentation says that the local heap is used
2519 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2520 * buffer on the local heap.
2523 static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es)
2527 if (!(es->style & ES_MULTILINE))
2531 hLocal = es->hloc32W;
2537 UINT countA, alloc_size;
2538 TRACE("Allocating 32-bit ANSI alias buffer\n");
2539 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
2540 alloc_size = ROUND_TO_GROW(countA);
2541 if(!(es->hloc32A = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2543 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size);
2546 textA = LocalLock(es->hloc32A);
2547 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
2548 LocalUnlock(es->hloc32A);
2550 hLocal = es->hloc32A;
2553 TRACE("Returning %p, LocalSize() = %ld\n", hLocal, LocalSize(hLocal));
2558 /*********************************************************************
2562 * Hopefully this won't fire back at us.
2563 * We always start with a buffer in 32 bit linear memory.
2564 * However, with this message a 16 bit application requests
2565 * a handle of 16 bit local heap memory, where it expects to find
2567 * It's a pitty that from this moment on we have to use this
2568 * local heap, because applications may rely on the handle
2571 * In this function we'll try to switch to local heap.
2573 static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es)
2575 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
2577 UINT countA, alloc_size;
2579 if (!(es->style & ES_MULTILINE))
2585 if (!LOCAL_HeapSize(hInstance)) {
2586 if (!LocalInit16(hInstance, 0,
2587 GlobalSize16(hInstance))) {
2588 ERR("could not initialize local heap\n");
2591 TRACE("local heap initialized\n");
2594 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
2595 alloc_size = ROUND_TO_GROW(countA);
2597 TRACE("Allocating 16-bit ANSI alias buffer\n");
2598 if (!(es->hloc16 = LOCAL_Alloc(hInstance, LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) {
2599 ERR("could not allocate new 16 bit buffer\n");
2603 if (!(textA = (LPSTR)LOCAL_Lock(hInstance, es->hloc16))) {
2604 ERR("could not lock new 16 bit buffer\n");
2605 LOCAL_Free(hInstance, es->hloc16);
2610 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
2611 LOCAL_Unlock(hInstance, es->hloc16);
2613 TRACE("Returning %04X, LocalSize() = %d\n", es->hloc16, LOCAL_Size(hInstance, es->hloc16));
2618 /*********************************************************************
2623 static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPWSTR dst, BOOL unicode)
2626 INT line_len, dst_len;
2629 if (es->style & ES_MULTILINE) {
2630 if (line >= es->line_count)
2634 i = EDIT_EM_LineIndex(es, line);
2636 line_len = EDIT_EM_LineLength(es, i);
2637 dst_len = *(WORD *)dst;
2640 if(dst_len <= line_len)
2642 memcpy(dst, src, dst_len * sizeof(WCHAR));
2645 else /* Append 0 if enough space */
2647 memcpy(dst, src, line_len * sizeof(WCHAR));
2654 INT ret = WideCharToMultiByte(CP_ACP, 0, src, line_len, (LPSTR)dst, dst_len, NULL, NULL);
2655 if(!ret) /* Insufficient buffer size */
2657 if(ret < dst_len) /* Append 0 if enough space */
2658 ((LPSTR)dst)[ret] = 0;
2664 /*********************************************************************
2669 static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end)
2671 UINT s = es->selection_start;
2672 UINT e = es->selection_end;
2679 return MAKELONG(s, e);
2683 /*********************************************************************
2687 * FIXME: is this right ? (or should it be only VSCROLL)
2688 * (and maybe only for edit controls that really have their
2689 * own scrollbars) (and maybe only for multiline controls ?)
2690 * All in all: very poorly documented
2693 static LRESULT EDIT_EM_GetThumb(EDITSTATE *es)
2695 return MAKELONG(EDIT_WM_VScroll(es, EM_GETTHUMB16, 0),
2696 EDIT_WM_HScroll(es, EM_GETTHUMB16, 0));
2700 /*********************************************************************
2705 static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index)
2710 if (!(es->style & ES_MULTILINE))
2712 if (index > (INT)strlenW(es->text))
2713 return es->line_count - 1;
2715 index = min(es->selection_start, es->selection_end);
2718 line_def = es->first_line_def;
2719 index -= line_def->length;
2720 while ((index >= 0) && line_def->next) {
2722 line_def = line_def->next;
2723 index -= line_def->length;
2729 /*********************************************************************
2734 static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line)
2739 if (!(es->style & ES_MULTILINE))
2741 if (line >= es->line_count)
2745 line_def = es->first_line_def;
2747 INT index = es->selection_end - line_def->length;
2748 while ((index >= 0) && line_def->next) {
2749 line_index += line_def->length;
2750 line_def = line_def->next;
2751 index -= line_def->length;
2755 line_index += line_def->length;
2756 line_def = line_def->next;
2764 /*********************************************************************
2769 static INT EDIT_EM_LineLength(EDITSTATE *es, INT index)
2773 if (!(es->style & ES_MULTILINE))
2774 return strlenW(es->text);
2777 /* get the number of remaining non-selected chars of selected lines */
2778 INT32 l; /* line number */
2779 INT32 li; /* index of first char in line */
2781 l = EDIT_EM_LineFromChar(es, es->selection_start);
2782 /* # chars before start of selection area */
2783 count = es->selection_start - EDIT_EM_LineIndex(es, l);
2784 l = EDIT_EM_LineFromChar(es, es->selection_end);
2785 /* # chars after end of selection */
2786 li = EDIT_EM_LineIndex(es, l);
2787 count += li + EDIT_EM_LineLength(es, li) - es->selection_end;
2790 line_def = es->first_line_def;
2791 index -= line_def->length;
2792 while ((index >= 0) && line_def->next) {
2793 line_def = line_def->next;
2794 index -= line_def->length;
2796 return line_def->net_length;
2800 /*********************************************************************
2804 * NOTE: dx is in average character widths, dy - in lines;
2807 static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy)
2809 if (!(es->style & ES_MULTILINE))
2812 dx *= es->char_width;
2813 return EDIT_EM_LineScroll_internal(es, dx, dy);
2816 /*********************************************************************
2818 * EDIT_EM_LineScroll_internal
2820 * Version of EDIT_EM_LineScroll for internal use.
2821 * It doesn't refuse if ES_MULTILINE is set and assumes that
2822 * dx is in pixels, dy - in lines.
2825 static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy)
2828 INT x_offset_in_pixels;
2829 INT lines_per_page = (es->format_rect.bottom - es->format_rect.top) /
2832 if (es->style & ES_MULTILINE)
2834 x_offset_in_pixels = es->x_offset;
2839 x_offset_in_pixels = (short)LOWORD(EDIT_EM_PosFromChar(es, es->x_offset, FALSE));
2842 if (-dx > x_offset_in_pixels)
2843 dx = -x_offset_in_pixels;
2844 if (dx > es->text_width - x_offset_in_pixels)
2845 dx = es->text_width - x_offset_in_pixels;
2846 nyoff = max(0, es->y_offset + dy);
2847 if (nyoff >= es->line_count - lines_per_page)
2848 nyoff = max(0, es->line_count - lines_per_page);
2849 dy = (es->y_offset - nyoff) * es->line_height;
2854 es->y_offset = nyoff;
2855 if(es->style & ES_MULTILINE)
2858 es->x_offset += dx / es->char_width;
2860 GetClientRect(es->hwndSelf, &rc1);
2861 IntersectRect(&rc, &rc1, &es->format_rect);
2862 ScrollWindowEx(es->hwndSelf, -dx, dy,
2863 NULL, &rc, NULL, NULL, SW_INVALIDATE);
2864 /* force scroll info update */
2865 EDIT_UpdateScrollInfo(es);
2867 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2868 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
2869 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2870 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
2875 /*********************************************************************
2880 static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap)
2882 INT len = strlenW(es->text);
2891 index = min(index, len);
2892 dc = GetDC(es->hwndSelf);
2894 old_font = SelectObject(dc, es->font);
2895 if (es->style & ES_MULTILINE) {
2896 l = EDIT_EM_LineFromChar(es, index);
2897 y = (l - es->y_offset) * es->line_height;
2898 li = EDIT_EM_LineIndex(es, l);
2899 if (after_wrap && (li == index) && l) {
2901 LINEDEF *line_def = es->first_line_def;
2903 line_def = line_def->next;
2906 if (line_def->ending == END_WRAP) {
2908 y -= es->line_height;
2909 li = EDIT_EM_LineIndex(es, l);
2912 x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li,
2913 es->tabs_count, es->tabs)) - es->x_offset;
2915 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
2916 if (index < es->x_offset) {
2917 GetTextExtentPoint32W(dc, text + index,
2918 es->x_offset - index, &size);
2921 GetTextExtentPoint32W(dc, text + es->x_offset,
2922 index - es->x_offset, &size);
2926 if (es->style & ES_PASSWORD)
2927 HeapFree(GetProcessHeap(), 0, text);
2929 x += es->format_rect.left;
2930 y += es->format_rect.top;
2932 SelectObject(dc, old_font);
2933 ReleaseDC(es->hwndSelf, dc);
2934 return MAKELONG((INT16)x, (INT16)y);
2938 /*********************************************************************
2942 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2945 static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit)
2947 UINT strl = strlenW(lpsz_replace);
2948 UINT tl = strlenW(es->text);
2957 TRACE("%s, can_undo %d, send_update %d\n",
2958 debugstr_w(lpsz_replace), can_undo, send_update);
2960 s = es->selection_start;
2961 e = es->selection_end;
2963 if ((s == e) && !strl)
2968 /* Issue the EN_MAXTEXT notification and continue with replacing text
2969 * such that buffer limit is honored. */
2970 size = tl - (e - s) + strl;
2971 if ((honor_limit) && (es->buffer_limit > 0) && (size > es->buffer_limit)) {
2972 EDIT_NOTIFY_PARENT(es, EN_MAXTEXT, "EN_MAXTEXT");
2973 strl = es->buffer_limit - (tl - (e-s));
2976 if (!EDIT_MakeFit(es, tl - (e - s) + strl))
2980 /* there is something to be deleted */
2981 TRACE("deleting stuff.\n");
2983 utl = strlenW(es->undo_text);
2984 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
2985 /* undo-buffer is extended to the right */
2986 EDIT_MakeUndoFit(es, utl + e - s);
2987 strncpyW(es->undo_text + utl, es->text + s, e - s + 1);
2988 (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */
2989 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
2990 /* undo-buffer is extended to the left */
2991 EDIT_MakeUndoFit(es, utl + e - s);
2992 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
2994 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2995 p[i] = (es->text + s)[i];
2996 es->undo_position = s;
2998 /* new undo-buffer */
2999 EDIT_MakeUndoFit(es, e - s);
3000 strncpyW(es->undo_text, es->text + s, e - s + 1);
3001 es->undo_text[e - s] = 0; /* ensure 0 termination */
3002 es->undo_position = s;
3004 /* any deletion makes the old insertion-undo invalid */
3005 es->undo_insert_count = 0;
3007 EDIT_EM_EmptyUndoBuffer(es);
3010 strcpyW(es->text + s, es->text + e);
3013 /* there is an insertion */
3015 if ((s == es->undo_position) ||
3016 ((es->undo_insert_count) &&
3017 (s == es->undo_position + es->undo_insert_count)))
3019 * insertion is new and at delete position or
3020 * an extension to either left or right
3022 es->undo_insert_count += strl;
3024 /* new insertion undo */
3025 es->undo_position = s;
3026 es->undo_insert_count = strl;
3027 /* new insertion makes old delete-buffer invalid */
3028 *es->undo_text = '\0';
3031 EDIT_EM_EmptyUndoBuffer(es);
3034 tl = strlenW(es->text);
3035 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));
3036 for (p = es->text + tl ; p >= es->text + s ; p--)
3038 for (i = 0 , p = es->text + s ; i < strl ; i++)
3039 p[i] = lpsz_replace[i];
3040 if(es->style & ES_UPPERCASE)
3041 CharUpperBuffW(p, strl);
3042 else if(es->style & ES_LOWERCASE)
3043 CharLowerBuffW(p, strl);
3046 if (es->style & ES_MULTILINE)
3048 INT s = min(es->selection_start, es->selection_end);
3050 hrgn = CreateRectRgn(0, 0, 0, 0);
3051 EDIT_BuildLineDefs_ML(es, s, s + strl,
3052 strl - abs(es->selection_end - es->selection_start), hrgn);
3055 EDIT_CalcLineWidth_SL(es);
3057 EDIT_EM_SetSel(es, s, s, FALSE);
3058 es->flags |= EF_MODIFIED;
3059 if (send_update) es->flags |= EF_UPDATE;
3062 EDIT_UpdateTextRegion(es, hrgn, TRUE);
3066 EDIT_UpdateText(es, NULL, TRUE);
3068 EDIT_EM_ScrollCaret(es);
3070 /* force scroll info update */
3071 EDIT_UpdateScrollInfo(es);
3074 if(es->flags & EF_UPDATE)
3076 es->flags &= ~EF_UPDATE;
3077 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3082 /*********************************************************************
3087 static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
3091 if (!(es->style & ES_MULTILINE))
3092 return (LRESULT)FALSE;
3102 if (es->y_offset < es->line_count - 1)
3107 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
3110 if (es->y_offset < es->line_count - 1)
3111 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3114 return (LRESULT)FALSE;
3117 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3118 /* check if we are going to move too far */
3119 if(es->y_offset + dy > es->line_count - vlc)
3120 dy = es->line_count - vlc - es->y_offset;
3122 /* Notification is done in EDIT_EM_LineScroll */
3124 EDIT_EM_LineScroll(es, 0, dy);
3126 return MAKELONG((INT16)dy, (BOOL16)TRUE);
3130 /*********************************************************************
3135 static void EDIT_EM_ScrollCaret(EDITSTATE *es)
3137 if (es->style & ES_MULTILINE) {
3142 INT cw = es->char_width;
3147 l = EDIT_EM_LineFromChar(es, es->selection_end);
3148 li = EDIT_EM_LineIndex(es, l);
3149 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP));
3150 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3151 if (l >= es->y_offset + vlc)
3152 dy = l - vlc + 1 - es->y_offset;
3153 if (l < es->y_offset)
3154 dy = l - es->y_offset;
3155 ww = es->format_rect.right - es->format_rect.left;
3156 if (x < es->format_rect.left)
3157 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
3158 if (x > es->format_rect.right)
3159 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
3162 /* check if we are going to move too far */
3163 if(es->x_offset + dx + ww > es->text_width)
3164 dx = es->text_width - ww - es->x_offset;
3166 EDIT_EM_LineScroll_internal(es, dx, dy);
3173 if (!(es->style & ES_AUTOHSCROLL))
3176 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3177 format_width = es->format_rect.right - es->format_rect.left;
3178 if (x < es->format_rect.left) {
3179 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
3182 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3183 } while ((x < goal) && es->x_offset);
3184 /* FIXME: use ScrollWindow() somehow to improve performance */
3185 EDIT_UpdateText(es, NULL, TRUE);
3186 } else if (x > es->format_rect.right) {
3188 INT len = strlenW(es->text);
3189 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
3192 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3193 x_last = (short)LOWORD(EDIT_EM_PosFromChar(es, len, FALSE));
3194 } while ((x > goal) && (x_last > es->format_rect.right));
3195 /* FIXME: use ScrollWindow() somehow to improve performance */
3196 EDIT_UpdateText(es, NULL, TRUE);
3200 if(es->flags & EF_FOCUSED)
3201 EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
3205 /*********************************************************************
3209 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3212 static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc)
3214 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
3216 if (!(es->style & ES_MULTILINE))
3220 WARN("called with NULL handle\n");
3224 EDIT_UnlockBuffer(es, TRUE);
3228 LOCAL_Free(hInstance, es->hloc16);
3229 es->hloc16 = (HLOCAL16)NULL;
3236 LocalFree(es->hloc32A);
3248 countA = LocalSize(hloc);
3249 textA = LocalLock(hloc);
3250 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3251 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3253 ERR("Could not allocate new unicode buffer\n");
3256 textW = LocalLock(hloc32W_new);
3257 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3258 LocalUnlock(hloc32W_new);
3262 LocalFree(es->hloc32W);
3264 es->hloc32W = hloc32W_new;
3268 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3270 EDIT_LockBuffer(es);
3272 es->x_offset = es->y_offset = 0;
3273 es->selection_start = es->selection_end = 0;
3274 EDIT_EM_EmptyUndoBuffer(es);
3275 es->flags &= ~EF_MODIFIED;
3276 es->flags &= ~EF_UPDATE;
3277 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3278 EDIT_UpdateText(es, NULL, TRUE);
3279 EDIT_EM_ScrollCaret(es);
3280 /* force scroll info update */
3281 EDIT_UpdateScrollInfo(es);
3285 /*********************************************************************
3289 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3292 static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc)
3294 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
3300 if (!(es->style & ES_MULTILINE))
3304 WARN("called with NULL handle\n");
3308 EDIT_UnlockBuffer(es, TRUE);
3312 LocalFree(es->hloc32A);
3316 countA = LOCAL_Size(hInstance, hloc);
3317 textA = LOCAL_Lock(hInstance, hloc);
3318 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3319 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3321 ERR("Could not allocate new unicode buffer\n");
3324 textW = LocalLock(hloc32W_new);
3325 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3326 LocalUnlock(hloc32W_new);
3327 LOCAL_Unlock(hInstance, hloc);
3330 LocalFree(es->hloc32W);
3332 es->hloc32W = hloc32W_new;
3335 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3337 EDIT_LockBuffer(es);
3339 es->x_offset = es->y_offset = 0;
3340 es->selection_start = es->selection_end = 0;
3341 EDIT_EM_EmptyUndoBuffer(es);
3342 es->flags &= ~EF_MODIFIED;
3343 es->flags &= ~EF_UPDATE;
3344 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3345 EDIT_UpdateText(es, NULL, TRUE);
3346 EDIT_EM_ScrollCaret(es);
3347 /* force scroll info update */
3348 EDIT_UpdateScrollInfo(es);
3352 /*********************************************************************
3356 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3357 * However, the windows version is not complied to yet in all of edit.c
3359 * Additionally as the wrapper for RichEdit controls we need larger buffers
3360 * at present -1 will represent nolimit
3362 static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit)
3364 if (limit == 0xFFFFFFFF)
3365 es->buffer_limit = -1;
3366 else if (es->style & ES_MULTILINE) {
3368 es->buffer_limit = min(limit, BUFLIMIT_MULTI);
3370 es->buffer_limit = BUFLIMIT_MULTI;
3373 es->buffer_limit = min(limit, BUFLIMIT_SINGLE);
3375 es->buffer_limit = BUFLIMIT_SINGLE;
3380 /*********************************************************************
3384 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3385 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3386 * margin according to the textmetrics of the current font.
3388 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3389 * of the char's width as the margin, but this is not how Windows handles this.
3390 * For all other fonts Windows sets the margins to zero.
3393 static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
3394 INT left, INT right)
3397 INT default_left_margin = 0; /* in pixels */
3398 INT default_right_margin = 0; /* in pixels */
3400 /* Set the default margins depending on the font */
3401 if (es->font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO)) {
3402 HDC dc = GetDC(es->hwndSelf);
3403 HFONT old_font = SelectObject(dc, es->font);
3404 GetTextMetricsW(dc, &tm);
3405 /* The default margins are only non zero for TrueType or Vector fonts */
3406 if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) {
3407 /* This must be calculated more exactly! But how? */
3408 default_left_margin = tm.tmAveCharWidth / 3;
3409 default_right_margin = tm.tmAveCharWidth / 3;
3411 SelectObject(dc, old_font);
3412 ReleaseDC(es->hwndSelf, dc);
3415 if (action & EC_LEFTMARGIN) {
3416 if (left != EC_USEFONTINFO)
3417 es->left_margin = left;
3419 es->left_margin = default_left_margin;
3422 if (action & EC_RIGHTMARGIN) {
3423 if (right != EC_USEFONTINFO)
3424 es->right_margin = right;
3426 es->right_margin = default_right_margin;
3428 TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin);
3432 /*********************************************************************
3434 * EM_SETPASSWORDCHAR
3437 static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c)
3441 if (es->style & ES_MULTILINE)
3444 if (es->password_char == c)
3447 style = GetWindowLongW( es->hwndSelf, GWL_STYLE );
3448 es->password_char = c;
3450 SetWindowLongW( es->hwndSelf, GWL_STYLE, style | ES_PASSWORD );
3451 es->style |= ES_PASSWORD;
3453 SetWindowLongW( es->hwndSelf, GWL_STYLE, style & ~ES_PASSWORD );
3454 es->style &= ~ES_PASSWORD;
3456 EDIT_UpdateText(es, NULL, TRUE);
3460 /*********************************************************************
3464 * note: unlike the specs say: the order of start and end
3465 * _is_ preserved in Windows. (i.e. start can be > end)
3466 * In other words: this handler is OK
3469 static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
3471 UINT old_start = es->selection_start;
3472 UINT old_end = es->selection_end;
3473 UINT len = strlenW(es->text);
3475 if (start == (UINT)-1) {
3476 start = es->selection_end;
3477 end = es->selection_end;
3479 start = min(start, len);
3480 end = min(end, len);
3482 es->selection_start = start;
3483 es->selection_end = end;
3485 es->flags |= EF_AFTER_WRAP;
3487 es->flags &= ~EF_AFTER_WRAP;
3488 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3489 ORDER_UINT(start, end);
3490 ORDER_UINT(end, old_end);
3491 ORDER_UINT(start, old_start);
3492 ORDER_UINT(old_start, old_end);
3493 if (end != old_start)
3497 * ORDER_UINT32(end, old_start);
3498 * EDIT_InvalidateText(es, start, end);
3499 * EDIT_InvalidateText(es, old_start, old_end);
3500 * in place of the following if statement.
3502 if (old_start > end )
3504 EDIT_InvalidateText(es, start, end);
3505 EDIT_InvalidateText(es, old_start, old_end);
3509 EDIT_InvalidateText(es, start, old_start);
3510 EDIT_InvalidateText(es, end, old_end);
3513 else EDIT_InvalidateText(es, start, old_end);
3517 /*********************************************************************
3522 static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs)
3524 if (!(es->style & ES_MULTILINE))
3526 HeapFree(GetProcessHeap(), 0, es->tabs);
3527 es->tabs_count = count;
3531 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
3532 memcpy(es->tabs, tabs, count * sizeof(INT));
3538 /*********************************************************************
3543 static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs)
3545 if (!(es->style & ES_MULTILINE))
3547 HeapFree(GetProcessHeap(), 0, es->tabs);
3548 es->tabs_count = count;
3553 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
3554 for (i = 0 ; i < count ; i++)
3555 es->tabs[i] = *tabs++;
3561 /*********************************************************************
3563 * EM_SETWORDBREAKPROC
3566 static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, void *wbp)
3568 if (es->word_break_proc == wbp)
3571 es->word_break_proc = wbp;
3572 es->word_break_proc16 = NULL;
3574 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
3575 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3576 EDIT_UpdateText(es, NULL, TRUE);
3581 /*********************************************************************
3583 * EM_SETWORDBREAKPROC16
3586 static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
3588 if (es->word_break_proc16 == wbp)
3591 es->word_break_proc = NULL;
3592 es->word_break_proc16 = wbp;
3593 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
3594 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
3595 EDIT_UpdateText(es, NULL, TRUE);
3600 /*********************************************************************
3605 static BOOL EDIT_EM_Undo(EDITSTATE *es)
3610 /* As per MSDN spec, for a single-line edit control,
3611 the return value is always TRUE */
3612 if( es->style & ES_READONLY )
3613 return !(es->style & ES_MULTILINE);
3615 ulength = strlenW(es->undo_text);
3617 utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR));
3619 strcpyW(utext, es->undo_text);
3621 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3622 es->undo_insert_count, debugstr_w(utext));
3624 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
3625 EDIT_EM_EmptyUndoBuffer(es);
3626 EDIT_EM_ReplaceSel(es, TRUE, utext, TRUE, TRUE);
3627 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
3628 /* send the notification after the selection start and end are set */
3629 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3630 EDIT_EM_ScrollCaret(es);
3631 HeapFree(GetProcessHeap(), 0, utext);
3633 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3634 es->undo_insert_count, debugstr_w(es->undo_text));
3639 /*********************************************************************
3644 static void EDIT_WM_Char(EDITSTATE *es, WCHAR c)
3648 control = GetKeyState(VK_CONTROL) & 0x8000;
3652 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3653 if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
3656 if (es->style & ES_MULTILINE) {
3657 if (es->style & ES_READONLY) {
3658 EDIT_MoveHome(es, FALSE);
3659 EDIT_MoveDown_ML(es, FALSE);
3661 static const WCHAR cr_lfW[] = {'\r','\n',0};
3662 EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, TRUE, TRUE);
3667 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
3669 static const WCHAR tabW[] = {'\t',0};
3670 EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE, TRUE);
3674 if (!(es->style & ES_READONLY) && !control) {
3675 if (es->selection_start != es->selection_end)
3678 /* delete character left of caret */
3679 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
3680 EDIT_MoveBackward(es, TRUE);
3686 SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
3689 if (!(es->style & ES_READONLY))
3690 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
3693 if (!(es->style & ES_READONLY))
3694 SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
3698 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3699 if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') )
3702 if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) {
3706 EDIT_EM_ReplaceSel(es, TRUE, str, TRUE, TRUE);
3713 /*********************************************************************
3718 static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND control)
3720 if (code || control)
3740 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
3741 EDIT_EM_ScrollCaret(es);
3744 ERR("unknown menu item, please report\n");
3750 /*********************************************************************
3754 * Note: the resource files resource/sysres_??.rc cannot define a
3755 * single popup menu. Hence we use a (dummy) menubar
3756 * containing the single popup menu as its first item.
3758 * FIXME: the message identifiers have been chosen arbitrarily,
3759 * hence we use MF_BYPOSITION.
3760 * We might as well use the "real" values (anybody knows ?)
3761 * The menu definition is in resources/sysres_??.rc.
3762 * Once these are OK, we better use MF_BYCOMMAND here
3763 * (as we do in EDIT_WM_Command()).
3766 static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
3768 HMENU menu = LoadMenuA(user32_module, "EDITMENU");
3769 HMENU popup = GetSubMenu(menu, 0);
3770 UINT start = es->selection_start;
3771 UINT end = es->selection_end;
3773 ORDER_UINT(start, end);
3776 EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3778 EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3780 EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
3782 EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3784 EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3786 EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != strlenW(es->text)) ? MF_ENABLED : MF_GRAYED));
3788 TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, es->hwndSelf, NULL);
3793 /*********************************************************************
3798 static void EDIT_WM_Copy(EDITSTATE *es)
3800 INT s = min(es->selection_start, es->selection_end);
3801 INT e = max(es->selection_start, es->selection_end);
3807 hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR));
3808 dst = GlobalLock(hdst);
3809 strncpyW(dst, es->text + s, e - s);
3810 dst[e - s] = 0; /* ensure 0 termination */
3811 TRACE("%s\n", debugstr_w(dst));
3813 OpenClipboard(es->hwndSelf);
3815 SetClipboardData(CF_UNICODETEXT, hdst);
3820 /*********************************************************************
3825 static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name)
3827 TRACE("%s\n", debugstr_w(name));
3829 * To initialize some final structure members, we call some helper
3830 * functions. However, since the EDITSTATE is not consistent (i.e.
3831 * not fully initialized), we should be very careful which
3832 * functions can be called, and in what order.
3834 EDIT_WM_SetFont(es, 0, FALSE);
3835 EDIT_EM_EmptyUndoBuffer(es);
3837 if (name && *name) {
3838 EDIT_EM_ReplaceSel(es, FALSE, name, FALSE, TRUE);
3839 /* if we insert text to the editline, the text scrolls out
3840 * of the window, as the caret is placed after the insert
3841 * pos normally; thus we reset es->selection... to 0 and
3844 es->selection_start = es->selection_end = 0;
3845 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3846 * Messages are only to be sent when the USER does something to
3847 * change the contents. So I am removing this EN_CHANGE
3849 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3851 EDIT_EM_ScrollCaret(es);
3853 /* force scroll info update */
3854 EDIT_UpdateScrollInfo(es);
3855 /* The rule seems to return 1 here for success */
3856 /* Power Builder masked edit controls will crash */
3858 /* FIXME: is that in all cases so ? */
3863 /*********************************************************************
3868 static LRESULT EDIT_WM_Destroy(EDITSTATE *es)
3873 while (LocalUnlock(es->hloc32W)) ;
3874 LocalFree(es->hloc32W);
3877 while (LocalUnlock(es->hloc32A)) ;
3878 LocalFree(es->hloc32A);
3881 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
3882 while (LOCAL_Unlock(hInstance, es->hloc16)) ;
3883 LOCAL_Free(hInstance, es->hloc16);
3886 pc = es->first_line_def;
3890 HeapFree(GetProcessHeap(), 0, pc);
3894 SetWindowLongW( es->hwndSelf, 0, 0 );
3895 HeapFree(GetProcessHeap(), 0, es);
3901 /*********************************************************************
3906 static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc)
3908 /* we do the proper erase in EDIT_WM_Paint */
3913 /*********************************************************************
3918 static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPWSTR dst, BOOL unicode)
3920 if(!count) return 0;
3924 lstrcpynW(dst, es->text, count);
3925 return strlenW(dst);
3929 LPSTR textA = (LPSTR)dst;
3930 if (!WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, count, NULL, NULL))
3931 textA[count - 1] = 0; /* ensure 0 termination */
3932 return strlen(textA);
3936 /*********************************************************************
3941 static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos)
3946 if (!(es->style & ES_MULTILINE))
3949 if (!(es->style & ES_AUTOHSCROLL))
3953 fw = es->format_rect.right - es->format_rect.left;
3956 TRACE("SB_LINELEFT\n");
3958 dx = -es->char_width;
3961 TRACE("SB_LINERIGHT\n");
3962 if (es->x_offset < es->text_width)
3963 dx = es->char_width;
3966 TRACE("SB_PAGELEFT\n");
3968 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3971 TRACE("SB_PAGERIGHT\n");
3972 if (es->x_offset < es->text_width)
3973 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3981 TRACE("SB_RIGHT\n");
3982 if (es->x_offset < es->text_width)
3983 dx = es->text_width - es->x_offset;
3986 TRACE("SB_THUMBTRACK %d\n", pos);
3987 es->flags |= EF_HSCROLL_TRACK;
3988 if(es->style & WS_HSCROLL)
3989 dx = pos - es->x_offset;
3994 if(pos < 0 || pos > 100) return 0;
3995 /* Assume default scroll range 0-100 */
3996 fw = es->format_rect.right - es->format_rect.left;
3997 new_x = pos * (es->text_width - fw) / 100;
3998 dx = es->text_width ? (new_x - es->x_offset) : 0;
4001 case SB_THUMBPOSITION:
4002 TRACE("SB_THUMBPOSITION %d\n", pos);
4003 es->flags &= ~EF_HSCROLL_TRACK;
4004 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
4005 dx = pos - es->x_offset;
4010 if(pos < 0 || pos > 100) return 0;
4011 /* Assume default scroll range 0-100 */
4012 fw = es->format_rect.right - es->format_rect.left;
4013 new_x = pos * (es->text_width - fw) / 100;
4014 dx = es->text_width ? (new_x - es->x_offset) : 0;
4017 /* force scroll info update */
4018 EDIT_UpdateScrollInfo(es);
4019 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
4023 TRACE("SB_ENDSCROLL\n");
4026 * FIXME : the next two are undocumented !
4027 * Are we doing the right thing ?
4028 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4029 * although it's also a regular control message.
4031 case EM_GETTHUMB: /* this one is used by NT notepad */
4035 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
4036 ret = GetScrollPos(es->hwndSelf, SB_HORZ);
4039 /* Assume default scroll range 0-100 */
4040 INT fw = es->format_rect.right - es->format_rect.left;
4041 ret = es->text_width ? es->x_offset * 100 / (es->text_width - fw) : 0;
4043 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4046 case EM_LINESCROLL16:
4047 TRACE("EM_LINESCROLL16\n");
4052 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4058 INT fw = es->format_rect.right - es->format_rect.left;
4059 /* check if we are going to move too far */
4060 if(es->x_offset + dx + fw > es->text_width)
4061 dx = es->text_width - fw - es->x_offset;
4063 EDIT_EM_LineScroll_internal(es, dx, 0);
4069 /*********************************************************************
4074 static BOOL EDIT_CheckCombo(EDITSTATE *es, UINT msg, INT key)
4076 HWND hLBox = es->hwndListBox;
4084 hCombo = GetParent(es->hwndSelf);
4088 TRACE_(combo)("[%p]: handling msg %x (%x)\n", es->hwndSelf, msg, key);
4090 if (key == VK_UP || key == VK_DOWN)
4092 if (SendMessageW(hCombo, CB_GETEXTENDEDUI, 0, 0))
4095 if (msg == WM_KEYDOWN || nEUI)
4096 bDropped = (BOOL)SendMessageW(hCombo, CB_GETDROPPEDSTATE, 0, 0);
4102 if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN))
4104 /* make sure ComboLBox pops up */
4105 SendMessageW(hCombo, CB_SETEXTENDEDUI, FALSE, 0);
4110 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
4113 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
4115 SendMessageW(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0);
4117 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0);
4122 SendMessageW(hCombo, CB_SETEXTENDEDUI, TRUE, 0);
4128 /*********************************************************************
4132 * Handling of special keys that don't produce a WM_CHAR
4133 * (i.e. non-printable keys) & Backspace & Delete
4136 static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key)
4141 if (GetKeyState(VK_MENU) & 0x8000)
4144 shift = GetKeyState(VK_SHIFT) & 0x8000;
4145 control = GetKeyState(VK_CONTROL) & 0x8000;
4150 if (EDIT_CheckCombo(es, WM_KEYDOWN, key) || key == VK_F4)
4155 if ((es->style & ES_MULTILINE) && (key == VK_UP))
4156 EDIT_MoveUp_ML(es, shift);
4159 EDIT_MoveWordBackward(es, shift);
4161 EDIT_MoveBackward(es, shift);
4164 if (EDIT_CheckCombo(es, WM_KEYDOWN, key))
4168 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
4169 EDIT_MoveDown_ML(es, shift);
4171 EDIT_MoveWordForward(es, shift);
4173 EDIT_MoveForward(es, shift);
4176 EDIT_MoveHome(es, shift);
4179 EDIT_MoveEnd(es, shift);
4182 if (es->style & ES_MULTILINE)
4183 EDIT_MovePageUp_ML(es, shift);
4185 EDIT_CheckCombo(es, WM_KEYDOWN, key);
4188 if (es->style & ES_MULTILINE)
4189 EDIT_MovePageDown_ML(es, shift);
4191 EDIT_CheckCombo(es, WM_KEYDOWN, key);
4194 if (!(es->style & ES_READONLY) && !(shift && control)) {
4195 if (es->selection_start != es->selection_end) {
4202 /* delete character left of caret */
4203 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4204 EDIT_MoveBackward(es, TRUE);
4206 } else if (control) {
4207 /* delete to end of line */
4208 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4209 EDIT_MoveEnd(es, TRUE);
4212 /* delete character right of caret */
4213 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4214 EDIT_MoveForward(es, TRUE);
4222 if (!(es->style & ES_READONLY))
4228 /* If the edit doesn't want the return send a message to the default object */
4229 if(!(es->style & ES_WANTRETURN))
4231 HWND hwndParent = GetParent(es->hwndSelf);
4232 DWORD dw = SendMessageW( hwndParent, DM_GETDEFID, 0, 0 );
4233 if (HIWORD(dw) == DC_HASDEFID)
4235 SendMessageW( hwndParent, WM_COMMAND,
4236 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
4237 (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
4246 /*********************************************************************
4251 static LRESULT EDIT_WM_KillFocus(EDITSTATE *es)
4253 es->flags &= ~EF_FOCUSED;
4255 if(!(es->style & ES_NOHIDESEL))
4256 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4257 EDIT_NOTIFY_PARENT(es, EN_KILLFOCUS, "EN_KILLFOCUS");
4262 /*********************************************************************
4266 * The caret position has been set on the WM_LBUTTONDOWN message
4269 static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es)
4272 INT e = es->selection_end;
4277 if (!(es->flags & EF_FOCUSED))
4280 l = EDIT_EM_LineFromChar(es, e);
4281 li = EDIT_EM_LineIndex(es, l);
4282 ll = EDIT_EM_LineLength(es, e);
4283 s = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT);
4284 e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_RIGHT);
4285 EDIT_EM_SetSel(es, s, e, FALSE);
4286 EDIT_EM_ScrollCaret(es);
4291 /*********************************************************************
4296 static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y)
4301 SetFocus(es->hwndSelf);
4302 if (!(es->flags & EF_FOCUSED))
4305 es->bCaptureState = TRUE;
4306 SetCapture(es->hwndSelf);
4307 EDIT_ConfinePoint(es, &x, &y);
4308 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4309 EDIT_EM_SetSel(es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
4310 EDIT_EM_ScrollCaret(es);
4311 es->region_posx = es->region_posy = 0;
4312 SetTimer(es->hwndSelf, 0, 100, NULL);
4317 /*********************************************************************
4322 static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es)
4324 if (es->bCaptureState) {
4325 KillTimer(es->hwndSelf, 0);
4326 if (GetCapture() == es->hwndSelf) ReleaseCapture();
4328 es->bCaptureState = FALSE;
4333 /*********************************************************************
4338 static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es)
4340 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
4345 /*********************************************************************
4350 static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y)
4356 if (GetCapture() != es->hwndSelf)
4360 * FIXME: gotta do some scrolling if outside client
4361 * area. Maybe reset the timer ?
4364 EDIT_ConfinePoint(es, &x, &y);
4365 es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
4366 es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
4367 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4368 EDIT_EM_SetSel(es, es->selection_start, e, after_wrap);
4369 EDIT_SetCaretPos(es,es->selection_end,es->flags & EF_AFTER_WRAP);
4374 /*********************************************************************
4378 * See also EDIT_WM_StyleChanged
4380 static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode)
4385 TRACE("Creating %s edit control, style = %08lx\n",
4386 unicode ? "Unicode" : "ANSI", lpcs->style);
4388 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
4390 SetWindowLongW( hwnd, 0, (LONG)es );
4393 * Note: since the EDITSTATE has not been fully initialized yet,
4394 * we can't use any API calls that may send
4395 * WM_XXX messages before WM_NCCREATE is completed.
4398 es->is_unicode = unicode;
4399 es->style = lpcs->style;
4401 es->bEnableState = !(es->style & WS_DISABLED);
4403 es->hwndSelf = hwnd;
4404 /* Save parent, which will be notified by EN_* messages */
4405 es->hwndParent = lpcs->hwndParent;
4407 if (es->style & ES_COMBO)
4408 es->hwndListBox = GetDlgItem(es->hwndParent, ID_CB_LISTBOX);
4410 /* Number overrides lowercase overrides uppercase (at least it
4411 * does in Win95). However I'll bet that ES_NUMBER would be
4412 * invalid under Win 3.1.
4414 if (es->style & ES_NUMBER) {
4415 ; /* do not override the ES_NUMBER */
4416 } else if (es->style & ES_LOWERCASE) {
4417 es->style &= ~ES_UPPERCASE;
4419 if (es->style & ES_MULTILINE) {
4420 es->buffer_limit = BUFLIMIT_MULTI;
4421 if (es->style & WS_VSCROLL)
4422 es->style |= ES_AUTOVSCROLL;
4423 if (es->style & WS_HSCROLL)
4424 es->style |= ES_AUTOHSCROLL;
4425 es->style &= ~ES_PASSWORD;
4426 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
4427 /* Confirmed - RIGHT overrides CENTER */
4428 if (es->style & ES_RIGHT)
4429 es->style &= ~ES_CENTER;
4430 es->style &= ~WS_HSCROLL;
4433 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4434 es->style |= ES_AUTOVSCROLL;
4436 es->buffer_limit = BUFLIMIT_SINGLE;
4437 es->style &= ~ES_CENTER;
4438 es->style &= ~ES_RIGHT;
4439 es->style &= ~WS_HSCROLL;
4440 es->style &= ~WS_VSCROLL;
4441 if (es->style & ES_PASSWORD)
4442 es->password_char = '*';
4444 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4445 es->style |= ES_AUTOHSCROLL;
4448 alloc_size = ROUND_TO_GROW((es->buffer_size + 1) * sizeof(WCHAR));
4449 if(!(es->hloc32W = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
4451 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
4453 if (!(es->undo_text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (es->buffer_size + 1) * sizeof(WCHAR))))
4455 es->undo_buffer_size = es->buffer_size;
4457 if (es->style & ES_MULTILINE)
4458 if (!(es->first_line_def = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
4463 * In Win95 look and feel, the WS_BORDER style is replaced by the
4464 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4465 * control a nonclient area so we don't need to draw the border.
4466 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4467 * a nonclient area and we should handle painting the border ourselves.
4469 * When making modifications please ensure that the code still works
4470 * for edit controls created directly with style 0x50800000, exStyle 0
4471 * (which should have a single pixel border)
4473 if (lpcs->dwExStyle & WS_EX_CLIENTEDGE)
4474 es->style &= ~WS_BORDER;
4475 else if (es->style & WS_BORDER)
4476 SetWindowLongW(hwnd, GWL_STYLE, es->style & ~WS_BORDER);
4481 /*********************************************************************
4486 static void EDIT_WM_Paint(EDITSTATE *es, HDC hdc)
4497 BOOL rev = es->bEnableState &&
4498 ((es->flags & EF_FOCUSED) ||
4499 (es->style & ES_NOHIDESEL));
4500 dc = hdc ? hdc : BeginPaint(es->hwndSelf, &ps);
4502 GetClientRect(es->hwndSelf, &rcClient);
4504 /* paint the background */
4505 if (!(brush = EDIT_NotifyCtlColor(es, dc)))
4506 brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
4507 IntersectClipRect(dc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
4508 GetClipBox(dc, &rc);
4509 FillRect(dc, &rc, brush);
4511 /* draw the border */
4512 if(es->style & WS_BORDER) {
4514 if(es->style & ES_MULTILINE) {
4515 if(es->style & WS_HSCROLL) rc.bottom++;
4516 if(es->style & WS_VSCROLL) rc.right++;
4518 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
4520 IntersectClipRect(dc, es->format_rect.left,
4521 es->format_rect.top,
4522 es->format_rect.right,
4523 es->format_rect.bottom);
4524 if (es->style & ES_MULTILINE) {
4526 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
4529 old_font = SelectObject(dc, es->font);
4530 EDIT_NotifyCtlColor(es, dc);
4532 if (!es->bEnableState)
4533 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
4534 GetClipBox(dc, &rcRgn);
4535 if (es->style & ES_MULTILINE) {
4536 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4537 for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
4538 EDIT_GetLineRect(es, i, 0, -1, &rcLine);
4539 if (IntersectRect(&rc, &rcRgn, &rcLine))
4540 EDIT_PaintLine(es, dc, i, rev);
4543 EDIT_GetLineRect(es, 0, 0, -1, &rcLine);
4544 if (IntersectRect(&rc, &rcRgn, &rcLine))
4545 EDIT_PaintLine(es, dc, 0, rev);
4548 SelectObject(dc, old_font);
4551 EndPaint(es->hwndSelf, &ps);
4555 /*********************************************************************
4560 static void EDIT_WM_Paste(EDITSTATE *es)
4565 /* Protect read-only edit control from modification */
4566 if(es->style & ES_READONLY)
4569 OpenClipboard(es->hwndSelf);
4570 if ((hsrc = GetClipboardData(CF_UNICODETEXT))) {
4571 src = (LPWSTR)GlobalLock(hsrc);
4572 EDIT_EM_ReplaceSel(es, TRUE, src, TRUE, TRUE);
4579 /*********************************************************************
4584 static void EDIT_WM_SetFocus(EDITSTATE *es)
4586 es->flags |= EF_FOCUSED;
4587 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4588 EDIT_SetCaretPos(es, es->selection_end,
4589 es->flags & EF_AFTER_WRAP);
4590 if(!(es->style & ES_NOHIDESEL))
4591 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4592 ShowCaret(es->hwndSelf);
4593 EDIT_NOTIFY_PARENT(es, EN_SETFOCUS, "EN_SETFOCUS");
4597 /*********************************************************************
4601 * With Win95 look the margins are set to default font value unless
4602 * the system font (font == 0) is being set, in which case they are left
4606 static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
4614 dc = GetDC(es->hwndSelf);
4616 old_font = SelectObject(dc, font);
4617 GetTextMetricsW(dc, &tm);
4618 es->line_height = tm.tmHeight;
4619 es->char_width = tm.tmAveCharWidth;
4621 SelectObject(dc, old_font);
4622 ReleaseDC(es->hwndSelf, dc);
4623 EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
4624 EC_USEFONTINFO, EC_USEFONTINFO);
4626 /* Force the recalculation of the format rect for each font change */
4627 GetClientRect(es->hwndSelf, &r);
4628 EDIT_SetRectNP(es, &r);
4630 if (es->style & ES_MULTILINE)
4631 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
4633 EDIT_CalcLineWidth_SL(es);
4636 EDIT_UpdateText(es, NULL, TRUE);
4637 if (es->flags & EF_FOCUSED) {
4639 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4640 EDIT_SetCaretPos(es, es->selection_end,
4641 es->flags & EF_AFTER_WRAP);
4642 ShowCaret(es->hwndSelf);
4647 /*********************************************************************
4652 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4653 * The modified flag is reset. No notifications are sent.
4655 * For single-line controls, reception of WM_SETTEXT triggers:
4656 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4659 static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text, BOOL unicode)
4661 if (!unicode && text)
4663 LPCSTR textA = (LPCSTR)text;
4664 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
4665 LPWSTR textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR));
4667 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
4671 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
4674 TRACE("%s\n", debugstr_w(text));
4675 EDIT_EM_ReplaceSel(es, FALSE, text, FALSE, FALSE);
4677 HeapFree(GetProcessHeap(), 0, (LPWSTR)text);
4681 static const WCHAR empty_stringW[] = {0};
4683 EDIT_EM_ReplaceSel(es, FALSE, empty_stringW, FALSE, FALSE);
4686 es->flags &= ~EF_MODIFIED;
4687 EDIT_EM_SetSel(es, 0, 0, FALSE);
4689 /* Send the notification after the selection start and end have been set
4690 * edit control doesn't send notification on WM_SETTEXT
4691 * if it is multiline, or it is part of combobox
4693 if( !((es->style & ES_MULTILINE) || es->hwndListBox))
4695 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
4696 EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4698 EDIT_EM_ScrollCaret(es);
4702 /*********************************************************************
4707 static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height)
4709 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
4711 TRACE("width = %d, height = %d\n", width, height);
4712 SetRect(&rc, 0, 0, width, height);
4713 EDIT_SetRectNP(es, &rc);
4714 EDIT_UpdateText(es, NULL, TRUE);
4719 /*********************************************************************
4723 * This message is sent by SetWindowLong on having changed either the Style
4724 * or the extended style.
4726 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4728 * See also EDIT_WM_NCCreate
4730 * It appears that the Windows version of the edit control allows the style
4731 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4732 * style variable which will generally be different. In this function we
4733 * update the internal style based on what changed in the externally visible
4736 * Much of this content as based upon the MSDN, especially:
4737 * Platform SDK Documentation -> User Interface Services ->
4738 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4739 * Edit Control Styles
4741 static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLESTRUCT *style)
4743 if (GWL_STYLE == which) {
4744 DWORD style_change_mask;
4746 /* Only a subset of changes can be applied after the control
4749 style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
4751 if (es->style & ES_MULTILINE)
4752 style_change_mask |= ES_WANTRETURN;
4754 new_style = style->styleNew & style_change_mask;
4756 /* Number overrides lowercase overrides uppercase (at least it
4757 * does in Win95). However I'll bet that ES_NUMBER would be
4758 * invalid under Win 3.1.
4760 if (new_style & ES_NUMBER) {
4761 ; /* do not override the ES_NUMBER */
4762 } else if (new_style & ES_LOWERCASE) {
4763 new_style &= ~ES_UPPERCASE;
4766 es->style = (es->style & ~style_change_mask) | new_style;
4767 } else if (GWL_EXSTYLE == which) {
4768 ; /* FIXME - what is needed here */
4770 WARN ("Invalid style change %d\n",which);
4776 /*********************************************************************
4781 static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data)
4783 if ((key == VK_BACK) && (key_data & 0x2000)) {
4784 if (EDIT_EM_CanUndo(es))
4787 } else if (key == VK_UP || key == VK_DOWN) {
4788 if (EDIT_CheckCombo(es, WM_SYSKEYDOWN, key))
4791 return DefWindowProcW(es->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
4795 /*********************************************************************
4800 static void EDIT_WM_Timer(EDITSTATE *es)
4802 if (es->region_posx < 0) {
4803 EDIT_MoveBackward(es, TRUE);
4804 } else if (es->region_posx > 0) {
4805 EDIT_MoveForward(es, TRUE);
4808 * FIXME: gotta do some vertical scrolling here, like
4809 * EDIT_EM_LineScroll(hwnd, 0, 1);
4813 /*********************************************************************
4818 static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos)
4822 if (!(es->style & ES_MULTILINE))
4825 if (!(es->style & ES_AUTOVSCROLL))
4834 TRACE("action %d (%s)\n", action, (action == SB_LINEUP ? "SB_LINEUP" :
4835 (action == SB_LINEDOWN ? "SB_LINEDOWN" :
4836 (action == SB_PAGEUP ? "SB_PAGEUP" :
4838 EDIT_EM_Scroll(es, action);
4845 TRACE("SB_BOTTOM\n");
4846 dy = es->line_count - 1 - es->y_offset;
4849 TRACE("SB_THUMBTRACK %d\n", pos);
4850 es->flags |= EF_VSCROLL_TRACK;
4851 if(es->style & WS_VSCROLL)
4852 dy = pos - es->y_offset;
4855 /* Assume default scroll range 0-100 */
4858 if(pos < 0 || pos > 100) return 0;
4859 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4860 new_y = pos * (es->line_count - vlc) / 100;
4861 dy = es->line_count ? (new_y - es->y_offset) : 0;
4862 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4863 es->line_count, es->y_offset, pos, dy);
4866 case SB_THUMBPOSITION:
4867 TRACE("SB_THUMBPOSITION %d\n", pos);
4868 es->flags &= ~EF_VSCROLL_TRACK;
4869 if(es->style & WS_VSCROLL)
4870 dy = pos - es->y_offset;
4873 /* Assume default scroll range 0-100 */
4876 if(pos < 0 || pos > 100) return 0;
4877 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4878 new_y = pos * (es->line_count - vlc) / 100;
4879 dy = es->line_count ? (new_y - es->y_offset) : 0;
4880 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4881 es->line_count, es->y_offset, pos, dy);
4885 /* force scroll info update */
4886 EDIT_UpdateScrollInfo(es);
4887 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
4891 TRACE("SB_ENDSCROLL\n");
4894 * FIXME : the next two are undocumented !
4895 * Are we doing the right thing ?
4896 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4897 * although it's also a regular control message.
4899 case EM_GETTHUMB: /* this one is used by NT notepad */
4903 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_VSCROLL)
4904 ret = GetScrollPos(es->hwndSelf, SB_VERT);
4907 /* Assume default scroll range 0-100 */
4908 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4909 ret = es->line_count ? es->y_offset * 100 / (es->line_count - vlc) : 0;
4911 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4914 case EM_LINESCROLL16:
4915 TRACE("EM_LINESCROLL16 %d\n", pos);
4920 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4925 EDIT_EM_LineScroll(es, 0, dy);
4929 /*********************************************************************
4934 static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase)
4936 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4937 InvalidateRgn(es->hwndSelf, hrgn, bErase);
4941 /*********************************************************************
4946 static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase)
4948 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4949 InvalidateRect(es->hwndSelf, rc, bErase);