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
);
215 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
216 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
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 void 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_COMMAND
, IDOK
, (LPARAM
)GetDlgItem(GetParent(hwnd
), IDOK
));
818 SendMessageW(GetParent(hwnd
), WM_CLOSE
, 0, 0);
821 SendMessageW(GetParent(hwnd
), WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0);
836 strng
[0] = wParam
>> 8;
837 strng
[1] = wParam
& 0xff;
838 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
839 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
840 EDIT_WM_Char(es
, charW
);
853 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
856 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
858 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
859 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
862 EDIT_WM_Char(es
, charW
);
871 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
875 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
884 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
887 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
891 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
892 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
893 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
895 result
= EDIT_WM_Create(es
, nameW
);
896 HeapFree(GetProcessHeap(), 0, nameW
);
905 es
->bEnableState
= (BOOL
) wParam
;
906 EDIT_UpdateText(es
, NULL
, TRUE
);
910 /* we do the proper erase in EDIT_WM_Paint */
915 result
= (LRESULT
)es
->font
;
919 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
922 case WM_GETTEXTLENGTH
:
923 if (unicode
) result
= get_text_length(es
);
924 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
925 NULL
, 0, NULL
, NULL
);
929 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
933 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
937 result
= EDIT_WM_KillFocus(es
);
940 case WM_LBUTTONDBLCLK
:
941 result
= EDIT_WM_LButtonDblClk(es
);
945 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
949 result
= EDIT_WM_LButtonUp(es
);
953 result
= EDIT_WM_MButtonDown(es
);
957 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
962 EDIT_WM_Paint(es
, (HDC
)wParam
);
970 EDIT_WM_SetFocus(es
);
974 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
978 /* FIXME: actually set an internal flag and behave accordingly */
982 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
987 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
990 case WM_STYLECHANGED
:
991 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
994 case WM_STYLECHANGING
:
995 result
= 0; /* See EDIT_WM_StyleChanged */
999 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
1007 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
1012 int gcWheelDelta
= 0;
1013 UINT pulScrollLines
= 3;
1014 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1016 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1017 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1020 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1021 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1023 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1024 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1025 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1031 /* IME messages to make the edit control IME aware */
1032 case WM_IME_SETCONTEXT
:
1035 case WM_IME_STARTCOMPOSITION
:
1037 * FIXME in IME: This message is not always sent like it should be
1039 if (es
->selection_start
!= es
->selection_end
)
1041 static const WCHAR empty_stringW
[] = {0};
1042 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1044 es
->composition_start
= es
->selection_end
;
1045 es
->composition_len
= 0;
1048 case WM_IME_COMPOSITION
:
1050 int caret_pos
= es
->selection_end
;
1051 if (es
->composition_len
== 0)
1053 if (es
->selection_start
!= es
->selection_end
)
1055 static const WCHAR empty_stringW
[] = {0};
1056 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1059 es
->composition_start
= es
->selection_end
;
1061 EDIT_ImeComposition(hwnd
,lParam
,es
);
1062 EDIT_SetCaretPos(es
, caret_pos
, es
->flags
& EF_AFTER_WRAP
);
1066 case WM_IME_ENDCOMPOSITION
:
1067 es
->composition_len
= 0;
1070 case WM_IME_COMPOSITIONFULL
:
1076 case WM_IME_CONTROL
:
1080 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1084 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1086 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1091 /*********************************************************************
1093 * EditWndProcW (USER32.@)
1095 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1097 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1100 /*********************************************************************
1102 * EditWndProc (USER32.@)
1104 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1106 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1109 /*********************************************************************
1111 * EDIT_BuildLineDefs_ML
1113 * Build linked list of text lines.
1114 * Lines can end with '\0' (last line), a character (if it is wrapped),
1115 * a soft return '\r\r\n' or a hard return '\r\n'
1118 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1122 LPWSTR current_position
, cp
;
1124 LINEDEF
*current_line
;
1125 LINEDEF
*previous_line
;
1126 LINEDEF
*start_line
;
1127 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1128 INT line_count
= es
->line_count
;
1129 INT orig_net_length
;
1132 if (istart
== iend
&& delta
== 0)
1135 dc
= GetDC(es
->hwndSelf
);
1137 old_font
= SelectObject(dc
, es
->font
);
1139 previous_line
= NULL
;
1140 current_line
= es
->first_line_def
;
1142 /* Find starting line. istart must lie inside an existing line or
1143 * at the end of buffer */
1145 if (istart
< current_line
->index
+ current_line
->length
||
1146 current_line
->ending
== END_0
)
1149 previous_line
= current_line
;
1150 current_line
= current_line
->next
;
1152 } while (current_line
);
1154 if (!current_line
) /* Error occurred start is not inside previous buffer */
1156 FIXME(" modification occurred outside buffer\n");
1157 ReleaseDC(es
->hwndSelf
, dc
);
1161 /* Remember start of modifications in order to calculate update region */
1162 nstart_line
= line_index
;
1163 nstart_index
= current_line
->index
;
1165 /* We must start to reformat from the previous line since the modifications
1166 * may have caused the line to wrap upwards. */
1167 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1170 current_line
= previous_line
;
1172 start_line
= current_line
;
1174 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1175 current_position
= es
->text
+ current_line
->index
;
1177 if (current_line
!= start_line
)
1179 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1181 /* The buffer has been expanded, create a new line and
1182 insert it into the link list */
1183 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1184 new_line
->next
= previous_line
->next
;
1185 previous_line
->next
= new_line
;
1186 current_line
= new_line
;
1189 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1191 /* The previous line merged with this line so we delete this extra entry */
1192 previous_line
->next
= current_line
->next
;
1193 HeapFree(GetProcessHeap(), 0, current_line
);
1194 current_line
= previous_line
->next
;
1198 else /* current_line->index + delta == current_position */
1200 if (current_position
- es
->text
> iend
)
1201 break; /* We reached end of line modifications */
1202 /* else recalulate this line */
1206 current_line
->index
= current_position
- es
->text
;
1207 orig_net_length
= current_line
->net_length
;
1209 /* Find end of line */
1210 cp
= current_position
;
1212 if (*cp
== '\n') break;
1213 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1218 /* Mark type of line termination */
1220 current_line
->ending
= END_0
;
1221 current_line
->net_length
= strlenW(current_position
);
1222 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1223 current_line
->ending
= END_SOFT
;
1224 current_line
->net_length
= cp
- current_position
- 1;
1225 } else if (*cp
== '\n') {
1226 current_line
->ending
= END_RICH
;
1227 current_line
->net_length
= cp
- current_position
;
1229 current_line
->ending
= END_HARD
;
1230 current_line
->net_length
= cp
- current_position
;
1233 /* Calculate line width */
1234 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1235 current_position
, current_line
->net_length
,
1236 es
->tabs_count
, es
->tabs
));
1238 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1239 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1240 if (current_line
->width
> fw
) {
1245 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1246 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1247 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1248 current_position
, next
, es
->tabs_count
, es
->tabs
));
1249 } while (current_line
->width
<= fw
);
1250 if (!prev
) { /* Didn't find a line break so force a break */
1255 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1256 current_position
, next
, es
->tabs_count
, es
->tabs
));
1257 } while (current_line
->width
<= fw
);
1262 /* If the first line we are calculating, wrapped before istart, we must
1263 * adjust istart in order for this to be reflected in the update region. */
1264 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1265 istart
= current_line
->index
+ prev
;
1266 /* else if we are updating the previous line before the first line we
1267 * are re-calculating and it expanded */
1268 else if (current_line
== start_line
&&
1269 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1271 /* Line expanded due to an upwards line wrap so we must partially include
1272 * previous line in update region */
1273 nstart_line
= line_index
;
1274 nstart_index
= current_line
->index
;
1275 istart
= current_line
->index
+ orig_net_length
;
1278 current_line
->net_length
= prev
;
1279 current_line
->ending
= END_WRAP
;
1280 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1281 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1283 else if (orig_net_length
< current_line
->net_length
&&
1284 current_line
== start_line
&&
1285 current_line
->index
!= nstart_index
) {
1286 /* The previous line expanded but it's still not as wide as the client rect */
1287 /* The expansion is due to an upwards line wrap so we must partially include
1288 it in the update region */
1289 nstart_line
= line_index
;
1290 nstart_index
= current_line
->index
;
1291 istart
= current_line
->index
+ orig_net_length
;
1296 /* Adjust length to include line termination */
1297 switch (current_line
->ending
) {
1299 current_line
->length
= current_line
->net_length
+ 3;
1302 current_line
->length
= current_line
->net_length
+ 1;
1305 current_line
->length
= current_line
->net_length
+ 2;
1309 current_line
->length
= current_line
->net_length
;
1312 es
->text_width
= max(es
->text_width
, current_line
->width
);
1313 current_position
+= current_line
->length
;
1314 previous_line
= current_line
;
1315 current_line
= current_line
->next
;
1317 } while (previous_line
->ending
!= END_0
);
1319 /* Finish adjusting line indexes by delta or remove hanging lines */
1320 if (previous_line
->ending
== END_0
)
1322 LINEDEF
*pnext
= NULL
;
1324 previous_line
->next
= NULL
;
1325 while (current_line
)
1327 pnext
= current_line
->next
;
1328 HeapFree(GetProcessHeap(), 0, current_line
);
1329 current_line
= pnext
;
1333 else if (delta
!= 0)
1335 while (current_line
)
1337 current_line
->index
+= delta
;
1338 current_line
= current_line
->next
;
1342 /* Calculate rest of modification rectangle */
1347 * We calculate two rectangles. One for the first line which may have
1348 * an indent with respect to the format rect. The other is a format-width
1349 * rectangle that spans the rest of the lines that changed or moved.
1351 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1352 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1353 rc
.bottom
= rc
.top
+ es
->line_height
;
1354 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1355 rc
.left
= es
->format_rect
.left
;
1357 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1358 es
->text
+ nstart_index
, istart
- nstart_index
,
1359 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1360 rc
.right
= es
->format_rect
.right
;
1361 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1364 rc
.left
= es
->format_rect
.left
;
1365 rc
.right
= es
->format_rect
.right
;
1367 * If lines were added or removed we must re-paint the remainder of the
1368 * lines since the remaining lines were either shifted up or down.
1370 if (line_count
< es
->line_count
) /* We added lines */
1371 rc
.bottom
= es
->line_count
* es
->line_height
;
1372 else if (line_count
> es
->line_count
) /* We removed lines */
1373 rc
.bottom
= line_count
* es
->line_height
;
1375 rc
.bottom
= line_index
* es
->line_height
;
1376 rc
.bottom
+= es
->format_rect
.top
;
1377 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1378 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1379 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1380 DeleteObject(tmphrgn
);
1384 SelectObject(dc
, old_font
);
1386 ReleaseDC(es
->hwndSelf
, dc
);
1389 /*********************************************************************
1391 * EDIT_CalcLineWidth_SL
1394 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1401 text
= EDIT_GetPasswordPointer_SL(es
);
1403 dc
= GetDC(es
->hwndSelf
);
1405 old_font
= SelectObject(dc
, es
->font
);
1407 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1410 SelectObject(dc
, old_font
);
1411 ReleaseDC(es
->hwndSelf
, dc
);
1413 if (es
->style
& ES_PASSWORD
)
1414 HeapFree(GetProcessHeap(), 0, text
);
1416 es
->text_width
= size
.cx
;
1419 /*********************************************************************
1421 * EDIT_CallWordBreakProc
1423 * Call appropriate WordBreakProc (internal or external).
1425 * Note: The "start" argument should always be an index referring
1426 * to es->text. The actual wordbreak proc might be
1427 * 16 bit, so we can't always pass any 32 bit LPSTR.
1428 * Hence we assume that es->text is the buffer that holds
1429 * the string under examination (we can decide this for ourselves).
1432 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1436 if (es
->word_break_proc16
) {
1443 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1444 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1445 segptr
= WOWGlobalLock16(hglob16
);
1446 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1447 args
[4] = SELECTOROF(segptr
);
1448 args
[3] = OFFSETOF(segptr
);
1452 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1453 ret
= LOWORD(result
);
1454 GlobalUnlock16(hglob16
);
1455 GlobalFree16(hglob16
);
1457 else if (es
->word_break_proc
)
1461 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1463 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1464 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1465 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1469 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1473 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1474 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1475 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1476 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1477 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1478 ret
= wbpA(textA
, index
, countA
, action
);
1479 HeapFree(GetProcessHeap(), 0, textA
);
1483 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1489 /*********************************************************************
1493 * Beware: This is not the function called on EM_CHARFROMPOS
1494 * The position _can_ be outside the formatting / client
1496 * The return value is only the character index
1499 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1504 INT x_high
= 0, x_low
= 0;
1506 if (es
->style
& ES_MULTILINE
) {
1507 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1509 LINEDEF
*line_def
= es
->first_line_def
;
1511 while ((line
> 0) && line_def
->next
) {
1512 line_index
+= line_def
->length
;
1513 line_def
= line_def
->next
;
1516 x
+= es
->x_offset
- es
->format_rect
.left
;
1517 if (es
->style
& ES_RIGHT
)
1518 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1519 else if (es
->style
& ES_CENTER
)
1520 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1521 if (x
>= line_def
->width
) {
1523 *after_wrap
= (line_def
->ending
== END_WRAP
);
1524 return line_index
+ line_def
->net_length
;
1528 *after_wrap
= FALSE
;
1531 dc
= GetDC(es
->hwndSelf
);
1533 old_font
= SelectObject(dc
, es
->font
);
1535 high
= line_index
+ line_def
->net_length
+ 1;
1536 while (low
< high
- 1)
1538 INT mid
= (low
+ high
) / 2;
1539 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1548 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1554 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1555 (line_def
->ending
== END_WRAP
));
1560 *after_wrap
= FALSE
;
1561 x
-= es
->format_rect
.left
;
1563 return es
->x_offset
;
1567 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1568 if (es
->style
& ES_RIGHT
)
1570 else if (es
->style
& ES_CENTER
)
1574 text
= EDIT_GetPasswordPointer_SL(es
);
1575 dc
= GetDC(es
->hwndSelf
);
1577 old_font
= SelectObject(dc
, es
->font
);
1581 INT high
= es
->x_offset
;
1582 while (low
< high
- 1)
1584 INT mid
= (low
+ high
) / 2;
1585 GetTextExtentPoint32W( dc
, text
+ mid
,
1586 es
->x_offset
- mid
, &size
);
1595 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1602 INT low
= es
->x_offset
;
1603 INT high
= get_text_length(es
) + 1;
1604 while (low
< high
- 1)
1606 INT mid
= (low
+ high
) / 2;
1607 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1608 mid
- es
->x_offset
, &size
);
1617 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1622 if (es
->style
& ES_PASSWORD
)
1623 HeapFree(GetProcessHeap(), 0, text
);
1626 SelectObject(dc
, old_font
);
1627 ReleaseDC(es
->hwndSelf
, dc
);
1632 /*********************************************************************
1636 * adjusts the point to be within the formatting rectangle
1637 * (so CharFromPos returns the nearest _visible_ character)
1640 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
1642 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1643 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1647 /*********************************************************************
1651 * Calculates the bounding rectangle for a line from a starting
1652 * column to an ending column.
1655 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1657 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1659 if (es
->style
& ES_MULTILINE
)
1660 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1662 rc
->top
= es
->format_rect
.top
;
1663 rc
->bottom
= rc
->top
+ es
->line_height
;
1664 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1665 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1669 /*********************************************************************
1671 * EDIT_GetPasswordPointer_SL
1673 * note: caller should free the (optionally) allocated buffer
1676 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1678 if (es
->style
& ES_PASSWORD
) {
1679 INT len
= get_text_length(es
);
1680 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1682 while(len
) text
[--len
] = es
->password_char
;
1689 /*********************************************************************
1693 * This acts as a LocalLock16(), but it locks only once. This way
1694 * you can call it whenever you like, without unlocking.
1696 * Initially the edit control allocates a HLOCAL32 buffer
1697 * (32 bit linear memory handler). However, 16 bit application
1698 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1699 * handler). From that moment on we have to keep using this 16 bit memory
1700 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1701 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1705 static void EDIT_LockBuffer(EDITSTATE
*es
)
1707 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1708 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1713 BOOL _16bit
= FALSE
;
1719 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1720 textA
= LocalLock(es
->hloc32A
);
1721 countA
= strlen(textA
) + 1;
1725 HANDLE16 oldDS
= stack16
->ds
;
1726 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1727 stack16
->ds
= hInstance
;
1728 textA
= MapSL(LocalLock16(es
->hloc16
));
1729 stack16
->ds
= oldDS
;
1730 countA
= strlen(textA
) + 1;
1735 ERR("no buffer ... please report\n");
1742 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1743 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1744 if(countW_new
> es
->buffer_size
+ 1)
1746 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1747 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1748 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1751 es
->hloc32W
= hloc32W_new
;
1752 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1753 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1756 WARN("FAILED! Will synchronize partially\n");
1760 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1761 es
->text
= LocalLock(es
->hloc32W
);
1765 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1768 HANDLE16 oldDS
= stack16
->ds
;
1769 stack16
->ds
= hInstance
;
1770 LocalUnlock16(es
->hloc16
);
1771 stack16
->ds
= oldDS
;
1774 LocalUnlock(es
->hloc32A
);
1777 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1782 /*********************************************************************
1784 * EDIT_SL_InvalidateText
1786 * Called from EDIT_InvalidateText().
1787 * Does the job for single-line controls only.
1790 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1795 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1796 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1797 EDIT_UpdateText(es
, &rc
, TRUE
);
1801 /*********************************************************************
1803 * EDIT_ML_InvalidateText
1805 * Called from EDIT_InvalidateText().
1806 * Does the job for multi-line controls only.
1809 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1811 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1812 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1813 INT el
= EDIT_EM_LineFromChar(es
, end
);
1822 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1825 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1826 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1827 if (sl
< es
->y_offset
) {
1831 if (el
> es
->y_offset
+ vlc
) {
1832 el
= es
->y_offset
+ vlc
;
1833 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1835 GetClientRect(es
->hwndSelf
, &rc1
);
1836 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1838 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1839 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1840 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1842 EDIT_GetLineRect(es
, sl
, sc
,
1843 EDIT_EM_LineLength(es
,
1844 EDIT_EM_LineIndex(es
, sl
)),
1846 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1847 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1848 for (l
= sl
+ 1 ; l
< el
; l
++) {
1849 EDIT_GetLineRect(es
, l
, 0,
1850 EDIT_EM_LineLength(es
,
1851 EDIT_EM_LineIndex(es
, l
)),
1853 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1854 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1856 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1857 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1858 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1863 /*********************************************************************
1865 * EDIT_InvalidateText
1867 * Invalidate the text from offset start up to, but not including,
1868 * offset end. Useful for (re)painting the selection.
1869 * Regions outside the linewidth are not invalidated.
1870 * end == -1 means end == TextLength.
1871 * start and end need not be ordered.
1874 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1880 end
= get_text_length(es
);
1888 if (es
->style
& ES_MULTILINE
)
1889 EDIT_ML_InvalidateText(es
, start
, end
);
1891 EDIT_SL_InvalidateText(es
, start
, end
);
1895 /*********************************************************************
1899 * Try to fit size + 1 characters in the buffer.
1901 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1905 if (size
<= es
->buffer_size
)
1908 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1910 /* Force edit to unlock it's buffer. es->text now NULL */
1911 EDIT_UnlockBuffer(es
, TRUE
);
1914 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1915 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1916 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1917 es
->hloc32W
= hNew32W
;
1918 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1922 EDIT_LockBuffer(es
);
1924 if (es
->buffer_size
< size
) {
1925 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1926 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1929 TRACE("We now have %d+1\n", es
->buffer_size
);
1935 /*********************************************************************
1939 * Try to fit size + 1 bytes in the undo buffer.
1942 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1946 if (size
<= es
->undo_buffer_size
)
1949 TRACE("trying to ReAlloc to %d+1\n", size
);
1951 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1952 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1953 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1958 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1964 /*********************************************************************
1969 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1971 INT e
= es
->selection_end
;
1975 if ((es
->style
& ES_MULTILINE
) && e
&&
1976 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1978 if (e
&& (es
->text
[e
- 1] == '\r'))
1982 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1983 EDIT_EM_ScrollCaret(es
);
1987 /*********************************************************************
1991 * Only for multi line controls
1992 * Move the caret one line down, on a column with the nearest
1993 * x coordinate on the screen (might be a different column).
1996 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1998 INT s
= es
->selection_start
;
1999 INT e
= es
->selection_end
;
2000 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2001 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2002 INT x
= (short)LOWORD(pos
);
2003 INT y
= (short)HIWORD(pos
);
2005 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
2008 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2009 EDIT_EM_ScrollCaret(es
);
2013 /*********************************************************************
2018 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
2020 BOOL after_wrap
= FALSE
;
2023 /* Pass a high value in x to make sure of receiving the end of the line */
2024 if (es
->style
& ES_MULTILINE
)
2025 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2026 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2028 e
= get_text_length(es
);
2029 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2030 EDIT_EM_ScrollCaret(es
);
2034 /*********************************************************************
2039 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2041 INT e
= es
->selection_end
;
2045 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2046 if (es
->text
[e
] == '\n')
2048 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2052 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2053 EDIT_EM_ScrollCaret(es
);
2057 /*********************************************************************
2061 * Home key: move to beginning of line.
2064 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2068 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2069 if (es
->style
& ES_MULTILINE
)
2070 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2071 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2074 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2075 EDIT_EM_ScrollCaret(es
);
2079 /*********************************************************************
2081 * EDIT_MovePageDown_ML
2083 * Only for multi line controls
2084 * Move the caret one page down, on a column with the nearest
2085 * x coordinate on the screen (might be a different column).
2088 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2090 INT s
= es
->selection_start
;
2091 INT e
= es
->selection_end
;
2092 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2093 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2094 INT x
= (short)LOWORD(pos
);
2095 INT y
= (short)HIWORD(pos
);
2097 e
= EDIT_CharFromPos(es
, x
,
2098 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2102 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2103 EDIT_EM_ScrollCaret(es
);
2107 /*********************************************************************
2109 * EDIT_MovePageUp_ML
2111 * Only for multi line controls
2112 * Move the caret one page up, on a column with the nearest
2113 * x coordinate on the screen (might be a different column).
2116 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2118 INT s
= es
->selection_start
;
2119 INT e
= es
->selection_end
;
2120 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2121 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2122 INT x
= (short)LOWORD(pos
);
2123 INT y
= (short)HIWORD(pos
);
2125 e
= EDIT_CharFromPos(es
, x
,
2126 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2130 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2131 EDIT_EM_ScrollCaret(es
);
2135 /*********************************************************************
2139 * Only for multi line controls
2140 * Move the caret one line up, on a column with the nearest
2141 * x coordinate on the screen (might be a different column).
2144 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2146 INT s
= es
->selection_start
;
2147 INT e
= es
->selection_end
;
2148 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2149 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2150 INT x
= (short)LOWORD(pos
);
2151 INT y
= (short)HIWORD(pos
);
2153 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2156 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2157 EDIT_EM_ScrollCaret(es
);
2161 /*********************************************************************
2163 * EDIT_MoveWordBackward
2166 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2168 INT s
= es
->selection_start
;
2169 INT e
= es
->selection_end
;
2174 l
= EDIT_EM_LineFromChar(es
, e
);
2175 ll
= EDIT_EM_LineLength(es
, e
);
2176 li
= EDIT_EM_LineIndex(es
, l
);
2179 li
= EDIT_EM_LineIndex(es
, l
- 1);
2180 e
= li
+ EDIT_EM_LineLength(es
, li
);
2183 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2187 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2188 EDIT_EM_ScrollCaret(es
);
2192 /*********************************************************************
2194 * EDIT_MoveWordForward
2197 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2199 INT s
= es
->selection_start
;
2200 INT e
= es
->selection_end
;
2205 l
= EDIT_EM_LineFromChar(es
, e
);
2206 ll
= EDIT_EM_LineLength(es
, e
);
2207 li
= EDIT_EM_LineIndex(es
, l
);
2209 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2210 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2212 e
= li
+ EDIT_CallWordBreakProc(es
,
2213 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2217 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2218 EDIT_EM_ScrollCaret(es
);
2222 /*********************************************************************
2227 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2229 INT s
= es
->selection_start
;
2230 INT e
= es
->selection_end
;
2237 if (es
->style
& ES_MULTILINE
) {
2238 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2239 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2244 TRACE("line=%d\n", line
);
2246 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2247 x
= (short)LOWORD(pos
);
2248 y
= (short)HIWORD(pos
);
2249 li
= EDIT_EM_LineIndex(es
, line
);
2250 ll
= EDIT_EM_LineLength(es
, li
);
2251 s
= min(es
->selection_start
, es
->selection_end
);
2252 e
= max(es
->selection_start
, es
->selection_end
);
2253 s
= min(li
+ ll
, max(li
, s
));
2254 e
= min(li
+ ll
, max(li
, e
));
2255 if (rev
&& (s
!= e
) &&
2256 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2257 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2258 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2259 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2261 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2265 /*********************************************************************
2270 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2274 LOGFONTW underline_font
;
2275 HFONT hUnderline
= 0;
2284 BkMode
= GetBkMode(dc
);
2285 BkColor
= GetBkColor(dc
);
2286 TextColor
= GetTextColor(dc
);
2288 if (es
->composition_len
== 0)
2290 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2291 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2292 SetBkMode( dc
, OPAQUE
);
2296 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2297 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2298 underline_font
.lfUnderline
= TRUE
;
2299 hUnderline
= CreateFontIndirectW(&underline_font
);
2300 old_font
= SelectObject(dc
,hUnderline
);
2303 li
= EDIT_EM_LineIndex(es
, line
);
2304 if (es
->style
& ES_MULTILINE
) {
2305 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2306 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2308 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2309 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2310 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2312 if (es
->style
& ES_PASSWORD
)
2313 HeapFree(GetProcessHeap(), 0, text
);
2316 if (es
->composition_len
== 0)
2318 SetBkColor(dc
, BkColor
);
2319 SetTextColor(dc
, TextColor
);
2320 SetBkMode( dc
, BkMode
);
2325 SelectObject(dc
,old_font
);
2327 DeleteObject(hUnderline
);
2334 /*********************************************************************
2339 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2342 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2343 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2344 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2348 /*********************************************************************
2350 * EDIT_AdjustFormatRect
2352 * Adjusts the format rectangle for the current font and the
2353 * current client rectangle.
2356 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2360 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2361 if (es
->style
& ES_MULTILINE
)
2363 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2365 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2366 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2368 /* correct es->x_offset */
2369 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2370 max_x_offset
= es
->text_width
- fw
;
2371 if(max_x_offset
< 0) max_x_offset
= 0;
2372 if(es
->x_offset
> max_x_offset
)
2373 es
->x_offset
= max_x_offset
;
2375 /* correct es->y_offset */
2376 max_y_offset
= es
->line_count
- vlc
;
2377 if(max_y_offset
< 0) max_y_offset
= 0;
2378 if(es
->y_offset
> max_y_offset
)
2379 es
->y_offset
= max_y_offset
;
2381 /* force scroll info update */
2382 EDIT_UpdateScrollInfo(es
);
2385 /* Windows doesn't care to fix text placement for SL controls */
2386 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2388 /* Always stay within the client area */
2389 GetClientRect(es
->hwndSelf
, &ClientRect
);
2390 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2392 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2393 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2395 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2399 /*********************************************************************
2403 * note: this is not (exactly) the handler called on EM_SETRECTNP
2404 * it is also used to set the rect of a single line control
2407 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2411 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2413 CopyRect(&es
->format_rect
, rc
);
2415 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2416 es
->format_rect
.left
++;
2417 es
->format_rect
.right
--;
2419 if (es
->format_rect
.bottom
- es
->format_rect
.top
2420 >= es
->line_height
+ 2)
2422 es
->format_rect
.top
++;
2423 es
->format_rect
.bottom
--;
2426 else if (es
->style
& WS_BORDER
) {
2427 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2428 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2429 es
->format_rect
.left
+= bw
;
2430 es
->format_rect
.right
-= bw
;
2431 if (es
->format_rect
.bottom
- es
->format_rect
.top
2432 >= es
->line_height
+ 2 * bh
)
2434 es
->format_rect
.top
+= bh
;
2435 es
->format_rect
.bottom
-= bh
;
2439 es
->format_rect
.left
+= es
->left_margin
;
2440 es
->format_rect
.right
-= es
->right_margin
;
2441 EDIT_AdjustFormatRect(es
);
2445 /*********************************************************************
2450 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2453 /* Edit window might be already destroyed */
2454 if(!IsWindow(es
->hwndSelf
))
2456 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2460 if (!es
->lock_count
) {
2461 ERR("lock_count == 0 ... please report\n");
2465 ERR("es->text == 0 ... please report\n");
2469 if (force
|| (es
->lock_count
== 1)) {
2473 UINT countW
= get_text_length(es
) + 1;
2474 STACK16FRAME
* stack16
= NULL
;
2479 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2480 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2481 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2482 countA
= LocalSize(es
->hloc32A
);
2483 if(countA_new
> countA
)
2486 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2487 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2488 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2491 es
->hloc32A
= hloc32A_new
;
2492 countA
= LocalSize(hloc32A_new
);
2493 TRACE("Real new size %d bytes\n", countA
);
2496 WARN("FAILED! Will synchronize partially\n");
2498 textA
= LocalLock(es
->hloc32A
);
2502 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2504 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2505 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2507 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2508 oldDS
= stack16
->ds
;
2509 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2511 countA
= LocalSize16(es
->hloc16
);
2512 if(countA_new
> countA
)
2514 HLOCAL16 hloc16_new
;
2515 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2516 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2517 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2520 es
->hloc16
= hloc16_new
;
2521 countA
= LocalSize16(hloc16_new
);
2522 TRACE("Real new size %d bytes\n", countA
);
2525 WARN("FAILED! Will synchronize partially\n");
2527 textA
= MapSL(LocalLock16(es
->hloc16
));
2532 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2534 LocalUnlock16(es
->hloc16
);
2536 LocalUnlock(es
->hloc32A
);
2539 if (stack16
) stack16
->ds
= oldDS
;
2540 LocalUnlock(es
->hloc32W
);
2544 ERR("no buffer ... please report\n");
2552 /*********************************************************************
2554 * EDIT_UpdateScrollInfo
2557 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2559 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2562 si
.cbSize
= sizeof(SCROLLINFO
);
2563 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2565 si
.nMax
= es
->line_count
- 1;
2566 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2567 si
.nPos
= es
->y_offset
;
2568 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2569 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2570 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2573 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2576 si
.cbSize
= sizeof(SCROLLINFO
);
2577 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2579 si
.nMax
= es
->text_width
- 1;
2580 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2581 si
.nPos
= es
->x_offset
;
2582 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2583 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2584 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2588 /*********************************************************************
2590 * EDIT_WordBreakProc
2592 * Find the beginning of words.
2593 * Note: unlike the specs for a WordBreakProc, this function only
2594 * allows to be called without linebreaks between s[0] up to
2595 * s[count - 1]. Remember it is only called
2596 * internally, so we can decide this for ourselves.
2599 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2603 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2613 if (s
[index
] == ' ') {
2614 while (index
&& (s
[index
] == ' '))
2617 while (index
&& (s
[index
] != ' '))
2619 if (s
[index
] == ' ')
2623 while (index
&& (s
[index
] != ' '))
2625 if (s
[index
] == ' ')
2635 if (s
[index
] == ' ')
2636 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2638 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2640 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2644 case WB_ISDELIMITER
:
2645 ret
= (s
[index
] == ' ');
2648 ERR("unknown action code, please report !\n");
2655 /*********************************************************************
2659 * returns line number (not index) in high-order word of result.
2660 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2661 * to Richedit, not to the edit control. Original documentation is valid.
2662 * FIXME: do the specs mean to return -1 if outside client area or
2663 * if outside formatting rectangle ???
2666 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2674 GetClientRect(es
->hwndSelf
, &rc
);
2675 if (!PtInRect(&rc
, pt
))
2678 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2679 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2683 /*********************************************************************
2687 * Enable or disable soft breaks.
2689 * This means: insert or remove the soft linebreak character (\r\r\n).
2690 * Take care to check if the text still fits the buffer after insertion.
2691 * If not, notify with EN_ERRSPACE.
2694 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2696 es
->flags
&= ~EF_USE_SOFTBRK
;
2698 es
->flags
|= EF_USE_SOFTBRK
;
2699 FIXME("soft break enabled, not implemented\n");
2705 /*********************************************************************
2709 * Hopefully this won't fire back at us.
2710 * We always start with a fixed buffer in the local heap.
2711 * Despite of the documentation says that the local heap is used
2712 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2713 * buffer on the local heap.
2716 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2720 if (!(es
->style
& ES_MULTILINE
))
2724 hLocal
= es
->hloc32W
;
2730 UINT countA
, alloc_size
;
2731 TRACE("Allocating 32-bit ANSI alias buffer\n");
2732 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2733 alloc_size
= ROUND_TO_GROW(countA
);
2734 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2736 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2739 textA
= LocalLock(es
->hloc32A
);
2740 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2741 LocalUnlock(es
->hloc32A
);
2743 hLocal
= es
->hloc32A
;
2746 es
->flags
|= EF_APP_HAS_HANDLE
;
2747 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2752 /*********************************************************************
2756 * Hopefully this won't fire back at us.
2757 * We always start with a buffer in 32 bit linear memory.
2758 * However, with this message a 16 bit application requests
2759 * a handle of 16 bit local heap memory, where it expects to find
2761 * It's a pitty that from this moment on we have to use this
2762 * local heap, because applications may rely on the handle
2765 * In this function we'll try to switch to local heap.
2767 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2770 UINT countA
, alloc_size
;
2771 STACK16FRAME
* stack16
;
2774 if (!(es
->style
& ES_MULTILINE
))
2780 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2781 oldDS
= stack16
->ds
;
2782 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2784 if (!LocalHeapSize16()) {
2786 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2787 ERR("could not initialize local heap\n");
2790 TRACE("local heap initialized\n");
2793 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2794 alloc_size
= ROUND_TO_GROW(countA
);
2796 TRACE("Allocating 16-bit ANSI alias buffer\n");
2797 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2798 ERR("could not allocate new 16 bit buffer\n");
2802 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2803 ERR("could not lock new 16 bit buffer\n");
2804 LocalFree16(es
->hloc16
);
2809 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2810 LocalUnlock16(es
->hloc16
);
2811 es
->flags
|= EF_APP_HAS_HANDLE
;
2813 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2816 stack16
->ds
= oldDS
;
2821 /*********************************************************************
2826 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2829 INT line_len
, dst_len
;
2832 if (es
->style
& ES_MULTILINE
) {
2833 if (line
>= es
->line_count
)
2837 i
= EDIT_EM_LineIndex(es
, line
);
2839 line_len
= EDIT_EM_LineLength(es
, i
);
2840 dst_len
= *(WORD
*)dst
;
2843 if(dst_len
<= line_len
)
2845 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2848 else /* Append 0 if enough space */
2850 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2857 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2858 if(!ret
&& line_len
) /* Insufficient buffer size */
2860 if(ret
< dst_len
) /* Append 0 if enough space */
2861 ((LPSTR
)dst
)[ret
] = 0;
2867 /*********************************************************************
2872 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2874 UINT s
= es
->selection_start
;
2875 UINT e
= es
->selection_end
;
2882 return MAKELONG(s
, e
);
2886 /*********************************************************************
2890 * FIXME: is this right ? (or should it be only VSCROLL)
2891 * (and maybe only for edit controls that really have their
2892 * own scrollbars) (and maybe only for multiline controls ?)
2893 * All in all: very poorly documented
2896 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2898 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2899 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2903 /*********************************************************************
2908 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2913 if (!(es
->style
& ES_MULTILINE
))
2915 if (index
> (INT
)get_text_length(es
))
2916 return es
->line_count
- 1;
2918 index
= min(es
->selection_start
, es
->selection_end
);
2921 line_def
= es
->first_line_def
;
2922 index
-= line_def
->length
;
2923 while ((index
>= 0) && line_def
->next
) {
2925 line_def
= line_def
->next
;
2926 index
-= line_def
->length
;
2932 /*********************************************************************
2937 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
2940 const LINEDEF
*line_def
;
2942 if (!(es
->style
& ES_MULTILINE
))
2944 if (line
>= es
->line_count
)
2948 line_def
= es
->first_line_def
;
2950 INT index
= es
->selection_end
- line_def
->length
;
2951 while ((index
>= 0) && line_def
->next
) {
2952 line_index
+= line_def
->length
;
2953 line_def
= line_def
->next
;
2954 index
-= line_def
->length
;
2958 line_index
+= line_def
->length
;
2959 line_def
= line_def
->next
;
2967 /*********************************************************************
2972 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2976 if (!(es
->style
& ES_MULTILINE
))
2977 return get_text_length(es
);
2980 /* get the number of remaining non-selected chars of selected lines */
2981 INT32 l
; /* line number */
2982 INT32 li
; /* index of first char in line */
2984 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2985 /* # chars before start of selection area */
2986 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2987 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2988 /* # chars after end of selection */
2989 li
= EDIT_EM_LineIndex(es
, l
);
2990 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2993 line_def
= es
->first_line_def
;
2994 index
-= line_def
->length
;
2995 while ((index
>= 0) && line_def
->next
) {
2996 line_def
= line_def
->next
;
2997 index
-= line_def
->length
;
2999 return line_def
->net_length
;
3003 /*********************************************************************
3007 * NOTE: dx is in average character widths, dy - in lines;
3010 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
3012 if (!(es
->style
& ES_MULTILINE
))
3015 dx
*= es
->char_width
;
3016 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3019 /*********************************************************************
3021 * EDIT_EM_LineScroll_internal
3023 * Version of EDIT_EM_LineScroll for internal use.
3024 * It doesn't refuse if ES_MULTILINE is set and assumes that
3025 * dx is in pixels, dy - in lines.
3028 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3031 INT x_offset_in_pixels
;
3032 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3035 if (es
->style
& ES_MULTILINE
)
3037 x_offset_in_pixels
= es
->x_offset
;
3042 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3045 if (-dx
> x_offset_in_pixels
)
3046 dx
= -x_offset_in_pixels
;
3047 if (dx
> es
->text_width
- x_offset_in_pixels
)
3048 dx
= es
->text_width
- x_offset_in_pixels
;
3049 nyoff
= max(0, es
->y_offset
+ dy
);
3050 if (nyoff
>= es
->line_count
- lines_per_page
)
3051 nyoff
= max(0, es
->line_count
- lines_per_page
);
3052 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3057 es
->y_offset
= nyoff
;
3058 if(es
->style
& ES_MULTILINE
)
3061 es
->x_offset
+= dx
/ es
->char_width
;
3063 GetClientRect(es
->hwndSelf
, &rc1
);
3064 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3065 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3066 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3067 /* force scroll info update */
3068 EDIT_UpdateScrollInfo(es
);
3070 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3071 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3072 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3073 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3078 /*********************************************************************
3083 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3085 INT len
= get_text_length(es
);
3098 index
= min(index
, len
);
3099 dc
= GetDC(es
->hwndSelf
);
3101 old_font
= SelectObject(dc
, es
->font
);
3102 if (es
->style
& ES_MULTILINE
) {
3103 l
= EDIT_EM_LineFromChar(es
, index
);
3104 y
= (l
- es
->y_offset
) * es
->line_height
;
3105 li
= EDIT_EM_LineIndex(es
, l
);
3106 if (after_wrap
&& (li
== index
) && l
) {
3108 line_def
= es
->first_line_def
;
3110 line_def
= line_def
->next
;
3113 if (line_def
->ending
== END_WRAP
) {
3115 y
-= es
->line_height
;
3116 li
= EDIT_EM_LineIndex(es
, l
);
3120 line_def
= es
->first_line_def
;
3121 while (line_def
->index
!= li
)
3122 line_def
= line_def
->next
;
3124 ll
= line_def
->net_length
;
3125 lw
= line_def
->width
;
3127 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3128 if (es
->style
& ES_RIGHT
)
3130 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3131 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3134 else if (es
->style
& ES_CENTER
)
3136 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3137 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3142 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3143 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3146 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3147 if (index
< es
->x_offset
) {
3148 GetTextExtentPoint32W(dc
, text
+ index
,
3149 es
->x_offset
- index
, &size
);
3152 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3153 index
- es
->x_offset
, &size
);
3156 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3158 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3159 if (w
> es
->text_width
)
3161 if (es
->style
& ES_RIGHT
)
3162 x
+= w
- es
->text_width
;
3163 else if (es
->style
& ES_CENTER
)
3164 x
+= (w
- es
->text_width
) / 2;
3169 if (es
->style
& ES_PASSWORD
)
3170 HeapFree(GetProcessHeap(), 0, text
);
3172 x
+= es
->format_rect
.left
;
3173 y
+= es
->format_rect
.top
;
3175 SelectObject(dc
, old_font
);
3176 ReleaseDC(es
->hwndSelf
, dc
);
3177 return MAKELONG((INT16
)x
, (INT16
)y
);
3181 /*********************************************************************
3185 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3188 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3190 UINT strl
= strlenW(lpsz_replace
);
3191 UINT tl
= get_text_length(es
);
3202 TRACE("%s, can_undo %d, send_update %d\n",
3203 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3205 s
= es
->selection_start
;
3206 e
= es
->selection_end
;
3208 if ((s
== e
) && !strl
)
3213 size
= tl
- (e
- s
) + strl
;
3217 /* Issue the EN_MAXTEXT notification and continue with replacing text
3218 * such that buffer limit is honored. */
3219 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
3220 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3221 /* Buffer limit can be smaller than the actual length of text in combobox */
3222 if (es
->buffer_limit
< (tl
- (e
-s
)))
3225 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3228 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3232 /* there is something to be deleted */
3233 TRACE("deleting stuff.\n");
3235 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3237 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3238 buf
[bufl
] = 0; /* ensure 0 termination */
3240 strcpyW(es
->text
+ s
, es
->text
+ e
);
3241 text_buffer_changed(es
);
3244 /* there is an insertion */
3245 tl
= get_text_length(es
);
3246 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
));
3247 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3249 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3250 p
[i
] = lpsz_replace
[i
];
3251 if(es
->style
& ES_UPPERCASE
)
3252 CharUpperBuffW(p
, strl
);
3253 else if(es
->style
& ES_LOWERCASE
)
3254 CharLowerBuffW(p
, strl
);
3255 text_buffer_changed(es
);
3257 if (es
->style
& ES_MULTILINE
)
3259 INT st
= min(es
->selection_start
, es
->selection_end
);
3260 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3262 hrgn
= CreateRectRgn(0, 0, 0, 0);
3263 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3264 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3265 /* if text is too long undo all changes */
3266 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3268 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3270 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3272 text_buffer_changed(es
);
3273 EDIT_BuildLineDefs_ML(es
, s
, e
,
3274 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3277 hrgn
= CreateRectRgn(0, 0, 0, 0);
3278 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3282 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3283 EDIT_CalcLineWidth_SL(es
);
3284 /* remove chars that don't fit */
3285 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3286 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3287 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3289 EDIT_CalcLineWidth_SL(es
);
3291 text_buffer_changed(es
);
3292 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3298 utl
= strlenW(es
->undo_text
);
3299 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3300 /* undo-buffer is extended to the right */
3301 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3302 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3303 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3304 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3305 /* undo-buffer is extended to the left */
3306 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3307 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3309 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3311 es
->undo_position
= s
;
3313 /* new undo-buffer */
3314 EDIT_MakeUndoFit(es
, e
- s
);
3315 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3316 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3317 es
->undo_position
= s
;
3319 /* any deletion makes the old insertion-undo invalid */
3320 es
->undo_insert_count
= 0;
3322 EDIT_EM_EmptyUndoBuffer(es
);
3326 if ((s
== es
->undo_position
) ||
3327 ((es
->undo_insert_count
) &&
3328 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3330 * insertion is new and at delete position or
3331 * an extension to either left or right
3333 es
->undo_insert_count
+= strl
;
3335 /* new insertion undo */
3336 es
->undo_position
= s
;
3337 es
->undo_insert_count
= strl
;
3338 /* new insertion makes old delete-buffer invalid */
3339 *es
->undo_text
= '\0';
3342 EDIT_EM_EmptyUndoBuffer(es
);
3346 HeapFree(GetProcessHeap(), 0, buf
);
3350 /* If text has been deleted and we're right or center aligned then scroll rightward */
3351 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3353 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3355 if (delta
< 0 && es
->x_offset
)
3357 if (abs(delta
) > es
->x_offset
)
3360 es
->x_offset
+= delta
;
3364 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3365 es
->flags
|= EF_MODIFIED
;
3366 if (send_update
) es
->flags
|= EF_UPDATE
;
3369 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3373 EDIT_UpdateText(es
, NULL
, TRUE
);
3375 EDIT_EM_ScrollCaret(es
);
3377 /* force scroll info update */
3378 EDIT_UpdateScrollInfo(es
);
3381 if(send_update
|| (es
->flags
& EF_UPDATE
))
3383 es
->flags
&= ~EF_UPDATE
;
3384 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3389 /*********************************************************************
3394 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3398 if (!(es
->style
& ES_MULTILINE
))
3399 return (LRESULT
)FALSE
;
3409 if (es
->y_offset
< es
->line_count
- 1)
3414 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3417 if (es
->y_offset
< es
->line_count
- 1)
3418 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3421 return (LRESULT
)FALSE
;
3424 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3425 /* check if we are going to move too far */
3426 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3427 dy
= es
->line_count
- vlc
- es
->y_offset
;
3429 /* Notification is done in EDIT_EM_LineScroll */
3431 EDIT_EM_LineScroll(es
, 0, dy
);
3433 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3437 /*********************************************************************
3442 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3444 if (es
->style
& ES_MULTILINE
) {
3449 INT cw
= es
->char_width
;
3454 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3455 li
= EDIT_EM_LineIndex(es
, l
);
3456 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3457 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3458 if (l
>= es
->y_offset
+ vlc
)
3459 dy
= l
- vlc
+ 1 - es
->y_offset
;
3460 if (l
< es
->y_offset
)
3461 dy
= l
- es
->y_offset
;
3462 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3463 if (x
< es
->format_rect
.left
)
3464 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3465 if (x
> es
->format_rect
.right
)
3466 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3467 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3469 /* check if we are going to move too far */
3470 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3471 dx
= es
->text_width
- ww
- es
->x_offset
;
3472 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3473 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3480 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3481 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3482 if (x
< es
->format_rect
.left
) {
3483 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3486 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3487 } while ((x
< goal
) && es
->x_offset
);
3488 /* FIXME: use ScrollWindow() somehow to improve performance */
3489 EDIT_UpdateText(es
, NULL
, TRUE
);
3490 } else if (x
> es
->format_rect
.right
) {
3492 INT len
= get_text_length(es
);
3493 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3496 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3497 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3498 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3499 /* FIXME: use ScrollWindow() somehow to improve performance */
3500 EDIT_UpdateText(es
, NULL
, TRUE
);
3504 if(es
->flags
& EF_FOCUSED
)
3505 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3509 /*********************************************************************
3513 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3516 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3518 if (!(es
->style
& ES_MULTILINE
))
3522 WARN("called with NULL handle\n");
3526 EDIT_UnlockBuffer(es
, TRUE
);
3530 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3531 HANDLE16 oldDS
= stack16
->ds
;
3533 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3534 LocalFree16(es
->hloc16
);
3535 stack16
->ds
= oldDS
;
3543 LocalFree(es
->hloc32A
);
3555 countA
= LocalSize(hloc
);
3556 textA
= LocalLock(hloc
);
3557 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3558 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3560 ERR("Could not allocate new unicode buffer\n");
3563 textW
= LocalLock(hloc32W_new
);
3564 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3565 LocalUnlock(hloc32W_new
);
3569 LocalFree(es
->hloc32W
);
3571 es
->hloc32W
= hloc32W_new
;
3575 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3577 es
->flags
|= EF_APP_HAS_HANDLE
;
3578 EDIT_LockBuffer(es
);
3580 es
->x_offset
= es
->y_offset
= 0;
3581 es
->selection_start
= es
->selection_end
= 0;
3582 EDIT_EM_EmptyUndoBuffer(es
);
3583 es
->flags
&= ~EF_MODIFIED
;
3584 es
->flags
&= ~EF_UPDATE
;
3585 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3586 EDIT_UpdateText(es
, NULL
, TRUE
);
3587 EDIT_EM_ScrollCaret(es
);
3588 /* force scroll info update */
3589 EDIT_UpdateScrollInfo(es
);
3593 /*********************************************************************
3597 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3600 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3602 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3603 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3604 HANDLE16 oldDS
= stack16
->ds
;
3610 if (!(es
->style
& ES_MULTILINE
))
3614 WARN("called with NULL handle\n");
3618 EDIT_UnlockBuffer(es
, TRUE
);
3622 LocalFree(es
->hloc32A
);
3626 stack16
->ds
= hInstance
;
3627 countA
= LocalSize16(hloc
);
3628 textA
= MapSL(LocalLock16(hloc
));
3629 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3630 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3632 ERR("Could not allocate new unicode buffer\n");
3635 textW
= LocalLock(hloc32W_new
);
3636 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3637 LocalUnlock(hloc32W_new
);
3638 LocalUnlock16(hloc
);
3639 stack16
->ds
= oldDS
;
3642 LocalFree(es
->hloc32W
);
3644 es
->hloc32W
= hloc32W_new
;
3647 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3649 es
->flags
|= EF_APP_HAS_HANDLE
;
3650 EDIT_LockBuffer(es
);
3652 es
->x_offset
= es
->y_offset
= 0;
3653 es
->selection_start
= es
->selection_end
= 0;
3654 EDIT_EM_EmptyUndoBuffer(es
);
3655 es
->flags
&= ~EF_MODIFIED
;
3656 es
->flags
&= ~EF_UPDATE
;
3657 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3658 EDIT_UpdateText(es
, NULL
, TRUE
);
3659 EDIT_EM_ScrollCaret(es
);
3660 /* force scroll info update */
3661 EDIT_UpdateScrollInfo(es
);
3665 /*********************************************************************
3669 * NOTE: this version currently implements WinNT limits
3672 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
3674 if (!limit
) limit
= ~0u;
3675 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
3676 es
->buffer_limit
= limit
;
3680 /*********************************************************************
3684 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3685 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3686 * margin according to the textmetrics of the current font.
3688 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3689 * of the char's width as the margin, but this is not how Windows handles this.
3690 * For all other fonts Windows sets the margins to zero.
3692 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3693 * edit control is equal to or larger than a certain size.
3694 * Interestingly if one subtracts both the left and right margins from
3695 * this size one always seems to get an even number. The extents of
3696 * the (four character) string "'**'" match this quite closely, so
3697 * we'll use this until we come up with a better idea.
3699 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3701 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3704 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3705 return sz
.cx
+ left
+ right
;
3708 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3709 WORD left
, WORD right
, BOOL repaint
)
3712 INT default_left_margin
= 0; /* in pixels */
3713 INT default_right_margin
= 0; /* in pixels */
3715 /* Set the default margins depending on the font */
3716 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3717 HDC dc
= GetDC(es
->hwndSelf
);
3718 HFONT old_font
= SelectObject(dc
, es
->font
);
3719 GetTextMetricsW(dc
, &tm
);
3720 /* The default margins are only non zero for TrueType or Vector fonts */
3721 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3724 /* This must be calculated more exactly! But how? */
3725 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3726 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3727 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3728 GetClientRect(es
->hwndSelf
, &rc
);
3729 if(rc
.right
- rc
.left
< min_size
) {
3730 default_left_margin
= es
->left_margin
;
3731 default_right_margin
= es
->right_margin
;
3734 SelectObject(dc
, old_font
);
3735 ReleaseDC(es
->hwndSelf
, dc
);
3738 if (action
& EC_LEFTMARGIN
) {
3739 es
->format_rect
.left
-= es
->left_margin
;
3740 if (left
!= EC_USEFONTINFO
)
3741 es
->left_margin
= left
;
3743 es
->left_margin
= default_left_margin
;
3744 es
->format_rect
.left
+= es
->left_margin
;
3747 if (action
& EC_RIGHTMARGIN
) {
3748 es
->format_rect
.right
+= es
->right_margin
;
3749 if (right
!= EC_USEFONTINFO
)
3750 es
->right_margin
= right
;
3752 es
->right_margin
= default_right_margin
;
3753 es
->format_rect
.right
-= es
->right_margin
;
3756 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3757 EDIT_AdjustFormatRect(es
);
3758 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3761 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3765 /*********************************************************************
3767 * EM_SETPASSWORDCHAR
3770 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3774 if (es
->style
& ES_MULTILINE
)
3777 if (es
->password_char
== c
)
3780 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3781 es
->password_char
= c
;
3783 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3784 es
->style
|= ES_PASSWORD
;
3786 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3787 es
->style
&= ~ES_PASSWORD
;
3789 EDIT_UpdateText(es
, NULL
, TRUE
);
3793 /*********************************************************************
3797 * note: unlike the specs say: the order of start and end
3798 * _is_ preserved in Windows. (i.e. start can be > end)
3799 * In other words: this handler is OK
3802 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3804 UINT old_start
= es
->selection_start
;
3805 UINT old_end
= es
->selection_end
;
3806 UINT len
= get_text_length(es
);
3808 if (start
== (UINT
)-1) {
3809 start
= es
->selection_end
;
3810 end
= es
->selection_end
;
3812 start
= min(start
, len
);
3813 end
= min(end
, len
);
3815 es
->selection_start
= start
;
3816 es
->selection_end
= end
;
3818 es
->flags
|= EF_AFTER_WRAP
;
3820 es
->flags
&= ~EF_AFTER_WRAP
;
3821 /* Compute the necessary invalidation region. */
3822 /* Note that we don't need to invalidate regions which have
3823 * "never" been selected, or those which are "still" selected.
3824 * In fact, every time we hit a selection boundary, we can
3825 * *toggle* whether we need to invalidate. Thus we can optimize by
3826 * *sorting* the interval endpoints. Let's assume that we sort them
3828 * start <= end <= old_start <= old_end
3829 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3830 * in 5 comparisons; ie it's impossible to do better than the
3832 ORDER_UINT(end
, old_end
);
3833 ORDER_UINT(start
, old_start
);
3834 ORDER_UINT(old_start
, old_end
);
3835 ORDER_UINT(start
, end
);
3836 /* Note that at this point 'end' and 'old_start' are not in order, but
3837 * start is definitely the min. and old_end is definitely the max. */
3838 if (end
!= old_start
)
3842 * ORDER_UINT32(end, old_start);
3843 * EDIT_InvalidateText(es, start, end);
3844 * EDIT_InvalidateText(es, old_start, old_end);
3845 * in place of the following if statement.
3846 * (That would complete the optimal five-comparison four-element sort.)
3848 if (old_start
> end
)
3850 EDIT_InvalidateText(es
, start
, end
);
3851 EDIT_InvalidateText(es
, old_start
, old_end
);
3855 EDIT_InvalidateText(es
, start
, old_start
);
3856 EDIT_InvalidateText(es
, end
, old_end
);
3859 else EDIT_InvalidateText(es
, start
, old_end
);
3863 /*********************************************************************
3868 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3870 if (!(es
->style
& ES_MULTILINE
))
3872 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3873 es
->tabs_count
= count
;
3877 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3878 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3884 /*********************************************************************
3889 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3891 if (!(es
->style
& ES_MULTILINE
))
3893 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3894 es
->tabs_count
= count
;
3899 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3900 for (i
= 0 ; i
< count
; i
++)
3901 es
->tabs
[i
] = *tabs
++;
3907 /*********************************************************************
3909 * EM_SETWORDBREAKPROC
3912 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3914 if (es
->word_break_proc
== wbp
)
3917 es
->word_break_proc
= wbp
;
3918 es
->word_break_proc16
= NULL
;
3920 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3921 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3922 EDIT_UpdateText(es
, NULL
, TRUE
);
3927 /*********************************************************************
3929 * EM_SETWORDBREAKPROC16
3932 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3934 if (es
->word_break_proc16
== wbp
)
3937 es
->word_break_proc
= NULL
;
3938 es
->word_break_proc16
= wbp
;
3939 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3940 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3941 EDIT_UpdateText(es
, NULL
, TRUE
);
3946 /*********************************************************************
3951 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3956 /* As per MSDN spec, for a single-line edit control,
3957 the return value is always TRUE */
3958 if( es
->style
& ES_READONLY
)
3959 return !(es
->style
& ES_MULTILINE
);
3961 ulength
= strlenW(es
->undo_text
);
3963 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3965 strcpyW(utext
, es
->undo_text
);
3967 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3968 es
->undo_insert_count
, debugstr_w(utext
));
3970 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3971 EDIT_EM_EmptyUndoBuffer(es
);
3972 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3973 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3974 /* send the notification after the selection start and end are set */
3975 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3976 EDIT_EM_ScrollCaret(es
);
3977 HeapFree(GetProcessHeap(), 0, utext
);
3979 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3980 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3985 /*********************************************************************
3990 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3994 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3998 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3999 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
4002 if (es
->style
& ES_MULTILINE
) {
4003 if (es
->style
& ES_READONLY
) {
4004 EDIT_MoveHome(es
, FALSE
);
4005 EDIT_MoveDown_ML(es
, FALSE
);
4007 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4008 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4013 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4015 static const WCHAR tabW
[] = {'\t',0};
4016 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4020 if (!(es
->style
& ES_READONLY
) && !control
) {
4021 if (es
->selection_start
!= es
->selection_end
)
4024 /* delete character left of caret */
4025 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4026 EDIT_MoveBackward(es
, TRUE
);
4032 if (!(es
->style
& ES_PASSWORD
))
4033 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4036 if (!(es
->style
& ES_READONLY
))
4037 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4040 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4041 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4044 if (!(es
->style
& ES_READONLY
))
4045 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4049 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4050 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4053 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4057 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4064 /*********************************************************************
4069 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4071 if (code
|| control
)
4091 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4092 EDIT_EM_ScrollCaret(es
);
4095 ERR("unknown menu item, please report\n");
4101 /*********************************************************************
4105 * Note: the resource files resource/sysres_??.rc cannot define a
4106 * single popup menu. Hence we use a (dummy) menubar
4107 * containing the single popup menu as its first item.
4109 * FIXME: the message identifiers have been chosen arbitrarily,
4110 * hence we use MF_BYPOSITION.
4111 * We might as well use the "real" values (anybody knows ?)
4112 * The menu definition is in resources/sysres_??.rc.
4113 * Once these are OK, we better use MF_BYCOMMAND here
4114 * (as we do in EDIT_WM_Command()).
4117 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4119 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4120 HMENU popup
= GetSubMenu(menu
, 0);
4121 UINT start
= es
->selection_start
;
4122 UINT end
= es
->selection_end
;
4124 ORDER_UINT(start
, end
);
4127 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4129 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4131 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4133 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4135 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4137 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4139 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4142 /* Windows places the menu at the edit's center in this case */
4143 GetClientRect(es
->hwndSelf
, &rc
);
4144 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4145 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4146 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4149 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4154 /*********************************************************************
4159 static void EDIT_WM_Copy(EDITSTATE
*es
)
4161 INT s
= min(es
->selection_start
, es
->selection_end
);
4162 INT e
= max(es
->selection_start
, es
->selection_end
);
4170 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4171 dst
= GlobalLock(hdst
);
4172 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4173 dst
[len
] = 0; /* ensure 0 termination */
4174 TRACE("%s\n", debugstr_w(dst
));
4176 OpenClipboard(es
->hwndSelf
);
4178 SetClipboardData(CF_UNICODETEXT
, hdst
);
4183 /*********************************************************************
4188 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4192 TRACE("%s\n", debugstr_w(name
));
4194 * To initialize some final structure members, we call some helper
4195 * functions. However, since the EDITSTATE is not consistent (i.e.
4196 * not fully initialized), we should be very careful which
4197 * functions can be called, and in what order.
4199 EDIT_WM_SetFont(es
, 0, FALSE
);
4200 EDIT_EM_EmptyUndoBuffer(es
);
4202 /* We need to calculate the format rect
4203 (applications may send EM_SETMARGINS before the control gets visible) */
4204 GetClientRect(es
->hwndSelf
, &clientRect
);
4205 EDIT_SetRectNP(es
, &clientRect
);
4207 if (name
&& *name
) {
4208 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4209 /* if we insert text to the editline, the text scrolls out
4210 * of the window, as the caret is placed after the insert
4211 * pos normally; thus we reset es->selection... to 0 and
4214 es
->selection_start
= es
->selection_end
= 0;
4215 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4216 * Messages are only to be sent when the USER does something to
4217 * change the contents. So I am removing this EN_CHANGE
4219 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4221 EDIT_EM_ScrollCaret(es
);
4223 /* force scroll info update */
4224 EDIT_UpdateScrollInfo(es
);
4225 /* The rule seems to return 1 here for success */
4226 /* Power Builder masked edit controls will crash */
4228 /* FIXME: is that in all cases so ? */
4233 /*********************************************************************
4238 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4243 while (LocalUnlock(es
->hloc32W
)) ;
4244 LocalFree(es
->hloc32W
);
4247 while (LocalUnlock(es
->hloc32A
)) ;
4248 LocalFree(es
->hloc32A
);
4251 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4252 HANDLE16 oldDS
= stack16
->ds
;
4254 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4255 while (LocalUnlock16(es
->hloc16
)) ;
4256 LocalFree16(es
->hloc16
);
4257 stack16
->ds
= oldDS
;
4260 pc
= es
->first_line_def
;
4264 HeapFree(GetProcessHeap(), 0, pc
);
4268 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4269 HeapFree(GetProcessHeap(), 0, es
);
4275 /*********************************************************************
4280 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4282 if(!count
) return 0;
4286 lstrcpynW(dst
, es
->text
, count
);
4287 return strlenW(dst
);
4291 LPSTR textA
= (LPSTR
)dst
;
4292 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4293 textA
[count
- 1] = 0; /* ensure 0 termination */
4294 return strlen(textA
);
4298 /*********************************************************************
4303 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4308 if (!(es
->style
& ES_MULTILINE
))
4311 if (!(es
->style
& ES_AUTOHSCROLL
))
4315 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4318 TRACE("SB_LINELEFT\n");
4320 dx
= -es
->char_width
;
4323 TRACE("SB_LINERIGHT\n");
4324 if (es
->x_offset
< es
->text_width
)
4325 dx
= es
->char_width
;
4328 TRACE("SB_PAGELEFT\n");
4330 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4333 TRACE("SB_PAGERIGHT\n");
4334 if (es
->x_offset
< es
->text_width
)
4335 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4343 TRACE("SB_RIGHT\n");
4344 if (es
->x_offset
< es
->text_width
)
4345 dx
= es
->text_width
- es
->x_offset
;
4348 TRACE("SB_THUMBTRACK %d\n", pos
);
4349 es
->flags
|= EF_HSCROLL_TRACK
;
4350 if(es
->style
& WS_HSCROLL
)
4351 dx
= pos
- es
->x_offset
;
4356 if(pos
< 0 || pos
> 100) return 0;
4357 /* Assume default scroll range 0-100 */
4358 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4359 new_x
= pos
* (es
->text_width
- fw
) / 100;
4360 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4363 case SB_THUMBPOSITION
:
4364 TRACE("SB_THUMBPOSITION %d\n", pos
);
4365 es
->flags
&= ~EF_HSCROLL_TRACK
;
4366 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4367 dx
= pos
- es
->x_offset
;
4372 if(pos
< 0 || pos
> 100) return 0;
4373 /* Assume default scroll range 0-100 */
4374 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4375 new_x
= pos
* (es
->text_width
- fw
) / 100;
4376 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4379 /* force scroll info update */
4380 EDIT_UpdateScrollInfo(es
);
4381 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4385 TRACE("SB_ENDSCROLL\n");
4388 * FIXME : the next two are undocumented !
4389 * Are we doing the right thing ?
4390 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4391 * although it's also a regular control message.
4393 case EM_GETTHUMB
: /* this one is used by NT notepad */
4397 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4398 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4401 /* Assume default scroll range 0-100 */
4402 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4403 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4405 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4408 case EM_LINESCROLL16
:
4409 TRACE("EM_LINESCROLL16\n");
4414 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4420 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4421 /* check if we are going to move too far */
4422 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4423 dx
= es
->text_width
- fw
- es
->x_offset
;
4425 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4431 /*********************************************************************
4436 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4438 HWND hLBox
= es
->hwndListBox
;
4446 hCombo
= GetParent(es
->hwndSelf
);
4450 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4452 if (key
== VK_UP
|| key
== VK_DOWN
)
4454 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4457 if (msg
== WM_KEYDOWN
|| nEUI
)
4458 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4464 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4466 /* make sure ComboLBox pops up */
4467 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4472 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4475 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4477 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4479 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4484 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4490 /*********************************************************************
4494 * Handling of special keys that don't produce a WM_CHAR
4495 * (i.e. non-printable keys) & Backspace & Delete
4498 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4503 if (GetKeyState(VK_MENU
) & 0x8000)
4506 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4507 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4512 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4517 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4518 EDIT_MoveUp_ML(es
, shift
);
4521 EDIT_MoveWordBackward(es
, shift
);
4523 EDIT_MoveBackward(es
, shift
);
4526 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4530 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4531 EDIT_MoveDown_ML(es
, shift
);
4533 EDIT_MoveWordForward(es
, shift
);
4535 EDIT_MoveForward(es
, shift
);
4538 EDIT_MoveHome(es
, shift
);
4541 EDIT_MoveEnd(es
, shift
);
4544 if (es
->style
& ES_MULTILINE
)
4545 EDIT_MovePageUp_ML(es
, shift
);
4547 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4550 if (es
->style
& ES_MULTILINE
)
4551 EDIT_MovePageDown_ML(es
, shift
);
4553 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4556 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4557 if (es
->selection_start
!= es
->selection_end
) {
4564 /* delete character left of caret */
4565 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4566 EDIT_MoveBackward(es
, TRUE
);
4568 } else if (control
) {
4569 /* delete to end of line */
4570 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4571 EDIT_MoveEnd(es
, TRUE
);
4574 /* delete character right of caret */
4575 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4576 EDIT_MoveForward(es
, TRUE
);
4584 if (!(es
->style
& ES_READONLY
))
4590 /* If the edit doesn't want the return send a message to the default object */
4591 if(!(es
->style
& ES_WANTRETURN
))
4593 HWND hwndParent
= GetParent(es
->hwndSelf
);
4594 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4595 if (HIWORD(dw
) == DC_HASDEFID
)
4597 SendMessageW( hwndParent
, WM_COMMAND
,
4598 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4599 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4608 /*********************************************************************
4613 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4615 es
->flags
&= ~EF_FOCUSED
;
4617 if(!(es
->style
& ES_NOHIDESEL
))
4618 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4619 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4624 /*********************************************************************
4628 * The caret position has been set on the WM_LBUTTONDOWN message
4631 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4634 INT e
= es
->selection_end
;
4639 es
->bCaptureState
= TRUE
;
4640 SetCapture(es
->hwndSelf
);
4642 l
= EDIT_EM_LineFromChar(es
, e
);
4643 li
= EDIT_EM_LineIndex(es
, l
);
4644 ll
= EDIT_EM_LineLength(es
, e
);
4645 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4646 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4647 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4648 EDIT_EM_ScrollCaret(es
);
4649 es
->region_posx
= es
->region_posy
= 0;
4650 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4655 /*********************************************************************
4660 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4665 es
->bCaptureState
= TRUE
;
4666 SetCapture(es
->hwndSelf
);
4667 EDIT_ConfinePoint(es
, &x
, &y
);
4668 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4669 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4670 EDIT_EM_ScrollCaret(es
);
4671 es
->region_posx
= es
->region_posy
= 0;
4672 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4674 if (!(es
->flags
& EF_FOCUSED
))
4675 SetFocus(es
->hwndSelf
);
4681 /*********************************************************************
4686 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4688 if (es
->bCaptureState
) {
4689 KillTimer(es
->hwndSelf
, 0);
4690 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4692 es
->bCaptureState
= FALSE
;
4697 /*********************************************************************
4702 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4704 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4709 /*********************************************************************
4714 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4720 /* If the mouse has been captured by process other than the edit control itself,
4721 * the windows edit controls will not select the strings with mouse move.
4723 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4727 * FIXME: gotta do some scrolling if outside client
4728 * area. Maybe reset the timer ?
4731 EDIT_ConfinePoint(es
, &x
, &y
);
4732 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4733 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4734 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4735 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4736 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4741 /*********************************************************************
4745 * See also EDIT_WM_StyleChanged
4747 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4752 TRACE("Creating %s edit control, style = %08x\n",
4753 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4755 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4757 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4760 * Note: since the EDITSTATE has not been fully initialized yet,
4761 * we can't use any API calls that may send
4762 * WM_XXX messages before WM_NCCREATE is completed.
4765 es
->is_unicode
= unicode
;
4766 es
->style
= lpcs
->style
;
4768 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4770 es
->hwndSelf
= hwnd
;
4771 /* Save parent, which will be notified by EN_* messages */
4772 es
->hwndParent
= lpcs
->hwndParent
;
4774 if (es
->style
& ES_COMBO
)
4775 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4777 /* Number overrides lowercase overrides uppercase (at least it
4778 * does in Win95). However I'll bet that ES_NUMBER would be
4779 * invalid under Win 3.1.
4781 if (es
->style
& ES_NUMBER
) {
4782 ; /* do not override the ES_NUMBER */
4783 } else if (es
->style
& ES_LOWERCASE
) {
4784 es
->style
&= ~ES_UPPERCASE
;
4786 if (es
->style
& ES_MULTILINE
) {
4787 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4788 if (es
->style
& WS_VSCROLL
)
4789 es
->style
|= ES_AUTOVSCROLL
;
4790 if (es
->style
& WS_HSCROLL
)
4791 es
->style
|= ES_AUTOHSCROLL
;
4792 es
->style
&= ~ES_PASSWORD
;
4793 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4794 /* Confirmed - RIGHT overrides CENTER */
4795 if (es
->style
& ES_RIGHT
)
4796 es
->style
&= ~ES_CENTER
;
4797 es
->style
&= ~WS_HSCROLL
;
4798 es
->style
&= ~ES_AUTOHSCROLL
;
4801 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4802 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4803 es
->style
&= ~ES_CENTER
;
4804 es
->style
&= ~WS_HSCROLL
;
4805 es
->style
&= ~WS_VSCROLL
;
4806 if (es
->style
& ES_PASSWORD
)
4807 es
->password_char
= '*';
4810 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4811 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4813 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4815 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4817 es
->undo_buffer_size
= es
->buffer_size
;
4819 if (es
->style
& ES_MULTILINE
)
4820 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4825 * In Win95 look and feel, the WS_BORDER style is replaced by the
4826 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4827 * control a nonclient area so we don't need to draw the border.
4828 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4829 * a nonclient area and we should handle painting the border ourselves.
4831 * When making modifications please ensure that the code still works
4832 * for edit controls created directly with style 0x50800000, exStyle 0
4833 * (which should have a single pixel border)
4835 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4836 es
->style
&= ~WS_BORDER
;
4837 else if (es
->style
& WS_BORDER
)
4838 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4843 /*********************************************************************
4848 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4861 BOOL rev
= es
->bEnableState
&&
4862 ((es
->flags
& EF_FOCUSED
) ||
4863 (es
->style
& ES_NOHIDESEL
));
4864 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4866 GetClientRect(es
->hwndSelf
, &rcClient
);
4868 /* get the background brush */
4869 brush
= EDIT_NotifyCtlColor(es
, dc
);
4871 /* paint the border and the background */
4872 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4874 if(es
->style
& WS_BORDER
) {
4875 bw
= GetSystemMetrics(SM_CXBORDER
);
4876 bh
= GetSystemMetrics(SM_CYBORDER
);
4878 if(es
->style
& ES_MULTILINE
) {
4879 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4880 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4883 /* Draw the frame. Same code as in nonclient.c */
4884 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
4885 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
4886 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4887 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
4888 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4889 SelectObject(dc
, old_brush
);
4891 /* Keep the border clean */
4892 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
4893 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
4896 GetClipBox(dc
, &rc
);
4897 FillRect(dc
, &rc
, brush
);
4899 IntersectClipRect(dc
, es
->format_rect
.left
,
4900 es
->format_rect
.top
,
4901 es
->format_rect
.right
,
4902 es
->format_rect
.bottom
);
4903 if (es
->style
& ES_MULTILINE
) {
4905 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4908 old_font
= SelectObject(dc
, es
->font
);
4910 if (!es
->bEnableState
)
4911 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4912 GetClipBox(dc
, &rcRgn
);
4913 if (es
->style
& ES_MULTILINE
) {
4914 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4915 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4916 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4917 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4918 EDIT_PaintLine(es
, dc
, i
, rev
);
4921 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4922 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4923 EDIT_PaintLine(es
, dc
, 0, rev
);
4926 SelectObject(dc
, old_font
);
4929 EndPaint(es
->hwndSelf
, &ps
);
4933 /*********************************************************************
4938 static void EDIT_WM_Paste(EDITSTATE
*es
)
4943 /* Protect read-only edit control from modification */
4944 if(es
->style
& ES_READONLY
)
4947 OpenClipboard(es
->hwndSelf
);
4948 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4949 src
= (LPWSTR
)GlobalLock(hsrc
);
4950 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4953 else if (es
->style
& ES_PASSWORD
) {
4954 /* clear selected text in password edit box even with empty clipboard */
4955 const WCHAR empty_strW
[] = { 0 };
4956 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
4962 /*********************************************************************
4967 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4969 es
->flags
|= EF_FOCUSED
;
4971 if (!(es
->style
& ES_NOHIDESEL
))
4972 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4974 /* single line edit updates itself */
4975 if (!(es
->style
& ES_MULTILINE
))
4977 HDC hdc
= GetDC(es
->hwndSelf
);
4978 EDIT_WM_Paint(es
, hdc
);
4979 ReleaseDC(es
->hwndSelf
, hdc
);
4982 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4983 EDIT_SetCaretPos(es
, es
->selection_end
,
4984 es
->flags
& EF_AFTER_WRAP
);
4985 ShowCaret(es
->hwndSelf
);
4986 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
4990 /*********************************************************************
4994 * With Win95 look the margins are set to default font value unless
4995 * the system font (font == 0) is being set, in which case they are left
4999 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5007 dc
= GetDC(es
->hwndSelf
);
5009 old_font
= SelectObject(dc
, font
);
5010 GetTextMetricsW(dc
, &tm
);
5011 es
->line_height
= tm
.tmHeight
;
5012 es
->char_width
= tm
.tmAveCharWidth
;
5014 SelectObject(dc
, old_font
);
5015 ReleaseDC(es
->hwndSelf
, dc
);
5017 /* Reset the format rect and the margins */
5018 GetClientRect(es
->hwndSelf
, &clientRect
);
5019 EDIT_SetRectNP(es
, &clientRect
);
5020 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5021 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5023 if (es
->style
& ES_MULTILINE
)
5024 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5026 EDIT_CalcLineWidth_SL(es
);
5029 EDIT_UpdateText(es
, NULL
, TRUE
);
5030 if (es
->flags
& EF_FOCUSED
) {
5032 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5033 EDIT_SetCaretPos(es
, es
->selection_end
,
5034 es
->flags
& EF_AFTER_WRAP
);
5035 ShowCaret(es
->hwndSelf
);
5040 /*********************************************************************
5045 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5046 * The modified flag is reset. No notifications are sent.
5048 * For single-line controls, reception of WM_SETTEXT triggers:
5049 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5052 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5054 LPWSTR textW
= NULL
;
5055 if (!unicode
&& text
)
5057 LPCSTR textA
= (LPCSTR
)text
;
5058 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5059 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5061 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5065 if (es
->flags
& EF_UPDATE
)
5066 /* fixed this bug once; complain if we see it about to happen again. */
5067 ERR("SetSel may generate UPDATE message whose handler may reset "
5070 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5073 TRACE("%s\n", debugstr_w(text
));
5074 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5076 HeapFree(GetProcessHeap(), 0, textW
);
5080 static const WCHAR empty_stringW
[] = {0};
5082 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5085 es
->flags
&= ~EF_MODIFIED
;
5086 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5088 /* Send the notification after the selection start and end have been set
5089 * edit control doesn't send notification on WM_SETTEXT
5090 * if it is multiline, or it is part of combobox
5092 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5094 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5095 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5097 EDIT_EM_ScrollCaret(es
);
5098 EDIT_UpdateScrollInfo(es
);
5102 /*********************************************************************
5107 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5109 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5111 TRACE("width = %d, height = %d\n", width
, height
);
5112 SetRect(&rc
, 0, 0, width
, height
);
5113 EDIT_SetRectNP(es
, &rc
);
5114 EDIT_UpdateText(es
, NULL
, TRUE
);
5119 /*********************************************************************
5123 * This message is sent by SetWindowLong on having changed either the Style
5124 * or the extended style.
5126 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5128 * See also EDIT_WM_NCCreate
5130 * It appears that the Windows version of the edit control allows the style
5131 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5132 * style variable which will generally be different. In this function we
5133 * update the internal style based on what changed in the externally visible
5136 * Much of this content as based upon the MSDN, especially:
5137 * Platform SDK Documentation -> User Interface Services ->
5138 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5139 * Edit Control Styles
5141 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5143 if (GWL_STYLE
== which
) {
5144 DWORD style_change_mask
;
5146 /* Only a subset of changes can be applied after the control
5149 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5151 if (es
->style
& ES_MULTILINE
)
5152 style_change_mask
|= ES_WANTRETURN
;
5154 new_style
= style
->styleNew
& style_change_mask
;
5156 /* Number overrides lowercase overrides uppercase (at least it
5157 * does in Win95). However I'll bet that ES_NUMBER would be
5158 * invalid under Win 3.1.
5160 if (new_style
& ES_NUMBER
) {
5161 ; /* do not override the ES_NUMBER */
5162 } else if (new_style
& ES_LOWERCASE
) {
5163 new_style
&= ~ES_UPPERCASE
;
5166 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5167 } else if (GWL_EXSTYLE
== which
) {
5168 ; /* FIXME - what is needed here */
5170 WARN ("Invalid style change %ld\n",which
);
5176 /*********************************************************************
5181 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5183 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5184 if (EDIT_EM_CanUndo(es
))
5187 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5188 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5191 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5195 /*********************************************************************
5200 static void EDIT_WM_Timer(EDITSTATE
*es
)
5202 if (es
->region_posx
< 0) {
5203 EDIT_MoveBackward(es
, TRUE
);
5204 } else if (es
->region_posx
> 0) {
5205 EDIT_MoveForward(es
, TRUE
);
5208 * FIXME: gotta do some vertical scrolling here, like
5209 * EDIT_EM_LineScroll(hwnd, 0, 1);
5213 /*********************************************************************
5218 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5222 if (!(es
->style
& ES_MULTILINE
))
5225 if (!(es
->style
& ES_AUTOVSCROLL
))
5234 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5235 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5236 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5238 EDIT_EM_Scroll(es
, action
);
5245 TRACE("SB_BOTTOM\n");
5246 dy
= es
->line_count
- 1 - es
->y_offset
;
5249 TRACE("SB_THUMBTRACK %d\n", pos
);
5250 es
->flags
|= EF_VSCROLL_TRACK
;
5251 if(es
->style
& WS_VSCROLL
)
5252 dy
= pos
- es
->y_offset
;
5255 /* Assume default scroll range 0-100 */
5258 if(pos
< 0 || pos
> 100) return 0;
5259 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5260 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5261 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5262 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5263 es
->line_count
, es
->y_offset
, pos
, dy
);
5266 case SB_THUMBPOSITION
:
5267 TRACE("SB_THUMBPOSITION %d\n", pos
);
5268 es
->flags
&= ~EF_VSCROLL_TRACK
;
5269 if(es
->style
& WS_VSCROLL
)
5270 dy
= pos
- es
->y_offset
;
5273 /* Assume default scroll range 0-100 */
5276 if(pos
< 0 || pos
> 100) return 0;
5277 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5278 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5279 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5280 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5281 es
->line_count
, es
->y_offset
, pos
, dy
);
5285 /* force scroll info update */
5286 EDIT_UpdateScrollInfo(es
);
5287 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5291 TRACE("SB_ENDSCROLL\n");
5294 * FIXME : the next two are undocumented !
5295 * Are we doing the right thing ?
5296 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5297 * although it's also a regular control message.
5299 case EM_GETTHUMB
: /* this one is used by NT notepad */
5303 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5304 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5307 /* Assume default scroll range 0-100 */
5308 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5309 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5311 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5314 case EM_LINESCROLL16
:
5315 TRACE("EM_LINESCROLL16 %d\n", pos
);
5320 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5325 EDIT_EM_LineScroll(es
, 0, dy
);
5329 /*********************************************************************
5334 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5336 if (es
->flags
& EF_UPDATE
) {
5337 es
->flags
&= ~EF_UPDATE
;
5338 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5340 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5344 /*********************************************************************
5349 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
5351 if (es
->flags
& EF_UPDATE
) {
5352 es
->flags
&= ~EF_UPDATE
;
5353 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5355 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5358 /********************************************************************
5360 * The Following code is to handle inline editing from IMEs
5363 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5366 LPWSTR lpCompStr
= NULL
;
5368 LPSTR lpCompStrAttr
= NULL
;
5371 if (!(hIMC
= ImmGetContext(hwnd
)))
5374 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5378 ImmReleaseContext(hwnd
, hIMC
);
5382 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
5385 ERR("Unable to allocate IME CompositionString\n");
5386 ImmReleaseContext(hwnd
,hIMC
);
5391 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
5392 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
5394 if (CompFlag
& GCS_COMPATTR
)
5397 * We do not use the attributes yet. it would tell us what characters
5398 * are in transition and which are converted or decided upon
5400 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5404 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5407 ERR("Unable to allocate IME Attribute String\n");
5408 HeapFree(GetProcessHeap(),0,lpCompStr
);
5409 ImmReleaseContext(hwnd
,hIMC
);
5412 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5414 lpCompStrAttr
[dwBufLenAttr
] = 0;
5417 lpCompStrAttr
= NULL
;
5420 /* check for change in composition start */
5421 if (es
->selection_end
< es
->composition_start
)
5422 es
->composition_start
= es
->selection_end
;
5424 /* replace existing selection string */
5425 es
->selection_start
= es
->composition_start
;
5427 if (es
->composition_len
> 0)
5428 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5430 es
->selection_end
= es
->selection_start
;
5432 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5433 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5435 es
->selection_start
= es
->composition_start
;
5436 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5438 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5439 HeapFree(GetProcessHeap(),0,lpCompStr
);
5440 ImmReleaseContext(hwnd
,hIMC
);
5443 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5449 if ( !(hIMC
= ImmGetContext(hwnd
)))
5452 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5455 ImmReleaseContext(hwnd
, hIMC
);
5459 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
5462 ERR("Unable to alloc buffer for IME string\n");
5463 ImmReleaseContext(hwnd
, hIMC
);
5467 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
5468 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
5470 /* check for change in composition start */
5471 if (es
->selection_end
< es
->composition_start
)
5472 es
->composition_start
= es
->selection_end
;
5474 es
->selection_start
= es
->composition_start
;
5475 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5476 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5477 es
->composition_start
= es
->selection_end
;
5478 es
->composition_len
= 0;
5480 HeapFree(GetProcessHeap(),0,lpResultStr
);
5481 ImmReleaseContext(hwnd
, hIMC
);
5484 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5486 if (CompFlag
& GCS_RESULTSTR
)
5487 EDIT_GetResultStr(hwnd
,es
);
5488 if (CompFlag
& GCS_COMPSTR
)
5489 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);