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(hwnd,hdc) \
134 (SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC, \
135 (WPARAM)(hdc), (LPARAM)(hwnd)))
136 #define EDIT_SEND_CTLCOLOR(hwnd,hdc) \
137 (SendMessageW(GetParent(hwnd), WM_CTLCOLOREDIT, \
138 (WPARAM)(hdc), (LPARAM)(hwnd)))
139 #define EDIT_NOTIFY_PARENT(hwnd, 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(GetWindowLongA((hwnd),GWL_ID), wNotifyCode), \
147 #define DPRINTF_EDIT_MSG16(str) \
149 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
150 hwnd, (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 hwnd, (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(HWND hwnd
, EDITSTATE
*es
);
171 static inline void EDIT_WM_Cut(HWND hwnd
, EDITSTATE
*es
);
174 * Helper functions only valid for one type of control
176 static void EDIT_BuildLineDefs_ML(HWND hwnd
, EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
177 static void EDIT_CalcLineWidth_SL(HWND hwnd
, EDITSTATE
*es
);
178 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
179 static void EDIT_MoveDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
180 static void EDIT_MovePageDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
181 static void EDIT_MovePageUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
182 static void EDIT_MoveUp_ML(HWND hwnd
, 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(HWND hwnd
, 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(HWND hwnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
190 static void EDIT_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
);
191 static void EDIT_LockBuffer(HWND hwnd
, EDITSTATE
*es
);
192 static BOOL
EDIT_MakeFit(HWND hwnd
, EDITSTATE
*es
, UINT size
);
193 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
194 static void EDIT_MoveBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
195 static void EDIT_MoveEnd(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
196 static void EDIT_MoveForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
197 static void EDIT_MoveHome(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
198 static void EDIT_MoveWordBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
199 static void EDIT_MoveWordForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
200 static void EDIT_PaintLine(HWND hwnd
, 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(HWND hwnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
203 static void EDIT_SetRectNP(HWND hwnd
, EDITSTATE
*es
, LPRECT lprc
);
204 static void EDIT_UnlockBuffer(HWND hwnd
, EDITSTATE
*es
, BOOL force
);
205 static void EDIT_UpdateScrollInfo(HWND hwnd
, 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(HWND hwnd
, 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(HWND hwnd
, 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(HWND hwnd
, 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(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
);
221 static BOOL
EDIT_EM_LineScroll_internal(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
);
222 static LRESULT
EDIT_EM_PosFromChar(HWND hwnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
223 static void EDIT_EM_ReplaceSel(HWND hwnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
);
224 static LRESULT
EDIT_EM_Scroll(HWND hwnd
, EDITSTATE
*es
, INT action
);
225 static void EDIT_EM_ScrollCaret(HWND hwnd
, EDITSTATE
*es
);
226 static void EDIT_EM_SetHandle(HWND hwnd
, EDITSTATE
*es
, HLOCAL hloc
);
227 static void EDIT_EM_SetHandle16(HWND hwnd
, 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(HWND hwnd
, EDITSTATE
*es
, WCHAR c
);
231 static void EDIT_EM_SetSel(HWND hwnd
, 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(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
);
235 static void EDIT_EM_SetWordBreakProc16(HWND hwnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
236 static BOOL
EDIT_EM_Undo(HWND hwnd
, EDITSTATE
*es
);
238 * WM_XXX message handlers
240 static void EDIT_WM_Char(HWND hwnd
, EDITSTATE
*es
, WCHAR c
);
241 static void EDIT_WM_Command(HWND hwnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
242 static void EDIT_WM_ContextMenu(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
);
243 static void EDIT_WM_Copy(HWND hwnd
, EDITSTATE
*es
);
244 static LRESULT
EDIT_WM_Create(HWND hwnd
, EDITSTATE
*es
, LPCWSTR name
);
245 static void EDIT_WM_Destroy(HWND hwnd
, EDITSTATE
*es
);
246 static LRESULT
EDIT_WM_EraseBkGnd(HWND hwnd
, EDITSTATE
*es
, HDC dc
);
247 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
248 static LRESULT
EDIT_WM_HScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
);
249 static LRESULT
EDIT_WM_KeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
);
250 static LRESULT
EDIT_WM_KillFocus(HWND hwnd
, EDITSTATE
*es
);
251 static LRESULT
EDIT_WM_LButtonDblClk(HWND hwnd
, EDITSTATE
*es
);
252 static LRESULT
EDIT_WM_LButtonDown(HWND hwnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
253 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
);
254 static LRESULT
EDIT_WM_MButtonDown(HWND hwnd
);
255 static LRESULT
EDIT_WM_MouseMove(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
);
256 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, DWORD style
, HWND hwndParent
, BOOL unicode
);
257 static void EDIT_WM_Paint(HWND hwnd
, EDITSTATE
*es
, WPARAM wParam
);
258 static void EDIT_WM_Paste(HWND hwnd
, EDITSTATE
*es
);
259 static void EDIT_WM_SetFocus(HWND hwnd
, EDITSTATE
*es
);
260 static void EDIT_WM_SetFont(HWND hwnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
261 static void EDIT_WM_SetText(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
262 static void EDIT_WM_Size(HWND hwnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
263 static LRESULT
EDIT_WM_StyleChanged (HWND hwnd
, EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
264 static LRESULT
EDIT_WM_SysKeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
265 static void EDIT_WM_Timer(HWND hwnd
, EDITSTATE
*es
);
266 static LRESULT
EDIT_WM_VScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
);
267 static void EDIT_UpdateText(HWND hwnd
, EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
268 static void EDIT_UpdateTextRegion(HWND hwnd
, EDITSTATE
*es
, 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(HWND hwnd
, 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(hwnd
, es
, TRUE
, empty_stringW
, TRUE
);
328 /*********************************************************************
333 static inline void EDIT_WM_Cut(HWND hwnd
, EDITSTATE
*es
)
335 EDIT_WM_Copy(hwnd
, es
);
336 EDIT_WM_Clear(hwnd
, 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_common( HWND hwnd
, UINT msg
,
390 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
392 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongA( hwnd
, 0 );
397 DPRINTF_EDIT_MSG32("WM_DESTROY");
398 if (es
) EDIT_WM_Destroy(hwnd
, es
);
403 DPRINTF_EDIT_MSG32("WM_NCCREATE");
406 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
407 result
= EDIT_WM_NCCreate(hwnd
, cs
->style
, cs
->hwndParent
, TRUE
);
411 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
412 result
= EDIT_WM_NCCreate(hwnd
, cs
->style
, cs
->hwndParent
, FALSE
);
420 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
422 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
427 EDIT_LockBuffer(hwnd
, 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(hwnd
, es
, (UINT
)-1, 0, FALSE
);
444 EDIT_EM_SetSel(hwnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
446 EDIT_EM_ScrollCaret(hwnd
, es
);
450 DPRINTF_EDIT_MSG32("EM_SETSEL");
451 EDIT_EM_SetSel(hwnd
, es
, wParam
, lParam
, FALSE
);
452 EDIT_EM_ScrollCaret(hwnd
, 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(hwnd
, es
, &rc
);
473 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
477 DPRINTF_EDIT_MSG32("EM_SETRECT");
478 if ((es
->style
& ES_MULTILINE
) && lParam
) {
479 EDIT_SetRectNP(hwnd
, es
, (LPRECT
)lParam
);
480 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
485 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
486 if ((es
->style
& ES_MULTILINE
) && lParam
) {
488 CONV_RECT16TO32(MapSL(lParam
), &rc
);
489 EDIT_SetRectNP(hwnd
, es
, &rc
);
493 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
494 if ((es
->style
& ES_MULTILINE
) && lParam
)
495 EDIT_SetRectNP(hwnd
, es
, (LPRECT
)lParam
);
499 DPRINTF_EDIT_MSG16("EM_SCROLL");
502 DPRINTF_EDIT_MSG32("EM_SCROLL");
503 result
= EDIT_EM_Scroll(hwnd
, 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(hwnd
, 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(hwnd
, 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(hwnd
, es
, (HLOCAL16
)wParam
);
567 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
568 EDIT_EM_SetHandle(hwnd
, es
, (HLOCAL
)wParam
);
572 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
573 result
= (LRESULT
)EDIT_EM_GetHandle16(hwnd
, 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(hwnd
, 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");
595 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
599 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
602 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
603 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
606 case EM_LINELENGTH16
:
607 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
610 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
611 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
614 case EM_REPLACESEL16
:
615 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
616 lParam
= (LPARAM
)MapSL(lParam
);
617 unicode
= FALSE
; /* 16-bit message is always ascii */
622 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
625 textW
= (LPWSTR
)lParam
;
628 LPSTR textA
= (LPSTR
)lParam
;
629 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
630 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
631 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
634 EDIT_EM_ReplaceSel(hwnd
, es
, (BOOL
)wParam
, textW
, TRUE
);
638 HeapFree(GetProcessHeap(), 0, textW
);
641 /* message 0x00c3 missing from specs */
644 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
647 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
648 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
652 DPRINTF_EDIT_MSG16("EM_GETLINE");
653 lParam
= (LPARAM
)MapSL(lParam
);
654 unicode
= FALSE
; /* 16-bit message is always ascii */
657 DPRINTF_EDIT_MSG32("EM_GETLINE");
658 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, lParam
, unicode
);
662 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
664 case EM_SETLIMITTEXT
:
665 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
666 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
670 DPRINTF_EDIT_MSG16("EM_CANUNDO");
673 DPRINTF_EDIT_MSG32("EM_CANUNDO");
674 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
678 DPRINTF_EDIT_MSG16("EM_UNDO");
683 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
684 result
= (LRESULT
)EDIT_EM_Undo(hwnd
, es
);
688 DPRINTF_EDIT_MSG16("EM_FMTLINES");
691 DPRINTF_EDIT_MSG32("EM_FMTLINES");
692 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
695 case EM_LINEFROMCHAR16
:
696 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
698 case EM_LINEFROMCHAR
:
699 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
700 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
703 /* message 0x00ca missing from specs */
706 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
709 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
710 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
713 case EM_SETTABSTOPS16
:
714 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
715 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
718 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
719 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
722 case EM_SETPASSWORDCHAR16
:
723 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
724 unicode
= FALSE
; /* 16-bit message is always ascii */
726 case EM_SETPASSWORDCHAR
:
729 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
732 charW
= (WCHAR
)wParam
;
736 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
739 EDIT_EM_SetPasswordChar(hwnd
, es
, charW
);
743 case EM_EMPTYUNDOBUFFER16
:
744 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
746 case EM_EMPTYUNDOBUFFER
:
747 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
748 EDIT_EM_EmptyUndoBuffer(es
);
751 case EM_GETFIRSTVISIBLELINE16
:
752 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
753 result
= es
->y_offset
;
755 case EM_GETFIRSTVISIBLELINE
:
756 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
757 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
760 case EM_SETREADONLY16
:
761 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
764 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
766 SetWindowLongA( hwnd
, GWL_STYLE
,
767 GetWindowLongA( hwnd
, GWL_STYLE
) | ES_READONLY
);
768 es
->style
|= ES_READONLY
;
770 SetWindowLongA( hwnd
, GWL_STYLE
,
771 GetWindowLongA( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
772 es
->style
&= ~ES_READONLY
;
777 case EM_SETWORDBREAKPROC16
:
778 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
779 EDIT_EM_SetWordBreakProc16(hwnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
781 case EM_SETWORDBREAKPROC
:
782 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
783 EDIT_EM_SetWordBreakProc(hwnd
, es
, lParam
);
786 case EM_GETWORDBREAKPROC16
:
787 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
788 result
= (LRESULT
)es
->word_break_proc16
;
790 case EM_GETWORDBREAKPROC
:
791 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
792 result
= (LRESULT
)es
->word_break_proc
;
795 case EM_GETPASSWORDCHAR16
:
796 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
797 unicode
= FALSE
; /* 16-bit message is always ascii */
799 case EM_GETPASSWORDCHAR
:
801 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
804 result
= es
->password_char
;
807 WCHAR charW
= es
->password_char
;
809 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
815 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
818 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
819 EDIT_EM_SetMargins(es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
823 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
824 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
827 case EM_GETLIMITTEXT
:
828 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
829 result
= es
->buffer_limit
;
833 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
834 result
= EDIT_EM_PosFromChar(hwnd
, es
, (INT
)wParam
, FALSE
);
838 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
839 result
= EDIT_EM_CharFromPos(hwnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
842 /* End of the EM_ messages which were in numerical order; what order
843 * are these in? vaguely alphabetical?
847 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
848 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
850 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
852 int vk
= (int)((LPMSG
)lParam
)->wParam
;
854 if (vk
== VK_RETURN
&& (GetWindowLongA( hwnd
, GWL_STYLE
) & ES_WANTRETURN
))
856 result
|= DLGC_WANTMESSAGE
;
858 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
860 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
861 result
|= DLGC_WANTMESSAGE
;
869 DPRINTF_EDIT_MSG32("WM_CHAR");
876 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
879 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
881 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
882 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
885 EDIT_WM_Char(hwnd
, es
, charW
);
890 DPRINTF_EDIT_MSG32("WM_CLEAR");
891 EDIT_WM_Clear(hwnd
, es
);
895 DPRINTF_EDIT_MSG32("WM_COMMAND");
896 EDIT_WM_Command(hwnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
900 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
901 EDIT_WM_ContextMenu(hwnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
905 DPRINTF_EDIT_MSG32("WM_COPY");
906 EDIT_WM_Copy(hwnd
, es
);
910 DPRINTF_EDIT_MSG32("WM_CREATE");
912 result
= EDIT_WM_Create(hwnd
, es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
915 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
919 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
920 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
921 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
923 result
= EDIT_WM_Create(hwnd
, es
, nameW
);
925 HeapFree(GetProcessHeap(), 0, nameW
);
930 DPRINTF_EDIT_MSG32("WM_CUT");
931 EDIT_WM_Cut(hwnd
, es
);
935 DPRINTF_EDIT_MSG32("WM_ENABLE");
936 es
->bEnableState
= (BOOL
) wParam
;
937 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
941 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
942 result
= EDIT_WM_EraseBkGnd(hwnd
, es
, (HDC
)wParam
);
946 DPRINTF_EDIT_MSG32("WM_GETFONT");
947 result
= (LRESULT
)es
->font
;
951 DPRINTF_EDIT_MSG32("WM_GETTEXT");
952 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
955 case WM_GETTEXTLENGTH
:
956 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
957 result
= strlenW(es
->text
);
961 DPRINTF_EDIT_MSG32("WM_HSCROLL");
962 result
= EDIT_WM_HScroll(hwnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
966 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
967 result
= EDIT_WM_KeyDown(hwnd
, es
, (INT
)wParam
);
971 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
972 result
= EDIT_WM_KillFocus(hwnd
, es
);
975 case WM_LBUTTONDBLCLK
:
976 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
977 result
= EDIT_WM_LButtonDblClk(hwnd
, es
);
981 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
982 result
= EDIT_WM_LButtonDown(hwnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
986 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
987 result
= EDIT_WM_LButtonUp(hwnd
, es
);
991 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
992 result
= EDIT_WM_MButtonDown(hwnd
);
995 case WM_MOUSEACTIVATE
:
997 * FIXME: maybe DefWindowProc() screws up, but it seems that
998 * modeless dialog boxes need this. If we don't do this, the focus
999 * will _not_ be set by DefWindowProc() for edit controls in a
1000 * modeless dialog box ???
1002 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
1004 result
= MA_ACTIVATE
;
1009 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
1011 result
= EDIT_WM_MouseMove(hwnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
1015 DPRINTF_EDIT_MSG32("WM_PAINT");
1016 EDIT_WM_Paint(hwnd
, es
, wParam
);
1020 DPRINTF_EDIT_MSG32("WM_PASTE");
1021 EDIT_WM_Paste(hwnd
, es
);
1025 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
1026 EDIT_WM_SetFocus(hwnd
, es
);
1030 DPRINTF_EDIT_MSG32("WM_SETFONT");
1031 EDIT_WM_SetFont(hwnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
1035 /* FIXME: actually set an internal flag and behave accordingly */
1039 DPRINTF_EDIT_MSG32("WM_SETTEXT");
1040 EDIT_WM_SetText(hwnd
, es
, lParam
, unicode
);
1045 DPRINTF_EDIT_MSG32("WM_SIZE");
1046 EDIT_WM_Size(hwnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1049 case WM_STYLECHANGED
:
1050 DPRINTF_EDIT_MSG32("WM_STYLECHANGED");
1051 result
= EDIT_WM_StyleChanged (hwnd
, es
, wParam
, (const STYLESTRUCT
*)lParam
);
1054 case WM_STYLECHANGING
:
1055 DPRINTF_EDIT_MSG32("WM_STYLECHANGING");
1056 result
= 0; /* See EDIT_WM_StyleChanged */
1060 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
1061 result
= EDIT_WM_SysKeyDown(hwnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
1065 DPRINTF_EDIT_MSG32("WM_TIMER");
1066 EDIT_WM_Timer(hwnd
, es
);
1070 DPRINTF_EDIT_MSG32("WM_VSCROLL");
1071 result
= EDIT_WM_VScroll(hwnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
1076 int gcWheelDelta
= 0;
1077 UINT pulScrollLines
= 3;
1078 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1080 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1081 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1084 gcWheelDelta
-= SHIWORD(wParam
);
1085 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1087 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1088 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1089 result
= EDIT_EM_LineScroll(hwnd
, es
, 0, cLineScroll
);
1095 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1097 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
1100 EDIT_UnlockBuffer(hwnd
, es
, FALSE
);
1105 /*********************************************************************
1107 * EditWndProcW (USER32.@)
1109 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1111 if (!IsWindow( hWnd
)) return 0;
1112 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1115 /*********************************************************************
1117 * EditWndProc (USER32.@)
1119 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1121 if (!IsWindow( hWnd
)) return 0;
1122 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1125 /*********************************************************************
1127 * EDIT_BuildLineDefs_ML
1129 * Build linked list of text lines.
1130 * Lines can end with '\0' (last line), a character (if it is wrapped),
1131 * a soft return '\r\r\n' or a hard return '\r\n'
1134 static void EDIT_BuildLineDefs_ML(HWND hwnd
, EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1138 LPWSTR current_position
, cp
;
1140 LINEDEF
*current_line
;
1141 LINEDEF
*previous_line
;
1142 LINEDEF
*start_line
;
1143 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1144 INT line_count
= es
->line_count
;
1145 INT orig_net_length
;
1148 if (istart
== iend
&& delta
== 0)
1153 old_font
= SelectObject(dc
, es
->font
);
1155 previous_line
= NULL
;
1156 current_line
= es
->first_line_def
;
1158 /* Find starting line. istart must lie inside an existing line or
1159 * at the end of buffer */
1161 if (istart
< current_line
->index
+ current_line
->length
||
1162 current_line
->ending
== END_0
)
1165 previous_line
= current_line
;
1166 current_line
= current_line
->next
;
1168 } while (current_line
);
1170 if (!current_line
) /* Error occurred start is not inside previous buffer */
1172 FIXME(" modification occurred outside buffer\n");
1176 /* Remember start of modifications in order to calculate update region */
1177 nstart_line
= line_index
;
1178 nstart_index
= current_line
->index
;
1180 /* We must start to reformat from the previous line since the modifications
1181 * may have caused the line to wrap upwards. */
1182 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1185 current_line
= previous_line
;
1187 start_line
= current_line
;
1189 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1190 current_position
= es
->text
+ current_line
->index
;
1192 if (current_line
!= start_line
)
1194 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1196 /* The buffer has been expanded, create a new line and
1197 insert it into the link list */
1198 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1199 new_line
->next
= previous_line
->next
;
1200 previous_line
->next
= new_line
;
1201 current_line
= new_line
;
1204 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1206 /* The previous line merged with this line so we delete this extra entry */
1207 previous_line
->next
= current_line
->next
;
1208 HeapFree(GetProcessHeap(), 0, current_line
);
1209 current_line
= previous_line
->next
;
1213 else /* current_line->index + delta == current_position */
1215 if (current_position
- es
->text
> iend
)
1216 break; /* We reached end of line modifications */
1217 /* else recalulate this line */
1221 current_line
->index
= current_position
- es
->text
;
1222 orig_net_length
= current_line
->net_length
;
1224 /* Find end of line */
1225 cp
= current_position
;
1227 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1232 /* Mark type of line termination */
1234 current_line
->ending
= END_0
;
1235 current_line
->net_length
= strlenW(current_position
);
1236 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1237 current_line
->ending
= END_SOFT
;
1238 current_line
->net_length
= cp
- current_position
- 1;
1240 current_line
->ending
= END_HARD
;
1241 current_line
->net_length
= cp
- current_position
;
1244 /* Calculate line width */
1245 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1246 current_position
, current_line
->net_length
,
1247 es
->tabs_count
, es
->tabs
));
1249 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1250 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1255 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1256 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1257 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1258 current_position
, next
, es
->tabs_count
, es
->tabs
));
1259 } while (current_line
->width
<= fw
);
1260 if (!prev
) { /* Didn't find a line break so force a break */
1265 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1266 current_position
, next
, es
->tabs_count
, es
->tabs
));
1267 } while (current_line
->width
<= fw
);
1272 /* If the first line we are calculating, wrapped before istart, we must
1273 * adjust istart in order for this to be reflected in the update region. */
1274 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1275 istart
= current_line
->index
+ prev
;
1276 /* else if we are updating the previous line before the first line we
1277 * are re-calculating and it expanded */
1278 else if (current_line
== start_line
&&
1279 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1281 /* Line expanded due to an upwards line wrap so we must partially include
1282 * previous line in update region */
1283 nstart_line
= line_index
;
1284 nstart_index
= current_line
->index
;
1285 istart
= current_line
->index
+ orig_net_length
;
1288 current_line
->net_length
= prev
;
1289 current_line
->ending
= END_WRAP
;
1290 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1291 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1295 /* Adjust length to include line termination */
1296 switch (current_line
->ending
) {
1298 current_line
->length
= current_line
->net_length
+ 3;
1301 current_line
->length
= current_line
->net_length
+ 2;
1305 current_line
->length
= current_line
->net_length
;
1308 es
->text_width
= max(es
->text_width
, current_line
->width
);
1309 current_position
+= current_line
->length
;
1310 previous_line
= current_line
;
1311 current_line
= current_line
->next
;
1313 } while (previous_line
->ending
!= END_0
);
1315 /* Finish adjusting line indexes by delta or remove hanging lines */
1316 if (previous_line
->ending
== END_0
)
1318 LINEDEF
*pnext
= NULL
;
1320 previous_line
->next
= NULL
;
1321 while (current_line
)
1323 pnext
= current_line
->next
;
1324 HeapFree(GetProcessHeap(), 0, current_line
);
1325 current_line
= pnext
;
1331 while (current_line
)
1333 current_line
->index
+= delta
;
1334 current_line
= current_line
->next
;
1338 /* Calculate rest of modification rectangle */
1343 * We calculate two rectangles. One for the first line which may have
1344 * an indent with respect to the format rect. The other is a format-width
1345 * rectangle that spans the rest of the lines that changed or moved.
1347 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1348 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1349 rc
.bottom
= rc
.top
+ es
->line_height
;
1350 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1351 es
->text
+ nstart_index
, istart
- nstart_index
,
1352 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1353 rc
.right
= es
->format_rect
.right
;
1354 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1357 rc
.left
= es
->format_rect
.left
;
1358 rc
.right
= es
->format_rect
.right
;
1360 * If lines were added or removed we must re-paint the remainder of the
1361 * lines since the remaining lines were either shifted up or down.
1363 if (line_count
< es
->line_count
) /* We added lines */
1364 rc
.bottom
= es
->line_count
* es
->line_height
;
1365 else if (line_count
> es
->line_count
) /* We removed lines */
1366 rc
.bottom
= line_count
* es
->line_height
;
1368 rc
.bottom
= line_index
* es
->line_height
;
1369 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1370 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1371 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1372 DeleteObject(tmphrgn
);
1376 SelectObject(dc
, old_font
);
1378 ReleaseDC(hwnd
, dc
);
1381 /*********************************************************************
1383 * EDIT_CalcLineWidth_SL
1386 static void EDIT_CalcLineWidth_SL(HWND hwnd
, EDITSTATE
*es
)
1388 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, strlenW(es
->text
), FALSE
));
1391 /*********************************************************************
1393 * EDIT_CallWordBreakProc
1395 * Call appropriate WordBreakProc (internal or external).
1397 * Note: The "start" argument should always be an index referring
1398 * to es->text. The actual wordbreak proc might be
1399 * 16 bit, so we can't always pass any 32 bit LPSTR.
1400 * Hence we assume that es->text is the buffer that holds
1401 * the string under examination (we can decide this for ourselves).
1404 /* ### start build ### */
1405 extern WORD CALLBACK
EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16
,SEGPTR
,WORD
,WORD
,WORD
);
1406 /* ### stop build ### */
1407 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1409 INT ret
, iWndsLocks
;
1411 /* To avoid any deadlocks, all the locks on the window structures
1412 must be suspended before the control is passed to the application */
1413 iWndsLocks
= WIN_SuspendWndsLock();
1415 if (es
->word_break_proc16
) {
1420 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1421 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1422 segptr
= K32WOWGlobalLock16(hglob16
);
1423 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1424 ret
= (INT
)EDIT_CallTo16_word_lwww(es
->word_break_proc16
,
1425 segptr
, index
, countA
, action
);
1426 GlobalUnlock16(hglob16
);
1427 GlobalFree16(hglob16
);
1429 else if (es
->word_break_proc
)
1433 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1435 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1436 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1437 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1441 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1445 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1446 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1447 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1448 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1449 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1450 ret
= wbpA(textA
, index
, countA
, action
);
1451 HeapFree(GetProcessHeap(), 0, textA
);
1455 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1457 WIN_RestoreWndsLock(iWndsLocks
);
1462 /*********************************************************************
1466 * Beware: This is not the function called on EM_CHARFROMPOS
1467 * The position _can_ be outside the formatting / client
1469 * The return value is only the character index
1472 static INT
EDIT_CharFromPos(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1478 if (es
->style
& ES_MULTILINE
) {
1479 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1481 LINEDEF
*line_def
= es
->first_line_def
;
1483 while ((line
> 0) && line_def
->next
) {
1484 line_index
+= line_def
->length
;
1485 line_def
= line_def
->next
;
1488 x
+= es
->x_offset
- es
->format_rect
.left
;
1489 if (x
>= line_def
->width
) {
1491 *after_wrap
= (line_def
->ending
== END_WRAP
);
1492 return line_index
+ line_def
->net_length
;
1496 *after_wrap
= FALSE
;
1501 old_font
= SelectObject(dc
, es
->font
);
1502 low
= line_index
+ 1;
1503 high
= line_index
+ line_def
->net_length
+ 1;
1504 while (low
< high
- 1)
1506 INT mid
= (low
+ high
) / 2;
1507 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1513 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1514 (line_def
->ending
== END_WRAP
));
1519 *after_wrap
= FALSE
;
1520 x
-= es
->format_rect
.left
;
1522 return es
->x_offset
;
1523 text
= EDIT_GetPasswordPointer_SL(es
);
1526 old_font
= SelectObject(dc
, es
->font
);
1530 INT high
= es
->x_offset
;
1531 while (low
< high
- 1)
1533 INT mid
= (low
+ high
) / 2;
1534 GetTextExtentPoint32W( dc
, text
+ mid
,
1535 es
->x_offset
- mid
, &size
);
1536 if (size
.cx
> -x
) low
= mid
;
1543 INT low
= es
->x_offset
;
1544 INT high
= strlenW(es
->text
) + 1;
1545 while (low
< high
- 1)
1547 INT mid
= (low
+ high
) / 2;
1548 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1549 mid
- es
->x_offset
, &size
);
1550 if (size
.cx
> x
) high
= mid
;
1555 if (es
->style
& ES_PASSWORD
)
1556 HeapFree(GetProcessHeap(), 0, text
);
1559 SelectObject(dc
, old_font
);
1560 ReleaseDC(hwnd
, dc
);
1565 /*********************************************************************
1569 * adjusts the point to be within the formatting rectangle
1570 * (so CharFromPos returns the nearest _visible_ character)
1573 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1575 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1576 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1580 /*********************************************************************
1584 * Calculates the bounding rectangle for a line from a starting
1585 * column to an ending column.
1588 static void EDIT_GetLineRect(HWND hwnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1590 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1592 if (es
->style
& ES_MULTILINE
)
1593 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1595 rc
->top
= es
->format_rect
.top
;
1596 rc
->bottom
= rc
->top
+ es
->line_height
;
1597 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, line_index
+ scol
, TRUE
));
1598 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, line_index
+ ecol
, TRUE
));
1602 /*********************************************************************
1604 * EDIT_GetPasswordPointer_SL
1606 * note: caller should free the (optionally) allocated buffer
1609 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1611 if (es
->style
& ES_PASSWORD
) {
1612 INT len
= strlenW(es
->text
);
1613 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1615 while(len
) text
[--len
] = es
->password_char
;
1622 /*********************************************************************
1626 * This acts as a LOCAL_Lock(), but it locks only once. This way
1627 * you can call it whenever you like, without unlocking.
1630 static void EDIT_LockBuffer(HWND hwnd
, EDITSTATE
*es
)
1632 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
1634 ERR("no EDITSTATE ... please report\n");
1640 BOOL _16bit
= FALSE
;
1646 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1647 textA
= LocalLock(es
->hloc32A
);
1648 countA
= strlen(textA
) + 1;
1652 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1653 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1654 countA
= strlen(textA
) + 1;
1659 ERR("no buffer ... please report\n");
1666 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1667 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1668 if(countW_new
> es
->buffer_size
+ 1)
1670 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1671 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1672 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1675 es
->hloc32W
= hloc32W_new
;
1676 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1677 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1680 WARN("FAILED! Will synchronize partially\n");
1684 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1685 es
->text
= LocalLock(es
->hloc32W
);
1689 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1691 LOCAL_Unlock(hInstance
, es
->hloc16
);
1693 LocalUnlock(es
->hloc32A
);
1700 /*********************************************************************
1702 * EDIT_SL_InvalidateText
1704 * Called from EDIT_InvalidateText().
1705 * Does the job for single-line controls only.
1708 static void EDIT_SL_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
)
1713 EDIT_GetLineRect(hwnd
, es
, 0, start
, end
, &line_rect
);
1714 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1715 EDIT_UpdateText(hwnd
, es
, &rc
, FALSE
);
1719 /*********************************************************************
1721 * EDIT_ML_InvalidateText
1723 * Called from EDIT_InvalidateText().
1724 * Does the job for multi-line controls only.
1727 static void EDIT_ML_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
)
1729 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1730 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1731 INT el
= EDIT_EM_LineFromChar(es
, end
);
1740 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1743 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1744 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1745 if (sl
< es
->y_offset
) {
1749 if (el
> es
->y_offset
+ vlc
) {
1750 el
= es
->y_offset
+ vlc
;
1751 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1753 GetClientRect(hwnd
, &rc1
);
1754 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1756 EDIT_GetLineRect(hwnd
, es
, sl
, sc
, ec
, &rcLine
);
1757 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1758 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1760 EDIT_GetLineRect(hwnd
, es
, sl
, sc
,
1761 EDIT_EM_LineLength(es
,
1762 EDIT_EM_LineIndex(es
, sl
)),
1764 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1765 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1766 for (l
= sl
+ 1 ; l
< el
; l
++) {
1767 EDIT_GetLineRect(hwnd
, es
, l
, 0,
1768 EDIT_EM_LineLength(es
,
1769 EDIT_EM_LineIndex(es
, l
)),
1771 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1772 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1774 EDIT_GetLineRect(hwnd
, es
, el
, 0, ec
, &rcLine
);
1775 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1776 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1781 /*********************************************************************
1783 * EDIT_InvalidateText
1785 * Invalidate the text from offset start upto, but not including,
1786 * offset end. Useful for (re)painting the selection.
1787 * Regions outside the linewidth are not invalidated.
1788 * end == -1 means end == TextLength.
1789 * start and end need not be ordered.
1792 static void EDIT_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
)
1798 end
= strlenW(es
->text
);
1800 ORDER_INT(start
, end
);
1802 if (es
->style
& ES_MULTILINE
)
1803 EDIT_ML_InvalidateText(hwnd
, es
, start
, end
);
1805 EDIT_SL_InvalidateText(hwnd
, es
, start
, end
);
1809 /*********************************************************************
1813 * Try to fit size + 1 characters in the buffer. Constrain to limits.
1816 static BOOL
EDIT_MakeFit(HWND hwnd
, EDITSTATE
*es
, UINT size
)
1820 if (size
<= es
->buffer_size
)
1822 if (size
> es
->buffer_limit
) {
1823 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_MAXTEXT
, "EN_MAXTEXT");
1826 if (size
> es
->buffer_limit
)
1827 size
= es
->buffer_limit
;
1829 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1831 /* Force edit to unlock it's buffer. es->text now NULL */
1832 EDIT_UnlockBuffer(hwnd
, es
, TRUE
);
1835 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1836 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1837 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32W
, hNew32W
);
1838 es
->hloc32W
= hNew32W
;
1839 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1843 EDIT_LockBuffer(hwnd
, es
);
1845 if (es
->buffer_size
< size
) {
1846 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1847 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_ERRSPACE
, "EN_ERRSPACE");
1850 TRACE("We now have %d+1\n", es
->buffer_size
);
1856 /*********************************************************************
1860 * Try to fit size + 1 bytes in the undo buffer.
1863 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1867 if (size
<= es
->undo_buffer_size
)
1870 TRACE("trying to ReAlloc to %d+1\n", size
);
1872 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1873 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1874 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
);
1879 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1885 /*********************************************************************
1890 static void EDIT_MoveBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1892 INT e
= es
->selection_end
;
1896 if ((es
->style
& ES_MULTILINE
) && e
&&
1897 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1899 if (e
&& (es
->text
[e
- 1] == '\r'))
1903 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1904 EDIT_EM_ScrollCaret(hwnd
, es
);
1908 /*********************************************************************
1912 * Only for multi line controls
1913 * Move the caret one line down, on a column with the nearest
1914 * x coordinate on the screen (might be a different column).
1917 static void EDIT_MoveDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1919 INT s
= es
->selection_start
;
1920 INT e
= es
->selection_end
;
1921 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1922 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
1923 INT x
= SLOWORD(pos
);
1924 INT y
= SHIWORD(pos
);
1926 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1929 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
1930 EDIT_EM_ScrollCaret(hwnd
, es
);
1934 /*********************************************************************
1939 static void EDIT_MoveEnd(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1941 BOOL after_wrap
= FALSE
;
1944 /* Pass a high value in x to make sure of receiving the end of the line */
1945 if (es
->style
& ES_MULTILINE
)
1946 e
= EDIT_CharFromPos(hwnd
, es
, 0x3fffffff,
1947 HIWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1949 e
= strlenW(es
->text
);
1950 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1951 EDIT_EM_ScrollCaret(hwnd
, es
);
1955 /*********************************************************************
1960 static void EDIT_MoveForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1962 INT e
= es
->selection_end
;
1966 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1967 if (es
->text
[e
] == '\n')
1969 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1973 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1974 EDIT_EM_ScrollCaret(hwnd
, es
);
1978 /*********************************************************************
1982 * Home key: move to beginning of line.
1985 static void EDIT_MoveHome(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1989 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1990 if (es
->style
& ES_MULTILINE
)
1991 e
= EDIT_CharFromPos(hwnd
, es
, -es
->x_offset
,
1992 HIWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1995 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1996 EDIT_EM_ScrollCaret(hwnd
, es
);
2000 /*********************************************************************
2002 * EDIT_MovePageDown_ML
2004 * Only for multi line controls
2005 * Move the caret one page down, on a column with the nearest
2006 * x coordinate on the screen (might be a different column).
2009 static void EDIT_MovePageDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2011 INT s
= es
->selection_start
;
2012 INT e
= es
->selection_end
;
2013 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2014 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
2015 INT x
= SLOWORD(pos
);
2016 INT y
= SHIWORD(pos
);
2018 e
= EDIT_CharFromPos(hwnd
, es
, x
,
2019 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2023 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
2024 EDIT_EM_ScrollCaret(hwnd
, es
);
2028 /*********************************************************************
2030 * EDIT_MovePageUp_ML
2032 * Only for multi line controls
2033 * Move the caret one page up, on a column with the nearest
2034 * x coordinate on the screen (might be a different column).
2037 static void EDIT_MovePageUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2039 INT s
= es
->selection_start
;
2040 INT e
= es
->selection_end
;
2041 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2042 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
2043 INT x
= SLOWORD(pos
);
2044 INT y
= SHIWORD(pos
);
2046 e
= EDIT_CharFromPos(hwnd
, es
, x
,
2047 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2051 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
2052 EDIT_EM_ScrollCaret(hwnd
, es
);
2056 /*********************************************************************
2060 * Only for multi line controls
2061 * Move the caret one line up, on a column with the nearest
2062 * x coordinate on the screen (might be a different column).
2065 static void EDIT_MoveUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2067 INT s
= es
->selection_start
;
2068 INT e
= es
->selection_end
;
2069 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2070 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
2071 INT x
= SLOWORD(pos
);
2072 INT y
= SHIWORD(pos
);
2074 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
2077 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
2078 EDIT_EM_ScrollCaret(hwnd
, es
);
2082 /*********************************************************************
2084 * EDIT_MoveWordBackward
2087 static void EDIT_MoveWordBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2089 INT s
= es
->selection_start
;
2090 INT e
= es
->selection_end
;
2095 l
= EDIT_EM_LineFromChar(es
, e
);
2096 ll
= EDIT_EM_LineLength(es
, e
);
2097 li
= EDIT_EM_LineIndex(es
, l
);
2100 li
= EDIT_EM_LineIndex(es
, l
- 1);
2101 e
= li
+ EDIT_EM_LineLength(es
, li
);
2104 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2105 li
, e
- li
, ll
, WB_LEFT
);
2109 EDIT_EM_SetSel(hwnd
, es
, s
, e
, FALSE
);
2110 EDIT_EM_ScrollCaret(hwnd
, es
);
2114 /*********************************************************************
2116 * EDIT_MoveWordForward
2119 static void EDIT_MoveWordForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2121 INT s
= es
->selection_start
;
2122 INT e
= es
->selection_end
;
2127 l
= EDIT_EM_LineFromChar(es
, e
);
2128 ll
= EDIT_EM_LineLength(es
, e
);
2129 li
= EDIT_EM_LineIndex(es
, l
);
2131 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2132 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2134 e
= li
+ EDIT_CallWordBreakProc(es
,
2135 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2139 EDIT_EM_SetSel(hwnd
, es
, s
, e
, FALSE
);
2140 EDIT_EM_ScrollCaret(hwnd
, es
);
2144 /*********************************************************************
2149 static void EDIT_PaintLine(HWND hwnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2151 INT s
= es
->selection_start
;
2152 INT e
= es
->selection_end
;
2159 if (es
->style
& ES_MULTILINE
) {
2160 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2161 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2166 TRACE("line=%d\n", line
);
2168 pos
= EDIT_EM_PosFromChar(hwnd
, es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2171 li
= EDIT_EM_LineIndex(es
, line
);
2172 ll
= EDIT_EM_LineLength(es
, li
);
2173 s
= es
->selection_start
;
2174 e
= es
->selection_end
;
2176 s
= min(li
+ ll
, max(li
, s
));
2177 e
= min(li
+ ll
, max(li
, e
));
2178 if (rev
&& (s
!= e
) &&
2179 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2180 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2181 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2182 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2184 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2188 /*********************************************************************
2193 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2204 BkMode
= GetBkMode(dc
);
2205 BkColor
= GetBkColor(dc
);
2206 TextColor
= GetTextColor(dc
);
2208 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2209 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2210 SetBkMode( dc
, OPAQUE
);
2212 li
= EDIT_EM_LineIndex(es
, line
);
2213 if (es
->style
& ES_MULTILINE
) {
2214 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2215 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2217 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2218 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2219 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2221 if (es
->style
& ES_PASSWORD
)
2222 HeapFree(GetProcessHeap(), 0, text
);
2225 SetBkColor(dc
, BkColor
);
2226 SetTextColor(dc
, TextColor
);
2227 SetBkMode( dc
, BkMode
);
2233 /*********************************************************************
2238 static void EDIT_SetCaretPos(HWND hwnd
, EDITSTATE
*es
, INT pos
,
2241 LRESULT res
= EDIT_EM_PosFromChar(hwnd
, es
, pos
, after_wrap
);
2242 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2246 /*********************************************************************
2250 * note: this is not (exactly) the handler called on EM_SETRECTNP
2251 * it is also used to set the rect of a single line control
2254 static void EDIT_SetRectNP(HWND hwnd
, EDITSTATE
*es
, LPRECT rc
)
2256 CopyRect(&es
->format_rect
, rc
);
2257 if (es
->style
& WS_BORDER
) {
2258 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2259 if(TWEAK_WineLook
== WIN31_LOOK
)
2261 es
->format_rect
.left
+= bw
;
2262 es
->format_rect
.top
+= bw
;
2263 es
->format_rect
.right
-= bw
;
2264 es
->format_rect
.bottom
-= bw
;
2266 es
->format_rect
.left
+= es
->left_margin
;
2267 es
->format_rect
.right
-= es
->right_margin
;
2268 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2269 if (es
->style
& ES_MULTILINE
)
2271 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2273 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2274 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2276 /* correct es->x_offset */
2277 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2278 max_x_offset
= es
->text_width
- fw
;
2279 if(max_x_offset
< 0) max_x_offset
= 0;
2280 if(es
->x_offset
> max_x_offset
)
2281 es
->x_offset
= max_x_offset
;
2283 /* correct es->y_offset */
2284 max_y_offset
= es
->line_count
- vlc
;
2285 if(max_y_offset
< 0) max_y_offset
= 0;
2286 if(es
->y_offset
> max_y_offset
)
2287 es
->y_offset
= max_y_offset
;
2289 /* force scroll info update */
2290 EDIT_UpdateScrollInfo(hwnd
, es
);
2293 /* Windows doesn't care to fix text placement for SL controls */
2294 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2296 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2297 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
2301 /*********************************************************************
2306 static void EDIT_UnlockBuffer(HWND hwnd
, EDITSTATE
*es
, BOOL force
)
2308 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
2310 /* Edit window might be already destroyed */
2313 WARN("edit hwnd %04x already destroyed\n", hwnd
);
2318 ERR("no EDITSTATE ... please report\n");
2321 if (!es
->lock_count
) {
2322 ERR("lock_count == 0 ... please report\n");
2326 ERR("es->text == 0 ... please report\n");
2330 if (force
|| (es
->lock_count
== 1)) {
2333 BOOL _16bit
= FALSE
;
2335 UINT countW
= strlenW(es
->text
) + 1;
2339 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2340 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2341 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2342 countA
= LocalSize(es
->hloc32A
);
2343 if(countA_new
> countA
)
2346 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2347 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2348 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2351 es
->hloc32A
= hloc32A_new
;
2352 countA
= LocalSize(hloc32A_new
);
2353 TRACE("Real new size %d bytes\n", countA
);
2356 WARN("FAILED! Will synchronize partially\n");
2358 textA
= LocalLock(es
->hloc32A
);
2362 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2363 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2364 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2365 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2366 if(countA_new
> countA
)
2368 HLOCAL16 hloc16_new
;
2369 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2370 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2371 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2374 es
->hloc16
= hloc16_new
;
2375 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2376 TRACE("Real new size %d bytes\n", countA
);
2379 WARN("FAILED! Will synchronize partially\n");
2381 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2387 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2389 LOCAL_Unlock(hInstance
, es
->hloc16
);
2391 LocalUnlock(es
->hloc32A
);
2394 LocalUnlock(es
->hloc32W
);
2398 ERR("no buffer ... please report\n");
2406 /*********************************************************************
2408 * EDIT_UpdateScrollInfo
2411 static void EDIT_UpdateScrollInfo(HWND hwnd
, EDITSTATE
*es
)
2413 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2416 si
.cbSize
= sizeof(SCROLLINFO
);
2417 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2419 si
.nMax
= es
->line_count
- 1;
2420 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2421 si
.nPos
= es
->y_offset
;
2422 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2423 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2424 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2427 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2430 si
.cbSize
= sizeof(SCROLLINFO
);
2431 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2433 si
.nMax
= es
->text_width
- 1;
2434 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2435 si
.nPos
= es
->x_offset
;
2436 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2437 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2438 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2442 /*********************************************************************
2444 * EDIT_WordBreakProc
2446 * Find the beginning of words.
2447 * Note: unlike the specs for a WordBreakProc, this function only
2448 * allows to be called without linebreaks between s[0] upto
2449 * s[count - 1]. Remember it is only called
2450 * internally, so we can decide this for ourselves.
2453 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2457 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2467 if (s
[index
] == ' ') {
2468 while (index
&& (s
[index
] == ' '))
2471 while (index
&& (s
[index
] != ' '))
2473 if (s
[index
] == ' ')
2477 while (index
&& (s
[index
] != ' '))
2479 if (s
[index
] == ' ')
2489 if (s
[index
] == ' ')
2490 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2492 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2494 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2498 case WB_ISDELIMITER
:
2499 ret
= (s
[index
] == ' ');
2502 ERR("unknown action code, please report !\n");
2509 /*********************************************************************
2513 * returns line number (not index) in high-order word of result.
2514 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2515 * to Richedit, not to the edit control. Original documentation is valid.
2516 * FIXME: do the specs mean to return -1 if outside client area or
2517 * if outside formatting rectangle ???
2520 static LRESULT
EDIT_EM_CharFromPos(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
)
2528 GetClientRect(hwnd
, &rc
);
2529 if (!PtInRect(&rc
, pt
))
2532 index
= EDIT_CharFromPos(hwnd
, es
, x
, y
, NULL
);
2533 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2537 /*********************************************************************
2541 * Enable or disable soft breaks.
2543 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2545 es
->flags
&= ~EF_USE_SOFTBRK
;
2547 es
->flags
|= EF_USE_SOFTBRK
;
2548 FIXME("soft break enabled, not implemented\n");
2554 /*********************************************************************
2558 * Hopefully this won't fire back at us.
2559 * We always start with a fixed buffer in the local heap.
2560 * Despite of the documentation says that the local heap is used
2561 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2562 * buffer on the local heap.
2565 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2569 if (!(es
->style
& ES_MULTILINE
))
2573 hLocal
= es
->hloc32W
;
2579 UINT countA
, alloc_size
;
2580 TRACE("Allocating 32-bit ANSI alias buffer\n");
2581 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2582 alloc_size
= ROUND_TO_GROW(countA
);
2583 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2585 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2588 textA
= LocalLock(es
->hloc32A
);
2589 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2590 LocalUnlock(es
->hloc32A
);
2592 hLocal
= es
->hloc32A
;
2595 TRACE("Returning %04X, LocalSize() = %d\n", hLocal
, LocalSize(hLocal
));
2600 /*********************************************************************
2604 * Hopefully this won't fire back at us.
2605 * We always start with a buffer in 32 bit linear memory.
2606 * However, with this message a 16 bit application requests
2607 * a handle of 16 bit local heap memory, where it expects to find
2609 * It's a pitty that from this moment on we have to use this
2610 * local heap, because applications may rely on the handle
2613 * In this function we'll try to switch to local heap.
2615 static HLOCAL16
EDIT_EM_GetHandle16(HWND hwnd
, EDITSTATE
*es
)
2617 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
2619 UINT countA
, alloc_size
;
2621 if (!(es
->style
& ES_MULTILINE
))
2627 if (!LOCAL_HeapSize(hInstance
)) {
2628 if (!LocalInit16(hInstance
, 0,
2629 GlobalSize16(hInstance
))) {
2630 ERR("could not initialize local heap\n");
2633 TRACE("local heap initialized\n");
2636 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2637 alloc_size
= ROUND_TO_GROW(countA
);
2639 TRACE("Allocating 16-bit ANSI alias buffer\n");
2640 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2641 ERR("could not allocate new 16 bit buffer\n");
2645 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2646 ERR("could not lock new 16 bit buffer\n");
2647 LOCAL_Free(hInstance
, es
->hloc16
);
2652 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2653 LOCAL_Unlock(hInstance
, es
->hloc16
);
2655 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2660 /*********************************************************************
2665 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2668 INT line_len
, dst_len
;
2671 if (es
->style
& ES_MULTILINE
) {
2672 if (line
>= es
->line_count
)
2676 i
= EDIT_EM_LineIndex(es
, line
);
2678 line_len
= EDIT_EM_LineLength(es
, i
);
2679 dst_len
= *(WORD
*)lParam
;
2682 LPWSTR dst
= (LPWSTR
)lParam
;
2683 if(dst_len
<= line_len
)
2685 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2688 else /* Append 0 if enough space */
2690 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2697 LPSTR dst
= (LPSTR
)lParam
;
2699 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2700 if(!ret
) /* Insufficient buffer size */
2702 if(ret
< dst_len
) /* Append 0 if enough space */
2709 /*********************************************************************
2714 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2716 UINT s
= es
->selection_start
;
2717 UINT e
= es
->selection_end
;
2724 return MAKELONG(s
, e
);
2728 /*********************************************************************
2732 * FIXME: is this right ? (or should it be only VSCROLL)
2733 * (and maybe only for edit controls that really have their
2734 * own scrollbars) (and maybe only for multiline controls ?)
2735 * All in all: very poorly documented
2738 static LRESULT
EDIT_EM_GetThumb(HWND hwnd
, EDITSTATE
*es
)
2740 return MAKELONG(EDIT_WM_VScroll(hwnd
, es
, EM_GETTHUMB16
, 0),
2741 EDIT_WM_HScroll(hwnd
, es
, EM_GETTHUMB16
, 0));
2745 /*********************************************************************
2750 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2755 if (!(es
->style
& ES_MULTILINE
))
2757 if (index
> (INT
)strlenW(es
->text
))
2758 return es
->line_count
- 1;
2760 index
= min(es
->selection_start
, es
->selection_end
);
2763 line_def
= es
->first_line_def
;
2764 index
-= line_def
->length
;
2765 while ((index
>= 0) && line_def
->next
) {
2767 line_def
= line_def
->next
;
2768 index
-= line_def
->length
;
2774 /*********************************************************************
2779 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2784 if (!(es
->style
& ES_MULTILINE
))
2786 if (line
>= es
->line_count
)
2790 line_def
= es
->first_line_def
;
2792 INT index
= es
->selection_end
- line_def
->length
;
2793 while ((index
>= 0) && line_def
->next
) {
2794 line_index
+= line_def
->length
;
2795 line_def
= line_def
->next
;
2796 index
-= line_def
->length
;
2800 line_index
+= line_def
->length
;
2801 line_def
= line_def
->next
;
2809 /*********************************************************************
2814 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2818 if (!(es
->style
& ES_MULTILINE
))
2819 return strlenW(es
->text
);
2822 /* get the number of remaining non-selected chars of selected lines */
2823 INT32 l
; /* line number */
2824 INT32 li
; /* index of first char in line */
2826 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2827 /* # chars before start of selection area */
2828 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2829 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2830 /* # chars after end of selection */
2831 li
= EDIT_EM_LineIndex(es
, l
);
2832 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2835 line_def
= es
->first_line_def
;
2836 index
-= line_def
->length
;
2837 while ((index
>= 0) && line_def
->next
) {
2838 line_def
= line_def
->next
;
2839 index
-= line_def
->length
;
2841 return line_def
->net_length
;
2845 /*********************************************************************
2849 * NOTE: dx is in average character widths, dy - in lines;
2852 static BOOL
EDIT_EM_LineScroll(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2854 if (!(es
->style
& ES_MULTILINE
))
2857 dx
*= es
->char_width
;
2858 return EDIT_EM_LineScroll_internal(hwnd
, es
, dx
, dy
);
2861 /*********************************************************************
2863 * EDIT_EM_LineScroll_internal
2865 * Version of EDIT_EM_LineScroll for internal use.
2866 * It doesn't refuse if ES_MULTILINE is set and assumes that
2867 * dx is in pixels, dy - in lines.
2870 static BOOL
EDIT_EM_LineScroll_internal(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2873 INT x_offset_in_pixels
;
2875 if (es
->style
& ES_MULTILINE
)
2877 x_offset_in_pixels
= es
->x_offset
;
2882 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->x_offset
, FALSE
));
2885 if (-dx
> x_offset_in_pixels
)
2886 dx
= -x_offset_in_pixels
;
2887 if (dx
> es
->text_width
- x_offset_in_pixels
)
2888 dx
= es
->text_width
- x_offset_in_pixels
;
2889 nyoff
= max(0, es
->y_offset
+ dy
);
2890 if (nyoff
>= es
->line_count
)
2891 nyoff
= es
->line_count
- 1;
2892 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2897 es
->y_offset
= nyoff
;
2898 if(es
->style
& ES_MULTILINE
)
2901 es
->x_offset
+= dx
/ es
->char_width
;
2903 GetClientRect(hwnd
, &rc1
);
2904 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2905 ScrollWindowEx(hwnd
, -dx
, dy
,
2906 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2907 /* force scroll info update */
2908 EDIT_UpdateScrollInfo(hwnd
, es
);
2910 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2911 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_HSCROLL
, "EN_HSCROLL");
2912 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2913 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_VSCROLL
, "EN_VSCROLL");
2918 /*********************************************************************
2923 static LRESULT
EDIT_EM_PosFromChar(HWND hwnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2925 INT len
= strlenW(es
->text
);
2934 index
= min(index
, len
);
2937 old_font
= SelectObject(dc
, es
->font
);
2938 if (es
->style
& ES_MULTILINE
) {
2939 l
= EDIT_EM_LineFromChar(es
, index
);
2940 y
= (l
- es
->y_offset
) * es
->line_height
;
2941 li
= EDIT_EM_LineIndex(es
, l
);
2942 if (after_wrap
&& (li
== index
) && l
) {
2944 LINEDEF
*line_def
= es
->first_line_def
;
2946 line_def
= line_def
->next
;
2949 if (line_def
->ending
== END_WRAP
) {
2951 y
-= es
->line_height
;
2952 li
= EDIT_EM_LineIndex(es
, l
);
2955 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2956 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2958 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2959 if (index
< es
->x_offset
) {
2960 GetTextExtentPoint32W(dc
, text
+ index
,
2961 es
->x_offset
- index
, &size
);
2964 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2965 index
- es
->x_offset
, &size
);
2969 if (es
->style
& ES_PASSWORD
)
2970 HeapFree(GetProcessHeap(), 0, text
);
2972 x
+= es
->format_rect
.left
;
2973 y
+= es
->format_rect
.top
;
2975 SelectObject(dc
, old_font
);
2976 ReleaseDC(hwnd
, dc
);
2977 return MAKELONG((INT16
)x
, (INT16
)y
);
2981 /*********************************************************************
2985 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2988 static void EDIT_EM_ReplaceSel(HWND hwnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
)
2990 UINT strl
= strlenW(lpsz_replace
);
2991 UINT tl
= strlenW(es
->text
);
2999 TRACE("%s, can_undo %d, send_update %d\n",
3000 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3002 s
= es
->selection_start
;
3003 e
= es
->selection_end
;
3005 if ((s
== e
) && !strl
)
3010 if (!EDIT_MakeFit(hwnd
, es
, tl
- (e
- s
) + strl
))
3014 /* there is something to be deleted */
3015 TRACE("deleting stuff.\n");
3017 utl
= strlenW(es
->undo_text
);
3018 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3019 /* undo-buffer is extended to the right */
3020 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3021 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
3022 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3023 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3024 /* undo-buffer is extended to the left */
3025 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3026 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3028 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3029 p
[i
] = (es
->text
+ s
)[i
];
3030 es
->undo_position
= s
;
3032 /* new undo-buffer */
3033 EDIT_MakeUndoFit(es
, e
- s
);
3034 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
3035 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3036 es
->undo_position
= s
;
3038 /* any deletion makes the old insertion-undo invalid */
3039 es
->undo_insert_count
= 0;
3041 EDIT_EM_EmptyUndoBuffer(es
);
3044 strcpyW(es
->text
+ s
, es
->text
+ e
);
3047 /* there is an insertion */
3049 if ((s
== es
->undo_position
) ||
3050 ((es
->undo_insert_count
) &&
3051 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3053 * insertion is new and at delete position or
3054 * an extension to either left or right
3056 es
->undo_insert_count
+= strl
;
3058 /* new insertion undo */
3059 es
->undo_position
= s
;
3060 es
->undo_insert_count
= strl
;
3061 /* new insertion makes old delete-buffer invalid */
3062 *es
->undo_text
= '\0';
3065 EDIT_EM_EmptyUndoBuffer(es
);
3068 tl
= strlenW(es
->text
);
3069 TRACE("inserting stuff (tl %d, strl %d, selstart %d ('%s'), text '%s')\n", tl
, strl
, s
, debugstr_w(es
->text
+ s
), debugstr_w(es
->text
));
3070 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3072 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3073 p
[i
] = lpsz_replace
[i
];
3074 if(es
->style
& ES_UPPERCASE
)
3075 CharUpperBuffW(p
, strl
);
3076 else if(es
->style
& ES_LOWERCASE
)
3077 CharLowerBuffW(p
, strl
);
3080 if (es
->style
& ES_MULTILINE
)
3082 INT s
= min(es
->selection_start
, es
->selection_end
);
3084 hrgn
= CreateRectRgn(0, 0, 0, 0);
3085 EDIT_BuildLineDefs_ML(hwnd
, es
, s
, s
+ strl
,
3086 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3089 EDIT_CalcLineWidth_SL(hwnd
, es
);
3091 EDIT_EM_SetSel(hwnd
, es
, s
, s
, FALSE
);
3092 es
->flags
|= EF_MODIFIED
;
3093 if (send_update
) es
->flags
|= EF_UPDATE
;
3094 EDIT_EM_ScrollCaret(hwnd
, es
);
3096 /* force scroll info update */
3097 EDIT_UpdateScrollInfo(hwnd
, es
);
3101 EDIT_UpdateTextRegion(hwnd
, es
, hrgn
, TRUE
);
3105 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3107 if(es
->flags
& EF_UPDATE
)
3109 es
->flags
&= ~EF_UPDATE
;
3110 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
3115 /*********************************************************************
3120 static LRESULT
EDIT_EM_Scroll(HWND hwnd
, EDITSTATE
*es
, INT action
)
3124 if (!(es
->style
& ES_MULTILINE
))
3125 return (LRESULT
)FALSE
;
3135 if (es
->y_offset
< es
->line_count
- 1)
3140 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3143 if (es
->y_offset
< es
->line_count
- 1)
3144 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3147 return (LRESULT
)FALSE
;
3150 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3151 /* check if we are going to move too far */
3152 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3153 dy
= es
->line_count
- vlc
- es
->y_offset
;
3155 /* Notification is done in EDIT_EM_LineScroll */
3157 EDIT_EM_LineScroll(hwnd
, es
, 0, dy
);
3159 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3163 /*********************************************************************
3168 static void EDIT_EM_ScrollCaret(HWND hwnd
, EDITSTATE
*es
)
3170 if (es
->style
& ES_MULTILINE
) {
3175 INT cw
= es
->char_width
;
3180 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3181 li
= EDIT_EM_LineIndex(es
, l
);
3182 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3183 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3184 if (l
>= es
->y_offset
+ vlc
)
3185 dy
= l
- vlc
+ 1 - es
->y_offset
;
3186 if (l
< es
->y_offset
)
3187 dy
= l
- es
->y_offset
;
3188 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3189 if (x
< es
->format_rect
.left
)
3190 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3191 if (x
> es
->format_rect
.right
)
3192 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3195 /* check if we are going to move too far */
3196 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3197 dx
= es
->text_width
- ww
- es
->x_offset
;
3199 EDIT_EM_LineScroll_internal(hwnd
, es
, dx
, dy
);
3206 if (!(es
->style
& ES_AUTOHSCROLL
))
3209 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, FALSE
));
3210 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3211 if (x
< es
->format_rect
.left
) {
3212 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3215 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, FALSE
));
3216 } while ((x
< goal
) && es
->x_offset
);
3217 /* FIXME: use ScrollWindow() somehow to improve performance */
3218 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3219 } else if (x
> es
->format_rect
.right
) {
3221 INT len
= strlenW(es
->text
);
3222 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3225 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, FALSE
));
3226 x_last
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, len
, FALSE
));
3227 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3228 /* FIXME: use ScrollWindow() somehow to improve performance */
3229 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3233 if(es
->flags
& EF_FOCUSED
)
3234 EDIT_SetCaretPos(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3238 /*********************************************************************
3242 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3245 static void EDIT_EM_SetHandle(HWND hwnd
, EDITSTATE
*es
, HLOCAL hloc
)
3247 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
3249 if (!(es
->style
& ES_MULTILINE
))
3253 WARN("called with NULL handle\n");
3257 EDIT_UnlockBuffer(hwnd
, es
, TRUE
);
3261 LOCAL_Free(hInstance
, es
->hloc16
);
3262 es
->hloc16
= (HLOCAL16
)NULL
;
3269 LocalFree(es
->hloc32A
);
3270 es
->hloc32A
= (HLOCAL
)NULL
;
3281 countA
= LocalSize(hloc
);
3282 textA
= LocalLock(hloc
);
3283 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3284 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3286 ERR("Could not allocate new unicode buffer\n");
3289 textW
= LocalLock(hloc32W_new
);
3290 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3291 LocalUnlock(hloc32W_new
);
3295 LocalFree(es
->hloc32W
);
3297 es
->hloc32W
= hloc32W_new
;
3301 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3303 EDIT_LockBuffer(hwnd
, es
);
3305 es
->x_offset
= es
->y_offset
= 0;
3306 es
->selection_start
= es
->selection_end
= 0;
3307 EDIT_EM_EmptyUndoBuffer(es
);
3308 es
->flags
&= ~EF_MODIFIED
;
3309 es
->flags
&= ~EF_UPDATE
;
3310 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3311 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3312 EDIT_EM_ScrollCaret(hwnd
, es
);
3313 /* force scroll info update */
3314 EDIT_UpdateScrollInfo(hwnd
, es
);
3318 /*********************************************************************
3322 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3325 static void EDIT_EM_SetHandle16(HWND hwnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
3327 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
3333 if (!(es
->style
& ES_MULTILINE
))
3337 WARN("called with NULL handle\n");
3341 EDIT_UnlockBuffer(hwnd
, es
, TRUE
);
3345 LocalFree(es
->hloc32A
);
3346 es
->hloc32A
= (HLOCAL
)NULL
;
3349 countA
= LOCAL_Size(hInstance
, hloc
);
3350 textA
= LOCAL_Lock(hInstance
, hloc
);
3351 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3352 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3354 ERR("Could not allocate new unicode buffer\n");
3357 textW
= LocalLock(hloc32W_new
);
3358 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3359 LocalUnlock(hloc32W_new
);
3360 LOCAL_Unlock(hInstance
, hloc
);
3363 LocalFree(es
->hloc32W
);
3365 es
->hloc32W
= hloc32W_new
;
3368 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3370 EDIT_LockBuffer(hwnd
, es
);
3372 es
->x_offset
= es
->y_offset
= 0;
3373 es
->selection_start
= es
->selection_end
= 0;
3374 EDIT_EM_EmptyUndoBuffer(es
);
3375 es
->flags
&= ~EF_MODIFIED
;
3376 es
->flags
&= ~EF_UPDATE
;
3377 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3378 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3379 EDIT_EM_ScrollCaret(hwnd
, es
);
3380 /* force scroll info update */
3381 EDIT_UpdateScrollInfo(hwnd
, es
);
3385 /*********************************************************************
3389 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3390 * However, the windows version is not complied to yet in all of edit.c
3393 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3395 if (es
->style
& ES_MULTILINE
) {
3397 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3399 es
->buffer_limit
= BUFLIMIT_MULTI
;
3402 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3404 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3409 /*********************************************************************
3413 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3414 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3415 * of the char's width, according to the new docs.
3418 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3419 INT left
, INT right
)
3421 if (action
& EC_LEFTMARGIN
) {
3422 if (left
!= EC_USEFONTINFO
)
3423 es
->left_margin
= left
;
3425 es
->left_margin
= es
->char_width
/ 3;
3428 if (action
& EC_RIGHTMARGIN
) {
3429 if (right
!= EC_USEFONTINFO
)
3430 es
->right_margin
= right
;
3432 es
->right_margin
= es
->char_width
/ 3;
3434 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3438 /*********************************************************************
3440 * EM_SETPASSWORDCHAR
3443 static void EDIT_EM_SetPasswordChar(HWND hwnd
, EDITSTATE
*es
, WCHAR c
)
3447 if (es
->style
& ES_MULTILINE
)
3450 if (es
->password_char
== c
)
3453 style
= GetWindowLongA( hwnd
, GWL_STYLE
);
3454 es
->password_char
= c
;
3456 SetWindowLongA( hwnd
, GWL_STYLE
, style
| ES_PASSWORD
);
3457 es
->style
|= ES_PASSWORD
;
3459 SetWindowLongA( hwnd
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3460 es
->style
&= ~ES_PASSWORD
;
3462 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3466 /*********************************************************************
3470 * note: unlike the specs say: the order of start and end
3471 * _is_ preserved in Windows. (i.e. start can be > end)
3472 * In other words: this handler is OK
3475 static void EDIT_EM_SetSel(HWND hwnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3477 UINT old_start
= es
->selection_start
;
3478 UINT old_end
= es
->selection_end
;
3479 UINT len
= strlenW(es
->text
);
3481 if (start
== (UINT
)-1) {
3482 start
= es
->selection_end
;
3483 end
= es
->selection_end
;
3485 start
= min(start
, len
);
3486 end
= min(end
, len
);
3488 es
->selection_start
= start
;
3489 es
->selection_end
= end
;
3491 es
->flags
|= EF_AFTER_WRAP
;
3493 es
->flags
&= ~EF_AFTER_WRAP
;
3494 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3495 ORDER_UINT(start
, end
);
3496 ORDER_UINT(end
, old_end
);
3497 ORDER_UINT(start
, old_start
);
3498 ORDER_UINT(old_start
, old_end
);
3499 if (end
!= old_start
)
3503 * ORDER_UINT32(end, old_start);
3504 * EDIT_InvalidateText(hwnd, es, start, end);
3505 * EDIT_InvalidateText(hwnd, es, old_start, old_end);
3506 * in place of the following if statement.
3508 if (old_start
> end
)
3510 EDIT_InvalidateText(hwnd
, es
, start
, end
);
3511 EDIT_InvalidateText(hwnd
, es
, old_start
, old_end
);
3515 EDIT_InvalidateText(hwnd
, es
, start
, old_start
);
3516 EDIT_InvalidateText(hwnd
, es
, end
, old_end
);
3519 else EDIT_InvalidateText(hwnd
, es
, start
, old_end
);
3523 /*********************************************************************
3528 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3530 if (!(es
->style
& ES_MULTILINE
))
3533 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3534 es
->tabs_count
= count
;
3538 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3539 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3545 /*********************************************************************
3550 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3552 if (!(es
->style
& ES_MULTILINE
))
3555 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3556 es
->tabs_count
= count
;
3561 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3562 for (i
= 0 ; i
< count
; i
++)
3563 es
->tabs
[i
] = *tabs
++;
3569 /*********************************************************************
3571 * EM_SETWORDBREAKPROC
3574 static void EDIT_EM_SetWordBreakProc(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
)
3576 if (es
->word_break_proc
== (void *)lParam
)
3579 es
->word_break_proc
= (void *)lParam
;
3580 es
->word_break_proc16
= NULL
;
3582 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3583 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3584 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3589 /*********************************************************************
3591 * EM_SETWORDBREAKPROC16
3594 static void EDIT_EM_SetWordBreakProc16(HWND hwnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3596 if (es
->word_break_proc16
== wbp
)
3599 es
->word_break_proc
= NULL
;
3600 es
->word_break_proc16
= wbp
;
3601 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3602 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3603 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3608 /*********************************************************************
3613 static BOOL
EDIT_EM_Undo(HWND hwnd
, EDITSTATE
*es
)
3618 /* Protect read-only edit control from modification */
3619 if(es
->style
& ES_READONLY
)
3622 ulength
= strlenW(es
->undo_text
);
3623 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3625 strcpyW(utext
, es
->undo_text
);
3627 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3628 es
->undo_insert_count
, debugstr_w(utext
));
3630 EDIT_EM_SetSel(hwnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3631 EDIT_EM_EmptyUndoBuffer(es
);
3632 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, utext
, FALSE
);
3633 EDIT_EM_SetSel(hwnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3634 /* send the notification after the selection start and end are set */
3635 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
3636 EDIT_EM_ScrollCaret(hwnd
, es
);
3637 HeapFree(GetProcessHeap(), 0, utext
);
3639 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3640 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3645 /*********************************************************************
3650 static void EDIT_WM_Char(HWND hwnd
, EDITSTATE
*es
, WCHAR c
)
3654 /* Protect read-only edit control from modification */
3655 if(es
->style
& ES_READONLY
)
3658 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3662 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3663 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3666 if (es
->style
& ES_MULTILINE
) {
3667 if (es
->style
& ES_READONLY
) {
3668 EDIT_MoveHome(hwnd
, es
, FALSE
);
3669 EDIT_MoveDown_ML(hwnd
, es
, FALSE
);
3671 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3672 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, cr_lfW
, TRUE
);
3677 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3679 static const WCHAR tabW
[] = {'\t',0};
3680 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, tabW
, TRUE
);
3684 if (!(es
->style
& ES_READONLY
) && !control
) {
3685 if (es
->selection_start
!= es
->selection_end
)
3686 EDIT_WM_Clear(hwnd
, es
);
3688 /* delete character left of caret */
3689 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
3690 EDIT_MoveBackward(hwnd
, es
, TRUE
);
3691 EDIT_WM_Clear(hwnd
, es
);
3696 SendMessageW(hwnd
, WM_COPY
, 0, 0);
3699 SendMessageW(hwnd
, WM_PASTE
, 0, 0);
3702 SendMessageW(hwnd
, WM_CUT
, 0, 0);
3706 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3710 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, str
, TRUE
);
3717 /*********************************************************************
3722 static void EDIT_WM_Command(HWND hwnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3724 if (code
|| control
)
3729 EDIT_EM_Undo(hwnd
, es
);
3732 EDIT_WM_Cut(hwnd
, es
);
3735 EDIT_WM_Copy(hwnd
, es
);
3738 EDIT_WM_Paste(hwnd
, es
);
3741 EDIT_WM_Clear(hwnd
, es
);
3744 EDIT_EM_SetSel(hwnd
, es
, 0, (UINT
)-1, FALSE
);
3745 EDIT_EM_ScrollCaret(hwnd
, es
);
3748 ERR("unknown menu item, please report\n");
3754 /*********************************************************************
3758 * Note: the resource files resource/sysres_??.rc cannot define a
3759 * single popup menu. Hence we use a (dummy) menubar
3760 * containing the single popup menu as its first item.
3762 * FIXME: the message identifiers have been chosen arbitrarily,
3763 * hence we use MF_BYPOSITION.
3764 * We might as well use the "real" values (anybody knows ?)
3765 * The menu definition is in resources/sysres_??.rc.
3766 * Once these are OK, we better use MF_BYCOMMAND here
3767 * (as we do in EDIT_WM_Command()).
3770 static void EDIT_WM_ContextMenu(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
)
3772 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3773 HMENU popup
= GetSubMenu(menu
, 0);
3774 UINT start
= es
->selection_start
;
3775 UINT end
= es
->selection_end
;
3777 ORDER_UINT(start
, end
);
3780 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3782 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3784 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3786 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3788 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3790 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3792 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, hwnd
, NULL
);
3797 /*********************************************************************
3802 static void EDIT_WM_Copy(HWND hwnd
, EDITSTATE
*es
)
3804 INT s
= es
->selection_start
;
3805 INT e
= es
->selection_end
;
3812 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3813 dst
= GlobalLock(hdst
);
3814 strncpyW(dst
, es
->text
+ s
, e
- s
);
3815 dst
[e
- s
] = 0; /* ensure 0 termination */
3816 TRACE("%s\n", debugstr_w(dst
));
3818 OpenClipboard(hwnd
);
3820 SetClipboardData(CF_UNICODETEXT
, hdst
);
3825 /*********************************************************************
3830 static LRESULT
EDIT_WM_Create(HWND hwnd
, EDITSTATE
*es
, LPCWSTR name
)
3832 TRACE("%s\n", debugstr_w(name
));
3834 * To initialize some final structure members, we call some helper
3835 * functions. However, since the EDITSTATE is not consistent (i.e.
3836 * not fully initialized), we should be very careful which
3837 * functions can be called, and in what order.
3839 EDIT_WM_SetFont(hwnd
, es
, 0, FALSE
);
3840 EDIT_EM_EmptyUndoBuffer(es
);
3842 if (name
&& *name
) {
3843 EDIT_EM_ReplaceSel(hwnd
, es
, FALSE
, name
, FALSE
);
3844 /* if we insert text to the editline, the text scrolls out
3845 * of the window, as the caret is placed after the insert
3846 * pos normally; thus we reset es->selection... to 0 and
3849 es
->selection_start
= es
->selection_end
= 0;
3850 /* send the notification after the selection start and end are set */
3851 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
3852 EDIT_EM_ScrollCaret(hwnd
, es
);
3854 /* force scroll info update */
3855 EDIT_UpdateScrollInfo(hwnd
, es
);
3860 /*********************************************************************
3865 static void EDIT_WM_Destroy(HWND hwnd
, EDITSTATE
*es
)
3867 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
3871 while (LocalUnlock(es
->hloc32W
)) ;
3872 LocalFree(es
->hloc32W
);
3875 while (LocalUnlock(es
->hloc32A
)) ;
3876 LocalFree(es
->hloc32A
);
3879 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3880 LOCAL_Free(hInstance
, es
->hloc16
);
3883 pc
= es
->first_line_def
;
3887 HeapFree(GetProcessHeap(), 0, pc
);
3891 SetWindowLongA( hwnd
, 0, 0 );
3892 HeapFree(GetProcessHeap(), 0, es
);
3896 /*********************************************************************
3901 static LRESULT
EDIT_WM_EraseBkGnd(HWND hwnd
, EDITSTATE
*es
, HDC dc
)
3906 if ( get_app_version() >= 0x40000 &&(
3907 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3908 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(hwnd
, dc
);
3910 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(hwnd
, dc
);
3913 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3915 GetClientRect(hwnd
, &rc
);
3916 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3917 GetClipBox(dc
, &rc
);
3919 * FIXME: specs say that we should UnrealizeObject() the brush,
3920 * but the specs of UnrealizeObject() say that we shouldn't
3921 * unrealize a stock object. The default brush that
3922 * DefWndProc() returns is ... a stock object.
3924 FillRect(dc
, &rc
, brush
);
3929 /*********************************************************************
3934 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3936 if(!count
) return 0;
3940 LPWSTR textW
= (LPWSTR
)lParam
;
3941 strncpyW(textW
, es
->text
, count
);
3942 textW
[count
- 1] = 0; /* ensure 0 termination */
3943 return strlenW(textW
);
3947 LPSTR textA
= (LPSTR
)lParam
;
3948 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
);
3949 textA
[count
- 1] = 0; /* ensure 0 termination */
3950 return strlen(textA
);
3954 /*********************************************************************
3959 static LRESULT
EDIT_WM_HScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
)
3964 if (!(es
->style
& ES_MULTILINE
))
3967 if (!(es
->style
& ES_AUTOHSCROLL
))
3971 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3974 TRACE("SB_LINELEFT\n");
3976 dx
= -es
->char_width
;
3979 TRACE("SB_LINERIGHT\n");
3980 if (es
->x_offset
< es
->text_width
)
3981 dx
= es
->char_width
;
3984 TRACE("SB_PAGELEFT\n");
3986 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3989 TRACE("SB_PAGERIGHT\n");
3990 if (es
->x_offset
< es
->text_width
)
3991 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3999 TRACE("SB_RIGHT\n");
4000 if (es
->x_offset
< es
->text_width
)
4001 dx
= es
->text_width
- es
->x_offset
;
4004 TRACE("SB_THUMBTRACK %d\n", pos
);
4005 es
->flags
|= EF_HSCROLL_TRACK
;
4006 if(es
->style
& WS_HSCROLL
)
4007 dx
= pos
- es
->x_offset
;
4012 if(pos
< 0 || pos
> 100) return 0;
4013 /* Assume default scroll range 0-100 */
4014 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4015 new_x
= pos
* (es
->text_width
- fw
) / 100;
4016 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4019 case SB_THUMBPOSITION
:
4020 TRACE("SB_THUMBPOSITION %d\n", pos
);
4021 es
->flags
&= ~EF_HSCROLL_TRACK
;
4022 if(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_HSCROLL
)
4023 dx
= pos
- es
->x_offset
;
4028 if(pos
< 0 || pos
> 100) return 0;
4029 /* Assume default scroll range 0-100 */
4030 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4031 new_x
= pos
* (es
->text_width
- fw
) / 100;
4032 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4035 /* force scroll info update */
4036 EDIT_UpdateScrollInfo(hwnd
, es
);
4037 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_HSCROLL
, "EN_HSCROLL");
4041 TRACE("SB_ENDSCROLL\n");
4044 * FIXME : the next two are undocumented !
4045 * Are we doing the right thing ?
4046 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4047 * although it's also a regular control message.
4049 case EM_GETTHUMB
: /* this one is used by NT notepad */
4053 if(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_HSCROLL
)
4054 ret
= GetScrollPos(hwnd
, SB_HORZ
);
4057 /* Assume default scroll range 0-100 */
4058 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4059 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4061 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4064 case EM_LINESCROLL16
:
4065 TRACE("EM_LINESCROLL16\n");
4070 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4076 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4077 /* check if we are going to move too far */
4078 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4079 dx
= es
->text_width
- fw
- es
->x_offset
;
4081 EDIT_EM_LineScroll_internal(hwnd
, es
, dx
, 0);
4087 /*********************************************************************
4092 static BOOL
EDIT_CheckCombo(HWND hwnd
, EDITSTATE
*es
, UINT msg
, INT key
)
4094 HWND hLBox
= es
->hwndListBox
;
4102 hCombo
= GetParent(hwnd
);
4106 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
4107 hwnd
, (UINT16
)msg
, (UINT16
)key
);
4109 if (key
== VK_UP
|| key
== VK_DOWN
)
4111 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4114 if (msg
== WM_KEYDOWN
|| nEUI
)
4115 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4121 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4123 /* make sure ComboLBox pops up */
4124 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4129 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4132 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4134 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4136 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4141 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4147 /*********************************************************************
4151 * Handling of special keys that don't produce a WM_CHAR
4152 * (i.e. non-printable keys) & Backspace & Delete
4155 static LRESULT
EDIT_WM_KeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
)
4160 if (GetKeyState(VK_MENU
) & 0x8000)
4163 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4164 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4169 if (EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4174 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4175 EDIT_MoveUp_ML(hwnd
, es
, shift
);
4178 EDIT_MoveWordBackward(hwnd
, es
, shift
);
4180 EDIT_MoveBackward(hwnd
, es
, shift
);
4183 if (EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
))
4187 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4188 EDIT_MoveDown_ML(hwnd
, es
, shift
);
4190 EDIT_MoveWordForward(hwnd
, es
, shift
);
4192 EDIT_MoveForward(hwnd
, es
, shift
);
4195 EDIT_MoveHome(hwnd
, es
, shift
);
4198 EDIT_MoveEnd(hwnd
, es
, shift
);
4201 if (es
->style
& ES_MULTILINE
)
4202 EDIT_MovePageUp_ML(hwnd
, es
, shift
);
4204 EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
);
4207 if (es
->style
& ES_MULTILINE
)
4208 EDIT_MovePageDown_ML(hwnd
, es
, shift
);
4210 EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
);
4213 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4214 if (es
->selection_start
!= es
->selection_end
) {
4216 EDIT_WM_Cut(hwnd
, es
);
4218 EDIT_WM_Clear(hwnd
, es
);
4221 /* delete character left of caret */
4222 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
4223 EDIT_MoveBackward(hwnd
, es
, TRUE
);
4224 EDIT_WM_Clear(hwnd
, es
);
4225 } else if (control
) {
4226 /* delete to end of line */
4227 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
4228 EDIT_MoveEnd(hwnd
, es
, TRUE
);
4229 EDIT_WM_Clear(hwnd
, es
);
4231 /* delete character right of caret */
4232 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
4233 EDIT_MoveForward(hwnd
, es
, TRUE
);
4234 EDIT_WM_Clear(hwnd
, es
);
4241 if (!(es
->style
& ES_READONLY
))
4242 EDIT_WM_Paste(hwnd
, es
);
4244 EDIT_WM_Copy(hwnd
, es
);
4247 /* If the edit doesn't want the return send a message to the default object */
4248 if(!(es
->style
& ES_WANTRETURN
))
4250 HWND hwndParent
= GetParent(hwnd
);
4251 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4252 if (HIWORD(dw
) == DC_HASDEFID
)
4254 SendMessageW( hwndParent
, WM_COMMAND
,
4255 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4256 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4265 /*********************************************************************
4270 static LRESULT
EDIT_WM_KillFocus(HWND hwnd
, EDITSTATE
*es
)
4272 es
->flags
&= ~EF_FOCUSED
;
4274 if(!(es
->style
& ES_NOHIDESEL
))
4275 EDIT_InvalidateText(hwnd
, es
, es
->selection_start
, es
->selection_end
);
4276 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4281 /*********************************************************************
4285 * The caret position has been set on the WM_LBUTTONDOWN message
4288 static LRESULT
EDIT_WM_LButtonDblClk(HWND hwnd
, EDITSTATE
*es
)
4291 INT e
= es
->selection_end
;
4296 if (!(es
->flags
& EF_FOCUSED
))
4299 l
= EDIT_EM_LineFromChar(es
, e
);
4300 li
= EDIT_EM_LineIndex(es
, l
);
4301 ll
= EDIT_EM_LineLength(es
, e
);
4302 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4303 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4304 EDIT_EM_SetSel(hwnd
, es
, s
, e
, FALSE
);
4305 EDIT_EM_ScrollCaret(hwnd
, es
);
4310 /*********************************************************************
4315 static LRESULT
EDIT_WM_LButtonDown(HWND hwnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4320 if (!(es
->flags
& EF_FOCUSED
))
4323 es
->bCaptureState
= TRUE
;
4325 EDIT_ConfinePoint(es
, &x
, &y
);
4326 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
, &after_wrap
);
4327 EDIT_EM_SetSel(hwnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4328 EDIT_EM_ScrollCaret(hwnd
, es
);
4329 es
->region_posx
= es
->region_posy
= 0;
4330 SetTimer(hwnd
, 0, 100, NULL
);
4335 /*********************************************************************
4340 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
)
4342 if (es
->bCaptureState
&& GetCapture() == hwndSelf
) {
4343 KillTimer(hwndSelf
, 0);
4346 es
->bCaptureState
= FALSE
;
4351 /*********************************************************************
4356 static LRESULT
EDIT_WM_MButtonDown(HWND hwnd
)
4358 SendMessageW(hwnd
,WM_PASTE
,0,0);
4363 /*********************************************************************
4368 static LRESULT
EDIT_WM_MouseMove(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
)
4374 if (GetCapture() != hwnd
)
4378 * FIXME: gotta do some scrolling if outside client
4379 * area. Maybe reset the timer ?
4382 EDIT_ConfinePoint(es
, &x
, &y
);
4383 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4384 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4385 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
, &after_wrap
);
4386 EDIT_EM_SetSel(hwnd
, es
, es
->selection_start
, e
, after_wrap
);
4391 /*********************************************************************
4395 * See also EDIT_WM_StyleChanged
4397 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, DWORD style
, HWND hwndParent
, BOOL unicode
)
4402 TRACE("Creating %s edit control, style = %08lx\n",
4403 unicode
? "Unicode" : "ANSI", style
);
4405 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4407 SetWindowLongA( hwnd
, 0, (LONG
)es
);
4410 * Note: since the EDITSTATE has not been fully initialized yet,
4411 * we can't use any API calls that may send
4412 * WM_XXX messages before WM_NCCREATE is completed.
4415 es
->is_unicode
= unicode
;
4418 es
->bEnableState
= !(style
& WS_DISABLED
);
4420 /* Save parent, which will be notified by EN_* messages */
4421 es
->hwndParent
= hwndParent
;
4423 if (es
->style
& ES_COMBO
)
4424 es
->hwndListBox
= GetDlgItem(hwndParent
, ID_CB_LISTBOX
);
4426 /* Number overrides lowercase overrides uppercase (at least it
4427 * does in Win95). However I'll bet that ES_NUMBER would be
4428 * invalid under Win 3.1.
4430 if (es
->style
& ES_NUMBER
) {
4431 ; /* do not override the ES_NUMBER */
4432 } else if (es
->style
& ES_LOWERCASE
) {
4433 es
->style
&= ~ES_UPPERCASE
;
4435 if (es
->style
& ES_MULTILINE
) {
4436 es
->buffer_limit
= BUFLIMIT_MULTI
;
4437 if (es
->style
& WS_VSCROLL
)
4438 es
->style
|= ES_AUTOVSCROLL
;
4439 if (es
->style
& WS_HSCROLL
)
4440 es
->style
|= ES_AUTOHSCROLL
;
4441 es
->style
&= ~ES_PASSWORD
;
4442 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4443 /* Confirmed - RIGHT overrides CENTER */
4444 if (es
->style
& ES_RIGHT
)
4445 es
->style
&= ~ES_CENTER
;
4446 es
->style
&= ~WS_HSCROLL
;
4447 es
->style
&= ~ES_AUTOHSCROLL
;
4450 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4451 es
->style
|= ES_AUTOVSCROLL
;
4453 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4454 if (WIN31_LOOK
== TWEAK_WineLook
||
4455 WIN95_LOOK
== TWEAK_WineLook
) {
4456 es
->style
&= ~ES_CENTER
;
4457 es
->style
&= ~ES_RIGHT
;
4459 if (es
->style
& ES_RIGHT
)
4460 es
->style
&= ~ES_CENTER
;
4462 es
->style
&= ~WS_HSCROLL
;
4463 es
->style
&= ~WS_VSCROLL
;
4464 es
->style
&= ~ES_AUTOVSCROLL
;
4465 es
->style
&= ~ES_WANTRETURN
;
4466 if (es
->style
& ES_PASSWORD
)
4467 es
->password_char
= '*';
4469 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4470 es
->style
|= ES_AUTOHSCROLL
;
4473 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4474 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4476 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4478 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4480 es
->undo_buffer_size
= es
->buffer_size
;
4482 if (es
->style
& ES_MULTILINE
)
4483 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4488 * In Win95 look and feel, the WS_BORDER style is replaced by the
4489 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4490 * control a non client area. Not always. This coordinates in some
4491 * way with the window creation code in dialog.c When making
4492 * modifications please ensure that the code still works for edit
4493 * controls created directly with style 0x50800000, exStyle 0 (
4494 * which should have a single pixel border)
4496 if (TWEAK_WineLook
!= WIN31_LOOK
)
4498 es
->style
&= ~WS_BORDER
;
4502 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4503 SetWindowLongA( hwnd
, GWL_STYLE
,
4504 GetWindowLongA( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4510 /*********************************************************************
4515 static void EDIT_WM_Paint(HWND hwnd
, EDITSTATE
*es
, WPARAM wParam
)
4524 BOOL rev
= es
->bEnableState
&&
4525 ((es
->flags
& EF_FOCUSED
) ||
4526 (es
->style
& ES_NOHIDESEL
));
4528 dc
= BeginPaint(hwnd
, &ps
);
4531 if(es
->style
& WS_BORDER
) {
4532 GetClientRect(hwnd
, &rc
);
4533 if(es
->style
& ES_MULTILINE
) {
4534 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4535 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4537 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4539 IntersectClipRect(dc
, es
->format_rect
.left
,
4540 es
->format_rect
.top
,
4541 es
->format_rect
.right
,
4542 es
->format_rect
.bottom
);
4543 if (es
->style
& ES_MULTILINE
) {
4544 GetClientRect(hwnd
, &rc
);
4545 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4548 old_font
= SelectObject(dc
, es
->font
);
4549 if ( get_app_version() >= 0x40000 &&(
4550 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
4551 EDIT_SEND_CTLCOLORSTATIC(hwnd
, dc
);
4553 EDIT_SEND_CTLCOLOR(hwnd
, dc
);
4555 if (!es
->bEnableState
)
4556 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4557 GetClipBox(dc
, &rcRgn
);
4558 if (es
->style
& ES_MULTILINE
) {
4559 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4560 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4561 EDIT_GetLineRect(hwnd
, es
, i
, 0, -1, &rcLine
);
4562 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4563 EDIT_PaintLine(hwnd
, es
, dc
, i
, rev
);
4566 EDIT_GetLineRect(hwnd
, es
, 0, 0, -1, &rcLine
);
4567 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4568 EDIT_PaintLine(hwnd
, es
, dc
, 0, rev
);
4571 SelectObject(dc
, old_font
);
4574 EndPaint(hwnd
, &ps
);
4578 /*********************************************************************
4583 static void EDIT_WM_Paste(HWND hwnd
, EDITSTATE
*es
)
4588 /* Protect read-only edit control from modification */
4589 if(es
->style
& ES_READONLY
)
4592 OpenClipboard(hwnd
);
4593 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4594 src
= (LPWSTR
)GlobalLock(hsrc
);
4595 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, src
, TRUE
);
4602 /*********************************************************************
4607 static void EDIT_WM_SetFocus(HWND hwnd
, EDITSTATE
*es
)
4609 es
->flags
|= EF_FOCUSED
;
4610 CreateCaret(hwnd
, 0, 2, es
->line_height
);
4611 EDIT_SetCaretPos(hwnd
, es
, es
->selection_end
,
4612 es
->flags
& EF_AFTER_WRAP
);
4613 if(!(es
->style
& ES_NOHIDESEL
))
4614 EDIT_InvalidateText(hwnd
, es
, es
->selection_start
, es
->selection_end
);
4616 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_SETFOCUS
, "EN_SETFOCUS");
4620 /*********************************************************************
4624 * With Win95 look the margins are set to default font value unless
4625 * the system font (font == 0) is being set, in which case they are left
4629 static void EDIT_WM_SetFont(HWND hwnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4639 old_font
= SelectObject(dc
, font
);
4640 GetTextMetricsW(dc
, &tm
);
4641 es
->line_height
= tm
.tmHeight
;
4642 es
->char_width
= tm
.tmAveCharWidth
;
4644 SelectObject(dc
, old_font
);
4645 ReleaseDC(hwnd
, dc
);
4646 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4647 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4648 EC_USEFONTINFO
, EC_USEFONTINFO
);
4650 /* Force the recalculation of the format rect for each font change */
4651 GetClientRect(hwnd
, &r
);
4652 EDIT_SetRectNP(hwnd
, es
, &r
);
4654 if (es
->style
& ES_MULTILINE
)
4655 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
4657 EDIT_CalcLineWidth_SL(hwnd
, es
);
4660 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
4661 if (es
->flags
& EF_FOCUSED
) {
4663 CreateCaret(hwnd
, 0, 2, es
->line_height
);
4664 EDIT_SetCaretPos(hwnd
, es
, es
->selection_end
,
4665 es
->flags
& EF_AFTER_WRAP
);
4671 /*********************************************************************
4676 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4677 * The modified flag is reset. No notifications are sent.
4679 * For single-line controls, reception of WM_SETTEXT triggers:
4680 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4683 static void EDIT_WM_SetText(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4688 text
= (LPWSTR
)lParam
;
4691 LPCSTR textA
= (LPCSTR
)lParam
;
4692 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4693 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4694 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4697 EDIT_EM_SetSel(hwnd
, es
, 0, (UINT
)-1, FALSE
);
4699 TRACE("%s\n", debugstr_w(text
));
4700 EDIT_EM_ReplaceSel(hwnd
, es
, FALSE
, text
, FALSE
);
4702 HeapFree(GetProcessHeap(), 0, text
);
4704 static const WCHAR empty_stringW
[] = {0};
4706 EDIT_EM_ReplaceSel(hwnd
, es
, FALSE
, empty_stringW
, FALSE
);
4709 es
->flags
&= ~EF_MODIFIED
;
4710 EDIT_EM_SetSel(hwnd
, es
, 0, 0, FALSE
);
4711 /* Send the notification after the selection start and end have been set
4712 * edit control doesn't send notification on WM_SETTEXT
4713 * if it is multiline, or it is part of combobox
4715 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4716 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
4717 EDIT_EM_ScrollCaret(hwnd
, es
);
4721 /*********************************************************************
4726 static void EDIT_WM_Size(HWND hwnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4728 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4730 TRACE("width = %d, height = %d\n", width
, height
);
4731 SetRect(&rc
, 0, 0, width
, height
);
4732 EDIT_SetRectNP(hwnd
, es
, &rc
);
4733 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
4738 /*********************************************************************
4742 * This message is sent by SetWindowLong on having changed either the Style
4743 * or the extended style.
4745 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4747 * See also EDIT_WM_NCCreate
4749 * It appears that the Windows version of the edit control allows the style
4750 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4751 * style variable which will generally be different. In this function we
4752 * update the internal style based on what changed in the externally visible
4755 * Much of this content as based upon the MSDN, especially:
4756 * Platform SDK Documentation -> User Interface Services ->
4757 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4758 * Edit Control Styles
4760 static LRESULT
EDIT_WM_StyleChanged (HWND hwnd
,
4763 const STYLESTRUCT
*style
)
4765 if (GWL_STYLE
== which
) {
4766 DWORD style_change_mask
;
4768 /* Only a subset of changes can be applied after the control
4771 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4773 if (es
->style
& ES_MULTILINE
)
4774 style_change_mask
|= ES_WANTRETURN
;
4776 new_style
= style
->styleNew
& style_change_mask
;
4778 /* Number overrides lowercase overrides uppercase (at least it
4779 * does in Win95). However I'll bet that ES_NUMBER would be
4780 * invalid under Win 3.1.
4782 if (new_style
& ES_NUMBER
) {
4783 ; /* do not override the ES_NUMBER */
4784 } else if (new_style
& ES_LOWERCASE
) {
4785 new_style
&= ~ES_UPPERCASE
;
4788 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4789 } else if (GWL_EXSTYLE
== which
) {
4790 ; /* FIXME - what is needed here */
4792 WARN ("Invalid style change %d\n",which
);
4798 /*********************************************************************
4803 static LRESULT
EDIT_WM_SysKeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4805 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4806 if (EDIT_EM_CanUndo(es
))
4807 EDIT_EM_Undo(hwnd
, es
);
4809 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4810 if (EDIT_CheckCombo(hwnd
, es
, WM_SYSKEYDOWN
, key
))
4813 return DefWindowProcW(hwnd
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4817 /*********************************************************************
4822 static void EDIT_WM_Timer(HWND hwnd
, EDITSTATE
*es
)
4824 if (es
->region_posx
< 0) {
4825 EDIT_MoveBackward(hwnd
, es
, TRUE
);
4826 } else if (es
->region_posx
> 0) {
4827 EDIT_MoveForward(hwnd
, es
, TRUE
);
4830 * FIXME: gotta do some vertical scrolling here, like
4831 * EDIT_EM_LineScroll(hwnd, 0, 1);
4835 /*********************************************************************
4840 static LRESULT
EDIT_WM_VScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
)
4844 if (!(es
->style
& ES_MULTILINE
))
4847 if (!(es
->style
& ES_AUTOVSCROLL
))
4856 TRACE("action %d\n", action
);
4857 EDIT_EM_Scroll(hwnd
, es
, action
);
4864 TRACE("SB_BOTTOM\n");
4865 dy
= es
->line_count
- 1 - es
->y_offset
;
4868 TRACE("SB_THUMBTRACK %d\n", pos
);
4869 es
->flags
|= EF_VSCROLL_TRACK
;
4870 if(es
->style
& WS_VSCROLL
)
4871 dy
= pos
- es
->y_offset
;
4874 /* Assume default scroll range 0-100 */
4877 if(pos
< 0 || pos
> 100) return 0;
4878 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4879 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4880 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4881 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4882 es
->line_count
, es
->y_offset
, pos
, dy
);
4885 case SB_THUMBPOSITION
:
4886 TRACE("SB_THUMBPOSITION %d\n", pos
);
4887 es
->flags
&= ~EF_VSCROLL_TRACK
;
4888 if(es
->style
& WS_VSCROLL
)
4889 dy
= pos
- es
->y_offset
;
4892 /* Assume default scroll range 0-100 */
4895 if(pos
< 0 || pos
> 100) return 0;
4896 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4897 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4898 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4899 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4900 es
->line_count
, es
->y_offset
, pos
, dy
);
4904 /* force scroll info update */
4905 EDIT_UpdateScrollInfo(hwnd
, es
);
4906 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_VSCROLL
, "EN_VSCROLL");
4910 TRACE("SB_ENDSCROLL\n");
4913 * FIXME : the next two are undocumented !
4914 * Are we doing the right thing ?
4915 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4916 * although it's also a regular control message.
4918 case EM_GETTHUMB
: /* this one is used by NT notepad */
4922 if(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_VSCROLL
)
4923 ret
= GetScrollPos(hwnd
, SB_VERT
);
4926 /* Assume default scroll range 0-100 */
4927 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4928 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4930 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4933 case EM_LINESCROLL16
:
4934 TRACE("EM_LINESCROLL16 %d\n", pos
);
4939 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4944 EDIT_EM_LineScroll(hwnd
, es
, 0, dy
);
4948 /*********************************************************************
4953 static void EDIT_UpdateTextRegion(HWND hwnd
, EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4955 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(hwnd
, es
, EN_UPDATE
, "EN_UPDATE");
4956 InvalidateRgn(hwnd
, hrgn
, bErase
);
4960 /*********************************************************************
4965 static void EDIT_UpdateText(HWND hwnd
, EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4967 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(hwnd
, es
, EN_UPDATE
, "EN_UPDATE");
4968 InvalidateRect(hwnd
, rc
, bErase
);