Fixed strict aliasing issue in __pthread_once and SetWaitableTimer.
[wine/multimedia.git] / controls / edit.c
blob2d14b6d19385c41a94668d3003c18055d1cd04db
1 /*
2 * Edit control
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
23 * TODO:
24 * - ES_CENTER
25 * - ES_RIGHT
26 * - ES_NUMBER (new since win95)
27 * - ES_OEMCONVERT
28 * -!ES_AUTOVSCROLL (every multi line control *is* auto vscroll)
29 * -!ES_AUTOHSCROLL (every single line control *is* auto hscroll)
31 * When there is no autoscrolling, the control should first check whether
32 * the new text would fit. If not, an EN_MAXTEXT should be sent.
33 * However, currently this would require the actual change to be made,
34 * then call EDIT_BuildLineDefs() and then find out that the new text doesn't
35 * fit. After all this, things should be put back in the state before the
36 * changes. Note that for multi line controls !ES_AUTOHSCROLL works : wordwrap.
40 #include "config.h"
42 #include <string.h>
43 #include <stdlib.h>
45 #include "winbase.h"
46 #include "winnt.h"
47 #include "win.h"
48 #include "wine/winbase16.h"
49 #include "wine/winuser16.h"
50 #include "wine/unicode.h"
51 #include "controls.h"
52 #include "local.h"
53 #include "user.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(edit);
57 WINE_DECLARE_DEBUG_CHANNEL(combo);
58 WINE_DECLARE_DEBUG_CHANNEL(relay);
60 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
61 FIXME: BTW, new specs say 65535 (do you dare ???) */
62 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
63 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
64 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
65 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
68 * extra flags for EDITSTATE.flags field
70 #define EF_MODIFIED 0x0001 /* text has been modified */
71 #define EF_FOCUSED 0x0002 /* we have input focus */
72 #define EF_UPDATE 0x0004 /* notify parent of changed state */
73 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
74 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
75 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
76 wrapped line, instead of in front of the next character */
77 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
79 typedef enum
81 END_0 = 0, /* line ends with terminating '\0' character */
82 END_WRAP, /* line is wrapped */
83 END_HARD, /* line ends with a hard return '\r\n' */
84 END_SOFT, /* line ends with a soft return '\r\r\n' */
85 END_RICH /* line ends with a single '\n' */
86 } LINE_END;
88 typedef struct tagLINEDEF {
89 INT length; /* bruto length of a line in bytes */
90 INT net_length; /* netto length of a line in visible characters */
91 LINE_END ending;
92 INT width; /* width of the line in pixels */
93 INT index; /* line index into the buffer */
94 struct tagLINEDEF *next;
95 } LINEDEF;
97 typedef struct
99 BOOL is_unicode; /* how the control was created */
100 LPWSTR text; /* the actual contents of the control */
101 UINT buffer_size; /* the size of the buffer in characters */
102 UINT buffer_limit; /* the maximum size to which the buffer may grow in characters */
103 HFONT font; /* NULL means standard system font */
104 INT x_offset; /* scroll offset for multi lines this is in pixels
105 for single lines it's in characters */
106 INT line_height; /* height of a screen line in pixels */
107 INT char_width; /* average character width in pixels */
108 DWORD style; /* sane version of wnd->dwStyle */
109 WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
110 INT undo_insert_count; /* number of characters inserted in sequence */
111 UINT undo_position; /* character index of the insertion and deletion */
112 LPWSTR undo_text; /* deleted text */
113 UINT undo_buffer_size; /* size of the deleted text buffer */
114 INT selection_start; /* == selection_end if no selection */
115 INT selection_end; /* == current caret position */
116 WCHAR password_char; /* == 0 if no password char, and for multi line controls */
117 INT left_margin; /* in pixels */
118 INT right_margin; /* in pixels */
119 RECT format_rect;
120 INT text_width; /* width of the widest line in pixels for multi line controls
121 and just line width for single line controls */
122 INT region_posx; /* Position of cursor relative to region: */
123 INT region_posy; /* -1: to left, 0: within, 1: to right */
124 EDITWORDBREAKPROC16 word_break_proc16;
125 void *word_break_proc; /* 32-bit word break proc: ANSI or Unicode */
126 INT line_count; /* number of lines */
127 INT y_offset; /* scroll offset in number of lines */
128 BOOL bCaptureState; /* flag indicating whether mouse was captured */
129 BOOL bEnableState; /* flag keeping the enable state */
130 HWND hwndSelf; /* the our window handle */
131 HWND hwndParent; /* Handle of parent for sending EN_* messages.
132 Even if parent will change, EN_* messages
133 should be sent to the first parent. */
134 HWND hwndListBox; /* handle of ComboBox's listbox or NULL */
136 * only for multi line controls
138 INT lock_count; /* amount of re-entries in the EditWndProc */
139 INT tabs_count;
140 LPINT tabs;
141 LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
142 HLOCAL hloc32W; /* our unicode local memory block */
143 HLOCAL16 hloc16; /* alias for 16-bit control receiving EM_GETHANDLE16
144 or EM_SETHANDLE16 */
145 HLOCAL hloc32A; /* alias for ANSI control receiving EM_GETHANDLE
146 or EM_SETHANDLE */
147 } EDITSTATE;
150 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
151 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
153 /* used for disabled or read-only edit control */
154 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
155 do \
156 { /* Notify parent which has created this edit control */ \
157 TRACE("notification " str " sent to hwnd=%08x\n", es->hwndParent); \
158 SendMessageW(es->hwndParent, WM_COMMAND, \
159 MAKEWPARAM(GetWindowLongW((es->hwndSelf),GWL_ID), wNotifyCode), \
160 (LPARAM)(es->hwndSelf)); \
161 } while(0)
163 /*********************************************************************
165 * Declarations
170 * These functions have trivial implementations
171 * We still like to call them internally
172 * "static inline" makes them more like macro's
174 static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es);
175 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es);
176 static inline void EDIT_WM_Clear(EDITSTATE *es);
177 static inline void EDIT_WM_Cut(EDITSTATE *es);
180 * Helper functions only valid for one type of control
182 static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT iStart, INT iEnd, INT delta, HRGN hrgn);
183 static void EDIT_CalcLineWidth_SL(EDITSTATE *es);
184 static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es);
185 static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend);
186 static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend);
187 static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend);
188 static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend);
190 * Helper functions valid for both single line _and_ multi line controls
192 static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action);
193 static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
194 static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y);
195 static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
196 static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end);
197 static void EDIT_LockBuffer(EDITSTATE *es);
198 static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size);
199 static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size);
200 static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend);
201 static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend);
202 static void EDIT_MoveForward(EDITSTATE *es, BOOL extend);
203 static void EDIT_MoveHome(EDITSTATE *es, BOOL extend);
204 static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend);
205 static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend);
206 static void EDIT_PaintLine(EDITSTATE *es, HDC hdc, INT line, BOOL rev);
207 static INT EDIT_PaintText(EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev);
208 static void EDIT_SetCaretPos(EDITSTATE *es, INT pos, BOOL after_wrap);
209 static void EDIT_SetRectNP(EDITSTATE *es, LPRECT lprc);
210 static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force);
211 static void EDIT_UpdateScrollInfo(EDITSTATE *es);
212 static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action);
214 * EM_XXX message handlers
216 static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y);
217 static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol);
218 static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es);
219 static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es);
220 static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPARAM lParam, BOOL unicode);
221 static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end);
222 static LRESULT EDIT_EM_GetThumb(EDITSTATE *es);
223 static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index);
224 static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line);
225 static INT EDIT_EM_LineLength(EDITSTATE *es, INT index);
226 static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy);
227 static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy);
228 static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap);
229 static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update);
230 static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action);
231 static void EDIT_EM_ScrollCaret(EDITSTATE *es);
232 static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc);
233 static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc);
234 static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit);
235 static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, INT left, INT right);
236 static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c);
237 static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap);
238 static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs);
239 static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs);
240 static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, LPARAM lParam);
241 static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp);
242 static BOOL EDIT_EM_Undo(EDITSTATE *es);
244 * WM_XXX message handlers
246 static void EDIT_WM_Char(EDITSTATE *es, WCHAR c);
247 static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND conrtol);
248 static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y);
249 static void EDIT_WM_Copy(EDITSTATE *es);
250 static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name);
251 static LRESULT EDIT_WM_Destroy(EDITSTATE *es);
252 static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc);
253 static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPARAM lParam, BOOL unicode);
254 static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos);
255 static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key);
256 static LRESULT EDIT_WM_KillFocus(EDITSTATE *es);
257 static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es);
258 static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y);
259 static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es);
260 static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es);
261 static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y);
262 static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode);
263 static void EDIT_WM_Paint(EDITSTATE *es, WPARAM wParam);
264 static void EDIT_WM_Paste(EDITSTATE *es);
265 static void EDIT_WM_SetFocus(EDITSTATE *es);
266 static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw);
267 static void EDIT_WM_SetText(EDITSTATE *es, LPARAM lParam, BOOL unicode);
268 static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height);
269 static LRESULT EDIT_WM_StyleChanged(EDITSTATE *es, WPARAM which, const STYLESTRUCT *style);
270 static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data);
271 static void EDIT_WM_Timer(EDITSTATE *es);
272 static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos);
273 static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase);
274 static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase);
276 LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
277 LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
279 /*********************************************************************
280 * edit class descriptor
282 const struct builtin_class_descr EDIT_builtin_class =
284 "Edit", /* name */
285 CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, /* style */
286 EditWndProcA, /* procA */
287 EditWndProcW, /* procW */
288 sizeof(EDITSTATE *), /* extra */
289 IDC_IBEAMA, /* cursor */
290 0 /* brush */
294 /*********************************************************************
296 * EM_CANUNDO
299 static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es)
301 return (es->undo_insert_count || strlenW(es->undo_text));
305 /*********************************************************************
307 * EM_EMPTYUNDOBUFFER
310 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es)
312 es->undo_insert_count = 0;
313 *es->undo_text = '\0';
317 /*********************************************************************
319 * WM_CLEAR
322 static inline void EDIT_WM_Clear(EDITSTATE *es)
324 static const WCHAR empty_stringW[] = {0};
326 /* Protect read-only edit control from modification */
327 if(es->style & ES_READONLY)
328 return;
330 EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE);
334 /*********************************************************************
336 * WM_CUT
339 static inline void EDIT_WM_Cut(EDITSTATE *es)
341 EDIT_WM_Copy(es);
342 EDIT_WM_Clear(es);
346 /**********************************************************************
347 * get_app_version
349 * Returns the window version in case Wine emulates a later version
350 * of windows then the application expects.
352 * In a number of cases when windows runs an application that was
353 * designed for an earlier windows version, windows reverts
354 * to "old" behaviour of that earlier version.
356 * An example is a disabled edit control that needs to be painted.
357 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
358 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
359 * applications with an expected version 0f 4.0 or higher.
362 static DWORD get_app_version(void)
364 static DWORD version;
365 if (!version)
367 DWORD dwEmulatedVersion;
368 OSVERSIONINFOW info;
369 DWORD dwProcVersion = GetProcessVersion(0);
371 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
372 GetVersionExW( &info );
373 dwEmulatedVersion = MAKELONG( info.dwMinorVersion, info.dwMajorVersion );
374 /* FIXME: this may not be 100% correct; see discussion on the
375 * wine developer list in Nov 1999 */
376 version = dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion;
378 return version;
382 static HBRUSH EDIT_NotifyCtlColor(EDITSTATE *es, HDC hdc)
384 UINT msg;
386 if ( get_app_version() >= 0x40000 && (!es->bEnableState || (es->style & ES_READONLY)))
387 msg = WM_CTLCOLORSTATIC;
388 else
389 msg = WM_CTLCOLOREDIT;
391 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
392 return (HBRUSH)SendMessageW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf);
395 static inline LRESULT DefWindowProcT(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
397 if(unicode)
398 return DefWindowProcW(hwnd, msg, wParam, lParam);
399 else
400 return DefWindowProcA(hwnd, msg, wParam, lParam);
403 /*********************************************************************
405 * EditWndProc_common
407 * The messages are in the order of the actual integer values
408 * (which can be found in include/windows.h)
409 * Wherever possible the 16 bit versions are converted to
410 * the 32 bit ones, so that we can 'fall through' to the
411 * helper functions. These are mostly 32 bit (with a few
412 * exceptions, clearly indicated by a '16' extension to their
413 * names).
416 static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg,
417 WPARAM wParam, LPARAM lParam, BOOL unicode )
419 EDITSTATE *es = (EDITSTATE *)GetWindowLongW( hwnd, 0 );
420 LRESULT result = 0;
422 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
424 if (!es && msg != WM_NCCREATE)
425 return DefWindowProcT(hwnd, msg, wParam, lParam, unicode);
426 else if (msg == WM_NCCREATE)
427 return EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTW)lParam, unicode);
428 else if (msg == WM_DESTROY)
429 return EDIT_WM_Destroy(es);
432 if (es) EDIT_LockBuffer(es);
434 switch (msg) {
435 case EM_GETSEL16:
436 wParam = 0;
437 lParam = 0;
438 /* fall through */
439 case EM_GETSEL:
440 result = EDIT_EM_GetSel(es, (PUINT)wParam, (PUINT)lParam);
441 break;
443 case EM_SETSEL16:
444 if (SLOWORD(lParam) == -1)
445 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
446 else
447 EDIT_EM_SetSel(es, LOWORD(lParam), HIWORD(lParam), FALSE);
448 if (!wParam)
449 EDIT_EM_ScrollCaret(es);
450 result = 1;
451 break;
452 case EM_SETSEL:
453 EDIT_EM_SetSel(es, wParam, lParam, FALSE);
454 EDIT_EM_ScrollCaret(es);
455 result = 1;
456 break;
458 case EM_GETRECT16:
459 if (lParam)
460 CONV_RECT32TO16(&es->format_rect, MapSL(lParam));
461 break;
462 case EM_GETRECT:
463 if (lParam)
464 CopyRect((LPRECT)lParam, &es->format_rect);
465 break;
467 case EM_SETRECT16:
468 if ((es->style & ES_MULTILINE) && lParam) {
469 RECT rc;
470 CONV_RECT16TO32(MapSL(lParam), &rc);
471 EDIT_SetRectNP(es, &rc);
472 EDIT_UpdateText(es, NULL, TRUE);
474 break;
475 case EM_SETRECT:
476 if ((es->style & ES_MULTILINE) && lParam) {
477 EDIT_SetRectNP(es, (LPRECT)lParam);
478 EDIT_UpdateText(es, NULL, TRUE);
480 break;
482 case EM_SETRECTNP16:
483 if ((es->style & ES_MULTILINE) && lParam) {
484 RECT rc;
485 CONV_RECT16TO32(MapSL(lParam), &rc);
486 EDIT_SetRectNP(es, &rc);
488 break;
489 case EM_SETRECTNP:
490 if ((es->style & ES_MULTILINE) && lParam)
491 EDIT_SetRectNP(es, (LPRECT)lParam);
492 break;
494 case EM_SCROLL16:
495 case EM_SCROLL:
496 result = EDIT_EM_Scroll(es, (INT)wParam);
497 break;
499 case EM_LINESCROLL16:
500 wParam = (WPARAM)(INT)SHIWORD(lParam);
501 lParam = (LPARAM)(INT)SLOWORD(lParam);
502 /* fall through */
503 case EM_LINESCROLL:
504 result = (LRESULT)EDIT_EM_LineScroll(es, (INT)wParam, (INT)lParam);
505 break;
507 case EM_SCROLLCARET16:
508 case EM_SCROLLCARET:
509 EDIT_EM_ScrollCaret(es);
510 result = 1;
511 break;
513 case EM_GETMODIFY16:
514 case EM_GETMODIFY:
515 result = ((es->flags & EF_MODIFIED) != 0);
516 break;
518 case EM_SETMODIFY16:
519 case EM_SETMODIFY:
520 if (wParam)
521 es->flags |= EF_MODIFIED;
522 else
523 es->flags &= ~(EF_MODIFIED | EF_UPDATE); /* reset pending updates */
524 break;
526 case EM_GETLINECOUNT16:
527 case EM_GETLINECOUNT:
528 result = (es->style & ES_MULTILINE) ? es->line_count : 1;
529 break;
531 case EM_LINEINDEX16:
532 if ((INT16)wParam == -1)
533 wParam = (WPARAM)-1;
534 /* fall through */
535 case EM_LINEINDEX:
536 result = (LRESULT)EDIT_EM_LineIndex(es, (INT)wParam);
537 break;
539 case EM_SETHANDLE16:
540 EDIT_EM_SetHandle16(es, (HLOCAL16)wParam);
541 break;
542 case EM_SETHANDLE:
543 EDIT_EM_SetHandle(es, (HLOCAL)wParam);
544 break;
546 case EM_GETHANDLE16:
547 result = (LRESULT)EDIT_EM_GetHandle16(es);
548 break;
549 case EM_GETHANDLE:
550 result = (LRESULT)EDIT_EM_GetHandle(es);
551 break;
553 case EM_GETTHUMB16:
554 case EM_GETTHUMB:
555 result = EDIT_EM_GetThumb(es);
556 break;
558 /* these messages missing from specs */
559 case WM_USER+15:
560 case 0x00bf:
561 case WM_USER+16:
562 case 0x00c0:
563 case WM_USER+19:
564 case 0x00c3:
565 case WM_USER+26:
566 case 0x00ca:
567 FIXME("undocumented message 0x%x, please report\n", msg);
568 result = DefWindowProcW(hwnd, msg, wParam, lParam);
569 break;
571 case EM_LINELENGTH16:
572 case EM_LINELENGTH:
573 result = (LRESULT)EDIT_EM_LineLength(es, (INT)wParam);
574 break;
576 case EM_REPLACESEL16:
577 lParam = (LPARAM)MapSL(lParam);
578 unicode = FALSE; /* 16-bit message is always ascii */
579 /* fall through */
580 case EM_REPLACESEL:
582 LPWSTR textW;
584 if(unicode)
585 textW = (LPWSTR)lParam;
586 else
588 LPSTR textA = (LPSTR)lParam;
589 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
590 if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
591 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
594 EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, TRUE);
595 result = 1;
597 if(!unicode)
598 HeapFree(GetProcessHeap(), 0, textW);
599 break;
602 case EM_GETLINE16:
603 lParam = (LPARAM)MapSL(lParam);
604 unicode = FALSE; /* 16-bit message is always ascii */
605 /* fall through */
606 case EM_GETLINE:
607 result = (LRESULT)EDIT_EM_GetLine(es, (INT)wParam, lParam, unicode);
608 break;
610 case EM_LIMITTEXT16:
611 case EM_SETLIMITTEXT:
612 EDIT_EM_SetLimitText(es, (INT)wParam);
613 break;
615 case EM_CANUNDO16:
616 case EM_CANUNDO:
617 result = (LRESULT)EDIT_EM_CanUndo(es);
618 break;
620 case EM_UNDO16:
621 case EM_UNDO:
622 case WM_UNDO:
623 result = (LRESULT)EDIT_EM_Undo(es);
624 break;
626 case EM_FMTLINES16:
627 case EM_FMTLINES:
628 result = (LRESULT)EDIT_EM_FmtLines(es, (BOOL)wParam);
629 break;
631 case EM_LINEFROMCHAR16:
632 case EM_LINEFROMCHAR:
633 result = (LRESULT)EDIT_EM_LineFromChar(es, (INT)wParam);
634 break;
636 case EM_SETTABSTOPS16:
637 result = (LRESULT)EDIT_EM_SetTabStops16(es, (INT)wParam, MapSL(lParam));
638 break;
639 case EM_SETTABSTOPS:
640 result = (LRESULT)EDIT_EM_SetTabStops(es, (INT)wParam, (LPINT)lParam);
641 break;
643 case EM_SETPASSWORDCHAR16:
644 unicode = FALSE; /* 16-bit message is always ascii */
645 /* fall through */
646 case EM_SETPASSWORDCHAR:
648 WCHAR charW = 0;
650 if(unicode)
651 charW = (WCHAR)wParam;
652 else
654 CHAR charA = wParam;
655 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
658 EDIT_EM_SetPasswordChar(es, charW);
659 break;
662 case EM_EMPTYUNDOBUFFER16:
663 case EM_EMPTYUNDOBUFFER:
664 EDIT_EM_EmptyUndoBuffer(es);
665 break;
667 case EM_GETFIRSTVISIBLELINE16:
668 result = es->y_offset;
669 break;
670 case EM_GETFIRSTVISIBLELINE:
671 result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
672 break;
674 case EM_SETREADONLY16:
675 case EM_SETREADONLY:
676 if (wParam) {
677 SetWindowLongW( hwnd, GWL_STYLE,
678 GetWindowLongW( hwnd, GWL_STYLE ) | ES_READONLY );
679 es->style |= ES_READONLY;
680 } else {
681 SetWindowLongW( hwnd, GWL_STYLE,
682 GetWindowLongW( hwnd, GWL_STYLE ) & ~ES_READONLY );
683 es->style &= ~ES_READONLY;
685 result = 1;
686 break;
688 case EM_SETWORDBREAKPROC16:
689 EDIT_EM_SetWordBreakProc16(es, (EDITWORDBREAKPROC16)lParam);
690 break;
691 case EM_SETWORDBREAKPROC:
692 EDIT_EM_SetWordBreakProc(es, lParam);
693 break;
695 case EM_GETWORDBREAKPROC16:
696 result = (LRESULT)es->word_break_proc16;
697 break;
698 case EM_GETWORDBREAKPROC:
699 result = (LRESULT)es->word_break_proc;
700 break;
702 case EM_GETPASSWORDCHAR16:
703 unicode = FALSE; /* 16-bit message is always ascii */
704 /* fall through */
705 case EM_GETPASSWORDCHAR:
707 if(unicode)
708 result = es->password_char;
709 else
711 WCHAR charW = es->password_char;
712 CHAR charA = 0;
713 WideCharToMultiByte(CP_ACP, 0, &charW, 1, &charA, 1, NULL, NULL);
714 result = charA;
716 break;
719 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
721 case EM_SETMARGINS:
722 EDIT_EM_SetMargins(es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam));
723 break;
725 case EM_GETMARGINS:
726 result = MAKELONG(es->left_margin, es->right_margin);
727 break;
729 case EM_GETLIMITTEXT:
730 result = es->buffer_limit;
731 break;
733 case EM_POSFROMCHAR:
734 result = EDIT_EM_PosFromChar(es, (INT)wParam, FALSE);
735 break;
737 case EM_CHARFROMPOS:
738 result = EDIT_EM_CharFromPos(es, SLOWORD(lParam), SHIWORD(lParam));
739 break;
741 /* End of the EM_ messages which were in numerical order; what order
742 * are these in? vaguely alphabetical?
745 case WM_GETDLGCODE:
746 result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
748 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
750 int vk = (int)((LPMSG)lParam)->wParam;
752 if (vk == VK_RETURN && (GetWindowLongW( hwnd, GWL_STYLE ) & ES_WANTRETURN))
754 result |= DLGC_WANTMESSAGE;
756 else if (es->hwndListBox && (vk == VK_RETURN || vk == VK_ESCAPE))
758 if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
759 result |= DLGC_WANTMESSAGE;
762 break;
764 case WM_CHAR:
766 WCHAR charW;
768 if(unicode)
769 charW = wParam;
770 else
772 CHAR charA = wParam;
773 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
776 if ((charW == VK_RETURN || charW == VK_ESCAPE) && es->hwndListBox)
778 if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
779 SendMessageW(GetParent(hwnd), WM_KEYDOWN, charW, 0);
780 break;
782 EDIT_WM_Char(es, charW);
783 break;
786 case WM_CLEAR:
787 EDIT_WM_Clear(es);
788 break;
790 case WM_COMMAND:
791 EDIT_WM_Command(es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
792 break;
794 case WM_CONTEXTMENU:
795 EDIT_WM_ContextMenu(es, SLOWORD(lParam), SHIWORD(lParam));
796 break;
798 case WM_COPY:
799 EDIT_WM_Copy(es);
800 break;
802 case WM_CREATE:
803 if(unicode)
804 result = EDIT_WM_Create(es, ((LPCREATESTRUCTW)lParam)->lpszName);
805 else
807 LPCSTR nameA = ((LPCREATESTRUCTA)lParam)->lpszName;
808 LPWSTR nameW = NULL;
809 if(nameA)
811 INT countW = MultiByteToWideChar(CP_ACP, 0, nameA, -1, NULL, 0);
812 if((nameW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
813 MultiByteToWideChar(CP_ACP, 0, nameA, -1, nameW, countW);
815 result = EDIT_WM_Create(es, nameW);
816 if(nameW)
817 HeapFree(GetProcessHeap(), 0, nameW);
819 break;
821 case WM_CUT:
822 EDIT_WM_Cut(es);
823 break;
825 case WM_ENABLE:
826 es->bEnableState = (BOOL) wParam;
827 EDIT_UpdateText(es, NULL, TRUE);
828 break;
830 case WM_ERASEBKGND:
831 result = EDIT_WM_EraseBkGnd(es, (HDC)wParam);
832 break;
834 case WM_GETFONT:
835 result = (LRESULT)es->font;
836 break;
838 case WM_GETTEXT:
839 result = (LRESULT)EDIT_WM_GetText(es, (INT)wParam, lParam, unicode);
840 break;
842 case WM_GETTEXTLENGTH:
843 if (unicode) result = strlenW(es->text);
844 else result = WideCharToMultiByte( CP_ACP, 0, es->text, strlenW(es->text),
845 NULL, 0, NULL, NULL );
846 break;
848 case WM_HSCROLL:
849 result = EDIT_WM_HScroll(es, LOWORD(wParam), SHIWORD(wParam));
850 break;
852 case WM_KEYDOWN:
853 result = EDIT_WM_KeyDown(es, (INT)wParam);
854 break;
856 case WM_KILLFOCUS:
857 result = EDIT_WM_KillFocus(es);
858 break;
860 case WM_LBUTTONDBLCLK:
861 result = EDIT_WM_LButtonDblClk(es);
862 break;
864 case WM_LBUTTONDOWN:
865 result = EDIT_WM_LButtonDown(es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
866 break;
868 case WM_LBUTTONUP:
869 result = EDIT_WM_LButtonUp(es);
870 break;
872 case WM_MBUTTONDOWN:
873 result = EDIT_WM_MButtonDown(es);
874 break;
876 case WM_MOUSEACTIVATE:
878 * FIXME: maybe DefWindowProc() screws up, but it seems that
879 * modeless dialog boxes need this. If we don't do this, the focus
880 * will _not_ be set by DefWindowProc() for edit controls in a
881 * modeless dialog box ???
883 SetFocus(hwnd);
884 result = MA_ACTIVATE;
885 break;
887 case WM_MOUSEMOVE:
888 result = EDIT_WM_MouseMove(es, SLOWORD(lParam), SHIWORD(lParam));
889 break;
891 case WM_PAINT:
892 EDIT_WM_Paint(es, wParam);
893 break;
895 case WM_PASTE:
896 EDIT_WM_Paste(es);
897 break;
899 case WM_SETFOCUS:
900 EDIT_WM_SetFocus(es);
901 break;
903 case WM_SETFONT:
904 EDIT_WM_SetFont(es, (HFONT)wParam, LOWORD(lParam) != 0);
905 break;
907 case WM_SETREDRAW:
908 /* FIXME: actually set an internal flag and behave accordingly */
909 break;
911 case WM_SETTEXT:
912 EDIT_WM_SetText(es, lParam, unicode);
913 result = TRUE;
914 break;
916 case WM_SIZE:
917 EDIT_WM_Size(es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam));
918 break;
920 case WM_STYLECHANGED:
921 result = EDIT_WM_StyleChanged(es, wParam, (const STYLESTRUCT *)lParam);
922 break;
924 case WM_STYLECHANGING:
925 result = 0; /* See EDIT_WM_StyleChanged */
926 break;
928 case WM_SYSKEYDOWN:
929 result = EDIT_WM_SysKeyDown(es, (INT)wParam, (DWORD)lParam);
930 break;
932 case WM_TIMER:
933 EDIT_WM_Timer(es);
934 break;
936 case WM_VSCROLL:
937 result = EDIT_WM_VScroll(es, LOWORD(wParam), SHIWORD(wParam));
938 break;
940 case WM_MOUSEWHEEL:
942 int gcWheelDelta = 0;
943 UINT pulScrollLines = 3;
944 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
946 if (wParam & (MK_SHIFT | MK_CONTROL)) {
947 result = DefWindowProcW(hwnd, msg, wParam, lParam);
948 break;
950 gcWheelDelta -= SHIWORD(wParam);
951 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
953 int cLineScroll= (int) min((UINT) es->line_count, pulScrollLines);
954 cLineScroll *= (gcWheelDelta / WHEEL_DELTA);
955 result = EDIT_EM_LineScroll(es, 0, cLineScroll);
958 break;
959 default:
960 result = DefWindowProcT(hwnd, msg, wParam, lParam, unicode);
961 break;
964 if (es) EDIT_UnlockBuffer(es, FALSE);
966 return result;
969 /*********************************************************************
971 * EditWndProcW (USER32.@)
973 LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
975 return EditWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
978 /*********************************************************************
980 * EditWndProc (USER32.@)
982 LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
984 return EditWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
987 /*********************************************************************
989 * EDIT_BuildLineDefs_ML
991 * Build linked list of text lines.
992 * Lines can end with '\0' (last line), a character (if it is wrapped),
993 * a soft return '\r\r\n' or a hard return '\r\n'
996 static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT istart, INT iend, INT delta, HRGN hrgn)
998 HDC dc;
999 HFONT old_font = 0;
1000 LPWSTR current_position, cp;
1001 INT fw;
1002 LINEDEF *current_line;
1003 LINEDEF *previous_line;
1004 LINEDEF *start_line;
1005 INT line_index = 0, nstart_line = 0, nstart_index = 0;
1006 INT line_count = es->line_count;
1007 INT orig_net_length;
1008 RECT rc;
1010 if (istart == iend && delta == 0)
1011 return;
1013 dc = GetDC(es->hwndSelf);
1014 if (es->font)
1015 old_font = SelectObject(dc, es->font);
1017 previous_line = NULL;
1018 current_line = es->first_line_def;
1020 /* Find starting line. istart must lie inside an existing line or
1021 * at the end of buffer */
1022 do {
1023 if (istart < current_line->index + current_line->length ||
1024 current_line->ending == END_0)
1025 break;
1027 previous_line = current_line;
1028 current_line = current_line->next;
1029 line_index++;
1030 } while (current_line);
1032 if (!current_line) /* Error occurred start is not inside previous buffer */
1034 FIXME(" modification occurred outside buffer\n");
1035 return;
1038 /* Remember start of modifications in order to calculate update region */
1039 nstart_line = line_index;
1040 nstart_index = current_line->index;
1042 /* We must start to reformat from the previous line since the modifications
1043 * may have caused the line to wrap upwards. */
1044 if (!(es->style & ES_AUTOHSCROLL) && line_index > 0)
1046 line_index--;
1047 current_line = previous_line;
1049 start_line = current_line;
1051 fw = es->format_rect.right - es->format_rect.left;
1052 current_position = es->text + current_line->index;
1053 do {
1054 if (current_line != start_line)
1056 if (!current_line || current_line->index + delta > current_position - es->text)
1058 /* The buffer has been expanded, create a new line and
1059 insert it into the link list */
1060 LINEDEF *new_line = HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF));
1061 new_line->next = previous_line->next;
1062 previous_line->next = new_line;
1063 current_line = new_line;
1064 es->line_count++;
1066 else if (current_line->index + delta < current_position - es->text)
1068 /* The previous line merged with this line so we delete this extra entry */
1069 previous_line->next = current_line->next;
1070 HeapFree(GetProcessHeap(), 0, current_line);
1071 current_line = previous_line->next;
1072 es->line_count--;
1073 continue;
1075 else /* current_line->index + delta == current_position */
1077 if (current_position - es->text > iend)
1078 break; /* We reached end of line modifications */
1079 /* else recalulate this line */
1083 current_line->index = current_position - es->text;
1084 orig_net_length = current_line->net_length;
1086 /* Find end of line */
1087 cp = current_position;
1088 while (*cp) {
1089 if (*cp == '\n') break;
1090 if ((*cp == '\r') && (*(cp + 1) == '\n'))
1091 break;
1092 cp++;
1095 /* Mark type of line termination */
1096 if (!(*cp)) {
1097 current_line->ending = END_0;
1098 current_line->net_length = strlenW(current_position);
1099 } else if ((cp > current_position) && (*(cp - 1) == '\r')) {
1100 current_line->ending = END_SOFT;
1101 current_line->net_length = cp - current_position - 1;
1102 } else if (*cp == '\n') {
1103 current_line->ending = END_RICH;
1104 current_line->net_length = cp - current_position;
1105 } else {
1106 current_line->ending = END_HARD;
1107 current_line->net_length = cp - current_position;
1110 /* Calculate line width */
1111 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1112 current_position, current_line->net_length,
1113 es->tabs_count, es->tabs));
1115 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1116 if ((!(es->style & ES_AUTOHSCROLL)) && (current_line->width > fw)) {
1117 INT next = 0;
1118 INT prev;
1119 do {
1120 prev = next;
1121 next = EDIT_CallWordBreakProc(es, current_position - es->text,
1122 prev + 1, current_line->net_length, WB_RIGHT);
1123 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1124 current_position, next, es->tabs_count, es->tabs));
1125 } while (current_line->width <= fw);
1126 if (!prev) { /* Didn't find a line break so force a break */
1127 next = 0;
1128 do {
1129 prev = next;
1130 next++;
1131 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1132 current_position, next, es->tabs_count, es->tabs));
1133 } while (current_line->width <= fw);
1134 if (!prev)
1135 prev = 1;
1138 /* If the first line we are calculating, wrapped before istart, we must
1139 * adjust istart in order for this to be reflected in the update region. */
1140 if (current_line->index == nstart_index && istart > current_line->index + prev)
1141 istart = current_line->index + prev;
1142 /* else if we are updating the previous line before the first line we
1143 * are re-calculating and it expanded */
1144 else if (current_line == start_line &&
1145 current_line->index != nstart_index && orig_net_length < prev)
1147 /* Line expanded due to an upwards line wrap so we must partially include
1148 * previous line in update region */
1149 nstart_line = line_index;
1150 nstart_index = current_line->index;
1151 istart = current_line->index + orig_net_length;
1154 current_line->net_length = prev;
1155 current_line->ending = END_WRAP;
1156 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, current_position,
1157 current_line->net_length, es->tabs_count, es->tabs));
1161 /* Adjust length to include line termination */
1162 switch (current_line->ending) {
1163 case END_SOFT:
1164 current_line->length = current_line->net_length + 3;
1165 break;
1166 case END_RICH:
1167 current_line->length = current_line->net_length + 1;
1168 break;
1169 case END_HARD:
1170 current_line->length = current_line->net_length + 2;
1171 break;
1172 case END_WRAP:
1173 case END_0:
1174 current_line->length = current_line->net_length;
1175 break;
1177 es->text_width = max(es->text_width, current_line->width);
1178 current_position += current_line->length;
1179 previous_line = current_line;
1180 current_line = current_line->next;
1181 line_index++;
1182 } while (previous_line->ending != END_0);
1184 /* Finish adjusting line indexes by delta or remove hanging lines */
1185 if (previous_line->ending == END_0)
1187 LINEDEF *pnext = NULL;
1189 previous_line->next = NULL;
1190 while (current_line)
1192 pnext = current_line->next;
1193 HeapFree(GetProcessHeap(), 0, current_line);
1194 current_line = pnext;
1195 es->line_count--;
1198 else
1200 while (current_line)
1202 current_line->index += delta;
1203 current_line = current_line->next;
1207 /* Calculate rest of modification rectangle */
1208 if (hrgn)
1210 HRGN tmphrgn;
1212 * We calculate two rectangles. One for the first line which may have
1213 * an indent with respect to the format rect. The other is a format-width
1214 * rectangle that spans the rest of the lines that changed or moved.
1216 rc.top = es->format_rect.top + nstart_line * es->line_height -
1217 (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
1218 rc.bottom = rc.top + es->line_height;
1219 rc.left = es->format_rect.left + (INT)LOWORD(GetTabbedTextExtentW(dc,
1220 es->text + nstart_index, istart - nstart_index,
1221 es->tabs_count, es->tabs)) - es->x_offset; /* Adjust for horz scroll */
1222 rc.right = es->format_rect.right;
1223 SetRectRgn(hrgn, rc.left, rc.top, rc.right, rc.bottom);
1225 rc.top = rc.bottom;
1226 rc.left = es->format_rect.left;
1227 rc.right = es->format_rect.right;
1229 * If lines were added or removed we must re-paint the remainder of the
1230 * lines since the remaining lines were either shifted up or down.
1232 if (line_count < es->line_count) /* We added lines */
1233 rc.bottom = es->line_count * es->line_height;
1234 else if (line_count > es->line_count) /* We removed lines */
1235 rc.bottom = line_count * es->line_height;
1236 else
1237 rc.bottom = line_index * es->line_height;
1238 rc.bottom -= (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
1239 tmphrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
1240 CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR);
1241 DeleteObject(tmphrgn);
1244 if (es->font)
1245 SelectObject(dc, old_font);
1247 ReleaseDC(es->hwndSelf, dc);
1250 /*********************************************************************
1252 * EDIT_CalcLineWidth_SL
1255 static void EDIT_CalcLineWidth_SL(EDITSTATE *es)
1257 es->text_width = SLOWORD(EDIT_EM_PosFromChar(es, strlenW(es->text), FALSE));
1260 /*********************************************************************
1262 * EDIT_CallWordBreakProc
1264 * Call appropriate WordBreakProc (internal or external).
1266 * Note: The "start" argument should always be an index referring
1267 * to es->text. The actual wordbreak proc might be
1268 * 16 bit, so we can't always pass any 32 bit LPSTR.
1269 * Hence we assume that es->text is the buffer that holds
1270 * the string under examination (we can decide this for ourselves).
1273 /* ### start build ### */
1274 extern WORD CALLBACK EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16,SEGPTR,WORD,WORD,WORD);
1275 /* ### stop build ### */
1276 static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action)
1278 INT ret, iWndsLocks;
1280 /* To avoid any deadlocks, all the locks on the window structures
1281 must be suspended before the control is passed to the application */
1282 iWndsLocks = WIN_SuspendWndsLock();
1284 if (es->word_break_proc16) {
1285 HGLOBAL16 hglob16;
1286 SEGPTR segptr;
1287 INT countA;
1289 countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
1290 hglob16 = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT, countA);
1291 segptr = K32WOWGlobalLock16(hglob16);
1292 WideCharToMultiByte(CP_ACP, 0, es->text + start, count, MapSL(segptr), countA, NULL, NULL);
1293 ret = (INT)EDIT_CallTo16_word_lwww(es->word_break_proc16,
1294 segptr, index, countA, action);
1295 GlobalUnlock16(hglob16);
1296 GlobalFree16(hglob16);
1298 else if (es->word_break_proc)
1300 if(es->is_unicode)
1302 EDITWORDBREAKPROCW wbpW = (EDITWORDBREAKPROCW)es->word_break_proc;
1304 TRACE_(relay)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1305 es->word_break_proc, debugstr_wn(es->text + start, count), index, count, action);
1306 ret = wbpW(es->text + start, index, count, action);
1308 else
1310 EDITWORDBREAKPROCA wbpA = (EDITWORDBREAKPROCA)es->word_break_proc;
1311 INT countA;
1312 CHAR *textA;
1314 countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
1315 textA = HeapAlloc(GetProcessHeap(), 0, countA);
1316 WideCharToMultiByte(CP_ACP, 0, es->text + start, count, textA, countA, NULL, NULL);
1317 TRACE_(relay)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1318 es->word_break_proc, debugstr_an(textA, countA), index, countA, action);
1319 ret = wbpA(textA, index, countA, action);
1320 HeapFree(GetProcessHeap(), 0, textA);
1323 else
1324 ret = EDIT_WordBreakProc(es->text + start, index, count, action);
1326 WIN_RestoreWndsLock(iWndsLocks);
1327 return ret;
1331 /*********************************************************************
1333 * EDIT_CharFromPos
1335 * Beware: This is not the function called on EM_CHARFROMPOS
1336 * The position _can_ be outside the formatting / client
1337 * rectangle
1338 * The return value is only the character index
1341 static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
1343 INT index;
1344 HDC dc;
1345 HFONT old_font = 0;
1347 if (es->style & ES_MULTILINE) {
1348 INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1349 INT line_index = 0;
1350 LINEDEF *line_def = es->first_line_def;
1351 INT low, high;
1352 while ((line > 0) && line_def->next) {
1353 line_index += line_def->length;
1354 line_def = line_def->next;
1355 line--;
1357 x += es->x_offset - es->format_rect.left;
1358 if (x >= line_def->width) {
1359 if (after_wrap)
1360 *after_wrap = (line_def->ending == END_WRAP);
1361 return line_index + line_def->net_length;
1363 if (x <= 0) {
1364 if (after_wrap)
1365 *after_wrap = FALSE;
1366 return line_index;
1368 dc = GetDC(es->hwndSelf);
1369 if (es->font)
1370 old_font = SelectObject(dc, es->font);
1371 low = line_index + 1;
1372 high = line_index + line_def->net_length + 1;
1373 while (low < high - 1)
1375 INT mid = (low + high) / 2;
1376 if (LOWORD(GetTabbedTextExtentW(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
1377 else low = mid;
1379 index = low;
1381 if (after_wrap)
1382 *after_wrap = ((index == line_index + line_def->net_length) &&
1383 (line_def->ending == END_WRAP));
1384 } else {
1385 LPWSTR text;
1386 SIZE size;
1387 if (after_wrap)
1388 *after_wrap = FALSE;
1389 x -= es->format_rect.left;
1390 if (!x)
1391 return es->x_offset;
1392 text = EDIT_GetPasswordPointer_SL(es);
1393 dc = GetDC(es->hwndSelf);
1394 if (es->font)
1395 old_font = SelectObject(dc, es->font);
1396 if (x < 0)
1398 INT low = 0;
1399 INT high = es->x_offset;
1400 while (low < high - 1)
1402 INT mid = (low + high) / 2;
1403 GetTextExtentPoint32W( dc, text + mid,
1404 es->x_offset - mid, &size );
1405 if (size.cx > -x) low = mid;
1406 else high = mid;
1408 index = low;
1410 else
1412 INT low = es->x_offset;
1413 INT high = strlenW(es->text) + 1;
1414 while (low < high - 1)
1416 INT mid = (low + high) / 2;
1417 GetTextExtentPoint32W( dc, text + es->x_offset,
1418 mid - es->x_offset, &size );
1419 if (size.cx > x) high = mid;
1420 else low = mid;
1422 index = low;
1424 if (es->style & ES_PASSWORD)
1425 HeapFree(GetProcessHeap(), 0, text);
1427 if (es->font)
1428 SelectObject(dc, old_font);
1429 ReleaseDC(es->hwndSelf, dc);
1430 return index;
1434 /*********************************************************************
1436 * EDIT_ConfinePoint
1438 * adjusts the point to be within the formatting rectangle
1439 * (so CharFromPos returns the nearest _visible_ character)
1442 static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y)
1444 *x = min(max(*x, es->format_rect.left), es->format_rect.right - 1);
1445 *y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1);
1449 /*********************************************************************
1451 * EDIT_GetLineRect
1453 * Calculates the bounding rectangle for a line from a starting
1454 * column to an ending column.
1457 static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
1459 INT line_index = EDIT_EM_LineIndex(es, line);
1461 if (es->style & ES_MULTILINE)
1462 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1463 else
1464 rc->top = es->format_rect.top;
1465 rc->bottom = rc->top + es->line_height;
1466 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(es, line_index + scol, TRUE));
1467 rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(es, line_index + ecol, TRUE));
1471 /*********************************************************************
1473 * EDIT_GetPasswordPointer_SL
1475 * note: caller should free the (optionally) allocated buffer
1478 static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es)
1480 if (es->style & ES_PASSWORD) {
1481 INT len = strlenW(es->text);
1482 LPWSTR text = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
1483 text[len] = '\0';
1484 while(len) text[--len] = es->password_char;
1485 return text;
1486 } else
1487 return es->text;
1491 /*********************************************************************
1493 * EDIT_LockBuffer
1495 * This acts as a LOCAL_Lock(), but it locks only once. This way
1496 * you can call it whenever you like, without unlocking.
1498 * Initially the edit control allocates a HLOCAL32 buffer
1499 * (32 bit linear memory handler). However, 16 bit application
1500 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1501 * handler). From that moment on we have to keep using this 16 bit memory
1502 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1503 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1504 * conversion.
1507 static void EDIT_LockBuffer(EDITSTATE *es)
1509 HINSTANCE hInstance = (HINSTANCE)GetWindowLongW( es->hwndSelf, GWL_HINSTANCE );
1510 if (!es->text) {
1511 CHAR *textA = NULL;
1512 UINT countA = 0;
1513 BOOL _16bit = FALSE;
1515 if(es->hloc32W)
1517 if(es->hloc32A)
1519 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1520 textA = LocalLock(es->hloc32A);
1521 countA = strlen(textA) + 1;
1523 else if(es->hloc16)
1525 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1526 textA = LOCAL_Lock(hInstance, es->hloc16);
1527 countA = strlen(textA) + 1;
1528 _16bit = TRUE;
1531 else {
1532 ERR("no buffer ... please report\n");
1533 return;
1536 if(textA)
1538 HLOCAL hloc32W_new;
1539 UINT countW_new = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
1540 TRACE("%d bytes translated to %d WCHARs\n", countA, countW_new);
1541 if(countW_new > es->buffer_size + 1)
1543 UINT alloc_size = ROUND_TO_GROW(countW_new * sizeof(WCHAR));
1544 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es->buffer_size, countW_new);
1545 hloc32W_new = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
1546 if(hloc32W_new)
1548 es->hloc32W = hloc32W_new;
1549 es->buffer_size = LocalSize(hloc32W_new)/sizeof(WCHAR) - 1;
1550 TRACE("Real new size %d+1 WCHARs\n", es->buffer_size);
1552 else
1553 WARN("FAILED! Will synchronize partially\n");
1557 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1558 es->text = LocalLock(es->hloc32W);
1560 if(textA)
1562 MultiByteToWideChar(CP_ACP, 0, textA, countA, es->text, es->buffer_size + 1);
1563 if(_16bit)
1564 LOCAL_Unlock(hInstance, es->hloc16);
1565 else
1566 LocalUnlock(es->hloc32A);
1569 es->lock_count++;
1573 /*********************************************************************
1575 * EDIT_SL_InvalidateText
1577 * Called from EDIT_InvalidateText().
1578 * Does the job for single-line controls only.
1581 static void EDIT_SL_InvalidateText(EDITSTATE *es, INT start, INT end)
1583 RECT line_rect;
1584 RECT rc;
1586 EDIT_GetLineRect(es, 0, start, end, &line_rect);
1587 if (IntersectRect(&rc, &line_rect, &es->format_rect))
1588 EDIT_UpdateText(es, &rc, TRUE);
1592 /*********************************************************************
1594 * EDIT_ML_InvalidateText
1596 * Called from EDIT_InvalidateText().
1597 * Does the job for multi-line controls only.
1600 static void EDIT_ML_InvalidateText(EDITSTATE *es, INT start, INT end)
1602 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1603 INT sl = EDIT_EM_LineFromChar(es, start);
1604 INT el = EDIT_EM_LineFromChar(es, end);
1605 INT sc;
1606 INT ec;
1607 RECT rc1;
1608 RECT rcWnd;
1609 RECT rcLine;
1610 RECT rcUpdate;
1611 INT l;
1613 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1614 return;
1616 sc = start - EDIT_EM_LineIndex(es, sl);
1617 ec = end - EDIT_EM_LineIndex(es, el);
1618 if (sl < es->y_offset) {
1619 sl = es->y_offset;
1620 sc = 0;
1622 if (el > es->y_offset + vlc) {
1623 el = es->y_offset + vlc;
1624 ec = EDIT_EM_LineLength(es, EDIT_EM_LineIndex(es, el));
1626 GetClientRect(es->hwndSelf, &rc1);
1627 IntersectRect(&rcWnd, &rc1, &es->format_rect);
1628 if (sl == el) {
1629 EDIT_GetLineRect(es, sl, sc, ec, &rcLine);
1630 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1631 EDIT_UpdateText(es, &rcUpdate, TRUE);
1632 } else {
1633 EDIT_GetLineRect(es, sl, sc,
1634 EDIT_EM_LineLength(es,
1635 EDIT_EM_LineIndex(es, sl)),
1636 &rcLine);
1637 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1638 EDIT_UpdateText(es, &rcUpdate, TRUE);
1639 for (l = sl + 1 ; l < el ; l++) {
1640 EDIT_GetLineRect(es, l, 0,
1641 EDIT_EM_LineLength(es,
1642 EDIT_EM_LineIndex(es, l)),
1643 &rcLine);
1644 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1645 EDIT_UpdateText(es, &rcUpdate, TRUE);
1647 EDIT_GetLineRect(es, el, 0, ec, &rcLine);
1648 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1649 EDIT_UpdateText(es, &rcUpdate, TRUE);
1654 /*********************************************************************
1656 * EDIT_InvalidateText
1658 * Invalidate the text from offset start upto, but not including,
1659 * offset end. Useful for (re)painting the selection.
1660 * Regions outside the linewidth are not invalidated.
1661 * end == -1 means end == TextLength.
1662 * start and end need not be ordered.
1665 static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end)
1667 if (end == start)
1668 return;
1670 if (end == -1)
1671 end = strlenW(es->text);
1673 if (end < start) {
1674 INT tmp = start;
1675 start = end;
1676 end = tmp;
1679 if (es->style & ES_MULTILINE)
1680 EDIT_ML_InvalidateText(es, start, end);
1681 else
1682 EDIT_SL_InvalidateText(es, start, end);
1686 /*********************************************************************
1688 * EDIT_MakeFit
1690 * Try to fit size + 1 characters in the buffer. Constrain to limits.
1693 static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size)
1695 HLOCAL hNew32W;
1697 if (size <= es->buffer_size)
1698 return TRUE;
1699 if ((es->buffer_limit > 0) && (size > es->buffer_limit)) {
1700 EDIT_NOTIFY_PARENT(es, EN_MAXTEXT, "EN_MAXTEXT");
1701 return FALSE;
1703 if ((es->buffer_limit > 0) && (size > es->buffer_limit))
1704 size = es->buffer_limit;
1706 TRACE("trying to ReAlloc to %d+1 characters\n", size);
1708 /* Force edit to unlock it's buffer. es->text now NULL */
1709 EDIT_UnlockBuffer(es, TRUE);
1711 if (es->hloc32W) {
1712 UINT alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
1713 if ((hNew32W = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT))) {
1714 TRACE("Old 32 bit handle %08x, new handle %08x\n", es->hloc32W, hNew32W);
1715 es->hloc32W = hNew32W;
1716 es->buffer_size = LocalSize(hNew32W)/sizeof(WCHAR) - 1;
1720 EDIT_LockBuffer(es);
1722 if (es->buffer_size < size) {
1723 WARN("FAILED ! We now have %d+1\n", es->buffer_size);
1724 EDIT_NOTIFY_PARENT(es, EN_ERRSPACE, "EN_ERRSPACE");
1725 return FALSE;
1726 } else {
1727 TRACE("We now have %d+1\n", es->buffer_size);
1728 return TRUE;
1733 /*********************************************************************
1735 * EDIT_MakeUndoFit
1737 * Try to fit size + 1 bytes in the undo buffer.
1740 static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size)
1742 UINT alloc_size;
1744 if (size <= es->undo_buffer_size)
1745 return TRUE;
1747 TRACE("trying to ReAlloc to %d+1\n", size);
1749 alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
1750 if ((es->undo_text = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, es->undo_text, alloc_size))) {
1751 es->undo_buffer_size = alloc_size/sizeof(WCHAR);
1752 return TRUE;
1754 else
1756 WARN("FAILED ! We now have %d+1\n", es->undo_buffer_size);
1757 return FALSE;
1762 /*********************************************************************
1764 * EDIT_MoveBackward
1767 static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend)
1769 INT e = es->selection_end;
1771 if (e) {
1772 e--;
1773 if ((es->style & ES_MULTILINE) && e &&
1774 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1775 e--;
1776 if (e && (es->text[e - 1] == '\r'))
1777 e--;
1780 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1781 EDIT_EM_ScrollCaret(es);
1785 /*********************************************************************
1787 * EDIT_MoveDown_ML
1789 * Only for multi line controls
1790 * Move the caret one line down, on a column with the nearest
1791 * x coordinate on the screen (might be a different column).
1794 static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend)
1796 INT s = es->selection_start;
1797 INT e = es->selection_end;
1798 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1799 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1800 INT x = SLOWORD(pos);
1801 INT y = SHIWORD(pos);
1803 e = EDIT_CharFromPos(es, x, y + es->line_height, &after_wrap);
1804 if (!extend)
1805 s = e;
1806 EDIT_EM_SetSel(es, s, e, after_wrap);
1807 EDIT_EM_ScrollCaret(es);
1811 /*********************************************************************
1813 * EDIT_MoveEnd
1816 static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend)
1818 BOOL after_wrap = FALSE;
1819 INT e;
1821 /* Pass a high value in x to make sure of receiving the end of the line */
1822 if (es->style & ES_MULTILINE)
1823 e = EDIT_CharFromPos(es, 0x3fffffff,
1824 HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1825 else
1826 e = strlenW(es->text);
1827 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, after_wrap);
1828 EDIT_EM_ScrollCaret(es);
1832 /*********************************************************************
1834 * EDIT_MoveForward
1837 static void EDIT_MoveForward(EDITSTATE *es, BOOL extend)
1839 INT e = es->selection_end;
1841 if (es->text[e]) {
1842 e++;
1843 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1844 if (es->text[e] == '\n')
1845 e++;
1846 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1847 e += 2;
1850 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1851 EDIT_EM_ScrollCaret(es);
1855 /*********************************************************************
1857 * EDIT_MoveHome
1859 * Home key: move to beginning of line.
1862 static void EDIT_MoveHome(EDITSTATE *es, BOOL extend)
1864 INT e;
1866 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1867 if (es->style & ES_MULTILINE)
1868 e = EDIT_CharFromPos(es, -es->x_offset,
1869 HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1870 else
1871 e = 0;
1872 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1873 EDIT_EM_ScrollCaret(es);
1877 /*********************************************************************
1879 * EDIT_MovePageDown_ML
1881 * Only for multi line controls
1882 * Move the caret one page down, on a column with the nearest
1883 * x coordinate on the screen (might be a different column).
1886 static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend)
1888 INT s = es->selection_start;
1889 INT e = es->selection_end;
1890 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1891 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1892 INT x = SLOWORD(pos);
1893 INT y = SHIWORD(pos);
1895 e = EDIT_CharFromPos(es, x,
1896 y + (es->format_rect.bottom - es->format_rect.top),
1897 &after_wrap);
1898 if (!extend)
1899 s = e;
1900 EDIT_EM_SetSel(es, s, e, after_wrap);
1901 EDIT_EM_ScrollCaret(es);
1905 /*********************************************************************
1907 * EDIT_MovePageUp_ML
1909 * Only for multi line controls
1910 * Move the caret one page up, on a column with the nearest
1911 * x coordinate on the screen (might be a different column).
1914 static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend)
1916 INT s = es->selection_start;
1917 INT e = es->selection_end;
1918 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1919 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1920 INT x = SLOWORD(pos);
1921 INT y = SHIWORD(pos);
1923 e = EDIT_CharFromPos(es, x,
1924 y - (es->format_rect.bottom - es->format_rect.top),
1925 &after_wrap);
1926 if (!extend)
1927 s = e;
1928 EDIT_EM_SetSel(es, s, e, after_wrap);
1929 EDIT_EM_ScrollCaret(es);
1933 /*********************************************************************
1935 * EDIT_MoveUp_ML
1937 * Only for multi line controls
1938 * Move the caret one line up, on a column with the nearest
1939 * x coordinate on the screen (might be a different column).
1942 static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend)
1944 INT s = es->selection_start;
1945 INT e = es->selection_end;
1946 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1947 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1948 INT x = SLOWORD(pos);
1949 INT y = SHIWORD(pos);
1951 e = EDIT_CharFromPos(es, x, y - es->line_height, &after_wrap);
1952 if (!extend)
1953 s = e;
1954 EDIT_EM_SetSel(es, s, e, after_wrap);
1955 EDIT_EM_ScrollCaret(es);
1959 /*********************************************************************
1961 * EDIT_MoveWordBackward
1964 static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend)
1966 INT s = es->selection_start;
1967 INT e = es->selection_end;
1968 INT l;
1969 INT ll;
1970 INT li;
1972 l = EDIT_EM_LineFromChar(es, e);
1973 ll = EDIT_EM_LineLength(es, e);
1974 li = EDIT_EM_LineIndex(es, l);
1975 if (e - li == 0) {
1976 if (l) {
1977 li = EDIT_EM_LineIndex(es, l - 1);
1978 e = li + EDIT_EM_LineLength(es, li);
1980 } else {
1981 e = li + (INT)EDIT_CallWordBreakProc(es,
1982 li, e - li, ll, WB_LEFT);
1984 if (!extend)
1985 s = e;
1986 EDIT_EM_SetSel(es, s, e, FALSE);
1987 EDIT_EM_ScrollCaret(es);
1991 /*********************************************************************
1993 * EDIT_MoveWordForward
1996 static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend)
1998 INT s = es->selection_start;
1999 INT e = es->selection_end;
2000 INT l;
2001 INT ll;
2002 INT li;
2004 l = EDIT_EM_LineFromChar(es, e);
2005 ll = EDIT_EM_LineLength(es, e);
2006 li = EDIT_EM_LineIndex(es, l);
2007 if (e - li == ll) {
2008 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
2009 e = EDIT_EM_LineIndex(es, l + 1);
2010 } else {
2011 e = li + EDIT_CallWordBreakProc(es,
2012 li, e - li + 1, ll, WB_RIGHT);
2014 if (!extend)
2015 s = e;
2016 EDIT_EM_SetSel(es, s, e, FALSE);
2017 EDIT_EM_ScrollCaret(es);
2021 /*********************************************************************
2023 * EDIT_PaintLine
2026 static void EDIT_PaintLine(EDITSTATE *es, HDC dc, INT line, BOOL rev)
2028 INT s = es->selection_start;
2029 INT e = es->selection_end;
2030 INT li;
2031 INT ll;
2032 INT x;
2033 INT y;
2034 LRESULT pos;
2036 if (es->style & ES_MULTILINE) {
2037 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2038 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
2039 return;
2040 } else if (line)
2041 return;
2043 TRACE("line=%d\n", line);
2045 pos = EDIT_EM_PosFromChar(es, EDIT_EM_LineIndex(es, line), FALSE);
2046 x = SLOWORD(pos);
2047 y = SHIWORD(pos);
2048 li = EDIT_EM_LineIndex(es, line);
2049 ll = EDIT_EM_LineLength(es, li);
2050 s = min(es->selection_start, es->selection_end);
2051 e = max(es->selection_start, es->selection_end);
2052 s = min(li + ll, max(li, s));
2053 e = min(li + ll, max(li, e));
2054 if (rev && (s != e) &&
2055 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
2056 x += EDIT_PaintText(es, dc, x, y, line, 0, s - li, FALSE);
2057 x += EDIT_PaintText(es, dc, x, y, line, s - li, e - s, TRUE);
2058 x += EDIT_PaintText(es, dc, x, y, line, e - li, li + ll - e, FALSE);
2059 } else
2060 x += EDIT_PaintText(es, dc, x, y, line, 0, ll, FALSE);
2064 /*********************************************************************
2066 * EDIT_PaintText
2069 static INT EDIT_PaintText(EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
2071 COLORREF BkColor;
2072 COLORREF TextColor;
2073 INT ret;
2074 INT li;
2075 INT BkMode;
2076 SIZE size;
2078 if (!count)
2079 return 0;
2080 BkMode = GetBkMode(dc);
2081 BkColor = GetBkColor(dc);
2082 TextColor = GetTextColor(dc);
2083 if (rev) {
2084 SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
2085 SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2086 SetBkMode( dc, OPAQUE);
2088 li = EDIT_EM_LineIndex(es, line);
2089 if (es->style & ES_MULTILINE) {
2090 ret = (INT)LOWORD(TabbedTextOutW(dc, x, y, es->text + li + col, count,
2091 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
2092 } else {
2093 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
2094 TextOutW(dc, x, y, text + li + col, count);
2095 GetTextExtentPoint32W(dc, text + li + col, count, &size);
2096 ret = size.cx;
2097 if (es->style & ES_PASSWORD)
2098 HeapFree(GetProcessHeap(), 0, text);
2100 if (rev) {
2101 SetBkColor(dc, BkColor);
2102 SetTextColor(dc, TextColor);
2103 SetBkMode( dc, BkMode);
2105 return ret;
2109 /*********************************************************************
2111 * EDIT_SetCaretPos
2114 static void EDIT_SetCaretPos(EDITSTATE *es, INT pos,
2115 BOOL after_wrap)
2117 LRESULT res = EDIT_EM_PosFromChar(es, pos, after_wrap);
2118 SetCaretPos(SLOWORD(res), SHIWORD(res));
2122 /*********************************************************************
2124 * EDIT_SetRectNP
2126 * note: this is not (exactly) the handler called on EM_SETRECTNP
2127 * it is also used to set the rect of a single line control
2130 static void EDIT_SetRectNP(EDITSTATE *es, LPRECT rc)
2132 CopyRect(&es->format_rect, rc);
2133 if (es->style & WS_BORDER) {
2134 INT bw = GetSystemMetrics(SM_CXBORDER) + 1;
2135 if(TWEAK_WineLook == WIN31_LOOK)
2136 bw += 2;
2137 es->format_rect.left += bw;
2138 es->format_rect.top += bw;
2139 es->format_rect.right -= bw;
2140 es->format_rect.bottom -= bw;
2142 es->format_rect.left += es->left_margin;
2143 es->format_rect.right -= es->right_margin;
2144 es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width);
2145 if (es->style & ES_MULTILINE)
2147 INT fw, vlc, max_x_offset, max_y_offset;
2149 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2150 es->format_rect.bottom = es->format_rect.top + max(1, vlc) * es->line_height;
2152 /* correct es->x_offset */
2153 fw = es->format_rect.right - es->format_rect.left;
2154 max_x_offset = es->text_width - fw;
2155 if(max_x_offset < 0) max_x_offset = 0;
2156 if(es->x_offset > max_x_offset)
2157 es->x_offset = max_x_offset;
2159 /* correct es->y_offset */
2160 max_y_offset = es->line_count - vlc;
2161 if(max_y_offset < 0) max_y_offset = 0;
2162 if(es->y_offset > max_y_offset)
2163 es->y_offset = max_y_offset;
2165 /* force scroll info update */
2166 EDIT_UpdateScrollInfo(es);
2168 else
2169 /* Windows doesn't care to fix text placement for SL controls */
2170 es->format_rect.bottom = es->format_rect.top + es->line_height;
2172 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
2173 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, (HRGN)0);
2177 /*********************************************************************
2179 * EDIT_UnlockBuffer
2182 static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force)
2184 HINSTANCE hInstance = (HINSTANCE)GetWindowLongW( es->hwndSelf, GWL_HINSTANCE );
2186 /* Edit window might be already destroyed */
2187 if(!IsWindow(es->hwndSelf))
2189 WARN("edit hwnd %04x already destroyed\n", es->hwndSelf);
2190 return;
2193 if (!es->lock_count) {
2194 ERR("lock_count == 0 ... please report\n");
2195 return;
2197 if (!es->text) {
2198 ERR("es->text == 0 ... please report\n");
2199 return;
2202 if (force || (es->lock_count == 1)) {
2203 if (es->hloc32W) {
2204 CHAR *textA = NULL;
2205 BOOL _16bit = FALSE;
2206 UINT countA = 0;
2207 UINT countW = strlenW(es->text) + 1;
2209 if(es->hloc32A)
2211 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
2212 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2213 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
2214 countA = LocalSize(es->hloc32A);
2215 if(countA_new > countA)
2217 HLOCAL hloc32A_new;
2218 UINT alloc_size = ROUND_TO_GROW(countA_new);
2219 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2220 hloc32A_new = LocalReAlloc(es->hloc32A, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2221 if(hloc32A_new)
2223 es->hloc32A = hloc32A_new;
2224 countA = LocalSize(hloc32A_new);
2225 TRACE("Real new size %d bytes\n", countA);
2227 else
2228 WARN("FAILED! Will synchronize partially\n");
2230 textA = LocalLock(es->hloc32A);
2232 else if(es->hloc16)
2234 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
2235 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2236 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
2237 countA = LOCAL_Size(hInstance, es->hloc16);
2238 if(countA_new > countA)
2240 HLOCAL16 hloc16_new;
2241 UINT alloc_size = ROUND_TO_GROW(countA_new);
2242 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2243 hloc16_new = LOCAL_ReAlloc(hInstance, es->hloc16, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2244 if(hloc16_new)
2246 es->hloc16 = hloc16_new;
2247 countA = LOCAL_Size(hInstance, hloc16_new);
2248 TRACE("Real new size %d bytes\n", countA);
2250 else
2251 WARN("FAILED! Will synchronize partially\n");
2253 textA = LOCAL_Lock(hInstance, es->hloc16);
2254 _16bit = TRUE;
2257 if(textA)
2259 WideCharToMultiByte(CP_ACP, 0, es->text, countW, textA, countA, NULL, NULL);
2260 if(_16bit)
2261 LOCAL_Unlock(hInstance, es->hloc16);
2262 else
2263 LocalUnlock(es->hloc32A);
2266 LocalUnlock(es->hloc32W);
2267 es->text = NULL;
2269 else {
2270 ERR("no buffer ... please report\n");
2271 return;
2274 es->lock_count--;
2278 /*********************************************************************
2280 * EDIT_UpdateScrollInfo
2283 static void EDIT_UpdateScrollInfo(EDITSTATE *es)
2285 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
2287 SCROLLINFO si;
2288 si.cbSize = sizeof(SCROLLINFO);
2289 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2290 si.nMin = 0;
2291 si.nMax = es->line_count - 1;
2292 si.nPage = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2293 si.nPos = es->y_offset;
2294 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2295 si.nMin, si.nMax, si.nPage, si.nPos);
2296 SetScrollInfo(es->hwndSelf, SB_VERT, &si, TRUE);
2299 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
2301 SCROLLINFO si;
2302 si.cbSize = sizeof(SCROLLINFO);
2303 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2304 si.nMin = 0;
2305 si.nMax = es->text_width - 1;
2306 si.nPage = es->format_rect.right - es->format_rect.left;
2307 si.nPos = es->x_offset;
2308 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2309 si.nMin, si.nMax, si.nPage, si.nPos);
2310 SetScrollInfo(es->hwndSelf, SB_HORZ, &si, TRUE);
2314 /*********************************************************************
2316 * EDIT_WordBreakProc
2318 * Find the beginning of words.
2319 * Note: unlike the specs for a WordBreakProc, this function only
2320 * allows to be called without linebreaks between s[0] upto
2321 * s[count - 1]. Remember it is only called
2322 * internally, so we can decide this for ourselves.
2325 static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action)
2327 INT ret = 0;
2329 TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action);
2331 if(!s) return 0;
2333 switch (action) {
2334 case WB_LEFT:
2335 if (!count)
2336 break;
2337 if (index)
2338 index--;
2339 if (s[index] == ' ') {
2340 while (index && (s[index] == ' '))
2341 index--;
2342 if (index) {
2343 while (index && (s[index] != ' '))
2344 index--;
2345 if (s[index] == ' ')
2346 index++;
2348 } else {
2349 while (index && (s[index] != ' '))
2350 index--;
2351 if (s[index] == ' ')
2352 index++;
2354 ret = index;
2355 break;
2356 case WB_RIGHT:
2357 if (!count)
2358 break;
2359 if (index)
2360 index--;
2361 if (s[index] == ' ')
2362 while ((index < count) && (s[index] == ' ')) index++;
2363 else {
2364 while (s[index] && (s[index] != ' ') && (index < count))
2365 index++;
2366 while ((s[index] == ' ') && (index < count)) index++;
2368 ret = index;
2369 break;
2370 case WB_ISDELIMITER:
2371 ret = (s[index] == ' ');
2372 break;
2373 default:
2374 ERR("unknown action code, please report !\n");
2375 break;
2377 return ret;
2381 /*********************************************************************
2383 * EM_CHARFROMPOS
2385 * returns line number (not index) in high-order word of result.
2386 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2387 * to Richedit, not to the edit control. Original documentation is valid.
2388 * FIXME: do the specs mean to return -1 if outside client area or
2389 * if outside formatting rectangle ???
2392 static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y)
2394 POINT pt;
2395 RECT rc;
2396 INT index;
2398 pt.x = x;
2399 pt.y = y;
2400 GetClientRect(es->hwndSelf, &rc);
2401 if (!PtInRect(&rc, pt))
2402 return -1;
2404 index = EDIT_CharFromPos(es, x, y, NULL);
2405 return MAKELONG(index, EDIT_EM_LineFromChar(es, index));
2409 /*********************************************************************
2411 * EM_FMTLINES
2413 * Enable or disable soft breaks.
2415 * This means: insert or remove the soft linebreak character (\r\r\n).
2416 * Take care to check if the text still fits the buffer after insertion.
2417 * If not, notify with EN_ERRSPACE.
2420 static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol)
2422 es->flags &= ~EF_USE_SOFTBRK;
2423 if (add_eol) {
2424 es->flags |= EF_USE_SOFTBRK;
2425 FIXME("soft break enabled, not implemented\n");
2427 return add_eol;
2431 /*********************************************************************
2433 * EM_GETHANDLE
2435 * Hopefully this won't fire back at us.
2436 * We always start with a fixed buffer in the local heap.
2437 * Despite of the documentation says that the local heap is used
2438 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2439 * buffer on the local heap.
2442 static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es)
2444 HLOCAL hLocal;
2446 if (!(es->style & ES_MULTILINE))
2447 return 0;
2449 if(es->is_unicode)
2450 hLocal = es->hloc32W;
2451 else
2453 if(!es->hloc32A)
2455 CHAR *textA;
2456 UINT countA, alloc_size;
2457 TRACE("Allocating 32-bit ANSI alias buffer\n");
2458 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
2459 alloc_size = ROUND_TO_GROW(countA);
2460 if(!(es->hloc32A = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2462 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size);
2463 return 0;
2465 textA = LocalLock(es->hloc32A);
2466 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
2467 LocalUnlock(es->hloc32A);
2469 hLocal = es->hloc32A;
2472 TRACE("Returning %04X, LocalSize() = %ld\n", hLocal, LocalSize(hLocal));
2473 return hLocal;
2477 /*********************************************************************
2479 * EM_GETHANDLE16
2481 * Hopefully this won't fire back at us.
2482 * We always start with a buffer in 32 bit linear memory.
2483 * However, with this message a 16 bit application requests
2484 * a handle of 16 bit local heap memory, where it expects to find
2485 * the text.
2486 * It's a pitty that from this moment on we have to use this
2487 * local heap, because applications may rely on the handle
2488 * in the future.
2490 * In this function we'll try to switch to local heap.
2492 static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es)
2494 HINSTANCE hInstance = (HINSTANCE)GetWindowLongW( es->hwndSelf, GWL_HINSTANCE );
2495 CHAR *textA;
2496 UINT countA, alloc_size;
2498 if (!(es->style & ES_MULTILINE))
2499 return 0;
2501 if (es->hloc16)
2502 return es->hloc16;
2504 if (!LOCAL_HeapSize(hInstance)) {
2505 if (!LocalInit16(hInstance, 0,
2506 GlobalSize16(hInstance))) {
2507 ERR("could not initialize local heap\n");
2508 return 0;
2510 TRACE("local heap initialized\n");
2513 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
2514 alloc_size = ROUND_TO_GROW(countA);
2516 TRACE("Allocating 16-bit ANSI alias buffer\n");
2517 if (!(es->hloc16 = LOCAL_Alloc(hInstance, LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) {
2518 ERR("could not allocate new 16 bit buffer\n");
2519 return 0;
2522 if (!(textA = (LPSTR)LOCAL_Lock(hInstance, es->hloc16))) {
2523 ERR("could not lock new 16 bit buffer\n");
2524 LOCAL_Free(hInstance, es->hloc16);
2525 es->hloc16 = 0;
2526 return 0;
2529 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
2530 LOCAL_Unlock(hInstance, es->hloc16);
2532 TRACE("Returning %04X, LocalSize() = %d\n", es->hloc16, LOCAL_Size(hInstance, es->hloc16));
2533 return es->hloc16;
2537 /*********************************************************************
2539 * EM_GETLINE
2542 static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPARAM lParam, BOOL unicode)
2544 LPWSTR src;
2545 INT line_len, dst_len;
2546 INT i;
2548 if (es->style & ES_MULTILINE) {
2549 if (line >= es->line_count)
2550 return 0;
2551 } else
2552 line = 0;
2553 i = EDIT_EM_LineIndex(es, line);
2554 src = es->text + i;
2555 line_len = EDIT_EM_LineLength(es, i);
2556 dst_len = *(WORD *)lParam;
2557 if(unicode)
2559 LPWSTR dst = (LPWSTR)lParam;
2560 if(dst_len <= line_len)
2562 memcpy(dst, src, dst_len * sizeof(WCHAR));
2563 return dst_len;
2565 else /* Append 0 if enough space */
2567 memcpy(dst, src, line_len * sizeof(WCHAR));
2568 dst[line_len] = 0;
2569 return line_len;
2572 else
2574 LPSTR dst = (LPSTR)lParam;
2575 INT ret;
2576 ret = WideCharToMultiByte(CP_ACP, 0, src, line_len, dst, dst_len, NULL, NULL);
2577 if(!ret) /* Insufficient buffer size */
2578 return dst_len;
2579 if(ret < dst_len) /* Append 0 if enough space */
2580 dst[ret] = 0;
2581 return ret;
2586 /*********************************************************************
2588 * EM_GETSEL
2591 static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end)
2593 UINT s = es->selection_start;
2594 UINT e = es->selection_end;
2596 ORDER_UINT(s, e);
2597 if (start)
2598 *start = s;
2599 if (end)
2600 *end = e;
2601 return MAKELONG(s, e);
2605 /*********************************************************************
2607 * EM_GETTHUMB
2609 * FIXME: is this right ? (or should it be only VSCROLL)
2610 * (and maybe only for edit controls that really have their
2611 * own scrollbars) (and maybe only for multiline controls ?)
2612 * All in all: very poorly documented
2615 static LRESULT EDIT_EM_GetThumb(EDITSTATE *es)
2617 return MAKELONG(EDIT_WM_VScroll(es, EM_GETTHUMB16, 0),
2618 EDIT_WM_HScroll(es, EM_GETTHUMB16, 0));
2622 /*********************************************************************
2624 * EM_LINEFROMCHAR
2627 static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index)
2629 INT line;
2630 LINEDEF *line_def;
2632 if (!(es->style & ES_MULTILINE))
2633 return 0;
2634 if (index > (INT)strlenW(es->text))
2635 return es->line_count - 1;
2636 if (index == -1)
2637 index = min(es->selection_start, es->selection_end);
2639 line = 0;
2640 line_def = es->first_line_def;
2641 index -= line_def->length;
2642 while ((index >= 0) && line_def->next) {
2643 line++;
2644 line_def = line_def->next;
2645 index -= line_def->length;
2647 return line;
2651 /*********************************************************************
2653 * EM_LINEINDEX
2656 static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line)
2658 INT line_index;
2659 LINEDEF *line_def;
2661 if (!(es->style & ES_MULTILINE))
2662 return 0;
2663 if (line >= es->line_count)
2664 return -1;
2666 line_index = 0;
2667 line_def = es->first_line_def;
2668 if (line == -1) {
2669 INT index = es->selection_end - line_def->length;
2670 while ((index >= 0) && line_def->next) {
2671 line_index += line_def->length;
2672 line_def = line_def->next;
2673 index -= line_def->length;
2675 } else {
2676 while (line > 0) {
2677 line_index += line_def->length;
2678 line_def = line_def->next;
2679 line--;
2682 return line_index;
2686 /*********************************************************************
2688 * EM_LINELENGTH
2691 static INT EDIT_EM_LineLength(EDITSTATE *es, INT index)
2693 LINEDEF *line_def;
2695 if (!(es->style & ES_MULTILINE))
2696 return strlenW(es->text);
2698 if (index == -1) {
2699 /* get the number of remaining non-selected chars of selected lines */
2700 INT32 l; /* line number */
2701 INT32 li; /* index of first char in line */
2702 INT32 count;
2703 l = EDIT_EM_LineFromChar(es, es->selection_start);
2704 /* # chars before start of selection area */
2705 count = es->selection_start - EDIT_EM_LineIndex(es, l);
2706 l = EDIT_EM_LineFromChar(es, es->selection_end);
2707 /* # chars after end of selection */
2708 li = EDIT_EM_LineIndex(es, l);
2709 count += li + EDIT_EM_LineLength(es, li) - es->selection_end;
2710 return count;
2712 line_def = es->first_line_def;
2713 index -= line_def->length;
2714 while ((index >= 0) && line_def->next) {
2715 line_def = line_def->next;
2716 index -= line_def->length;
2718 return line_def->net_length;
2722 /*********************************************************************
2724 * EM_LINESCROLL
2726 * NOTE: dx is in average character widths, dy - in lines;
2729 static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy)
2731 if (!(es->style & ES_MULTILINE))
2732 return FALSE;
2734 dx *= es->char_width;
2735 return EDIT_EM_LineScroll_internal(es, dx, dy);
2738 /*********************************************************************
2740 * EDIT_EM_LineScroll_internal
2742 * Version of EDIT_EM_LineScroll for internal use.
2743 * It doesn't refuse if ES_MULTILINE is set and assumes that
2744 * dx is in pixels, dy - in lines.
2747 static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy)
2749 INT nyoff;
2750 INT x_offset_in_pixels;
2752 if (es->style & ES_MULTILINE)
2754 x_offset_in_pixels = es->x_offset;
2756 else
2758 dy = 0;
2759 x_offset_in_pixels = SLOWORD(EDIT_EM_PosFromChar(es, es->x_offset, FALSE));
2762 if (-dx > x_offset_in_pixels)
2763 dx = -x_offset_in_pixels;
2764 if (dx > es->text_width - x_offset_in_pixels)
2765 dx = es->text_width - x_offset_in_pixels;
2766 nyoff = max(0, es->y_offset + dy);
2767 if (nyoff >= es->line_count)
2768 nyoff = es->line_count - 1;
2769 dy = (es->y_offset - nyoff) * es->line_height;
2770 if (dx || dy) {
2771 RECT rc1;
2772 RECT rc;
2774 es->y_offset = nyoff;
2775 if(es->style & ES_MULTILINE)
2776 es->x_offset += dx;
2777 else
2778 es->x_offset += dx / es->char_width;
2780 GetClientRect(es->hwndSelf, &rc1);
2781 IntersectRect(&rc, &rc1, &es->format_rect);
2782 ScrollWindowEx(es->hwndSelf, -dx, dy,
2783 NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE);
2784 /* force scroll info update */
2785 EDIT_UpdateScrollInfo(es);
2787 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2788 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
2789 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2790 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
2791 return TRUE;
2795 /*********************************************************************
2797 * EM_POSFROMCHAR
2800 static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap)
2802 INT len = strlenW(es->text);
2803 INT l;
2804 INT li;
2805 INT x;
2806 INT y = 0;
2807 HDC dc;
2808 HFONT old_font = 0;
2809 SIZE size;
2811 index = min(index, len);
2812 dc = GetDC(es->hwndSelf);
2813 if (es->font)
2814 old_font = SelectObject(dc, es->font);
2815 if (es->style & ES_MULTILINE) {
2816 l = EDIT_EM_LineFromChar(es, index);
2817 y = (l - es->y_offset) * es->line_height;
2818 li = EDIT_EM_LineIndex(es, l);
2819 if (after_wrap && (li == index) && l) {
2820 INT l2 = l - 1;
2821 LINEDEF *line_def = es->first_line_def;
2822 while (l2) {
2823 line_def = line_def->next;
2824 l2--;
2826 if (line_def->ending == END_WRAP) {
2827 l--;
2828 y -= es->line_height;
2829 li = EDIT_EM_LineIndex(es, l);
2832 x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li,
2833 es->tabs_count, es->tabs)) - es->x_offset;
2834 } else {
2835 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
2836 if (index < es->x_offset) {
2837 GetTextExtentPoint32W(dc, text + index,
2838 es->x_offset - index, &size);
2839 x = -size.cx;
2840 } else {
2841 GetTextExtentPoint32W(dc, text + es->x_offset,
2842 index - es->x_offset, &size);
2843 x = size.cx;
2845 y = 0;
2846 if (es->style & ES_PASSWORD)
2847 HeapFree(GetProcessHeap(), 0, text);
2849 x += es->format_rect.left;
2850 y += es->format_rect.top;
2851 if (es->font)
2852 SelectObject(dc, old_font);
2853 ReleaseDC(es->hwndSelf, dc);
2854 return MAKELONG((INT16)x, (INT16)y);
2858 /*********************************************************************
2860 * EM_REPLACESEL
2862 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2865 static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update)
2867 UINT strl = strlenW(lpsz_replace);
2868 UINT tl = strlenW(es->text);
2869 UINT utl;
2870 UINT s;
2871 UINT e;
2872 UINT i;
2873 LPWSTR p;
2874 HRGN hrgn = 0;
2876 TRACE("%s, can_undo %d, send_update %d\n",
2877 debugstr_w(lpsz_replace), can_undo, send_update);
2879 s = es->selection_start;
2880 e = es->selection_end;
2882 if ((s == e) && !strl)
2883 return;
2885 ORDER_UINT(s, e);
2887 if (!EDIT_MakeFit(es, tl - (e - s) + strl))
2888 return;
2890 if (e != s) {
2891 /* there is something to be deleted */
2892 TRACE("deleting stuff.\n");
2893 if (can_undo) {
2894 utl = strlenW(es->undo_text);
2895 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
2896 /* undo-buffer is extended to the right */
2897 EDIT_MakeUndoFit(es, utl + e - s);
2898 strncpyW(es->undo_text + utl, es->text + s, e - s + 1);
2899 (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */
2900 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
2901 /* undo-buffer is extended to the left */
2902 EDIT_MakeUndoFit(es, utl + e - s);
2903 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
2904 p[e - s] = p[0];
2905 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2906 p[i] = (es->text + s)[i];
2907 es->undo_position = s;
2908 } else {
2909 /* new undo-buffer */
2910 EDIT_MakeUndoFit(es, e - s);
2911 strncpyW(es->undo_text, es->text + s, e - s + 1);
2912 es->undo_text[e - s] = 0; /* ensure 0 termination */
2913 es->undo_position = s;
2915 /* any deletion makes the old insertion-undo invalid */
2916 es->undo_insert_count = 0;
2917 } else
2918 EDIT_EM_EmptyUndoBuffer(es);
2920 /* now delete */
2921 strcpyW(es->text + s, es->text + e);
2923 if (strl) {
2924 /* there is an insertion */
2925 if (can_undo) {
2926 if ((s == es->undo_position) ||
2927 ((es->undo_insert_count) &&
2928 (s == es->undo_position + es->undo_insert_count)))
2930 * insertion is new and at delete position or
2931 * an extension to either left or right
2933 es->undo_insert_count += strl;
2934 else {
2935 /* new insertion undo */
2936 es->undo_position = s;
2937 es->undo_insert_count = strl;
2938 /* new insertion makes old delete-buffer invalid */
2939 *es->undo_text = '\0';
2941 } else
2942 EDIT_EM_EmptyUndoBuffer(es);
2944 /* now insert */
2945 tl = strlenW(es->text);
2946 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));
2947 for (p = es->text + tl ; p >= es->text + s ; p--)
2948 p[strl] = p[0];
2949 for (i = 0 , p = es->text + s ; i < strl ; i++)
2950 p[i] = lpsz_replace[i];
2951 if(es->style & ES_UPPERCASE)
2952 CharUpperBuffW(p, strl);
2953 else if(es->style & ES_LOWERCASE)
2954 CharLowerBuffW(p, strl);
2955 s += strl;
2957 if (es->style & ES_MULTILINE)
2959 INT s = min(es->selection_start, es->selection_end);
2961 hrgn = CreateRectRgn(0, 0, 0, 0);
2962 EDIT_BuildLineDefs_ML(es, s, s + strl,
2963 strl - abs(es->selection_end - es->selection_start), hrgn);
2965 else
2966 EDIT_CalcLineWidth_SL(es);
2968 EDIT_EM_SetSel(es, s, s, FALSE);
2969 es->flags |= EF_MODIFIED;
2970 if (send_update) es->flags |= EF_UPDATE;
2971 EDIT_EM_ScrollCaret(es);
2973 /* force scroll info update */
2974 EDIT_UpdateScrollInfo(es);
2976 if (hrgn)
2978 EDIT_UpdateTextRegion(es, hrgn, TRUE);
2979 DeleteObject(hrgn);
2981 else
2982 EDIT_UpdateText(es, NULL, TRUE);
2984 if(es->flags & EF_UPDATE)
2986 es->flags &= ~EF_UPDATE;
2987 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
2992 /*********************************************************************
2994 * EM_SCROLL
2997 static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
2999 INT dy;
3001 if (!(es->style & ES_MULTILINE))
3002 return (LRESULT)FALSE;
3004 dy = 0;
3006 switch (action) {
3007 case SB_LINEUP:
3008 if (es->y_offset)
3009 dy = -1;
3010 break;
3011 case SB_LINEDOWN:
3012 if (es->y_offset < es->line_count - 1)
3013 dy = 1;
3014 break;
3015 case SB_PAGEUP:
3016 if (es->y_offset)
3017 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
3018 break;
3019 case SB_PAGEDOWN:
3020 if (es->y_offset < es->line_count - 1)
3021 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3022 break;
3023 default:
3024 return (LRESULT)FALSE;
3026 if (dy) {
3027 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3028 /* check if we are going to move too far */
3029 if(es->y_offset + dy > es->line_count - vlc)
3030 dy = es->line_count - vlc - es->y_offset;
3032 /* Notification is done in EDIT_EM_LineScroll */
3033 if(dy)
3034 EDIT_EM_LineScroll(es, 0, dy);
3036 return MAKELONG((INT16)dy, (BOOL16)TRUE);
3040 /*********************************************************************
3042 * EM_SCROLLCARET
3045 static void EDIT_EM_ScrollCaret(EDITSTATE *es)
3047 if (es->style & ES_MULTILINE) {
3048 INT l;
3049 INT li;
3050 INT vlc;
3051 INT ww;
3052 INT cw = es->char_width;
3053 INT x;
3054 INT dy = 0;
3055 INT dx = 0;
3057 l = EDIT_EM_LineFromChar(es, es->selection_end);
3058 li = EDIT_EM_LineIndex(es, l);
3059 x = SLOWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP));
3060 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3061 if (l >= es->y_offset + vlc)
3062 dy = l - vlc + 1 - es->y_offset;
3063 if (l < es->y_offset)
3064 dy = l - es->y_offset;
3065 ww = es->format_rect.right - es->format_rect.left;
3066 if (x < es->format_rect.left)
3067 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
3068 if (x > es->format_rect.right)
3069 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
3070 if (dy || dx)
3072 /* check if we are going to move too far */
3073 if(es->x_offset + dx + ww > es->text_width)
3074 dx = es->text_width - ww - es->x_offset;
3075 if(dx || dy)
3076 EDIT_EM_LineScroll_internal(es, dx, dy);
3078 } else {
3079 INT x;
3080 INT goal;
3081 INT format_width;
3083 if (!(es->style & ES_AUTOHSCROLL))
3084 return;
3086 x = SLOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3087 format_width = es->format_rect.right - es->format_rect.left;
3088 if (x < es->format_rect.left) {
3089 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
3090 do {
3091 es->x_offset--;
3092 x = SLOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3093 } while ((x < goal) && es->x_offset);
3094 /* FIXME: use ScrollWindow() somehow to improve performance */
3095 EDIT_UpdateText(es, NULL, TRUE);
3096 } else if (x > es->format_rect.right) {
3097 INT x_last;
3098 INT len = strlenW(es->text);
3099 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
3100 do {
3101 es->x_offset++;
3102 x = SLOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3103 x_last = SLOWORD(EDIT_EM_PosFromChar(es, len, FALSE));
3104 } while ((x > goal) && (x_last > es->format_rect.right));
3105 /* FIXME: use ScrollWindow() somehow to improve performance */
3106 EDIT_UpdateText(es, NULL, TRUE);
3110 if(es->flags & EF_FOCUSED)
3111 EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
3115 /*********************************************************************
3117 * EM_SETHANDLE
3119 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3122 static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc)
3124 HINSTANCE hInstance = (HINSTANCE)GetWindowLongW( es->hwndSelf, GWL_HINSTANCE );
3126 if (!(es->style & ES_MULTILINE))
3127 return;
3129 if (!hloc) {
3130 WARN("called with NULL handle\n");
3131 return;
3134 EDIT_UnlockBuffer(es, TRUE);
3136 if(es->hloc16)
3138 LOCAL_Free(hInstance, es->hloc16);
3139 es->hloc16 = (HLOCAL16)NULL;
3142 if(es->is_unicode)
3144 if(es->hloc32A)
3146 LocalFree(es->hloc32A);
3147 es->hloc32A = (HLOCAL)NULL;
3149 es->hloc32W = hloc;
3151 else
3153 INT countW, countA;
3154 HLOCAL hloc32W_new;
3155 WCHAR *textW;
3156 CHAR *textA;
3158 countA = LocalSize(hloc);
3159 textA = LocalLock(hloc);
3160 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3161 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3163 ERR("Could not allocate new unicode buffer\n");
3164 return;
3166 textW = LocalLock(hloc32W_new);
3167 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3168 LocalUnlock(hloc32W_new);
3169 LocalUnlock(hloc);
3171 if(es->hloc32W)
3172 LocalFree(es->hloc32W);
3174 es->hloc32W = hloc32W_new;
3175 es->hloc32A = hloc;
3178 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3180 EDIT_LockBuffer(es);
3182 es->x_offset = es->y_offset = 0;
3183 es->selection_start = es->selection_end = 0;
3184 EDIT_EM_EmptyUndoBuffer(es);
3185 es->flags &= ~EF_MODIFIED;
3186 es->flags &= ~EF_UPDATE;
3187 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, (HRGN)0);
3188 EDIT_UpdateText(es, NULL, TRUE);
3189 EDIT_EM_ScrollCaret(es);
3190 /* force scroll info update */
3191 EDIT_UpdateScrollInfo(es);
3195 /*********************************************************************
3197 * EM_SETHANDLE16
3199 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3202 static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc)
3204 HINSTANCE hInstance = (HINSTANCE)GetWindowLongW( es->hwndSelf, GWL_HINSTANCE );
3205 INT countW, countA;
3206 HLOCAL hloc32W_new;
3207 WCHAR *textW;
3208 CHAR *textA;
3210 if (!(es->style & ES_MULTILINE))
3211 return;
3213 if (!hloc) {
3214 WARN("called with NULL handle\n");
3215 return;
3218 EDIT_UnlockBuffer(es, TRUE);
3220 if(es->hloc32A)
3222 LocalFree(es->hloc32A);
3223 es->hloc32A = (HLOCAL)NULL;
3226 countA = LOCAL_Size(hInstance, hloc);
3227 textA = LOCAL_Lock(hInstance, hloc);
3228 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3229 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3231 ERR("Could not allocate new unicode buffer\n");
3232 return;
3234 textW = LocalLock(hloc32W_new);
3235 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3236 LocalUnlock(hloc32W_new);
3237 LOCAL_Unlock(hInstance, hloc);
3239 if(es->hloc32W)
3240 LocalFree(es->hloc32W);
3242 es->hloc32W = hloc32W_new;
3243 es->hloc16 = hloc;
3245 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3247 EDIT_LockBuffer(es);
3249 es->x_offset = es->y_offset = 0;
3250 es->selection_start = es->selection_end = 0;
3251 EDIT_EM_EmptyUndoBuffer(es);
3252 es->flags &= ~EF_MODIFIED;
3253 es->flags &= ~EF_UPDATE;
3254 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, (HRGN)0);
3255 EDIT_UpdateText(es, NULL, TRUE);
3256 EDIT_EM_ScrollCaret(es);
3257 /* force scroll info update */
3258 EDIT_UpdateScrollInfo(es);
3262 /*********************************************************************
3264 * EM_SETLIMITTEXT
3266 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3267 * However, the windows version is not complied to yet in all of edit.c
3269 * Additionally as the wrapper for RichEdit controls we need larger buffers
3270 * at present -1 will represent nolimit
3272 static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit)
3274 if (limit == 0xFFFFFFFF)
3275 es->buffer_limit = -1;
3276 else if (es->style & ES_MULTILINE) {
3277 if (limit)
3278 es->buffer_limit = min(limit, BUFLIMIT_MULTI);
3279 else
3280 es->buffer_limit = BUFLIMIT_MULTI;
3281 } else {
3282 if (limit)
3283 es->buffer_limit = min(limit, BUFLIMIT_SINGLE);
3284 else
3285 es->buffer_limit = BUFLIMIT_SINGLE;
3290 /*********************************************************************
3292 * EM_SETMARGINS
3294 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3295 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3296 * of the char's width, according to the new docs.
3299 static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
3300 INT left, INT right)
3302 if (action & EC_LEFTMARGIN) {
3303 if (left != EC_USEFONTINFO)
3304 es->left_margin = left;
3305 else
3306 es->left_margin = es->char_width / 3;
3309 if (action & EC_RIGHTMARGIN) {
3310 if (right != EC_USEFONTINFO)
3311 es->right_margin = right;
3312 else
3313 es->right_margin = es->char_width / 3;
3315 TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin);
3319 /*********************************************************************
3321 * EM_SETPASSWORDCHAR
3324 static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c)
3326 LONG style;
3328 if (es->style & ES_MULTILINE)
3329 return;
3331 if (es->password_char == c)
3332 return;
3334 style = GetWindowLongW( es->hwndSelf, GWL_STYLE );
3335 es->password_char = c;
3336 if (c) {
3337 SetWindowLongW( es->hwndSelf, GWL_STYLE, style | ES_PASSWORD );
3338 es->style |= ES_PASSWORD;
3339 } else {
3340 SetWindowLongW( es->hwndSelf, GWL_STYLE, style & ~ES_PASSWORD );
3341 es->style &= ~ES_PASSWORD;
3343 EDIT_UpdateText(es, NULL, TRUE);
3347 /*********************************************************************
3349 * EDIT_EM_SetSel
3351 * note: unlike the specs say: the order of start and end
3352 * _is_ preserved in Windows. (i.e. start can be > end)
3353 * In other words: this handler is OK
3356 static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
3358 UINT old_start = es->selection_start;
3359 UINT old_end = es->selection_end;
3360 UINT len = strlenW(es->text);
3362 if (start == (UINT)-1) {
3363 start = es->selection_end;
3364 end = es->selection_end;
3365 } else {
3366 start = min(start, len);
3367 end = min(end, len);
3369 es->selection_start = start;
3370 es->selection_end = end;
3371 if (after_wrap)
3372 es->flags |= EF_AFTER_WRAP;
3373 else
3374 es->flags &= ~EF_AFTER_WRAP;
3375 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3376 ORDER_UINT(start, end);
3377 ORDER_UINT(end, old_end);
3378 ORDER_UINT(start, old_start);
3379 ORDER_UINT(old_start, old_end);
3380 if (end != old_start)
3383 * One can also do
3384 * ORDER_UINT32(end, old_start);
3385 * EDIT_InvalidateText(es, start, end);
3386 * EDIT_InvalidateText(es, old_start, old_end);
3387 * in place of the following if statement.
3389 if (old_start > end )
3391 EDIT_InvalidateText(es, start, end);
3392 EDIT_InvalidateText(es, old_start, old_end);
3394 else
3396 EDIT_InvalidateText(es, start, old_start);
3397 EDIT_InvalidateText(es, end, old_end);
3400 else EDIT_InvalidateText(es, start, old_end);
3404 /*********************************************************************
3406 * EM_SETTABSTOPS
3409 static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs)
3411 if (!(es->style & ES_MULTILINE))
3412 return FALSE;
3413 if (es->tabs)
3414 HeapFree(GetProcessHeap(), 0, es->tabs);
3415 es->tabs_count = count;
3416 if (!count)
3417 es->tabs = NULL;
3418 else {
3419 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
3420 memcpy(es->tabs, tabs, count * sizeof(INT));
3422 return TRUE;
3426 /*********************************************************************
3428 * EM_SETTABSTOPS16
3431 static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs)
3433 if (!(es->style & ES_MULTILINE))
3434 return FALSE;
3435 if (es->tabs)
3436 HeapFree(GetProcessHeap(), 0, es->tabs);
3437 es->tabs_count = count;
3438 if (!count)
3439 es->tabs = NULL;
3440 else {
3441 INT i;
3442 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
3443 for (i = 0 ; i < count ; i++)
3444 es->tabs[i] = *tabs++;
3446 return TRUE;
3450 /*********************************************************************
3452 * EM_SETWORDBREAKPROC
3455 static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, LPARAM lParam)
3457 if (es->word_break_proc == (void *)lParam)
3458 return;
3460 es->word_break_proc = (void *)lParam;
3461 es->word_break_proc16 = NULL;
3463 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
3464 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, (HRGN)0);
3465 EDIT_UpdateText(es, NULL, TRUE);
3470 /*********************************************************************
3472 * EM_SETWORDBREAKPROC16
3475 static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
3477 if (es->word_break_proc16 == wbp)
3478 return;
3480 es->word_break_proc = NULL;
3481 es->word_break_proc16 = wbp;
3482 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
3483 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, (HRGN)0);
3484 EDIT_UpdateText(es, NULL, TRUE);
3489 /*********************************************************************
3491 * EM_UNDO / WM_UNDO
3494 static BOOL EDIT_EM_Undo(EDITSTATE *es)
3496 INT ulength;
3497 LPWSTR utext;
3499 /* Protect read-only edit control from modification */
3500 if(es->style & ES_READONLY)
3501 return FALSE;
3503 ulength = strlenW(es->undo_text);
3504 utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR));
3506 strcpyW(utext, es->undo_text);
3508 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3509 es->undo_insert_count, debugstr_w(utext));
3511 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
3512 EDIT_EM_EmptyUndoBuffer(es);
3513 EDIT_EM_ReplaceSel(es, TRUE, utext, FALSE);
3514 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
3515 /* send the notification after the selection start and end are set */
3516 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3517 EDIT_EM_ScrollCaret(es);
3518 HeapFree(GetProcessHeap(), 0, utext);
3520 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3521 es->undo_insert_count, debugstr_w(es->undo_text));
3522 return TRUE;
3526 /*********************************************************************
3528 * WM_CHAR
3531 static void EDIT_WM_Char(EDITSTATE *es, WCHAR c)
3533 BOOL control;
3535 /* Protect read-only edit control from modification */
3536 if(es->style & ES_READONLY)
3537 return;
3539 control = GetKeyState(VK_CONTROL) & 0x8000;
3541 switch (c) {
3542 case '\r':
3543 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3544 if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
3545 break;
3546 case '\n':
3547 if (es->style & ES_MULTILINE) {
3548 if (es->style & ES_READONLY) {
3549 EDIT_MoveHome(es, FALSE);
3550 EDIT_MoveDown_ML(es, FALSE);
3551 } else {
3552 static const WCHAR cr_lfW[] = {'\r','\n',0};
3553 EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, TRUE);
3556 break;
3557 case '\t':
3558 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
3560 static const WCHAR tabW[] = {'\t',0};
3561 EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE);
3563 break;
3564 case VK_BACK:
3565 if (!(es->style & ES_READONLY) && !control) {
3566 if (es->selection_start != es->selection_end)
3567 EDIT_WM_Clear(es);
3568 else {
3569 /* delete character left of caret */
3570 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
3571 EDIT_MoveBackward(es, TRUE);
3572 EDIT_WM_Clear(es);
3575 break;
3576 case 0x03: /* ^C */
3577 SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
3578 break;
3579 case 0x16: /* ^V */
3580 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
3581 break;
3582 case 0x18: /* ^X */
3583 SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
3584 break;
3586 default:
3587 if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) {
3588 WCHAR str[2];
3589 str[0] = c;
3590 str[1] = '\0';
3591 EDIT_EM_ReplaceSel(es, TRUE, str, TRUE);
3593 break;
3598 /*********************************************************************
3600 * WM_COMMAND
3603 static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND control)
3605 if (code || control)
3606 return;
3608 switch (id) {
3609 case EM_UNDO:
3610 EDIT_EM_Undo(es);
3611 break;
3612 case WM_CUT:
3613 EDIT_WM_Cut(es);
3614 break;
3615 case WM_COPY:
3616 EDIT_WM_Copy(es);
3617 break;
3618 case WM_PASTE:
3619 EDIT_WM_Paste(es);
3620 break;
3621 case WM_CLEAR:
3622 EDIT_WM_Clear(es);
3623 break;
3624 case EM_SETSEL:
3625 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
3626 EDIT_EM_ScrollCaret(es);
3627 break;
3628 default:
3629 ERR("unknown menu item, please report\n");
3630 break;
3635 /*********************************************************************
3637 * WM_CONTEXTMENU
3639 * Note: the resource files resource/sysres_??.rc cannot define a
3640 * single popup menu. Hence we use a (dummy) menubar
3641 * containing the single popup menu as its first item.
3643 * FIXME: the message identifiers have been chosen arbitrarily,
3644 * hence we use MF_BYPOSITION.
3645 * We might as well use the "real" values (anybody knows ?)
3646 * The menu definition is in resources/sysres_??.rc.
3647 * Once these are OK, we better use MF_BYCOMMAND here
3648 * (as we do in EDIT_WM_Command()).
3651 static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
3653 HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3654 HMENU popup = GetSubMenu(menu, 0);
3655 UINT start = es->selection_start;
3656 UINT end = es->selection_end;
3658 ORDER_UINT(start, end);
3660 /* undo */
3661 EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3662 /* cut */
3663 EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3664 /* copy */
3665 EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
3666 /* paste */
3667 EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3668 /* delete */
3669 EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3670 /* select all */
3671 EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != strlenW(es->text)) ? MF_ENABLED : MF_GRAYED));
3673 TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, es->hwndSelf, NULL);
3674 DestroyMenu(menu);
3678 /*********************************************************************
3680 * WM_COPY
3683 static void EDIT_WM_Copy(EDITSTATE *es)
3685 INT s = min(es->selection_start, es->selection_end);
3686 INT e = max(es->selection_start, es->selection_end);
3687 HGLOBAL hdst;
3688 LPWSTR dst;
3690 if (e == s) return;
3692 hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR));
3693 dst = GlobalLock(hdst);
3694 strncpyW(dst, es->text + s, e - s);
3695 dst[e - s] = 0; /* ensure 0 termination */
3696 TRACE("%s\n", debugstr_w(dst));
3697 GlobalUnlock(hdst);
3698 OpenClipboard(es->hwndSelf);
3699 EmptyClipboard();
3700 SetClipboardData(CF_UNICODETEXT, hdst);
3701 CloseClipboard();
3705 /*********************************************************************
3707 * WM_CREATE
3710 static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name)
3712 TRACE("%s\n", debugstr_w(name));
3714 * To initialize some final structure members, we call some helper
3715 * functions. However, since the EDITSTATE is not consistent (i.e.
3716 * not fully initialized), we should be very careful which
3717 * functions can be called, and in what order.
3719 EDIT_WM_SetFont(es, 0, FALSE);
3720 EDIT_EM_EmptyUndoBuffer(es);
3722 if (name && *name) {
3723 EDIT_EM_ReplaceSel(es, FALSE, name, FALSE);
3724 /* if we insert text to the editline, the text scrolls out
3725 * of the window, as the caret is placed after the insert
3726 * pos normally; thus we reset es->selection... to 0 and
3727 * update caret
3729 es->selection_start = es->selection_end = 0;
3730 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3731 * Messages are only to be sent when the USER does something to
3732 * change the contents. So I am removing this EN_CHANGE
3734 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3736 EDIT_EM_ScrollCaret(es);
3738 /* force scroll info update */
3739 EDIT_UpdateScrollInfo(es);
3740 return 0;
3744 /*********************************************************************
3746 * WM_DESTROY
3749 static LRESULT EDIT_WM_Destroy(EDITSTATE *es)
3751 HINSTANCE hInstance = (HINSTANCE)GetWindowLongW( es->hwndSelf, GWL_HINSTANCE );
3752 LINEDEF *pc, *pp;
3754 if (es->hloc32W) {
3755 while (LocalUnlock(es->hloc32W)) ;
3756 LocalFree(es->hloc32W);
3758 if (es->hloc32A) {
3759 while (LocalUnlock(es->hloc32A)) ;
3760 LocalFree(es->hloc32A);
3762 if (es->hloc16) {
3763 while (LOCAL_Unlock(hInstance, es->hloc16)) ;
3764 LOCAL_Free(hInstance, es->hloc16);
3767 pc = es->first_line_def;
3768 while (pc)
3770 pp = pc->next;
3771 HeapFree(GetProcessHeap(), 0, pc);
3772 pc = pp;
3775 SetWindowLongW( es->hwndSelf, 0, 0 );
3776 HeapFree(GetProcessHeap(), 0, es);
3778 return 0;
3782 /*********************************************************************
3784 * WM_ERASEBKGND
3787 static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc)
3789 HBRUSH brush;
3790 RECT rc;
3792 if (!(brush = EDIT_NotifyCtlColor(es, dc)))
3793 brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
3795 GetClientRect(es->hwndSelf, &rc);
3796 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
3797 GetClipBox(dc, &rc);
3799 * FIXME: specs say that we should UnrealizeObject() the brush,
3800 * but the specs of UnrealizeObject() say that we shouldn't
3801 * unrealize a stock object. The default brush that
3802 * DefWndProc() returns is ... a stock object.
3804 FillRect(dc, &rc, brush);
3805 return -1;
3809 /*********************************************************************
3811 * WM_GETTEXT
3814 static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPARAM lParam, BOOL unicode)
3816 if(!count) return 0;
3818 if(unicode)
3820 LPWSTR textW = (LPWSTR)lParam;
3821 lstrcpynW(textW, es->text, count);
3822 return strlenW(textW);
3824 else
3826 LPSTR textA = (LPSTR)lParam;
3827 if (!WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, count, NULL, NULL))
3828 textA[count - 1] = 0; /* ensure 0 termination */
3829 return strlen(textA);
3833 /*********************************************************************
3835 * WM_HSCROLL
3838 static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos)
3840 INT dx;
3841 INT fw;
3843 if (!(es->style & ES_MULTILINE))
3844 return 0;
3846 if (!(es->style & ES_AUTOHSCROLL))
3847 return 0;
3849 dx = 0;
3850 fw = es->format_rect.right - es->format_rect.left;
3851 switch (action) {
3852 case SB_LINELEFT:
3853 TRACE("SB_LINELEFT\n");
3854 if (es->x_offset)
3855 dx = -es->char_width;
3856 break;
3857 case SB_LINERIGHT:
3858 TRACE("SB_LINERIGHT\n");
3859 if (es->x_offset < es->text_width)
3860 dx = es->char_width;
3861 break;
3862 case SB_PAGELEFT:
3863 TRACE("SB_PAGELEFT\n");
3864 if (es->x_offset)
3865 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3866 break;
3867 case SB_PAGERIGHT:
3868 TRACE("SB_PAGERIGHT\n");
3869 if (es->x_offset < es->text_width)
3870 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3871 break;
3872 case SB_LEFT:
3873 TRACE("SB_LEFT\n");
3874 if (es->x_offset)
3875 dx = -es->x_offset;
3876 break;
3877 case SB_RIGHT:
3878 TRACE("SB_RIGHT\n");
3879 if (es->x_offset < es->text_width)
3880 dx = es->text_width - es->x_offset;
3881 break;
3882 case SB_THUMBTRACK:
3883 TRACE("SB_THUMBTRACK %d\n", pos);
3884 es->flags |= EF_HSCROLL_TRACK;
3885 if(es->style & WS_HSCROLL)
3886 dx = pos - es->x_offset;
3887 else
3889 INT fw, new_x;
3890 /* Sanity check */
3891 if(pos < 0 || pos > 100) return 0;
3892 /* Assume default scroll range 0-100 */
3893 fw = es->format_rect.right - es->format_rect.left;
3894 new_x = pos * (es->text_width - fw) / 100;
3895 dx = es->text_width ? (new_x - es->x_offset) : 0;
3897 break;
3898 case SB_THUMBPOSITION:
3899 TRACE("SB_THUMBPOSITION %d\n", pos);
3900 es->flags &= ~EF_HSCROLL_TRACK;
3901 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
3902 dx = pos - es->x_offset;
3903 else
3905 INT fw, new_x;
3906 /* Sanity check */
3907 if(pos < 0 || pos > 100) return 0;
3908 /* Assume default scroll range 0-100 */
3909 fw = es->format_rect.right - es->format_rect.left;
3910 new_x = pos * (es->text_width - fw) / 100;
3911 dx = es->text_width ? (new_x - es->x_offset) : 0;
3913 if (!dx) {
3914 /* force scroll info update */
3915 EDIT_UpdateScrollInfo(es);
3916 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
3918 break;
3919 case SB_ENDSCROLL:
3920 TRACE("SB_ENDSCROLL\n");
3921 break;
3923 * FIXME : the next two are undocumented !
3924 * Are we doing the right thing ?
3925 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3926 * although it's also a regular control message.
3928 case EM_GETTHUMB: /* this one is used by NT notepad */
3929 case EM_GETTHUMB16:
3931 LRESULT ret;
3932 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
3933 ret = GetScrollPos(es->hwndSelf, SB_HORZ);
3934 else
3936 /* Assume default scroll range 0-100 */
3937 INT fw = es->format_rect.right - es->format_rect.left;
3938 ret = es->text_width ? es->x_offset * 100 / (es->text_width - fw) : 0;
3940 TRACE("EM_GETTHUMB: returning %ld\n", ret);
3941 return ret;
3943 case EM_LINESCROLL16:
3944 TRACE("EM_LINESCROLL16\n");
3945 dx = pos;
3946 break;
3948 default:
3949 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3950 action, action);
3951 return 0;
3953 if (dx)
3955 INT fw = es->format_rect.right - es->format_rect.left;
3956 /* check if we are going to move too far */
3957 if(es->x_offset + dx + fw > es->text_width)
3958 dx = es->text_width - fw - es->x_offset;
3959 if(dx)
3960 EDIT_EM_LineScroll_internal(es, dx, 0);
3962 return 0;
3966 /*********************************************************************
3968 * EDIT_CheckCombo
3971 static BOOL EDIT_CheckCombo(EDITSTATE *es, UINT msg, INT key)
3973 HWND hLBox = es->hwndListBox;
3974 HWND hCombo;
3975 BOOL bDropped;
3976 int nEUI;
3978 if (!hLBox)
3979 return FALSE;
3981 hCombo = GetParent(es->hwndSelf);
3982 bDropped = TRUE;
3983 nEUI = 0;
3985 TRACE_(combo)("[%04x]: handling msg %04x (%04x)\n",
3986 es->hwndSelf, (UINT16)msg, (UINT16)key);
3988 if (key == VK_UP || key == VK_DOWN)
3990 if (SendMessageW(hCombo, CB_GETEXTENDEDUI, 0, 0))
3991 nEUI = 1;
3993 if (msg == WM_KEYDOWN || nEUI)
3994 bDropped = (BOOL)SendMessageW(hCombo, CB_GETDROPPEDSTATE, 0, 0);
3997 switch (msg)
3999 case WM_KEYDOWN:
4000 if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN))
4002 /* make sure ComboLBox pops up */
4003 SendMessageW(hCombo, CB_SETEXTENDEDUI, FALSE, 0);
4004 key = VK_F4;
4005 nEUI = 2;
4008 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
4009 break;
4011 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
4012 if (nEUI)
4013 SendMessageW(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0);
4014 else
4015 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0);
4016 break;
4019 if(nEUI == 2)
4020 SendMessageW(hCombo, CB_SETEXTENDEDUI, TRUE, 0);
4022 return TRUE;
4026 /*********************************************************************
4028 * WM_KEYDOWN
4030 * Handling of special keys that don't produce a WM_CHAR
4031 * (i.e. non-printable keys) & Backspace & Delete
4034 static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key)
4036 BOOL shift;
4037 BOOL control;
4039 if (GetKeyState(VK_MENU) & 0x8000)
4040 return 0;
4042 shift = GetKeyState(VK_SHIFT) & 0x8000;
4043 control = GetKeyState(VK_CONTROL) & 0x8000;
4045 switch (key) {
4046 case VK_F4:
4047 case VK_UP:
4048 if (EDIT_CheckCombo(es, WM_KEYDOWN, key) || key == VK_F4)
4049 break;
4051 /* fall through */
4052 case VK_LEFT:
4053 if ((es->style & ES_MULTILINE) && (key == VK_UP))
4054 EDIT_MoveUp_ML(es, shift);
4055 else
4056 if (control)
4057 EDIT_MoveWordBackward(es, shift);
4058 else
4059 EDIT_MoveBackward(es, shift);
4060 break;
4061 case VK_DOWN:
4062 if (EDIT_CheckCombo(es, WM_KEYDOWN, key))
4063 break;
4064 /* fall through */
4065 case VK_RIGHT:
4066 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
4067 EDIT_MoveDown_ML(es, shift);
4068 else if (control)
4069 EDIT_MoveWordForward(es, shift);
4070 else
4071 EDIT_MoveForward(es, shift);
4072 break;
4073 case VK_HOME:
4074 EDIT_MoveHome(es, shift);
4075 break;
4076 case VK_END:
4077 EDIT_MoveEnd(es, shift);
4078 break;
4079 case VK_PRIOR:
4080 if (es->style & ES_MULTILINE)
4081 EDIT_MovePageUp_ML(es, shift);
4082 else
4083 EDIT_CheckCombo(es, WM_KEYDOWN, key);
4084 break;
4085 case VK_NEXT:
4086 if (es->style & ES_MULTILINE)
4087 EDIT_MovePageDown_ML(es, shift);
4088 else
4089 EDIT_CheckCombo(es, WM_KEYDOWN, key);
4090 break;
4091 case VK_DELETE:
4092 if (!(es->style & ES_READONLY) && !(shift && control)) {
4093 if (es->selection_start != es->selection_end) {
4094 if (shift)
4095 EDIT_WM_Cut(es);
4096 else
4097 EDIT_WM_Clear(es);
4098 } else {
4099 if (shift) {
4100 /* delete character left of caret */
4101 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4102 EDIT_MoveBackward(es, TRUE);
4103 EDIT_WM_Clear(es);
4104 } else if (control) {
4105 /* delete to end of line */
4106 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4107 EDIT_MoveEnd(es, TRUE);
4108 EDIT_WM_Clear(es);
4109 } else {
4110 /* delete character right of caret */
4111 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4112 EDIT_MoveForward(es, TRUE);
4113 EDIT_WM_Clear(es);
4117 break;
4118 case VK_INSERT:
4119 if (shift) {
4120 if (!(es->style & ES_READONLY))
4121 EDIT_WM_Paste(es);
4122 } else if (control)
4123 EDIT_WM_Copy(es);
4124 break;
4125 case VK_RETURN:
4126 /* If the edit doesn't want the return send a message to the default object */
4127 if(!(es->style & ES_WANTRETURN))
4129 HWND hwndParent = GetParent(es->hwndSelf);
4130 DWORD dw = SendMessageW( hwndParent, DM_GETDEFID, 0, 0 );
4131 if (HIWORD(dw) == DC_HASDEFID)
4133 SendMessageW( hwndParent, WM_COMMAND,
4134 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
4135 (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
4138 break;
4140 return 0;
4144 /*********************************************************************
4146 * WM_KILLFOCUS
4149 static LRESULT EDIT_WM_KillFocus(EDITSTATE *es)
4151 es->flags &= ~EF_FOCUSED;
4152 DestroyCaret();
4153 if(!(es->style & ES_NOHIDESEL))
4154 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4155 EDIT_NOTIFY_PARENT(es, EN_KILLFOCUS, "EN_KILLFOCUS");
4156 return 0;
4160 /*********************************************************************
4162 * WM_LBUTTONDBLCLK
4164 * The caret position has been set on the WM_LBUTTONDOWN message
4167 static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es)
4169 INT s;
4170 INT e = es->selection_end;
4171 INT l;
4172 INT li;
4173 INT ll;
4175 if (!(es->flags & EF_FOCUSED))
4176 return 0;
4178 l = EDIT_EM_LineFromChar(es, e);
4179 li = EDIT_EM_LineIndex(es, l);
4180 ll = EDIT_EM_LineLength(es, e);
4181 s = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT);
4182 e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_RIGHT);
4183 EDIT_EM_SetSel(es, s, e, FALSE);
4184 EDIT_EM_ScrollCaret(es);
4185 return 0;
4189 /*********************************************************************
4191 * WM_LBUTTONDOWN
4194 static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y)
4196 INT e;
4197 BOOL after_wrap;
4199 if (!(es->flags & EF_FOCUSED))
4200 return 0;
4202 es->bCaptureState = TRUE;
4203 SetCapture(es->hwndSelf);
4204 EDIT_ConfinePoint(es, &x, &y);
4205 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4206 EDIT_EM_SetSel(es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
4207 EDIT_EM_ScrollCaret(es);
4208 es->region_posx = es->region_posy = 0;
4209 SetTimer(es->hwndSelf, 0, 100, NULL);
4210 return 0;
4214 /*********************************************************************
4216 * WM_LBUTTONUP
4219 static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es)
4221 if (es->bCaptureState && GetCapture() == es->hwndSelf) {
4222 KillTimer(es->hwndSelf, 0);
4223 ReleaseCapture();
4225 es->bCaptureState = FALSE;
4226 return 0;
4230 /*********************************************************************
4232 * WM_MBUTTONDOWN
4235 static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es)
4237 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
4238 return 0;
4242 /*********************************************************************
4244 * WM_MOUSEMOVE
4247 static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y)
4249 INT e;
4250 BOOL after_wrap;
4251 INT prex, prey;
4253 if (GetCapture() != es->hwndSelf)
4254 return 0;
4257 * FIXME: gotta do some scrolling if outside client
4258 * area. Maybe reset the timer ?
4260 prex = x; prey = y;
4261 EDIT_ConfinePoint(es, &x, &y);
4262 es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
4263 es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
4264 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4265 EDIT_EM_SetSel(es, es->selection_start, e, after_wrap);
4266 EDIT_SetCaretPos(es,es->selection_end,es->flags & EF_AFTER_WRAP);
4267 return 0;
4271 /*********************************************************************
4273 * WM_NCCREATE
4275 * See also EDIT_WM_StyleChanged
4277 static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode)
4279 EDITSTATE *es;
4280 UINT alloc_size;
4282 TRACE("Creating %s edit control, style = %08lx\n",
4283 unicode ? "Unicode" : "ANSI", lpcs->style);
4285 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
4286 return FALSE;
4287 SetWindowLongW( hwnd, 0, (LONG)es );
4290 * Note: since the EDITSTATE has not been fully initialized yet,
4291 * we can't use any API calls that may send
4292 * WM_XXX messages before WM_NCCREATE is completed.
4295 es->is_unicode = unicode;
4296 es->style = lpcs->style;
4298 es->bEnableState = !(es->style & WS_DISABLED);
4300 es->hwndSelf = hwnd;
4301 /* Save parent, which will be notified by EN_* messages */
4302 es->hwndParent = lpcs->hwndParent;
4304 if (es->style & ES_COMBO)
4305 es->hwndListBox = GetDlgItem(es->hwndParent, ID_CB_LISTBOX);
4307 /* Number overrides lowercase overrides uppercase (at least it
4308 * does in Win95). However I'll bet that ES_NUMBER would be
4309 * invalid under Win 3.1.
4311 if (es->style & ES_NUMBER) {
4312 ; /* do not override the ES_NUMBER */
4313 } else if (es->style & ES_LOWERCASE) {
4314 es->style &= ~ES_UPPERCASE;
4316 if (es->style & ES_MULTILINE) {
4317 es->buffer_limit = BUFLIMIT_MULTI;
4318 if (es->style & WS_VSCROLL)
4319 es->style |= ES_AUTOVSCROLL;
4320 if (es->style & WS_HSCROLL)
4321 es->style |= ES_AUTOHSCROLL;
4322 es->style &= ~ES_PASSWORD;
4323 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
4324 /* Confirmed - RIGHT overrides CENTER */
4325 if (es->style & ES_RIGHT)
4326 es->style &= ~ES_CENTER;
4327 es->style &= ~WS_HSCROLL;
4328 es->style &= ~ES_AUTOHSCROLL;
4331 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4332 es->style |= ES_AUTOVSCROLL;
4333 } else {
4334 es->buffer_limit = BUFLIMIT_SINGLE;
4335 if (WIN31_LOOK == TWEAK_WineLook ||
4336 WIN95_LOOK == TWEAK_WineLook) {
4337 es->style &= ~ES_CENTER;
4338 es->style &= ~ES_RIGHT;
4339 } else {
4340 if (es->style & ES_RIGHT)
4341 es->style &= ~ES_CENTER;
4343 es->style &= ~WS_HSCROLL;
4344 es->style &= ~WS_VSCROLL;
4345 es->style &= ~ES_AUTOVSCROLL;
4346 es->style &= ~ES_WANTRETURN;
4347 if (es->style & ES_PASSWORD)
4348 es->password_char = '*';
4350 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4351 es->style |= ES_AUTOHSCROLL;
4354 alloc_size = ROUND_TO_GROW((es->buffer_size + 1) * sizeof(WCHAR));
4355 if(!(es->hloc32W = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
4356 return FALSE;
4357 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
4359 if (!(es->undo_text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (es->buffer_size + 1) * sizeof(WCHAR))))
4360 return FALSE;
4361 es->undo_buffer_size = es->buffer_size;
4363 if (es->style & ES_MULTILINE)
4364 if (!(es->first_line_def = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
4365 return FALSE;
4366 es->line_count = 1;
4369 * In Win95 look and feel, the WS_BORDER style is replaced by the
4370 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4371 * control a non client area. Not always. This coordinates in some
4372 * way with the window creation code in dialog.c When making
4373 * modifications please ensure that the code still works for edit
4374 * controls created directly with style 0x50800000, exStyle 0 (
4375 * which should have a single pixel border)
4377 if (TWEAK_WineLook != WIN31_LOOK)
4379 es->style &= ~WS_BORDER;
4381 else
4383 if ((es->style & WS_BORDER) && !(es->style & WS_DLGFRAME))
4384 SetWindowLongW( hwnd, GWL_STYLE,
4385 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_BORDER );
4388 return TRUE;
4391 /*********************************************************************
4393 * WM_PAINT
4396 static void EDIT_WM_Paint(EDITSTATE *es, WPARAM wParam)
4398 PAINTSTRUCT ps;
4399 INT i;
4400 HDC dc;
4401 HFONT old_font = 0;
4402 RECT rc;
4403 RECT rcLine;
4404 RECT rcRgn;
4405 BOOL rev = es->bEnableState &&
4406 ((es->flags & EF_FOCUSED) ||
4407 (es->style & ES_NOHIDESEL));
4408 if (!wParam)
4409 dc = BeginPaint(es->hwndSelf, &ps);
4410 else
4411 dc = (HDC) wParam;
4412 if(es->style & WS_BORDER) {
4413 GetClientRect(es->hwndSelf, &rc);
4414 if(es->style & ES_MULTILINE) {
4415 if(es->style & WS_HSCROLL) rc.bottom++;
4416 if(es->style & WS_VSCROLL) rc.right++;
4418 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
4420 IntersectClipRect(dc, es->format_rect.left,
4421 es->format_rect.top,
4422 es->format_rect.right,
4423 es->format_rect.bottom);
4424 if (es->style & ES_MULTILINE) {
4425 GetClientRect(es->hwndSelf, &rc);
4426 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
4428 if (es->font)
4429 old_font = SelectObject(dc, es->font);
4430 EDIT_NotifyCtlColor(es, dc);
4432 if (!es->bEnableState)
4433 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
4434 GetClipBox(dc, &rcRgn);
4435 if (es->style & ES_MULTILINE) {
4436 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4437 for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
4438 EDIT_GetLineRect(es, i, 0, -1, &rcLine);
4439 if (IntersectRect(&rc, &rcRgn, &rcLine))
4440 EDIT_PaintLine(es, dc, i, rev);
4442 } else {
4443 EDIT_GetLineRect(es, 0, 0, -1, &rcLine);
4444 if (IntersectRect(&rc, &rcRgn, &rcLine))
4445 EDIT_PaintLine(es, dc, 0, rev);
4447 if (es->font)
4448 SelectObject(dc, old_font);
4450 if (!wParam)
4451 EndPaint(es->hwndSelf, &ps);
4455 /*********************************************************************
4457 * WM_PASTE
4460 static void EDIT_WM_Paste(EDITSTATE *es)
4462 HGLOBAL hsrc;
4463 LPWSTR src;
4465 /* Protect read-only edit control from modification */
4466 if(es->style & ES_READONLY)
4467 return;
4469 OpenClipboard(es->hwndSelf);
4470 if ((hsrc = GetClipboardData(CF_UNICODETEXT))) {
4471 src = (LPWSTR)GlobalLock(hsrc);
4472 EDIT_EM_ReplaceSel(es, TRUE, src, TRUE);
4473 GlobalUnlock(hsrc);
4475 CloseClipboard();
4479 /*********************************************************************
4481 * WM_SETFOCUS
4484 static void EDIT_WM_SetFocus(EDITSTATE *es)
4486 es->flags |= EF_FOCUSED;
4487 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4488 EDIT_SetCaretPos(es, es->selection_end,
4489 es->flags & EF_AFTER_WRAP);
4490 if(!(es->style & ES_NOHIDESEL))
4491 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4492 ShowCaret(es->hwndSelf);
4493 EDIT_NOTIFY_PARENT(es, EN_SETFOCUS, "EN_SETFOCUS");
4497 /*********************************************************************
4499 * WM_SETFONT
4501 * With Win95 look the margins are set to default font value unless
4502 * the system font (font == 0) is being set, in which case they are left
4503 * unchanged.
4506 static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
4508 TEXTMETRICW tm;
4509 HDC dc;
4510 HFONT old_font = 0;
4511 RECT r;
4513 es->font = font;
4514 dc = GetDC(es->hwndSelf);
4515 if (font)
4516 old_font = SelectObject(dc, font);
4517 GetTextMetricsW(dc, &tm);
4518 es->line_height = tm.tmHeight;
4519 es->char_width = tm.tmAveCharWidth;
4520 if (font)
4521 SelectObject(dc, old_font);
4522 ReleaseDC(es->hwndSelf, dc);
4523 if (font && (TWEAK_WineLook > WIN31_LOOK))
4524 EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
4525 EC_USEFONTINFO, EC_USEFONTINFO);
4527 /* Force the recalculation of the format rect for each font change */
4528 GetClientRect(es->hwndSelf, &r);
4529 EDIT_SetRectNP(es, &r);
4531 if (es->style & ES_MULTILINE)
4532 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, (HRGN)0);
4533 else
4534 EDIT_CalcLineWidth_SL(es);
4536 if (redraw)
4537 EDIT_UpdateText(es, NULL, TRUE);
4538 if (es->flags & EF_FOCUSED) {
4539 DestroyCaret();
4540 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4541 EDIT_SetCaretPos(es, es->selection_end,
4542 es->flags & EF_AFTER_WRAP);
4543 ShowCaret(es->hwndSelf);
4548 /*********************************************************************
4550 * WM_SETTEXT
4552 * NOTES
4553 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4554 * The modified flag is reset. No notifications are sent.
4556 * For single-line controls, reception of WM_SETTEXT triggers:
4557 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4560 static void EDIT_WM_SetText(EDITSTATE *es, LPARAM lParam, BOOL unicode)
4562 LPWSTR text = NULL;
4564 if(unicode)
4565 text = (LPWSTR)lParam;
4566 else if (lParam)
4568 LPCSTR textA = (LPCSTR)lParam;
4569 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
4570 if((text = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
4571 MultiByteToWideChar(CP_ACP, 0, textA, -1, text, countW);
4574 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
4575 if (text) {
4576 TRACE("%s\n", debugstr_w(text));
4577 EDIT_EM_ReplaceSel(es, FALSE, text, FALSE);
4578 if(!unicode)
4579 HeapFree(GetProcessHeap(), 0, text);
4580 } else {
4581 static const WCHAR empty_stringW[] = {0};
4582 TRACE("<NULL>\n");
4583 EDIT_EM_ReplaceSel(es, FALSE, empty_stringW, FALSE);
4585 es->x_offset = 0;
4586 es->flags &= ~EF_MODIFIED;
4587 EDIT_EM_SetSel(es, 0, 0, FALSE);
4588 /* Send the notification after the selection start and end have been set
4589 * edit control doesn't send notification on WM_SETTEXT
4590 * if it is multiline, or it is part of combobox
4592 if( !((es->style & ES_MULTILINE) || es->hwndListBox))
4594 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
4595 EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4597 EDIT_EM_ScrollCaret(es);
4601 /*********************************************************************
4603 * WM_SIZE
4606 static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height)
4608 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
4609 RECT rc;
4610 TRACE("width = %d, height = %d\n", width, height);
4611 SetRect(&rc, 0, 0, width, height);
4612 EDIT_SetRectNP(es, &rc);
4613 EDIT_UpdateText(es, NULL, TRUE);
4618 /*********************************************************************
4620 * WM_STYLECHANGED
4622 * This message is sent by SetWindowLong on having changed either the Style
4623 * or the extended style.
4625 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4627 * See also EDIT_WM_NCCreate
4629 * It appears that the Windows version of the edit control allows the style
4630 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4631 * style variable which will generally be different. In this function we
4632 * update the internal style based on what changed in the externally visible
4633 * style.
4635 * Much of this content as based upon the MSDN, especially:
4636 * Platform SDK Documentation -> User Interface Services ->
4637 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4638 * Edit Control Styles
4640 static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLESTRUCT *style)
4642 if (GWL_STYLE == which) {
4643 DWORD style_change_mask;
4644 DWORD new_style;
4645 /* Only a subset of changes can be applied after the control
4646 * has been created.
4648 style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
4649 ES_NUMBER;
4650 if (es->style & ES_MULTILINE)
4651 style_change_mask |= ES_WANTRETURN;
4653 new_style = style->styleNew & style_change_mask;
4655 /* Number overrides lowercase overrides uppercase (at least it
4656 * does in Win95). However I'll bet that ES_NUMBER would be
4657 * invalid under Win 3.1.
4659 if (new_style & ES_NUMBER) {
4660 ; /* do not override the ES_NUMBER */
4661 } else if (new_style & ES_LOWERCASE) {
4662 new_style &= ~ES_UPPERCASE;
4665 es->style = (es->style & ~style_change_mask) | new_style;
4666 } else if (GWL_EXSTYLE == which) {
4667 ; /* FIXME - what is needed here */
4668 } else {
4669 WARN ("Invalid style change %d\n",which);
4672 return 0;
4675 /*********************************************************************
4677 * WM_SYSKEYDOWN
4680 static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data)
4682 if ((key == VK_BACK) && (key_data & 0x2000)) {
4683 if (EDIT_EM_CanUndo(es))
4684 EDIT_EM_Undo(es);
4685 return 0;
4686 } else if (key == VK_UP || key == VK_DOWN) {
4687 if (EDIT_CheckCombo(es, WM_SYSKEYDOWN, key))
4688 return 0;
4690 return DefWindowProcW(es->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
4694 /*********************************************************************
4696 * WM_TIMER
4699 static void EDIT_WM_Timer(EDITSTATE *es)
4701 if (es->region_posx < 0) {
4702 EDIT_MoveBackward(es, TRUE);
4703 } else if (es->region_posx > 0) {
4704 EDIT_MoveForward(es, TRUE);
4707 * FIXME: gotta do some vertical scrolling here, like
4708 * EDIT_EM_LineScroll(hwnd, 0, 1);
4712 /*********************************************************************
4714 * WM_VSCROLL
4717 static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos)
4719 INT dy;
4721 if (!(es->style & ES_MULTILINE))
4722 return 0;
4724 if (!(es->style & ES_AUTOVSCROLL))
4725 return 0;
4727 dy = 0;
4728 switch (action) {
4729 case SB_LINEUP:
4730 case SB_LINEDOWN:
4731 case SB_PAGEUP:
4732 case SB_PAGEDOWN:
4733 TRACE("action %d\n", action);
4734 EDIT_EM_Scroll(es, action);
4735 return 0;
4736 case SB_TOP:
4737 TRACE("SB_TOP\n");
4738 dy = -es->y_offset;
4739 break;
4740 case SB_BOTTOM:
4741 TRACE("SB_BOTTOM\n");
4742 dy = es->line_count - 1 - es->y_offset;
4743 break;
4744 case SB_THUMBTRACK:
4745 TRACE("SB_THUMBTRACK %d\n", pos);
4746 es->flags |= EF_VSCROLL_TRACK;
4747 if(es->style & WS_VSCROLL)
4748 dy = pos - es->y_offset;
4749 else
4751 /* Assume default scroll range 0-100 */
4752 INT vlc, new_y;
4753 /* Sanity check */
4754 if(pos < 0 || pos > 100) return 0;
4755 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4756 new_y = pos * (es->line_count - vlc) / 100;
4757 dy = es->line_count ? (new_y - es->y_offset) : 0;
4758 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4759 es->line_count, es->y_offset, pos, dy);
4761 break;
4762 case SB_THUMBPOSITION:
4763 TRACE("SB_THUMBPOSITION %d\n", pos);
4764 es->flags &= ~EF_VSCROLL_TRACK;
4765 if(es->style & WS_VSCROLL)
4766 dy = pos - es->y_offset;
4767 else
4769 /* Assume default scroll range 0-100 */
4770 INT vlc, new_y;
4771 /* Sanity check */
4772 if(pos < 0 || pos > 100) return 0;
4773 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4774 new_y = pos * (es->line_count - vlc) / 100;
4775 dy = es->line_count ? (new_y - es->y_offset) : 0;
4776 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4777 es->line_count, es->y_offset, pos, dy);
4779 if (!dy)
4781 /* force scroll info update */
4782 EDIT_UpdateScrollInfo(es);
4783 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
4785 break;
4786 case SB_ENDSCROLL:
4787 TRACE("SB_ENDSCROLL\n");
4788 break;
4790 * FIXME : the next two are undocumented !
4791 * Are we doing the right thing ?
4792 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4793 * although it's also a regular control message.
4795 case EM_GETTHUMB: /* this one is used by NT notepad */
4796 case EM_GETTHUMB16:
4798 LRESULT ret;
4799 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_VSCROLL)
4800 ret = GetScrollPos(es->hwndSelf, SB_VERT);
4801 else
4803 /* Assume default scroll range 0-100 */
4804 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4805 ret = es->line_count ? es->y_offset * 100 / (es->line_count - vlc) : 0;
4807 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4808 return ret;
4810 case EM_LINESCROLL16:
4811 TRACE("EM_LINESCROLL16 %d\n", pos);
4812 dy = pos;
4813 break;
4815 default:
4816 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4817 action, action);
4818 return 0;
4820 if (dy)
4821 EDIT_EM_LineScroll(es, 0, dy);
4822 return 0;
4825 /*********************************************************************
4827 * EDIT_UpdateText
4830 static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase)
4832 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4833 InvalidateRgn(es->hwndSelf, hrgn, bErase);
4837 /*********************************************************************
4839 * EDIT_UpdateText
4842 static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase)
4844 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4845 InvalidateRect(es->hwndSelf, rc, bErase);