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 on next WM_PAINT */
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 struct tagLINEDEF
*next
;
71 BOOL is_unicode
; /* how the control was created */
72 LPWSTR text
; /* the actual contents of the control */
73 UINT buffer_size
; /* the size of the buffer in characters */
74 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
75 HFONT font
; /* NULL means standard system font */
76 INT x_offset
; /* scroll offset for multi lines this is in pixels
77 for single lines it's in characters */
78 INT line_height
; /* height of a screen line in pixels */
79 INT char_width
; /* average character width in pixels */
80 DWORD style
; /* sane version of wnd->dwStyle */
81 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
82 INT undo_insert_count
; /* number of characters inserted in sequence */
83 UINT undo_position
; /* character index of the insertion and deletion */
84 LPWSTR undo_text
; /* deleted text */
85 UINT undo_buffer_size
; /* size of the deleted text buffer */
86 INT selection_start
; /* == selection_end if no selection */
87 INT selection_end
; /* == current caret position */
88 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
89 INT left_margin
; /* in pixels */
90 INT right_margin
; /* in pixels */
92 INT text_width
; /* width of the widest line in pixels for multi line controls
93 and just line width for single line controls */
94 INT region_posx
; /* Position of cursor relative to region: */
95 INT region_posy
; /* -1: to left, 0: within, 1: to right */
96 EDITWORDBREAKPROC16 word_break_proc16
;
97 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
98 INT line_count
; /* number of lines */
99 INT y_offset
; /* scroll offset in number of lines */
100 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
101 BOOL bEnableState
; /* flag keeping the enable state */
102 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
104 * only for multi line controls
106 INT lock_count
; /* amount of re-entries in the EditWndProc */
109 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
110 HLOCAL hloc32W
; /* our unicode local memory block */
111 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
113 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
118 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
119 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
121 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
122 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
124 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
125 do {TRACE("notification " str " sent to hwnd=%08x\n", \
126 (UINT)(hwnd));} while(0)
128 /* used for disabled or read-only edit control */
129 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
130 (SendMessageW((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
131 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
132 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
133 (SendMessageW((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
134 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
135 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
136 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
137 SendMessageW((wnd)->parent->hwndSelf, WM_COMMAND, \
138 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
139 (LPARAM)(wnd)->hwndSelf);} while(0)
140 #define DPRINTF_EDIT_MSG16(str) \
142 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
143 (UINT)wnd->hwndSelf, (UINT)wParam, (UINT)lParam)
144 #define DPRINTF_EDIT_MSG32(str) \
146 "32 bit %c : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
147 unicode ? 'W' : 'A', \
148 (UINT)wnd->hwndSelf, (UINT)wParam, (UINT)lParam)
150 /*********************************************************************
157 * These functions have trivial implementations
158 * We still like to call them internally
159 * "static inline" makes them more like macro's
161 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
162 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
163 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
164 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
167 * Helper functions only valid for one type of control
169 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
170 static void EDIT_CalcLineWidth_SL(WND
*wnd
, EDITSTATE
*es
);
171 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
172 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
173 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
174 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
175 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
177 * Helper functions valid for both single line _and_ multi line controls
179 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
180 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
181 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
182 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
183 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
184 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
185 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, UINT size
);
186 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
187 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
190 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
191 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
192 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
193 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
194 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
195 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
196 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
197 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
198 static void EDIT_UpdateScrollInfo(WND
*wnd
, EDITSTATE
*es
);
199 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
201 * EM_XXX message handlers
203 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
204 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
205 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
206 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
207 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR lpch
);
208 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
);
209 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
210 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
211 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
212 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
213 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
214 static BOOL
EDIT_EM_LineScroll_internal(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
215 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
216 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
);
217 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
218 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
219 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
220 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
221 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
222 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
223 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, WCHAR c
);
224 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
225 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
226 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
227 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
);
228 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
229 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
231 * WM_XXX message handlers
233 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, WCHAR c
);
234 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
235 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
236 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
237 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCWSTR name
);
238 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
239 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
240 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
241 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
);
242 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
);
243 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
);
244 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
);
245 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
246 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
);
247 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
);
248 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
249 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, DWORD style
, HWND hwndParent
, BOOL unicode
);
250 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
251 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
252 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
);
253 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
254 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
255 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
256 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
257 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
);
258 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
);
259 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
);
261 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
262 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
264 /*********************************************************************
265 * edit class descriptor
267 const struct builtin_class_descr EDIT_builtin_class
=
270 CS_GLOBALCLASS
| CS_DBLCLKS
/*| CS_PARENTDC*/, /* style */
271 EditWndProcA
, /* procA */
272 EditWndProcW
, /* procW */
273 sizeof(EDITSTATE
*), /* extra */
274 IDC_IBEAMA
, /* cursor */
279 /*********************************************************************
284 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
286 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
290 /*********************************************************************
295 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
297 es
->undo_insert_count
= 0;
298 *es
->undo_text
= '\0';
302 /*********************************************************************
307 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
309 static const WCHAR empty_stringW
[] = {0};
311 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, empty_stringW
, TRUE
);
313 if (es
->flags
& EF_UPDATE
) {
314 es
->flags
&= ~EF_UPDATE
;
315 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
320 /*********************************************************************
325 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
327 EDIT_WM_Copy(wnd
, es
);
328 EDIT_WM_Clear(wnd
, es
);
332 /**********************************************************************
335 * Returns the window version in case Wine emulates a later version
336 * of windows then the application expects.
338 * In a number of cases when windows runs an application that was
339 * designed for an earlier windows version, windows reverts
340 * to "old" behaviour of that earlier version.
342 * An example is a disabled edit control that needs to be painted.
343 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
344 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
345 * applications with an expected version 0f 4.0 or higher.
348 static DWORD
get_app_version(void)
350 static DWORD version
;
353 DWORD dwEmulatedVersion
;
355 DWORD dwProcVersion
= GetProcessVersion(0);
357 GetVersionExW( &info
);
358 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
359 /* fixme: this may not be 100% correct; see discussion on the
360 * wine developer list in Nov 1999 */
361 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
367 /*********************************************************************
371 * The messages are in the order of the actual integer values
372 * (which can be found in include/windows.h)
373 * Whereever possible the 16 bit versions are converted to
374 * the 32 bit ones, so that we can 'fall through' to the
375 * helper functions. These are mostly 32 bit (with a few
376 * exceptions, clearly indicated by a '16' extension to their
380 static LRESULT WINAPI
EditWndProc_locked( WND
*wnd
, UINT msg
,
381 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
383 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
388 DPRINTF_EDIT_MSG32("WM_DESTROY");
389 EDIT_WM_Destroy(wnd
, es
);
394 DPRINTF_EDIT_MSG32("WM_NCCREATE");
397 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
398 result
= EDIT_WM_NCCreate(wnd
, cs
->style
, cs
->hwndParent
, TRUE
);
402 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
403 result
= EDIT_WM_NCCreate(wnd
, cs
->style
, cs
->hwndParent
, FALSE
);
411 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
413 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
418 EDIT_LockBuffer(wnd
, es
);
421 DPRINTF_EDIT_MSG16("EM_GETSEL");
426 DPRINTF_EDIT_MSG32("EM_GETSEL");
427 result
= EDIT_EM_GetSel(es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
431 DPRINTF_EDIT_MSG16("EM_SETSEL");
432 if (SLOWORD(lParam
) == -1)
433 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
435 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
437 EDIT_EM_ScrollCaret(wnd
, es
);
441 DPRINTF_EDIT_MSG32("EM_SETSEL");
442 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
443 EDIT_EM_ScrollCaret(wnd
, es
);
448 DPRINTF_EDIT_MSG16("EM_GETRECT");
450 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
453 DPRINTF_EDIT_MSG32("EM_GETRECT");
455 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
459 DPRINTF_EDIT_MSG16("EM_SETRECT");
460 if ((es
->style
& ES_MULTILINE
) && lParam
) {
462 CONV_RECT16TO32(MapSL(lParam
), &rc
);
463 EDIT_SetRectNP(wnd
, es
, &rc
);
464 EDIT_UpdateText(wnd
, NULL
, TRUE
);
468 DPRINTF_EDIT_MSG32("EM_SETRECT");
469 if ((es
->style
& ES_MULTILINE
) && lParam
) {
470 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
471 EDIT_UpdateText(wnd
, NULL
, TRUE
);
476 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
477 if ((es
->style
& ES_MULTILINE
) && lParam
) {
479 CONV_RECT16TO32(MapSL(lParam
), &rc
);
480 EDIT_SetRectNP(wnd
, es
, &rc
);
484 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
485 if ((es
->style
& ES_MULTILINE
) && lParam
)
486 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
490 DPRINTF_EDIT_MSG16("EM_SCROLL");
493 DPRINTF_EDIT_MSG32("EM_SCROLL");
494 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
497 case EM_LINESCROLL16
:
498 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
499 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
500 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
503 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
504 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
507 case EM_SCROLLCARET16
:
508 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
511 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
512 EDIT_EM_ScrollCaret(wnd
, es
);
517 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
520 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
521 result
= ((es
->flags
& EF_MODIFIED
) != 0);
525 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
528 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
530 es
->flags
|= EF_MODIFIED
;
532 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
535 case EM_GETLINECOUNT16
:
536 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
538 case EM_GETLINECOUNT
:
539 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
540 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
544 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
545 if ((INT16
)wParam
== -1)
549 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
550 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
554 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
555 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
558 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
559 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
563 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
564 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
567 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
568 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
572 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
575 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
576 result
= EDIT_EM_GetThumb(wnd
, es
);
579 /* messages 0x00bf and 0x00c0 missing from specs */
582 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
585 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
587 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
589 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
593 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
596 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
598 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
600 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
603 case EM_LINELENGTH16
:
604 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
607 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
608 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
611 case EM_REPLACESEL16
:
612 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
613 lParam
= (LPARAM
)MapSL(lParam
);
618 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
621 textW
= (LPWSTR
)lParam
;
624 LPSTR textA
= (LPSTR
)lParam
;
625 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
626 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
627 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
630 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, textW
, TRUE
);
631 if (es
->flags
& EF_UPDATE
) {
632 es
->flags
&= ~EF_UPDATE
;
633 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
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");
649 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
651 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
655 DPRINTF_EDIT_MSG16("EM_GETLINE");
656 lParam
= (LPARAM
)MapSL(lParam
);
659 DPRINTF_EDIT_MSG32("EM_GETLINE");
660 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
664 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
666 case EM_SETLIMITTEXT
:
667 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
668 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
672 DPRINTF_EDIT_MSG16("EM_CANUNDO");
675 DPRINTF_EDIT_MSG32("EM_CANUNDO");
676 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
680 DPRINTF_EDIT_MSG16("EM_UNDO");
685 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
686 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
690 DPRINTF_EDIT_MSG16("EM_FMTLINES");
693 DPRINTF_EDIT_MSG32("EM_FMTLINES");
694 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
697 case EM_LINEFROMCHAR16
:
698 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
700 case EM_LINEFROMCHAR
:
701 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
702 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
705 /* message 0x00ca missing from specs */
708 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
711 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
713 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
715 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
718 case EM_SETTABSTOPS16
:
719 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
720 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
723 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
724 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
727 case EM_SETPASSWORDCHAR16
:
728 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
730 case EM_SETPASSWORDCHAR
:
733 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
736 charW
= (WCHAR
)wParam
;
740 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
743 EDIT_EM_SetPasswordChar(wnd
, es
, charW
);
747 case EM_EMPTYUNDOBUFFER16
:
748 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
750 case EM_EMPTYUNDOBUFFER
:
751 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
752 EDIT_EM_EmptyUndoBuffer(es
);
755 case EM_GETFIRSTVISIBLELINE16
:
756 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
757 result
= es
->y_offset
;
759 case EM_GETFIRSTVISIBLELINE
:
760 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
761 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
764 case EM_SETREADONLY16
:
765 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
768 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
770 wnd
->dwStyle
|= ES_READONLY
;
771 es
->style
|= ES_READONLY
;
773 wnd
->dwStyle
&= ~ES_READONLY
;
774 es
->style
&= ~ES_READONLY
;
779 case EM_SETWORDBREAKPROC16
:
780 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
781 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
783 case EM_SETWORDBREAKPROC
:
784 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
785 EDIT_EM_SetWordBreakProc(wnd
, es
, lParam
);
788 case EM_GETWORDBREAKPROC16
:
789 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
790 result
= (LRESULT
)es
->word_break_proc16
;
792 case EM_GETWORDBREAKPROC
:
793 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
794 result
= (LRESULT
)es
->word_break_proc
;
797 case EM_GETPASSWORDCHAR16
:
798 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
800 case EM_GETPASSWORDCHAR
:
802 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
805 result
= es
->password_char
;
808 WCHAR charW
= es
->password_char
;
810 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
816 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
819 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
820 EDIT_EM_SetMargins(es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
824 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
825 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
828 case EM_GETLIMITTEXT
:
829 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
830 result
= es
->buffer_limit
;
834 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
835 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
839 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
840 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
844 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
845 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
847 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
849 int vk
= (int)((LPMSG
)lParam
)->wParam
;
851 if ((wnd
->dwStyle
& ES_WANTRETURN
) && vk
== VK_RETURN
)
853 result
|= DLGC_WANTMESSAGE
;
855 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
857 if (SendMessageW(wnd
->parent
->hwndSelf
, CB_GETDROPPEDSTATE
, 0, 0))
858 result
|= DLGC_WANTMESSAGE
;
866 DPRINTF_EDIT_MSG32("WM_CHAR");
873 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
876 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
878 if (SendMessageW(wnd
->parent
->hwndSelf
, CB_GETDROPPEDSTATE
, 0, 0))
879 SendMessageW(wnd
->parent
->hwndSelf
, WM_KEYDOWN
, charW
, 0);
882 EDIT_WM_Char(wnd
, es
, charW
);
887 DPRINTF_EDIT_MSG32("WM_CLEAR");
888 EDIT_WM_Clear(wnd
, es
);
892 DPRINTF_EDIT_MSG32("WM_COMMAND");
893 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
897 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
898 EDIT_WM_ContextMenu(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
902 DPRINTF_EDIT_MSG32("WM_COPY");
903 EDIT_WM_Copy(wnd
, es
);
907 DPRINTF_EDIT_MSG32("WM_CREATE");
909 result
= EDIT_WM_Create(wnd
, es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
912 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
916 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
917 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
918 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
920 result
= EDIT_WM_Create(wnd
, es
, nameW
);
922 HeapFree(GetProcessHeap(), 0, nameW
);
927 DPRINTF_EDIT_MSG32("WM_CUT");
928 EDIT_WM_Cut(wnd
, es
);
932 DPRINTF_EDIT_MSG32("WM_ENABLE");
933 es
->bEnableState
= (BOOL
) wParam
;
934 EDIT_UpdateText(wnd
, NULL
, TRUE
);
938 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
939 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
943 DPRINTF_EDIT_MSG32("WM_GETFONT");
944 result
= (LRESULT
)es
->font
;
948 DPRINTF_EDIT_MSG32("WM_GETTEXT");
949 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
952 case WM_GETTEXTLENGTH
:
953 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
954 result
= strlenW(es
->text
);
958 DPRINTF_EDIT_MSG32("WM_HSCROLL");
959 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
963 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
964 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
);
968 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
969 result
= EDIT_WM_KillFocus(wnd
, es
);
972 case WM_LBUTTONDBLCLK
:
973 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
974 result
= EDIT_WM_LButtonDblClk(wnd
, es
);
978 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
979 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
983 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
984 result
= EDIT_WM_LButtonUp(wnd
->hwndSelf
, es
);
988 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
989 result
= EDIT_WM_MButtonDown(wnd
);
992 case WM_MOUSEACTIVATE
:
994 * FIXME: maybe DefWindowProc() screws up, but it seems that
995 * modeless dialog boxes need this. If we don't do this, the focus
996 * will _not_ be set by DefWindowProc() for edit controls in a
997 * modeless dialog box ???
999 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
1000 SetFocus(wnd
->hwndSelf
);
1001 result
= MA_ACTIVATE
;
1006 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
1008 result
= EDIT_WM_MouseMove(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
1012 DPRINTF_EDIT_MSG32("WM_PAINT");
1013 EDIT_WM_Paint(wnd
, es
, wParam
);
1017 DPRINTF_EDIT_MSG32("WM_PASTE");
1018 EDIT_WM_Paste(wnd
, es
);
1022 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
1023 EDIT_WM_SetFocus(wnd
, es
);
1027 DPRINTF_EDIT_MSG32("WM_SETFONT");
1028 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
1032 /* FIXME: actually set an internal flag and behave accordingly */
1036 DPRINTF_EDIT_MSG32("WM_SETTEXT");
1037 EDIT_WM_SetText(wnd
, es
, lParam
, unicode
);
1042 DPRINTF_EDIT_MSG32("WM_SIZE");
1043 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1047 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
1048 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
1052 DPRINTF_EDIT_MSG32("WM_TIMER");
1053 EDIT_WM_Timer(wnd
, es
);
1057 DPRINTF_EDIT_MSG32("WM_VSCROLL");
1058 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
1063 int gcWheelDelta
= 0;
1064 UINT pulScrollLines
= 3;
1065 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1067 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1069 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1071 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1074 gcWheelDelta
-= SHIWORD(wParam
);
1075 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1077 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1078 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1079 result
= EDIT_EM_LineScroll(wnd
, es
, 0, cLineScroll
);
1085 result
= DefWindowProcW(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1087 result
= DefWindowProcA(wnd
->hwndSelf
, msg
, wParam
, lParam
);
1090 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
1095 /*********************************************************************
1097 * EditWndProcW (USER32.@)
1099 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1102 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1104 res
= EditWndProc_locked(wndPtr
, uMsg
, wParam
, lParam
, TRUE
);
1106 WIN_ReleaseWndPtr(wndPtr
);
1110 /*********************************************************************
1112 * EditWndProcA (USER32.@)
1114 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1117 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1119 res
= EditWndProc_locked(wndPtr
, uMsg
, wParam
, lParam
, FALSE
);
1121 WIN_ReleaseWndPtr(wndPtr
);
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(WND
*wnd
, EDITSTATE
*es
)
1140 LINEDEF
*current_def
;
1141 LINEDEF
**previous_next
;
1143 current_def
= es
->first_line_def
;
1145 LINEDEF
*next_def
= current_def
->next
;
1146 HeapFree(GetProcessHeap(), 0, current_def
);
1147 current_def
= next_def
;
1148 } while (current_def
);
1152 dc
= GetDC(wnd
->hwndSelf
);
1154 old_font
= SelectObject(dc
, es
->font
);
1156 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1158 previous_next
= &es
->first_line_def
;
1160 current_def
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1161 current_def
->next
= NULL
;
1164 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1169 current_def
->ending
= END_0
;
1170 current_def
->net_length
= strlenW(start
);
1171 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
1172 current_def
->ending
= END_SOFT
;
1173 current_def
->net_length
= cp
- start
- 1;
1175 current_def
->ending
= END_HARD
;
1176 current_def
->net_length
= cp
- start
;
1178 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1179 start
, current_def
->net_length
,
1180 es
->tabs_count
, es
->tabs
));
1181 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1182 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
1187 next
= EDIT_CallWordBreakProc(es
, start
- es
->text
,
1188 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
1189 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1190 start
, next
, es
->tabs_count
, es
->tabs
));
1191 } while (current_def
->width
<= fw
);
1197 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1198 start
, next
, es
->tabs_count
, es
->tabs
));
1199 } while (current_def
->width
<= fw
);
1203 current_def
->net_length
= prev
;
1204 current_def
->ending
= END_WRAP
;
1205 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, start
,
1206 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
1208 switch (current_def
->ending
) {
1210 current_def
->length
= current_def
->net_length
+ 3;
1213 current_def
->length
= current_def
->net_length
+ 2;
1217 current_def
->length
= current_def
->net_length
;
1220 es
->text_width
= max(es
->text_width
, current_def
->width
);
1221 start
+= current_def
->length
;
1222 *previous_next
= current_def
;
1223 previous_next
= ¤t_def
->next
;
1225 } while (current_def
->ending
!= END_0
);
1227 SelectObject(dc
, old_font
);
1228 ReleaseDC(wnd
->hwndSelf
, dc
);
1231 /*********************************************************************
1233 * EDIT_CalcLineWidth_SL
1236 static void EDIT_CalcLineWidth_SL(WND
*wnd
, EDITSTATE
*es
)
1238 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, strlenW(es
->text
), FALSE
));
1241 /*********************************************************************
1243 * EDIT_CallWordBreakProc
1245 * Call appropriate WordBreakProc (internal or external).
1247 * Note: The "start" argument should always be an index refering
1248 * to es->text. The actual wordbreak proc might be
1249 * 16 bit, so we can't always pass any 32 bit LPSTR.
1250 * Hence we assume that es->text is the buffer that holds
1251 * the string under examination (we can decide this for ourselves).
1254 /* ### start build ### */
1255 extern WORD CALLBACK
EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16
,SEGPTR
,WORD
,WORD
,WORD
);
1256 /* ### stop build ### */
1257 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1259 INT ret
, iWndsLocks
;
1261 /* To avoid any deadlocks, all the locks on the windows structures
1262 must be suspended before the control is passed to the application */
1263 iWndsLocks
= WIN_SuspendWndsLock();
1265 if (es
->word_break_proc16
) {
1270 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1271 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1272 segptr
= K32WOWGlobalLock16(hglob16
);
1273 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1274 ret
= (INT
)EDIT_CallTo16_word_lwww(es
->word_break_proc16
,
1275 segptr
, index
, countA
, action
);
1276 GlobalUnlock16(hglob16
);
1277 GlobalFree16(hglob16
);
1279 else if (es
->word_break_proc
)
1283 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1285 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1286 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1287 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1291 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1295 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1296 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1297 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1298 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1299 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1300 ret
= wbpA(textA
, index
, countA
, action
);
1301 HeapFree(GetProcessHeap(), 0, textA
);
1305 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1307 WIN_RestoreWndsLock(iWndsLocks
);
1312 /*********************************************************************
1316 * Beware: This is not the function called on EM_CHARFROMPOS
1317 * The position _can_ be outside the formatting / client
1319 * The return value is only the character index
1322 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1328 if (es
->style
& ES_MULTILINE
) {
1329 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1331 LINEDEF
*line_def
= es
->first_line_def
;
1333 while ((line
> 0) && line_def
->next
) {
1334 line_index
+= line_def
->length
;
1335 line_def
= line_def
->next
;
1338 x
+= es
->x_offset
- es
->format_rect
.left
;
1339 if (x
>= line_def
->width
) {
1341 *after_wrap
= (line_def
->ending
== END_WRAP
);
1342 return line_index
+ line_def
->net_length
;
1346 *after_wrap
= FALSE
;
1349 dc
= GetDC(wnd
->hwndSelf
);
1351 old_font
= SelectObject(dc
, es
->font
);
1352 low
= line_index
+ 1;
1353 high
= line_index
+ line_def
->net_length
+ 1;
1354 while (low
< high
- 1)
1356 INT mid
= (low
+ high
) / 2;
1357 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1363 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1364 (line_def
->ending
== END_WRAP
));
1369 *after_wrap
= FALSE
;
1370 x
-= es
->format_rect
.left
;
1372 return es
->x_offset
;
1373 text
= EDIT_GetPasswordPointer_SL(es
);
1374 dc
= GetDC(wnd
->hwndSelf
);
1376 old_font
= SelectObject(dc
, es
->font
);
1380 INT high
= es
->x_offset
;
1381 while (low
< high
- 1)
1383 INT mid
= (low
+ high
) / 2;
1384 GetTextExtentPoint32W( dc
, text
+ mid
,
1385 es
->x_offset
- mid
, &size
);
1386 if (size
.cx
> -x
) low
= mid
;
1393 INT low
= es
->x_offset
;
1394 INT high
= strlenW(es
->text
) + 1;
1395 while (low
< high
- 1)
1397 INT mid
= (low
+ high
) / 2;
1398 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1399 mid
- es
->x_offset
, &size
);
1400 if (size
.cx
> x
) high
= mid
;
1405 if (es
->style
& ES_PASSWORD
)
1406 HeapFree(GetProcessHeap(), 0, text
);
1409 SelectObject(dc
, old_font
);
1410 ReleaseDC(wnd
->hwndSelf
, dc
);
1415 /*********************************************************************
1419 * adjusts the point to be within the formatting rectangle
1420 * (so CharFromPos returns the nearest _visible_ character)
1423 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1425 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1426 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1430 /*********************************************************************
1434 * Calculates the bounding rectangle for a line from a starting
1435 * column to an ending column.
1438 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1440 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1442 if (es
->style
& ES_MULTILINE
)
1443 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1445 rc
->top
= es
->format_rect
.top
;
1446 rc
->bottom
= rc
->top
+ es
->line_height
;
1447 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1448 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1452 /*********************************************************************
1454 * EDIT_GetPasswordPointer_SL
1456 * note: caller should free the (optionally) allocated buffer
1459 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1461 if (es
->style
& ES_PASSWORD
) {
1462 INT len
= strlenW(es
->text
);
1463 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1465 while(len
) text
[--len
] = es
->password_char
;
1472 /*********************************************************************
1476 * This acts as a LOCAL_Lock(), but it locks only once. This way
1477 * you can call it whenever you like, without unlocking.
1480 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1483 ERR("no EDITSTATE ... please report\n");
1489 BOOL _16bit
= FALSE
;
1495 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1496 textA
= LocalLock(es
->hloc32A
);
1497 countA
= strlen(textA
) + 1;
1501 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1502 textA
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1503 countA
= strlen(textA
) + 1;
1508 ERR("no buffer ... please report\n");
1515 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1516 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1517 if(countW_new
> es
->buffer_size
+ 1)
1519 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1520 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1521 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1524 es
->hloc32W
= hloc32W_new
;
1525 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1526 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1529 WARN("FAILED! Will synchronize partially\n");
1533 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1534 es
->text
= LocalLock(es
->hloc32W
);
1538 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1540 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1542 LocalUnlock(es
->hloc32A
);
1549 /*********************************************************************
1551 * EDIT_SL_InvalidateText
1553 * Called from EDIT_InvalidateText().
1554 * Does the job for single-line controls only.
1557 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1562 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1563 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1564 EDIT_UpdateText(wnd
, &rc
, FALSE
);
1568 /*********************************************************************
1570 * EDIT_ML_InvalidateText
1572 * Called from EDIT_InvalidateText().
1573 * Does the job for multi-line controls only.
1576 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1578 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1579 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1580 INT el
= EDIT_EM_LineFromChar(es
, end
);
1589 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1592 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1593 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1594 if (sl
< es
->y_offset
) {
1598 if (el
> es
->y_offset
+ vlc
) {
1599 el
= es
->y_offset
+ vlc
;
1600 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1602 GetClientRect(wnd
->hwndSelf
, &rc1
);
1603 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1605 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1606 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1607 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1609 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1610 EDIT_EM_LineLength(es
,
1611 EDIT_EM_LineIndex(es
, sl
)),
1613 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1614 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1615 for (l
= sl
+ 1 ; l
< el
; l
++) {
1616 EDIT_GetLineRect(wnd
, es
, l
, 0,
1617 EDIT_EM_LineLength(es
,
1618 EDIT_EM_LineIndex(es
, l
)),
1620 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1621 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1623 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1624 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1625 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1630 /*********************************************************************
1632 * EDIT_InvalidateText
1634 * Invalidate the text from offset start upto, but not including,
1635 * offset end. Useful for (re)painting the selection.
1636 * Regions outside the linewidth are not invalidated.
1637 * end == -1 means end == TextLength.
1638 * start and end need not be ordered.
1641 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1647 end
= strlenW(es
->text
);
1649 ORDER_INT(start
, end
);
1651 if (es
->style
& ES_MULTILINE
)
1652 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1654 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1658 /*********************************************************************
1662 * Try to fit size + 1 characters in the buffer. Constrain to limits.
1665 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, UINT size
)
1669 if (size
<= es
->buffer_size
)
1671 if (size
> es
->buffer_limit
) {
1672 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1675 if (size
> es
->buffer_limit
)
1676 size
= es
->buffer_limit
;
1678 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1680 /* Force edit to unlock it's buffer. es->text now NULL */
1681 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1684 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1685 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1686 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32W
, hNew32W
);
1687 es
->hloc32W
= hNew32W
;
1688 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1692 EDIT_LockBuffer(wnd
, es
);
1694 if (es
->buffer_size
< size
) {
1695 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1696 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1699 TRACE("We now have %d+1\n", es
->buffer_size
);
1705 /*********************************************************************
1709 * Try to fit size + 1 bytes in the undo buffer.
1712 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1716 if (size
<= es
->undo_buffer_size
)
1719 TRACE("trying to ReAlloc to %d+1\n", size
);
1721 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1722 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1723 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
);
1728 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1734 /*********************************************************************
1739 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1741 INT e
= es
->selection_end
;
1745 if ((es
->style
& ES_MULTILINE
) && e
&&
1746 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1748 if (e
&& (es
->text
[e
- 1] == '\r'))
1752 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1753 EDIT_EM_ScrollCaret(wnd
, es
);
1757 /*********************************************************************
1761 * Only for multi line controls
1762 * Move the caret one line down, on a column with the nearest
1763 * x coordinate on the screen (might be a different column).
1766 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1768 INT s
= es
->selection_start
;
1769 INT e
= es
->selection_end
;
1770 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1771 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1772 INT x
= SLOWORD(pos
);
1773 INT y
= SHIWORD(pos
);
1775 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1778 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1779 EDIT_EM_ScrollCaret(wnd
, es
);
1783 /*********************************************************************
1788 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1790 BOOL after_wrap
= FALSE
;
1793 /* Pass a high value in x to make sure of receiving the end of the line */
1794 if (es
->style
& ES_MULTILINE
)
1795 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1796 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1798 e
= strlenW(es
->text
);
1799 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1800 EDIT_EM_ScrollCaret(wnd
, es
);
1804 /*********************************************************************
1809 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1811 INT e
= es
->selection_end
;
1815 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1816 if (es
->text
[e
] == '\n')
1818 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1822 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1823 EDIT_EM_ScrollCaret(wnd
, es
);
1827 /*********************************************************************
1831 * Home key: move to beginning of line.
1834 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1838 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1839 if (es
->style
& ES_MULTILINE
)
1840 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1841 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1844 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1845 EDIT_EM_ScrollCaret(wnd
, es
);
1849 /*********************************************************************
1851 * EDIT_MovePageDown_ML
1853 * Only for multi line controls
1854 * Move the caret one page down, on a column with the nearest
1855 * x coordinate on the screen (might be a different column).
1858 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1860 INT s
= es
->selection_start
;
1861 INT e
= es
->selection_end
;
1862 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1863 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1864 INT x
= SLOWORD(pos
);
1865 INT y
= SHIWORD(pos
);
1867 e
= EDIT_CharFromPos(wnd
, es
, x
,
1868 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1872 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1873 EDIT_EM_ScrollCaret(wnd
, es
);
1877 /*********************************************************************
1879 * EDIT_MovePageUp_ML
1881 * Only for multi line controls
1882 * Move the caret one page up, on a column with the nearest
1883 * x coordinate on the screen (might be a different column).
1886 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1888 INT s
= es
->selection_start
;
1889 INT e
= es
->selection_end
;
1890 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1891 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1892 INT x
= SLOWORD(pos
);
1893 INT y
= SHIWORD(pos
);
1895 e
= EDIT_CharFromPos(wnd
, es
, x
,
1896 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1900 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1901 EDIT_EM_ScrollCaret(wnd
, es
);
1905 /*********************************************************************
1909 * Only for multi line controls
1910 * Move the caret one line up, on a column with the nearest
1911 * x coordinate on the screen (might be a different column).
1914 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1916 INT s
= es
->selection_start
;
1917 INT e
= es
->selection_end
;
1918 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1919 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1920 INT x
= SLOWORD(pos
);
1921 INT y
= SHIWORD(pos
);
1923 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1926 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1927 EDIT_EM_ScrollCaret(wnd
, es
);
1931 /*********************************************************************
1933 * EDIT_MoveWordBackward
1936 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1938 INT s
= es
->selection_start
;
1939 INT e
= es
->selection_end
;
1944 l
= EDIT_EM_LineFromChar(es
, e
);
1945 ll
= EDIT_EM_LineLength(es
, e
);
1946 li
= EDIT_EM_LineIndex(es
, l
);
1949 li
= EDIT_EM_LineIndex(es
, l
- 1);
1950 e
= li
+ EDIT_EM_LineLength(es
, li
);
1953 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
1954 li
, e
- li
, ll
, WB_LEFT
);
1958 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1959 EDIT_EM_ScrollCaret(wnd
, es
);
1963 /*********************************************************************
1965 * EDIT_MoveWordForward
1968 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1970 INT s
= es
->selection_start
;
1971 INT e
= es
->selection_end
;
1976 l
= EDIT_EM_LineFromChar(es
, e
);
1977 ll
= EDIT_EM_LineLength(es
, e
);
1978 li
= EDIT_EM_LineIndex(es
, l
);
1980 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1981 e
= EDIT_EM_LineIndex(es
, l
+ 1);
1983 e
= li
+ EDIT_CallWordBreakProc(es
,
1984 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1988 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1989 EDIT_EM_ScrollCaret(wnd
, es
);
1993 /*********************************************************************
1998 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2000 INT s
= es
->selection_start
;
2001 INT e
= es
->selection_end
;
2008 if (es
->style
& ES_MULTILINE
) {
2009 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2010 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2015 TRACE("line=%d\n", line
);
2017 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2020 li
= EDIT_EM_LineIndex(es
, line
);
2021 ll
= EDIT_EM_LineLength(es
, li
);
2022 s
= es
->selection_start
;
2023 e
= es
->selection_end
;
2025 s
= min(li
+ ll
, max(li
, s
));
2026 e
= min(li
+ ll
, max(li
, e
));
2027 if (rev
&& (s
!= e
) &&
2028 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2029 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2030 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2031 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2033 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2037 /*********************************************************************
2042 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2052 BkColor
= GetBkColor(dc
);
2053 TextColor
= GetTextColor(dc
);
2055 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2056 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2058 li
= EDIT_EM_LineIndex(es
, line
);
2059 if (es
->style
& ES_MULTILINE
) {
2060 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2061 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2063 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2064 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2065 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2067 if (es
->style
& ES_PASSWORD
)
2068 HeapFree(GetProcessHeap(), 0, text
);
2071 SetBkColor(dc
, BkColor
);
2072 SetTextColor(dc
, TextColor
);
2078 /*********************************************************************
2083 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
2086 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
2087 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2091 /*********************************************************************
2095 * note: this is not (exactly) the handler called on EM_SETRECTNP
2096 * it is also used to set the rect of a single line control
2099 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
2101 CopyRect(&es
->format_rect
, rc
);
2102 if (es
->style
& WS_BORDER
) {
2103 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2104 if(TWEAK_WineLook
== WIN31_LOOK
)
2106 es
->format_rect
.left
+= bw
;
2107 es
->format_rect
.top
+= bw
;
2108 es
->format_rect
.right
-= bw
;
2109 es
->format_rect
.bottom
-= bw
;
2111 es
->format_rect
.left
+= es
->left_margin
;
2112 es
->format_rect
.right
-= es
->right_margin
;
2113 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2114 if (es
->style
& ES_MULTILINE
)
2116 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2118 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2119 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2121 /* correct es->x_offset */
2122 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2123 max_x_offset
= es
->text_width
- fw
;
2124 if(max_x_offset
< 0) max_x_offset
= 0;
2125 if(es
->x_offset
> max_x_offset
)
2126 es
->x_offset
= max_x_offset
;
2128 /* correct es->y_offset */
2129 max_y_offset
= es
->line_count
- vlc
;
2130 if(max_y_offset
< 0) max_y_offset
= 0;
2131 if(es
->y_offset
> max_y_offset
)
2132 es
->y_offset
= max_y_offset
;
2134 /* force scroll info update */
2135 EDIT_UpdateScrollInfo(wnd
, es
);
2138 /* Windows doesn't care to fix text placement for SL controls */
2139 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2141 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2142 EDIT_BuildLineDefs_ML(wnd
, es
);
2146 /*********************************************************************
2151 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
2154 ERR("no EDITSTATE ... please report\n");
2157 if (!es
->lock_count
) {
2158 ERR("lock_count == 0 ... please report\n");
2162 ERR("es->text == 0 ... please report\n");
2166 if (force
|| (es
->lock_count
== 1)) {
2169 BOOL _16bit
= FALSE
;
2171 UINT countW
= strlenW(es
->text
) + 1;
2175 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2176 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2177 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2178 countA
= LocalSize(es
->hloc32A
);
2179 if(countA_new
> countA
)
2182 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2183 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2184 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2187 es
->hloc32A
= hloc32A_new
;
2188 countA
= LocalSize(hloc32A_new
);
2189 TRACE("Real new size %d bytes\n", countA
);
2192 WARN("FAILED! Will synchronize partially\n");
2194 textA
= LocalLock(es
->hloc32A
);
2198 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2199 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2200 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2201 countA
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
);
2202 if(countA_new
> countA
)
2204 HLOCAL16 hloc16_new
;
2205 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2206 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2207 hloc16_new
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2210 es
->hloc16
= hloc16_new
;
2211 countA
= LOCAL_Size(wnd
->hInstance
, hloc16_new
);
2212 TRACE("Real new size %d bytes\n", countA
);
2215 WARN("FAILED! Will synchronize partially\n");
2217 textA
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
2223 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2225 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
2227 LocalUnlock(es
->hloc32A
);
2230 LocalUnlock(es
->hloc32W
);
2234 ERR("no buffer ... please report\n");
2242 /*********************************************************************
2244 * EDIT_UpdateScrollInfo
2247 static void EDIT_UpdateScrollInfo(WND
*wnd
, EDITSTATE
*es
)
2249 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2252 si
.cbSize
= sizeof(SCROLLINFO
);
2253 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2255 si
.nMax
= es
->line_count
- 1;
2256 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2257 si
.nPos
= es
->y_offset
;
2258 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2259 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2260 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2263 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2266 si
.cbSize
= sizeof(SCROLLINFO
);
2267 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2269 si
.nMax
= es
->text_width
- 1;
2270 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2271 si
.nPos
= es
->x_offset
;
2272 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2273 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2274 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2278 /*********************************************************************
2280 * EDIT_WordBreakProc
2282 * Find the beginning of words.
2283 * Note: unlike the specs for a WordBreakProc, this function only
2284 * allows to be called without linebreaks between s[0] upto
2285 * s[count - 1]. Remember it is only called
2286 * internally, so we can decide this for ourselves.
2289 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2293 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2303 if (s
[index
] == ' ') {
2304 while (index
&& (s
[index
] == ' '))
2307 while (index
&& (s
[index
] != ' '))
2309 if (s
[index
] == ' ')
2313 while (index
&& (s
[index
] != ' '))
2315 if (s
[index
] == ' ')
2325 if (s
[index
] == ' ')
2326 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2328 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2330 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2334 case WB_ISDELIMITER
:
2335 ret
= (s
[index
] == ' ');
2338 ERR("unknown action code, please report !\n");
2345 /*********************************************************************
2349 * returns line number (not index) in high-order word of result.
2350 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2351 * to Richedit, not to the edit control. Original documentation is valid.
2352 * FIXME: do the specs mean to return -1 if outside client area or
2353 * if outside formatting rectangle ???
2356 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
2364 GetClientRect(wnd
->hwndSelf
, &rc
);
2365 if (!PtInRect(&rc
, pt
))
2368 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
2369 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2373 /*********************************************************************
2377 * Enable or disable soft breaks.
2379 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2381 es
->flags
&= ~EF_USE_SOFTBRK
;
2383 es
->flags
|= EF_USE_SOFTBRK
;
2384 FIXME("soft break enabled, not implemented\n");
2390 /*********************************************************************
2394 * Hopefully this won't fire back at us.
2395 * We always start with a fixed buffer in the local heap.
2396 * Despite of the documentation says that the local heap is used
2397 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2398 * buffer on the local heap.
2401 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2405 if (!(es
->style
& ES_MULTILINE
))
2409 hLocal
= es
->hloc32W
;
2415 UINT countA
, alloc_size
;
2416 TRACE("Allocating 32-bit ANSI alias buffer\n");
2417 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2418 alloc_size
= ROUND_TO_GROW(countA
);
2419 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2421 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2424 textA
= LocalLock(es
->hloc32A
);
2425 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2426 LocalUnlock(es
->hloc32A
);
2428 hLocal
= es
->hloc32A
;
2431 TRACE("Returning %04X, LocalSize() = %d\n", hLocal
, LocalSize(hLocal
));
2436 /*********************************************************************
2440 * Hopefully this won't fire back at us.
2441 * We always start with a buffer in 32 bit linear memory.
2442 * However, with this message a 16 bit application requests
2443 * a handle of 16 bit local heap memory, where it expects to find
2445 * It's a pitty that from this moment on we have to use this
2446 * local heap, because applications may rely on the handle
2449 * In this function we'll try to switch to local heap.
2451 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2454 UINT countA
, alloc_size
;
2456 if (!(es
->style
& ES_MULTILINE
))
2462 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2463 if (!LocalInit16(wnd
->hInstance
, 0,
2464 GlobalSize16(wnd
->hInstance
))) {
2465 ERR("could not initialize local heap\n");
2468 TRACE("local heap initialized\n");
2471 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2472 alloc_size
= ROUND_TO_GROW(countA
);
2474 TRACE("Allocating 16-bit ANSI alias buffer\n");
2475 if (!(es
->hloc16
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2476 ERR("could not allocate new 16 bit buffer\n");
2480 if (!(textA
= (LPSTR
)LOCAL_Lock(wnd
->hInstance
, es
->hloc16
))) {
2481 ERR("could not lock new 16 bit buffer\n");
2482 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
2487 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2488 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
2490 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(wnd
->hInstance
, es
->hloc16
));
2495 /*********************************************************************
2500 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR lpch
)
2506 if (es
->style
& ES_MULTILINE
) {
2507 if (line
>= es
->line_count
)
2511 i
= EDIT_EM_LineIndex(es
, line
);
2513 len
= min(*(WORD
*)lpch
, EDIT_EM_LineLength(es
, i
));
2514 for (i
= 0 ; i
< len
; i
++) {
2519 return (LRESULT
)len
;
2523 /*********************************************************************
2528 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2530 UINT s
= es
->selection_start
;
2531 UINT e
= es
->selection_end
;
2538 return MAKELONG(s
, e
);
2542 /*********************************************************************
2546 * FIXME: is this right ? (or should it be only VSCROLL)
2547 * (and maybe only for edit controls that really have their
2548 * own scrollbars) (and maybe only for multiline controls ?)
2549 * All in all: very poorly documented
2552 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2554 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0),
2555 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0));
2559 /*********************************************************************
2564 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2569 if (!(es
->style
& ES_MULTILINE
))
2571 if (index
> (INT
)strlenW(es
->text
))
2572 return es
->line_count
- 1;
2574 index
= min(es
->selection_start
, es
->selection_end
);
2577 line_def
= es
->first_line_def
;
2578 index
-= line_def
->length
;
2579 while ((index
>= 0) && line_def
->next
) {
2581 line_def
= line_def
->next
;
2582 index
-= line_def
->length
;
2588 /*********************************************************************
2593 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2598 if (!(es
->style
& ES_MULTILINE
))
2600 if (line
>= es
->line_count
)
2604 line_def
= es
->first_line_def
;
2606 INT index
= es
->selection_end
- line_def
->length
;
2607 while ((index
>= 0) && line_def
->next
) {
2608 line_index
+= line_def
->length
;
2609 line_def
= line_def
->next
;
2610 index
-= line_def
->length
;
2614 line_index
+= line_def
->length
;
2615 line_def
= line_def
->next
;
2623 /*********************************************************************
2628 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2632 if (!(es
->style
& ES_MULTILINE
))
2633 return strlenW(es
->text
);
2636 /* get the number of remaining non-selected chars of selected lines */
2639 li
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2640 /* # chars before start of selection area */
2641 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, li
);
2642 li
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2643 /* # chars after end of selection */
2644 count
+= EDIT_EM_LineIndex(es
, li
) +
2645 EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2648 line_def
= es
->first_line_def
;
2649 index
-= line_def
->length
;
2650 while ((index
>= 0) && line_def
->next
) {
2651 line_def
= line_def
->next
;
2652 index
-= line_def
->length
;
2654 return line_def
->net_length
;
2658 /*********************************************************************
2662 * NOTE: dx is in average character widths, dy - in lines;
2665 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2667 if (!(es
->style
& ES_MULTILINE
))
2670 dx
*= es
->char_width
;
2671 return EDIT_EM_LineScroll_internal(wnd
, es
, dx
, dy
);
2674 /*********************************************************************
2676 * EDIT_EM_LineScroll_internal
2678 * Version of EDIT_EM_LineScroll for internal use.
2679 * It doesn't refuse if ES_MULTILINE is set and assumes that
2680 * dx is in pixels, dy - in lines.
2683 static BOOL
EDIT_EM_LineScroll_internal(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2686 INT x_offset_in_pixels
;
2688 if (es
->style
& ES_MULTILINE
)
2690 x_offset_in_pixels
= es
->x_offset
;
2695 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->x_offset
, FALSE
));
2698 if (-dx
> x_offset_in_pixels
)
2699 dx
= -x_offset_in_pixels
;
2700 if (dx
> es
->text_width
- x_offset_in_pixels
)
2701 dx
= es
->text_width
- x_offset_in_pixels
;
2702 nyoff
= max(0, es
->y_offset
+ dy
);
2703 if (nyoff
>= es
->line_count
)
2704 nyoff
= es
->line_count
- 1;
2705 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2710 es
->y_offset
= nyoff
;
2711 if(es
->style
& ES_MULTILINE
)
2714 es
->x_offset
+= dx
/ es
->char_width
;
2716 GetClientRect(wnd
->hwndSelf
, &rc1
);
2717 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2718 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2719 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2720 /* force scroll info update */
2721 EDIT_UpdateScrollInfo(wnd
, es
);
2723 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2724 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2725 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2726 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2731 /*********************************************************************
2736 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2738 INT len
= strlenW(es
->text
);
2747 index
= min(index
, len
);
2748 dc
= GetDC(wnd
->hwndSelf
);
2750 old_font
= SelectObject(dc
, es
->font
);
2751 if (es
->style
& ES_MULTILINE
) {
2752 l
= EDIT_EM_LineFromChar(es
, index
);
2753 y
= (l
- es
->y_offset
) * es
->line_height
;
2754 li
= EDIT_EM_LineIndex(es
, l
);
2755 if (after_wrap
&& (li
== index
) && l
) {
2757 LINEDEF
*line_def
= es
->first_line_def
;
2759 line_def
= line_def
->next
;
2762 if (line_def
->ending
== END_WRAP
) {
2764 y
-= es
->line_height
;
2765 li
= EDIT_EM_LineIndex(es
, l
);
2768 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2769 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2771 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2772 if (index
< es
->x_offset
) {
2773 GetTextExtentPoint32W(dc
, text
+ index
,
2774 es
->x_offset
- index
, &size
);
2777 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2778 index
- es
->x_offset
, &size
);
2782 if (es
->style
& ES_PASSWORD
)
2783 HeapFree(GetProcessHeap(), 0, text
);
2785 x
+= es
->format_rect
.left
;
2786 y
+= es
->format_rect
.top
;
2788 SelectObject(dc
, old_font
);
2789 ReleaseDC(wnd
->hwndSelf
, dc
);
2790 return MAKELONG((INT16
)x
, (INT16
)y
);
2794 /*********************************************************************
2798 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2801 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
)
2803 UINT strl
= strlenW(lpsz_replace
);
2804 UINT tl
= strlenW(es
->text
);
2811 TRACE("%s, can_undo %d, send_update %d\n",
2812 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2814 s
= es
->selection_start
;
2815 e
= es
->selection_end
;
2817 if ((s
== e
) && !strl
)
2822 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2826 /* there is something to be deleted */
2828 utl
= strlenW(es
->undo_text
);
2829 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2830 /* undo-buffer is extended to the right */
2831 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2832 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2833 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2834 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2835 /* undo-buffer is extended to the left */
2836 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2837 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2839 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2840 p
[i
] = (es
->text
+ s
)[i
];
2841 es
->undo_position
= s
;
2843 /* new undo-buffer */
2844 EDIT_MakeUndoFit(es
, e
- s
);
2845 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2846 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2847 es
->undo_position
= s
;
2849 /* any deletion makes the old insertion-undo invalid */
2850 es
->undo_insert_count
= 0;
2852 EDIT_EM_EmptyUndoBuffer(es
);
2855 strcpyW(es
->text
+ s
, es
->text
+ e
);
2858 /* there is an insertion */
2860 if ((s
== es
->undo_position
) ||
2861 ((es
->undo_insert_count
) &&
2862 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2864 * insertion is new and at delete position or
2865 * an extension to either left or right
2867 es
->undo_insert_count
+= strl
;
2869 /* new insertion undo */
2870 es
->undo_position
= s
;
2871 es
->undo_insert_count
= strl
;
2872 /* new insertion makes old delete-buffer invalid */
2873 *es
->undo_text
= '\0';
2876 EDIT_EM_EmptyUndoBuffer(es
);
2879 tl
= strlenW(es
->text
);
2880 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2882 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2883 p
[i
] = lpsz_replace
[i
];
2884 if(es
->style
& ES_UPPERCASE
)
2885 CharUpperBuffW(p
, strl
);
2886 else if(es
->style
& ES_LOWERCASE
)
2887 CharLowerBuffW(p
, strl
);
2890 /* FIXME: really inefficient */
2891 if (es
->style
& ES_MULTILINE
)
2892 EDIT_BuildLineDefs_ML(wnd
, es
);
2894 EDIT_CalcLineWidth_SL(wnd
, es
);
2896 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2897 es
->flags
|= EF_MODIFIED
;
2898 if (send_update
) es
->flags
|= EF_UPDATE
;
2899 EDIT_EM_ScrollCaret(wnd
, es
);
2901 /* force scroll info update */
2902 EDIT_UpdateScrollInfo(wnd
, es
);
2904 /* FIXME: really inefficient */
2905 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2909 /*********************************************************************
2914 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2918 if (!(es
->style
& ES_MULTILINE
))
2919 return (LRESULT
)FALSE
;
2929 if (es
->y_offset
< es
->line_count
- 1)
2934 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2937 if (es
->y_offset
< es
->line_count
- 1)
2938 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2941 return (LRESULT
)FALSE
;
2944 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2945 /* check if we are going to move too far */
2946 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
2947 dy
= es
->line_count
- vlc
- es
->y_offset
;
2949 /* Notification is done in EDIT_EM_LineScroll */
2951 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2953 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2957 /*********************************************************************
2962 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2964 if (es
->style
& ES_MULTILINE
) {
2969 INT cw
= es
->char_width
;
2974 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2975 li
= EDIT_EM_LineIndex(es
, l
);
2976 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2977 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2978 if (l
>= es
->y_offset
+ vlc
)
2979 dy
= l
- vlc
+ 1 - es
->y_offset
;
2980 if (l
< es
->y_offset
)
2981 dy
= l
- es
->y_offset
;
2982 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2983 if (x
< es
->format_rect
.left
)
2984 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2985 if (x
> es
->format_rect
.right
)
2986 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2989 /* check if we are going to move too far */
2990 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
2991 dx
= es
->text_width
- ww
- es
->x_offset
;
2993 EDIT_EM_LineScroll_internal(wnd
, es
, dx
, dy
);
3000 if (!(es
->style
& ES_AUTOHSCROLL
))
3003 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
3004 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3005 if (x
< es
->format_rect
.left
) {
3006 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3009 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
3010 } while ((x
< goal
) && es
->x_offset
);
3011 /* FIXME: use ScrollWindow() somehow to improve performance */
3012 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3013 } else if (x
> es
->format_rect
.right
) {
3015 INT len
= strlenW(es
->text
);
3016 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3019 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
3020 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
3021 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3022 /* FIXME: use ScrollWindow() somehow to improve performance */
3023 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3027 if(es
->flags
& EF_FOCUSED
)
3028 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3032 /*********************************************************************
3036 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3039 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
3041 if (!(es
->style
& ES_MULTILINE
))
3045 WARN("called with NULL handle\n");
3049 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
3053 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3054 es
->hloc16
= (HLOCAL16
)NULL
;
3061 LocalFree(es
->hloc32A
);
3062 es
->hloc32A
= (HLOCAL
)NULL
;
3073 countA
= LocalSize(hloc
);
3074 textA
= LocalLock(hloc
);
3075 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3076 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3078 ERR("Could not allocate new unicode buffer\n");
3081 textW
= LocalLock(hloc32W_new
);
3082 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3083 LocalUnlock(hloc32W_new
);
3087 LocalFree(es
->hloc32W
);
3089 es
->hloc32W
= hloc32W_new
;
3093 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3095 EDIT_LockBuffer(wnd
, es
);
3097 es
->x_offset
= es
->y_offset
= 0;
3098 es
->selection_start
= es
->selection_end
= 0;
3099 EDIT_EM_EmptyUndoBuffer(es
);
3100 es
->flags
&= ~EF_MODIFIED
;
3101 es
->flags
&= ~EF_UPDATE
;
3102 EDIT_BuildLineDefs_ML(wnd
, es
);
3103 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3104 EDIT_EM_ScrollCaret(wnd
, es
);
3105 /* force scroll info update */
3106 EDIT_UpdateScrollInfo(wnd
, es
);
3110 /*********************************************************************
3114 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3117 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
3124 if (!(es
->style
& ES_MULTILINE
))
3128 WARN("called with NULL handle\n");
3132 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
3136 LocalFree(es
->hloc32A
);
3137 es
->hloc32A
= (HLOCAL
)NULL
;
3140 countA
= LOCAL_Size(wnd
->hInstance
, hloc
);
3141 textA
= LOCAL_Lock(wnd
->hInstance
, hloc
);
3142 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3143 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3145 ERR("Could not allocate new unicode buffer\n");
3148 textW
= LocalLock(hloc32W_new
);
3149 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3150 LocalUnlock(hloc32W_new
);
3151 LOCAL_Unlock(wnd
->hInstance
, hloc
);
3154 LocalFree(es
->hloc32W
);
3156 es
->hloc32W
= hloc32W_new
;
3159 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3161 EDIT_LockBuffer(wnd
, es
);
3163 es
->x_offset
= es
->y_offset
= 0;
3164 es
->selection_start
= es
->selection_end
= 0;
3165 EDIT_EM_EmptyUndoBuffer(es
);
3166 es
->flags
&= ~EF_MODIFIED
;
3167 es
->flags
&= ~EF_UPDATE
;
3168 EDIT_BuildLineDefs_ML(wnd
, es
);
3169 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3170 EDIT_EM_ScrollCaret(wnd
, es
);
3171 /* force scroll info update */
3172 EDIT_UpdateScrollInfo(wnd
, es
);
3176 /*********************************************************************
3180 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3181 * However, the windows version is not complied to yet in all of edit.c
3184 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3186 if (es
->style
& ES_MULTILINE
) {
3188 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3190 es
->buffer_limit
= BUFLIMIT_MULTI
;
3193 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3195 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3200 /*********************************************************************
3204 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3205 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3206 * of the char's width, according to the new docs.
3209 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3210 INT left
, INT right
)
3212 if (action
& EC_LEFTMARGIN
) {
3213 if (left
!= EC_USEFONTINFO
)
3214 es
->left_margin
= left
;
3216 es
->left_margin
= es
->char_width
/ 3;
3219 if (action
& EC_RIGHTMARGIN
) {
3220 if (right
!= EC_USEFONTINFO
)
3221 es
->right_margin
= right
;
3223 es
->right_margin
= es
->char_width
/ 3;
3225 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3229 /*********************************************************************
3231 * EM_SETPASSWORDCHAR
3234 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, WCHAR c
)
3236 if (es
->style
& ES_MULTILINE
)
3239 if (es
->password_char
== c
)
3242 es
->password_char
= c
;
3244 wnd
->dwStyle
|= ES_PASSWORD
;
3245 es
->style
|= ES_PASSWORD
;
3247 wnd
->dwStyle
&= ~ES_PASSWORD
;
3248 es
->style
&= ~ES_PASSWORD
;
3250 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3254 /*********************************************************************
3258 * note: unlike the specs say: the order of start and end
3259 * _is_ preserved in Windows. (i.e. start can be > end)
3260 * In other words: this handler is OK
3263 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3265 UINT old_start
= es
->selection_start
;
3266 UINT old_end
= es
->selection_end
;
3267 UINT len
= strlenW(es
->text
);
3269 if (start
== (UINT
)-1) {
3270 start
= es
->selection_end
;
3271 end
= es
->selection_end
;
3273 start
= min(start
, len
);
3274 end
= min(end
, len
);
3276 es
->selection_start
= start
;
3277 es
->selection_end
= end
;
3279 es
->flags
|= EF_AFTER_WRAP
;
3281 es
->flags
&= ~EF_AFTER_WRAP
;
3282 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3283 ORDER_UINT(start
, end
);
3284 ORDER_UINT(end
, old_end
);
3285 ORDER_UINT(start
, old_start
);
3286 ORDER_UINT(old_start
, old_end
);
3287 if (end
!= old_start
)
3291 * ORDER_UINT32(end, old_start);
3292 * EDIT_InvalidateText(wnd, es, start, end);
3293 * EDIT_InvalidateText(wnd, es, old_start, old_end);
3294 * in place of the following if statement.
3296 if (old_start
> end
)
3298 EDIT_InvalidateText(wnd
, es
, start
, end
);
3299 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
3303 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
3304 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
3307 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
3311 /*********************************************************************
3316 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3318 if (!(es
->style
& ES_MULTILINE
))
3321 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3322 es
->tabs_count
= count
;
3326 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3327 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3333 /*********************************************************************
3338 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3340 if (!(es
->style
& ES_MULTILINE
))
3343 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3344 es
->tabs_count
= count
;
3349 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3350 for (i
= 0 ; i
< count
; i
++)
3351 es
->tabs
[i
] = *tabs
++;
3357 /*********************************************************************
3359 * EM_SETWORDBREAKPROC
3362 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
)
3364 if (es
->word_break_proc
== (void *)lParam
)
3367 es
->word_break_proc
= (void *)lParam
;
3368 es
->word_break_proc16
= NULL
;
3370 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3371 EDIT_BuildLineDefs_ML(wnd
, es
);
3372 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3377 /*********************************************************************
3379 * EM_SETWORDBREAKPROC16
3382 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3384 if (es
->word_break_proc16
== wbp
)
3387 es
->word_break_proc
= NULL
;
3388 es
->word_break_proc16
= wbp
;
3389 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3390 EDIT_BuildLineDefs_ML(wnd
, es
);
3391 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3396 /*********************************************************************
3401 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
3403 INT ulength
= strlenW(es
->undo_text
);
3404 LPWSTR utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3406 strcpyW(utext
, es
->undo_text
);
3408 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3409 es
->undo_insert_count
, debugstr_w(utext
));
3411 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3412 EDIT_EM_EmptyUndoBuffer(es
);
3413 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
, TRUE
);
3414 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3415 EDIT_EM_ScrollCaret(wnd
, es
);
3416 HeapFree(GetProcessHeap(), 0, utext
);
3418 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3419 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3421 if (es
->flags
& EF_UPDATE
) {
3422 es
->flags
&= ~EF_UPDATE
;
3423 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3430 /*********************************************************************
3435 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, WCHAR c
)
3437 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
3440 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3441 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3444 if (es
->style
& ES_MULTILINE
) {
3445 if (es
->style
& ES_READONLY
) {
3446 EDIT_MoveHome(wnd
, es
, FALSE
);
3447 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
3449 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3450 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, cr_lfW
, TRUE
);
3451 if (es
->flags
& EF_UPDATE
) {
3452 es
->flags
&= ~EF_UPDATE
;
3453 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3459 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3461 static const WCHAR tabW
[] = {'\t',0};
3462 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, tabW
, TRUE
);
3463 if (es
->flags
& EF_UPDATE
) {
3464 es
->flags
&= ~EF_UPDATE
;
3465 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3470 if (!(es
->style
& ES_READONLY
) && !control
) {
3471 if (es
->selection_start
!= es
->selection_end
)
3472 EDIT_WM_Clear(wnd
, es
);
3474 /* delete character left of caret */
3475 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
3476 EDIT_MoveBackward(wnd
, es
, TRUE
);
3477 EDIT_WM_Clear(wnd
, es
);
3482 SendMessageW(wnd
->hwndSelf
, WM_COPY
, 0, 0);
3485 SendMessageW(wnd
->hwndSelf
, WM_PASTE
, 0, 0);
3488 SendMessageW(wnd
->hwndSelf
, WM_CUT
, 0, 0);
3492 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3496 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
, TRUE
);
3497 if (es
->flags
& EF_UPDATE
) {
3498 es
->flags
&= ~EF_UPDATE
;
3499 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3507 /*********************************************************************
3512 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3514 if (code
|| control
)
3519 EDIT_EM_Undo(wnd
, es
);
3522 EDIT_WM_Cut(wnd
, es
);
3525 EDIT_WM_Copy(wnd
, es
);
3528 EDIT_WM_Paste(wnd
, es
);
3531 EDIT_WM_Clear(wnd
, es
);
3534 EDIT_EM_SetSel(wnd
, es
, 0, (UINT
)-1, FALSE
);
3535 EDIT_EM_ScrollCaret(wnd
, es
);
3538 ERR("unknown menu item, please report\n");
3544 /*********************************************************************
3548 * Note: the resource files resource/sysres_??.rc cannot define a
3549 * single popup menu. Hence we use a (dummy) menubar
3550 * containing the single popup menu as its first item.
3552 * FIXME: the message identifiers have been chosen arbitrarily,
3553 * hence we use MF_BYPOSITION.
3554 * We might as well use the "real" values (anybody knows ?)
3555 * The menu definition is in resources/sysres_??.rc.
3556 * Once these are OK, we better use MF_BYCOMMAND here
3557 * (as we do in EDIT_WM_Command()).
3560 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
3562 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3563 HMENU popup
= GetSubMenu(menu
, 0);
3564 UINT start
= es
->selection_start
;
3565 UINT end
= es
->selection_end
;
3567 ORDER_UINT(start
, end
);
3570 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) ? MF_ENABLED
: MF_GRAYED
));
3572 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3574 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3576 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
3578 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3580 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3582 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3587 /*********************************************************************
3592 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3594 INT s
= es
->selection_start
;
3595 INT e
= es
->selection_end
;
3602 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3603 dst
= GlobalLock(hdst
);
3604 strncpyW(dst
, es
->text
+ s
, e
- s
);
3605 dst
[e
- s
] = 0; /* ensure 0 termination */
3606 TRACE("%s\n", debugstr_w(dst
));
3608 OpenClipboard(wnd
->hwndSelf
);
3610 SetClipboardData(CF_UNICODETEXT
, hdst
);
3615 /*********************************************************************
3620 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCWSTR name
)
3622 TRACE("%s\n", debugstr_w(name
));
3624 * To initialize some final structure members, we call some helper
3625 * functions. However, since the EDITSTATE is not consistent (i.e.
3626 * not fully initialized), we should be very careful which
3627 * functions can be called, and in what order.
3629 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3630 EDIT_EM_EmptyUndoBuffer(es
);
3632 if (name
&& *name
) {
3633 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, name
, TRUE
);
3634 /* if we insert text to the editline, the text scrolls out
3635 * of the window, as the caret is placed after the insert
3636 * pos normally; thus we reset es->selection... to 0 and
3639 es
->selection_start
= es
->selection_end
= 0;
3640 EDIT_EM_ScrollCaret(wnd
, es
);
3641 if (es
->flags
& EF_UPDATE
) {
3642 es
->flags
&= ~EF_UPDATE
;
3643 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3646 /* force scroll info update */
3647 EDIT_UpdateScrollInfo(wnd
, es
);
3652 /*********************************************************************
3657 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3660 while (LocalUnlock(es
->hloc32W
)) ;
3661 LocalFree(es
->hloc32W
);
3664 while (LocalUnlock(es
->hloc32A
)) ;
3665 LocalFree(es
->hloc32A
);
3668 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3669 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3671 HeapFree(GetProcessHeap(), 0, es
);
3672 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3676 /*********************************************************************
3681 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3686 if ( get_app_version() >= 0x40000 &&(
3687 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3688 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3690 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3693 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3695 GetClientRect(wnd
->hwndSelf
, &rc
);
3696 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3697 GetClipBox(dc
, &rc
);
3699 * FIXME: specs say that we should UnrealizeObject() the brush,
3700 * but the specs of UnrealizeObject() say that we shouldn't
3701 * unrealize a stock object. The default brush that
3702 * DefWndProc() returns is ... a stock object.
3704 FillRect(dc
, &rc
, brush
);
3709 /*********************************************************************
3714 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3716 if(!count
) return 0;
3720 LPWSTR textW
= (LPWSTR
)lParam
;
3721 strncpyW(textW
, es
->text
, count
);
3722 textW
[count
- 1] = 0; /* ensure 0 termination */
3723 return strlenW(textW
);
3727 LPSTR textA
= (LPSTR
)lParam
;
3728 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
);
3729 textA
[count
- 1] = 0; /* ensure 0 termination */
3730 return strlen(textA
);
3734 /*********************************************************************
3739 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
)
3744 if (!(es
->style
& ES_MULTILINE
))
3747 if (!(es
->style
& ES_AUTOHSCROLL
))
3751 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3754 TRACE("SB_LINELEFT\n");
3756 dx
= -es
->char_width
;
3759 TRACE("SB_LINERIGHT\n");
3760 if (es
->x_offset
< es
->text_width
)
3761 dx
= es
->char_width
;
3764 TRACE("SB_PAGELEFT\n");
3766 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3769 TRACE("SB_PAGERIGHT\n");
3770 if (es
->x_offset
< es
->text_width
)
3771 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3779 TRACE("SB_RIGHT\n");
3780 if (es
->x_offset
< es
->text_width
)
3781 dx
= es
->text_width
- es
->x_offset
;
3784 TRACE("SB_THUMBTRACK %d\n", pos
);
3785 es
->flags
|= EF_HSCROLL_TRACK
;
3786 if(es
->style
& WS_HSCROLL
)
3787 dx
= pos
- es
->x_offset
;
3792 if(pos
< 0 || pos
> 100) return 0;
3793 /* Assume default scroll range 0-100 */
3794 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3795 new_x
= pos
* (es
->text_width
- fw
) / 100;
3796 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3799 case SB_THUMBPOSITION
:
3800 TRACE("SB_THUMBPOSITION %d\n", pos
);
3801 es
->flags
&= ~EF_HSCROLL_TRACK
;
3802 if(wnd
->dwStyle
& WS_HSCROLL
)
3803 dx
= pos
- es
->x_offset
;
3808 if(pos
< 0 || pos
> 100) return 0;
3809 /* Assume default scroll range 0-100 */
3810 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3811 new_x
= pos
* (es
->text_width
- fw
) / 100;
3812 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3815 /* force scroll info update */
3816 EDIT_UpdateScrollInfo(wnd
, es
);
3817 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3821 TRACE("SB_ENDSCROLL\n");
3824 * FIXME : the next two are undocumented !
3825 * Are we doing the right thing ?
3826 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3827 * although it's also a regular control message.
3829 case EM_GETTHUMB
: /* this one is used by NT notepad */
3833 if(wnd
->dwStyle
& WS_HSCROLL
)
3834 ret
= GetScrollPos(wnd
->hwndSelf
, SB_HORZ
);
3837 /* Assume default scroll range 0-100 */
3838 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3839 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3841 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3844 case EM_LINESCROLL16
:
3845 TRACE("EM_LINESCROLL16\n");
3850 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3856 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3857 /* check if we are going to move too far */
3858 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3859 dx
= es
->text_width
- fw
- es
->x_offset
;
3861 EDIT_EM_LineScroll_internal(wnd
, es
, dx
, 0);
3867 /*********************************************************************
3872 static BOOL
EDIT_CheckCombo(WND
*wnd
, EDITSTATE
*es
, UINT msg
, INT key
)
3874 HWND hLBox
= es
->hwndListBox
;
3882 hCombo
= wnd
->parent
->hwndSelf
;
3886 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3887 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3889 if (key
== VK_UP
|| key
== VK_DOWN
)
3891 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3894 if (msg
== WM_KEYDOWN
|| nEUI
)
3895 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3901 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3903 /* make sure ComboLBox pops up */
3904 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3909 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3912 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3914 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3916 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
3921 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3927 /*********************************************************************
3931 * Handling of special keys that don't produce a WM_CHAR
3932 * (i.e. non-printable keys) & Backspace & Delete
3935 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
)
3940 if (GetKeyState(VK_MENU
) & 0x8000)
3943 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3944 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3949 if (EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3954 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3955 EDIT_MoveUp_ML(wnd
, es
, shift
);
3958 EDIT_MoveWordBackward(wnd
, es
, shift
);
3960 EDIT_MoveBackward(wnd
, es
, shift
);
3963 if (EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
))
3967 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3968 EDIT_MoveDown_ML(wnd
, es
, shift
);
3970 EDIT_MoveWordForward(wnd
, es
, shift
);
3972 EDIT_MoveForward(wnd
, es
, shift
);
3975 EDIT_MoveHome(wnd
, es
, shift
);
3978 EDIT_MoveEnd(wnd
, es
, shift
);
3981 if (es
->style
& ES_MULTILINE
)
3982 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3984 EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
);
3987 if (es
->style
& ES_MULTILINE
)
3988 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3990 EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
);
3993 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3994 if (es
->selection_start
!= es
->selection_end
) {
3996 EDIT_WM_Cut(wnd
, es
);
3998 EDIT_WM_Clear(wnd
, es
);
4001 /* delete character left of caret */
4002 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
4003 EDIT_MoveBackward(wnd
, es
, TRUE
);
4004 EDIT_WM_Clear(wnd
, es
);
4005 } else if (control
) {
4006 /* delete to end of line */
4007 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
4008 EDIT_MoveEnd(wnd
, es
, TRUE
);
4009 EDIT_WM_Clear(wnd
, es
);
4011 /* delete character right of caret */
4012 EDIT_EM_SetSel(wnd
, es
, (UINT
)-1, 0, FALSE
);
4013 EDIT_MoveForward(wnd
, es
, TRUE
);
4014 EDIT_WM_Clear(wnd
, es
);
4021 if (!(es
->style
& ES_READONLY
))
4022 EDIT_WM_Paste(wnd
, es
);
4024 EDIT_WM_Copy(wnd
, es
);
4027 /* If the edit doesn't want the return send a message to the default object */
4028 if(!(es
->style
& ES_WANTRETURN
))
4030 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
4031 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4032 if (HIWORD(dw
) == DC_HASDEFID
)
4034 SendMessageW( hwndParent
, WM_COMMAND
,
4035 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4036 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4045 /*********************************************************************
4050 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
)
4052 es
->flags
&= ~EF_FOCUSED
;
4054 if(!(es
->style
& ES_NOHIDESEL
))
4055 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
4056 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4061 /*********************************************************************
4065 * The caret position has been set on the WM_LBUTTONDOWN message
4068 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
)
4071 INT e
= es
->selection_end
;
4076 if (!(es
->flags
& EF_FOCUSED
))
4079 l
= EDIT_EM_LineFromChar(es
, e
);
4080 li
= EDIT_EM_LineIndex(es
, l
);
4081 ll
= EDIT_EM_LineLength(es
, e
);
4082 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4083 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4084 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
4085 EDIT_EM_ScrollCaret(wnd
, es
);
4090 /*********************************************************************
4095 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4100 if (!(es
->flags
& EF_FOCUSED
))
4103 es
->bCaptureState
= TRUE
;
4104 SetCapture(wnd
->hwndSelf
);
4105 EDIT_ConfinePoint(es
, &x
, &y
);
4106 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
4107 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4108 EDIT_EM_ScrollCaret(wnd
, es
);
4109 es
->region_posx
= es
->region_posy
= 0;
4110 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
4115 /*********************************************************************
4120 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
)
4122 if (es
->bCaptureState
&& GetCapture() == hwndSelf
) {
4123 KillTimer(hwndSelf
, 0);
4126 es
->bCaptureState
= FALSE
;
4131 /*********************************************************************
4136 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
)
4138 SendMessageW(wnd
->hwndSelf
,WM_PASTE
,0,0);
4143 /*********************************************************************
4148 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
4154 if (GetCapture() != wnd
->hwndSelf
)
4158 * FIXME: gotta do some scrolling if outside client
4159 * area. Maybe reset the timer ?
4162 EDIT_ConfinePoint(es
, &x
, &y
);
4163 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4164 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4165 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
4166 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
4171 /*********************************************************************
4176 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, DWORD style
, HWND hwndParent
, BOOL unicode
)
4181 TRACE("Creating %s edit control\n", unicode
? "Unicode" : "ANSI");
4183 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4185 *(EDITSTATE
**)wnd
->wExtra
= es
;
4188 * Note: since the EDITSTATE has not been fully initialized yet,
4189 * we can't use any API calls that may send
4190 * WM_XXX messages before WM_NCCREATE is completed.
4193 es
->is_unicode
= unicode
;
4196 es
->bEnableState
= !(style
& WS_DISABLED
);
4199 * In Win95 look and feel, the WS_BORDER style is replaced by the
4200 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4201 * control a non client area.
4203 if (TWEAK_WineLook
!= WIN31_LOOK
)
4205 if (es
->style
& WS_BORDER
)
4207 es
->style
&= ~WS_BORDER
;
4208 wnd
->dwStyle
&= ~WS_BORDER
;
4209 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
4214 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4215 wnd
->dwStyle
&= ~WS_BORDER
;
4218 if (es
->style
& ES_COMBO
)
4219 es
->hwndListBox
= GetDlgItem(hwndParent
, ID_CB_LISTBOX
);
4221 if (es
->style
& ES_MULTILINE
) {
4222 es
->buffer_limit
= BUFLIMIT_MULTI
;
4223 if (es
->style
& WS_VSCROLL
)
4224 es
->style
|= ES_AUTOVSCROLL
;
4225 if (es
->style
& WS_HSCROLL
)
4226 es
->style
|= ES_AUTOHSCROLL
;
4227 es
->style
&= ~ES_PASSWORD
;
4228 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4229 if (es
->style
& ES_RIGHT
)
4230 es
->style
&= ~ES_CENTER
;
4231 es
->style
&= ~WS_HSCROLL
;
4232 es
->style
&= ~ES_AUTOHSCROLL
;
4235 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4236 es
->style
|= ES_AUTOVSCROLL
;
4238 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4239 es
->style
&= ~ES_CENTER
;
4240 es
->style
&= ~ES_RIGHT
;
4241 es
->style
&= ~WS_HSCROLL
;
4242 es
->style
&= ~WS_VSCROLL
;
4243 es
->style
&= ~ES_AUTOVSCROLL
;
4244 es
->style
&= ~ES_WANTRETURN
;
4245 if (es
->style
& ES_UPPERCASE
) {
4246 es
->style
&= ~ES_LOWERCASE
;
4247 es
->style
&= ~ES_NUMBER
;
4248 } else if (es
->style
& ES_LOWERCASE
)
4249 es
->style
&= ~ES_NUMBER
;
4250 if (es
->style
& ES_PASSWORD
)
4251 es
->password_char
= '*';
4253 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4254 es
->style
|= ES_AUTOHSCROLL
;
4257 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4258 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4260 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4262 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4264 es
->undo_buffer_size
= es
->buffer_size
;
4266 if (es
->style
& ES_MULTILINE
)
4267 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4274 /*********************************************************************
4279 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
4288 BOOL rev
= es
->bEnableState
&&
4289 ((es
->flags
& EF_FOCUSED
) ||
4290 (es
->style
& ES_NOHIDESEL
));
4292 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
4295 if(es
->style
& WS_BORDER
) {
4296 GetClientRect(wnd
->hwndSelf
, &rc
);
4297 if(es
->style
& ES_MULTILINE
) {
4298 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4299 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4301 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4303 IntersectClipRect(dc
, es
->format_rect
.left
,
4304 es
->format_rect
.top
,
4305 es
->format_rect
.right
,
4306 es
->format_rect
.bottom
);
4307 if (es
->style
& ES_MULTILINE
) {
4308 GetClientRect(wnd
->hwndSelf
, &rc
);
4309 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4312 old_font
= SelectObject(dc
, es
->font
);
4313 if ( get_app_version() >= 0x40000 &&(
4314 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
4315 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
4317 EDIT_SEND_CTLCOLOR(wnd
, dc
);
4319 if (!es
->bEnableState
)
4320 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4321 GetClipBox(dc
, &rcRgn
);
4322 if (es
->style
& ES_MULTILINE
) {
4323 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4324 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4325 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
4326 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4327 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
4330 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
4331 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4332 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
4335 SelectObject(dc
, old_font
);
4338 EndPaint(wnd
->hwndSelf
, &ps
);
4342 /*********************************************************************
4347 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
4352 OpenClipboard(wnd
->hwndSelf
);
4353 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4354 src
= (LPWSTR
)GlobalLock(hsrc
);
4355 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
, TRUE
);
4358 if (es
->flags
& EF_UPDATE
) {
4359 es
->flags
&= ~EF_UPDATE
;
4360 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
4367 /*********************************************************************
4372 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
)
4374 es
->flags
|= EF_FOCUSED
;
4375 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
4376 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
4377 es
->flags
& EF_AFTER_WRAP
);
4378 if(!(es
->style
& ES_NOHIDESEL
))
4379 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
4380 ShowCaret(wnd
->hwndSelf
);
4381 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
4385 /*********************************************************************
4389 * With Win95 look the margins are set to default font value unless
4390 * the system font (font == 0) is being set, in which case they are left
4394 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4402 dc
= GetDC(wnd
->hwndSelf
);
4404 old_font
= SelectObject(dc
, font
);
4405 GetTextMetricsW(dc
, &tm
);
4406 es
->line_height
= tm
.tmHeight
;
4407 es
->char_width
= tm
.tmAveCharWidth
;
4409 SelectObject(dc
, old_font
);
4410 ReleaseDC(wnd
->hwndSelf
, dc
);
4411 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4412 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4413 EC_USEFONTINFO
, EC_USEFONTINFO
);
4415 /* Force the recalculation of the format rect for each font change */
4416 GetClientRect(wnd
->hwndSelf
, &r
);
4417 EDIT_SetRectNP(wnd
, es
, &r
);
4419 if (es
->style
& ES_MULTILINE
)
4420 EDIT_BuildLineDefs_ML(wnd
, es
);
4422 EDIT_CalcLineWidth_SL(wnd
, es
);
4425 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4426 if (es
->flags
& EF_FOCUSED
) {
4428 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
4429 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
4430 es
->flags
& EF_AFTER_WRAP
);
4431 ShowCaret(wnd
->hwndSelf
);
4436 /*********************************************************************
4441 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4442 * The modified flag is reset. No notifications are sent.
4444 * For single-line controls, reception of WM_SETTEXT triggers:
4445 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4448 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4453 text
= (LPWSTR
)lParam
;
4456 LPCSTR textA
= (LPCSTR
)lParam
;
4457 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4458 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4459 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4462 EDIT_EM_SetSel(wnd
, es
, 0, (UINT
)-1, FALSE
);
4464 TRACE("%s\n", debugstr_w(text
));
4465 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
, !(es
->style
& ES_MULTILINE
));
4467 HeapFree(GetProcessHeap(), 0, text
);
4469 static const WCHAR empty_stringW
[] = {0};
4471 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, empty_stringW
, !(es
->style
& ES_MULTILINE
));
4474 es
->flags
&= ~EF_MODIFIED
;
4475 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
4476 EDIT_EM_ScrollCaret(wnd
, es
);
4478 if (es
->flags
& EF_UPDATE
) {
4479 es
->flags
&= ~EF_UPDATE
;
4480 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
4485 /*********************************************************************
4490 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4492 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4494 TRACE("width = %d, height = %d\n", width
, height
);
4495 SetRect(&rc
, 0, 0, width
, height
);
4496 EDIT_SetRectNP(wnd
, es
, &rc
);
4497 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4502 /*********************************************************************
4507 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4509 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4510 if (EDIT_EM_CanUndo(es
))
4511 EDIT_EM_Undo(wnd
, es
);
4513 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4514 if (EDIT_CheckCombo(wnd
, es
, WM_SYSKEYDOWN
, key
))
4517 return DefWindowProcW(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4521 /*********************************************************************
4526 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
)
4528 if (es
->region_posx
< 0) {
4529 EDIT_MoveBackward(wnd
, es
, TRUE
);
4530 } else if (es
->region_posx
> 0) {
4531 EDIT_MoveForward(wnd
, es
, TRUE
);
4534 * FIXME: gotta do some vertical scrolling here, like
4535 * EDIT_EM_LineScroll(wnd, 0, 1);
4539 /*********************************************************************
4544 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
)
4548 if (!(es
->style
& ES_MULTILINE
))
4551 if (!(es
->style
& ES_AUTOVSCROLL
))
4560 TRACE("action %d\n", action
);
4561 EDIT_EM_Scroll(wnd
, es
, action
);
4568 TRACE("SB_BOTTOM\n");
4569 dy
= es
->line_count
- 1 - es
->y_offset
;
4572 TRACE("SB_THUMBTRACK %d\n", pos
);
4573 es
->flags
|= EF_VSCROLL_TRACK
;
4574 if(es
->style
& WS_VSCROLL
)
4575 dy
= pos
- es
->y_offset
;
4578 /* Assume default scroll range 0-100 */
4581 if(pos
< 0 || pos
> 100) return 0;
4582 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4583 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4584 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4585 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4586 es
->line_count
, es
->y_offset
, pos
, dy
);
4589 case SB_THUMBPOSITION
:
4590 TRACE("SB_THUMBPOSITION %d\n", pos
);
4591 es
->flags
&= ~EF_VSCROLL_TRACK
;
4592 if(es
->style
& WS_VSCROLL
)
4593 dy
= pos
- es
->y_offset
;
4596 /* Assume default scroll range 0-100 */
4599 if(pos
< 0 || pos
> 100) return 0;
4600 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4601 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4602 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4603 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4604 es
->line_count
, es
->y_offset
, pos
, dy
);
4608 /* force scroll info update */
4609 EDIT_UpdateScrollInfo(wnd
, es
);
4610 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4614 TRACE("SB_ENDSCROLL\n");
4617 * FIXME : the next two are undocumented !
4618 * Are we doing the right thing ?
4619 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4620 * although it's also a regular control message.
4622 case EM_GETTHUMB
: /* this one is used by NT notepad */
4626 if(wnd
->dwStyle
& WS_VSCROLL
)
4627 ret
= GetScrollPos(wnd
->hwndSelf
, SB_VERT
);
4630 /* Assume default scroll range 0-100 */
4631 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4632 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4634 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4637 case EM_LINESCROLL16
:
4638 TRACE("EM_LINESCROLL16 %d\n", pos
);
4643 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4648 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4653 /*********************************************************************
4658 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
)
4660 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
4662 /* EF_UPDATE will be turned off in paint */
4663 if (es
->flags
& EF_UPDATE
)
4664 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
4666 InvalidateRect(wnd
->hwndSelf
, rc
, bErase
);