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
57 #include "wine/winbase16.h"
58 #include "wine/winuser16.h"
59 #include "wine/unicode.h"
61 #include "user_private.h"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
65 WINE_DECLARE_DEBUG_CHANNEL(combo
);
66 WINE_DECLARE_DEBUG_CHANNEL(relay
);
68 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
69 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
70 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
71 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
74 * extra flags for EDITSTATE.flags field
76 #define EF_MODIFIED 0x0001 /* text has been modified */
77 #define EF_FOCUSED 0x0002 /* we have input focus */
78 #define EF_UPDATE 0x0004 /* notify parent of changed state */
79 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
80 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
81 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
82 wrapped line, instead of in front of the next character */
83 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
84 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
85 the text buffer if this is clear. */
88 END_0
= 0, /* line ends with terminating '\0' character */
89 END_WRAP
, /* line is wrapped */
90 END_HARD
, /* line ends with a hard return '\r\n' */
91 END_SOFT
, /* line ends with a soft return '\r\r\n' */
92 END_RICH
/* line ends with a single '\n' */
95 typedef struct tagLINEDEF
{
96 INT length
; /* bruto length of a line in bytes */
97 INT net_length
; /* netto length of a line in visible characters */
99 INT width
; /* width of the line in pixels */
100 INT index
; /* line index into the buffer */
101 struct tagLINEDEF
*next
;
106 BOOL is_unicode
; /* how the control was created */
107 LPWSTR text
; /* the actual contents of the control */
108 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
109 UINT buffer_size
; /* the size of the buffer in characters */
110 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
111 HFONT font
; /* NULL means standard system font */
112 INT x_offset
; /* scroll offset for multi lines this is in pixels
113 for single lines it's in characters */
114 INT line_height
; /* height of a screen line in pixels */
115 INT char_width
; /* average character width in pixels */
116 DWORD style
; /* sane version of wnd->dwStyle */
117 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
118 INT undo_insert_count
; /* number of characters inserted in sequence */
119 UINT undo_position
; /* character index of the insertion and deletion */
120 LPWSTR undo_text
; /* deleted text */
121 UINT undo_buffer_size
; /* size of the deleted text buffer */
122 INT selection_start
; /* == selection_end if no selection */
123 INT selection_end
; /* == current caret position */
124 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
125 INT left_margin
; /* in pixels */
126 INT right_margin
; /* in pixels */
128 INT text_width
; /* width of the widest line in pixels for multi line controls
129 and just line width for single line controls */
130 INT region_posx
; /* Position of cursor relative to region: */
131 INT region_posy
; /* -1: to left, 0: within, 1: to right */
132 EDITWORDBREAKPROC16 word_break_proc16
;
133 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
134 INT line_count
; /* number of lines */
135 INT y_offset
; /* scroll offset in number of lines */
136 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
137 BOOL bEnableState
; /* flag keeping the enable state */
138 HWND hwndSelf
; /* the our window handle */
139 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
140 Even if parent will change, EN_* messages
141 should be sent to the first parent. */
142 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
144 * only for multi line controls
146 INT lock_count
; /* amount of re-entries in the EditWndProc */
149 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
150 HLOCAL hloc32W
; /* our unicode local memory block */
151 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
153 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
158 UINT composition_len
; /* length of composition, 0 == no composition */
159 int composition_start
; /* the character position for the composition */
163 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
164 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
166 /* used for disabled or read-only edit control */
167 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
169 { /* Notify parent which has created this edit control */ \
170 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
171 SendMessageW(es->hwndParent, WM_COMMAND, \
172 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
173 (LPARAM)(es->hwndSelf)); \
176 /*********************************************************************
183 * These functions have trivial implementations
184 * We still like to call them internally
185 * "static inline" makes them more like macro's
187 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
);
188 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
189 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
190 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
193 * Helper functions only valid for one type of control
195 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
196 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
197 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
198 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
199 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
200 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
201 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
203 * Helper functions valid for both single line _and_ multi line controls
205 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
206 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
207 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
);
208 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
209 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
210 static void EDIT_LockBuffer(EDITSTATE
*es
);
211 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
212 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
213 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
214 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
);
215 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
216 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
);
217 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
218 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
219 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
220 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
221 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
222 static void EDIT_AdjustFormatRect(EDITSTATE
*es
);
223 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*lprc
);
224 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
225 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
226 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
228 * EM_XXX message handlers
230 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
231 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
232 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
233 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
234 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
235 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
);
236 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
237 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
238 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
);
239 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
240 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
241 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
242 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
243 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
244 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
245 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
246 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
247 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
248 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
);
249 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, WORD left
, WORD right
, BOOL repaint
);
250 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
251 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
252 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
);
253 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
);
254 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
255 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
256 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
258 * WM_XXX message handlers
260 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
261 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
262 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
263 static void EDIT_WM_Copy(EDITSTATE
*es
);
264 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
265 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
266 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
267 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
268 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
269 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
270 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
271 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
272 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
273 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
274 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
275 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
276 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
277 static void EDIT_WM_Paste(EDITSTATE
*es
);
278 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
279 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
280 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
281 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
282 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
283 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
284 static void EDIT_WM_Timer(EDITSTATE
*es
);
285 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
286 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
);
287 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
288 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
);
290 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
291 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
293 /*********************************************************************
294 * edit class descriptor
296 static const WCHAR editW
[] = {'E','d','i','t',0};
297 const struct builtin_class_descr EDIT_builtin_class
=
300 CS_DBLCLKS
| CS_PARENTDC
, /* style */
301 EditWndProcA
, /* procA */
302 EditWndProcW
, /* procW */
303 sizeof(EDITSTATE
*), /* extra */
304 IDC_IBEAM
, /* cursor */
309 /*********************************************************************
314 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
316 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
320 /*********************************************************************
325 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
327 es
->undo_insert_count
= 0;
328 *es
->undo_text
= '\0';
332 /*********************************************************************
337 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
339 static const WCHAR empty_stringW
[] = {0};
341 /* Protect read-only edit control from modification */
342 if(es
->style
& ES_READONLY
)
345 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
349 /*********************************************************************
354 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
361 /**********************************************************************
364 * Returns the window version in case Wine emulates a later version
365 * of windows than the application expects.
367 * In a number of cases when windows runs an application that was
368 * designed for an earlier windows version, windows reverts
369 * to "old" behaviour of that earlier version.
371 * An example is a disabled edit control that needs to be painted.
372 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
373 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
374 * applications with an expected version 0f 4.0 or higher.
377 static DWORD
get_app_version(void)
379 static DWORD version
;
382 DWORD dwEmulatedVersion
;
384 DWORD dwProcVersion
= GetProcessVersion(0);
386 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
387 GetVersionExW( &info
);
388 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
389 /* FIXME: this may not be 100% correct; see discussion on the
390 * wine developer list in Nov 1999 */
391 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
396 static inline UINT
get_text_length(EDITSTATE
*es
)
398 if(es
->text_length
== (UINT
)-1)
399 es
->text_length
= strlenW(es
->text
);
400 return es
->text_length
;
403 static inline void text_buffer_changed(EDITSTATE
*es
)
405 es
->text_length
= (UINT
)-1;
408 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
413 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
414 msg
= WM_CTLCOLORSTATIC
;
416 msg
= WM_CTLCOLOREDIT
;
418 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
419 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
421 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
425 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
428 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
430 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
433 /*********************************************************************
437 * The messages are in the order of the actual integer values
438 * (which can be found in include/windows.h)
439 * Wherever possible the 16 bit versions are converted to
440 * the 32 bit ones, so that we can 'fall through' to the
441 * helper functions. These are mostly 32 bit (with a few
442 * exceptions, clearly indicated by a '16' extension to their
446 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
447 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
449 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
452 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
454 if (!es
&& msg
!= WM_NCCREATE
)
455 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
457 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
465 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
469 if ((short)LOWORD(lParam
) == -1)
470 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
472 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
474 EDIT_EM_ScrollCaret(es
);
478 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
479 EDIT_EM_ScrollCaret(es
);
486 RECT16
*r16
= MapSL(lParam
);
487 r16
->left
= es
->format_rect
.left
;
488 r16
->top
= es
->format_rect
.top
;
489 r16
->right
= es
->format_rect
.right
;
490 r16
->bottom
= es
->format_rect
.bottom
;
495 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
499 if ((es
->style
& ES_MULTILINE
) && lParam
) {
501 RECT16
*r16
= MapSL(lParam
);
504 rc
.right
= r16
->right
;
505 rc
.bottom
= r16
->bottom
;
506 EDIT_SetRectNP(es
, &rc
);
507 EDIT_UpdateText(es
, NULL
, TRUE
);
511 if ((es
->style
& ES_MULTILINE
) && lParam
) {
512 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
513 EDIT_UpdateText(es
, NULL
, TRUE
);
518 if ((es
->style
& ES_MULTILINE
) && lParam
) {
520 RECT16
*r16
= MapSL(lParam
);
523 rc
.right
= r16
->right
;
524 rc
.bottom
= r16
->bottom
;
525 EDIT_SetRectNP(es
, &rc
);
529 if ((es
->style
& ES_MULTILINE
) && lParam
)
530 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
535 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
538 case EM_LINESCROLL16
:
539 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
540 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
543 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
546 case EM_SCROLLCARET16
:
548 EDIT_EM_ScrollCaret(es
);
554 result
= ((es
->flags
& EF_MODIFIED
) != 0);
560 es
->flags
|= EF_MODIFIED
;
562 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
565 case EM_GETLINECOUNT16
:
566 case EM_GETLINECOUNT
:
567 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
571 if ((INT16
)wParam
== -1)
575 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
579 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
582 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
586 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
589 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
594 result
= EDIT_EM_GetThumb(es
);
597 /* these messages missing from specs */
606 FIXME("undocumented message 0x%x, please report\n", msg
);
607 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
610 case EM_LINELENGTH16
:
612 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
615 case EM_REPLACESEL16
:
616 lParam
= (LPARAM
)MapSL(lParam
);
617 unicode
= FALSE
; /* 16-bit message is always ascii */
624 textW
= (LPWSTR
)lParam
;
627 LPSTR textA
= (LPSTR
)lParam
;
628 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
629 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
630 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
633 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
637 HeapFree(GetProcessHeap(), 0, textW
);
642 lParam
= (LPARAM
)MapSL(lParam
);
643 unicode
= FALSE
; /* 16-bit message is always ascii */
646 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
650 case EM_SETLIMITTEXT
:
651 EDIT_EM_SetLimitText(es
, wParam
);
656 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
662 result
= (LRESULT
)EDIT_EM_Undo(es
);
667 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
670 case EM_LINEFROMCHAR16
:
671 case EM_LINEFROMCHAR
:
672 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
675 case EM_SETTABSTOPS16
:
676 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
679 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
682 case EM_SETPASSWORDCHAR16
:
683 unicode
= FALSE
; /* 16-bit message is always ascii */
685 case EM_SETPASSWORDCHAR
:
690 charW
= (WCHAR
)wParam
;
694 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
697 EDIT_EM_SetPasswordChar(es
, charW
);
701 case EM_EMPTYUNDOBUFFER16
:
702 case EM_EMPTYUNDOBUFFER
:
703 EDIT_EM_EmptyUndoBuffer(es
);
706 case EM_GETFIRSTVISIBLELINE16
:
707 result
= es
->y_offset
;
709 case EM_GETFIRSTVISIBLELINE
:
710 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
713 case EM_SETREADONLY16
:
716 SetWindowLongW( hwnd
, GWL_STYLE
,
717 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
718 es
->style
|= ES_READONLY
;
720 SetWindowLongW( hwnd
, GWL_STYLE
,
721 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
722 es
->style
&= ~ES_READONLY
;
727 case EM_SETWORDBREAKPROC16
:
728 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
730 case EM_SETWORDBREAKPROC
:
731 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
734 case EM_GETWORDBREAKPROC16
:
735 result
= (LRESULT
)es
->word_break_proc16
;
737 case EM_GETWORDBREAKPROC
:
738 result
= (LRESULT
)es
->word_break_proc
;
741 case EM_GETPASSWORDCHAR16
:
742 unicode
= FALSE
; /* 16-bit message is always ascii */
744 case EM_GETPASSWORDCHAR
:
747 result
= es
->password_char
;
750 WCHAR charW
= es
->password_char
;
752 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
758 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
761 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
765 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
768 case EM_GETLIMITTEXT
:
769 result
= es
->buffer_limit
;
773 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
774 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
778 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
781 /* End of the EM_ messages which were in numerical order; what order
782 * are these in? vaguely alphabetical?
786 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
790 result
= EDIT_WM_Destroy(es
);
795 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
797 if (es
->style
& ES_MULTILINE
)
798 result
|= DLGC_WANTALLKEYS
;
800 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
802 int vk
= (int)((LPMSG
)lParam
)->wParam
;
806 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
807 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
808 result
|= DLGC_WANTMESSAGE
;
815 SendMessageW(GetParent(hwnd
), WM_CLOSE
, 0, 0);
830 strng
[0] = wParam
>> 8;
831 strng
[1] = wParam
& 0xff;
832 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
833 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
834 result
= EDIT_WM_Char(es
, charW
);
847 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
852 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
854 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
855 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
859 result
= EDIT_WM_Char(es
, charW
);
868 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
872 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
881 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
884 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
888 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
889 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
890 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
892 result
= EDIT_WM_Create(es
, nameW
);
893 HeapFree(GetProcessHeap(), 0, nameW
);
902 es
->bEnableState
= (BOOL
) wParam
;
903 EDIT_UpdateText(es
, NULL
, TRUE
);
907 /* we do the proper erase in EDIT_WM_Paint */
912 result
= (LRESULT
)es
->font
;
916 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
919 case WM_GETTEXTLENGTH
:
920 if (unicode
) result
= get_text_length(es
);
921 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
922 NULL
, 0, NULL
, NULL
);
926 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
930 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
934 result
= EDIT_WM_KillFocus(es
);
937 case WM_LBUTTONDBLCLK
:
938 result
= EDIT_WM_LButtonDblClk(es
);
942 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
946 result
= EDIT_WM_LButtonUp(es
);
950 result
= EDIT_WM_MButtonDown(es
);
954 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
959 EDIT_WM_Paint(es
, (HDC
)wParam
);
967 EDIT_WM_SetFocus(es
);
971 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
975 /* FIXME: actually set an internal flag and behave accordingly */
979 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
984 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
987 case WM_STYLECHANGED
:
988 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
991 case WM_STYLECHANGING
:
992 result
= 0; /* See EDIT_WM_StyleChanged */
996 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
1004 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
1009 int gcWheelDelta
= 0;
1010 UINT pulScrollLines
= 3;
1011 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1013 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1014 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1017 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1018 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1020 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1021 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1022 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1028 /* IME messages to make the edit control IME aware */
1029 case WM_IME_SETCONTEXT
:
1032 case WM_IME_STARTCOMPOSITION
:
1033 es
->composition_start
= es
->selection_end
;
1034 es
->composition_len
= 0;
1037 case WM_IME_COMPOSITION
:
1038 EDIT_ImeComposition(hwnd
, lParam
, es
);
1041 case WM_IME_ENDCOMPOSITION
:
1042 if (es
->composition_len
> 0)
1044 static const WCHAR empty_stringW
[] = {0};
1045 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1046 es
->selection_end
= es
->selection_start
;
1047 es
->composition_len
= 0;
1051 case WM_IME_COMPOSITIONFULL
:
1057 case WM_IME_CONTROL
:
1061 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1065 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1067 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1072 /*********************************************************************
1074 * EditWndProcW (USER32.@)
1076 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1078 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1081 /*********************************************************************
1083 * EditWndProc (USER32.@)
1085 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1087 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1090 /*********************************************************************
1092 * EDIT_BuildLineDefs_ML
1094 * Build linked list of text lines.
1095 * Lines can end with '\0' (last line), a character (if it is wrapped),
1096 * a soft return '\r\r\n' or a hard return '\r\n'
1099 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1103 LPWSTR current_position
, cp
;
1105 LINEDEF
*current_line
;
1106 LINEDEF
*previous_line
;
1107 LINEDEF
*start_line
;
1108 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1109 INT line_count
= es
->line_count
;
1110 INT orig_net_length
;
1113 if (istart
== iend
&& delta
== 0)
1116 dc
= GetDC(es
->hwndSelf
);
1118 old_font
= SelectObject(dc
, es
->font
);
1120 previous_line
= NULL
;
1121 current_line
= es
->first_line_def
;
1123 /* Find starting line. istart must lie inside an existing line or
1124 * at the end of buffer */
1126 if (istart
< current_line
->index
+ current_line
->length
||
1127 current_line
->ending
== END_0
)
1130 previous_line
= current_line
;
1131 current_line
= current_line
->next
;
1133 } while (current_line
);
1135 if (!current_line
) /* Error occurred start is not inside previous buffer */
1137 FIXME(" modification occurred outside buffer\n");
1138 ReleaseDC(es
->hwndSelf
, dc
);
1142 /* Remember start of modifications in order to calculate update region */
1143 nstart_line
= line_index
;
1144 nstart_index
= current_line
->index
;
1146 /* We must start to reformat from the previous line since the modifications
1147 * may have caused the line to wrap upwards. */
1148 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1151 current_line
= previous_line
;
1153 start_line
= current_line
;
1155 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1156 current_position
= es
->text
+ current_line
->index
;
1158 if (current_line
!= start_line
)
1160 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1162 /* The buffer has been expanded, create a new line and
1163 insert it into the link list */
1164 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1165 new_line
->next
= previous_line
->next
;
1166 previous_line
->next
= new_line
;
1167 current_line
= new_line
;
1170 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1172 /* The previous line merged with this line so we delete this extra entry */
1173 previous_line
->next
= current_line
->next
;
1174 HeapFree(GetProcessHeap(), 0, current_line
);
1175 current_line
= previous_line
->next
;
1179 else /* current_line->index + delta == current_position */
1181 if (current_position
- es
->text
> iend
)
1182 break; /* We reached end of line modifications */
1183 /* else recalculate this line */
1187 current_line
->index
= current_position
- es
->text
;
1188 orig_net_length
= current_line
->net_length
;
1190 /* Find end of line */
1191 cp
= current_position
;
1193 if (*cp
== '\n') break;
1194 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1199 /* Mark type of line termination */
1201 current_line
->ending
= END_0
;
1202 current_line
->net_length
= strlenW(current_position
);
1203 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1204 current_line
->ending
= END_SOFT
;
1205 current_line
->net_length
= cp
- current_position
- 1;
1206 } else if (*cp
== '\n') {
1207 current_line
->ending
= END_RICH
;
1208 current_line
->net_length
= cp
- current_position
;
1210 current_line
->ending
= END_HARD
;
1211 current_line
->net_length
= cp
- current_position
;
1214 /* Calculate line width */
1215 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1216 current_position
, current_line
->net_length
,
1217 es
->tabs_count
, es
->tabs
));
1219 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1220 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1221 if (current_line
->width
> fw
) {
1226 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1227 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1228 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1229 current_position
, next
, es
->tabs_count
, es
->tabs
));
1230 } while (current_line
->width
<= fw
);
1231 if (!prev
) { /* Didn't find a line break so force a break */
1236 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1237 current_position
, next
, es
->tabs_count
, es
->tabs
));
1238 } while (current_line
->width
<= fw
);
1243 /* If the first line we are calculating, wrapped before istart, we must
1244 * adjust istart in order for this to be reflected in the update region. */
1245 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1246 istart
= current_line
->index
+ prev
;
1247 /* else if we are updating the previous line before the first line we
1248 * are re-calculating and it expanded */
1249 else if (current_line
== start_line
&&
1250 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1252 /* Line expanded due to an upwards line wrap so we must partially include
1253 * previous line in update region */
1254 nstart_line
= line_index
;
1255 nstart_index
= current_line
->index
;
1256 istart
= current_line
->index
+ orig_net_length
;
1259 current_line
->net_length
= prev
;
1260 current_line
->ending
= END_WRAP
;
1261 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1262 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1264 else if (current_line
== start_line
&&
1265 current_line
->index
!= nstart_index
&&
1266 orig_net_length
< current_line
->net_length
) {
1267 /* The previous line expanded but it's still not as wide as the client rect */
1268 /* The expansion is due to an upwards line wrap so we must partially include
1269 it in the update region */
1270 nstart_line
= line_index
;
1271 nstart_index
= current_line
->index
;
1272 istart
= current_line
->index
+ orig_net_length
;
1277 /* Adjust length to include line termination */
1278 switch (current_line
->ending
) {
1280 current_line
->length
= current_line
->net_length
+ 3;
1283 current_line
->length
= current_line
->net_length
+ 1;
1286 current_line
->length
= current_line
->net_length
+ 2;
1290 current_line
->length
= current_line
->net_length
;
1293 es
->text_width
= max(es
->text_width
, current_line
->width
);
1294 current_position
+= current_line
->length
;
1295 previous_line
= current_line
;
1296 current_line
= current_line
->next
;
1298 } while (previous_line
->ending
!= END_0
);
1300 /* Finish adjusting line indexes by delta or remove hanging lines */
1301 if (previous_line
->ending
== END_0
)
1303 LINEDEF
*pnext
= NULL
;
1305 previous_line
->next
= NULL
;
1306 while (current_line
)
1308 pnext
= current_line
->next
;
1309 HeapFree(GetProcessHeap(), 0, current_line
);
1310 current_line
= pnext
;
1314 else if (delta
!= 0)
1316 while (current_line
)
1318 current_line
->index
+= delta
;
1319 current_line
= current_line
->next
;
1323 /* Calculate rest of modification rectangle */
1328 * We calculate two rectangles. One for the first line which may have
1329 * an indent with respect to the format rect. The other is a format-width
1330 * rectangle that spans the rest of the lines that changed or moved.
1332 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1333 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1334 rc
.bottom
= rc
.top
+ es
->line_height
;
1335 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1336 rc
.left
= es
->format_rect
.left
;
1338 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1339 es
->text
+ nstart_index
, istart
- nstart_index
,
1340 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1341 rc
.right
= es
->format_rect
.right
;
1342 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1345 rc
.left
= es
->format_rect
.left
;
1346 rc
.right
= es
->format_rect
.right
;
1348 * If lines were added or removed we must re-paint the remainder of the
1349 * lines since the remaining lines were either shifted up or down.
1351 if (line_count
< es
->line_count
) /* We added lines */
1352 rc
.bottom
= es
->line_count
* es
->line_height
;
1353 else if (line_count
> es
->line_count
) /* We removed lines */
1354 rc
.bottom
= line_count
* es
->line_height
;
1356 rc
.bottom
= line_index
* es
->line_height
;
1357 rc
.bottom
+= es
->format_rect
.top
;
1358 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1359 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1360 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1361 DeleteObject(tmphrgn
);
1365 SelectObject(dc
, old_font
);
1367 ReleaseDC(es
->hwndSelf
, dc
);
1370 /*********************************************************************
1372 * EDIT_CalcLineWidth_SL
1375 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1382 text
= EDIT_GetPasswordPointer_SL(es
);
1384 dc
= GetDC(es
->hwndSelf
);
1386 old_font
= SelectObject(dc
, es
->font
);
1388 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1391 SelectObject(dc
, old_font
);
1392 ReleaseDC(es
->hwndSelf
, dc
);
1394 if (es
->style
& ES_PASSWORD
)
1395 HeapFree(GetProcessHeap(), 0, text
);
1397 es
->text_width
= size
.cx
;
1400 /*********************************************************************
1402 * EDIT_CallWordBreakProc
1404 * Call appropriate WordBreakProc (internal or external).
1406 * Note: The "start" argument should always be an index referring
1407 * to es->text. The actual wordbreak proc might be
1408 * 16 bit, so we can't always pass any 32 bit LPSTR.
1409 * Hence we assume that es->text is the buffer that holds
1410 * the string under examination (we can decide this for ourselves).
1413 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1417 if (es
->word_break_proc16
) {
1424 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1425 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1426 segptr
= WOWGlobalLock16(hglob16
);
1427 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1428 args
[4] = SELECTOROF(segptr
);
1429 args
[3] = OFFSETOF(segptr
);
1433 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1434 ret
= LOWORD(result
);
1435 GlobalUnlock16(hglob16
);
1436 GlobalFree16(hglob16
);
1438 else if (es
->word_break_proc
)
1442 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1444 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1445 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1446 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1450 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1454 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1455 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1456 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1457 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1458 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1459 ret
= wbpA(textA
, index
, countA
, action
);
1460 HeapFree(GetProcessHeap(), 0, textA
);
1464 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1470 /*********************************************************************
1474 * Beware: This is not the function called on EM_CHARFROMPOS
1475 * The position _can_ be outside the formatting / client
1477 * The return value is only the character index
1480 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1485 INT x_high
= 0, x_low
= 0;
1487 if (es
->style
& ES_MULTILINE
) {
1488 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1490 LINEDEF
*line_def
= es
->first_line_def
;
1492 while ((line
> 0) && line_def
->next
) {
1493 line_index
+= line_def
->length
;
1494 line_def
= line_def
->next
;
1497 x
+= es
->x_offset
- es
->format_rect
.left
;
1498 if (es
->style
& ES_RIGHT
)
1499 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1500 else if (es
->style
& ES_CENTER
)
1501 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1502 if (x
>= line_def
->width
) {
1504 *after_wrap
= (line_def
->ending
== END_WRAP
);
1505 return line_index
+ line_def
->net_length
;
1509 *after_wrap
= FALSE
;
1512 dc
= GetDC(es
->hwndSelf
);
1514 old_font
= SelectObject(dc
, es
->font
);
1516 high
= line_index
+ line_def
->net_length
+ 1;
1517 while (low
< high
- 1)
1519 INT mid
= (low
+ high
) / 2;
1520 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1529 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1535 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1536 (line_def
->ending
== END_WRAP
));
1541 *after_wrap
= FALSE
;
1542 x
-= es
->format_rect
.left
;
1544 return es
->x_offset
;
1548 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1549 if (es
->style
& ES_RIGHT
)
1551 else if (es
->style
& ES_CENTER
)
1555 text
= EDIT_GetPasswordPointer_SL(es
);
1556 dc
= GetDC(es
->hwndSelf
);
1558 old_font
= SelectObject(dc
, es
->font
);
1562 INT high
= es
->x_offset
;
1563 while (low
< high
- 1)
1565 INT mid
= (low
+ high
) / 2;
1566 GetTextExtentPoint32W( dc
, text
+ mid
,
1567 es
->x_offset
- mid
, &size
);
1576 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1583 INT low
= es
->x_offset
;
1584 INT high
= get_text_length(es
) + 1;
1585 while (low
< high
- 1)
1587 INT mid
= (low
+ high
) / 2;
1588 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1589 mid
- es
->x_offset
, &size
);
1598 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1603 if (es
->style
& ES_PASSWORD
)
1604 HeapFree(GetProcessHeap(), 0, text
);
1607 SelectObject(dc
, old_font
);
1608 ReleaseDC(es
->hwndSelf
, dc
);
1613 /*********************************************************************
1617 * adjusts the point to be within the formatting rectangle
1618 * (so CharFromPos returns the nearest _visible_ character)
1621 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
1623 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1624 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1628 /*********************************************************************
1632 * Calculates the bounding rectangle for a line from a starting
1633 * column to an ending column.
1636 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1638 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1640 if (es
->style
& ES_MULTILINE
)
1641 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1643 rc
->top
= es
->format_rect
.top
;
1644 rc
->bottom
= rc
->top
+ es
->line_height
;
1645 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1646 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1650 /*********************************************************************
1652 * EDIT_GetPasswordPointer_SL
1654 * note: caller should free the (optionally) allocated buffer
1657 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1659 if (es
->style
& ES_PASSWORD
) {
1660 INT len
= get_text_length(es
);
1661 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1663 while(len
) text
[--len
] = es
->password_char
;
1670 /*********************************************************************
1674 * This acts as a LocalLock16(), but it locks only once. This way
1675 * you can call it whenever you like, without unlocking.
1677 * Initially the edit control allocates a HLOCAL32 buffer
1678 * (32 bit linear memory handler). However, 16 bit application
1679 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1680 * handler). From that moment on we have to keep using this 16 bit memory
1681 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1682 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1686 static void EDIT_LockBuffer(EDITSTATE
*es
)
1688 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1689 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1694 BOOL _16bit
= FALSE
;
1700 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1701 textA
= LocalLock(es
->hloc32A
);
1702 countA
= strlen(textA
) + 1;
1706 HANDLE16 oldDS
= stack16
->ds
;
1707 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1708 stack16
->ds
= hInstance
;
1709 textA
= MapSL(LocalLock16(es
->hloc16
));
1710 stack16
->ds
= oldDS
;
1711 countA
= strlen(textA
) + 1;
1716 ERR("no buffer ... please report\n");
1723 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1724 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1725 if(countW_new
> es
->buffer_size
+ 1)
1727 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1728 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1729 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1732 es
->hloc32W
= hloc32W_new
;
1733 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1734 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1737 WARN("FAILED! Will synchronize partially\n");
1741 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1742 es
->text
= LocalLock(es
->hloc32W
);
1746 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1749 HANDLE16 oldDS
= stack16
->ds
;
1750 stack16
->ds
= hInstance
;
1751 LocalUnlock16(es
->hloc16
);
1752 stack16
->ds
= oldDS
;
1755 LocalUnlock(es
->hloc32A
);
1758 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1763 /*********************************************************************
1765 * EDIT_SL_InvalidateText
1767 * Called from EDIT_InvalidateText().
1768 * Does the job for single-line controls only.
1771 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1776 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1777 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1778 EDIT_UpdateText(es
, &rc
, TRUE
);
1782 /*********************************************************************
1784 * EDIT_ML_InvalidateText
1786 * Called from EDIT_InvalidateText().
1787 * Does the job for multi-line controls only.
1790 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1792 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1793 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1794 INT el
= EDIT_EM_LineFromChar(es
, end
);
1803 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1806 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1807 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1808 if (sl
< es
->y_offset
) {
1812 if (el
> es
->y_offset
+ vlc
) {
1813 el
= es
->y_offset
+ vlc
;
1814 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1816 GetClientRect(es
->hwndSelf
, &rc1
);
1817 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1819 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1820 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1821 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1823 EDIT_GetLineRect(es
, sl
, sc
,
1824 EDIT_EM_LineLength(es
,
1825 EDIT_EM_LineIndex(es
, sl
)),
1827 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1828 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1829 for (l
= sl
+ 1 ; l
< el
; l
++) {
1830 EDIT_GetLineRect(es
, l
, 0,
1831 EDIT_EM_LineLength(es
,
1832 EDIT_EM_LineIndex(es
, l
)),
1834 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1835 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1837 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1838 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1839 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1844 /*********************************************************************
1846 * EDIT_InvalidateText
1848 * Invalidate the text from offset start up to, but not including,
1849 * offset end. Useful for (re)painting the selection.
1850 * Regions outside the linewidth are not invalidated.
1851 * end == -1 means end == TextLength.
1852 * start and end need not be ordered.
1855 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1861 end
= get_text_length(es
);
1869 if (es
->style
& ES_MULTILINE
)
1870 EDIT_ML_InvalidateText(es
, start
, end
);
1872 EDIT_SL_InvalidateText(es
, start
, end
);
1876 /*********************************************************************
1880 * Try to fit size + 1 characters in the buffer.
1882 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1886 if (size
<= es
->buffer_size
)
1889 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1891 /* Force edit to unlock it's buffer. es->text now NULL */
1892 EDIT_UnlockBuffer(es
, TRUE
);
1895 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1896 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1897 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1898 es
->hloc32W
= hNew32W
;
1899 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1903 EDIT_LockBuffer(es
);
1905 if (es
->buffer_size
< size
) {
1906 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1907 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1910 TRACE("We now have %d+1\n", es
->buffer_size
);
1916 /*********************************************************************
1920 * Try to fit size + 1 bytes in the undo buffer.
1923 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1927 if (size
<= es
->undo_buffer_size
)
1930 TRACE("trying to ReAlloc to %d+1\n", size
);
1932 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1933 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1934 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1939 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1945 /*********************************************************************
1950 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1952 INT e
= es
->selection_end
;
1956 if ((es
->style
& ES_MULTILINE
) && e
&&
1957 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1959 if (e
&& (es
->text
[e
- 1] == '\r'))
1963 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1964 EDIT_EM_ScrollCaret(es
);
1968 /*********************************************************************
1972 * Only for multi line controls
1973 * Move the caret one line down, on a column with the nearest
1974 * x coordinate on the screen (might be a different column).
1977 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1979 INT s
= es
->selection_start
;
1980 INT e
= es
->selection_end
;
1981 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1982 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1983 INT x
= (short)LOWORD(pos
);
1984 INT y
= (short)HIWORD(pos
);
1986 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1989 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1990 EDIT_EM_ScrollCaret(es
);
1994 /*********************************************************************
1999 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
2001 BOOL after_wrap
= FALSE
;
2004 /* Pass a high value in x to make sure of receiving the end of the line */
2005 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
2006 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2007 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2009 e
= get_text_length(es
);
2010 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2011 EDIT_EM_ScrollCaret(es
);
2015 /*********************************************************************
2020 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2022 INT e
= es
->selection_end
;
2026 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2027 if (es
->text
[e
] == '\n')
2029 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2033 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2034 EDIT_EM_ScrollCaret(es
);
2038 /*********************************************************************
2042 * Home key: move to beginning of line.
2045 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
2049 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2050 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
2051 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2052 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2055 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2056 EDIT_EM_ScrollCaret(es
);
2060 /*********************************************************************
2062 * EDIT_MovePageDown_ML
2064 * Only for multi line controls
2065 * Move the caret one page down, on a column with the nearest
2066 * x coordinate on the screen (might be a different column).
2069 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2071 INT s
= es
->selection_start
;
2072 INT e
= es
->selection_end
;
2073 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2074 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2075 INT x
= (short)LOWORD(pos
);
2076 INT y
= (short)HIWORD(pos
);
2078 e
= EDIT_CharFromPos(es
, x
,
2079 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2083 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2084 EDIT_EM_ScrollCaret(es
);
2088 /*********************************************************************
2090 * EDIT_MovePageUp_ML
2092 * Only for multi line controls
2093 * Move the caret one page up, on a column with the nearest
2094 * x coordinate on the screen (might be a different column).
2097 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2099 INT s
= es
->selection_start
;
2100 INT e
= es
->selection_end
;
2101 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2102 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2103 INT x
= (short)LOWORD(pos
);
2104 INT y
= (short)HIWORD(pos
);
2106 e
= EDIT_CharFromPos(es
, x
,
2107 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2111 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2112 EDIT_EM_ScrollCaret(es
);
2116 /*********************************************************************
2120 * Only for multi line controls
2121 * Move the caret one line up, on a column with the nearest
2122 * x coordinate on the screen (might be a different column).
2125 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2127 INT s
= es
->selection_start
;
2128 INT e
= es
->selection_end
;
2129 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2130 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2131 INT x
= (short)LOWORD(pos
);
2132 INT y
= (short)HIWORD(pos
);
2134 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2137 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2138 EDIT_EM_ScrollCaret(es
);
2142 /*********************************************************************
2144 * EDIT_MoveWordBackward
2147 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2149 INT s
= es
->selection_start
;
2150 INT e
= es
->selection_end
;
2155 l
= EDIT_EM_LineFromChar(es
, e
);
2156 ll
= EDIT_EM_LineLength(es
, e
);
2157 li
= EDIT_EM_LineIndex(es
, l
);
2160 li
= EDIT_EM_LineIndex(es
, l
- 1);
2161 e
= li
+ EDIT_EM_LineLength(es
, li
);
2164 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2168 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2169 EDIT_EM_ScrollCaret(es
);
2173 /*********************************************************************
2175 * EDIT_MoveWordForward
2178 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2180 INT s
= es
->selection_start
;
2181 INT e
= es
->selection_end
;
2186 l
= EDIT_EM_LineFromChar(es
, e
);
2187 ll
= EDIT_EM_LineLength(es
, e
);
2188 li
= EDIT_EM_LineIndex(es
, l
);
2190 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2191 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2193 e
= li
+ EDIT_CallWordBreakProc(es
,
2194 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2198 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2199 EDIT_EM_ScrollCaret(es
);
2203 /*********************************************************************
2208 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2210 INT s
= es
->selection_start
;
2211 INT e
= es
->selection_end
;
2218 if (es
->style
& ES_MULTILINE
) {
2219 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2220 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2225 TRACE("line=%d\n", line
);
2227 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2228 x
= (short)LOWORD(pos
);
2229 y
= (short)HIWORD(pos
);
2230 li
= EDIT_EM_LineIndex(es
, line
);
2231 ll
= EDIT_EM_LineLength(es
, li
);
2232 s
= min(es
->selection_start
, es
->selection_end
);
2233 e
= max(es
->selection_start
, es
->selection_end
);
2234 s
= min(li
+ ll
, max(li
, s
));
2235 e
= min(li
+ ll
, max(li
, e
));
2236 if (rev
&& (s
!= e
) &&
2237 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2238 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2239 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2240 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2242 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2246 /*********************************************************************
2251 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2255 LOGFONTW underline_font
;
2256 HFONT hUnderline
= 0;
2265 BkMode
= GetBkMode(dc
);
2266 BkColor
= GetBkColor(dc
);
2267 TextColor
= GetTextColor(dc
);
2269 if (es
->composition_len
== 0)
2271 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2272 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2273 SetBkMode( dc
, OPAQUE
);
2277 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2278 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2279 underline_font
.lfUnderline
= TRUE
;
2280 hUnderline
= CreateFontIndirectW(&underline_font
);
2281 old_font
= SelectObject(dc
,hUnderline
);
2284 li
= EDIT_EM_LineIndex(es
, line
);
2285 if (es
->style
& ES_MULTILINE
) {
2286 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2287 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2289 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2290 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2291 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2293 if (es
->style
& ES_PASSWORD
)
2294 HeapFree(GetProcessHeap(), 0, text
);
2297 if (es
->composition_len
== 0)
2299 SetBkColor(dc
, BkColor
);
2300 SetTextColor(dc
, TextColor
);
2301 SetBkMode( dc
, BkMode
);
2306 SelectObject(dc
,old_font
);
2308 DeleteObject(hUnderline
);
2315 /*********************************************************************
2320 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2323 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2324 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2325 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2329 /*********************************************************************
2331 * EDIT_AdjustFormatRect
2333 * Adjusts the format rectangle for the current font and the
2334 * current client rectangle.
2337 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2341 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2342 if (es
->style
& ES_MULTILINE
)
2344 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2346 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2347 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2349 /* correct es->x_offset */
2350 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2351 max_x_offset
= es
->text_width
- fw
;
2352 if(max_x_offset
< 0) max_x_offset
= 0;
2353 if(es
->x_offset
> max_x_offset
)
2354 es
->x_offset
= max_x_offset
;
2356 /* correct es->y_offset */
2357 max_y_offset
= es
->line_count
- vlc
;
2358 if(max_y_offset
< 0) max_y_offset
= 0;
2359 if(es
->y_offset
> max_y_offset
)
2360 es
->y_offset
= max_y_offset
;
2362 /* force scroll info update */
2363 EDIT_UpdateScrollInfo(es
);
2366 /* Windows doesn't care to fix text placement for SL controls */
2367 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2369 /* Always stay within the client area */
2370 GetClientRect(es
->hwndSelf
, &ClientRect
);
2371 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2373 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2374 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2376 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2380 /*********************************************************************
2384 * note: this is not (exactly) the handler called on EM_SETRECTNP
2385 * it is also used to set the rect of a single line control
2388 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2392 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2394 CopyRect(&es
->format_rect
, rc
);
2396 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2397 es
->format_rect
.left
++;
2398 es
->format_rect
.right
--;
2400 if (es
->format_rect
.bottom
- es
->format_rect
.top
2401 >= es
->line_height
+ 2)
2403 es
->format_rect
.top
++;
2404 es
->format_rect
.bottom
--;
2407 else if (es
->style
& WS_BORDER
) {
2408 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2409 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2410 es
->format_rect
.left
+= bw
;
2411 es
->format_rect
.right
-= bw
;
2412 if (es
->format_rect
.bottom
- es
->format_rect
.top
2413 >= es
->line_height
+ 2 * bh
)
2415 es
->format_rect
.top
+= bh
;
2416 es
->format_rect
.bottom
-= bh
;
2420 es
->format_rect
.left
+= es
->left_margin
;
2421 es
->format_rect
.right
-= es
->right_margin
;
2422 EDIT_AdjustFormatRect(es
);
2426 /*********************************************************************
2431 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2434 /* Edit window might be already destroyed */
2435 if(!IsWindow(es
->hwndSelf
))
2437 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2441 if (!es
->lock_count
) {
2442 ERR("lock_count == 0 ... please report\n");
2446 ERR("es->text == 0 ... please report\n");
2450 if (force
|| (es
->lock_count
== 1)) {
2454 UINT countW
= get_text_length(es
) + 1;
2455 STACK16FRAME
* stack16
= NULL
;
2460 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2461 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2462 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2463 countA
= LocalSize(es
->hloc32A
);
2464 if(countA_new
> countA
)
2467 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2468 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2469 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2472 es
->hloc32A
= hloc32A_new
;
2473 countA
= LocalSize(hloc32A_new
);
2474 TRACE("Real new size %d bytes\n", countA
);
2477 WARN("FAILED! Will synchronize partially\n");
2479 textA
= LocalLock(es
->hloc32A
);
2483 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2485 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2486 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2488 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2489 oldDS
= stack16
->ds
;
2490 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2492 countA
= LocalSize16(es
->hloc16
);
2493 if(countA_new
> countA
)
2495 HLOCAL16 hloc16_new
;
2496 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2497 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2498 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2501 es
->hloc16
= hloc16_new
;
2502 countA
= LocalSize16(hloc16_new
);
2503 TRACE("Real new size %d bytes\n", countA
);
2506 WARN("FAILED! Will synchronize partially\n");
2508 textA
= MapSL(LocalLock16(es
->hloc16
));
2513 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2515 LocalUnlock16(es
->hloc16
);
2517 LocalUnlock(es
->hloc32A
);
2520 if (stack16
) stack16
->ds
= oldDS
;
2521 LocalUnlock(es
->hloc32W
);
2525 ERR("no buffer ... please report\n");
2533 /*********************************************************************
2535 * EDIT_UpdateScrollInfo
2538 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2540 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2543 si
.cbSize
= sizeof(SCROLLINFO
);
2544 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2546 si
.nMax
= es
->line_count
- 1;
2547 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2548 si
.nPos
= es
->y_offset
;
2549 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2550 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2551 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2554 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2557 si
.cbSize
= sizeof(SCROLLINFO
);
2558 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2560 si
.nMax
= es
->text_width
- 1;
2561 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2562 si
.nPos
= es
->x_offset
;
2563 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2564 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2565 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2569 /*********************************************************************
2571 * EDIT_WordBreakProc
2573 * Find the beginning of words.
2574 * Note: unlike the specs for a WordBreakProc, this function only
2575 * allows to be called without linebreaks between s[0] up to
2576 * s[count - 1]. Remember it is only called
2577 * internally, so we can decide this for ourselves.
2580 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2584 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2594 if (s
[index
] == ' ') {
2595 while (index
&& (s
[index
] == ' '))
2598 while (index
&& (s
[index
] != ' '))
2600 if (s
[index
] == ' ')
2604 while (index
&& (s
[index
] != ' '))
2606 if (s
[index
] == ' ')
2616 if (s
[index
] == ' ')
2617 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2619 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2621 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2625 case WB_ISDELIMITER
:
2626 ret
= (s
[index
] == ' ');
2629 ERR("unknown action code, please report !\n");
2636 /*********************************************************************
2640 * returns line number (not index) in high-order word of result.
2641 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2642 * to Richedit, not to the edit control. Original documentation is valid.
2643 * FIXME: do the specs mean to return -1 if outside client area or
2644 * if outside formatting rectangle ???
2647 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2655 GetClientRect(es
->hwndSelf
, &rc
);
2656 if (!PtInRect(&rc
, pt
))
2659 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2660 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2664 /*********************************************************************
2668 * Enable or disable soft breaks.
2670 * This means: insert or remove the soft linebreak character (\r\r\n).
2671 * Take care to check if the text still fits the buffer after insertion.
2672 * If not, notify with EN_ERRSPACE.
2675 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2677 es
->flags
&= ~EF_USE_SOFTBRK
;
2679 es
->flags
|= EF_USE_SOFTBRK
;
2680 FIXME("soft break enabled, not implemented\n");
2686 /*********************************************************************
2690 * Hopefully this won't fire back at us.
2691 * We always start with a fixed buffer in the local heap.
2692 * Despite of the documentation says that the local heap is used
2693 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2694 * buffer on the local heap.
2697 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2701 if (!(es
->style
& ES_MULTILINE
))
2705 hLocal
= es
->hloc32W
;
2711 UINT countA
, alloc_size
;
2712 TRACE("Allocating 32-bit ANSI alias buffer\n");
2713 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2714 alloc_size
= ROUND_TO_GROW(countA
);
2715 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2717 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2720 textA
= LocalLock(es
->hloc32A
);
2721 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2722 LocalUnlock(es
->hloc32A
);
2724 hLocal
= es
->hloc32A
;
2727 es
->flags
|= EF_APP_HAS_HANDLE
;
2728 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2733 /*********************************************************************
2737 * Hopefully this won't fire back at us.
2738 * We always start with a buffer in 32 bit linear memory.
2739 * However, with this message a 16 bit application requests
2740 * a handle of 16 bit local heap memory, where it expects to find
2742 * It's a pitty that from this moment on we have to use this
2743 * local heap, because applications may rely on the handle
2746 * In this function we'll try to switch to local heap.
2748 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2751 UINT countA
, alloc_size
;
2752 STACK16FRAME
* stack16
;
2755 if (!(es
->style
& ES_MULTILINE
))
2761 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2762 oldDS
= stack16
->ds
;
2763 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2765 if (!LocalHeapSize16()) {
2767 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2768 ERR("could not initialize local heap\n");
2771 TRACE("local heap initialized\n");
2774 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2775 alloc_size
= ROUND_TO_GROW(countA
);
2777 TRACE("Allocating 16-bit ANSI alias buffer\n");
2778 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2779 ERR("could not allocate new 16 bit buffer\n");
2783 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2784 ERR("could not lock new 16 bit buffer\n");
2785 LocalFree16(es
->hloc16
);
2790 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2791 LocalUnlock16(es
->hloc16
);
2792 es
->flags
|= EF_APP_HAS_HANDLE
;
2794 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2797 stack16
->ds
= oldDS
;
2802 /*********************************************************************
2807 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2810 INT line_len
, dst_len
;
2813 if (es
->style
& ES_MULTILINE
) {
2814 if (line
>= es
->line_count
)
2818 i
= EDIT_EM_LineIndex(es
, line
);
2820 line_len
= EDIT_EM_LineLength(es
, i
);
2821 dst_len
= *(WORD
*)dst
;
2824 if(dst_len
<= line_len
)
2826 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2829 else /* Append 0 if enough space */
2831 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2838 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2839 if(!ret
&& line_len
) /* Insufficient buffer size */
2841 if(ret
< dst_len
) /* Append 0 if enough space */
2842 ((LPSTR
)dst
)[ret
] = 0;
2848 /*********************************************************************
2853 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2855 UINT s
= es
->selection_start
;
2856 UINT e
= es
->selection_end
;
2863 return MAKELONG(s
, e
);
2867 /*********************************************************************
2871 * FIXME: is this right ? (or should it be only VSCROLL)
2872 * (and maybe only for edit controls that really have their
2873 * own scrollbars) (and maybe only for multiline controls ?)
2874 * All in all: very poorly documented
2877 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2879 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2880 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2884 /*********************************************************************
2889 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2894 if (!(es
->style
& ES_MULTILINE
))
2896 if (index
> (INT
)get_text_length(es
))
2897 return es
->line_count
- 1;
2899 index
= min(es
->selection_start
, es
->selection_end
);
2902 line_def
= es
->first_line_def
;
2903 index
-= line_def
->length
;
2904 while ((index
>= 0) && line_def
->next
) {
2906 line_def
= line_def
->next
;
2907 index
-= line_def
->length
;
2913 /*********************************************************************
2918 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
2921 const LINEDEF
*line_def
;
2923 if (!(es
->style
& ES_MULTILINE
))
2925 if (line
>= es
->line_count
)
2929 line_def
= es
->first_line_def
;
2931 INT index
= es
->selection_end
- line_def
->length
;
2932 while ((index
>= 0) && line_def
->next
) {
2933 line_index
+= line_def
->length
;
2934 line_def
= line_def
->next
;
2935 index
-= line_def
->length
;
2939 line_index
+= line_def
->length
;
2940 line_def
= line_def
->next
;
2948 /*********************************************************************
2953 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2957 if (!(es
->style
& ES_MULTILINE
))
2958 return get_text_length(es
);
2961 /* get the number of remaining non-selected chars of selected lines */
2962 INT32 l
; /* line number */
2963 INT32 li
; /* index of first char in line */
2965 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2966 /* # chars before start of selection area */
2967 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2968 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2969 /* # chars after end of selection */
2970 li
= EDIT_EM_LineIndex(es
, l
);
2971 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2974 line_def
= es
->first_line_def
;
2975 index
-= line_def
->length
;
2976 while ((index
>= 0) && line_def
->next
) {
2977 line_def
= line_def
->next
;
2978 index
-= line_def
->length
;
2980 return line_def
->net_length
;
2984 /*********************************************************************
2988 * NOTE: dx is in average character widths, dy - in lines;
2991 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2993 if (!(es
->style
& ES_MULTILINE
))
2996 dx
*= es
->char_width
;
2997 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3000 /*********************************************************************
3002 * EDIT_EM_LineScroll_internal
3004 * Version of EDIT_EM_LineScroll for internal use.
3005 * It doesn't refuse if ES_MULTILINE is set and assumes that
3006 * dx is in pixels, dy - in lines.
3009 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3012 INT x_offset_in_pixels
;
3013 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3016 if (es
->style
& ES_MULTILINE
)
3018 x_offset_in_pixels
= es
->x_offset
;
3023 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3026 if (-dx
> x_offset_in_pixels
)
3027 dx
= -x_offset_in_pixels
;
3028 if (dx
> es
->text_width
- x_offset_in_pixels
)
3029 dx
= es
->text_width
- x_offset_in_pixels
;
3030 nyoff
= max(0, es
->y_offset
+ dy
);
3031 if (nyoff
>= es
->line_count
- lines_per_page
)
3032 nyoff
= max(0, es
->line_count
- lines_per_page
);
3033 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3038 es
->y_offset
= nyoff
;
3039 if(es
->style
& ES_MULTILINE
)
3042 es
->x_offset
+= dx
/ es
->char_width
;
3044 GetClientRect(es
->hwndSelf
, &rc1
);
3045 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3046 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3047 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3048 /* force scroll info update */
3049 EDIT_UpdateScrollInfo(es
);
3051 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3052 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3053 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3054 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3059 /*********************************************************************
3064 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3066 INT len
= get_text_length(es
);
3079 index
= min(index
, len
);
3080 dc
= GetDC(es
->hwndSelf
);
3082 old_font
= SelectObject(dc
, es
->font
);
3083 if (es
->style
& ES_MULTILINE
) {
3084 l
= EDIT_EM_LineFromChar(es
, index
);
3085 y
= (l
- es
->y_offset
) * es
->line_height
;
3086 li
= EDIT_EM_LineIndex(es
, l
);
3087 if (after_wrap
&& (li
== index
) && l
) {
3089 line_def
= es
->first_line_def
;
3091 line_def
= line_def
->next
;
3094 if (line_def
->ending
== END_WRAP
) {
3096 y
-= es
->line_height
;
3097 li
= EDIT_EM_LineIndex(es
, l
);
3101 line_def
= es
->first_line_def
;
3102 while (line_def
->index
!= li
)
3103 line_def
= line_def
->next
;
3105 ll
= line_def
->net_length
;
3106 lw
= line_def
->width
;
3108 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3109 if (es
->style
& ES_RIGHT
)
3111 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3112 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3115 else if (es
->style
& ES_CENTER
)
3117 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3118 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3123 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3124 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3127 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3128 if (index
< es
->x_offset
) {
3129 GetTextExtentPoint32W(dc
, text
+ index
,
3130 es
->x_offset
- index
, &size
);
3133 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3134 index
- es
->x_offset
, &size
);
3137 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3139 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3140 if (w
> es
->text_width
)
3142 if (es
->style
& ES_RIGHT
)
3143 x
+= w
- es
->text_width
;
3144 else if (es
->style
& ES_CENTER
)
3145 x
+= (w
- es
->text_width
) / 2;
3150 if (es
->style
& ES_PASSWORD
)
3151 HeapFree(GetProcessHeap(), 0, text
);
3153 x
+= es
->format_rect
.left
;
3154 y
+= es
->format_rect
.top
;
3156 SelectObject(dc
, old_font
);
3157 ReleaseDC(es
->hwndSelf
, dc
);
3158 return MAKELONG((INT16
)x
, (INT16
)y
);
3162 /*********************************************************************
3166 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3169 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3171 UINT strl
= strlenW(lpsz_replace
);
3172 UINT tl
= get_text_length(es
);
3183 TRACE("%s, can_undo %d, send_update %d\n",
3184 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3186 s
= es
->selection_start
;
3187 e
= es
->selection_end
;
3189 if ((s
== e
) && !strl
)
3194 size
= tl
- (e
- s
) + strl
;
3198 /* Issue the EN_MAXTEXT notification and continue with replacing text
3199 * such that buffer limit is honored. */
3200 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
3201 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3202 /* Buffer limit can be smaller than the actual length of text in combobox */
3203 if (es
->buffer_limit
< (tl
- (e
-s
)))
3206 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3209 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3213 /* there is something to be deleted */
3214 TRACE("deleting stuff.\n");
3216 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3218 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3219 buf
[bufl
] = 0; /* ensure 0 termination */
3221 strcpyW(es
->text
+ s
, es
->text
+ e
);
3222 text_buffer_changed(es
);
3225 /* there is an insertion */
3226 tl
= get_text_length(es
);
3227 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
));
3228 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3230 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3231 p
[i
] = lpsz_replace
[i
];
3232 if(es
->style
& ES_UPPERCASE
)
3233 CharUpperBuffW(p
, strl
);
3234 else if(es
->style
& ES_LOWERCASE
)
3235 CharLowerBuffW(p
, strl
);
3236 text_buffer_changed(es
);
3238 if (es
->style
& ES_MULTILINE
)
3240 INT st
= min(es
->selection_start
, es
->selection_end
);
3241 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3243 hrgn
= CreateRectRgn(0, 0, 0, 0);
3244 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3245 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3246 /* if text is too long undo all changes */
3247 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3249 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3251 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3253 text_buffer_changed(es
);
3254 EDIT_BuildLineDefs_ML(es
, s
, e
,
3255 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3258 hrgn
= CreateRectRgn(0, 0, 0, 0);
3259 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3263 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3264 EDIT_CalcLineWidth_SL(es
);
3265 /* remove chars that don't fit */
3266 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3267 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3268 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3270 EDIT_CalcLineWidth_SL(es
);
3272 text_buffer_changed(es
);
3273 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3279 utl
= strlenW(es
->undo_text
);
3280 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3281 /* undo-buffer is extended to the right */
3282 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3283 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3284 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3285 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3286 /* undo-buffer is extended to the left */
3287 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3288 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3290 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3292 es
->undo_position
= s
;
3294 /* new undo-buffer */
3295 EDIT_MakeUndoFit(es
, e
- s
);
3296 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3297 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3298 es
->undo_position
= s
;
3300 /* any deletion makes the old insertion-undo invalid */
3301 es
->undo_insert_count
= 0;
3303 EDIT_EM_EmptyUndoBuffer(es
);
3307 if ((s
== es
->undo_position
) ||
3308 ((es
->undo_insert_count
) &&
3309 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3311 * insertion is new and at delete position or
3312 * an extension to either left or right
3314 es
->undo_insert_count
+= strl
;
3316 /* new insertion undo */
3317 es
->undo_position
= s
;
3318 es
->undo_insert_count
= strl
;
3319 /* new insertion makes old delete-buffer invalid */
3320 *es
->undo_text
= '\0';
3323 EDIT_EM_EmptyUndoBuffer(es
);
3327 HeapFree(GetProcessHeap(), 0, buf
);
3331 /* If text has been deleted and we're right or center aligned then scroll rightward */
3332 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3334 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3336 if (delta
< 0 && es
->x_offset
)
3338 if (abs(delta
) > es
->x_offset
)
3341 es
->x_offset
+= delta
;
3345 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3346 es
->flags
|= EF_MODIFIED
;
3347 if (send_update
) es
->flags
|= EF_UPDATE
;
3350 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3354 EDIT_UpdateText(es
, NULL
, TRUE
);
3356 EDIT_EM_ScrollCaret(es
);
3358 /* force scroll info update */
3359 EDIT_UpdateScrollInfo(es
);
3362 if(send_update
|| (es
->flags
& EF_UPDATE
))
3364 es
->flags
&= ~EF_UPDATE
;
3365 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3370 /*********************************************************************
3375 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3379 if (!(es
->style
& ES_MULTILINE
))
3380 return (LRESULT
)FALSE
;
3390 if (es
->y_offset
< es
->line_count
- 1)
3395 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3398 if (es
->y_offset
< es
->line_count
- 1)
3399 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3402 return (LRESULT
)FALSE
;
3405 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3406 /* check if we are going to move too far */
3407 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3408 dy
= es
->line_count
- vlc
- es
->y_offset
;
3410 /* Notification is done in EDIT_EM_LineScroll */
3412 EDIT_EM_LineScroll(es
, 0, dy
);
3414 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3418 /*********************************************************************
3423 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3425 if (es
->style
& ES_MULTILINE
) {
3429 INT cw
= es
->char_width
;
3434 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3435 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3436 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3437 if (l
>= es
->y_offset
+ vlc
)
3438 dy
= l
- vlc
+ 1 - es
->y_offset
;
3439 if (l
< es
->y_offset
)
3440 dy
= l
- es
->y_offset
;
3441 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3442 if (x
< es
->format_rect
.left
)
3443 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3444 if (x
> es
->format_rect
.right
)
3445 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3446 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3448 /* check if we are going to move too far */
3449 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3450 dx
= es
->text_width
- ww
- es
->x_offset
;
3451 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3452 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3459 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3460 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3461 if (x
< es
->format_rect
.left
) {
3462 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3465 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3466 } while ((x
< goal
) && es
->x_offset
);
3467 /* FIXME: use ScrollWindow() somehow to improve performance */
3468 EDIT_UpdateText(es
, NULL
, TRUE
);
3469 } else if (x
> es
->format_rect
.right
) {
3471 INT len
= get_text_length(es
);
3472 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3475 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3476 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3477 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3478 /* FIXME: use ScrollWindow() somehow to improve performance */
3479 EDIT_UpdateText(es
, NULL
, TRUE
);
3483 if(es
->flags
& EF_FOCUSED
)
3484 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3488 /*********************************************************************
3492 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3495 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3497 if (!(es
->style
& ES_MULTILINE
))
3501 WARN("called with NULL handle\n");
3505 EDIT_UnlockBuffer(es
, TRUE
);
3509 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3510 HANDLE16 oldDS
= stack16
->ds
;
3512 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3513 LocalFree16(es
->hloc16
);
3514 stack16
->ds
= oldDS
;
3522 LocalFree(es
->hloc32A
);
3534 countA
= LocalSize(hloc
);
3535 textA
= LocalLock(hloc
);
3536 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3537 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3539 ERR("Could not allocate new unicode buffer\n");
3542 textW
= LocalLock(hloc32W_new
);
3543 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3544 LocalUnlock(hloc32W_new
);
3548 LocalFree(es
->hloc32W
);
3550 es
->hloc32W
= hloc32W_new
;
3554 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3556 es
->flags
|= EF_APP_HAS_HANDLE
;
3557 EDIT_LockBuffer(es
);
3559 es
->x_offset
= es
->y_offset
= 0;
3560 es
->selection_start
= es
->selection_end
= 0;
3561 EDIT_EM_EmptyUndoBuffer(es
);
3562 es
->flags
&= ~EF_MODIFIED
;
3563 es
->flags
&= ~EF_UPDATE
;
3564 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3565 EDIT_UpdateText(es
, NULL
, TRUE
);
3566 EDIT_EM_ScrollCaret(es
);
3567 /* force scroll info update */
3568 EDIT_UpdateScrollInfo(es
);
3572 /*********************************************************************
3576 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3579 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3581 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3582 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3583 HANDLE16 oldDS
= stack16
->ds
;
3589 if (!(es
->style
& ES_MULTILINE
))
3593 WARN("called with NULL handle\n");
3597 EDIT_UnlockBuffer(es
, TRUE
);
3601 LocalFree(es
->hloc32A
);
3605 stack16
->ds
= hInstance
;
3606 countA
= LocalSize16(hloc
);
3607 textA
= MapSL(LocalLock16(hloc
));
3608 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3609 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3611 ERR("Could not allocate new unicode buffer\n");
3614 textW
= LocalLock(hloc32W_new
);
3615 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3616 LocalUnlock(hloc32W_new
);
3617 LocalUnlock16(hloc
);
3618 stack16
->ds
= oldDS
;
3621 LocalFree(es
->hloc32W
);
3623 es
->hloc32W
= hloc32W_new
;
3626 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3628 es
->flags
|= EF_APP_HAS_HANDLE
;
3629 EDIT_LockBuffer(es
);
3631 es
->x_offset
= es
->y_offset
= 0;
3632 es
->selection_start
= es
->selection_end
= 0;
3633 EDIT_EM_EmptyUndoBuffer(es
);
3634 es
->flags
&= ~EF_MODIFIED
;
3635 es
->flags
&= ~EF_UPDATE
;
3636 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3637 EDIT_UpdateText(es
, NULL
, TRUE
);
3638 EDIT_EM_ScrollCaret(es
);
3639 /* force scroll info update */
3640 EDIT_UpdateScrollInfo(es
);
3644 /*********************************************************************
3648 * NOTE: this version currently implements WinNT limits
3651 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
3653 if (!limit
) limit
= ~0u;
3654 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
3655 es
->buffer_limit
= limit
;
3659 /*********************************************************************
3663 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3664 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3665 * margin according to the textmetrics of the current font.
3667 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3668 * of the char's width as the margin, but this is not how Windows handles this.
3669 * For all other fonts Windows sets the margins to zero.
3671 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3672 * edit control is equal to or larger than a certain size.
3673 * Interestingly if one subtracts both the left and right margins from
3674 * this size one always seems to get an even number. The extents of
3675 * the (four character) string "'**'" match this quite closely, so
3676 * we'll use this until we come up with a better idea.
3678 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3680 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3683 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3684 return sz
.cx
+ left
+ right
;
3687 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3688 WORD left
, WORD right
, BOOL repaint
)
3691 INT default_left_margin
= 0; /* in pixels */
3692 INT default_right_margin
= 0; /* in pixels */
3694 /* Set the default margins depending on the font */
3695 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3696 HDC dc
= GetDC(es
->hwndSelf
);
3697 HFONT old_font
= SelectObject(dc
, es
->font
);
3698 GetTextMetricsW(dc
, &tm
);
3699 /* The default margins are only non zero for TrueType or Vector fonts */
3700 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3703 /* This must be calculated more exactly! But how? */
3704 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3705 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3706 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3707 GetClientRect(es
->hwndSelf
, &rc
);
3708 if(rc
.right
- rc
.left
< min_size
) {
3709 default_left_margin
= es
->left_margin
;
3710 default_right_margin
= es
->right_margin
;
3713 SelectObject(dc
, old_font
);
3714 ReleaseDC(es
->hwndSelf
, dc
);
3717 if (action
& EC_LEFTMARGIN
) {
3718 es
->format_rect
.left
-= es
->left_margin
;
3719 if (left
!= EC_USEFONTINFO
)
3720 es
->left_margin
= left
;
3722 es
->left_margin
= default_left_margin
;
3723 es
->format_rect
.left
+= es
->left_margin
;
3726 if (action
& EC_RIGHTMARGIN
) {
3727 es
->format_rect
.right
+= es
->right_margin
;
3728 if (right
!= EC_USEFONTINFO
)
3729 es
->right_margin
= right
;
3731 es
->right_margin
= default_right_margin
;
3732 es
->format_rect
.right
-= es
->right_margin
;
3735 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3736 EDIT_AdjustFormatRect(es
);
3737 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3740 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3744 /*********************************************************************
3746 * EM_SETPASSWORDCHAR
3749 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3753 if (es
->style
& ES_MULTILINE
)
3756 if (es
->password_char
== c
)
3759 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3760 es
->password_char
= c
;
3762 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3763 es
->style
|= ES_PASSWORD
;
3765 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3766 es
->style
&= ~ES_PASSWORD
;
3768 EDIT_UpdateText(es
, NULL
, TRUE
);
3772 /*********************************************************************
3776 * note: unlike the specs say: the order of start and end
3777 * _is_ preserved in Windows. (i.e. start can be > end)
3778 * In other words: this handler is OK
3781 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3783 UINT old_start
= es
->selection_start
;
3784 UINT old_end
= es
->selection_end
;
3785 UINT len
= get_text_length(es
);
3787 if (start
== (UINT
)-1) {
3788 start
= es
->selection_end
;
3789 end
= es
->selection_end
;
3791 start
= min(start
, len
);
3792 end
= min(end
, len
);
3794 es
->selection_start
= start
;
3795 es
->selection_end
= end
;
3797 es
->flags
|= EF_AFTER_WRAP
;
3799 es
->flags
&= ~EF_AFTER_WRAP
;
3800 /* Compute the necessary invalidation region. */
3801 /* Note that we don't need to invalidate regions which have
3802 * "never" been selected, or those which are "still" selected.
3803 * In fact, every time we hit a selection boundary, we can
3804 * *toggle* whether we need to invalidate. Thus we can optimize by
3805 * *sorting* the interval endpoints. Let's assume that we sort them
3807 * start <= end <= old_start <= old_end
3808 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
3809 * in 5 comparisons; i.e. it is impossible to do better than the
3811 ORDER_UINT(end
, old_end
);
3812 ORDER_UINT(start
, old_start
);
3813 ORDER_UINT(old_start
, old_end
);
3814 ORDER_UINT(start
, end
);
3815 /* Note that at this point 'end' and 'old_start' are not in order, but
3816 * start is definitely the min. and old_end is definitely the max. */
3817 if (end
!= old_start
)
3821 * ORDER_UINT32(end, old_start);
3822 * EDIT_InvalidateText(es, start, end);
3823 * EDIT_InvalidateText(es, old_start, old_end);
3824 * in place of the following if statement.
3825 * (That would complete the optimal five-comparison four-element sort.)
3827 if (old_start
> end
)
3829 EDIT_InvalidateText(es
, start
, end
);
3830 EDIT_InvalidateText(es
, old_start
, old_end
);
3834 EDIT_InvalidateText(es
, start
, old_start
);
3835 EDIT_InvalidateText(es
, end
, old_end
);
3838 else EDIT_InvalidateText(es
, start
, old_end
);
3842 /*********************************************************************
3847 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3849 if (!(es
->style
& ES_MULTILINE
))
3851 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3852 es
->tabs_count
= count
;
3856 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3857 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3863 /*********************************************************************
3868 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3870 if (!(es
->style
& ES_MULTILINE
))
3872 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3873 es
->tabs_count
= count
;
3878 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3879 for (i
= 0 ; i
< count
; i
++)
3880 es
->tabs
[i
] = *tabs
++;
3886 /*********************************************************************
3888 * EM_SETWORDBREAKPROC
3891 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3893 if (es
->word_break_proc
== wbp
)
3896 es
->word_break_proc
= wbp
;
3897 es
->word_break_proc16
= NULL
;
3899 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3900 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3901 EDIT_UpdateText(es
, NULL
, TRUE
);
3906 /*********************************************************************
3908 * EM_SETWORDBREAKPROC16
3911 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3913 if (es
->word_break_proc16
== wbp
)
3916 es
->word_break_proc
= NULL
;
3917 es
->word_break_proc16
= wbp
;
3918 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3919 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3920 EDIT_UpdateText(es
, NULL
, TRUE
);
3925 /*********************************************************************
3930 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3935 /* As per MSDN spec, for a single-line edit control,
3936 the return value is always TRUE */
3937 if( es
->style
& ES_READONLY
)
3938 return !(es
->style
& ES_MULTILINE
);
3940 ulength
= strlenW(es
->undo_text
);
3942 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3944 strcpyW(utext
, es
->undo_text
);
3946 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3947 es
->undo_insert_count
, debugstr_w(utext
));
3949 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3950 EDIT_EM_EmptyUndoBuffer(es
);
3951 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3952 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3953 /* send the notification after the selection start and end are set */
3954 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3955 EDIT_EM_ScrollCaret(es
);
3956 HeapFree(GetProcessHeap(), 0, utext
);
3958 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3959 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3964 /* Helper function for WM_CHAR
3966 * According to an MSDN blog article titled "Just because you're a control
3967 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3968 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3969 * a dialog box or not.
3971 static BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3978 pParent
= WIN_GetPtr(es
->hwndParent
);
3979 if (pParent
&& pParent
!= WND_OTHER_PROCESS
&& pParent
!= WND_DESKTOP
)
3981 if (pParent
->flags
& WIN_ISDIALOG
)
3983 WIN_ReleasePtr(pParent
);
3990 /*********************************************************************
3995 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3999 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4003 /* If it's not a multiline edit box, it would be ignored below.
4004 * For multiline edit without ES_WANTRETURN, we have to make a
4007 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
4008 if (EDIT_IsInsideDialog(es
))
4011 if (es
->style
& ES_MULTILINE
) {
4012 if (es
->style
& ES_READONLY
) {
4013 EDIT_MoveHome(es
, FALSE
, FALSE
);
4014 EDIT_MoveDown_ML(es
, FALSE
);
4016 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4017 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4022 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4024 static const WCHAR tabW
[] = {'\t',0};
4025 if (EDIT_IsInsideDialog(es
))
4027 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4031 if (!(es
->style
& ES_READONLY
) && !control
) {
4032 if (es
->selection_start
!= es
->selection_end
)
4035 /* delete character left of caret */
4036 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4037 EDIT_MoveBackward(es
, TRUE
);
4043 if (!(es
->style
& ES_PASSWORD
))
4044 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4047 if (!(es
->style
& ES_READONLY
))
4048 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4051 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4052 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4055 if (!(es
->style
& ES_READONLY
))
4056 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4060 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4061 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4064 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4068 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4076 /*********************************************************************
4081 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4083 if (code
|| control
)
4103 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4104 EDIT_EM_ScrollCaret(es
);
4107 ERR("unknown menu item, please report\n");
4113 /*********************************************************************
4117 * Note: the resource files resource/sysres_??.rc cannot define a
4118 * single popup menu. Hence we use a (dummy) menubar
4119 * containing the single popup menu as its first item.
4121 * FIXME: the message identifiers have been chosen arbitrarily,
4122 * hence we use MF_BYPOSITION.
4123 * We might as well use the "real" values (anybody knows ?)
4124 * The menu definition is in resources/sysres_??.rc.
4125 * Once these are OK, we better use MF_BYCOMMAND here
4126 * (as we do in EDIT_WM_Command()).
4129 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4131 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4132 HMENU popup
= GetSubMenu(menu
, 0);
4133 UINT start
= es
->selection_start
;
4134 UINT end
= es
->selection_end
;
4136 ORDER_UINT(start
, end
);
4139 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4141 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4143 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4145 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4147 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4149 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4151 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4154 /* Windows places the menu at the edit's center in this case */
4155 GetClientRect(es
->hwndSelf
, &rc
);
4156 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4157 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4158 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4161 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4166 /*********************************************************************
4171 static void EDIT_WM_Copy(EDITSTATE
*es
)
4173 INT s
= min(es
->selection_start
, es
->selection_end
);
4174 INT e
= max(es
->selection_start
, es
->selection_end
);
4182 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4183 dst
= GlobalLock(hdst
);
4184 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4185 dst
[len
] = 0; /* ensure 0 termination */
4186 TRACE("%s\n", debugstr_w(dst
));
4188 OpenClipboard(es
->hwndSelf
);
4190 SetClipboardData(CF_UNICODETEXT
, hdst
);
4195 /*********************************************************************
4200 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4204 TRACE("%s\n", debugstr_w(name
));
4206 * To initialize some final structure members, we call some helper
4207 * functions. However, since the EDITSTATE is not consistent (i.e.
4208 * not fully initialized), we should be very careful which
4209 * functions can be called, and in what order.
4211 EDIT_WM_SetFont(es
, 0, FALSE
);
4212 EDIT_EM_EmptyUndoBuffer(es
);
4214 /* We need to calculate the format rect
4215 (applications may send EM_SETMARGINS before the control gets visible) */
4216 GetClientRect(es
->hwndSelf
, &clientRect
);
4217 EDIT_SetRectNP(es
, &clientRect
);
4219 if (name
&& *name
) {
4220 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4221 /* if we insert text to the editline, the text scrolls out
4222 * of the window, as the caret is placed after the insert
4223 * pos normally; thus we reset es->selection... to 0 and
4226 es
->selection_start
= es
->selection_end
= 0;
4227 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4228 * Messages are only to be sent when the USER does something to
4229 * change the contents. So I am removing this EN_CHANGE
4231 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4233 EDIT_EM_ScrollCaret(es
);
4235 /* force scroll info update */
4236 EDIT_UpdateScrollInfo(es
);
4237 /* The rule seems to return 1 here for success */
4238 /* Power Builder masked edit controls will crash */
4240 /* FIXME: is that in all cases so ? */
4245 /*********************************************************************
4250 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4255 LocalFree(es
->hloc32W
);
4258 LocalFree(es
->hloc32A
);
4261 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4262 HANDLE16 oldDS
= stack16
->ds
;
4264 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4265 while (LocalUnlock16(es
->hloc16
)) ;
4266 LocalFree16(es
->hloc16
);
4267 stack16
->ds
= oldDS
;
4270 pc
= es
->first_line_def
;
4274 HeapFree(GetProcessHeap(), 0, pc
);
4278 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4279 HeapFree(GetProcessHeap(), 0, es
);
4285 /*********************************************************************
4290 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4292 if(!count
) return 0;
4296 lstrcpynW(dst
, es
->text
, count
);
4297 return strlenW(dst
);
4301 LPSTR textA
= (LPSTR
)dst
;
4302 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4303 textA
[count
- 1] = 0; /* ensure 0 termination */
4304 return strlen(textA
);
4308 /*********************************************************************
4313 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4318 if (!(es
->style
& ES_MULTILINE
))
4321 if (!(es
->style
& ES_AUTOHSCROLL
))
4325 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4328 TRACE("SB_LINELEFT\n");
4330 dx
= -es
->char_width
;
4333 TRACE("SB_LINERIGHT\n");
4334 if (es
->x_offset
< es
->text_width
)
4335 dx
= es
->char_width
;
4338 TRACE("SB_PAGELEFT\n");
4340 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4343 TRACE("SB_PAGERIGHT\n");
4344 if (es
->x_offset
< es
->text_width
)
4345 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4353 TRACE("SB_RIGHT\n");
4354 if (es
->x_offset
< es
->text_width
)
4355 dx
= es
->text_width
- es
->x_offset
;
4358 TRACE("SB_THUMBTRACK %d\n", pos
);
4359 es
->flags
|= EF_HSCROLL_TRACK
;
4360 if(es
->style
& WS_HSCROLL
)
4361 dx
= pos
- es
->x_offset
;
4366 if(pos
< 0 || pos
> 100) return 0;
4367 /* Assume default scroll range 0-100 */
4368 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4369 new_x
= pos
* (es
->text_width
- fw
) / 100;
4370 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4373 case SB_THUMBPOSITION
:
4374 TRACE("SB_THUMBPOSITION %d\n", pos
);
4375 es
->flags
&= ~EF_HSCROLL_TRACK
;
4376 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4377 dx
= pos
- es
->x_offset
;
4382 if(pos
< 0 || pos
> 100) return 0;
4383 /* Assume default scroll range 0-100 */
4384 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4385 new_x
= pos
* (es
->text_width
- fw
) / 100;
4386 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4389 /* force scroll info update */
4390 EDIT_UpdateScrollInfo(es
);
4391 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4395 TRACE("SB_ENDSCROLL\n");
4398 * FIXME : the next two are undocumented !
4399 * Are we doing the right thing ?
4400 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4401 * although it's also a regular control message.
4403 case EM_GETTHUMB
: /* this one is used by NT notepad */
4407 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4408 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4411 /* Assume default scroll range 0-100 */
4412 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4413 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4415 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4418 case EM_LINESCROLL16
:
4419 TRACE("EM_LINESCROLL16\n");
4424 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4430 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4431 /* check if we are going to move too far */
4432 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4433 dx
= es
->text_width
- fw
- es
->x_offset
;
4435 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4441 /*********************************************************************
4446 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4448 HWND hLBox
= es
->hwndListBox
;
4456 hCombo
= GetParent(es
->hwndSelf
);
4460 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4462 if (key
== VK_UP
|| key
== VK_DOWN
)
4464 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4467 if (msg
== WM_KEYDOWN
|| nEUI
)
4468 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4474 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4476 /* make sure ComboLBox pops up */
4477 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4482 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4485 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4487 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4489 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4494 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4500 /*********************************************************************
4504 * Handling of special keys that don't produce a WM_CHAR
4505 * (i.e. non-printable keys) & Backspace & Delete
4508 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4513 if (GetKeyState(VK_MENU
) & 0x8000)
4516 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4517 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4522 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4527 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4528 EDIT_MoveUp_ML(es
, shift
);
4531 EDIT_MoveWordBackward(es
, shift
);
4533 EDIT_MoveBackward(es
, shift
);
4536 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4540 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4541 EDIT_MoveDown_ML(es
, shift
);
4543 EDIT_MoveWordForward(es
, shift
);
4545 EDIT_MoveForward(es
, shift
);
4548 EDIT_MoveHome(es
, shift
, control
);
4551 EDIT_MoveEnd(es
, shift
, control
);
4554 if (es
->style
& ES_MULTILINE
)
4555 EDIT_MovePageUp_ML(es
, shift
);
4557 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4560 if (es
->style
& ES_MULTILINE
)
4561 EDIT_MovePageDown_ML(es
, shift
);
4563 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4566 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4567 if (es
->selection_start
!= es
->selection_end
) {
4574 /* delete character left of caret */
4575 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4576 EDIT_MoveBackward(es
, TRUE
);
4578 } else if (control
) {
4579 /* delete to end of line */
4580 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4581 EDIT_MoveEnd(es
, TRUE
, FALSE
);
4584 /* delete character right of caret */
4585 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4586 EDIT_MoveForward(es
, TRUE
);
4594 if (!(es
->style
& ES_READONLY
))
4600 /* If the edit doesn't want the return send a message to the default object */
4601 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
4606 if (!EDIT_IsInsideDialog(es
)) return 1;
4608 hwndParent
= GetParent(es
->hwndSelf
);
4609 dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4610 if (HIWORD(dw
) == DC_HASDEFID
)
4612 SendMessageW( hwndParent
, WM_COMMAND
,
4613 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4614 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4617 SendMessageW( hwndParent
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndParent
, IDOK
) );
4621 if (!(es
->style
& ES_MULTILINE
))
4622 SendMessageW(GetParent(es
->hwndSelf
), WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( GetParent(es
->hwndSelf
), IDCANCEL
) );
4625 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
4632 /*********************************************************************
4637 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4639 es
->flags
&= ~EF_FOCUSED
;
4641 if(!(es
->style
& ES_NOHIDESEL
))
4642 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4643 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4648 /*********************************************************************
4652 * The caret position has been set on the WM_LBUTTONDOWN message
4655 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4658 INT e
= es
->selection_end
;
4663 es
->bCaptureState
= TRUE
;
4664 SetCapture(es
->hwndSelf
);
4666 l
= EDIT_EM_LineFromChar(es
, e
);
4667 li
= EDIT_EM_LineIndex(es
, l
);
4668 ll
= EDIT_EM_LineLength(es
, e
);
4669 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4670 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4671 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4672 EDIT_EM_ScrollCaret(es
);
4673 es
->region_posx
= es
->region_posy
= 0;
4674 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4679 /*********************************************************************
4684 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4689 es
->bCaptureState
= TRUE
;
4690 SetCapture(es
->hwndSelf
);
4691 EDIT_ConfinePoint(es
, &x
, &y
);
4692 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4693 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4694 EDIT_EM_ScrollCaret(es
);
4695 es
->region_posx
= es
->region_posy
= 0;
4696 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4698 if (!(es
->flags
& EF_FOCUSED
))
4699 SetFocus(es
->hwndSelf
);
4705 /*********************************************************************
4710 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4712 if (es
->bCaptureState
) {
4713 KillTimer(es
->hwndSelf
, 0);
4714 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4716 es
->bCaptureState
= FALSE
;
4721 /*********************************************************************
4726 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4728 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4733 /*********************************************************************
4738 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4744 /* If the mouse has been captured by process other than the edit control itself,
4745 * the windows edit controls will not select the strings with mouse move.
4747 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4751 * FIXME: gotta do some scrolling if outside client
4752 * area. Maybe reset the timer ?
4755 EDIT_ConfinePoint(es
, &x
, &y
);
4756 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4757 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4758 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4759 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4760 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4765 /*********************************************************************
4769 * See also EDIT_WM_StyleChanged
4771 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4776 TRACE("Creating %s edit control, style = %08x\n",
4777 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4779 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4781 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4784 * Note: since the EDITSTATE has not been fully initialized yet,
4785 * we can't use any API calls that may send
4786 * WM_XXX messages before WM_NCCREATE is completed.
4789 es
->is_unicode
= unicode
;
4790 es
->style
= lpcs
->style
;
4792 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4794 es
->hwndSelf
= hwnd
;
4795 /* Save parent, which will be notified by EN_* messages */
4796 es
->hwndParent
= lpcs
->hwndParent
;
4798 if (es
->style
& ES_COMBO
)
4799 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4801 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4802 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4804 /* Number overrides lowercase overrides uppercase (at least it
4805 * does in Win95). However I'll bet that ES_NUMBER would be
4806 * invalid under Win 3.1.
4808 if (es
->style
& ES_NUMBER
) {
4809 ; /* do not override the ES_NUMBER */
4810 } else if (es
->style
& ES_LOWERCASE
) {
4811 es
->style
&= ~ES_UPPERCASE
;
4813 if (es
->style
& ES_MULTILINE
) {
4814 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4815 if (es
->style
& WS_VSCROLL
)
4816 es
->style
|= ES_AUTOVSCROLL
;
4817 if (es
->style
& WS_HSCROLL
)
4818 es
->style
|= ES_AUTOHSCROLL
;
4819 es
->style
&= ~ES_PASSWORD
;
4820 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4821 /* Confirmed - RIGHT overrides CENTER */
4822 if (es
->style
& ES_RIGHT
)
4823 es
->style
&= ~ES_CENTER
;
4824 es
->style
&= ~WS_HSCROLL
;
4825 es
->style
&= ~ES_AUTOHSCROLL
;
4828 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4829 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4830 es
->style
&= ~ES_CENTER
;
4831 es
->style
&= ~WS_HSCROLL
;
4832 es
->style
&= ~WS_VSCROLL
;
4833 if (es
->style
& ES_PASSWORD
)
4834 es
->password_char
= '*';
4837 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4838 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4840 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4842 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4844 es
->undo_buffer_size
= es
->buffer_size
;
4846 if (es
->style
& ES_MULTILINE
)
4847 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4852 * In Win95 look and feel, the WS_BORDER style is replaced by the
4853 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4854 * control a nonclient area so we don't need to draw the border.
4855 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4856 * a nonclient area and we should handle painting the border ourselves.
4858 * When making modifications please ensure that the code still works
4859 * for edit controls created directly with style 0x50800000, exStyle 0
4860 * (which should have a single pixel border)
4862 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4863 es
->style
&= ~WS_BORDER
;
4864 else if (es
->style
& WS_BORDER
)
4865 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4870 /*********************************************************************
4875 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4888 BOOL rev
= es
->bEnableState
&&
4889 ((es
->flags
& EF_FOCUSED
) ||
4890 (es
->style
& ES_NOHIDESEL
));
4891 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4893 GetClientRect(es
->hwndSelf
, &rcClient
);
4895 /* get the background brush */
4896 brush
= EDIT_NotifyCtlColor(es
, dc
);
4898 /* paint the border and the background */
4899 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4901 if(es
->style
& WS_BORDER
) {
4902 bw
= GetSystemMetrics(SM_CXBORDER
);
4903 bh
= GetSystemMetrics(SM_CYBORDER
);
4905 if(es
->style
& ES_MULTILINE
) {
4906 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4907 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4910 /* Draw the frame. Same code as in nonclient.c */
4911 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
4912 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
4913 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4914 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
4915 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4916 SelectObject(dc
, old_brush
);
4918 /* Keep the border clean */
4919 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
4920 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
4923 GetClipBox(dc
, &rc
);
4924 FillRect(dc
, &rc
, brush
);
4926 IntersectClipRect(dc
, es
->format_rect
.left
,
4927 es
->format_rect
.top
,
4928 es
->format_rect
.right
,
4929 es
->format_rect
.bottom
);
4930 if (es
->style
& ES_MULTILINE
) {
4932 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4935 old_font
= SelectObject(dc
, es
->font
);
4937 if (!es
->bEnableState
)
4938 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4939 GetClipBox(dc
, &rcRgn
);
4940 if (es
->style
& ES_MULTILINE
) {
4941 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4942 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4943 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4944 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4945 EDIT_PaintLine(es
, dc
, i
, rev
);
4948 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4949 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4950 EDIT_PaintLine(es
, dc
, 0, rev
);
4953 SelectObject(dc
, old_font
);
4956 EndPaint(es
->hwndSelf
, &ps
);
4960 /*********************************************************************
4965 static void EDIT_WM_Paste(EDITSTATE
*es
)
4970 /* Protect read-only edit control from modification */
4971 if(es
->style
& ES_READONLY
)
4974 OpenClipboard(es
->hwndSelf
);
4975 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4976 src
= (LPWSTR
)GlobalLock(hsrc
);
4977 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4980 else if (es
->style
& ES_PASSWORD
) {
4981 /* clear selected text in password edit box even with empty clipboard */
4982 const WCHAR empty_strW
[] = { 0 };
4983 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
4989 /*********************************************************************
4994 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4996 es
->flags
|= EF_FOCUSED
;
4998 if (!(es
->style
& ES_NOHIDESEL
))
4999 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
5001 /* single line edit updates itself */
5002 if (!(es
->style
& ES_MULTILINE
))
5004 HDC hdc
= GetDC(es
->hwndSelf
);
5005 EDIT_WM_Paint(es
, hdc
);
5006 ReleaseDC(es
->hwndSelf
, hdc
);
5009 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5010 EDIT_SetCaretPos(es
, es
->selection_end
,
5011 es
->flags
& EF_AFTER_WRAP
);
5012 ShowCaret(es
->hwndSelf
);
5013 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
5017 /*********************************************************************
5021 * With Win95 look the margins are set to default font value unless
5022 * the system font (font == 0) is being set, in which case they are left
5026 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5034 dc
= GetDC(es
->hwndSelf
);
5036 old_font
= SelectObject(dc
, font
);
5037 GetTextMetricsW(dc
, &tm
);
5038 es
->line_height
= tm
.tmHeight
;
5039 es
->char_width
= tm
.tmAveCharWidth
;
5041 SelectObject(dc
, old_font
);
5042 ReleaseDC(es
->hwndSelf
, dc
);
5044 /* Reset the format rect and the margins */
5045 GetClientRect(es
->hwndSelf
, &clientRect
);
5046 EDIT_SetRectNP(es
, &clientRect
);
5047 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5048 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5050 if (es
->style
& ES_MULTILINE
)
5051 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5053 EDIT_CalcLineWidth_SL(es
);
5056 EDIT_UpdateText(es
, NULL
, TRUE
);
5057 if (es
->flags
& EF_FOCUSED
) {
5059 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5060 EDIT_SetCaretPos(es
, es
->selection_end
,
5061 es
->flags
& EF_AFTER_WRAP
);
5062 ShowCaret(es
->hwndSelf
);
5067 /*********************************************************************
5072 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5073 * The modified flag is reset. No notifications are sent.
5075 * For single-line controls, reception of WM_SETTEXT triggers:
5076 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5079 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5081 LPWSTR textW
= NULL
;
5082 if (!unicode
&& text
)
5084 LPCSTR textA
= (LPCSTR
)text
;
5085 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5086 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5088 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5092 if (es
->flags
& EF_UPDATE
)
5093 /* fixed this bug once; complain if we see it about to happen again. */
5094 ERR("SetSel may generate UPDATE message whose handler may reset "
5097 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5100 TRACE("%s\n", debugstr_w(text
));
5101 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5103 HeapFree(GetProcessHeap(), 0, textW
);
5107 static const WCHAR empty_stringW
[] = {0};
5109 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5112 es
->flags
&= ~EF_MODIFIED
;
5113 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5115 /* Send the notification after the selection start and end have been set
5116 * edit control doesn't send notification on WM_SETTEXT
5117 * if it is multiline, or it is part of combobox
5119 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5121 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5122 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5124 EDIT_EM_ScrollCaret(es
);
5125 EDIT_UpdateScrollInfo(es
);
5129 /*********************************************************************
5134 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5136 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5138 TRACE("width = %d, height = %d\n", width
, height
);
5139 SetRect(&rc
, 0, 0, width
, height
);
5140 EDIT_SetRectNP(es
, &rc
);
5141 EDIT_UpdateText(es
, NULL
, TRUE
);
5146 /*********************************************************************
5150 * This message is sent by SetWindowLong on having changed either the Style
5151 * or the extended style.
5153 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5155 * See also EDIT_WM_NCCreate
5157 * It appears that the Windows version of the edit control allows the style
5158 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5159 * style variable which will generally be different. In this function we
5160 * update the internal style based on what changed in the externally visible
5163 * Much of this content as based upon the MSDN, especially:
5164 * Platform SDK Documentation -> User Interface Services ->
5165 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5166 * Edit Control Styles
5168 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5170 if (GWL_STYLE
== which
) {
5171 DWORD style_change_mask
;
5173 /* Only a subset of changes can be applied after the control
5176 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5178 if (es
->style
& ES_MULTILINE
)
5179 style_change_mask
|= ES_WANTRETURN
;
5181 new_style
= style
->styleNew
& style_change_mask
;
5183 /* Number overrides lowercase overrides uppercase (at least it
5184 * does in Win95). However I'll bet that ES_NUMBER would be
5185 * invalid under Win 3.1.
5187 if (new_style
& ES_NUMBER
) {
5188 ; /* do not override the ES_NUMBER */
5189 } else if (new_style
& ES_LOWERCASE
) {
5190 new_style
&= ~ES_UPPERCASE
;
5193 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5194 } else if (GWL_EXSTYLE
== which
) {
5195 ; /* FIXME - what is needed here */
5197 WARN ("Invalid style change %ld\n",which
);
5203 /*********************************************************************
5208 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5210 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5211 if (EDIT_EM_CanUndo(es
))
5214 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5215 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5218 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5222 /*********************************************************************
5227 static void EDIT_WM_Timer(EDITSTATE
*es
)
5229 if (es
->region_posx
< 0) {
5230 EDIT_MoveBackward(es
, TRUE
);
5231 } else if (es
->region_posx
> 0) {
5232 EDIT_MoveForward(es
, TRUE
);
5235 * FIXME: gotta do some vertical scrolling here, like
5236 * EDIT_EM_LineScroll(hwnd, 0, 1);
5240 /*********************************************************************
5245 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5249 if (!(es
->style
& ES_MULTILINE
))
5252 if (!(es
->style
& ES_AUTOVSCROLL
))
5261 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5262 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5263 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5265 EDIT_EM_Scroll(es
, action
);
5272 TRACE("SB_BOTTOM\n");
5273 dy
= es
->line_count
- 1 - es
->y_offset
;
5276 TRACE("SB_THUMBTRACK %d\n", pos
);
5277 es
->flags
|= EF_VSCROLL_TRACK
;
5278 if(es
->style
& WS_VSCROLL
)
5279 dy
= pos
- es
->y_offset
;
5282 /* Assume default scroll range 0-100 */
5285 if(pos
< 0 || pos
> 100) return 0;
5286 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5287 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5288 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5289 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5290 es
->line_count
, es
->y_offset
, pos
, dy
);
5293 case SB_THUMBPOSITION
:
5294 TRACE("SB_THUMBPOSITION %d\n", pos
);
5295 es
->flags
&= ~EF_VSCROLL_TRACK
;
5296 if(es
->style
& WS_VSCROLL
)
5297 dy
= pos
- es
->y_offset
;
5300 /* Assume default scroll range 0-100 */
5303 if(pos
< 0 || pos
> 100) return 0;
5304 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5305 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5306 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5307 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5308 es
->line_count
, es
->y_offset
, pos
, dy
);
5312 /* force scroll info update */
5313 EDIT_UpdateScrollInfo(es
);
5314 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5318 TRACE("SB_ENDSCROLL\n");
5321 * FIXME : the next two are undocumented !
5322 * Are we doing the right thing ?
5323 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5324 * although it's also a regular control message.
5326 case EM_GETTHUMB
: /* this one is used by NT notepad */
5330 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5331 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5334 /* Assume default scroll range 0-100 */
5335 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5336 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5338 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5341 case EM_LINESCROLL16
:
5342 TRACE("EM_LINESCROLL16 %d\n", pos
);
5347 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5352 EDIT_EM_LineScroll(es
, 0, dy
);
5356 /*********************************************************************
5361 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5363 if (es
->flags
& EF_UPDATE
) {
5364 es
->flags
&= ~EF_UPDATE
;
5365 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5367 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5371 /*********************************************************************
5376 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
5378 if (es
->flags
& EF_UPDATE
) {
5379 es
->flags
&= ~EF_UPDATE
;
5380 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5382 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5385 /********************************************************************
5387 * The Following code is to handle inline editing from IMEs
5390 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
5393 LPWSTR lpCompStr
= NULL
;
5394 LPSTR lpCompStrAttr
= NULL
;
5397 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5404 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
5407 ERR("Unable to allocate IME CompositionString\n");
5412 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
5413 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
5415 if (CompFlag
& GCS_COMPATTR
)
5418 * We do not use the attributes yet. it would tell us what characters
5419 * are in transition and which are converted or decided upon
5421 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5425 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5428 ERR("Unable to allocate IME Attribute String\n");
5429 HeapFree(GetProcessHeap(),0,lpCompStr
);
5432 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5434 lpCompStrAttr
[dwBufLenAttr
] = 0;
5437 lpCompStrAttr
= NULL
;
5440 /* check for change in composition start */
5441 if (es
->selection_end
< es
->composition_start
)
5442 es
->composition_start
= es
->selection_end
;
5444 /* replace existing selection string */
5445 es
->selection_start
= es
->composition_start
;
5447 if (es
->composition_len
> 0)
5448 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5450 es
->selection_end
= es
->selection_start
;
5452 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5453 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5455 es
->selection_start
= es
->composition_start
;
5456 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5458 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5459 HeapFree(GetProcessHeap(),0,lpCompStr
);
5462 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
5467 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5473 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
5476 ERR("Unable to alloc buffer for IME string\n");
5480 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
5481 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
5483 /* check for change in composition start */
5484 if (es
->selection_end
< es
->composition_start
)
5485 es
->composition_start
= es
->selection_end
;
5487 es
->selection_start
= es
->composition_start
;
5488 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5489 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5490 es
->composition_start
= es
->selection_end
;
5491 es
->composition_len
= 0;
5493 HeapFree(GetProcessHeap(),0,lpResultStr
);
5496 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5501 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
5503 static const WCHAR empty_stringW
[] = {0};
5504 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5505 es
->composition_start
= es
->selection_end
;
5508 hIMC
= ImmGetContext(hwnd
);
5512 if (CompFlag
& GCS_RESULTSTR
)
5513 EDIT_GetResultStr(hIMC
, es
);
5514 if (CompFlag
& GCS_COMPSTR
)
5515 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
5516 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
5517 ImmReleaseContext(hwnd
, hIMC
);
5518 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);