4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
11 * please read EDIT.TODO (and update it when you change things)
22 #include "wine/winbase16.h"
23 #include "wine/winuser16.h"
24 #include "wine/unicode.h"
28 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(edit
);
31 DECLARE_DEBUG_CHANNEL(combo
);
32 DECLARE_DEBUG_CHANNEL(relay
);
34 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
35 FIXME: BTW, new specs say 65535 (do you dare ???) */
36 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
37 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
38 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
39 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
42 * extra flags for EDITSTATE.flags field
44 #define EF_MODIFIED 0x0001 /* text has been modified */
45 #define EF_FOCUSED 0x0002 /* we have input focus */
46 #define EF_UPDATE 0x0004 /* notify parent of changed state */
47 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
48 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
49 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
50 wrapped line, instead of in front of the next character */
51 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
55 END_0
= 0, /* line ends with terminating '\0' character */
56 END_WRAP
, /* line is wrapped */
57 END_HARD
, /* line ends with a hard return '\r\n' */
58 END_SOFT
/* line ends with a soft return '\r\r\n' */
61 typedef struct tagLINEDEF
{
62 INT length
; /* bruto length of a line in bytes */
63 INT net_length
; /* netto length of a line in visible characters */
65 INT width
; /* width of the line in pixels */
66 INT index
; /* line index into the buffer */
67 struct tagLINEDEF
*next
;
72 BOOL is_unicode
; /* how the control was created */
73 LPWSTR text
; /* the actual contents of the control */
74 UINT buffer_size
; /* the size of the buffer in characters */
75 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
76 HFONT font
; /* NULL means standard system font */
77 INT x_offset
; /* scroll offset for multi lines this is in pixels
78 for single lines it's in characters */
79 INT line_height
; /* height of a screen line in pixels */
80 INT char_width
; /* average character width in pixels */
81 DWORD style
; /* sane version of wnd->dwStyle */
82 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
83 INT undo_insert_count
; /* number of characters inserted in sequence */
84 UINT undo_position
; /* character index of the insertion and deletion */
85 LPWSTR undo_text
; /* deleted text */
86 UINT undo_buffer_size
; /* size of the deleted text buffer */
87 INT selection_start
; /* == selection_end if no selection */
88 INT selection_end
; /* == current caret position */
89 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
90 INT left_margin
; /* in pixels */
91 INT right_margin
; /* in pixels */
93 INT text_width
; /* width of the widest line in pixels for multi line controls
94 and just line width for single line controls */
95 INT region_posx
; /* Position of cursor relative to region: */
96 INT region_posy
; /* -1: to left, 0: within, 1: to right */
97 EDITWORDBREAKPROC16 word_break_proc16
;
98 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
99 INT line_count
; /* number of lines */
100 INT y_offset
; /* scroll offset in number of lines */
101 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
102 BOOL bEnableState
; /* flag keeping the enable state */
103 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
104 Even if parent will change, EN_* messages
105 should be sent to the first parent. */
106 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
108 * only for multi line controls
110 INT lock_count
; /* amount of re-entries in the EditWndProc */
113 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
114 HLOCAL hloc32W
; /* our unicode local memory block */
115 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
117 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
122 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
123 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
125 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
126 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
128 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
129 do {TRACE("notification " str " sent to hwnd=%08x\n", \
130 (UINT)(hwnd));} while(0)
132 /* used for disabled or read-only edit control */
133 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
134 (SendMessageW((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
135 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
136 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
137 (SendMessageW((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
138 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
139 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
141 { /* Notify parent which has created this edit control */ \
142 DPRINTF_EDIT_NOTIFY((es)->hwndParent, str); \
143 SendMessageW((es)->hwndParent, WM_COMMAND, \
144 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
145 (LPARAM)(wnd)->hwndSelf); \
147 #define DPRINTF_EDIT_MSG16(str) \
149 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
150 (UINT)wnd->hwndSelf, (UINT)wParam, (UINT)lParam)
151 #define DPRINTF_EDIT_MSG32(str) \
153 "32 bit %c : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
154 unicode ? 'W' : 'A', \
155 (UINT)wnd->hwndSelf, (UINT)wParam, (UINT)lParam)
157 /*********************************************************************
164 * These functions have trivial implementations
165 * We still like to call them internally
166 * "static inline" makes them more like macro's
168 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
169 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
170 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
171 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
174 * Helper functions only valid for one type of control
176 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
177 static void EDIT_CalcLineWidth_SL(WND
*wnd
, EDITSTATE
*es
);
178 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
179 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
180 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
181 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
182 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
184 * Helper functions valid for both single line _and_ multi line controls
186 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
187 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
188 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
189 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
190 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
191 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
192 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, UINT size
);
193 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
194 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
195 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
196 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
197 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
198 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
199 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
200 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
201 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
202 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
203 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
204 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
205 static void EDIT_UpdateScrollInfo(WND
*wnd
, EDITSTATE
*es
);
206 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
208 * EM_XXX message handlers
210 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
211 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
212 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
213 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
214 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
);
215 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
);
216 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
217 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
218 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
219 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
220 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
221 static BOOL
EDIT_EM_LineScroll_internal(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
222 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
223 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
);
224 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
225 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
226 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
227 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
228 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
229 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
230 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, WCHAR c
);
231 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
232 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
233 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
234 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
);
235 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
236 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
238 * WM_XXX message handlers
240 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, WCHAR c
);
241 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
242 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
243 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
244 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCWSTR name
);
245 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
246 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
247 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
248 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
);
249 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
);
250 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
);
251 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
);
252 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
253 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
);
254 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
);
255 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
256 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, DWORD style
, HWND hwndParent
, BOOL unicode
);
257 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
258 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
259 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
);
260 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
261 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
262 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
263 static LRESULT
EDIT_WM_StyleChanged (WND
*wnd
, EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
264 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
265 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
);
266 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
);
267 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
);
268 static void EDIT_UpdateTextRegion(WND
*wnd
, HRGN hrgn
, BOOL bErase
);
270 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
271 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
273 /*********************************************************************
274 * edit class descriptor
276 const struct builtin_class_descr EDIT_builtin_class
=
279 CS_GLOBALCLASS
| CS_DBLCLKS
/*| CS_PARENTDC*/, /* style */
280 EditWndProcA
, /* procA */
281 EditWndProcW
, /* procW */
282 sizeof(EDITSTATE
*), /* extra */
283 IDC_IBEAMA
, /* cursor */
288 /*********************************************************************
293 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
295 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
299 /*********************************************************************
304 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
306 es
->undo_insert_count
= 0;
307 *es
->undo_text
= '\0';
311 /*********************************************************************
316 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
318 static const WCHAR empty_stringW
[] = {0};
320 /* Protect read-only edit control from modification */
321 if(es
->style
& ES_READONLY
)
324 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, empty_stringW
, TRUE
);
328 /*********************************************************************
333 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
335 EDIT_WM_Copy(wnd
, es
);
336 EDIT_WM_Clear(wnd
, es
);
340 /**********************************************************************
343 * Returns the window version in case Wine emulates a later version
344 * of windows then the application expects.
346 * In a number of cases when windows runs an application that was
347 * designed for an earlier windows version, windows reverts
348 * to "old" behaviour of that earlier version.
350 * An example is a disabled edit control that needs to be painted.
351 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
352 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
353 * applications with an expected version 0f 4.0 or higher.
356 static DWORD
get_app_version(void)
358 static DWORD version
;
361 DWORD dwEmulatedVersion
;
363 DWORD dwProcVersion
= GetProcessVersion(0);
365 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
366 GetVersionExW( &info
);
367 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
368 /* fixme: this may not be 100% correct; see discussion on the
369 * wine developer list in Nov 1999 */
370 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
376 /*********************************************************************
380 * The messages are in the order of the actual integer values
381 * (which can be found in include/windows.h)
382 * Wherever possible the 16 bit versions are converted to
383 * the 32 bit ones, so that we can 'fall through' to the
384 * helper functions. These are mostly 32 bit (with a few
385 * exceptions, clearly indicated by a '16' extension to their
389 static LRESULT WINAPI
EditWndProc_locked( WND
*wnd
, UINT msg
,
390 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
392 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
397 DPRINTF_EDIT_MSG32("WM_DESTROY");
398 EDIT_WM_Destroy(wnd
, es
);
403 DPRINTF_EDIT_MSG32("WM_NCCREATE");
406 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
407 result
= EDIT_WM_NCCreate(wnd
, cs
->style
, cs
->hwndParent
, TRUE
);
411 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
412 result
= EDIT_WM_NCCreate(wnd
, cs
->style
, cs
->hwndParent
, FALSE
);
420 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
422 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
427 EDIT_LockBuffer(wnd
, es
);
430 DPRINTF_EDIT_MSG16("EM_GETSEL");
435 DPRINTF_EDIT_MSG32("EM_GETSEL");
436 result
= EDIT_EM_GetSel(es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
440 DPRINTF_EDIT_MSG16("EM_SETSEL");
441 if (SLOWORD(lParam
) == -1)
442 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
444 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
446 EDIT_EM_ScrollCaret(wnd
, es
);
450 DPRINTF_EDIT_MSG32("EM_SETSEL");
451 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
452 EDIT_EM_ScrollCaret(wnd
, es
);
457 DPRINTF_EDIT_MSG16("EM_GETRECT");
459 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
462 DPRINTF_EDIT_MSG32("EM_GETRECT");
464 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
468 DPRINTF_EDIT_MSG16("EM_SETRECT");
469 if ((es
->style
& ES_MULTILINE
) && lParam
) {
471 CONV_RECT16TO32(MapSL(lParam
), &rc
);
472 EDIT_SetRectNP(wnd
, es
, &rc
);
473 EDIT_UpdateText(wnd
, NULL
, TRUE
);
477 DPRINTF_EDIT_MSG32("EM_SETRECT");
478 if ((es
->style
& ES_MULTILINE
) && lParam
) {
479 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
480 EDIT_UpdateText(wnd
, NULL
, TRUE
);
485 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
486 if ((es
->style
& ES_MULTILINE
) && lParam
) {
488 CONV_RECT16TO32(MapSL(lParam
), &rc
);
489 EDIT_SetRectNP(wnd
, es
, &rc
);
493 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
494 if ((es
->style
& ES_MULTILINE
) && lParam
)
495 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
499 DPRINTF_EDIT_MSG16("EM_SCROLL");
502 DPRINTF_EDIT_MSG32("EM_SCROLL");
503 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
506 case EM_LINESCROLL16
:
507 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
508 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
509 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
512 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
513 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
516 case EM_SCROLLCARET16
:
517 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
520 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
521 EDIT_EM_ScrollCaret(wnd
, es
);
526 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
529 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
530 result
= ((es
->flags
& EF_MODIFIED
) != 0);
534 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
537 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
539 es
->flags
|= EF_MODIFIED
;
541 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
544 case EM_GETLINECOUNT16
:
545 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
547 case EM_GETLINECOUNT
:
548 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
549 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
553 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
554 if ((INT16
)wParam
== -1)
558 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
559 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
563 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
564 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
567 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
568 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
572 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
573 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
576 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
577 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
581 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
584 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
585 result
= EDIT_EM_GetThumb(wnd
, es
);
588 /* messages 0x00bf and 0x00c0 missing from specs */
591 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
594 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
596 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
598 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
602 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
605 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
607 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
609 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
612 case EM_LINELENGTH16
:
613 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
616 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
617 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
620 case EM_REPLACESEL16
:
621 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
622 lParam
= (LPARAM
)MapSL(lParam
);
623 unicode
= FALSE
; /* 16-bit message is always ascii */
628 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
631 textW
= (LPWSTR
)lParam
;
634 LPSTR textA
= (LPSTR
)lParam
;
635 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
636 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
637 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
640 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, textW
, TRUE
);
644 HeapFree(GetProcessHeap(), 0, textW
);
647 /* message 0x00c3 missing from specs */
650 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
653 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
655 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
657 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
661 DPRINTF_EDIT_MSG16("EM_GETLINE");
662 lParam
= (LPARAM
)MapSL(lParam
);
663 unicode
= FALSE
; /* 16-bit message is always ascii */
666 DPRINTF_EDIT_MSG32("EM_GETLINE");
667 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, lParam
, unicode
);
671 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
673 case EM_SETLIMITTEXT
:
674 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
675 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
679 DPRINTF_EDIT_MSG16("EM_CANUNDO");
682 DPRINTF_EDIT_MSG32("EM_CANUNDO");
683 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
687 DPRINTF_EDIT_MSG16("EM_UNDO");
692 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
693 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
697 DPRINTF_EDIT_MSG16("EM_FMTLINES");
700 DPRINTF_EDIT_MSG32("EM_FMTLINES");
701 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
704 case EM_LINEFROMCHAR16
:
705 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
707 case EM_LINEFROMCHAR
:
708 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
709 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
712 /* message 0x00ca missing from specs */
715 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
718 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
720 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
722 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
725 case EM_SETTABSTOPS16
:
726 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
727 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
730 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
731 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
734 case EM_SETPASSWORDCHAR16
:
735 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
736 unicode
= FALSE
; /* 16-bit message is always ascii */
738 case EM_SETPASSWORDCHAR
:
741 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
744 charW
= (WCHAR
)wParam
;
748 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
751 EDIT_EM_SetPasswordChar(wnd
, es
, charW
);
755 case EM_EMPTYUNDOBUFFER16
:
756 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
758 case EM_EMPTYUNDOBUFFER
:
759 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
760 EDIT_EM_EmptyUndoBuffer(es
);
763 case EM_GETFIRSTVISIBLELINE16
:
764 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
765 result
= es
->y_offset
;
767 case EM_GETFIRSTVISIBLELINE
:
768 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
769 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
772 case EM_SETREADONLY16
:
773 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
776 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
778 wnd
->dwStyle
|= ES_READONLY
;
779 es
->style
|= ES_READONLY
;
781 wnd
->dwStyle
&= ~ES_READONLY
;
782 es
->style
&= ~ES_READONLY
;
787 case EM_SETWORDBREAKPROC16
:
788 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
789 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
791 case EM_SETWORDBREAKPROC
:
792 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
793 EDIT_EM_SetWordBreakProc(wnd
, es
, lParam
);
796 case EM_GETWORDBREAKPROC16
:
797 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
798 result
= (LRESULT
)es
->word_break_proc16
;
800 case EM_GETWORDBREAKPROC
:
801 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
802 result
= (LRESULT
)es
->word_break_proc
;
805 case EM_GETPASSWORDCHAR16
:
806 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
807 unicode
= FALSE
; /* 16-bit message is always ascii */
809 case EM_GETPASSWORDCHAR
:
811 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
814 result
= es
->password_char
;
817 WCHAR charW
= es
->password_char
;
819 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
825 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
828 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
829 EDIT_EM_SetMargins(es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
833 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
834 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
837 case EM_GETLIMITTEXT
:
838 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
839 result
= es
->buffer_limit
;
843 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
844 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
848 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
849 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
852 /* End of the EM_ messages which were in numerical order; what order
853 * are these in? vaguely alphabetical?
857 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
858 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
860 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
862 int vk
= (int)((LPMSG
)lParam
)->wParam
;
864 if ((wnd
->dwStyle
& ES_WANTRETURN
) && vk
== VK_RETURN
)
866 result
|= DLGC_WANTMESSAGE
;
868 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
870 if (SendMessageW(wnd
->parent
->hwndSelf
, CB_GETDROPPEDSTATE
, 0, 0))
871 result
|= DLGC_WANTMESSAGE
;
879 DPRINTF_EDIT_MSG32("WM_CHAR");
886 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
889 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
891 if (SendMessageW(wnd
->parent
->hwndSelf
, CB_GETDROPPEDSTATE
, 0, 0))
892 SendMessageW(wnd
->parent
->hwndSelf
, WM_KEYDOWN
, charW
, 0);
895 EDIT_WM_Char(wnd
, es
, charW
);
900 DPRINTF_EDIT_MSG32("WM_CLEAR");
901 EDIT_WM_Clear(wnd
, es
);
905 DPRINTF_EDIT_MSG32("WM_COMMAND");
906 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
910 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
911 EDIT_WM_ContextMenu(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
915 DPRINTF_EDIT_MSG32("WM_COPY");
916 EDIT_WM_Copy(wnd
, es
);
920 DPRINTF_EDIT_MSG32("WM_CREATE");
922 result
= EDIT_WM_Create(wnd
, es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
925 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
929 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
930 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
931 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
933 result
= EDIT_WM_Create(wnd
, es
, nameW
);
935 HeapFree(GetProcessHeap(), 0, nameW
);
940 DPRINTF_EDIT_MSG32("WM_CUT");
941 EDIT_WM_Cut(wnd
, es
);
945 DPRINTF_EDIT_MSG32("WM_ENABLE");
946 es
->bEnableState
= (BOOL
) wParam
;
947 EDIT_UpdateText(wnd
, NULL
, TRUE
);
951 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
952 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
956 DPRINTF_EDIT_MSG32("WM_GETFONT");
957 result
= (LRESULT
)es
->font
;
961 DPRINTF_EDIT_MSG32("WM_GETTEXT");
962 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
965 case WM_GETTEXTLENGTH
:
966 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
967 result
= strlenW(es
->text
);
971 DPRINTF_EDIT_MSG32("WM_HSCROLL");
972 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
976 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
977 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
);
981 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
982 result
= EDIT_WM_KillFocus(wnd
, es
);
985 case WM_LBUTTONDBLCLK
:
986 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
987 result
= EDIT_WM_LButtonDblClk(wnd
, es
);
991 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
992 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
996 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
997 result
= EDIT_WM_LButtonUp(wnd
->hwndSelf
, es
);
1000 case WM_MBUTTONDOWN
:
1001 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
1002 result
= EDIT_WM_MButtonDown(wnd
);
1005 case WM_MOUSEACTIVATE
:
1007 * FIXME: maybe DefWindowProc() screws up, but it seems that
1008 * modeless dialog boxes need this. If we don't do this, the focus
1009 * will _not_ be set by DefWindowProc() for edit controls in a
1010 * modeless dialog box ???
1012 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
1013 SetFocus(wnd
->hwndSelf
);
1014 result
= MA_ACTIVATE
;
1019 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
1021 result
= EDIT_WM_MouseMove(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
1025 DPRINTF_EDIT_MSG32("WM_PAINT");
1026 EDIT_WM_Paint(wnd
, es
, wParam
);
1030 DPRINTF_EDIT_MSG32("WM_PASTE");
1031 EDIT_WM_Paste(wnd
, es
);
1035 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
1036 EDIT_WM_SetFocus(wnd
, es
);
1040 DPRINTF_EDIT_MSG32("WM_SETFONT");
1041 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
1045 /* FIXME: actually set an internal flag and behave accordingly */
1049 DPRINTF_EDIT_MSG32("WM_SETTEXT");
1050 EDIT_WM_SetText(wnd
, es
, lParam
, unicode
);
1055 DPRINTF_EDIT_MSG32("WM_SIZE");
1056 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1059 case WM_STYLECHANGED
:
1060 DPRINTF_EDIT_MSG32("WM_STYLECHANGED");
1061 result
= EDIT_WM_StyleChanged (wnd
, es
, wParam
, (const STYLESTRUCT
*)lParam
);
1064 case WM_STYLECHANGING
:
1065 DPRINTF_EDIT_MSG32("WM_STYLECHANGING");
1066 result
= 0; /* See EDIT_WM_StyleChanged */
1070 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
1071 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
1075 DPRINTF_EDIT_MSG32("WM_TIMER");
1076 EDIT_WM_Timer(wnd
, es
);
1080 DPRINTF_EDIT_MSG32("WM_VSCROLL");
1081 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
1086 int gcWheelDelta
= 0;
1087 UINT pulScrollLines
= 3;
1088 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1090 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1092 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1094 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1097 gcWheelDelta
-= SHIWORD(wParam
);
1098 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1100 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1101 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1102 result
= EDIT_EM_LineScroll(wnd
, es
, 0, cLineScroll
);
1108 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1110 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1113 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
1118 /*********************************************************************
1120 * EditWndProcW (USER32.@)
1122 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1125 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1127 res
= EditWndProc_locked(wndPtr
, uMsg
, wParam
, lParam
, TRUE
);
1129 WIN_ReleaseWndPtr(wndPtr
);
1133 /*********************************************************************
1135 * EditWndProc (USER32.@)
1137 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1140 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1142 res
= EditWndProc_locked(wndPtr
, uMsg
, wParam
, lParam
, FALSE
);
1144 WIN_ReleaseWndPtr(wndPtr
);
1148 /*********************************************************************
1150 * EDIT_BuildLineDefs_ML
1152 * Build linked list of text lines.
1153 * Lines can end with '\0' (last line), a character (if it is wrapped),
1154 * a soft return '\r\r\n' or a hard return '\r\n'
1157 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1161 LPWSTR current_position
, cp
;
1163 LINEDEF
*current_line
;
1164 LINEDEF
*previous_line
;
1165 LINEDEF
*start_line
;
1166 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1167 INT line_count
= es
->line_count
;
1168 INT orig_net_length
;
1171 if (istart
== iend
&& delta
== 0)
1174 dc
= GetDC(wnd
->hwndSelf
);
1176 old_font
= SelectObject(dc
, es
->font
);
1178 previous_line
= NULL
;
1179 current_line
= es
->first_line_def
;
1181 /* Find starting line. istart must lie inside an existing line or
1182 * at the end of buffer */
1184 if (istart
< current_line
->index
+ current_line
->length
||
1185 current_line
->ending
== END_0
)
1188 previous_line
= current_line
;
1189 current_line
= current_line
->next
;
1191 } while (current_line
);
1193 if (!current_line
) /* Error occurred start is not inside previous buffer */
1195 FIXME(" modification occurred outside buffer\n");
1199 /* Remember start of modifications in order to calculate update region */
1200 nstart_line
= line_index
;
1201 nstart_index
= current_line
->index
;
1203 /* We must start to reformat from the previous line since the modifications
1204 * may have caused the line to wrap upwards. */
1205 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1208 current_line
= previous_line
;
1210 start_line
= current_line
;
1212 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1213 current_position
= es
->text
+ current_line
->index
;
1215 if (current_line
!= start_line
)
1217 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1219 /* The buffer has been expanded, create a new line and
1220 insert it into the link list */
1221 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1222 new_line
->next
= previous_line
->next
;
1223 previous_line
->next
= new_line
;
1224 current_line
= new_line
;
1227 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1229 /* The previous line merged with this line so we delete this extra entry */
1230 previous_line
->next
= current_line
->next
;
1231 HeapFree(GetProcessHeap(), 0, current_line
);
1232 current_line
= previous_line
->next
;
1236 else /* current_line->index + delta == current_position */
1238 if (current_position
- es
->text
> iend
)
1239 break; /* We reached end of line modifications */
1240 /* else recalulate this line */
1244 current_line
->index
= current_position
- es
->text
;
1245 orig_net_length
= current_line
->net_length
;
1247 /* Find end of line */
1248 cp
= current_position
;
1250 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1255 /* Mark type of line termination */
1257 current_line
->ending
= END_0
;
1258 current_line
->net_length
= strlenW(current_position
);
1259 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1260 current_line
->ending
= END_SOFT
;
1261 current_line
->net_length
= cp
- current_position
- 1;
1263 current_line
->ending
= END_HARD
;
1264 current_line
->net_length
= cp
- current_position
;
1267 /* Calculate line width */
1268 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1269 current_position
, current_line
->net_length
,
1270 es
->tabs_count
, es
->tabs
));
1272 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1273 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1278 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1279 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1280 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1281 current_position
, next
, es
->tabs_count
, es
->tabs
));
1282 } while (current_line
->width
<= fw
);
1283 if (!prev
) { /* Didn't find a line break so force a break */
1288 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1289 current_position
, next
, es
->tabs_count
, es
->tabs
));
1290 } while (current_line
->width
<= fw
);
1295 /* If the first line we are calculating, wrapped before istart, we must
1296 * adjust istart in order for this to be reflected in the update region. */
1297 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1298 istart
= current_line
->index
+ prev
;
1299 /* else if we are updating the previous line before the first line we
1300 * are re-caulculating and it expanded */
1301 else if (current_line
== start_line
&&
1302 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1304 /* Line expanded due to an upwards line wrap so we must partially include
1305 * previous line in update region */
1306 nstart_line
= line_index
;
1307 nstart_index
= current_line
->index
;
1308 istart
= current_line
->index
+ orig_net_length
;
1311 current_line
->net_length
= prev
;
1312 current_line
->ending
= END_WRAP
;
1313 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1314 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1318 /* Adjust length to include line termination */
1319 switch (current_line
->ending
) {
1321 current_line
->length
= current_line
->net_length
+ 3;
1324 current_line
->length
= current_line
->net_length
+ 2;
1328 current_line
->length
= current_line
->net_length
;
1331 es
->text_width
= max(es
->text_width
, current_line
->width
);
1332 current_position
+= current_line
->length
;
1333 previous_line
= current_line
;
1334 current_line
= current_line
->next
;
1336 } while (previous_line
->ending
!= END_0
);
1338 /* Finish adjusting line index's by delta or remove hanging lines */
1339 if (previous_line
->ending
== END_0
)
1341 LINEDEF
*pnext
= NULL
;
1343 previous_line
->next
= NULL
;
1344 while (current_line
)
1346 pnext
= current_line
->next
;
1347 HeapFree(GetProcessHeap(), 0, current_line
);
1348 current_line
= pnext
;
1354 while (current_line
)
1356 current_line
->index
+= delta
;
1357 current_line
= current_line
->next
;
1361 /* Calculate rest of modification rectangle */
1366 * We calculate two rectangles. One for the first line which may have
1367 * an indent with respect to the format rect. The other is a format-width
1368 * rectangle that spans the rest of the lines that changed or moved.
1370 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1371 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1372 rc
.bottom
= rc
.top
+ es
->line_height
;
1373 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1374 es
->text
+ nstart_index
, istart
- nstart_index
,
1375 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1376 rc
.right
= es
->format_rect
.right
;
1377 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1380 rc
.left
= es
->format_rect
.left
;
1381 rc
.right
= es
->format_rect
.right
;
1383 * If lines were added or removed we must re-paint the remainder of the
1384 * lines since the remaining lines were either shifted up or down.
1386 if (line_count
< es
->line_count
) /* We added lines */
1387 rc
.bottom
= es
->line_count
* es
->line_height
;
1388 else if (line_count
> es
->line_count
) /* We removed lines */
1389 rc
.bottom
= line_count
* es
->line_height
;
1391 rc
.bottom
= line_index
* es
->line_height
;
1392 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1393 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1394 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1395 DeleteObject(tmphrgn
);
1399 SelectObject(dc
, old_font
);
1401 ReleaseDC(wnd
->hwndSelf
, dc
);
1404 /*********************************************************************
1406 * EDIT_CalcLineWidth_SL
1409 static void EDIT_CalcLineWidth_SL(WND
*wnd
, EDITSTATE
*es
)
1411 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, strlenW(es
->text
), FALSE
));
1414 /*********************************************************************
1416 * EDIT_CallWordBreakProc
1418 * Call appropriate WordBreakProc (internal or external).
1420 * Note: The "start" argument should always be an index refering
1421 * to es->text. The actual wordbreak proc might be
1422 * 16 bit, so we can't always pass any 32 bit LPSTR.
1423 * Hence we assume that es->text is the buffer that holds
1424 * the string under examination (we can decide this for ourselves).
1427 /* ### start build ### */
1428 extern WORD CALLBACK
EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16
,SEGPTR
,WORD
,WORD
,WORD
);
1429 /* ### stop build ### */
1430 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1432 INT ret
, iWndsLocks
;
1434 /* To avoid any deadlocks, all the locks on the windows structures
1435 must be suspended before the control is passed to the application */
1436 iWndsLocks
= WIN_SuspendWndsLock();
1438 if (es
->word_break_proc16
) {
1443 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1444 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1445 segptr
= K32WOWGlobalLock16(hglob16
);
1446 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1447 ret
= (INT
)EDIT_CallTo16_word_lwww(es
->word_break_proc16
,
1448 segptr
, index
, countA
, action
);
1449 GlobalUnlock16(hglob16
);
1450 GlobalFree16(hglob16
);
1452 else if (es
->word_break_proc
)
1456 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1458 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1459 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1460 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1464 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1468 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1469 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1470 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1471 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1472 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1473 ret
= wbpA(textA
, index
, countA
, action
);
1474 HeapFree(GetProcessHeap(), 0, textA
);
1478 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1480 WIN_RestoreWndsLock(iWndsLocks
);
1485 /*********************************************************************
1489 * Beware: This is not the function called on EM_CHARFROMPOS
1490 * The position _can_ be outside the formatting / client
1492 * The return value is only the character index
1495 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1501 if (es
->style
& ES_MULTILINE
) {
1502 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1504 LINEDEF
*line_def
= es
->first_line_def
;
1506 while ((line
> 0) && line_def
->next
) {
1507 line_index
+= line_def
->length
;
1508 line_def
= line_def
->next
;
1511 x
+= es
->x_offset
- es
->format_rect
.left
;
1512 if (x
>= line_def
->width
) {
1514 *after_wrap
= (line_def
->ending
== END_WRAP
);
1515 return line_index
+ line_def
->net_length
;
1519 *after_wrap
= FALSE
;
1522 dc
= GetDC(wnd
->hwndSelf
);
1524 old_font
= SelectObject(dc
, es
->font
);
1525 low
= line_index
+ 1;
1526 high
= line_index
+ line_def
->net_length
+ 1;
1527 while (low
< high
- 1)
1529 INT mid
= (low
+ high
) / 2;
1530 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1536 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1537 (line_def
->ending
== END_WRAP
));
1542 *after_wrap
= FALSE
;
1543 x
-= es
->format_rect
.left
;
1545 return es
->x_offset
;
1546 text
= EDIT_GetPasswordPointer_SL(es
);
1547 dc
= GetDC(wnd
->hwndSelf
);
1549 old_font
= SelectObject(dc
, es
->font
);
1553 INT high
= es
->x_offset
;
1554 while (low
< high
- 1)
1556 INT mid
= (low
+ high
) / 2;
1557 GetTextExtentPoint32W( dc
, text
+ mid
,
1558 es
->x_offset
- mid
, &size
);
1559 if (size
.cx
> -x
) low
= mid
;
1566 INT low
= es
->x_offset
;
1567 INT high
= strlenW(es
->text
) + 1;
1568 while (low
< high
- 1)
1570 INT mid
= (low
+ high
) / 2;
1571 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1572 mid
- es
->x_offset
, &size
);
1573 if (size
.cx
> x
) high
= mid
;
1578 if (es
->style
& ES_PASSWORD
)
1579 HeapFree(GetProcessHeap(), 0, text
);
1582 SelectObject(dc
, old_font
);
1583 ReleaseDC(wnd
->hwndSelf
, dc
);
1588 /*********************************************************************
1592 * adjusts the point to be within the formatting rectangle
1593 * (so CharFromPos returns the nearest _visible_ character)
1596 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1598 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1599 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1603 /*********************************************************************
1607 * Calculates the bounding rectangle for a line from a starting
1608 * column to an ending column.
1611 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1613 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1615 if (es
->style
& ES_MULTILINE
)
1616 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1618 rc
->top
= es
->format_rect
.top
;
1619 rc
->bottom
= rc
->top
+ es
->line_height
;
1620 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1621 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1625 /*********************************************************************
1627 * EDIT_GetPasswordPointer_SL
1629 * note: caller should free the (optionally) allocated buffer
1632 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1634 if (es
->style
& ES_PASSWORD
) {
1635 INT len
= strlenW(es
->text
);
1636 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1638 while(len
) text
[--len
] = es
->password_char
;
1645 /*********************************************************************
1649 * This acts as a LOCAL_Lock(), but it locks only once. This way
1650 * you can call it whenever you like, without unlocking.
1653 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1656 ERR("no EDITSTATE ... please report\n");
1662 BOOL _16bit
= FALSE
;
1668 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1669 textA
= LocalLock(es
->hloc32A
);
1670 countA
= strlen(textA
) + 1;
1674 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1675 textA
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1676 countA
= strlen(textA
) + 1;
1681 ERR("no buffer ... please report\n");
1688 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1689 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1690 if(countW_new
> es
->buffer_size
+ 1)
1692 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1693 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1694 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1697 es
->hloc32W
= hloc32W_new
;
1698 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1699 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1702 WARN("FAILED! Will synchronize partially\n");
1706 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1707 es
->text
= LocalLock(es
->hloc32W
);
1711 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1713 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1715 LocalUnlock(es
->hloc32A
);
1722 /*********************************************************************
1724 * EDIT_SL_InvalidateText
1726 * Called from EDIT_InvalidateText().
1727 * Does the job for single-line controls only.
1730 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1735 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1736 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1737 EDIT_UpdateText(wnd
, &rc
, FALSE
);
1741 /*********************************************************************
1743 * EDIT_ML_InvalidateText
1745 * Called from EDIT_InvalidateText().
1746 * Does the job for multi-line controls only.
1749 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1751 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1752 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1753 INT el
= EDIT_EM_LineFromChar(es
, end
);
1762 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1765 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1766 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1767 if (sl
< es
->y_offset
) {
1771 if (el
> es
->y_offset
+ vlc
) {
1772 el
= es
->y_offset
+ vlc
;
1773 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1775 GetClientRect(wnd
->hwndSelf
, &rc1
);
1776 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1778 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1779 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1780 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1782 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1783 EDIT_EM_LineLength(es
,
1784 EDIT_EM_LineIndex(es
, sl
)),
1786 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1787 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1788 for (l
= sl
+ 1 ; l
< el
; l
++) {
1789 EDIT_GetLineRect(wnd
, es
, l
, 0,
1790 EDIT_EM_LineLength(es
,
1791 EDIT_EM_LineIndex(es
, l
)),
1793 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1794 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1796 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1797 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1798 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1803 /*********************************************************************
1805 * EDIT_InvalidateText
1807 * Invalidate the text from offset start upto, but not including,
1808 * offset end. Useful for (re)painting the selection.
1809 * Regions outside the linewidth are not invalidated.
1810 * end == -1 means end == TextLength.
1811 * start and end need not be ordered.
1814 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1820 end
= strlenW(es
->text
);
1822 ORDER_INT(start
, end
);
1824 if (es
->style
& ES_MULTILINE
)
1825 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1827 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1831 /*********************************************************************
1835 * Try to fit size + 1 characters in the buffer. Constrain to limits.
1838 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, UINT size
)
1842 if (size
<= es
->buffer_size
)
1844 if (size
> es
->buffer_limit
) {
1845 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
1848 if (size
> es
->buffer_limit
)
1849 size
= es
->buffer_limit
;
1851 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1853 /* Force edit to unlock it's buffer. es->text now NULL */
1854 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1857 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1858 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1859 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32W
, hNew32W
);
1860 es
->hloc32W
= hNew32W
;
1861 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1865 EDIT_LockBuffer(wnd
, es
);
1867 if (es
->buffer_size
< size
) {
1868 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1869 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1872 TRACE("We now have %d+1\n", es
->buffer_size
);
1878 /*********************************************************************
1882 * Try to fit size + 1 bytes in the undo buffer.
1885 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1889 if (size
<= es
->undo_buffer_size
)
1892 TRACE("trying to ReAlloc to %d+1\n", size
);
1894 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1895 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1896 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
);
1901 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1907 /*********************************************************************
1912 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1914 INT e
= es
->selection_end
;
1918 if ((es
->style
& ES_MULTILINE
) && e
&&
1919 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1921 if (e
&& (es
->text
[e
- 1] == '\r'))
1925 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1926 EDIT_EM_ScrollCaret(wnd
, es
);
1930 /*********************************************************************
1934 * Only for multi line controls
1935 * Move the caret one line down, on a column with the nearest
1936 * x coordinate on the screen (might be a different column).
1939 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1941 INT s
= es
->selection_start
;
1942 INT e
= es
->selection_end
;
1943 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1944 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1945 INT x
= SLOWORD(pos
);
1946 INT y
= SHIWORD(pos
);
1948 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1951 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1952 EDIT_EM_ScrollCaret(wnd
, es
);
1956 /*********************************************************************
1961 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1963 BOOL after_wrap
= FALSE
;
1966 /* Pass a high value in x to make sure of receiving the end of the line */
1967 if (es
->style
& ES_MULTILINE
)
1968 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1969 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1971 e
= strlenW(es
->text
);
1972 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1973 EDIT_EM_ScrollCaret(wnd
, es
);
1977 /*********************************************************************
1982 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1984 INT e
= es
->selection_end
;
1988 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1989 if (es
->text
[e
] == '\n')
1991 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1995 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1996 EDIT_EM_ScrollCaret(wnd
, es
);
2000 /*********************************************************************
2004 * Home key: move to beginning of line.
2007 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
2011 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2012 if (es
->style
& ES_MULTILINE
)
2013 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
2014 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2017 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2018 EDIT_EM_ScrollCaret(wnd
, es
);
2022 /*********************************************************************
2024 * EDIT_MovePageDown_ML
2026 * Only for multi line controls
2027 * Move the caret one page down, on a column with the nearest
2028 * x coordinate on the screen (might be a different column).
2031 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
2033 INT s
= es
->selection_start
;
2034 INT e
= es
->selection_end
;
2035 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2036 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
2037 INT x
= SLOWORD(pos
);
2038 INT y
= SHIWORD(pos
);
2040 e
= EDIT_CharFromPos(wnd
, es
, x
,
2041 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2045 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
2046 EDIT_EM_ScrollCaret(wnd
, es
);
2050 /*********************************************************************
2052 * EDIT_MovePageUp_ML
2054 * Only for multi line controls
2055 * Move the caret one page up, on a column with the nearest
2056 * x coordinate on the screen (might be a different column).
2059 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
2061 INT s
= es
->selection_start
;
2062 INT e
= es
->selection_end
;
2063 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2064 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
2065 INT x
= SLOWORD(pos
);
2066 INT y
= SHIWORD(pos
);
2068 e
= EDIT_CharFromPos(wnd
, es
, x
,
2069 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2073 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
2074 EDIT_EM_ScrollCaret(wnd
, es
);
2078 /*********************************************************************
2082 * Only for multi line controls
2083 * Move the caret one line up, on a column with the nearest
2084 * x coordinate on the screen (might be a different column).
2087 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
2089 INT s
= es
->selection_start
;
2090 INT e
= es
->selection_end
;
2091 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2092 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
2093 INT x
= SLOWORD(pos
);
2094 INT y
= SHIWORD(pos
);
2096 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
2099 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
2100 EDIT_EM_ScrollCaret(wnd
, es
);
2104 /*********************************************************************
2106 * EDIT_MoveWordBackward
2109 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
2111 INT s
= es
->selection_start
;
2112 INT e
= es
->selection_end
;
2117 l
= EDIT_EM_LineFromChar(es
, e
);
2118 ll
= EDIT_EM_LineLength(es
, e
);
2119 li
= EDIT_EM_LineIndex(es
, l
);
2122 li
= EDIT_EM_LineIndex(es
, l
- 1);
2123 e
= li
+ EDIT_EM_LineLength(es
, li
);
2126 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2127 li
, e
- li
, ll
, WB_LEFT
);
2131 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
2132 EDIT_EM_ScrollCaret(wnd
, es
);
2136 /*********************************************************************
2138 * EDIT_MoveWordForward
2141 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
2143 INT s
= es
->selection_start
;
2144 INT e
= es
->selection_end
;
2149 l
= EDIT_EM_LineFromChar(es
, e
);
2150 ll
= EDIT_EM_LineLength(es
, e
);
2151 li
= EDIT_EM_LineIndex(es
, l
);
2153 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2154 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2156 e
= li
+ EDIT_CallWordBreakProc(es
,
2157 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2161 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
2162 EDIT_EM_ScrollCaret(wnd
, es
);
2166 /*********************************************************************
2171 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2173 INT s
= es
->selection_start
;
2174 INT e
= es
->selection_end
;
2181 if (es
->style
& ES_MULTILINE
) {
2182 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2183 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2188 TRACE("line=%d\n", line
);
2190 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2193 li
= EDIT_EM_LineIndex(es
, line
);
2194 ll
= EDIT_EM_LineLength(es
, li
);
2195 s
= es
->selection_start
;
2196 e
= es
->selection_end
;
2198 s
= min(li
+ ll
, max(li
, s
));
2199 e
= min(li
+ ll
, max(li
, e
));
2200 if (rev
&& (s
!= e
) &&
2201 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2202 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2203 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2204 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2206 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2210 /*********************************************************************
2215 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2226 BkMode
= GetBkMode(dc
);
2227 BkColor
= GetBkColor(dc
);
2228 TextColor
= GetTextColor(dc
);
2230 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2231 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2232 SetBkMode( dc
, OPAQUE
);
2234 li
= EDIT_EM_LineIndex(es
, line
);
2235 if (es
->style
& ES_MULTILINE
) {
2236 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2237 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2239 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2240 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2241 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2243 if (es
->style
& ES_PASSWORD
)
2244 HeapFree(GetProcessHeap(), 0, text
);
2247 SetBkColor(dc
, BkColor
);
2248 SetTextColor(dc
, TextColor
);
2249 SetBkMode( dc
, BkMode
);
2255 /*********************************************************************
2260 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
2263 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
2264 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2268 /*********************************************************************
2272 * note: this is not (exactly) the handler called on EM_SETRECTNP
2273 * it is also used to set the rect of a single line control
2276 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
2278 CopyRect(&es
->format_rect
, rc
);
2279 if (es
->style
& WS_BORDER
) {
2280 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2281 if(TWEAK_WineLook
== WIN31_LOOK
)
2283 es
->format_rect
.left
+= bw
;
2284 es
->format_rect
.top
+= bw
;
2285 es
->format_rect
.right
-= bw
;
2286 es
->format_rect
.bottom
-= bw
;
2288 es
->format_rect
.left
+= es
->left_margin
;
2289 es
->format_rect
.right
-= es
->right_margin
;
2290 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2291 if (es
->style
& ES_MULTILINE
)
2293 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2295 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2296 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2298 /* correct es->x_offset */
2299 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2300 max_x_offset
= es
->text_width
- fw
;
2301 if(max_x_offset
< 0) max_x_offset
= 0;
2302 if(es
->x_offset
> max_x_offset
)
2303 es
->x_offset
= max_x_offset
;
2305 /* correct es->y_offset */
2306 max_y_offset
= es
->line_count
- vlc
;
2307 if(max_y_offset
< 0) max_y_offset
= 0;
2308 if(es
->y_offset
> max_y_offset
)
2309 es
->y_offset
= max_y_offset
;
2311 /* force scroll info update */
2312 EDIT_UpdateScrollInfo(wnd
, es
);
2315 /* Windows doesn't care to fix text placement for SL controls */
2316 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2318 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2319 EDIT_BuildLineDefs_ML(wnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
2323 /*********************************************************************
2328 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
2330 /* Edit window might be already destroyed */
2331 if(!IsWindow(wnd
->hwndSelf
))
2333 WARN("edit wnd %04x already destroyed\n", wnd
->hwndSelf
);
2338 ERR("no EDITSTATE ... please report\n");
2341 if (!es
->lock_count
) {
2342 ERR("lock_count == 0 ... please report\n");
2346 ERR("es->text == 0 ... please report\n");
2350 if (force
|| (es
->lock_count
== 1)) {
2353 BOOL _16bit
= FALSE
;
2355 UINT countW
= strlenW(es
->text
) + 1;
2359 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2360 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2361 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2362 countA
= LocalSize(es
->hloc32A
);
2363 if(countA_new
> countA
)
2366 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2367 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2368 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2371 es
->hloc32A
= hloc32A_new
;
2372 countA
= LocalSize(hloc32A_new
);
2373 TRACE("Real new size %d bytes\n", countA
);
2376 WARN("FAILED! Will synchronize partially\n");
2378 textA
= LocalLock(es
->hloc32A
);
2382 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2383 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2384 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2385 countA
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
);
2386 if(countA_new
> countA
)
2388 HLOCAL16 hloc16_new
;
2389 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2390 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2391 hloc16_new
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2394 es
->hloc16
= hloc16_new
;
2395 countA
= LOCAL_Size(wnd
->hInstance
, hloc16_new
);
2396 TRACE("Real new size %d bytes\n", countA
);
2399 WARN("FAILED! Will synchronize partially\n");
2401 textA
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
2407 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2409 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
2411 LocalUnlock(es
->hloc32A
);
2414 LocalUnlock(es
->hloc32W
);
2418 ERR("no buffer ... please report\n");
2426 /*********************************************************************
2428 * EDIT_UpdateScrollInfo
2431 static void EDIT_UpdateScrollInfo(WND
*wnd
, EDITSTATE
*es
)
2433 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2436 si
.cbSize
= sizeof(SCROLLINFO
);
2437 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2439 si
.nMax
= es
->line_count
- 1;
2440 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2441 si
.nPos
= es
->y_offset
;
2442 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2443 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2444 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2447 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2450 si
.cbSize
= sizeof(SCROLLINFO
);
2451 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2453 si
.nMax
= es
->text_width
- 1;
2454 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2455 si
.nPos
= es
->x_offset
;
2456 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2457 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2458 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2462 /*********************************************************************
2464 * EDIT_WordBreakProc
2466 * Find the beginning of words.
2467 * Note: unlike the specs for a WordBreakProc, this function only
2468 * allows to be called without linebreaks between s[0] upto
2469 * s[count - 1]. Remember it is only called
2470 * internally, so we can decide this for ourselves.
2473 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2477 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2487 if (s
[index
] == ' ') {
2488 while (index
&& (s
[index
] == ' '))
2491 while (index
&& (s
[index
] != ' '))
2493 if (s
[index
] == ' ')
2497 while (index
&& (s
[index
] != ' '))
2499 if (s
[index
] == ' ')
2509 if (s
[index
] == ' ')
2510 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2512 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2514 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2518 case WB_ISDELIMITER
:
2519 ret
= (s
[index
] == ' ');
2522 ERR("unknown action code, please report !\n");
2529 /*********************************************************************
2533 * returns line number (not index) in high-order word of result.
2534 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2535 * to Richedit, not to the edit control. Original documentation is valid.
2536 * FIXME: do the specs mean to return -1 if outside client area or
2537 * if outside formatting rectangle ???
2540 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
2548 GetClientRect(wnd
->hwndSelf
, &rc
);
2549 if (!PtInRect(&rc
, pt
))
2552 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
2553 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2557 /*********************************************************************
2561 * Enable or disable soft breaks.
2563 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2565 es
->flags
&= ~EF_USE_SOFTBRK
;
2567 es
->flags
|= EF_USE_SOFTBRK
;
2568 FIXME("soft break enabled, not implemented\n");
2574 /*********************************************************************
2578 * Hopefully this won't fire back at us.
2579 * We always start with a fixed buffer in the local heap.
2580 * Despite of the documentation says that the local heap is used
2581 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2582 * buffer on the local heap.
2585 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2589 if (!(es
->style
& ES_MULTILINE
))
2593 hLocal
= es
->hloc32W
;
2599 UINT countA
, alloc_size
;
2600 TRACE("Allocating 32-bit ANSI alias buffer\n");
2601 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2602 alloc_size
= ROUND_TO_GROW(countA
);
2603 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2605 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2608 textA
= LocalLock(es
->hloc32A
);
2609 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2610 LocalUnlock(es
->hloc32A
);
2612 hLocal
= es
->hloc32A
;
2615 TRACE("Returning %04X, LocalSize() = %d\n", hLocal
, LocalSize(hLocal
));
2620 /*********************************************************************
2624 * Hopefully this won't fire back at us.
2625 * We always start with a buffer in 32 bit linear memory.
2626 * However, with this message a 16 bit application requests
2627 * a handle of 16 bit local heap memory, where it expects to find
2629 * It's a pitty that from this moment on we have to use this
2630 * local heap, because applications may rely on the handle
2633 * In this function we'll try to switch to local heap.
2635 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2638 UINT countA
, alloc_size
;
2640 if (!(es
->style
& ES_MULTILINE
))
2646 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2647 if (!LocalInit16(wnd
->hInstance
, 0,
2648 GlobalSize16(wnd
->hInstance
))) {
2649 ERR("could not initialize local heap\n");
2652 TRACE("local heap initialized\n");
2655 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2656 alloc_size
= ROUND_TO_GROW(countA
);
2658 TRACE("Allocating 16-bit ANSI alias buffer\n");
2659 if (!(es
->hloc16
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2660 ERR("could not allocate new 16 bit buffer\n");
2664 if (!(textA
= (LPSTR
)LOCAL_Lock(wnd
->hInstance
, es
->hloc16
))) {
2665 ERR("could not lock new 16 bit buffer\n");
2666 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
2671 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2672 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
2674 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(wnd
->hInstance
, es
->hloc16
));
2679 /*********************************************************************
2684 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2687 INT line_len
, dst_len
;
2690 if (es
->style
& ES_MULTILINE
) {
2691 if (line
>= es
->line_count
)
2695 i
= EDIT_EM_LineIndex(es
, line
);
2697 line_len
= EDIT_EM_LineLength(es
, i
);
2698 dst_len
= *(WORD
*)lParam
;
2701 LPWSTR dst
= (LPWSTR
)lParam
;
2702 if(dst_len
<= line_len
)
2704 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2707 else /* Append 0 if enough space */
2709 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2716 LPSTR dst
= (LPSTR
)lParam
;
2718 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2719 if(!ret
) /* Insufficient buffer size */
2721 if(ret
< dst_len
) /* Append 0 if enough space */
2728 /*********************************************************************
2733 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2735 UINT s
= es
->selection_start
;
2736 UINT e
= es
->selection_end
;
2743 return MAKELONG(s
, e
);
2747 /*********************************************************************
2751 * FIXME: is this right ? (or should it be only VSCROLL)
2752 * (and maybe only for edit controls that really have their
2753 * own scrollbars) (and maybe only for multiline controls ?)
2754 * All in all: very poorly documented
2757 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2759 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0),
2760 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0));
2764 /*********************************************************************
2769 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2774 if (!(es
->style
& ES_MULTILINE
))
2776 if (index
> (INT
)strlenW(es
->text
))
2777 return es
->line_count
- 1;
2779 index
= min(es
->selection_start
, es
->selection_end
);
2782 line_def
= es
->first_line_def
;
2783 index
-= line_def
->length
;
2784 while ((index
>= 0) && line_def
->next
) {
2786 line_def
= line_def
->next
;
2787 index
-= line_def
->length
;
2793 /*********************************************************************
2798 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2803 if (!(es
->style
& ES_MULTILINE
))
2805 if (line
>= es
->line_count
)
2809 line_def
= es
->first_line_def
;
2811 INT index
= es
->selection_end
- line_def
->length
;
2812 while ((index
>= 0) && line_def
->next
) {
2813 line_index
+= line_def
->length
;
2814 line_def
= line_def
->next
;
2815 index
-= line_def
->length
;
2819 line_index
+= line_def
->length
;
2820 line_def
= line_def
->next
;
2828 /*********************************************************************
2833 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2837 if (!(es
->style
& ES_MULTILINE
))
2838 return strlenW(es
->text
);
2841 /* get the number of remaining non-selected chars of selected lines */
2844 li
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2845 /* # chars before start of selection area */
2846 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, li
);
2847 li
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2848 /* # chars after end of selection */
2849 count
+= EDIT_EM_LineIndex(es
, li
) +
2850 EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2853 line_def
= es
->first_line_def
;
2854 index
-= line_def
->length
;
2855 while ((index
>= 0) && line_def
->next
) {
2856 line_def
= line_def
->next
;
2857 index
-= line_def
->length
;
2859 return line_def
->net_length
;
2863 /*********************************************************************
2867 * NOTE: dx is in average character widths, dy - in lines;
2870 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2872 if (!(es
->style
& ES_MULTILINE
))
2875 dx
*= es
->char_width
;
2876 return EDIT_EM_LineScroll_internal(wnd
, es
, dx
, dy
);
2879 /*********************************************************************
2881 * EDIT_EM_LineScroll_internal
2883 * Version of EDIT_EM_LineScroll for internal use.
2884 * It doesn't refuse if ES_MULTILINE is set and assumes that
2885 * dx is in pixels, dy - in lines.
2888 static BOOL
EDIT_EM_LineScroll_internal(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2891 INT x_offset_in_pixels
;
2893 if (es
->style
& ES_MULTILINE
)
2895 x_offset_in_pixels
= es
->x_offset
;
2900 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->x_offset
, FALSE
));
2903 if (-dx
> x_offset_in_pixels
)
2904 dx
= -x_offset_in_pixels
;
2905 if (dx
> es
->text_width
- x_offset_in_pixels
)
2906 dx
= es
->text_width
- x_offset_in_pixels
;
2907 nyoff
= max(0, es
->y_offset
+ dy
);
2908 if (nyoff
>= es
->line_count
)
2909 nyoff
= es
->line_count
- 1;
2910 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2915 es
->y_offset
= nyoff
;
2916 if(es
->style
& ES_MULTILINE
)
2919 es
->x_offset
+= dx
/ es
->char_width
;
2921 GetClientRect(wnd
->hwndSelf
, &rc1
);
2922 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2923 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2924 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2925 /* force scroll info update */
2926 EDIT_UpdateScrollInfo(wnd
, es
);
2928 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2929 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2930 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2931 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2936 /*********************************************************************
2941 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2943 INT len
= strlenW(es
->text
);
2952 index
= min(index
, len
);
2953 dc
= GetDC(wnd
->hwndSelf
);
2955 old_font
= SelectObject(dc
, es
->font
);
2956 if (es
->style
& ES_MULTILINE
) {
2957 l
= EDIT_EM_LineFromChar(es
, index
);
2958 y
= (l
- es
->y_offset
) * es
->line_height
;
2959 li
= EDIT_EM_LineIndex(es
, l
);
2960 if (after_wrap
&& (li
== index
) && l
) {
2962 LINEDEF
*line_def
= es
->first_line_def
;
2964 line_def
= line_def
->next
;
2967 if (line_def
->ending
== END_WRAP
) {
2969 y
-= es
->line_height
;
2970 li
= EDIT_EM_LineIndex(es
, l
);
2973 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2974 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2976 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2977 if (index
< es
->x_offset
) {
2978 GetTextExtentPoint32W(dc
, text
+ index
,
2979 es
->x_offset
- index
, &size
);
2982 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2983 index
- es
->x_offset
, &size
);
2987 if (es
->style
& ES_PASSWORD
)
2988 HeapFree(GetProcessHeap(), 0, text
);
2990 x
+= es
->format_rect
.left
;
2991 y
+= es
->format_rect
.top
;
2993 SelectObject(dc
, old_font
);
2994 ReleaseDC(wnd
->hwndSelf
, dc
);
2995 return MAKELONG((INT16
)x
, (INT16
)y
);
2999 /*********************************************************************
3003 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3006 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
)
3008 UINT strl
= strlenW(lpsz_replace
);
3009 UINT tl
= strlenW(es
->text
);
3017 TRACE("%s, can_undo %d, send_update %d\n",
3018 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3020 s
= es
->selection_start
;
3021 e
= es
->selection_end
;
3023 if ((s
== e
) && !strl
)
3028 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
3032 /* there is something to be deleted */
3034 utl
= strlenW(es
->undo_text
);
3035 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3036 /* undo-buffer is extended to the right */
3037 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3038 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
3039 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3040 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3041 /* undo-buffer is extended to the left */
3042 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3043 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3045 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3046 p
[i
] = (es
->text
+ s
)[i
];
3047 es
->undo_position
= s
;
3049 /* new undo-buffer */
3050 EDIT_MakeUndoFit(es
, e
- s
);
3051 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
3052 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3053 es
->undo_position
= s
;
3055 /* any deletion makes the old insertion-undo invalid */
3056 es
->undo_insert_count
= 0;
3058 EDIT_EM_EmptyUndoBuffer(es
);
3061 strcpyW(es
->text
+ s
, es
->text
+ e
);
3064 /* there is an insertion */
3066 if ((s
== es
->undo_position
) ||
3067 ((es
->undo_insert_count
) &&
3068 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3070 * insertion is new and at delete position or
3071 * an extension to either left or right
3073 es
->undo_insert_count
+= strl
;
3075 /* new insertion undo */
3076 es
->undo_position
= s
;
3077 es
->undo_insert_count
= strl
;
3078 /* new insertion makes old delete-buffer invalid */
3079 *es
->undo_text
= '\0';
3082 EDIT_EM_EmptyUndoBuffer(es
);
3085 tl
= strlenW(es
->text
);
3086 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3088 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3089 p
[i
] = lpsz_replace
[i
];
3090 if(es
->style
& ES_UPPERCASE
)
3091 CharUpperBuffW(p
, strl
);
3092 else if(es
->style
& ES_LOWERCASE
)
3093 CharLowerBuffW(p
, strl
);
3096 if (es
->style
& ES_MULTILINE
)
3098 INT s
= min(es
->selection_start
, es
->selection_end
);
3100 hrgn
= CreateRectRgn(0, 0, 0, 0);
3101 EDIT_BuildLineDefs_ML(wnd
, es
, s
, s
+ strl
,
3102 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3105 EDIT_CalcLineWidth_SL(wnd
, es
);
3107 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
3108 es
->flags
|= EF_MODIFIED
;
3109 if (send_update
) es
->flags
|= EF_UPDATE
;
3110 EDIT_EM_ScrollCaret(wnd
, es
);
3112 /* force scroll info update */
3113 EDIT_UpdateScrollInfo(wnd
, es
);
3117 EDIT_UpdateTextRegion(wnd
, hrgn
, TRUE
);
3121 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3123 if(es
->flags
& EF_UPDATE
)
3125 es
->flags
&= ~EF_UPDATE
;
3126 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3131 /*********************************************************************
3136 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
3140 if (!(es
->style
& ES_MULTILINE
))
3141 return (LRESULT
)FALSE
;
3151 if (es
->y_offset
< es
->line_count
- 1)
3156 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3159 if (es
->y_offset
< es
->line_count
- 1)
3160 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3163 return (LRESULT
)FALSE
;
3166 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3167 /* check if we are going to move too far */
3168 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3169 dy
= es
->line_count
- vlc
- es
->y_offset
;
3171 /* Notification is done in EDIT_EM_LineScroll */
3173 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
3175 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3179 /*********************************************************************
3184 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
3186 if (es
->style
& ES_MULTILINE
) {
3191 INT cw
= es
->char_width
;
3196 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3197 li
= EDIT_EM_LineIndex(es
, l
);
3198 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3199 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3200 if (l
>= es
->y_offset
+ vlc
)
3201 dy
= l
- vlc
+ 1 - es
->y_offset
;
3202 if (l
< es
->y_offset
)
3203 dy
= l
- es
->y_offset
;
3204 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3205 if (x
< es
->format_rect
.left
)
3206 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3207 if (x
> es
->format_rect
.right
)
3208 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3211 /* check if we are going to move too far */
3212 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3213 dx
= es
->text_width
- ww
- es
->x_offset
;
3215 EDIT_EM_LineScroll_internal(wnd
, es
, dx
, dy
);
3222 if (!(es
->style
& ES_AUTOHSCROLL
))
3225 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
3226 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3227 if (x
< es
->format_rect
.left
) {
3228 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3231 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
3232 } while ((x
< goal
) && es
->x_offset
);
3233 /* FIXME: use ScrollWindow() somehow to improve performance */
3234 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3235 } else if (x
> es
->format_rect
.right
) {
3237 INT len
= strlenW(es
->text
);
3238 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3241 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
3242 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
3243 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3244 /* FIXME: use ScrollWindow() somehow to improve performance */
3245 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3249 if(es
->flags
& EF_FOCUSED
)
3250 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3254 /*********************************************************************
3258 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3261 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
3263 if (!(es
->style
& ES_MULTILINE
))
3267 WARN("called with NULL handle\n");
3271 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
3275 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3276 es
->hloc16
= (HLOCAL16
)NULL
;
3283 LocalFree(es
->hloc32A
);
3284 es
->hloc32A
= (HLOCAL
)NULL
;
3295 countA
= LocalSize(hloc
);
3296 textA
= LocalLock(hloc
);
3297 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3298 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3300 ERR("Could not allocate new unicode buffer\n");
3303 textW
= LocalLock(hloc32W_new
);
3304 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3305 LocalUnlock(hloc32W_new
);
3309 LocalFree(es
->hloc32W
);
3311 es
->hloc32W
= hloc32W_new
;
3315 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3317 EDIT_LockBuffer(wnd
, es
);
3319 es
->x_offset
= es
->y_offset
= 0;
3320 es
->selection_start
= es
->selection_end
= 0;
3321 EDIT_EM_EmptyUndoBuffer(es
);
3322 es
->flags
&= ~EF_MODIFIED
;
3323 es
->flags
&= ~EF_UPDATE
;
3324 EDIT_BuildLineDefs_ML(wnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3325 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3326 EDIT_EM_ScrollCaret(wnd
, es
);
3327 /* force scroll info update */
3328 EDIT_UpdateScrollInfo(wnd
, es
);
3332 /*********************************************************************
3336 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3339 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
3346 if (!(es
->style
& ES_MULTILINE
))
3350 WARN("called with NULL handle\n");
3354 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
3358 LocalFree(es
->hloc32A
);
3359 es
->hloc32A
= (HLOCAL
)NULL
;
3362 countA
= LOCAL_Size(wnd
->hInstance
, hloc
);
3363 textA
= LOCAL_Lock(wnd
->hInstance
, hloc
);
3364 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3365 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3367 ERR("Could not allocate new unicode buffer\n");
3370 textW
= LocalLock(hloc32W_new
);
3371 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3372 LocalUnlock(hloc32W_new
);
3373 LOCAL_Unlock(wnd
->hInstance
, hloc
);
3376 LocalFree(es
->hloc32W
);
3378 es
->hloc32W
= hloc32W_new
;
3381 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3383 EDIT_LockBuffer(wnd
, es
);
3385 es
->x_offset
= es
->y_offset
= 0;
3386 es
->selection_start
= es
->selection_end
= 0;
3387 EDIT_EM_EmptyUndoBuffer(es
);
3388 es
->flags
&= ~EF_MODIFIED
;
3389 es
->flags
&= ~EF_UPDATE
;
3390 EDIT_BuildLineDefs_ML(wnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3391 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3392 EDIT_EM_ScrollCaret(wnd
, es
);
3393 /* force scroll info update */
3394 EDIT_UpdateScrollInfo(wnd
, es
);
3398 /*********************************************************************
3402 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3403 * However, the windows version is not complied to yet in all of edit.c
3406 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3408 if (es
->style
& ES_MULTILINE
) {
3410 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3412 es
->buffer_limit
= BUFLIMIT_MULTI
;
3415 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3417 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3422 /*********************************************************************
3426 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3427 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3428 * of the char's width, according to the new docs.
3431 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3432 INT left
, INT right
)
3434 if (action
& EC_LEFTMARGIN
) {
3435 if (left
!= EC_USEFONTINFO
)
3436 es
->left_margin
= left
;
3438 es
->left_margin
= es
->char_width
/ 3;
3441 if (action
& EC_RIGHTMARGIN
) {
3442 if (right
!= EC_USEFONTINFO
)
3443 es
->right_margin
= right
;
3445 es
->right_margin
= es
->char_width
/ 3;
3447 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3451 /*********************************************************************
3453 * EM_SETPASSWORDCHAR
3456 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, WCHAR c
)
3458 if (es
->style
& ES_MULTILINE
)
3461 if (es
->password_char
== c
)
3464 es
->password_char
= c
;
3466 wnd
->dwStyle
|= ES_PASSWORD
;
3467 es
->style
|= ES_PASSWORD
;
3469 wnd
->dwStyle
&= ~ES_PASSWORD
;
3470 es
->style
&= ~ES_PASSWORD
;
3472 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3476 /*********************************************************************
3480 * note: unlike the specs say: the order of start and end
3481 * _is_ preserved in Windows. (i.e. start can be > end)
3482 * In other words: this handler is OK
3485 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3487 UINT old_start
= es
->selection_start
;
3488 UINT old_end
= es
->selection_end
;
3489 UINT len
= strlenW(es
->text
);
3491 if (start
== (UINT
)-1) {
3492 start
= es
->selection_end
;
3493 end
= es
->selection_end
;
3495 start
= min(start
, len
);
3496 end
= min(end
, len
);
3498 es
->selection_start
= start
;
3499 es
->selection_end
= end
;
3501 es
->flags
|= EF_AFTER_WRAP
;
3503 es
->flags
&= ~EF_AFTER_WRAP
;
3504 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3505 ORDER_UINT(start
, end
);
3506 ORDER_UINT(end
, old_end
);
3507 ORDER_UINT(start
, old_start
);
3508 ORDER_UINT(old_start
, old_end
);
3509 if (end
!= old_start
)
3513 * ORDER_UINT32(end, old_start);
3514 * EDIT_InvalidateText(wnd, es, start, end);
3515 * EDIT_InvalidateText(wnd, es, old_start, old_end);
3516 * in place of the following if statement.
3518 if (old_start
> end
)
3520 EDIT_InvalidateText(wnd
, es
, start
, end
);
3521 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
3525 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
3526 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
3529 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
3533 /*********************************************************************
3538 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3540 if (!(es
->style
& ES_MULTILINE
))
3543 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3544 es
->tabs_count
= count
;
3548 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3549 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3555 /*********************************************************************
3560 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3562 if (!(es
->style
& ES_MULTILINE
))
3565 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3566 es
->tabs_count
= count
;
3571 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3572 for (i
= 0 ; i
< count
; i
++)
3573 es
->tabs
[i
] = *tabs
++;
3579 /*********************************************************************
3581 * EM_SETWORDBREAKPROC
3584 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
)
3586 if (es
->word_break_proc
== (void *)lParam
)
3589 es
->word_break_proc
= (void *)lParam
;
3590 es
->word_break_proc16
= NULL
;
3592 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3593 EDIT_BuildLineDefs_ML(wnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3594 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3599 /*********************************************************************
3601 * EM_SETWORDBREAKPROC16
3604 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3606 if (es
->word_break_proc16
== wbp
)
3609 es
->word_break_proc
= NULL
;
3610 es
->word_break_proc16
= wbp
;
3611 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3612 EDIT_BuildLineDefs_ML(wnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3613 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3618 /*********************************************************************
3623 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
3628 /* Protect read-only edit control from modification */
3629 if(es
->style
& ES_READONLY
)
3632 ulength
= strlenW(es
->undo_text
);
3633 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3635 strcpyW(utext
, es
->undo_text
);
3637 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3638 es
->undo_insert_count
, debugstr_w(utext
));
3640 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3641 EDIT_EM_EmptyUndoBuffer(es
);
3642 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
, FALSE
);
3643 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3644 /* send the notification after the selection start and end are set */
3645 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3646 EDIT_EM_ScrollCaret(wnd
, es
);
3647 HeapFree(GetProcessHeap(), 0, utext
);
3649 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3650 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3655 /*********************************************************************
3660 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, WCHAR c
)
3664 /* Protect read-only edit control from modification */
3665 if(es
->style
& ES_READONLY
)
3668 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3672 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3673 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3676 if (es
->style
& ES_MULTILINE
) {
3677 if (es
->style
& ES_READONLY
) {
3678 EDIT_MoveHome(wnd
, es
, FALSE
);
3679 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
3681 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3682 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, cr_lfW
, TRUE
);
3687 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3689 static const WCHAR tabW
[] = {'\t',0};
3690 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, tabW
, TRUE
);
3694 if (!(es
->style
& ES_READONLY
) && !control
) {
3695 if (es
->selection_start
!= es
->selection_end
)
3696 EDIT_WM_Clear(wnd
, es
);
3698 /* delete character left of caret */
3699 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
3700 EDIT_MoveBackward(wnd
, es
, TRUE
);
3701 EDIT_WM_Clear(wnd
, es
);
3706 SendMessageW(wnd
->hwndSelf
, WM_COPY
, 0, 0);
3709 SendMessageW(wnd
->hwndSelf
, WM_PASTE
, 0, 0);
3712 SendMessageW(wnd
->hwndSelf
, WM_CUT
, 0, 0);
3716 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3720 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
, TRUE
);
3727 /*********************************************************************
3732 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3734 if (code
|| control
)
3739 EDIT_EM_Undo(wnd
, es
);
3742 EDIT_WM_Cut(wnd
, es
);
3745 EDIT_WM_Copy(wnd
, es
);
3748 EDIT_WM_Paste(wnd
, es
);
3751 EDIT_WM_Clear(wnd
, es
);
3754 EDIT_EM_SetSel(wnd
, es
, 0, (UINT
)-1, FALSE
);
3755 EDIT_EM_ScrollCaret(wnd
, es
);
3758 ERR("unknown menu item, please report\n");
3764 /*********************************************************************
3768 * Note: the resource files resource/sysres_??.rc cannot define a
3769 * single popup menu. Hence we use a (dummy) menubar
3770 * containing the single popup menu as its first item.
3772 * FIXME: the message identifiers have been chosen arbitrarily,
3773 * hence we use MF_BYPOSITION.
3774 * We might as well use the "real" values (anybody knows ?)
3775 * The menu definition is in resources/sysres_??.rc.
3776 * Once these are OK, we better use MF_BYCOMMAND here
3777 * (as we do in EDIT_WM_Command()).
3780 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
3782 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3783 HMENU popup
= GetSubMenu(menu
, 0);
3784 UINT start
= es
->selection_start
;
3785 UINT end
= es
->selection_end
;
3787 ORDER_UINT(start
, end
);
3790 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3792 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3794 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3796 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3798 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3800 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3802 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3807 /*********************************************************************
3812 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3814 INT s
= es
->selection_start
;
3815 INT e
= es
->selection_end
;
3822 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3823 dst
= GlobalLock(hdst
);
3824 strncpyW(dst
, es
->text
+ s
, e
- s
);
3825 dst
[e
- s
] = 0; /* ensure 0 termination */
3826 TRACE("%s\n", debugstr_w(dst
));
3828 OpenClipboard(wnd
->hwndSelf
);
3830 SetClipboardData(CF_UNICODETEXT
, hdst
);
3835 /*********************************************************************
3840 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCWSTR name
)
3842 TRACE("%s\n", debugstr_w(name
));
3844 * To initialize some final structure members, we call some helper
3845 * functions. However, since the EDITSTATE is not consistent (i.e.
3846 * not fully initialized), we should be very careful which
3847 * functions can be called, and in what order.
3849 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3850 EDIT_EM_EmptyUndoBuffer(es
);
3852 if (name
&& *name
) {
3853 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, name
, FALSE
);
3854 /* if we insert text to the editline, the text scrolls out
3855 * of the window, as the caret is placed after the insert
3856 * pos normally; thus we reset es->selection... to 0 and
3859 es
->selection_start
= es
->selection_end
= 0;
3860 /* send the notification after the selection start and end are set */
3861 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3862 EDIT_EM_ScrollCaret(wnd
, es
);
3864 /* force scroll info update */
3865 EDIT_UpdateScrollInfo(wnd
, es
);
3870 /*********************************************************************
3875 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3880 while (LocalUnlock(es
->hloc32W
)) ;
3881 LocalFree(es
->hloc32W
);
3884 while (LocalUnlock(es
->hloc32A
)) ;
3885 LocalFree(es
->hloc32A
);
3888 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3889 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3892 pc
= es
->first_line_def
;
3896 HeapFree(GetProcessHeap(), 0, pc
);
3900 HeapFree(GetProcessHeap(), 0, es
);
3901 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3905 /*********************************************************************
3910 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3915 if ( get_app_version() >= 0x40000 &&(
3916 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3917 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3919 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3922 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3924 GetClientRect(wnd
->hwndSelf
, &rc
);
3925 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3926 GetClipBox(dc
, &rc
);
3928 * FIXME: specs say that we should UnrealizeObject() the brush,
3929 * but the specs of UnrealizeObject() say that we shouldn't
3930 * unrealize a stock object. The default brush that
3931 * DefWndProc() returns is ... a stock object.
3933 FillRect(dc
, &rc
, brush
);
3938 /*********************************************************************
3943 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3945 if(!count
) return 0;
3949 LPWSTR textW
= (LPWSTR
)lParam
;
3950 strncpyW(textW
, es
->text
, count
);
3951 textW
[count
- 1] = 0; /* ensure 0 termination */
3952 return strlenW(textW
);
3956 LPSTR textA
= (LPSTR
)lParam
;
3957 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
);
3958 textA
[count
- 1] = 0; /* ensure 0 termination */
3959 return strlen(textA
);
3963 /*********************************************************************
3968 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
)
3973 if (!(es
->style
& ES_MULTILINE
))
3976 if (!(es
->style
& ES_AUTOHSCROLL
))
3980 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3983 TRACE("SB_LINELEFT\n");
3985 dx
= -es
->char_width
;
3988 TRACE("SB_LINERIGHT\n");
3989 if (es
->x_offset
< es
->text_width
)
3990 dx
= es
->char_width
;
3993 TRACE("SB_PAGELEFT\n");
3995 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3998 TRACE("SB_PAGERIGHT\n");
3999 if (es
->x_offset
< es
->text_width
)
4000 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4008 TRACE("SB_RIGHT\n");
4009 if (es
->x_offset
< es
->text_width
)
4010 dx
= es
->text_width
- es
->x_offset
;
4013 TRACE("SB_THUMBTRACK %d\n", pos
);
4014 es
->flags
|= EF_HSCROLL_TRACK
;
4015 if(es
->style
& WS_HSCROLL
)
4016 dx
= pos
- es
->x_offset
;
4021 if(pos
< 0 || pos
> 100) return 0;
4022 /* Assume default scroll range 0-100 */
4023 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4024 new_x
= pos
* (es
->text_width
- fw
) / 100;
4025 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4028 case SB_THUMBPOSITION
:
4029 TRACE("SB_THUMBPOSITION %d\n", pos
);
4030 es
->flags
&= ~EF_HSCROLL_TRACK
;
4031 if(wnd
->dwStyle
& WS_HSCROLL
)
4032 dx
= pos
- es
->x_offset
;
4037 if(pos
< 0 || pos
> 100) return 0;
4038 /* Assume default scroll range 0-100 */
4039 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4040 new_x
= pos
* (es
->text_width
- fw
) / 100;
4041 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4044 /* force scroll info update */
4045 EDIT_UpdateScrollInfo(wnd
, es
);
4046 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
4050 TRACE("SB_ENDSCROLL\n");
4053 * FIXME : the next two are undocumented !
4054 * Are we doing the right thing ?
4055 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4056 * although it's also a regular control message.
4058 case EM_GETTHUMB
: /* this one is used by NT notepad */
4062 if(wnd
->dwStyle
& WS_HSCROLL
)
4063 ret
= GetScrollPos(wnd
->hwndSelf
, SB_HORZ
);
4066 /* Assume default scroll range 0-100 */
4067 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4068 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4070 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4073 case EM_LINESCROLL16
:
4074 TRACE("EM_LINESCROLL16\n");
4079 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4085 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4086 /* check if we are going to move too far */
4087 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4088 dx
= es
->text_width
- fw
- es
->x_offset
;
4090 EDIT_EM_LineScroll_internal(wnd
, es
, dx
, 0);
4096 /*********************************************************************
4101 static BOOL
EDIT_CheckCombo(WND
*wnd
, EDITSTATE
*es
, UINT msg
, INT key
)
4103 HWND hLBox
= es
->hwndListBox
;
4111 hCombo
= wnd
->parent
->hwndSelf
;
4115 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
4116 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
4118 if (key
== VK_UP
|| key
== VK_DOWN
)
4120 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4123 if (msg
== WM_KEYDOWN
|| nEUI
)
4124 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4130 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4132 /* make sure ComboLBox pops up */
4133 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4138 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4141 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4143 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4145 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4150 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4156 /*********************************************************************
4160 * Handling of special keys that don't produce a WM_CHAR
4161 * (i.e. non-printable keys) & Backspace & Delete
4164 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
)
4169 if (GetKeyState(VK_MENU
) & 0x8000)
4172 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4173 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4178 if (EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4183 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4184 EDIT_MoveUp_ML(wnd
, es
, shift
);
4187 EDIT_MoveWordBackward(wnd
, es
, shift
);
4189 EDIT_MoveBackward(wnd
, es
, shift
);
4192 if (EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
))
4196 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4197 EDIT_MoveDown_ML(wnd
, es
, shift
);
4199 EDIT_MoveWordForward(wnd
, es
, shift
);
4201 EDIT_MoveForward(wnd
, es
, shift
);
4204 EDIT_MoveHome(wnd
, es
, shift
);
4207 EDIT_MoveEnd(wnd
, es
, shift
);
4210 if (es
->style
& ES_MULTILINE
)
4211 EDIT_MovePageUp_ML(wnd
, es
, shift
);
4213 EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
);
4216 if (es
->style
& ES_MULTILINE
)
4217 EDIT_MovePageDown_ML(wnd
, es
, shift
);
4219 EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
);
4222 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4223 if (es
->selection_start
!= es
->selection_end
) {
4225 EDIT_WM_Cut(wnd
, es
);
4227 EDIT_WM_Clear(wnd
, es
);
4230 /* delete character left of caret */
4231 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
4232 EDIT_MoveBackward(wnd
, es
, TRUE
);
4233 EDIT_WM_Clear(wnd
, es
);
4234 } else if (control
) {
4235 /* delete to end of line */
4236 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
4237 EDIT_MoveEnd(wnd
, es
, TRUE
);
4238 EDIT_WM_Clear(wnd
, es
);
4240 /* delete character right of caret */
4241 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
4242 EDIT_MoveForward(wnd
, es
, TRUE
);
4243 EDIT_WM_Clear(wnd
, es
);
4250 if (!(es
->style
& ES_READONLY
))
4251 EDIT_WM_Paste(wnd
, es
);
4253 EDIT_WM_Copy(wnd
, es
);
4256 /* If the edit doesn't want the return send a message to the default object */
4257 if(!(es
->style
& ES_WANTRETURN
))
4259 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
4260 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4261 if (HIWORD(dw
) == DC_HASDEFID
)
4263 SendMessageW( hwndParent
, WM_COMMAND
,
4264 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4265 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4274 /*********************************************************************
4279 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
)
4281 es
->flags
&= ~EF_FOCUSED
;
4283 if(!(es
->style
& ES_NOHIDESEL
))
4284 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
4285 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4290 /*********************************************************************
4294 * The caret position has been set on the WM_LBUTTONDOWN message
4297 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
)
4300 INT e
= es
->selection_end
;
4305 if (!(es
->flags
& EF_FOCUSED
))
4308 l
= EDIT_EM_LineFromChar(es
, e
);
4309 li
= EDIT_EM_LineIndex(es
, l
);
4310 ll
= EDIT_EM_LineLength(es
, e
);
4311 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4312 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4313 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
4314 EDIT_EM_ScrollCaret(wnd
, es
);
4319 /*********************************************************************
4324 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4329 if (!(es
->flags
& EF_FOCUSED
))
4332 es
->bCaptureState
= TRUE
;
4333 SetCapture(wnd
->hwndSelf
);
4334 EDIT_ConfinePoint(es
, &x
, &y
);
4335 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
4336 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4337 EDIT_EM_ScrollCaret(wnd
, es
);
4338 es
->region_posx
= es
->region_posy
= 0;
4339 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
4344 /*********************************************************************
4349 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
)
4351 if (es
->bCaptureState
&& GetCapture() == hwndSelf
) {
4352 KillTimer(hwndSelf
, 0);
4355 es
->bCaptureState
= FALSE
;
4360 /*********************************************************************
4365 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
)
4367 SendMessageW(wnd
->hwndSelf
,WM_PASTE
,0,0);
4372 /*********************************************************************
4377 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
4383 if (GetCapture() != wnd
->hwndSelf
)
4387 * FIXME: gotta do some scrolling if outside client
4388 * area. Maybe reset the timer ?
4391 EDIT_ConfinePoint(es
, &x
, &y
);
4392 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4393 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4394 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
4395 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
4400 /*********************************************************************
4404 * See also EDIT_WM_StyleChanged
4406 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, DWORD style
, HWND hwndParent
, BOOL unicode
)
4411 TRACE("Creating %s edit control, style = %08lx %08lx\n",
4412 unicode
? "Unicode" : "ANSI", style
, wnd
->dwExStyle
);
4414 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4416 *(EDITSTATE
**)wnd
->wExtra
= es
;
4419 * Note: since the EDITSTATE has not been fully initialized yet,
4420 * we can't use any API calls that may send
4421 * WM_XXX messages before WM_NCCREATE is completed.
4424 es
->is_unicode
= unicode
;
4427 es
->bEnableState
= !(style
& WS_DISABLED
);
4430 * In Win95 look and feel, the WS_BORDER style is replaced by the
4431 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4432 * control a non client area. Not always. This coordinates in some
4433 * way with the window creation code in dialog.c When making
4434 * modifications please ensure that the code still works for edit
4435 * controls created directly with style 0x50800000, exStyle 0 (
4436 * which should have a single pixel border)
4438 if (TWEAK_WineLook
!= WIN31_LOOK
)
4440 es
->style
&= ~WS_BORDER
;
4444 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4445 wnd
->dwStyle
&= ~WS_BORDER
;
4448 /* Save parent, which will be notified by EN_* messages */
4449 es
->hwndParent
= hwndParent
;
4451 if (es
->style
& ES_COMBO
)
4452 es
->hwndListBox
= GetDlgItem(hwndParent
, ID_CB_LISTBOX
);
4454 /* Number overrides lowercase overrides uppercase (at least it
4455 * does in Win95). However I'll bet that ES_NUMBER would be
4456 * invalid under Win 3.1.
4458 if (es
->style
& ES_NUMBER
) {
4459 ; /* do not override the ES_NUMBER */
4460 } else if (es
->style
& ES_LOWERCASE
) {
4461 es
->style
&= ~ES_UPPERCASE
;
4463 if (es
->style
& ES_MULTILINE
) {
4464 es
->buffer_limit
= BUFLIMIT_MULTI
;
4465 if (es
->style
& WS_VSCROLL
)
4466 es
->style
|= ES_AUTOVSCROLL
;
4467 if (es
->style
& WS_HSCROLL
)
4468 es
->style
|= ES_AUTOHSCROLL
;
4469 es
->style
&= ~ES_PASSWORD
;
4470 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4471 /* Confirmed - RIGHT overrides CENTER */
4472 if (es
->style
& ES_RIGHT
)
4473 es
->style
&= ~ES_CENTER
;
4474 es
->style
&= ~WS_HSCROLL
;
4475 es
->style
&= ~ES_AUTOHSCROLL
;
4478 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4479 es
->style
|= ES_AUTOVSCROLL
;
4481 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4482 if (WIN31_LOOK
== TWEAK_WineLook
||
4483 WIN95_LOOK
== TWEAK_WineLook
) {
4484 es
->style
&= ~ES_CENTER
;
4485 es
->style
&= ~ES_RIGHT
;
4487 if (es
->style
& ES_RIGHT
)
4488 es
->style
&= ~ES_CENTER
;
4490 es
->style
&= ~WS_HSCROLL
;
4491 es
->style
&= ~WS_VSCROLL
;
4492 es
->style
&= ~ES_AUTOVSCROLL
;
4493 es
->style
&= ~ES_WANTRETURN
;
4494 if (es
->style
& ES_PASSWORD
)
4495 es
->password_char
= '*';
4497 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4498 es
->style
|= ES_AUTOHSCROLL
;
4501 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4502 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4504 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4506 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4508 es
->undo_buffer_size
= es
->buffer_size
;
4510 if (es
->style
& ES_MULTILINE
)
4511 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4518 /*********************************************************************
4523 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
4532 BOOL rev
= es
->bEnableState
&&
4533 ((es
->flags
& EF_FOCUSED
) ||
4534 (es
->style
& ES_NOHIDESEL
));
4536 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
4539 if(es
->style
& WS_BORDER
) {
4540 GetClientRect(wnd
->hwndSelf
, &rc
);
4541 if(es
->style
& ES_MULTILINE
) {
4542 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4543 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4545 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4547 IntersectClipRect(dc
, es
->format_rect
.left
,
4548 es
->format_rect
.top
,
4549 es
->format_rect
.right
,
4550 es
->format_rect
.bottom
);
4551 if (es
->style
& ES_MULTILINE
) {
4552 GetClientRect(wnd
->hwndSelf
, &rc
);
4553 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4556 old_font
= SelectObject(dc
, es
->font
);
4557 if ( get_app_version() >= 0x40000 &&(
4558 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
4559 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
4561 EDIT_SEND_CTLCOLOR(wnd
, dc
);
4563 if (!es
->bEnableState
)
4564 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4565 GetClipBox(dc
, &rcRgn
);
4566 if (es
->style
& ES_MULTILINE
) {
4567 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4568 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4569 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
4570 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4571 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
4574 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
4575 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4576 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
4579 SelectObject(dc
, old_font
);
4582 EndPaint(wnd
->hwndSelf
, &ps
);
4586 /*********************************************************************
4591 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
4596 /* Protect read-only edit control from modification */
4597 if(es
->style
& ES_READONLY
)
4600 OpenClipboard(wnd
->hwndSelf
);
4601 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4602 src
= (LPWSTR
)GlobalLock(hsrc
);
4603 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
, TRUE
);
4610 /*********************************************************************
4615 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
)
4617 es
->flags
|= EF_FOCUSED
;
4618 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
4619 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
4620 es
->flags
& EF_AFTER_WRAP
);
4621 if(!(es
->style
& ES_NOHIDESEL
))
4622 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
4623 ShowCaret(wnd
->hwndSelf
);
4624 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4628 /*********************************************************************
4632 * With Win95 look the margins are set to default font value unless
4633 * the system font (font == 0) is being set, in which case they are left
4637 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4645 dc
= GetDC(wnd
->hwndSelf
);
4647 old_font
= SelectObject(dc
, font
);
4648 GetTextMetricsW(dc
, &tm
);
4649 es
->line_height
= tm
.tmHeight
;
4650 es
->char_width
= tm
.tmAveCharWidth
;
4652 SelectObject(dc
, old_font
);
4653 ReleaseDC(wnd
->hwndSelf
, dc
);
4654 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4655 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4656 EC_USEFONTINFO
, EC_USEFONTINFO
);
4658 /* Force the recalculation of the format rect for each font change */
4659 GetClientRect(wnd
->hwndSelf
, &r
);
4660 EDIT_SetRectNP(wnd
, es
, &r
);
4662 if (es
->style
& ES_MULTILINE
)
4663 EDIT_BuildLineDefs_ML(wnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
4665 EDIT_CalcLineWidth_SL(wnd
, es
);
4668 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4669 if (es
->flags
& EF_FOCUSED
) {
4671 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
4672 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
4673 es
->flags
& EF_AFTER_WRAP
);
4674 ShowCaret(wnd
->hwndSelf
);
4679 /*********************************************************************
4684 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4685 * The modified flag is reset. No notifications are sent.
4687 * For single-line controls, reception of WM_SETTEXT triggers:
4688 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4691 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4696 text
= (LPWSTR
)lParam
;
4699 LPCSTR textA
= (LPCSTR
)lParam
;
4700 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4701 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4702 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4705 EDIT_EM_SetSel(wnd
, es
, 0, (UINT
)-1, FALSE
);
4707 TRACE("%s\n", debugstr_w(text
));
4708 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
, FALSE
);
4710 HeapFree(GetProcessHeap(), 0, text
);
4712 static const WCHAR empty_stringW
[] = {0};
4714 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, empty_stringW
, FALSE
);
4717 es
->flags
&= ~EF_MODIFIED
;
4718 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
4719 /* Send the notification after the selection start and end have been set
4720 * edit control doesn't send notification on WM_SETTEXT
4721 * if it is multiline, or it is part of combobox
4723 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4724 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4725 EDIT_EM_ScrollCaret(wnd
, es
);
4729 /*********************************************************************
4734 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4736 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4738 TRACE("width = %d, height = %d\n", width
, height
);
4739 SetRect(&rc
, 0, 0, width
, height
);
4740 EDIT_SetRectNP(wnd
, es
, &rc
);
4741 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4746 /*********************************************************************
4750 * This message is sent by SetWindowLong on having changed either the Style
4751 * or the extended style.
4753 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4755 * See also EDIT_WM_NCCreate
4757 * It appears that the Windows version of the edit control allows the style
4758 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4759 * style variable which will generally be different. In this function we
4760 * update the internal style based on what changed in the externally visible
4763 * Much of this content as based upon the MSDN, especially:
4764 * Platform SDK Documentation -> User Interface Services ->
4765 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4766 * Edit Control Styles
4768 static LRESULT
EDIT_WM_StyleChanged (WND
*wnd
,
4771 const STYLESTRUCT
*style
)
4773 if (GWL_STYLE
== which
) {
4774 DWORD style_change_mask
;
4776 /* Only a subset of changes can be applied after the control
4779 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4781 if (es
->style
& ES_MULTILINE
)
4782 style_change_mask
|= ES_WANTRETURN
;
4784 new_style
= style
->styleNew
& style_change_mask
;
4786 /* Number overrides lowercase overrides uppercase (at least it
4787 * does in Win95). However I'll bet that ES_NUMBER would be
4788 * invalid under Win 3.1.
4790 if (new_style
& ES_NUMBER
) {
4791 ; /* do not override the ES_NUMBER */
4792 } else if (new_style
& ES_LOWERCASE
) {
4793 new_style
&= ~ES_UPPERCASE
;
4796 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4797 } else if (GWL_EXSTYLE
== which
) {
4798 ; /* FIXME - what is needed here */
4800 WARN ("Invalid style change %d\n",which
);
4806 /*********************************************************************
4811 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4813 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4814 if (EDIT_EM_CanUndo(es
))
4815 EDIT_EM_Undo(wnd
, es
);
4817 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4818 if (EDIT_CheckCombo(wnd
, es
, WM_SYSKEYDOWN
, key
))
4821 return DefWindowProcW(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4825 /*********************************************************************
4830 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
)
4832 if (es
->region_posx
< 0) {
4833 EDIT_MoveBackward(wnd
, es
, TRUE
);
4834 } else if (es
->region_posx
> 0) {
4835 EDIT_MoveForward(wnd
, es
, TRUE
);
4838 * FIXME: gotta do some vertical scrolling here, like
4839 * EDIT_EM_LineScroll(wnd, 0, 1);
4843 /*********************************************************************
4848 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
)
4852 if (!(es
->style
& ES_MULTILINE
))
4855 if (!(es
->style
& ES_AUTOVSCROLL
))
4864 TRACE("action %d\n", action
);
4865 EDIT_EM_Scroll(wnd
, es
, action
);
4872 TRACE("SB_BOTTOM\n");
4873 dy
= es
->line_count
- 1 - es
->y_offset
;
4876 TRACE("SB_THUMBTRACK %d\n", pos
);
4877 es
->flags
|= EF_VSCROLL_TRACK
;
4878 if(es
->style
& WS_VSCROLL
)
4879 dy
= pos
- es
->y_offset
;
4882 /* Assume default scroll range 0-100 */
4885 if(pos
< 0 || pos
> 100) return 0;
4886 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4887 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4888 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4889 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4890 es
->line_count
, es
->y_offset
, pos
, dy
);
4893 case SB_THUMBPOSITION
:
4894 TRACE("SB_THUMBPOSITION %d\n", pos
);
4895 es
->flags
&= ~EF_VSCROLL_TRACK
;
4896 if(es
->style
& WS_VSCROLL
)
4897 dy
= pos
- es
->y_offset
;
4900 /* Assume default scroll range 0-100 */
4903 if(pos
< 0 || pos
> 100) return 0;
4904 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4905 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4906 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4907 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4908 es
->line_count
, es
->y_offset
, pos
, dy
);
4912 /* force scroll info update */
4913 EDIT_UpdateScrollInfo(wnd
, es
);
4914 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4918 TRACE("SB_ENDSCROLL\n");
4921 * FIXME : the next two are undocumented !
4922 * Are we doing the right thing ?
4923 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4924 * although it's also a regular control message.
4926 case EM_GETTHUMB
: /* this one is used by NT notepad */
4930 if(wnd
->dwStyle
& WS_VSCROLL
)
4931 ret
= GetScrollPos(wnd
->hwndSelf
, SB_VERT
);
4934 /* Assume default scroll range 0-100 */
4935 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4936 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4938 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4941 case EM_LINESCROLL16
:
4942 TRACE("EM_LINESCROLL16 %d\n", pos
);
4947 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4952 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4956 /*********************************************************************
4961 static void EDIT_UpdateTextRegion(WND
*wnd
, HRGN hrgn
, BOOL bErase
)
4963 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
4965 if (es
->flags
& EF_UPDATE
)
4966 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4968 InvalidateRgn(wnd
->hwndSelf
, hrgn
, bErase
);
4972 /*********************************************************************
4977 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
)
4979 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
4981 if (es
->flags
& EF_UPDATE
)
4982 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4984 InvalidateRect(wnd
->hwndSelf
, rc
, bErase
);