4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
47 #include <wine/debug.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
50 WINE_DECLARE_DEBUG_CHANNEL(combo
);
51 WINE_DECLARE_DEBUG_CHANNEL(relay
);
53 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
54 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
55 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
56 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
59 * extra flags for EDITSTATE.flags field
61 #define EF_MODIFIED 0x0001 /* text has been modified */
62 #define EF_FOCUSED 0x0002 /* we have input focus */
63 #define EF_UPDATE 0x0004 /* notify parent of changed state */
64 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
65 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
66 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
67 wrapped line, instead of in front of the next character */
68 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
69 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
70 the text buffer if this is clear. */
73 END_0
= 0, /* line ends with terminating '\0' character */
74 END_WRAP
, /* line is wrapped */
75 END_HARD
, /* line ends with a hard return '\r\n' */
76 END_SOFT
, /* line ends with a soft return '\r\r\n' */
77 END_RICH
/* line ends with a single '\n' */
80 typedef struct tagLINEDEF
{
81 INT length
; /* bruto length of a line in bytes */
82 INT net_length
; /* netto length of a line in visible characters */
84 INT width
; /* width of the line in pixels */
85 INT index
; /* line index into the buffer */
86 struct tagLINEDEF
*next
;
91 BOOL is_unicode
; /* how the control was created */
92 LPWSTR text
; /* the actual contents of the control */
93 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
94 UINT buffer_size
; /* the size of the buffer in characters */
95 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
96 HFONT font
; /* NULL means standard system font */
97 INT x_offset
; /* scroll offset for multi lines this is in pixels
98 for single lines it's in characters */
99 INT line_height
; /* height of a screen line in pixels */
100 INT char_width
; /* average character width in pixels */
101 DWORD style
; /* sane version of wnd->dwStyle */
102 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
103 INT undo_insert_count
; /* number of characters inserted in sequence */
104 UINT undo_position
; /* character index of the insertion and deletion */
105 LPWSTR undo_text
; /* deleted text */
106 UINT undo_buffer_size
; /* size of the deleted text buffer */
107 INT selection_start
; /* == selection_end if no selection */
108 INT selection_end
; /* == current caret position */
109 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
110 INT left_margin
; /* in pixels */
111 INT right_margin
; /* in pixels */
113 INT text_width
; /* width of the widest line in pixels for multi line controls
114 and just line width for single line controls */
115 INT region_posx
; /* Position of cursor relative to region: */
116 INT region_posy
; /* -1: to left, 0: within, 1: to right */
118 EDITWORDBREAKPROC16 word_break_proc16
;
120 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
121 INT line_count
; /* number of lines */
122 INT y_offset
; /* scroll offset in number of lines */
123 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
124 BOOL bEnableState
; /* flag keeping the enable state */
125 HWND hwndSelf
; /* the our window handle */
126 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
127 Even if parent will change, EN_* messages
128 should be sent to the first parent. */
129 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
131 * only for multi line controls
133 INT lock_count
; /* amount of re-entries in the EditWndProc */
136 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
137 HLOCAL hloc32W
; /* our unicode local memory block */
139 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
142 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
147 UINT composition_len
; /* length of composition, 0 == no composition */
148 int composition_start
; /* the character position for the composition */
152 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
153 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
155 /* used for disabled or read-only edit control */
156 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
158 { /* Notify parent which has created this edit control */ \
159 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
160 SendMessageW(es->hwndParent, WM_COMMAND, \
161 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
162 (LPARAM)(es->hwndSelf)); \
165 /*********************************************************************
172 * These functions have trivial implementations
173 * We still like to call them internally
174 * "static inline" makes them more like macro's
176 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
);
177 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
178 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
179 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
182 * Helper functions only valid for one type of control
184 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
185 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
186 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
187 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
190 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
192 * Helper functions valid for both single line _and_ multi line controls
194 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
195 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
196 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
);
197 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
198 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
199 static void EDIT_LockBuffer(EDITSTATE
*es
);
200 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
201 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
202 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
203 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
);
204 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
205 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
);
206 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
207 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
208 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
209 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
210 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
211 static void EDIT_AdjustFormatRect(EDITSTATE
*es
);
212 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*lprc
);
213 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
214 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
215 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
217 * EM_XXX message handlers
219 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
220 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
221 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
223 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
225 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
226 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
);
227 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
228 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
229 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
);
230 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
231 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
232 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
233 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
234 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
235 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
236 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
237 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
239 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
241 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
);
242 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, WORD left
, WORD right
, BOOL repaint
);
243 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
244 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
245 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
);
247 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
);
249 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
251 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
253 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
255 * WM_XXX message handlers
257 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
258 static void EDIT_WM_MenuSelect(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
259 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
260 static void EDIT_WM_Copy(EDITSTATE
*es
);
261 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
262 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
263 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
264 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
265 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
266 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
267 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
268 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
269 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
270 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
271 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
272 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
273 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
274 static void EDIT_WM_Paste(EDITSTATE
*es
);
275 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
276 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
277 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
278 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
279 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
280 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
281 static void EDIT_WM_Timer(EDITSTATE
*es
);
282 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
283 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
);
284 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
285 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
);
287 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
288 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
290 /*********************************************************************
291 * edit class descriptor
293 static const WCHAR editW
[] = {'E','d','i','t',0};
294 const struct builtin_class_descr EDIT_builtin_class
=
297 CS_DBLCLKS
| CS_PARENTDC
, /* style */
298 EditWndProcA
, /* procA */
299 EditWndProcW
, /* procW */
300 sizeof(EDITSTATE
*), /* extra */
301 IDC_IBEAM
, /* cursor */
306 /*********************************************************************
311 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
313 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
317 /*********************************************************************
322 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
324 es
->undo_insert_count
= 0;
325 *es
->undo_text
= '\0';
329 /*********************************************************************
334 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
336 static const WCHAR empty_stringW
[] = {0};
338 /* Protect read-only edit control from modification */
339 if(es
->style
& ES_READONLY
)
342 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
346 /*********************************************************************
351 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
358 /**********************************************************************
361 * Returns the window version in case Wine emulates a later version
362 * of windows than the application expects.
364 * In a number of cases when windows runs an application that was
365 * designed for an earlier windows version, windows reverts
366 * to "old" behaviour of that earlier version.
368 * An example is a disabled edit control that needs to be painted.
369 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
370 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
371 * applications with an expected version 0f 4.0 or higher.
374 static DWORD
get_app_version(void)
376 static DWORD version
;
379 DWORD dwEmulatedVersion
;
381 DWORD dwProcVersion
= GetProcessVersion(0);
383 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
384 GetVersionExW( &info
);
385 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
386 /* FIXME: this may not be 100% correct; see discussion on the
387 * wine developer list in Nov 1999 */
388 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
393 static inline UINT
get_text_length(EDITSTATE
*es
)
395 if(es
->text_length
== (UINT
)-1)
396 es
->text_length
= strlenW(es
->text
);
397 return es
->text_length
;
400 static inline void text_buffer_changed(EDITSTATE
*es
)
402 es
->text_length
= (UINT
)-1;
405 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
410 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
411 msg
= WM_CTLCOLORSTATIC
;
413 msg
= WM_CTLCOLOREDIT
;
415 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
416 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
418 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
422 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
425 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
427 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
430 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
432 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
436 /*********************************************************************
440 * The messages are in the order of the actual integer values
441 * (which can be found in include/windows.h)
442 * Wherever possible the 16 bit versions are converted to
443 * the 32 bit ones, so that we can 'fall through' to the
444 * helper functions. These are mostly 32 bit (with a few
445 * exceptions, clearly indicated by a '16' extension to their
449 static LRESULT
EditWndProc_common( HWND hwnd
, UINT msg
,
450 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
452 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
455 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
457 if (!es
&& msg
!= WM_NCCREATE
)
458 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
460 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
470 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
475 if ((short)LOWORD(lParam
) == -1)
476 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
478 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
480 EDIT_EM_ScrollCaret(es
);
485 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
486 EDIT_EM_ScrollCaret(es
);
494 RECT16
*r16
= MapSL(lParam
);
495 r16
->left
= es
->format_rect
.left
;
496 r16
->top
= es
->format_rect
.top
;
497 r16
->right
= es
->format_rect
.right
;
498 r16
->bottom
= es
->format_rect
.bottom
;
504 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
509 if ((es
->style
& ES_MULTILINE
) && lParam
) {
511 RECT16
*r16
= MapSL(lParam
);
514 rc
.right
= r16
->right
;
515 rc
.bottom
= r16
->bottom
;
516 EDIT_SetRectNP(es
, &rc
);
517 EDIT_UpdateText(es
, NULL
, TRUE
);
522 if ((es
->style
& ES_MULTILINE
) && lParam
) {
523 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
524 EDIT_UpdateText(es
, NULL
, TRUE
);
530 if ((es
->style
& ES_MULTILINE
) && lParam
) {
532 RECT16
*r16
= MapSL(lParam
);
535 rc
.right
= r16
->right
;
536 rc
.bottom
= r16
->bottom
;
537 EDIT_SetRectNP(es
, &rc
);
542 if ((es
->style
& ES_MULTILINE
) && lParam
)
543 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
550 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
554 case EM_LINESCROLL16
:
555 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
556 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
560 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
564 case EM_SCROLLCARET16
:
567 EDIT_EM_ScrollCaret(es
);
575 result
= ((es
->flags
& EF_MODIFIED
) != 0);
583 es
->flags
|= EF_MODIFIED
;
585 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
589 case EM_GETLINECOUNT16
:
591 case EM_GETLINECOUNT
:
592 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
597 if ((INT16
)wParam
== -1)
602 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
607 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
611 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
616 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
620 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
627 result
= EDIT_EM_GetThumb(es
);
630 /* these messages missing from specs */
639 FIXME("undocumented message 0x%x, please report\n", msg
);
640 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
644 case EM_LINELENGTH16
:
647 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
651 case EM_REPLACESEL16
:
652 lParam
= (LPARAM
)MapSL(lParam
);
653 unicode
= FALSE
; /* 16-bit message is always ascii */
661 textW
= (LPWSTR
)lParam
;
664 LPSTR textA
= (LPSTR
)lParam
;
665 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
666 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
667 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
670 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
674 HeapFree(GetProcessHeap(), 0, textW
);
680 lParam
= (LPARAM
)MapSL(lParam
);
681 unicode
= FALSE
; /* 16-bit message is always ascii */
685 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
691 case EM_SETLIMITTEXT
:
692 EDIT_EM_SetLimitText(es
, wParam
);
699 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
707 result
= (LRESULT
)EDIT_EM_Undo(es
);
714 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
718 case EM_LINEFROMCHAR16
:
720 case EM_LINEFROMCHAR
:
721 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
725 case EM_SETTABSTOPS16
:
726 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
730 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
734 case EM_SETPASSWORDCHAR16
:
735 unicode
= FALSE
; /* 16-bit message is always ascii */
738 case EM_SETPASSWORDCHAR
:
743 charW
= (WCHAR
)wParam
;
747 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
750 EDIT_EM_SetPasswordChar(es
, charW
);
755 case EM_EMPTYUNDOBUFFER16
:
757 case EM_EMPTYUNDOBUFFER
:
758 EDIT_EM_EmptyUndoBuffer(es
);
762 case EM_GETFIRSTVISIBLELINE16
:
763 result
= es
->y_offset
;
766 case EM_GETFIRSTVISIBLELINE
:
767 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
771 case EM_SETREADONLY16
:
775 SetWindowLongW( hwnd
, GWL_STYLE
,
776 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
777 es
->style
|= ES_READONLY
;
779 SetWindowLongW( hwnd
, GWL_STYLE
,
780 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
781 es
->style
&= ~ES_READONLY
;
787 case EM_SETWORDBREAKPROC16
:
788 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
791 case EM_SETWORDBREAKPROC
:
792 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
796 case EM_GETWORDBREAKPROC16
:
797 result
= (LRESULT
)es
->word_break_proc16
;
800 case EM_GETWORDBREAKPROC
:
801 result
= (LRESULT
)es
->word_break_proc
;
805 case EM_GETPASSWORDCHAR16
:
806 unicode
= FALSE
; /* 16-bit message is always ascii */
809 case EM_GETPASSWORDCHAR
:
812 result
= es
->password_char
;
815 WCHAR charW
= es
->password_char
;
817 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
823 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
826 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
830 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
833 case EM_GETLIMITTEXT
:
834 result
= es
->buffer_limit
;
838 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
839 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
843 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
846 /* End of the EM_ messages which were in numerical order; what order
847 * are these in? vaguely alphabetical?
851 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
855 result
= EDIT_WM_Destroy(es
);
860 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
862 if (es
->style
& ES_MULTILINE
)
863 result
|= DLGC_WANTALLKEYS
;
865 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
867 int vk
= (int)((LPMSG
)lParam
)->wParam
;
871 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
872 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
873 result
|= DLGC_WANTMESSAGE
;
880 SendMessageW(GetParent(hwnd
), WM_CLOSE
, 0, 0);
895 strng
[0] = wParam
>> 8;
896 strng
[1] = wParam
& 0xff;
897 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
898 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
899 result
= EDIT_WM_Char(es
, charW
);
912 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
917 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
919 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
920 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
924 result
= EDIT_WM_Char(es
, charW
);
931 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
932 if (wParam
<= 0x000fffff)
934 if(wParam
> 0xffff) /* convert to surrogates */
937 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
938 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
940 else EDIT_WM_Char(es
, wParam
);
951 EDIT_WM_MenuSelect(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
955 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
964 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
967 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
971 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
972 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
973 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
975 result
= EDIT_WM_Create(es
, nameW
);
976 HeapFree(GetProcessHeap(), 0, nameW
);
985 es
->bEnableState
= (BOOL
) wParam
;
986 EDIT_UpdateText(es
, NULL
, TRUE
);
990 /* we do the proper erase in EDIT_WM_Paint */
995 result
= (LRESULT
)es
->font
;
999 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
1002 case WM_GETTEXTLENGTH
:
1003 if (unicode
) result
= get_text_length(es
);
1004 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
1005 NULL
, 0, NULL
, NULL
);
1009 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
1013 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
1017 result
= EDIT_WM_KillFocus(es
);
1020 case WM_LBUTTONDBLCLK
:
1021 result
= EDIT_WM_LButtonDblClk(es
);
1024 case WM_LBUTTONDOWN
:
1025 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1029 result
= EDIT_WM_LButtonUp(es
);
1032 case WM_MBUTTONDOWN
:
1033 result
= EDIT_WM_MButtonDown(es
);
1037 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1040 case WM_PRINTCLIENT
:
1042 EDIT_WM_Paint(es
, (HDC
)wParam
);
1050 EDIT_WM_SetFocus(es
);
1054 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
1058 /* FIXME: actually set an internal flag and behave accordingly */
1062 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
1067 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1070 case WM_STYLECHANGED
:
1071 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
1074 case WM_STYLECHANGING
:
1075 result
= 0; /* See EDIT_WM_StyleChanged */
1079 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
1087 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
1092 int gcWheelDelta
= 0;
1093 UINT pulScrollLines
= 3;
1094 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1096 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1097 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1100 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1101 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1103 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1104 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1105 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1111 /* IME messages to make the edit control IME aware */
1112 case WM_IME_SETCONTEXT
:
1115 case WM_IME_STARTCOMPOSITION
:
1116 es
->composition_start
= es
->selection_end
;
1117 es
->composition_len
= 0;
1120 case WM_IME_COMPOSITION
:
1121 EDIT_ImeComposition(hwnd
, lParam
, es
);
1124 case WM_IME_ENDCOMPOSITION
:
1125 if (es
->composition_len
> 0)
1127 static const WCHAR empty_stringW
[] = {0};
1128 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1129 es
->selection_end
= es
->selection_start
;
1130 es
->composition_len
= 0;
1134 case WM_IME_COMPOSITIONFULL
:
1140 case WM_IME_CONTROL
:
1144 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1148 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1150 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1155 /*********************************************************************
1157 * EditWndProcW (USER32.@)
1159 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1161 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1164 /*********************************************************************
1166 * EditWndProc (USER32.@)
1168 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1170 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1173 /*********************************************************************
1175 * EDIT_BuildLineDefs_ML
1177 * Build linked list of text lines.
1178 * Lines can end with '\0' (last line), a character (if it is wrapped),
1179 * a soft return '\r\r\n' or a hard return '\r\n'
1182 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1186 LPWSTR current_position
, cp
;
1188 LINEDEF
*current_line
;
1189 LINEDEF
*previous_line
;
1190 LINEDEF
*start_line
;
1191 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1192 INT line_count
= es
->line_count
;
1193 INT orig_net_length
;
1196 if (istart
== iend
&& delta
== 0)
1199 dc
= GetDC(es
->hwndSelf
);
1201 old_font
= SelectObject(dc
, es
->font
);
1203 previous_line
= NULL
;
1204 current_line
= es
->first_line_def
;
1206 /* Find starting line. istart must lie inside an existing line or
1207 * at the end of buffer */
1209 if (istart
< current_line
->index
+ current_line
->length
||
1210 current_line
->ending
== END_0
)
1213 previous_line
= current_line
;
1214 current_line
= current_line
->next
;
1216 } while (current_line
);
1218 if (!current_line
) /* Error occurred start is not inside previous buffer */
1220 FIXME(" modification occurred outside buffer\n");
1221 ReleaseDC(es
->hwndSelf
, dc
);
1225 /* Remember start of modifications in order to calculate update region */
1226 nstart_line
= line_index
;
1227 nstart_index
= current_line
->index
;
1229 /* We must start to reformat from the previous line since the modifications
1230 * may have caused the line to wrap upwards. */
1231 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1234 current_line
= previous_line
;
1236 start_line
= current_line
;
1238 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1239 current_position
= es
->text
+ current_line
->index
;
1241 if (current_line
!= start_line
)
1243 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1245 /* The buffer has been expanded, create a new line and
1246 insert it into the link list */
1247 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1248 if (new_line
== NULL
)
1250 new_line
->next
= previous_line
->next
;
1251 previous_line
->next
= new_line
;
1252 current_line
= new_line
;
1255 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1257 /* The previous line merged with this line so we delete this extra entry */
1258 previous_line
->next
= current_line
->next
;
1259 HeapFree(GetProcessHeap(), 0, current_line
);
1260 current_line
= previous_line
->next
;
1264 else /* current_line->index + delta == current_position */
1266 if (current_position
- es
->text
> iend
)
1267 break; /* We reached end of line modifications */
1268 /* else recalculate this line */
1272 current_line
->index
= current_position
- es
->text
;
1273 orig_net_length
= current_line
->net_length
;
1275 /* Find end of line */
1276 cp
= current_position
;
1278 if (*cp
== '\n') break;
1279 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1284 /* Mark type of line termination */
1286 current_line
->ending
= END_0
;
1287 current_line
->net_length
= strlenW(current_position
);
1288 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1289 current_line
->ending
= END_SOFT
;
1290 current_line
->net_length
= cp
- current_position
- 1;
1291 } else if (*cp
== '\n') {
1292 current_line
->ending
= END_RICH
;
1293 current_line
->net_length
= cp
- current_position
;
1295 current_line
->ending
= END_HARD
;
1296 current_line
->net_length
= cp
- current_position
;
1299 /* Calculate line width */
1300 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1301 current_position
, current_line
->net_length
,
1302 es
->tabs_count
, es
->tabs
));
1304 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1305 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1306 if (current_line
->width
> fw
) {
1311 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1312 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1313 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1314 current_position
, next
, es
->tabs_count
, es
->tabs
));
1315 } while (current_line
->width
<= fw
);
1316 if (!prev
) { /* Didn't find a line break so force a break */
1321 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1322 current_position
, next
, es
->tabs_count
, es
->tabs
));
1323 } while (current_line
->width
<= fw
);
1328 /* If the first line we are calculating, wrapped before istart, we must
1329 * adjust istart in order for this to be reflected in the update region. */
1330 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1331 istart
= current_line
->index
+ prev
;
1332 /* else if we are updating the previous line before the first line we
1333 * are re-calculating and it expanded */
1334 else if (current_line
== start_line
&&
1335 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1337 /* Line expanded due to an upwards line wrap so we must partially include
1338 * previous line in update region */
1339 nstart_line
= line_index
;
1340 nstart_index
= current_line
->index
;
1341 istart
= current_line
->index
+ orig_net_length
;
1344 current_line
->net_length
= prev
;
1345 current_line
->ending
= END_WRAP
;
1346 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1347 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1349 else if (current_line
== start_line
&&
1350 current_line
->index
!= nstart_index
&&
1351 orig_net_length
< current_line
->net_length
) {
1352 /* The previous line expanded but it's still not as wide as the client rect */
1353 /* The expansion is due to an upwards line wrap so we must partially include
1354 it in the update region */
1355 nstart_line
= line_index
;
1356 nstart_index
= current_line
->index
;
1357 istart
= current_line
->index
+ orig_net_length
;
1362 /* Adjust length to include line termination */
1363 switch (current_line
->ending
) {
1365 current_line
->length
= current_line
->net_length
+ 3;
1368 current_line
->length
= current_line
->net_length
+ 1;
1371 current_line
->length
= current_line
->net_length
+ 2;
1375 current_line
->length
= current_line
->net_length
;
1378 es
->text_width
= max(es
->text_width
, current_line
->width
);
1379 current_position
+= current_line
->length
;
1380 previous_line
= current_line
;
1381 current_line
= current_line
->next
;
1383 } while (previous_line
->ending
!= END_0
);
1385 /* Finish adjusting line indexes by delta or remove hanging lines */
1386 if (previous_line
->ending
== END_0
)
1388 LINEDEF
*pnext
= NULL
;
1390 previous_line
->next
= NULL
;
1391 while (current_line
)
1393 pnext
= current_line
->next
;
1394 HeapFree(GetProcessHeap(), 0, current_line
);
1395 current_line
= pnext
;
1399 else if (delta
!= 0)
1401 while (current_line
)
1403 current_line
->index
+= delta
;
1404 current_line
= current_line
->next
;
1408 /* Calculate rest of modification rectangle */
1413 * We calculate two rectangles. One for the first line which may have
1414 * an indent with respect to the format rect. The other is a format-width
1415 * rectangle that spans the rest of the lines that changed or moved.
1417 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1418 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1419 rc
.bottom
= rc
.top
+ es
->line_height
;
1420 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1421 rc
.left
= es
->format_rect
.left
;
1423 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1424 es
->text
+ nstart_index
, istart
- nstart_index
,
1425 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1426 rc
.right
= es
->format_rect
.right
;
1427 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1430 rc
.left
= es
->format_rect
.left
;
1431 rc
.right
= es
->format_rect
.right
;
1433 * If lines were added or removed we must re-paint the remainder of the
1434 * lines since the remaining lines were either shifted up or down.
1436 if (line_count
< es
->line_count
) /* We added lines */
1437 rc
.bottom
= es
->line_count
* es
->line_height
;
1438 else if (line_count
> es
->line_count
) /* We removed lines */
1439 rc
.bottom
= line_count
* es
->line_height
;
1441 rc
.bottom
= line_index
* es
->line_height
;
1442 rc
.bottom
+= es
->format_rect
.top
;
1443 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1444 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1445 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1446 DeleteObject(tmphrgn
);
1450 SelectObject(dc
, old_font
);
1452 ReleaseDC(es
->hwndSelf
, dc
);
1455 /*********************************************************************
1457 * EDIT_CalcLineWidth_SL
1460 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1467 text
= EDIT_GetPasswordPointer_SL(es
);
1469 dc
= GetDC(es
->hwndSelf
);
1471 old_font
= SelectObject(dc
, es
->font
);
1473 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1476 SelectObject(dc
, old_font
);
1477 ReleaseDC(es
->hwndSelf
, dc
);
1479 if (es
->style
& ES_PASSWORD
)
1480 HeapFree(GetProcessHeap(), 0, text
);
1482 es
->text_width
= size
.cx
;
1485 /*********************************************************************
1487 * EDIT_CallWordBreakProc
1489 * Call appropriate WordBreakProc (internal or external).
1491 * Note: The "start" argument should always be an index referring
1492 * to es->text. The actual wordbreak proc might be
1493 * 16 bit, so we can't always pass any 32 bit LPSTR.
1494 * Hence we assume that es->text is the buffer that holds
1495 * the string under examination (we can decide this for ourselves).
1498 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1503 if (es
->word_break_proc16
) {
1510 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1511 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1512 segptr
= WOWGlobalLock16(hglob16
);
1513 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1514 args
[4] = SELECTOROF(segptr
);
1515 args
[3] = OFFSETOF(segptr
);
1519 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1520 ret
= LOWORD(result
);
1521 GlobalUnlock16(hglob16
);
1522 GlobalFree16(hglob16
);
1524 else if (es
->word_break_proc
)
1526 if (es
->word_break_proc
)
1531 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1533 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1534 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1535 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1539 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1543 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1544 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1547 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1548 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1549 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1550 ret
= wbpA(textA
, index
, countA
, action
);
1551 HeapFree(GetProcessHeap(), 0, textA
);
1555 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1561 /*********************************************************************
1565 * Beware: This is not the function called on EM_CHARFROMPOS
1566 * The position _can_ be outside the formatting / client
1568 * The return value is only the character index
1571 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1576 INT x_high
= 0, x_low
= 0;
1578 if (es
->style
& ES_MULTILINE
) {
1579 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1581 LINEDEF
*line_def
= es
->first_line_def
;
1583 while ((line
> 0) && line_def
->next
) {
1584 line_index
+= line_def
->length
;
1585 line_def
= line_def
->next
;
1588 x
+= es
->x_offset
- es
->format_rect
.left
;
1589 if (es
->style
& ES_RIGHT
)
1590 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1591 else if (es
->style
& ES_CENTER
)
1592 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1593 if (x
>= line_def
->width
) {
1595 *after_wrap
= (line_def
->ending
== END_WRAP
);
1596 return line_index
+ line_def
->net_length
;
1600 *after_wrap
= FALSE
;
1603 dc
= GetDC(es
->hwndSelf
);
1605 old_font
= SelectObject(dc
, es
->font
);
1607 high
= line_index
+ line_def
->net_length
+ 1;
1608 while (low
< high
- 1)
1610 INT mid
= (low
+ high
) / 2;
1611 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1620 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1626 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1627 (line_def
->ending
== END_WRAP
));
1632 *after_wrap
= FALSE
;
1633 x
-= es
->format_rect
.left
;
1635 return es
->x_offset
;
1639 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1640 if (es
->style
& ES_RIGHT
)
1642 else if (es
->style
& ES_CENTER
)
1646 text
= EDIT_GetPasswordPointer_SL(es
);
1647 dc
= GetDC(es
->hwndSelf
);
1649 old_font
= SelectObject(dc
, es
->font
);
1653 INT high
= es
->x_offset
;
1654 while (low
< high
- 1)
1656 INT mid
= (low
+ high
) / 2;
1657 GetTextExtentPoint32W( dc
, text
+ mid
,
1658 es
->x_offset
- mid
, &size
);
1667 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1674 INT low
= es
->x_offset
;
1675 INT high
= get_text_length(es
) + 1;
1676 while (low
< high
- 1)
1678 INT mid
= (low
+ high
) / 2;
1679 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1680 mid
- es
->x_offset
, &size
);
1689 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1694 if (es
->style
& ES_PASSWORD
)
1695 HeapFree(GetProcessHeap(), 0, text
);
1698 SelectObject(dc
, old_font
);
1699 ReleaseDC(es
->hwndSelf
, dc
);
1704 /*********************************************************************
1708 * adjusts the point to be within the formatting rectangle
1709 * (so CharFromPos returns the nearest _visible_ character)
1712 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
1714 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1715 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1719 /*********************************************************************
1723 * Calculates the bounding rectangle for a line from a starting
1724 * column to an ending column.
1727 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1729 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1731 if (es
->style
& ES_MULTILINE
)
1732 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1734 rc
->top
= es
->format_rect
.top
;
1735 rc
->bottom
= rc
->top
+ es
->line_height
;
1736 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1737 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1741 /*********************************************************************
1743 * EDIT_GetPasswordPointer_SL
1745 * note: caller should free the (optionally) allocated buffer
1748 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1750 if (es
->style
& ES_PASSWORD
) {
1751 INT len
= get_text_length(es
);
1752 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1756 while(len
) text
[--len
] = es
->password_char
;
1763 /*********************************************************************
1767 * This acts as a LocalLock16(), but it locks only once. This way
1768 * you can call it whenever you like, without unlocking.
1770 * Initially the edit control allocates a HLOCAL32 buffer
1771 * (32 bit linear memory handler). However, 16 bit application
1772 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1773 * handler). From that moment on we have to keep using this 16 bit memory
1774 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1775 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1779 static void EDIT_LockBuffer(EDITSTATE
*es
)
1782 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1783 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1789 BOOL _16bit
= FALSE
;
1796 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1797 textA
= LocalLock(es
->hloc32A
);
1798 countA
= strlen(textA
) + 1;
1803 HANDLE16 oldDS
= stack16
->ds
;
1804 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1805 stack16
->ds
= hInstance
;
1806 textA
= MapSL(LocalLock16(es
->hloc16
));
1807 stack16
->ds
= oldDS
;
1808 countA
= strlen(textA
) + 1;
1814 ERR("no buffer ... please report\n");
1821 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1822 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1823 if(countW_new
> es
->buffer_size
+ 1)
1825 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1826 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1827 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1830 es
->hloc32W
= hloc32W_new
;
1831 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1832 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1835 WARN("FAILED! Will synchronize partially\n");
1839 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1840 es
->text
= LocalLock(es
->hloc32W
);
1844 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1848 HANDLE16 oldDS
= stack16
->ds
;
1849 stack16
->ds
= hInstance
;
1850 LocalUnlock16(es
->hloc16
);
1851 stack16
->ds
= oldDS
;
1855 LocalUnlock(es
->hloc32A
);
1858 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1863 /*********************************************************************
1865 * EDIT_SL_InvalidateText
1867 * Called from EDIT_InvalidateText().
1868 * Does the job for single-line controls only.
1871 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1876 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1877 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1878 EDIT_UpdateText(es
, &rc
, TRUE
);
1882 /*********************************************************************
1884 * EDIT_ML_InvalidateText
1886 * Called from EDIT_InvalidateText().
1887 * Does the job for multi-line controls only.
1890 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1892 INT vlc
= get_vertical_line_count(es
);
1893 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1894 INT el
= EDIT_EM_LineFromChar(es
, end
);
1903 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1906 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1907 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1908 if (sl
< es
->y_offset
) {
1912 if (el
> es
->y_offset
+ vlc
) {
1913 el
= es
->y_offset
+ vlc
;
1914 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1916 GetClientRect(es
->hwndSelf
, &rc1
);
1917 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1919 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1920 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1921 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1923 EDIT_GetLineRect(es
, sl
, sc
,
1924 EDIT_EM_LineLength(es
,
1925 EDIT_EM_LineIndex(es
, sl
)),
1927 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1928 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1929 for (l
= sl
+ 1 ; l
< el
; l
++) {
1930 EDIT_GetLineRect(es
, l
, 0,
1931 EDIT_EM_LineLength(es
,
1932 EDIT_EM_LineIndex(es
, l
)),
1934 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1935 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1937 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1938 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1939 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1944 /*********************************************************************
1946 * EDIT_InvalidateText
1948 * Invalidate the text from offset start up to, but not including,
1949 * offset end. Useful for (re)painting the selection.
1950 * Regions outside the linewidth are not invalidated.
1951 * end == -1 means end == TextLength.
1952 * start and end need not be ordered.
1955 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1961 end
= get_text_length(es
);
1969 if (es
->style
& ES_MULTILINE
)
1970 EDIT_ML_InvalidateText(es
, start
, end
);
1972 EDIT_SL_InvalidateText(es
, start
, end
);
1976 /*********************************************************************
1980 * Try to fit size + 1 characters in the buffer.
1982 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1986 if (size
<= es
->buffer_size
)
1989 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1991 /* Force edit to unlock it's buffer. es->text now NULL */
1992 EDIT_UnlockBuffer(es
, TRUE
);
1995 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1996 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1997 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1998 es
->hloc32W
= hNew32W
;
1999 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
2003 EDIT_LockBuffer(es
);
2005 if (es
->buffer_size
< size
) {
2006 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
2007 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
2010 TRACE("We now have %d+1\n", es
->buffer_size
);
2016 /*********************************************************************
2020 * Try to fit size + 1 bytes in the undo buffer.
2023 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
2027 if (size
<= es
->undo_buffer_size
)
2030 TRACE("trying to ReAlloc to %d+1\n", size
);
2032 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
2033 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
2034 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
2039 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
2045 /*********************************************************************
2050 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
2052 INT e
= es
->selection_end
;
2056 if ((es
->style
& ES_MULTILINE
) && e
&&
2057 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
2059 if (e
&& (es
->text
[e
- 1] == '\r'))
2063 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2064 EDIT_EM_ScrollCaret(es
);
2068 /*********************************************************************
2072 * Only for multi line controls
2073 * Move the caret one line down, on a column with the nearest
2074 * x coordinate on the screen (might be a different column).
2077 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
2079 INT s
= es
->selection_start
;
2080 INT e
= es
->selection_end
;
2081 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2082 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2083 INT x
= (short)LOWORD(pos
);
2084 INT y
= (short)HIWORD(pos
);
2086 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
2089 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2090 EDIT_EM_ScrollCaret(es
);
2094 /*********************************************************************
2099 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
2101 BOOL after_wrap
= FALSE
;
2104 /* Pass a high value in x to make sure of receiving the end of the line */
2105 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
2106 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2107 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2109 e
= get_text_length(es
);
2110 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2111 EDIT_EM_ScrollCaret(es
);
2115 /*********************************************************************
2120 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2122 INT e
= es
->selection_end
;
2126 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2127 if (es
->text
[e
] == '\n')
2129 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2133 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2134 EDIT_EM_ScrollCaret(es
);
2138 /*********************************************************************
2142 * Home key: move to beginning of line.
2145 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
2149 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2150 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
2151 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2152 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2155 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2156 EDIT_EM_ScrollCaret(es
);
2160 /*********************************************************************
2162 * EDIT_MovePageDown_ML
2164 * Only for multi line controls
2165 * Move the caret one page down, on a column with the nearest
2166 * x coordinate on the screen (might be a different column).
2169 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2171 INT s
= es
->selection_start
;
2172 INT e
= es
->selection_end
;
2173 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2174 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2175 INT x
= (short)LOWORD(pos
);
2176 INT y
= (short)HIWORD(pos
);
2178 e
= EDIT_CharFromPos(es
, x
,
2179 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2183 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2184 EDIT_EM_ScrollCaret(es
);
2188 /*********************************************************************
2190 * EDIT_MovePageUp_ML
2192 * Only for multi line controls
2193 * Move the caret one page up, on a column with the nearest
2194 * x coordinate on the screen (might be a different column).
2197 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2199 INT s
= es
->selection_start
;
2200 INT e
= es
->selection_end
;
2201 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2202 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2203 INT x
= (short)LOWORD(pos
);
2204 INT y
= (short)HIWORD(pos
);
2206 e
= EDIT_CharFromPos(es
, x
,
2207 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2211 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2212 EDIT_EM_ScrollCaret(es
);
2216 /*********************************************************************
2220 * Only for multi line controls
2221 * Move the caret one line up, on a column with the nearest
2222 * x coordinate on the screen (might be a different column).
2225 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2227 INT s
= es
->selection_start
;
2228 INT e
= es
->selection_end
;
2229 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2230 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2231 INT x
= (short)LOWORD(pos
);
2232 INT y
= (short)HIWORD(pos
);
2234 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2237 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2238 EDIT_EM_ScrollCaret(es
);
2242 /*********************************************************************
2244 * EDIT_MoveWordBackward
2247 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2249 INT s
= es
->selection_start
;
2250 INT e
= es
->selection_end
;
2255 l
= EDIT_EM_LineFromChar(es
, e
);
2256 ll
= EDIT_EM_LineLength(es
, e
);
2257 li
= EDIT_EM_LineIndex(es
, l
);
2260 li
= EDIT_EM_LineIndex(es
, l
- 1);
2261 e
= li
+ EDIT_EM_LineLength(es
, li
);
2264 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2268 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2269 EDIT_EM_ScrollCaret(es
);
2273 /*********************************************************************
2275 * EDIT_MoveWordForward
2278 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2280 INT s
= es
->selection_start
;
2281 INT e
= es
->selection_end
;
2286 l
= EDIT_EM_LineFromChar(es
, e
);
2287 ll
= EDIT_EM_LineLength(es
, e
);
2288 li
= EDIT_EM_LineIndex(es
, l
);
2290 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2291 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2293 e
= li
+ EDIT_CallWordBreakProc(es
,
2294 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2298 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2299 EDIT_EM_ScrollCaret(es
);
2303 /*********************************************************************
2308 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2310 INT s
= es
->selection_start
;
2311 INT e
= es
->selection_end
;
2318 if (es
->style
& ES_MULTILINE
) {
2319 INT vlc
= get_vertical_line_count(es
);
2321 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2326 TRACE("line=%d\n", line
);
2328 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2329 x
= (short)LOWORD(pos
);
2330 y
= (short)HIWORD(pos
);
2331 li
= EDIT_EM_LineIndex(es
, line
);
2332 ll
= EDIT_EM_LineLength(es
, li
);
2333 s
= min(es
->selection_start
, es
->selection_end
);
2334 e
= max(es
->selection_start
, es
->selection_end
);
2335 s
= min(li
+ ll
, max(li
, s
));
2336 e
= min(li
+ ll
, max(li
, e
));
2337 if (rev
&& (s
!= e
) &&
2338 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2339 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2340 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2341 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2343 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2347 /*********************************************************************
2352 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2356 LOGFONTW underline_font
;
2357 HFONT hUnderline
= 0;
2366 BkMode
= GetBkMode(dc
);
2367 BkColor
= GetBkColor(dc
);
2368 TextColor
= GetTextColor(dc
);
2370 if (es
->composition_len
== 0)
2372 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2373 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2374 SetBkMode( dc
, OPAQUE
);
2378 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2379 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2380 underline_font
.lfUnderline
= TRUE
;
2381 hUnderline
= CreateFontIndirectW(&underline_font
);
2382 old_font
= SelectObject(dc
,hUnderline
);
2385 li
= EDIT_EM_LineIndex(es
, line
);
2386 if (es
->style
& ES_MULTILINE
) {
2387 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2388 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2390 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2391 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2392 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2394 if (es
->style
& ES_PASSWORD
)
2395 HeapFree(GetProcessHeap(), 0, text
);
2398 if (es
->composition_len
== 0)
2400 SetBkColor(dc
, BkColor
);
2401 SetTextColor(dc
, TextColor
);
2402 SetBkMode( dc
, BkMode
);
2407 SelectObject(dc
,old_font
);
2409 DeleteObject(hUnderline
);
2416 /*********************************************************************
2421 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2424 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2425 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2426 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2430 /*********************************************************************
2432 * EDIT_AdjustFormatRect
2434 * Adjusts the format rectangle for the current font and the
2435 * current client rectangle.
2438 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2442 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2443 if (es
->style
& ES_MULTILINE
)
2445 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2447 vlc
= get_vertical_line_count(es
);
2448 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2450 /* correct es->x_offset */
2451 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2452 max_x_offset
= es
->text_width
- fw
;
2453 if(max_x_offset
< 0) max_x_offset
= 0;
2454 if(es
->x_offset
> max_x_offset
)
2455 es
->x_offset
= max_x_offset
;
2457 /* correct es->y_offset */
2458 max_y_offset
= es
->line_count
- vlc
;
2459 if(max_y_offset
< 0) max_y_offset
= 0;
2460 if(es
->y_offset
> max_y_offset
)
2461 es
->y_offset
= max_y_offset
;
2463 /* force scroll info update */
2464 EDIT_UpdateScrollInfo(es
);
2467 /* Windows doesn't care to fix text placement for SL controls */
2468 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2470 /* Always stay within the client area */
2471 GetClientRect(es
->hwndSelf
, &ClientRect
);
2472 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2474 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2475 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2477 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2481 /*********************************************************************
2485 * note: this is not (exactly) the handler called on EM_SETRECTNP
2486 * it is also used to set the rect of a single line control
2489 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2493 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2495 CopyRect(&es
->format_rect
, rc
);
2497 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2498 es
->format_rect
.left
++;
2499 es
->format_rect
.right
--;
2501 if (es
->format_rect
.bottom
- es
->format_rect
.top
2502 >= es
->line_height
+ 2)
2504 es
->format_rect
.top
++;
2505 es
->format_rect
.bottom
--;
2508 else if (es
->style
& WS_BORDER
) {
2509 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2510 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2511 es
->format_rect
.left
+= bw
;
2512 es
->format_rect
.right
-= bw
;
2513 if (es
->format_rect
.bottom
- es
->format_rect
.top
2514 >= es
->line_height
+ 2 * bh
)
2516 es
->format_rect
.top
+= bh
;
2517 es
->format_rect
.bottom
-= bh
;
2521 es
->format_rect
.left
+= es
->left_margin
;
2522 es
->format_rect
.right
-= es
->right_margin
;
2523 EDIT_AdjustFormatRect(es
);
2527 /*********************************************************************
2532 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2535 /* Edit window might be already destroyed */
2536 if(!IsWindow(es
->hwndSelf
))
2538 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2542 if (!es
->lock_count
) {
2543 ERR("lock_count == 0 ... please report\n");
2547 ERR("es->text == 0 ... please report\n");
2551 if (force
|| (es
->lock_count
== 1)) {
2555 UINT countW
= get_text_length(es
) + 1;
2557 STACK16FRAME
* stack16
= NULL
;
2563 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2564 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2565 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2566 countA
= LocalSize(es
->hloc32A
);
2567 if(countA_new
> countA
)
2570 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2571 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2572 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2575 es
->hloc32A
= hloc32A_new
;
2576 countA
= LocalSize(hloc32A_new
);
2577 TRACE("Real new size %d bytes\n", countA
);
2580 WARN("FAILED! Will synchronize partially\n");
2582 textA
= LocalLock(es
->hloc32A
);
2587 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2589 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2590 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2592 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2593 oldDS
= stack16
->ds
;
2594 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2596 countA
= LocalSize16(es
->hloc16
);
2597 if(countA_new
> countA
)
2599 HLOCAL16 hloc16_new
;
2600 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2601 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2602 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2605 es
->hloc16
= hloc16_new
;
2606 countA
= LocalSize16(hloc16_new
);
2607 TRACE("Real new size %d bytes\n", countA
);
2610 WARN("FAILED! Will synchronize partially\n");
2612 textA
= MapSL(LocalLock16(es
->hloc16
));
2618 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2621 LocalUnlock16(es
->hloc16
);
2624 LocalUnlock(es
->hloc32A
);
2628 if (stack16
) stack16
->ds
= oldDS
;
2630 LocalUnlock(es
->hloc32W
);
2634 ERR("no buffer ... please report\n");
2642 /*********************************************************************
2644 * EDIT_UpdateScrollInfo
2647 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2649 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2652 si
.cbSize
= sizeof(SCROLLINFO
);
2653 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2655 si
.nMax
= es
->line_count
- 1;
2656 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2657 si
.nPos
= es
->y_offset
;
2658 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2659 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2660 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2663 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2666 si
.cbSize
= sizeof(SCROLLINFO
);
2667 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2669 si
.nMax
= es
->text_width
- 1;
2670 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2671 si
.nPos
= es
->x_offset
;
2672 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2673 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2674 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2678 /*********************************************************************
2680 * EDIT_WordBreakProc
2682 * Find the beginning of words.
2683 * Note: unlike the specs for a WordBreakProc, this function only
2684 * allows to be called without linebreaks between s[0] up to
2685 * s[count - 1]. Remember it is only called
2686 * internally, so we can decide this for ourselves.
2689 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2693 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2703 if (s
[index
] == ' ') {
2704 while (index
&& (s
[index
] == ' '))
2707 while (index
&& (s
[index
] != ' '))
2709 if (s
[index
] == ' ')
2713 while (index
&& (s
[index
] != ' '))
2715 if (s
[index
] == ' ')
2725 if (s
[index
] == ' ')
2726 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2728 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2730 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2734 case WB_ISDELIMITER
:
2735 ret
= (s
[index
] == ' ');
2738 ERR("unknown action code, please report !\n");
2745 /*********************************************************************
2749 * returns line number (not index) in high-order word of result.
2750 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2751 * to Richedit, not to the edit control. Original documentation is valid.
2752 * FIXME: do the specs mean to return -1 if outside client area or
2753 * if outside formatting rectangle ???
2756 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2764 GetClientRect(es
->hwndSelf
, &rc
);
2765 if (!PtInRect(&rc
, pt
))
2768 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2769 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2773 /*********************************************************************
2777 * Enable or disable soft breaks.
2779 * This means: insert or remove the soft linebreak character (\r\r\n).
2780 * Take care to check if the text still fits the buffer after insertion.
2781 * If not, notify with EN_ERRSPACE.
2784 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2786 es
->flags
&= ~EF_USE_SOFTBRK
;
2788 es
->flags
|= EF_USE_SOFTBRK
;
2789 FIXME("soft break enabled, not implemented\n");
2795 /*********************************************************************
2799 * Hopefully this won't fire back at us.
2800 * We always start with a fixed buffer in the local heap.
2801 * Despite of the documentation says that the local heap is used
2802 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2803 * buffer on the local heap.
2806 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2810 if (!(es
->style
& ES_MULTILINE
))
2814 hLocal
= es
->hloc32W
;
2820 UINT countA
, alloc_size
;
2821 TRACE("Allocating 32-bit ANSI alias buffer\n");
2822 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2823 alloc_size
= ROUND_TO_GROW(countA
);
2824 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2826 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2829 textA
= LocalLock(es
->hloc32A
);
2830 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2831 LocalUnlock(es
->hloc32A
);
2833 hLocal
= es
->hloc32A
;
2836 es
->flags
|= EF_APP_HAS_HANDLE
;
2837 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2843 /*********************************************************************
2847 * Hopefully this won't fire back at us.
2848 * We always start with a buffer in 32 bit linear memory.
2849 * However, with this message a 16 bit application requests
2850 * a handle of 16 bit local heap memory, where it expects to find
2852 * It's a pitty that from this moment on we have to use this
2853 * local heap, because applications may rely on the handle
2856 * In this function we'll try to switch to local heap.
2858 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2861 UINT countA
, alloc_size
;
2862 STACK16FRAME
* stack16
;
2865 if (!(es
->style
& ES_MULTILINE
))
2871 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2872 oldDS
= stack16
->ds
;
2873 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2875 if (!LocalHeapSize16()) {
2877 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2878 ERR("could not initialize local heap\n");
2881 TRACE("local heap initialized\n");
2884 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2885 alloc_size
= ROUND_TO_GROW(countA
);
2887 TRACE("Allocating 16-bit ANSI alias buffer\n");
2888 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2889 ERR("could not allocate new 16 bit buffer\n");
2893 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2894 ERR("could not lock new 16 bit buffer\n");
2895 LocalFree16(es
->hloc16
);
2900 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2901 LocalUnlock16(es
->hloc16
);
2902 es
->flags
|= EF_APP_HAS_HANDLE
;
2904 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2907 stack16
->ds
= oldDS
;
2913 /*********************************************************************
2918 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2921 INT line_len
, dst_len
;
2924 if (es
->style
& ES_MULTILINE
) {
2925 if (line
>= es
->line_count
)
2929 i
= EDIT_EM_LineIndex(es
, line
);
2931 line_len
= EDIT_EM_LineLength(es
, i
);
2932 dst_len
= *(WORD
*)dst
;
2935 if(dst_len
<= line_len
)
2937 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2940 else /* Append 0 if enough space */
2942 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2949 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2950 if(!ret
&& line_len
) /* Insufficient buffer size */
2952 if(ret
< dst_len
) /* Append 0 if enough space */
2953 ((LPSTR
)dst
)[ret
] = 0;
2959 /*********************************************************************
2964 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2966 UINT s
= es
->selection_start
;
2967 UINT e
= es
->selection_end
;
2974 return MAKELONG(s
, e
);
2978 /*********************************************************************
2982 * FIXME: is this right ? (or should it be only VSCROLL)
2983 * (and maybe only for edit controls that really have their
2984 * own scrollbars) (and maybe only for multiline controls ?)
2985 * All in all: very poorly documented
2988 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2991 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
2992 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
2994 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2995 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
3000 /*********************************************************************
3005 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
3010 if (!(es
->style
& ES_MULTILINE
))
3012 if (index
> (INT
)get_text_length(es
))
3013 return es
->line_count
- 1;
3015 index
= min(es
->selection_start
, es
->selection_end
);
3018 line_def
= es
->first_line_def
;
3019 index
-= line_def
->length
;
3020 while ((index
>= 0) && line_def
->next
) {
3022 line_def
= line_def
->next
;
3023 index
-= line_def
->length
;
3029 /*********************************************************************
3034 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
3037 const LINEDEF
*line_def
;
3039 if (!(es
->style
& ES_MULTILINE
))
3041 if (line
>= es
->line_count
)
3045 line_def
= es
->first_line_def
;
3047 INT index
= es
->selection_end
- line_def
->length
;
3048 while ((index
>= 0) && line_def
->next
) {
3049 line_index
+= line_def
->length
;
3050 line_def
= line_def
->next
;
3051 index
-= line_def
->length
;
3055 line_index
+= line_def
->length
;
3056 line_def
= line_def
->next
;
3064 /*********************************************************************
3069 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
3073 if (!(es
->style
& ES_MULTILINE
))
3074 return get_text_length(es
);
3077 /* get the number of remaining non-selected chars of selected lines */
3078 INT32 l
; /* line number */
3079 INT32 li
; /* index of first char in line */
3081 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
3082 /* # chars before start of selection area */
3083 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
3084 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3085 /* # chars after end of selection */
3086 li
= EDIT_EM_LineIndex(es
, l
);
3087 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
3090 line_def
= es
->first_line_def
;
3091 index
-= line_def
->length
;
3092 while ((index
>= 0) && line_def
->next
) {
3093 line_def
= line_def
->next
;
3094 index
-= line_def
->length
;
3096 return line_def
->net_length
;
3100 /*********************************************************************
3104 * NOTE: dx is in average character widths, dy - in lines;
3107 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
3109 if (!(es
->style
& ES_MULTILINE
))
3112 dx
*= es
->char_width
;
3113 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3116 /*********************************************************************
3118 * EDIT_EM_LineScroll_internal
3120 * Version of EDIT_EM_LineScroll for internal use.
3121 * It doesn't refuse if ES_MULTILINE is set and assumes that
3122 * dx is in pixels, dy - in lines.
3125 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3128 INT x_offset_in_pixels
;
3129 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3132 if (es
->style
& ES_MULTILINE
)
3134 x_offset_in_pixels
= es
->x_offset
;
3139 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3142 if (-dx
> x_offset_in_pixels
)
3143 dx
= -x_offset_in_pixels
;
3144 if (dx
> es
->text_width
- x_offset_in_pixels
)
3145 dx
= es
->text_width
- x_offset_in_pixels
;
3146 nyoff
= max(0, es
->y_offset
+ dy
);
3147 if (nyoff
>= es
->line_count
- lines_per_page
)
3148 nyoff
= max(0, es
->line_count
- lines_per_page
);
3149 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3154 es
->y_offset
= nyoff
;
3155 if(es
->style
& ES_MULTILINE
)
3158 es
->x_offset
+= dx
/ es
->char_width
;
3160 GetClientRect(es
->hwndSelf
, &rc1
);
3161 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3162 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3163 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3164 /* force scroll info update */
3165 EDIT_UpdateScrollInfo(es
);
3167 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3168 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3169 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3170 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3175 /*********************************************************************
3180 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3182 INT len
= get_text_length(es
);
3195 index
= min(index
, len
);
3196 dc
= GetDC(es
->hwndSelf
);
3198 old_font
= SelectObject(dc
, es
->font
);
3199 if (es
->style
& ES_MULTILINE
) {
3200 l
= EDIT_EM_LineFromChar(es
, index
);
3201 y
= (l
- es
->y_offset
) * es
->line_height
;
3202 li
= EDIT_EM_LineIndex(es
, l
);
3203 if (after_wrap
&& (li
== index
) && l
) {
3205 line_def
= es
->first_line_def
;
3207 line_def
= line_def
->next
;
3210 if (line_def
->ending
== END_WRAP
) {
3212 y
-= es
->line_height
;
3213 li
= EDIT_EM_LineIndex(es
, l
);
3217 line_def
= es
->first_line_def
;
3218 while (line_def
->index
!= li
)
3219 line_def
= line_def
->next
;
3221 ll
= line_def
->net_length
;
3222 lw
= line_def
->width
;
3224 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3225 if (es
->style
& ES_RIGHT
)
3227 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3228 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3231 else if (es
->style
& ES_CENTER
)
3233 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3234 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3239 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3240 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3243 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3244 if (index
< es
->x_offset
) {
3245 GetTextExtentPoint32W(dc
, text
+ index
,
3246 es
->x_offset
- index
, &size
);
3249 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3250 index
- es
->x_offset
, &size
);
3253 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3255 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3256 if (w
> es
->text_width
)
3258 if (es
->style
& ES_RIGHT
)
3259 x
+= w
- es
->text_width
;
3260 else if (es
->style
& ES_CENTER
)
3261 x
+= (w
- es
->text_width
) / 2;
3266 if (es
->style
& ES_PASSWORD
)
3267 HeapFree(GetProcessHeap(), 0, text
);
3269 x
+= es
->format_rect
.left
;
3270 y
+= es
->format_rect
.top
;
3272 SelectObject(dc
, old_font
);
3273 ReleaseDC(es
->hwndSelf
, dc
);
3274 return MAKELONG((INT16
)x
, (INT16
)y
);
3278 /*********************************************************************
3282 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3285 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3287 UINT strl
= strlenW(lpsz_replace
);
3288 UINT tl
= get_text_length(es
);
3299 TRACE("%s, can_undo %d, send_update %d\n",
3300 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3302 s
= es
->selection_start
;
3303 e
= es
->selection_end
;
3305 if ((s
== e
) && !strl
)
3310 size
= tl
- (e
- s
) + strl
;
3314 /* Issue the EN_MAXTEXT notification and continue with replacing text
3315 * such that buffer limit is honored. */
3316 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
3317 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3318 /* Buffer limit can be smaller than the actual length of text in combobox */
3319 if (es
->buffer_limit
< (tl
- (e
-s
)))
3322 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3325 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3329 /* there is something to be deleted */
3330 TRACE("deleting stuff.\n");
3332 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3334 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3335 buf
[bufl
] = 0; /* ensure 0 termination */
3337 strcpyW(es
->text
+ s
, es
->text
+ e
);
3338 text_buffer_changed(es
);
3341 /* there is an insertion */
3342 tl
= get_text_length(es
);
3343 TRACE("inserting stuff (tl %d, strl %d, selstart %d (%s), text %s)\n", tl
, strl
, s
, debugstr_w(es
->text
+ s
), debugstr_w(es
->text
));
3344 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3346 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3347 p
[i
] = lpsz_replace
[i
];
3348 if(es
->style
& ES_UPPERCASE
)
3349 CharUpperBuffW(p
, strl
);
3350 else if(es
->style
& ES_LOWERCASE
)
3351 CharLowerBuffW(p
, strl
);
3352 text_buffer_changed(es
);
3354 if (es
->style
& ES_MULTILINE
)
3356 INT st
= min(es
->selection_start
, es
->selection_end
);
3357 INT vlc
= get_vertical_line_count(es
);
3359 hrgn
= CreateRectRgn(0, 0, 0, 0);
3360 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3361 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3362 /* if text is too long undo all changes */
3363 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3365 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3367 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3369 text_buffer_changed(es
);
3370 EDIT_BuildLineDefs_ML(es
, s
, e
,
3371 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3374 hrgn
= CreateRectRgn(0, 0, 0, 0);
3375 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3379 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3380 EDIT_CalcLineWidth_SL(es
);
3381 /* remove chars that don't fit */
3382 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3383 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3384 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3386 EDIT_CalcLineWidth_SL(es
);
3388 text_buffer_changed(es
);
3389 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3395 utl
= strlenW(es
->undo_text
);
3396 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3397 /* undo-buffer is extended to the right */
3398 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3399 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3400 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3401 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3402 /* undo-buffer is extended to the left */
3403 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3404 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3406 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3408 es
->undo_position
= s
;
3410 /* new undo-buffer */
3411 EDIT_MakeUndoFit(es
, e
- s
);
3412 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3413 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3414 es
->undo_position
= s
;
3416 /* any deletion makes the old insertion-undo invalid */
3417 es
->undo_insert_count
= 0;
3419 EDIT_EM_EmptyUndoBuffer(es
);
3423 if ((s
== es
->undo_position
) ||
3424 ((es
->undo_insert_count
) &&
3425 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3427 * insertion is new and at delete position or
3428 * an extension to either left or right
3430 es
->undo_insert_count
+= strl
;
3432 /* new insertion undo */
3433 es
->undo_position
= s
;
3434 es
->undo_insert_count
= strl
;
3435 /* new insertion makes old delete-buffer invalid */
3436 *es
->undo_text
= '\0';
3439 EDIT_EM_EmptyUndoBuffer(es
);
3443 HeapFree(GetProcessHeap(), 0, buf
);
3447 /* If text has been deleted and we're right or center aligned then scroll rightward */
3448 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3450 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3452 if (delta
< 0 && es
->x_offset
)
3454 if (abs(delta
) > es
->x_offset
)
3457 es
->x_offset
+= delta
;
3461 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3462 es
->flags
|= EF_MODIFIED
;
3463 if (send_update
) es
->flags
|= EF_UPDATE
;
3466 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3470 EDIT_UpdateText(es
, NULL
, TRUE
);
3472 EDIT_EM_ScrollCaret(es
);
3474 /* force scroll info update */
3475 EDIT_UpdateScrollInfo(es
);
3478 if(send_update
|| (es
->flags
& EF_UPDATE
))
3480 es
->flags
&= ~EF_UPDATE
;
3481 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3486 /*********************************************************************
3491 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3495 if (!(es
->style
& ES_MULTILINE
))
3496 return (LRESULT
)FALSE
;
3506 if (es
->y_offset
< es
->line_count
- 1)
3511 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3514 if (es
->y_offset
< es
->line_count
- 1)
3515 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3518 return (LRESULT
)FALSE
;
3521 INT vlc
= get_vertical_line_count(es
);
3522 /* check if we are going to move too far */
3523 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3524 dy
= es
->line_count
- vlc
- es
->y_offset
;
3526 /* Notification is done in EDIT_EM_LineScroll */
3528 EDIT_EM_LineScroll(es
, 0, dy
);
3531 return MAKELONG((SHORT
)dy
, (BOOL
)TRUE
);
3533 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3538 /*********************************************************************
3543 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3545 if (es
->style
& ES_MULTILINE
) {
3549 INT cw
= es
->char_width
;
3554 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3555 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3556 vlc
= get_vertical_line_count(es
);
3557 if (l
>= es
->y_offset
+ vlc
)
3558 dy
= l
- vlc
+ 1 - es
->y_offset
;
3559 if (l
< es
->y_offset
)
3560 dy
= l
- es
->y_offset
;
3561 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3562 if (x
< es
->format_rect
.left
)
3563 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3564 if (x
> es
->format_rect
.right
)
3565 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3566 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3568 /* check if we are going to move too far */
3569 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3570 dx
= es
->text_width
- ww
- es
->x_offset
;
3571 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3572 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3579 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3580 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3581 if (x
< es
->format_rect
.left
) {
3582 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3585 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3586 } while ((x
< goal
) && es
->x_offset
);
3587 /* FIXME: use ScrollWindow() somehow to improve performance */
3588 EDIT_UpdateText(es
, NULL
, TRUE
);
3589 } else if (x
> es
->format_rect
.right
) {
3591 INT len
= get_text_length(es
);
3592 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3595 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3596 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3597 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3598 /* FIXME: use ScrollWindow() somehow to improve performance */
3599 EDIT_UpdateText(es
, NULL
, TRUE
);
3603 if(es
->flags
& EF_FOCUSED
)
3604 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3608 /*********************************************************************
3612 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3615 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3617 if (!(es
->style
& ES_MULTILINE
))
3621 WARN("called with NULL handle\n");
3625 EDIT_UnlockBuffer(es
, TRUE
);
3630 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3631 HANDLE16 oldDS
= stack16
->ds
;
3633 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3634 LocalFree16(es
->hloc16
);
3635 stack16
->ds
= oldDS
;
3644 LocalFree(es
->hloc32A
);
3656 countA
= LocalSize(hloc
);
3657 textA
= LocalLock(hloc
);
3658 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3659 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3661 ERR("Could not allocate new unicode buffer\n");
3664 textW
= LocalLock(hloc32W_new
);
3665 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3666 LocalUnlock(hloc32W_new
);
3670 LocalFree(es
->hloc32W
);
3672 es
->hloc32W
= hloc32W_new
;
3676 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3678 es
->flags
|= EF_APP_HAS_HANDLE
;
3679 EDIT_LockBuffer(es
);
3681 es
->x_offset
= es
->y_offset
= 0;
3682 es
->selection_start
= es
->selection_end
= 0;
3683 EDIT_EM_EmptyUndoBuffer(es
);
3684 es
->flags
&= ~EF_MODIFIED
;
3685 es
->flags
&= ~EF_UPDATE
;
3686 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3687 EDIT_UpdateText(es
, NULL
, TRUE
);
3688 EDIT_EM_ScrollCaret(es
);
3689 /* force scroll info update */
3690 EDIT_UpdateScrollInfo(es
);
3695 /*********************************************************************
3699 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3702 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3704 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3705 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3706 HANDLE16 oldDS
= stack16
->ds
;
3712 if (!(es
->style
& ES_MULTILINE
))
3716 WARN("called with NULL handle\n");
3720 EDIT_UnlockBuffer(es
, TRUE
);
3724 LocalFree(es
->hloc32A
);
3728 stack16
->ds
= hInstance
;
3729 countA
= LocalSize16(hloc
);
3730 textA
= MapSL(LocalLock16(hloc
));
3731 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3732 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3734 ERR("Could not allocate new unicode buffer\n");
3737 textW
= LocalLock(hloc32W_new
);
3738 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3739 LocalUnlock(hloc32W_new
);
3740 LocalUnlock16(hloc
);
3741 stack16
->ds
= oldDS
;
3744 LocalFree(es
->hloc32W
);
3746 es
->hloc32W
= hloc32W_new
;
3749 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3751 es
->flags
|= EF_APP_HAS_HANDLE
;
3752 EDIT_LockBuffer(es
);
3754 es
->x_offset
= es
->y_offset
= 0;
3755 es
->selection_start
= es
->selection_end
= 0;
3756 EDIT_EM_EmptyUndoBuffer(es
);
3757 es
->flags
&= ~EF_MODIFIED
;
3758 es
->flags
&= ~EF_UPDATE
;
3759 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3760 EDIT_UpdateText(es
, NULL
, TRUE
);
3761 EDIT_EM_ScrollCaret(es
);
3762 /* force scroll info update */
3763 EDIT_UpdateScrollInfo(es
);
3768 /*********************************************************************
3772 * NOTE: this version currently implements WinNT limits
3775 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
3777 if (!limit
) limit
= ~0u;
3778 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
3779 es
->buffer_limit
= limit
;
3783 /*********************************************************************
3787 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3788 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3789 * margin according to the textmetrics of the current font.
3791 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3792 * of the char's width as the margin, but this is not how Windows handles this.
3793 * For all other fonts Windows sets the margins to zero.
3795 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3796 * edit control is equal to or larger than a certain size.
3797 * Interestingly if one subtracts both the left and right margins from
3798 * this size one always seems to get an even number. The extents of
3799 * the (four character) string "'**'" match this quite closely, so
3800 * we'll use this until we come up with a better idea.
3802 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3804 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3807 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3808 return sz
.cx
+ left
+ right
;
3811 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3812 WORD left
, WORD right
, BOOL repaint
)
3815 INT default_left_margin
= 0; /* in pixels */
3816 INT default_right_margin
= 0; /* in pixels */
3818 /* Set the default margins depending on the font */
3819 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3820 HDC dc
= GetDC(es
->hwndSelf
);
3821 HFONT old_font
= SelectObject(dc
, es
->font
);
3822 GetTextMetricsW(dc
, &tm
);
3823 /* The default margins are only non zero for TrueType or Vector fonts */
3824 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3827 /* This must be calculated more exactly! But how? */
3828 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3829 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3830 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3831 GetClientRect(es
->hwndSelf
, &rc
);
3832 if(rc
.right
- rc
.left
< min_size
) {
3833 default_left_margin
= es
->left_margin
;
3834 default_right_margin
= es
->right_margin
;
3837 SelectObject(dc
, old_font
);
3838 ReleaseDC(es
->hwndSelf
, dc
);
3841 if (action
& EC_LEFTMARGIN
) {
3842 es
->format_rect
.left
-= es
->left_margin
;
3843 if (left
!= EC_USEFONTINFO
)
3844 es
->left_margin
= left
;
3846 es
->left_margin
= default_left_margin
;
3847 es
->format_rect
.left
+= es
->left_margin
;
3850 if (action
& EC_RIGHTMARGIN
) {
3851 es
->format_rect
.right
+= es
->right_margin
;
3852 if (right
!= EC_USEFONTINFO
)
3853 es
->right_margin
= right
;
3855 es
->right_margin
= default_right_margin
;
3856 es
->format_rect
.right
-= es
->right_margin
;
3859 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3860 EDIT_AdjustFormatRect(es
);
3861 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3864 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3868 /*********************************************************************
3870 * EM_SETPASSWORDCHAR
3873 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3877 if (es
->style
& ES_MULTILINE
)
3880 if (es
->password_char
== c
)
3883 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3884 es
->password_char
= c
;
3886 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3887 es
->style
|= ES_PASSWORD
;
3889 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3890 es
->style
&= ~ES_PASSWORD
;
3892 EDIT_UpdateText(es
, NULL
, TRUE
);
3896 /*********************************************************************
3900 * note: unlike the specs say: the order of start and end
3901 * _is_ preserved in Windows. (i.e. start can be > end)
3902 * In other words: this handler is OK
3905 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3907 UINT old_start
= es
->selection_start
;
3908 UINT old_end
= es
->selection_end
;
3909 UINT len
= get_text_length(es
);
3911 if (start
== (UINT
)-1) {
3912 start
= es
->selection_end
;
3913 end
= es
->selection_end
;
3915 start
= min(start
, len
);
3916 end
= min(end
, len
);
3918 es
->selection_start
= start
;
3919 es
->selection_end
= end
;
3921 es
->flags
|= EF_AFTER_WRAP
;
3923 es
->flags
&= ~EF_AFTER_WRAP
;
3924 /* Compute the necessary invalidation region. */
3925 /* Note that we don't need to invalidate regions which have
3926 * "never" been selected, or those which are "still" selected.
3927 * In fact, every time we hit a selection boundary, we can
3928 * *toggle* whether we need to invalidate. Thus we can optimize by
3929 * *sorting* the interval endpoints. Let's assume that we sort them
3931 * start <= end <= old_start <= old_end
3932 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
3933 * in 5 comparisons; i.e. it is impossible to do better than the
3935 ORDER_UINT(end
, old_end
);
3936 ORDER_UINT(start
, old_start
);
3937 ORDER_UINT(old_start
, old_end
);
3938 ORDER_UINT(start
, end
);
3939 /* Note that at this point 'end' and 'old_start' are not in order, but
3940 * start is definitely the min. and old_end is definitely the max. */
3941 if (end
!= old_start
)
3945 * ORDER_UINT32(end, old_start);
3946 * EDIT_InvalidateText(es, start, end);
3947 * EDIT_InvalidateText(es, old_start, old_end);
3948 * in place of the following if statement.
3949 * (That would complete the optimal five-comparison four-element sort.)
3951 if (old_start
> end
)
3953 EDIT_InvalidateText(es
, start
, end
);
3954 EDIT_InvalidateText(es
, old_start
, old_end
);
3958 EDIT_InvalidateText(es
, start
, old_start
);
3959 EDIT_InvalidateText(es
, end
, old_end
);
3962 else EDIT_InvalidateText(es
, start
, old_end
);
3966 /*********************************************************************
3971 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3973 if (!(es
->style
& ES_MULTILINE
))
3975 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3976 es
->tabs_count
= count
;
3980 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3981 if (es
->tabs
== NULL
)
3986 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3993 /*********************************************************************
3998 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
4000 if (!(es
->style
& ES_MULTILINE
))
4002 HeapFree(GetProcessHeap(), 0, es
->tabs
);
4003 es
->tabs_count
= count
;
4008 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
4009 for (i
= 0 ; i
< count
; i
++)
4010 es
->tabs
[i
] = *tabs
++;
4017 /*********************************************************************
4019 * EM_SETWORDBREAKPROC
4022 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
4024 if (es
->word_break_proc
== wbp
)
4027 es
->word_break_proc
= wbp
;
4029 es
->word_break_proc16
= NULL
;
4032 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
4033 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
4034 EDIT_UpdateText(es
, NULL
, TRUE
);
4040 /*********************************************************************
4042 * EM_SETWORDBREAKPROC16
4045 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
4047 if (es
->word_break_proc16
== wbp
)
4050 es
->word_break_proc
= NULL
;
4051 es
->word_break_proc16
= wbp
;
4052 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
4053 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
4054 EDIT_UpdateText(es
, NULL
, TRUE
);
4060 /*********************************************************************
4065 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
4070 /* As per MSDN spec, for a single-line edit control,
4071 the return value is always TRUE */
4072 if( es
->style
& ES_READONLY
)
4073 return !(es
->style
& ES_MULTILINE
);
4075 ulength
= strlenW(es
->undo_text
);
4077 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
4081 strcpyW(utext
, es
->undo_text
);
4083 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
4084 es
->undo_insert_count
, debugstr_w(utext
));
4086 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
4087 EDIT_EM_EmptyUndoBuffer(es
);
4088 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
4089 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
4090 /* send the notification after the selection start and end are set */
4091 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4092 EDIT_EM_ScrollCaret(es
);
4093 HeapFree(GetProcessHeap(), 0, utext
);
4095 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
4096 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
4101 /* Helper function for WM_CHAR
4103 * According to an MSDN blog article titled "Just because you're a control
4104 * doesn't mean that you're necessarily inside a dialog box," multiline edit
4105 * controls without ES_WANTRETURN would attempt to detect whether it is inside
4106 * a dialog box or not.
4108 static BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
4111 if (es
->hwndParent
&& es
->hwndParent
!= GetDesktopWindow())
4113 if (GetClassLongW (es
->hwndParent
, GCW_ATOM
) == (DWORD
)MAKEINTATOM(32770))
4123 pParent
= WIN_GetPtr(es
->hwndParent
);
4124 if (pParent
&& pParent
!= WND_OTHER_PROCESS
&& pParent
!= WND_DESKTOP
)
4126 if (pParent
->flags
& WIN_ISDIALOG
)
4128 WIN_ReleasePtr(pParent
);
4136 /*********************************************************************
4141 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
4145 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4149 /* If it's not a multiline edit box, it would be ignored below.
4150 * For multiline edit without ES_WANTRETURN, we have to make a
4153 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
4154 if (EDIT_IsInsideDialog(es
))
4157 if (es
->style
& ES_MULTILINE
) {
4158 if (es
->style
& ES_READONLY
) {
4159 EDIT_MoveHome(es
, FALSE
, FALSE
);
4160 EDIT_MoveDown_ML(es
, FALSE
);
4162 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4163 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4168 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4170 static const WCHAR tabW
[] = {'\t',0};
4171 if (EDIT_IsInsideDialog(es
))
4173 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4177 if (!(es
->style
& ES_READONLY
) && !control
) {
4178 if (es
->selection_start
!= es
->selection_end
)
4181 /* delete character left of caret */
4182 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4183 EDIT_MoveBackward(es
, TRUE
);
4189 if (!(es
->style
& ES_PASSWORD
))
4190 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4193 if (!(es
->style
& ES_READONLY
))
4194 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4197 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4198 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4201 if (!(es
->style
& ES_READONLY
))
4202 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4206 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4207 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4210 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4214 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4222 /*********************************************************************
4227 static void EDIT_WM_MenuSelect(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4230 static INT MenuSelected
;
4237 switch (MenuSelected
) {
4239 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4242 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4245 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4248 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4251 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
4254 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4255 EDIT_EM_ScrollCaret(es
);
4258 ERR("unknown menu item, please report\n");
4264 /*********************************************************************
4268 * Note: the resource files resource/sysres_??.rc cannot define a
4269 * single popup menu. Hence we use a (dummy) menubar
4270 * containing the single popup menu as its first item.
4272 * FIXME: the message identifiers have been chosen arbitrarily,
4273 * hence we use MF_BYPOSITION.
4274 * We might as well use the "real" values (anybody knows ?)
4275 * The menu definition is in resources/sysres_??.rc.
4276 * Once these are OK, we better use MF_BYCOMMAND here
4277 * (as we do in EDIT_WM_Command()).
4280 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4283 HMENU menu
= LoadMenuA(User32Instance
, "EDITMENU");
4285 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4287 HMENU popup
= GetSubMenu(menu
, 0);
4288 UINT start
= es
->selection_start
;
4289 UINT end
= es
->selection_end
;
4291 ORDER_UINT(start
, end
);
4294 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4296 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4298 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4300 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4302 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4304 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4306 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4309 /* Windows places the menu at the edit's center in this case */
4310 GetClientRect(es
->hwndSelf
, &rc
);
4311 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4312 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4313 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4316 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4321 /*********************************************************************
4326 static void EDIT_WM_Copy(EDITSTATE
*es
)
4328 INT s
= min(es
->selection_start
, es
->selection_end
);
4329 INT e
= max(es
->selection_start
, es
->selection_end
);
4337 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4338 dst
= GlobalLock(hdst
);
4339 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4340 dst
[len
] = 0; /* ensure 0 termination */
4341 TRACE("%s\n", debugstr_w(dst
));
4343 OpenClipboard(es
->hwndSelf
);
4345 SetClipboardData(CF_UNICODETEXT
, hdst
);
4350 /*********************************************************************
4355 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4359 TRACE("%s\n", debugstr_w(name
));
4361 * To initialize some final structure members, we call some helper
4362 * functions. However, since the EDITSTATE is not consistent (i.e.
4363 * not fully initialized), we should be very careful which
4364 * functions can be called, and in what order.
4366 EDIT_WM_SetFont(es
, 0, FALSE
);
4367 EDIT_EM_EmptyUndoBuffer(es
);
4369 /* We need to calculate the format rect
4370 (applications may send EM_SETMARGINS before the control gets visible) */
4371 GetClientRect(es
->hwndSelf
, &clientRect
);
4372 EDIT_SetRectNP(es
, &clientRect
);
4374 if (name
&& *name
) {
4375 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4376 /* if we insert text to the editline, the text scrolls out
4377 * of the window, as the caret is placed after the insert
4378 * pos normally; thus we reset es->selection... to 0 and
4381 es
->selection_start
= es
->selection_end
= 0;
4382 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4383 * Messages are only to be sent when the USER does something to
4384 * change the contents. So I am removing this EN_CHANGE
4386 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4388 EDIT_EM_ScrollCaret(es
);
4390 /* force scroll info update */
4391 EDIT_UpdateScrollInfo(es
);
4392 /* The rule seems to return 1 here for success */
4393 /* Power Builder masked edit controls will crash */
4395 /* FIXME: is that in all cases so ? */
4400 /*********************************************************************
4405 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4410 LocalFree(es
->hloc32W
);
4413 LocalFree(es
->hloc32A
);
4417 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4418 HANDLE16 oldDS
= stack16
->ds
;
4420 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4421 while (LocalUnlock16(es
->hloc16
)) ;
4422 LocalFree16(es
->hloc16
);
4423 stack16
->ds
= oldDS
;
4427 pc
= es
->first_line_def
;
4431 HeapFree(GetProcessHeap(), 0, pc
);
4435 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4436 HeapFree(GetProcessHeap(), 0, es
);
4442 /*********************************************************************
4447 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4449 if(!count
) return 0;
4453 lstrcpynW(dst
, es
->text
, count
);
4454 return strlenW(dst
);
4458 LPSTR textA
= (LPSTR
)dst
;
4459 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4460 textA
[count
- 1] = 0; /* ensure 0 termination */
4461 return strlen(textA
);
4465 /*********************************************************************
4470 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4475 if (!(es
->style
& ES_MULTILINE
))
4478 if (!(es
->style
& ES_AUTOHSCROLL
))
4482 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4485 TRACE("SB_LINELEFT\n");
4487 dx
= -es
->char_width
;
4490 TRACE("SB_LINERIGHT\n");
4491 if (es
->x_offset
< es
->text_width
)
4492 dx
= es
->char_width
;
4495 TRACE("SB_PAGELEFT\n");
4497 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4500 TRACE("SB_PAGERIGHT\n");
4501 if (es
->x_offset
< es
->text_width
)
4502 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4510 TRACE("SB_RIGHT\n");
4511 if (es
->x_offset
< es
->text_width
)
4512 dx
= es
->text_width
- es
->x_offset
;
4515 TRACE("SB_THUMBTRACK %d\n", pos
);
4516 es
->flags
|= EF_HSCROLL_TRACK
;
4517 if(es
->style
& WS_HSCROLL
)
4518 dx
= pos
- es
->x_offset
;
4523 if(pos
< 0 || pos
> 100) return 0;
4524 /* Assume default scroll range 0-100 */
4525 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4526 new_x
= pos
* (es
->text_width
- fw
) / 100;
4527 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4530 case SB_THUMBPOSITION
:
4531 TRACE("SB_THUMBPOSITION %d\n", pos
);
4532 es
->flags
&= ~EF_HSCROLL_TRACK
;
4533 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4534 dx
= pos
- es
->x_offset
;
4539 if(pos
< 0 || pos
> 100) return 0;
4540 /* Assume default scroll range 0-100 */
4541 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4542 new_x
= pos
* (es
->text_width
- fw
) / 100;
4543 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4546 /* force scroll info update */
4547 EDIT_UpdateScrollInfo(es
);
4548 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4552 TRACE("SB_ENDSCROLL\n");
4555 * FIXME : the next two are undocumented !
4556 * Are we doing the right thing ?
4557 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4558 * although it's also a regular control message.
4560 case EM_GETTHUMB
: /* this one is used by NT notepad */
4566 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4567 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4570 /* Assume default scroll range 0-100 */
4571 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4572 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4574 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4578 case EM_LINESCROLL16
:
4579 TRACE("EM_LINESCROLL16\n");
4585 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4591 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4592 /* check if we are going to move too far */
4593 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4594 dx
= es
->text_width
- fw
- es
->x_offset
;
4596 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4602 /*********************************************************************
4607 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4609 HWND hLBox
= es
->hwndListBox
;
4617 hCombo
= GetParent(es
->hwndSelf
);
4621 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4623 if (key
== VK_UP
|| key
== VK_DOWN
)
4625 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4628 if (msg
== WM_KEYDOWN
|| nEUI
)
4629 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4635 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4637 /* make sure ComboLBox pops up */
4638 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4643 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4646 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4648 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4650 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4655 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4661 /*********************************************************************
4665 * Handling of special keys that don't produce a WM_CHAR
4666 * (i.e. non-printable keys) & Backspace & Delete
4669 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4674 if (GetKeyState(VK_MENU
) & 0x8000)
4677 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4678 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4683 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4688 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4689 EDIT_MoveUp_ML(es
, shift
);
4692 EDIT_MoveWordBackward(es
, shift
);
4694 EDIT_MoveBackward(es
, shift
);
4697 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4701 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4702 EDIT_MoveDown_ML(es
, shift
);
4704 EDIT_MoveWordForward(es
, shift
);
4706 EDIT_MoveForward(es
, shift
);
4709 EDIT_MoveHome(es
, shift
, control
);
4712 EDIT_MoveEnd(es
, shift
, control
);
4715 if (es
->style
& ES_MULTILINE
)
4716 EDIT_MovePageUp_ML(es
, shift
);
4718 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4721 if (es
->style
& ES_MULTILINE
)
4722 EDIT_MovePageDown_ML(es
, shift
);
4724 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4727 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4728 if (es
->selection_start
!= es
->selection_end
) {
4735 /* delete character left of caret */
4736 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4737 EDIT_MoveBackward(es
, TRUE
);
4739 } else if (control
) {
4740 /* delete to end of line */
4741 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4742 EDIT_MoveEnd(es
, TRUE
, FALSE
);
4745 /* delete character right of caret */
4746 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4747 EDIT_MoveForward(es
, TRUE
);
4755 if (!(es
->style
& ES_READONLY
))
4761 /* If the edit doesn't want the return send a message to the default object */
4762 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
4767 if (!EDIT_IsInsideDialog(es
)) return 1;
4770 hwndParent
= GetParent(es
->hwndSelf
);
4771 dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4772 if (HIWORD(dw
) == DC_HASDEFID
)
4774 SendMessageW( hwndParent
, WM_COMMAND
,
4775 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4776 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4779 SendMessageW( hwndParent
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndParent
, IDOK
) );
4783 if (!(es
->style
& ES_MULTILINE
))
4784 SendMessageW(GetParent(es
->hwndSelf
), WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( GetParent(es
->hwndSelf
), IDCANCEL
) );
4787 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
4794 /*********************************************************************
4799 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4801 es
->flags
&= ~EF_FOCUSED
;
4803 if(!(es
->style
& ES_NOHIDESEL
))
4804 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4805 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4810 /*********************************************************************
4814 * The caret position has been set on the WM_LBUTTONDOWN message
4817 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4820 INT e
= es
->selection_end
;
4825 es
->bCaptureState
= TRUE
;
4826 SetCapture(es
->hwndSelf
);
4828 l
= EDIT_EM_LineFromChar(es
, e
);
4829 li
= EDIT_EM_LineIndex(es
, l
);
4830 ll
= EDIT_EM_LineLength(es
, e
);
4831 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4832 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4833 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4834 EDIT_EM_ScrollCaret(es
);
4835 es
->region_posx
= es
->region_posy
= 0;
4836 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4841 /*********************************************************************
4846 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4851 es
->bCaptureState
= TRUE
;
4852 SetCapture(es
->hwndSelf
);
4853 EDIT_ConfinePoint(es
, &x
, &y
);
4854 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4855 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4856 EDIT_EM_ScrollCaret(es
);
4857 es
->region_posx
= es
->region_posy
= 0;
4858 if (!(es
->style
& ES_MULTILINE
))
4859 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4861 if (!(es
->flags
& EF_FOCUSED
))
4862 SetFocus(es
->hwndSelf
);
4868 /*********************************************************************
4873 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4875 if (es
->bCaptureState
) {
4876 KillTimer(es
->hwndSelf
, 0);
4877 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4879 es
->bCaptureState
= FALSE
;
4884 /*********************************************************************
4889 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4891 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4896 /*********************************************************************
4901 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4907 /* If the mouse has been captured by process other than the edit control itself,
4908 * the windows edit controls will not select the strings with mouse move.
4910 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4914 * FIXME: gotta do some scrolling if outside client
4915 * area. Maybe reset the timer ?
4918 EDIT_ConfinePoint(es
, &x
, &y
);
4919 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4920 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4921 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4922 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4923 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4928 /*********************************************************************
4932 * See also EDIT_WM_StyleChanged
4934 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4939 TRACE("Creating %s edit control, style = %08x\n",
4940 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4942 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4944 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4947 * Note: since the EDITSTATE has not been fully initialized yet,
4948 * we can't use any API calls that may send
4949 * WM_XXX messages before WM_NCCREATE is completed.
4952 es
->is_unicode
= unicode
;
4953 es
->style
= lpcs
->style
;
4955 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4957 es
->hwndSelf
= hwnd
;
4958 /* Save parent, which will be notified by EN_* messages */
4959 es
->hwndParent
= lpcs
->hwndParent
;
4961 if (es
->style
& ES_COMBO
)
4962 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4964 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4965 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4967 /* Number overrides lowercase overrides uppercase (at least it
4968 * does in Win95). However I'll bet that ES_NUMBER would be
4969 * invalid under Win 3.1.
4971 if (es
->style
& ES_NUMBER
) {
4972 ; /* do not override the ES_NUMBER */
4973 } else if (es
->style
& ES_LOWERCASE
) {
4974 es
->style
&= ~ES_UPPERCASE
;
4976 if (es
->style
& ES_MULTILINE
) {
4977 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4978 if (es
->style
& WS_VSCROLL
)
4979 es
->style
|= ES_AUTOVSCROLL
;
4980 if (es
->style
& WS_HSCROLL
)
4981 es
->style
|= ES_AUTOHSCROLL
;
4982 es
->style
&= ~ES_PASSWORD
;
4983 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4984 /* Confirmed - RIGHT overrides CENTER */
4985 if (es
->style
& ES_RIGHT
)
4986 es
->style
&= ~ES_CENTER
;
4987 es
->style
&= ~WS_HSCROLL
;
4988 es
->style
&= ~ES_AUTOHSCROLL
;
4991 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4992 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4993 es
->style
&= ~ES_CENTER
;
4994 es
->style
&= ~WS_HSCROLL
;
4995 es
->style
&= ~WS_VSCROLL
;
4996 if (es
->style
& ES_PASSWORD
)
4997 es
->password_char
= '*';
5000 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
5001 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
5003 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
5005 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
5007 es
->undo_buffer_size
= es
->buffer_size
;
5009 if (es
->style
& ES_MULTILINE
)
5010 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
5015 * In Win95 look and feel, the WS_BORDER style is replaced by the
5016 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
5017 * control a nonclient area so we don't need to draw the border.
5018 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
5019 * a nonclient area and we should handle painting the border ourselves.
5021 * When making modifications please ensure that the code still works
5022 * for edit controls created directly with style 0x50800000, exStyle 0
5023 * (which should have a single pixel border)
5025 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
5026 es
->style
&= ~WS_BORDER
;
5027 else if (es
->style
& WS_BORDER
)
5028 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
5033 /*********************************************************************
5038 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
5051 BOOL rev
= es
->bEnableState
&&
5052 ((es
->flags
& EF_FOCUSED
) ||
5053 (es
->style
& ES_NOHIDESEL
));
5054 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
5056 GetClientRect(es
->hwndSelf
, &rcClient
);
5058 /* get the background brush */
5059 brush
= EDIT_NotifyCtlColor(es
, dc
);
5061 /* paint the border and the background */
5062 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5064 if(es
->style
& WS_BORDER
) {
5065 bw
= GetSystemMetrics(SM_CXBORDER
);
5066 bh
= GetSystemMetrics(SM_CYBORDER
);
5068 if(es
->style
& ES_MULTILINE
) {
5069 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
5070 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
5073 /* Draw the frame. Same code as in nonclient.c */
5074 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
5075 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
5076 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
5077 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
5078 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
5079 SelectObject(dc
, old_brush
);
5081 /* Keep the border clean */
5082 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
5083 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
5086 GetClipBox(dc
, &rc
);
5087 FillRect(dc
, &rc
, brush
);
5089 IntersectClipRect(dc
, es
->format_rect
.left
,
5090 es
->format_rect
.top
,
5091 es
->format_rect
.right
,
5092 es
->format_rect
.bottom
);
5093 if (es
->style
& ES_MULTILINE
) {
5095 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5098 old_font
= SelectObject(dc
, es
->font
);
5100 if (!es
->bEnableState
)
5101 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
5102 GetClipBox(dc
, &rcRgn
);
5103 if (es
->style
& ES_MULTILINE
) {
5104 INT vlc
= get_vertical_line_count(es
);
5105 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
5106 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
5107 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
5108 EDIT_PaintLine(es
, dc
, i
, rev
);
5111 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
5112 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
5113 EDIT_PaintLine(es
, dc
, 0, rev
);
5116 SelectObject(dc
, old_font
);
5119 EndPaint(es
->hwndSelf
, &ps
);
5123 /*********************************************************************
5128 static void EDIT_WM_Paste(EDITSTATE
*es
)
5133 /* Protect read-only edit control from modification */
5134 if(es
->style
& ES_READONLY
)
5137 OpenClipboard(es
->hwndSelf
);
5138 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
5139 src
= GlobalLock(hsrc
);
5140 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
5143 else if (es
->style
& ES_PASSWORD
) {
5144 /* clear selected text in password edit box even with empty clipboard */
5145 const WCHAR empty_strW
[] = { 0 };
5146 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
5152 /*********************************************************************
5157 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
5159 es
->flags
|= EF_FOCUSED
;
5161 if (!(es
->style
& ES_NOHIDESEL
))
5162 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
5164 /* single line edit updates itself */
5165 if (!(es
->style
& ES_MULTILINE
))
5167 HDC hdc
= GetDC(es
->hwndSelf
);
5168 EDIT_WM_Paint(es
, hdc
);
5169 ReleaseDC(es
->hwndSelf
, hdc
);
5172 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5173 EDIT_SetCaretPos(es
, es
->selection_end
,
5174 es
->flags
& EF_AFTER_WRAP
);
5175 ShowCaret(es
->hwndSelf
);
5176 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
5180 /*********************************************************************
5184 * With Win95 look the margins are set to default font value unless
5185 * the system font (font == 0) is being set, in which case they are left
5189 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5197 dc
= GetDC(es
->hwndSelf
);
5199 old_font
= SelectObject(dc
, font
);
5200 GetTextMetricsW(dc
, &tm
);
5201 es
->line_height
= tm
.tmHeight
;
5202 es
->char_width
= tm
.tmAveCharWidth
;
5204 SelectObject(dc
, old_font
);
5205 ReleaseDC(es
->hwndSelf
, dc
);
5207 /* Reset the format rect and the margins */
5208 GetClientRect(es
->hwndSelf
, &clientRect
);
5209 EDIT_SetRectNP(es
, &clientRect
);
5210 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5211 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5213 if (es
->style
& ES_MULTILINE
)
5214 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5216 EDIT_CalcLineWidth_SL(es
);
5219 EDIT_UpdateText(es
, NULL
, TRUE
);
5220 if (es
->flags
& EF_FOCUSED
) {
5222 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5223 EDIT_SetCaretPos(es
, es
->selection_end
,
5224 es
->flags
& EF_AFTER_WRAP
);
5225 ShowCaret(es
->hwndSelf
);
5230 /*********************************************************************
5235 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5236 * The modified flag is reset. No notifications are sent.
5238 * For single-line controls, reception of WM_SETTEXT triggers:
5239 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5242 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5244 LPWSTR textW
= NULL
;
5245 if (!unicode
&& text
)
5247 LPCSTR textA
= (LPCSTR
)text
;
5248 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5249 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5251 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5255 if (es
->flags
& EF_UPDATE
)
5256 /* fixed this bug once; complain if we see it about to happen again. */
5257 ERR("SetSel may generate UPDATE message whose handler may reset "
5260 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5263 TRACE("%s\n", debugstr_w(text
));
5264 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5266 HeapFree(GetProcessHeap(), 0, textW
);
5270 static const WCHAR empty_stringW
[] = {0};
5272 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5275 es
->flags
&= ~EF_MODIFIED
;
5276 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5278 /* Send the notification after the selection start and end have been set
5279 * edit control doesn't send notification on WM_SETTEXT
5280 * if it is multiline, or it is part of combobox
5282 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5284 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5285 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5287 EDIT_EM_ScrollCaret(es
);
5288 EDIT_UpdateScrollInfo(es
);
5292 /*********************************************************************
5297 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5299 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5301 TRACE("width = %d, height = %d\n", width
, height
);
5302 SetRect(&rc
, 0, 0, width
, height
);
5303 EDIT_SetRectNP(es
, &rc
);
5304 EDIT_UpdateText(es
, NULL
, TRUE
);
5309 /*********************************************************************
5313 * This message is sent by SetWindowLong on having changed either the Style
5314 * or the extended style.
5316 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5318 * See also EDIT_WM_NCCreate
5320 * It appears that the Windows version of the edit control allows the style
5321 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5322 * style variable which will generally be different. In this function we
5323 * update the internal style based on what changed in the externally visible
5326 * Much of this content as based upon the MSDN, especially:
5327 * Platform SDK Documentation -> User Interface Services ->
5328 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5329 * Edit Control Styles
5331 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5333 if (GWL_STYLE
== which
) {
5334 DWORD style_change_mask
;
5336 /* Only a subset of changes can be applied after the control
5339 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5341 if (es
->style
& ES_MULTILINE
)
5342 style_change_mask
|= ES_WANTRETURN
;
5344 new_style
= style
->styleNew
& style_change_mask
;
5346 /* Number overrides lowercase overrides uppercase (at least it
5347 * does in Win95). However I'll bet that ES_NUMBER would be
5348 * invalid under Win 3.1.
5350 if (new_style
& ES_NUMBER
) {
5351 ; /* do not override the ES_NUMBER */
5352 } else if (new_style
& ES_LOWERCASE
) {
5353 new_style
&= ~ES_UPPERCASE
;
5356 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5357 } else if (GWL_EXSTYLE
== which
) {
5358 ; /* FIXME - what is needed here */
5360 WARN ("Invalid style change %ld\n",which
);
5366 /*********************************************************************
5371 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5373 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5374 if (EDIT_EM_CanUndo(es
))
5377 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5378 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5381 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5385 /*********************************************************************
5390 static void EDIT_WM_Timer(EDITSTATE
*es
)
5392 if (es
->region_posx
< 0) {
5393 EDIT_MoveBackward(es
, TRUE
);
5394 } else if (es
->region_posx
> 0) {
5395 EDIT_MoveForward(es
, TRUE
);
5398 * FIXME: gotta do some vertical scrolling here, like
5399 * EDIT_EM_LineScroll(hwnd, 0, 1);
5403 /*********************************************************************
5408 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5412 if (!(es
->style
& ES_MULTILINE
))
5415 if (!(es
->style
& ES_AUTOVSCROLL
))
5424 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5425 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5426 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5428 EDIT_EM_Scroll(es
, action
);
5435 TRACE("SB_BOTTOM\n");
5436 dy
= es
->line_count
- 1 - es
->y_offset
;
5439 TRACE("SB_THUMBTRACK %d\n", pos
);
5440 es
->flags
|= EF_VSCROLL_TRACK
;
5441 if(es
->style
& WS_VSCROLL
)
5442 dy
= pos
- es
->y_offset
;
5445 /* Assume default scroll range 0-100 */
5448 if(pos
< 0 || pos
> 100) return 0;
5449 vlc
= get_vertical_line_count(es
);
5450 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5451 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5452 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5453 es
->line_count
, es
->y_offset
, pos
, dy
);
5456 case SB_THUMBPOSITION
:
5457 TRACE("SB_THUMBPOSITION %d\n", pos
);
5458 es
->flags
&= ~EF_VSCROLL_TRACK
;
5459 if(es
->style
& WS_VSCROLL
)
5460 dy
= pos
- es
->y_offset
;
5463 /* Assume default scroll range 0-100 */
5466 if(pos
< 0 || pos
> 100) return 0;
5467 vlc
= get_vertical_line_count(es
);
5468 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5469 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5470 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5471 es
->line_count
, es
->y_offset
, pos
, dy
);
5475 /* force scroll info update */
5476 EDIT_UpdateScrollInfo(es
);
5477 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5481 TRACE("SB_ENDSCROLL\n");
5484 * FIXME : the next two are undocumented !
5485 * Are we doing the right thing ?
5486 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5487 * although it's also a regular control message.
5489 case EM_GETTHUMB
: /* this one is used by NT notepad */
5495 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5496 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5499 /* Assume default scroll range 0-100 */
5500 INT vlc
= get_vertical_line_count(es
);
5501 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5503 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5507 case EM_LINESCROLL16
:
5508 TRACE("EM_LINESCROLL16 %d\n", pos
);
5514 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5519 EDIT_EM_LineScroll(es
, 0, dy
);
5523 /*********************************************************************
5528 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5530 if (es
->flags
& EF_UPDATE
) {
5531 es
->flags
&= ~EF_UPDATE
;
5532 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5534 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5538 /*********************************************************************
5543 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
5545 if (es
->flags
& EF_UPDATE
) {
5546 es
->flags
&= ~EF_UPDATE
;
5547 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5549 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5552 /********************************************************************
5554 * The Following code is to handle inline editing from IMEs
5557 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
5560 LPWSTR lpCompStr
= NULL
;
5561 LPSTR lpCompStrAttr
= NULL
;
5564 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5571 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
5574 ERR("Unable to allocate IME CompositionString\n");
5579 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
5580 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
5582 if (CompFlag
& GCS_COMPATTR
)
5585 * We do not use the attributes yet. it would tell us what characters
5586 * are in transition and which are converted or decided upon
5588 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5592 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5595 ERR("Unable to allocate IME Attribute String\n");
5596 HeapFree(GetProcessHeap(),0,lpCompStr
);
5599 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5601 lpCompStrAttr
[dwBufLenAttr
] = 0;
5604 lpCompStrAttr
= NULL
;
5607 /* check for change in composition start */
5608 if (es
->selection_end
< es
->composition_start
)
5609 es
->composition_start
= es
->selection_end
;
5611 /* replace existing selection string */
5612 es
->selection_start
= es
->composition_start
;
5614 if (es
->composition_len
> 0)
5615 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5617 es
->selection_end
= es
->selection_start
;
5619 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5620 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5622 es
->selection_start
= es
->composition_start
;
5623 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5625 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5626 HeapFree(GetProcessHeap(),0,lpCompStr
);
5629 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
5634 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5640 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
5643 ERR("Unable to alloc buffer for IME string\n");
5647 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
5648 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
5650 /* check for change in composition start */
5651 if (es
->selection_end
< es
->composition_start
)
5652 es
->composition_start
= es
->selection_end
;
5654 es
->selection_start
= es
->composition_start
;
5655 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5656 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5657 es
->composition_start
= es
->selection_end
;
5658 es
->composition_len
= 0;
5660 HeapFree(GetProcessHeap(),0,lpResultStr
);
5663 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5668 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
5670 static const WCHAR empty_stringW
[] = {0};
5671 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5672 es
->composition_start
= es
->selection_end
;
5675 hIMC
= ImmGetContext(hwnd
);
5679 if (CompFlag
& GCS_RESULTSTR
)
5680 EDIT_GetResultStr(hIMC
, es
);
5681 if (CompFlag
& GCS_COMPSTR
)
5682 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
5683 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
5684 ImmReleaseContext(hwnd
, hIMC
);
5685 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);