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
)
799 result
|= DLGC_WANTALLKEYS
;
803 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
805 int vk
= (int)((LPMSG
)lParam
)->wParam
;
807 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
809 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
810 result
|= DLGC_WANTMESSAGE
;
821 strng
[0] = wParam
>> 8;
822 strng
[1] = wParam
& 0xff;
823 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
824 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
825 EDIT_WM_Char(es
, charW
);
838 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
841 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
843 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
844 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
847 EDIT_WM_Char(es
, charW
);
856 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
860 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
869 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
872 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
876 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
877 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
878 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
880 result
= EDIT_WM_Create(es
, nameW
);
881 HeapFree(GetProcessHeap(), 0, nameW
);
890 es
->bEnableState
= (BOOL
) wParam
;
891 EDIT_UpdateText(es
, NULL
, TRUE
);
895 /* we do the proper erase in EDIT_WM_Paint */
900 result
= (LRESULT
)es
->font
;
904 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
907 case WM_GETTEXTLENGTH
:
908 if (unicode
) result
= get_text_length(es
);
909 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
910 NULL
, 0, NULL
, NULL
);
914 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
918 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
922 result
= EDIT_WM_KillFocus(es
);
925 case WM_LBUTTONDBLCLK
:
926 result
= EDIT_WM_LButtonDblClk(es
);
930 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
934 result
= EDIT_WM_LButtonUp(es
);
938 result
= EDIT_WM_MButtonDown(es
);
942 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
947 EDIT_WM_Paint(es
, (HDC
)wParam
);
955 EDIT_WM_SetFocus(es
);
959 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
963 /* FIXME: actually set an internal flag and behave accordingly */
967 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
972 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
975 case WM_STYLECHANGED
:
976 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
979 case WM_STYLECHANGING
:
980 result
= 0; /* See EDIT_WM_StyleChanged */
984 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
992 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
997 int gcWheelDelta
= 0;
998 UINT pulScrollLines
= 3;
999 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1001 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1002 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1005 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1006 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1008 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1009 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1010 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1016 /* IME messages to make the edit control IME aware */
1017 case WM_IME_SETCONTEXT
:
1020 case WM_IME_STARTCOMPOSITION
:
1022 * FIXME in IME: This message is not always sent like it should be
1024 if (es
->selection_start
!= es
->selection_end
)
1026 static const WCHAR empty_stringW
[] = {0};
1027 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1029 es
->composition_start
= es
->selection_end
;
1030 es
->composition_len
= 0;
1033 case WM_IME_COMPOSITION
:
1035 int caret_pos
= es
->selection_end
;
1036 if (es
->composition_len
== 0)
1038 if (es
->selection_start
!= es
->selection_end
)
1040 static const WCHAR empty_stringW
[] = {0};
1041 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1044 es
->composition_start
= es
->selection_end
;
1046 EDIT_ImeComposition(hwnd
,lParam
,es
);
1047 EDIT_SetCaretPos(es
, caret_pos
, es
->flags
& EF_AFTER_WRAP
);
1051 case WM_IME_ENDCOMPOSITION
:
1052 es
->composition_len
= 0;
1055 case WM_IME_COMPOSITIONFULL
:
1061 case WM_IME_CONTROL
:
1065 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1069 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1071 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1076 /*********************************************************************
1078 * EditWndProcW (USER32.@)
1080 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1082 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1085 /*********************************************************************
1087 * EditWndProc (USER32.@)
1089 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1091 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1094 /*********************************************************************
1096 * EDIT_BuildLineDefs_ML
1098 * Build linked list of text lines.
1099 * Lines can end with '\0' (last line), a character (if it is wrapped),
1100 * a soft return '\r\r\n' or a hard return '\r\n'
1103 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1107 LPWSTR current_position
, cp
;
1109 LINEDEF
*current_line
;
1110 LINEDEF
*previous_line
;
1111 LINEDEF
*start_line
;
1112 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1113 INT line_count
= es
->line_count
;
1114 INT orig_net_length
;
1117 if (istart
== iend
&& delta
== 0)
1120 dc
= GetDC(es
->hwndSelf
);
1122 old_font
= SelectObject(dc
, es
->font
);
1124 previous_line
= NULL
;
1125 current_line
= es
->first_line_def
;
1127 /* Find starting line. istart must lie inside an existing line or
1128 * at the end of buffer */
1130 if (istart
< current_line
->index
+ current_line
->length
||
1131 current_line
->ending
== END_0
)
1134 previous_line
= current_line
;
1135 current_line
= current_line
->next
;
1137 } while (current_line
);
1139 if (!current_line
) /* Error occurred start is not inside previous buffer */
1141 FIXME(" modification occurred outside buffer\n");
1142 ReleaseDC(es
->hwndSelf
, dc
);
1146 /* Remember start of modifications in order to calculate update region */
1147 nstart_line
= line_index
;
1148 nstart_index
= current_line
->index
;
1150 /* We must start to reformat from the previous line since the modifications
1151 * may have caused the line to wrap upwards. */
1152 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1155 current_line
= previous_line
;
1157 start_line
= current_line
;
1159 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1160 current_position
= es
->text
+ current_line
->index
;
1162 if (current_line
!= start_line
)
1164 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1166 /* The buffer has been expanded, create a new line and
1167 insert it into the link list */
1168 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1169 new_line
->next
= previous_line
->next
;
1170 previous_line
->next
= new_line
;
1171 current_line
= new_line
;
1174 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1176 /* The previous line merged with this line so we delete this extra entry */
1177 previous_line
->next
= current_line
->next
;
1178 HeapFree(GetProcessHeap(), 0, current_line
);
1179 current_line
= previous_line
->next
;
1183 else /* current_line->index + delta == current_position */
1185 if (current_position
- es
->text
> iend
)
1186 break; /* We reached end of line modifications */
1187 /* else recalulate this line */
1191 current_line
->index
= current_position
- es
->text
;
1192 orig_net_length
= current_line
->net_length
;
1194 /* Find end of line */
1195 cp
= current_position
;
1197 if (*cp
== '\n') break;
1198 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1203 /* Mark type of line termination */
1205 current_line
->ending
= END_0
;
1206 current_line
->net_length
= strlenW(current_position
);
1207 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1208 current_line
->ending
= END_SOFT
;
1209 current_line
->net_length
= cp
- current_position
- 1;
1210 } else if (*cp
== '\n') {
1211 current_line
->ending
= END_RICH
;
1212 current_line
->net_length
= cp
- current_position
;
1214 current_line
->ending
= END_HARD
;
1215 current_line
->net_length
= cp
- current_position
;
1218 /* Calculate line width */
1219 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1220 current_position
, current_line
->net_length
,
1221 es
->tabs_count
, es
->tabs
));
1223 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1224 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1225 if (current_line
->width
> fw
) {
1230 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1231 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1232 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1233 current_position
, next
, es
->tabs_count
, es
->tabs
));
1234 } while (current_line
->width
<= fw
);
1235 if (!prev
) { /* Didn't find a line break so force a break */
1240 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1241 current_position
, next
, es
->tabs_count
, es
->tabs
));
1242 } while (current_line
->width
<= fw
);
1247 /* If the first line we are calculating, wrapped before istart, we must
1248 * adjust istart in order for this to be reflected in the update region. */
1249 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1250 istart
= current_line
->index
+ prev
;
1251 /* else if we are updating the previous line before the first line we
1252 * are re-calculating and it expanded */
1253 else if (current_line
== start_line
&&
1254 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1256 /* Line expanded due to an upwards line wrap so we must partially include
1257 * previous line in update region */
1258 nstart_line
= line_index
;
1259 nstart_index
= current_line
->index
;
1260 istart
= current_line
->index
+ orig_net_length
;
1263 current_line
->net_length
= prev
;
1264 current_line
->ending
= END_WRAP
;
1265 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1266 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1268 else if (orig_net_length
< current_line
->net_length
&&
1269 current_line
== start_line
&&
1270 current_line
->index
!= nstart_index
) {
1271 /* The previous line expanded but it's still not as wide as the client rect */
1272 /* The expansion is due to an upwards line wrap so we must partially include
1273 it in the update region */
1274 nstart_line
= line_index
;
1275 nstart_index
= current_line
->index
;
1276 istart
= current_line
->index
+ orig_net_length
;
1281 /* Adjust length to include line termination */
1282 switch (current_line
->ending
) {
1284 current_line
->length
= current_line
->net_length
+ 3;
1287 current_line
->length
= current_line
->net_length
+ 1;
1290 current_line
->length
= current_line
->net_length
+ 2;
1294 current_line
->length
= current_line
->net_length
;
1297 es
->text_width
= max(es
->text_width
, current_line
->width
);
1298 current_position
+= current_line
->length
;
1299 previous_line
= current_line
;
1300 current_line
= current_line
->next
;
1302 } while (previous_line
->ending
!= END_0
);
1304 /* Finish adjusting line indexes by delta or remove hanging lines */
1305 if (previous_line
->ending
== END_0
)
1307 LINEDEF
*pnext
= NULL
;
1309 previous_line
->next
= NULL
;
1310 while (current_line
)
1312 pnext
= current_line
->next
;
1313 HeapFree(GetProcessHeap(), 0, current_line
);
1314 current_line
= pnext
;
1318 else if (delta
!= 0)
1320 while (current_line
)
1322 current_line
->index
+= delta
;
1323 current_line
= current_line
->next
;
1327 /* Calculate rest of modification rectangle */
1332 * We calculate two rectangles. One for the first line which may have
1333 * an indent with respect to the format rect. The other is a format-width
1334 * rectangle that spans the rest of the lines that changed or moved.
1336 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1337 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1338 rc
.bottom
= rc
.top
+ es
->line_height
;
1339 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1340 rc
.left
= es
->format_rect
.left
;
1342 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1343 es
->text
+ nstart_index
, istart
- nstart_index
,
1344 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1345 rc
.right
= es
->format_rect
.right
;
1346 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1349 rc
.left
= es
->format_rect
.left
;
1350 rc
.right
= es
->format_rect
.right
;
1352 * If lines were added or removed we must re-paint the remainder of the
1353 * lines since the remaining lines were either shifted up or down.
1355 if (line_count
< es
->line_count
) /* We added lines */
1356 rc
.bottom
= es
->line_count
* es
->line_height
;
1357 else if (line_count
> es
->line_count
) /* We removed lines */
1358 rc
.bottom
= line_count
* es
->line_height
;
1360 rc
.bottom
= line_index
* es
->line_height
;
1361 rc
.bottom
+= es
->format_rect
.top
;
1362 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1363 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1364 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1365 DeleteObject(tmphrgn
);
1369 SelectObject(dc
, old_font
);
1371 ReleaseDC(es
->hwndSelf
, dc
);
1374 /*********************************************************************
1376 * EDIT_CalcLineWidth_SL
1379 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1386 text
= EDIT_GetPasswordPointer_SL(es
);
1388 dc
= GetDC(es
->hwndSelf
);
1390 old_font
= SelectObject(dc
, es
->font
);
1392 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1395 SelectObject(dc
, old_font
);
1396 ReleaseDC(es
->hwndSelf
, dc
);
1398 if (es
->style
& ES_PASSWORD
)
1399 HeapFree(GetProcessHeap(), 0, text
);
1401 es
->text_width
= size
.cx
;
1404 /*********************************************************************
1406 * EDIT_CallWordBreakProc
1408 * Call appropriate WordBreakProc (internal or external).
1410 * Note: The "start" argument should always be an index referring
1411 * to es->text. The actual wordbreak proc might be
1412 * 16 bit, so we can't always pass any 32 bit LPSTR.
1413 * Hence we assume that es->text is the buffer that holds
1414 * the string under examination (we can decide this for ourselves).
1417 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1421 if (es
->word_break_proc16
) {
1428 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1429 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1430 segptr
= WOWGlobalLock16(hglob16
);
1431 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1432 args
[4] = SELECTOROF(segptr
);
1433 args
[3] = OFFSETOF(segptr
);
1437 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1438 ret
= LOWORD(result
);
1439 GlobalUnlock16(hglob16
);
1440 GlobalFree16(hglob16
);
1442 else if (es
->word_break_proc
)
1446 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1448 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1449 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1450 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1454 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1458 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1459 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1460 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1461 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1462 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1463 ret
= wbpA(textA
, index
, countA
, action
);
1464 HeapFree(GetProcessHeap(), 0, textA
);
1468 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1474 /*********************************************************************
1478 * Beware: This is not the function called on EM_CHARFROMPOS
1479 * The position _can_ be outside the formatting / client
1481 * The return value is only the character index
1484 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1489 INT x_high
= 0, x_low
= 0;
1491 if (es
->style
& ES_MULTILINE
) {
1492 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1494 LINEDEF
*line_def
= es
->first_line_def
;
1496 while ((line
> 0) && line_def
->next
) {
1497 line_index
+= line_def
->length
;
1498 line_def
= line_def
->next
;
1501 x
+= es
->x_offset
- es
->format_rect
.left
;
1502 if (es
->style
& ES_RIGHT
)
1503 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1504 else if (es
->style
& ES_CENTER
)
1505 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1506 if (x
>= line_def
->width
) {
1508 *after_wrap
= (line_def
->ending
== END_WRAP
);
1509 return line_index
+ line_def
->net_length
;
1513 *after_wrap
= FALSE
;
1516 dc
= GetDC(es
->hwndSelf
);
1518 old_font
= SelectObject(dc
, es
->font
);
1520 high
= line_index
+ line_def
->net_length
+ 1;
1521 while (low
< high
- 1)
1523 INT mid
= (low
+ high
) / 2;
1524 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1533 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1539 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1540 (line_def
->ending
== END_WRAP
));
1545 *after_wrap
= FALSE
;
1546 x
-= es
->format_rect
.left
;
1548 return es
->x_offset
;
1552 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1553 if (es
->style
& ES_RIGHT
)
1555 else if (es
->style
& ES_CENTER
)
1559 text
= EDIT_GetPasswordPointer_SL(es
);
1560 dc
= GetDC(es
->hwndSelf
);
1562 old_font
= SelectObject(dc
, es
->font
);
1566 INT high
= es
->x_offset
;
1567 while (low
< high
- 1)
1569 INT mid
= (low
+ high
) / 2;
1570 GetTextExtentPoint32W( dc
, text
+ mid
,
1571 es
->x_offset
- mid
, &size
);
1580 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1587 INT low
= es
->x_offset
;
1588 INT high
= get_text_length(es
) + 1;
1589 while (low
< high
- 1)
1591 INT mid
= (low
+ high
) / 2;
1592 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1593 mid
- es
->x_offset
, &size
);
1602 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1607 if (es
->style
& ES_PASSWORD
)
1608 HeapFree(GetProcessHeap(), 0, text
);
1611 SelectObject(dc
, old_font
);
1612 ReleaseDC(es
->hwndSelf
, dc
);
1617 /*********************************************************************
1621 * adjusts the point to be within the formatting rectangle
1622 * (so CharFromPos returns the nearest _visible_ character)
1625 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
1627 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1628 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1632 /*********************************************************************
1636 * Calculates the bounding rectangle for a line from a starting
1637 * column to an ending column.
1640 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1642 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1644 if (es
->style
& ES_MULTILINE
)
1645 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1647 rc
->top
= es
->format_rect
.top
;
1648 rc
->bottom
= rc
->top
+ es
->line_height
;
1649 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1650 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1654 /*********************************************************************
1656 * EDIT_GetPasswordPointer_SL
1658 * note: caller should free the (optionally) allocated buffer
1661 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1663 if (es
->style
& ES_PASSWORD
) {
1664 INT len
= get_text_length(es
);
1665 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1667 while(len
) text
[--len
] = es
->password_char
;
1674 /*********************************************************************
1678 * This acts as a LocalLock16(), but it locks only once. This way
1679 * you can call it whenever you like, without unlocking.
1681 * Initially the edit control allocates a HLOCAL32 buffer
1682 * (32 bit linear memory handler). However, 16 bit application
1683 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1684 * handler). From that moment on we have to keep using this 16 bit memory
1685 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1686 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1690 static void EDIT_LockBuffer(EDITSTATE
*es
)
1692 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1693 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1698 BOOL _16bit
= FALSE
;
1704 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1705 textA
= LocalLock(es
->hloc32A
);
1706 countA
= strlen(textA
) + 1;
1710 HANDLE16 oldDS
= stack16
->ds
;
1711 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1712 stack16
->ds
= hInstance
;
1713 textA
= MapSL(LocalLock16(es
->hloc16
));
1714 stack16
->ds
= oldDS
;
1715 countA
= strlen(textA
) + 1;
1720 ERR("no buffer ... please report\n");
1727 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1728 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1729 if(countW_new
> es
->buffer_size
+ 1)
1731 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1732 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1733 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1736 es
->hloc32W
= hloc32W_new
;
1737 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1738 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1741 WARN("FAILED! Will synchronize partially\n");
1745 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1746 es
->text
= LocalLock(es
->hloc32W
);
1750 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1753 HANDLE16 oldDS
= stack16
->ds
;
1754 stack16
->ds
= hInstance
;
1755 LocalUnlock16(es
->hloc16
);
1756 stack16
->ds
= oldDS
;
1759 LocalUnlock(es
->hloc32A
);
1762 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1767 /*********************************************************************
1769 * EDIT_SL_InvalidateText
1771 * Called from EDIT_InvalidateText().
1772 * Does the job for single-line controls only.
1775 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1780 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1781 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1782 EDIT_UpdateText(es
, &rc
, TRUE
);
1786 /*********************************************************************
1788 * EDIT_ML_InvalidateText
1790 * Called from EDIT_InvalidateText().
1791 * Does the job for multi-line controls only.
1794 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1796 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1797 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1798 INT el
= EDIT_EM_LineFromChar(es
, end
);
1807 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1810 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1811 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1812 if (sl
< es
->y_offset
) {
1816 if (el
> es
->y_offset
+ vlc
) {
1817 el
= es
->y_offset
+ vlc
;
1818 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1820 GetClientRect(es
->hwndSelf
, &rc1
);
1821 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1823 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1824 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1825 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1827 EDIT_GetLineRect(es
, sl
, sc
,
1828 EDIT_EM_LineLength(es
,
1829 EDIT_EM_LineIndex(es
, sl
)),
1831 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1832 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1833 for (l
= sl
+ 1 ; l
< el
; l
++) {
1834 EDIT_GetLineRect(es
, l
, 0,
1835 EDIT_EM_LineLength(es
,
1836 EDIT_EM_LineIndex(es
, l
)),
1838 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1839 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1841 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1842 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1843 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1848 /*********************************************************************
1850 * EDIT_InvalidateText
1852 * Invalidate the text from offset start up to, but not including,
1853 * offset end. Useful for (re)painting the selection.
1854 * Regions outside the linewidth are not invalidated.
1855 * end == -1 means end == TextLength.
1856 * start and end need not be ordered.
1859 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1865 end
= get_text_length(es
);
1873 if (es
->style
& ES_MULTILINE
)
1874 EDIT_ML_InvalidateText(es
, start
, end
);
1876 EDIT_SL_InvalidateText(es
, start
, end
);
1880 /*********************************************************************
1884 * Try to fit size + 1 characters in the buffer.
1886 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1890 if (size
<= es
->buffer_size
)
1893 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1895 /* Force edit to unlock it's buffer. es->text now NULL */
1896 EDIT_UnlockBuffer(es
, TRUE
);
1899 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1900 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1901 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1902 es
->hloc32W
= hNew32W
;
1903 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1907 EDIT_LockBuffer(es
);
1909 if (es
->buffer_size
< size
) {
1910 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1911 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1914 TRACE("We now have %d+1\n", es
->buffer_size
);
1920 /*********************************************************************
1924 * Try to fit size + 1 bytes in the undo buffer.
1927 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1931 if (size
<= es
->undo_buffer_size
)
1934 TRACE("trying to ReAlloc to %d+1\n", size
);
1936 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1937 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1938 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1943 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1949 /*********************************************************************
1954 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1956 INT e
= es
->selection_end
;
1960 if ((es
->style
& ES_MULTILINE
) && e
&&
1961 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1963 if (e
&& (es
->text
[e
- 1] == '\r'))
1967 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1968 EDIT_EM_ScrollCaret(es
);
1972 /*********************************************************************
1976 * Only for multi line controls
1977 * Move the caret one line down, on a column with the nearest
1978 * x coordinate on the screen (might be a different column).
1981 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1983 INT s
= es
->selection_start
;
1984 INT e
= es
->selection_end
;
1985 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1986 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1987 INT x
= (short)LOWORD(pos
);
1988 INT y
= (short)HIWORD(pos
);
1990 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1993 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1994 EDIT_EM_ScrollCaret(es
);
1998 /*********************************************************************
2003 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
2005 BOOL after_wrap
= FALSE
;
2008 /* Pass a high value in x to make sure of receiving the end of the line */
2009 if (es
->style
& ES_MULTILINE
)
2010 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2011 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2013 e
= get_text_length(es
);
2014 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2015 EDIT_EM_ScrollCaret(es
);
2019 /*********************************************************************
2024 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2026 INT e
= es
->selection_end
;
2030 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2031 if (es
->text
[e
] == '\n')
2033 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2037 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2038 EDIT_EM_ScrollCaret(es
);
2042 /*********************************************************************
2046 * Home key: move to beginning of line.
2049 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2053 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2054 if (es
->style
& ES_MULTILINE
)
2055 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2056 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2059 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2060 EDIT_EM_ScrollCaret(es
);
2064 /*********************************************************************
2066 * EDIT_MovePageDown_ML
2068 * Only for multi line controls
2069 * Move the caret one page down, on a column with the nearest
2070 * x coordinate on the screen (might be a different column).
2073 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2075 INT s
= es
->selection_start
;
2076 INT e
= es
->selection_end
;
2077 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2078 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2079 INT x
= (short)LOWORD(pos
);
2080 INT y
= (short)HIWORD(pos
);
2082 e
= EDIT_CharFromPos(es
, x
,
2083 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2087 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2088 EDIT_EM_ScrollCaret(es
);
2092 /*********************************************************************
2094 * EDIT_MovePageUp_ML
2096 * Only for multi line controls
2097 * Move the caret one page up, on a column with the nearest
2098 * x coordinate on the screen (might be a different column).
2101 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2103 INT s
= es
->selection_start
;
2104 INT e
= es
->selection_end
;
2105 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2106 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2107 INT x
= (short)LOWORD(pos
);
2108 INT y
= (short)HIWORD(pos
);
2110 e
= EDIT_CharFromPos(es
, x
,
2111 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2115 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2116 EDIT_EM_ScrollCaret(es
);
2120 /*********************************************************************
2124 * Only for multi line controls
2125 * Move the caret one line up, on a column with the nearest
2126 * x coordinate on the screen (might be a different column).
2129 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2131 INT s
= es
->selection_start
;
2132 INT e
= es
->selection_end
;
2133 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2134 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2135 INT x
= (short)LOWORD(pos
);
2136 INT y
= (short)HIWORD(pos
);
2138 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2141 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2142 EDIT_EM_ScrollCaret(es
);
2146 /*********************************************************************
2148 * EDIT_MoveWordBackward
2151 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2153 INT s
= es
->selection_start
;
2154 INT e
= es
->selection_end
;
2159 l
= EDIT_EM_LineFromChar(es
, e
);
2160 ll
= EDIT_EM_LineLength(es
, e
);
2161 li
= EDIT_EM_LineIndex(es
, l
);
2164 li
= EDIT_EM_LineIndex(es
, l
- 1);
2165 e
= li
+ EDIT_EM_LineLength(es
, li
);
2168 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2169 li
, e
- li
, ll
, WB_LEFT
);
2173 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2174 EDIT_EM_ScrollCaret(es
);
2178 /*********************************************************************
2180 * EDIT_MoveWordForward
2183 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2185 INT s
= es
->selection_start
;
2186 INT e
= es
->selection_end
;
2191 l
= EDIT_EM_LineFromChar(es
, e
);
2192 ll
= EDIT_EM_LineLength(es
, e
);
2193 li
= EDIT_EM_LineIndex(es
, l
);
2195 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2196 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2198 e
= li
+ EDIT_CallWordBreakProc(es
,
2199 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2203 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2204 EDIT_EM_ScrollCaret(es
);
2208 /*********************************************************************
2213 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2215 INT s
= es
->selection_start
;
2216 INT e
= es
->selection_end
;
2223 if (es
->style
& ES_MULTILINE
) {
2224 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2225 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2230 TRACE("line=%d\n", line
);
2232 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2233 x
= (short)LOWORD(pos
);
2234 y
= (short)HIWORD(pos
);
2235 li
= EDIT_EM_LineIndex(es
, line
);
2236 ll
= EDIT_EM_LineLength(es
, li
);
2237 s
= min(es
->selection_start
, es
->selection_end
);
2238 e
= max(es
->selection_start
, es
->selection_end
);
2239 s
= min(li
+ ll
, max(li
, s
));
2240 e
= min(li
+ ll
, max(li
, e
));
2241 if (rev
&& (s
!= e
) &&
2242 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2243 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2244 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2245 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2247 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2251 /*********************************************************************
2256 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2260 LOGFONTW underline_font
;
2261 HFONT hUnderline
= 0;
2270 BkMode
= GetBkMode(dc
);
2271 BkColor
= GetBkColor(dc
);
2272 TextColor
= GetTextColor(dc
);
2274 if (es
->composition_len
== 0)
2276 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2277 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2278 SetBkMode( dc
, OPAQUE
);
2282 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2283 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2284 underline_font
.lfUnderline
= TRUE
;
2285 hUnderline
= CreateFontIndirectW(&underline_font
);
2286 old_font
= SelectObject(dc
,hUnderline
);
2289 li
= EDIT_EM_LineIndex(es
, line
);
2290 if (es
->style
& ES_MULTILINE
) {
2291 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2292 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2294 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2295 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2296 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2298 if (es
->style
& ES_PASSWORD
)
2299 HeapFree(GetProcessHeap(), 0, text
);
2302 if (es
->composition_len
== 0)
2304 SetBkColor(dc
, BkColor
);
2305 SetTextColor(dc
, TextColor
);
2306 SetBkMode( dc
, BkMode
);
2311 SelectObject(dc
,old_font
);
2313 DeleteObject(hUnderline
);
2320 /*********************************************************************
2325 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2328 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2329 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2330 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2334 /*********************************************************************
2336 * EDIT_AdjustFormatRect
2338 * Adjusts the format rectangle for the current font and the
2339 * current client rectangle.
2342 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2346 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2347 if (es
->style
& ES_MULTILINE
)
2349 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2351 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2352 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2354 /* correct es->x_offset */
2355 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2356 max_x_offset
= es
->text_width
- fw
;
2357 if(max_x_offset
< 0) max_x_offset
= 0;
2358 if(es
->x_offset
> max_x_offset
)
2359 es
->x_offset
= max_x_offset
;
2361 /* correct es->y_offset */
2362 max_y_offset
= es
->line_count
- vlc
;
2363 if(max_y_offset
< 0) max_y_offset
= 0;
2364 if(es
->y_offset
> max_y_offset
)
2365 es
->y_offset
= max_y_offset
;
2367 /* force scroll info update */
2368 EDIT_UpdateScrollInfo(es
);
2371 /* Windows doesn't care to fix text placement for SL controls */
2372 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2374 /* Always stay within the client area */
2375 GetClientRect(es
->hwndSelf
, &ClientRect
);
2376 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2378 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2379 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2381 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2385 /*********************************************************************
2389 * note: this is not (exactly) the handler called on EM_SETRECTNP
2390 * it is also used to set the rect of a single line control
2393 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2397 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2399 CopyRect(&es
->format_rect
, rc
);
2401 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2402 es
->format_rect
.left
++;
2403 es
->format_rect
.right
--;
2405 if (es
->format_rect
.bottom
- es
->format_rect
.top
2406 >= es
->line_height
+ 2)
2408 es
->format_rect
.top
++;
2409 es
->format_rect
.bottom
--;
2412 else if (es
->style
& WS_BORDER
) {
2413 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2414 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2415 es
->format_rect
.left
+= bw
;
2416 es
->format_rect
.right
-= bw
;
2417 if (es
->format_rect
.bottom
- es
->format_rect
.top
2418 >= es
->line_height
+ 2 * bh
)
2420 es
->format_rect
.top
+= bh
;
2421 es
->format_rect
.bottom
-= bh
;
2425 es
->format_rect
.left
+= es
->left_margin
;
2426 es
->format_rect
.right
-= es
->right_margin
;
2427 EDIT_AdjustFormatRect(es
);
2431 /*********************************************************************
2436 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2439 /* Edit window might be already destroyed */
2440 if(!IsWindow(es
->hwndSelf
))
2442 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2446 if (!es
->lock_count
) {
2447 ERR("lock_count == 0 ... please report\n");
2451 ERR("es->text == 0 ... please report\n");
2455 if (force
|| (es
->lock_count
== 1)) {
2459 UINT countW
= get_text_length(es
) + 1;
2460 STACK16FRAME
* stack16
= NULL
;
2465 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2466 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2467 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2468 countA
= LocalSize(es
->hloc32A
);
2469 if(countA_new
> countA
)
2472 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2473 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2474 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2477 es
->hloc32A
= hloc32A_new
;
2478 countA
= LocalSize(hloc32A_new
);
2479 TRACE("Real new size %d bytes\n", countA
);
2482 WARN("FAILED! Will synchronize partially\n");
2484 textA
= LocalLock(es
->hloc32A
);
2488 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2490 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2491 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2493 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2494 oldDS
= stack16
->ds
;
2495 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2497 countA
= LocalSize16(es
->hloc16
);
2498 if(countA_new
> countA
)
2500 HLOCAL16 hloc16_new
;
2501 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2502 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2503 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2506 es
->hloc16
= hloc16_new
;
2507 countA
= LocalSize16(hloc16_new
);
2508 TRACE("Real new size %d bytes\n", countA
);
2511 WARN("FAILED! Will synchronize partially\n");
2513 textA
= MapSL(LocalLock16(es
->hloc16
));
2518 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2520 LocalUnlock16(es
->hloc16
);
2522 LocalUnlock(es
->hloc32A
);
2525 if (stack16
) stack16
->ds
= oldDS
;
2526 LocalUnlock(es
->hloc32W
);
2530 ERR("no buffer ... please report\n");
2538 /*********************************************************************
2540 * EDIT_UpdateScrollInfo
2543 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2545 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2548 si
.cbSize
= sizeof(SCROLLINFO
);
2549 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2551 si
.nMax
= es
->line_count
- 1;
2552 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2553 si
.nPos
= es
->y_offset
;
2554 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2555 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2556 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2559 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2562 si
.cbSize
= sizeof(SCROLLINFO
);
2563 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2565 si
.nMax
= es
->text_width
- 1;
2566 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2567 si
.nPos
= es
->x_offset
;
2568 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2569 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2570 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2574 /*********************************************************************
2576 * EDIT_WordBreakProc
2578 * Find the beginning of words.
2579 * Note: unlike the specs for a WordBreakProc, this function only
2580 * allows to be called without linebreaks between s[0] up to
2581 * s[count - 1]. Remember it is only called
2582 * internally, so we can decide this for ourselves.
2585 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2589 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2599 if (s
[index
] == ' ') {
2600 while (index
&& (s
[index
] == ' '))
2603 while (index
&& (s
[index
] != ' '))
2605 if (s
[index
] == ' ')
2609 while (index
&& (s
[index
] != ' '))
2611 if (s
[index
] == ' ')
2621 if (s
[index
] == ' ')
2622 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2624 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2626 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2630 case WB_ISDELIMITER
:
2631 ret
= (s
[index
] == ' ');
2634 ERR("unknown action code, please report !\n");
2641 /*********************************************************************
2645 * returns line number (not index) in high-order word of result.
2646 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2647 * to Richedit, not to the edit control. Original documentation is valid.
2648 * FIXME: do the specs mean to return -1 if outside client area or
2649 * if outside formatting rectangle ???
2652 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2660 GetClientRect(es
->hwndSelf
, &rc
);
2661 if (!PtInRect(&rc
, pt
))
2664 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2665 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2669 /*********************************************************************
2673 * Enable or disable soft breaks.
2675 * This means: insert or remove the soft linebreak character (\r\r\n).
2676 * Take care to check if the text still fits the buffer after insertion.
2677 * If not, notify with EN_ERRSPACE.
2680 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2682 es
->flags
&= ~EF_USE_SOFTBRK
;
2684 es
->flags
|= EF_USE_SOFTBRK
;
2685 FIXME("soft break enabled, not implemented\n");
2691 /*********************************************************************
2695 * Hopefully this won't fire back at us.
2696 * We always start with a fixed buffer in the local heap.
2697 * Despite of the documentation says that the local heap is used
2698 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2699 * buffer on the local heap.
2702 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2706 if (!(es
->style
& ES_MULTILINE
))
2710 hLocal
= es
->hloc32W
;
2716 UINT countA
, alloc_size
;
2717 TRACE("Allocating 32-bit ANSI alias buffer\n");
2718 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2719 alloc_size
= ROUND_TO_GROW(countA
);
2720 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2722 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2725 textA
= LocalLock(es
->hloc32A
);
2726 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2727 LocalUnlock(es
->hloc32A
);
2729 hLocal
= es
->hloc32A
;
2732 es
->flags
|= EF_APP_HAS_HANDLE
;
2733 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2738 /*********************************************************************
2742 * Hopefully this won't fire back at us.
2743 * We always start with a buffer in 32 bit linear memory.
2744 * However, with this message a 16 bit application requests
2745 * a handle of 16 bit local heap memory, where it expects to find
2747 * It's a pitty that from this moment on we have to use this
2748 * local heap, because applications may rely on the handle
2751 * In this function we'll try to switch to local heap.
2753 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2756 UINT countA
, alloc_size
;
2757 STACK16FRAME
* stack16
;
2760 if (!(es
->style
& ES_MULTILINE
))
2766 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2767 oldDS
= stack16
->ds
;
2768 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2770 if (!LocalHeapSize16()) {
2772 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2773 ERR("could not initialize local heap\n");
2776 TRACE("local heap initialized\n");
2779 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2780 alloc_size
= ROUND_TO_GROW(countA
);
2782 TRACE("Allocating 16-bit ANSI alias buffer\n");
2783 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2784 ERR("could not allocate new 16 bit buffer\n");
2788 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2789 ERR("could not lock new 16 bit buffer\n");
2790 LocalFree16(es
->hloc16
);
2795 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2796 LocalUnlock16(es
->hloc16
);
2797 es
->flags
|= EF_APP_HAS_HANDLE
;
2799 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2802 stack16
->ds
= oldDS
;
2807 /*********************************************************************
2812 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2815 INT line_len
, dst_len
;
2818 if (es
->style
& ES_MULTILINE
) {
2819 if (line
>= es
->line_count
)
2823 i
= EDIT_EM_LineIndex(es
, line
);
2825 line_len
= EDIT_EM_LineLength(es
, i
);
2826 dst_len
= *(WORD
*)dst
;
2829 if(dst_len
<= line_len
)
2831 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2834 else /* Append 0 if enough space */
2836 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2843 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2844 if(!ret
&& line_len
) /* Insufficient buffer size */
2846 if(ret
< dst_len
) /* Append 0 if enough space */
2847 ((LPSTR
)dst
)[ret
] = 0;
2853 /*********************************************************************
2858 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2860 UINT s
= es
->selection_start
;
2861 UINT e
= es
->selection_end
;
2868 return MAKELONG(s
, e
);
2872 /*********************************************************************
2876 * FIXME: is this right ? (or should it be only VSCROLL)
2877 * (and maybe only for edit controls that really have their
2878 * own scrollbars) (and maybe only for multiline controls ?)
2879 * All in all: very poorly documented
2882 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2884 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2885 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2889 /*********************************************************************
2894 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2899 if (!(es
->style
& ES_MULTILINE
))
2901 if (index
> (INT
)get_text_length(es
))
2902 return es
->line_count
- 1;
2904 index
= min(es
->selection_start
, es
->selection_end
);
2907 line_def
= es
->first_line_def
;
2908 index
-= line_def
->length
;
2909 while ((index
>= 0) && line_def
->next
) {
2911 line_def
= line_def
->next
;
2912 index
-= line_def
->length
;
2918 /*********************************************************************
2923 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
2926 const LINEDEF
*line_def
;
2928 if (!(es
->style
& ES_MULTILINE
))
2930 if (line
>= es
->line_count
)
2934 line_def
= es
->first_line_def
;
2936 INT index
= es
->selection_end
- line_def
->length
;
2937 while ((index
>= 0) && line_def
->next
) {
2938 line_index
+= line_def
->length
;
2939 line_def
= line_def
->next
;
2940 index
-= line_def
->length
;
2944 line_index
+= line_def
->length
;
2945 line_def
= line_def
->next
;
2953 /*********************************************************************
2958 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2962 if (!(es
->style
& ES_MULTILINE
))
2963 return get_text_length(es
);
2966 /* get the number of remaining non-selected chars of selected lines */
2967 INT32 l
; /* line number */
2968 INT32 li
; /* index of first char in line */
2970 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2971 /* # chars before start of selection area */
2972 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2973 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2974 /* # chars after end of selection */
2975 li
= EDIT_EM_LineIndex(es
, l
);
2976 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2979 line_def
= es
->first_line_def
;
2980 index
-= line_def
->length
;
2981 while ((index
>= 0) && line_def
->next
) {
2982 line_def
= line_def
->next
;
2983 index
-= line_def
->length
;
2985 return line_def
->net_length
;
2989 /*********************************************************************
2993 * NOTE: dx is in average character widths, dy - in lines;
2996 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2998 if (!(es
->style
& ES_MULTILINE
))
3001 dx
*= es
->char_width
;
3002 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3005 /*********************************************************************
3007 * EDIT_EM_LineScroll_internal
3009 * Version of EDIT_EM_LineScroll for internal use.
3010 * It doesn't refuse if ES_MULTILINE is set and assumes that
3011 * dx is in pixels, dy - in lines.
3014 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3017 INT x_offset_in_pixels
;
3018 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3021 if (es
->style
& ES_MULTILINE
)
3023 x_offset_in_pixels
= es
->x_offset
;
3028 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3031 if (-dx
> x_offset_in_pixels
)
3032 dx
= -x_offset_in_pixels
;
3033 if (dx
> es
->text_width
- x_offset_in_pixels
)
3034 dx
= es
->text_width
- x_offset_in_pixels
;
3035 nyoff
= max(0, es
->y_offset
+ dy
);
3036 if (nyoff
>= es
->line_count
- lines_per_page
)
3037 nyoff
= max(0, es
->line_count
- lines_per_page
);
3038 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3043 es
->y_offset
= nyoff
;
3044 if(es
->style
& ES_MULTILINE
)
3047 es
->x_offset
+= dx
/ es
->char_width
;
3049 GetClientRect(es
->hwndSelf
, &rc1
);
3050 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3051 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3052 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3053 /* force scroll info update */
3054 EDIT_UpdateScrollInfo(es
);
3056 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3057 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3058 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3059 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3064 /*********************************************************************
3069 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3071 INT len
= get_text_length(es
);
3084 index
= min(index
, len
);
3085 dc
= GetDC(es
->hwndSelf
);
3087 old_font
= SelectObject(dc
, es
->font
);
3088 if (es
->style
& ES_MULTILINE
) {
3089 l
= EDIT_EM_LineFromChar(es
, index
);
3090 y
= (l
- es
->y_offset
) * es
->line_height
;
3091 li
= EDIT_EM_LineIndex(es
, l
);
3092 if (after_wrap
&& (li
== index
) && l
) {
3094 line_def
= es
->first_line_def
;
3096 line_def
= line_def
->next
;
3099 if (line_def
->ending
== END_WRAP
) {
3101 y
-= es
->line_height
;
3102 li
= EDIT_EM_LineIndex(es
, l
);
3106 line_def
= es
->first_line_def
;
3107 while (line_def
->index
!= li
)
3108 line_def
= line_def
->next
;
3110 ll
= line_def
->net_length
;
3111 lw
= line_def
->width
;
3113 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3114 if (es
->style
& ES_RIGHT
)
3116 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3117 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3120 else if (es
->style
& ES_CENTER
)
3122 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3123 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3128 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3129 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3132 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3133 if (index
< es
->x_offset
) {
3134 GetTextExtentPoint32W(dc
, text
+ index
,
3135 es
->x_offset
- index
, &size
);
3138 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3139 index
- es
->x_offset
, &size
);
3142 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3144 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3145 if (w
> es
->text_width
)
3147 if (es
->style
& ES_RIGHT
)
3148 x
+= w
- es
->text_width
;
3149 else if (es
->style
& ES_CENTER
)
3150 x
+= (w
- es
->text_width
) / 2;
3155 if (es
->style
& ES_PASSWORD
)
3156 HeapFree(GetProcessHeap(), 0, text
);
3158 x
+= es
->format_rect
.left
;
3159 y
+= es
->format_rect
.top
;
3161 SelectObject(dc
, old_font
);
3162 ReleaseDC(es
->hwndSelf
, dc
);
3163 return MAKELONG((INT16
)x
, (INT16
)y
);
3167 /*********************************************************************
3171 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3174 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3176 UINT strl
= strlenW(lpsz_replace
);
3177 UINT tl
= get_text_length(es
);
3188 TRACE("%s, can_undo %d, send_update %d\n",
3189 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3191 s
= es
->selection_start
;
3192 e
= es
->selection_end
;
3194 if ((s
== e
) && !strl
)
3199 size
= tl
- (e
- s
) + strl
;
3203 /* Issue the EN_MAXTEXT notification and continue with replacing text
3204 * such that buffer limit is honored. */
3205 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
3206 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3207 /* Buffer limit can be smaller than the actual length of text in combobox */
3208 if (es
->buffer_limit
< (tl
- (e
-s
)))
3211 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3214 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3218 /* there is something to be deleted */
3219 TRACE("deleting stuff.\n");
3221 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3223 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3224 buf
[bufl
] = 0; /* ensure 0 termination */
3226 strcpyW(es
->text
+ s
, es
->text
+ e
);
3227 text_buffer_changed(es
);
3230 /* there is an insertion */
3231 tl
= get_text_length(es
);
3232 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
));
3233 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3235 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3236 p
[i
] = lpsz_replace
[i
];
3237 if(es
->style
& ES_UPPERCASE
)
3238 CharUpperBuffW(p
, strl
);
3239 else if(es
->style
& ES_LOWERCASE
)
3240 CharLowerBuffW(p
, strl
);
3241 text_buffer_changed(es
);
3243 if (es
->style
& ES_MULTILINE
)
3245 INT st
= min(es
->selection_start
, es
->selection_end
);
3246 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3248 hrgn
= CreateRectRgn(0, 0, 0, 0);
3249 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3250 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3251 /* if text is too long undo all changes */
3252 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3254 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3256 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3258 text_buffer_changed(es
);
3259 EDIT_BuildLineDefs_ML(es
, s
, e
,
3260 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3263 hrgn
= CreateRectRgn(0, 0, 0, 0);
3264 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3268 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3269 EDIT_CalcLineWidth_SL(es
);
3270 /* remove chars that don't fit */
3271 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3272 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3273 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3275 EDIT_CalcLineWidth_SL(es
);
3277 text_buffer_changed(es
);
3278 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3284 utl
= strlenW(es
->undo_text
);
3285 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3286 /* undo-buffer is extended to the right */
3287 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3288 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3289 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3290 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3291 /* undo-buffer is extended to the left */
3292 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3293 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3295 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3297 es
->undo_position
= s
;
3299 /* new undo-buffer */
3300 EDIT_MakeUndoFit(es
, e
- s
);
3301 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3302 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3303 es
->undo_position
= s
;
3305 /* any deletion makes the old insertion-undo invalid */
3306 es
->undo_insert_count
= 0;
3308 EDIT_EM_EmptyUndoBuffer(es
);
3312 if ((s
== es
->undo_position
) ||
3313 ((es
->undo_insert_count
) &&
3314 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3316 * insertion is new and at delete position or
3317 * an extension to either left or right
3319 es
->undo_insert_count
+= strl
;
3321 /* new insertion undo */
3322 es
->undo_position
= s
;
3323 es
->undo_insert_count
= strl
;
3324 /* new insertion makes old delete-buffer invalid */
3325 *es
->undo_text
= '\0';
3328 EDIT_EM_EmptyUndoBuffer(es
);
3332 HeapFree(GetProcessHeap(), 0, buf
);
3336 /* If text has been deleted and we're right or center aligned then scroll rightward */
3337 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3339 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3341 if (delta
< 0 && es
->x_offset
)
3343 if (abs(delta
) > es
->x_offset
)
3346 es
->x_offset
+= delta
;
3350 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3351 es
->flags
|= EF_MODIFIED
;
3352 if (send_update
) es
->flags
|= EF_UPDATE
;
3355 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3359 EDIT_UpdateText(es
, NULL
, TRUE
);
3361 EDIT_EM_ScrollCaret(es
);
3363 /* force scroll info update */
3364 EDIT_UpdateScrollInfo(es
);
3367 if(send_update
|| (es
->flags
& EF_UPDATE
))
3369 es
->flags
&= ~EF_UPDATE
;
3370 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3375 /*********************************************************************
3380 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3384 if (!(es
->style
& ES_MULTILINE
))
3385 return (LRESULT
)FALSE
;
3395 if (es
->y_offset
< es
->line_count
- 1)
3400 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3403 if (es
->y_offset
< es
->line_count
- 1)
3404 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3407 return (LRESULT
)FALSE
;
3410 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3411 /* check if we are going to move too far */
3412 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3413 dy
= es
->line_count
- vlc
- es
->y_offset
;
3415 /* Notification is done in EDIT_EM_LineScroll */
3417 EDIT_EM_LineScroll(es
, 0, dy
);
3419 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3423 /*********************************************************************
3428 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3430 if (es
->style
& ES_MULTILINE
) {
3435 INT cw
= es
->char_width
;
3440 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3441 li
= EDIT_EM_LineIndex(es
, l
);
3442 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3443 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3444 if (l
>= es
->y_offset
+ vlc
)
3445 dy
= l
- vlc
+ 1 - es
->y_offset
;
3446 if (l
< es
->y_offset
)
3447 dy
= l
- es
->y_offset
;
3448 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3449 if (x
< es
->format_rect
.left
)
3450 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3451 if (x
> es
->format_rect
.right
)
3452 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3453 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3455 /* check if we are going to move too far */
3456 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3457 dx
= es
->text_width
- ww
- es
->x_offset
;
3458 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3459 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3466 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3467 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3468 if (x
< es
->format_rect
.left
) {
3469 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3472 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3473 } while ((x
< goal
) && es
->x_offset
);
3474 /* FIXME: use ScrollWindow() somehow to improve performance */
3475 EDIT_UpdateText(es
, NULL
, TRUE
);
3476 } else if (x
> es
->format_rect
.right
) {
3478 INT len
= get_text_length(es
);
3479 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3482 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3483 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3484 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3485 /* FIXME: use ScrollWindow() somehow to improve performance */
3486 EDIT_UpdateText(es
, NULL
, TRUE
);
3490 if(es
->flags
& EF_FOCUSED
)
3491 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3495 /*********************************************************************
3499 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3502 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3504 if (!(es
->style
& ES_MULTILINE
))
3508 WARN("called with NULL handle\n");
3512 EDIT_UnlockBuffer(es
, TRUE
);
3516 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3517 HANDLE16 oldDS
= stack16
->ds
;
3519 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3520 LocalFree16(es
->hloc16
);
3521 stack16
->ds
= oldDS
;
3529 LocalFree(es
->hloc32A
);
3541 countA
= LocalSize(hloc
);
3542 textA
= LocalLock(hloc
);
3543 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3544 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3546 ERR("Could not allocate new unicode buffer\n");
3549 textW
= LocalLock(hloc32W_new
);
3550 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3551 LocalUnlock(hloc32W_new
);
3555 LocalFree(es
->hloc32W
);
3557 es
->hloc32W
= hloc32W_new
;
3561 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3563 es
->flags
|= EF_APP_HAS_HANDLE
;
3564 EDIT_LockBuffer(es
);
3566 es
->x_offset
= es
->y_offset
= 0;
3567 es
->selection_start
= es
->selection_end
= 0;
3568 EDIT_EM_EmptyUndoBuffer(es
);
3569 es
->flags
&= ~EF_MODIFIED
;
3570 es
->flags
&= ~EF_UPDATE
;
3571 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3572 EDIT_UpdateText(es
, NULL
, TRUE
);
3573 EDIT_EM_ScrollCaret(es
);
3574 /* force scroll info update */
3575 EDIT_UpdateScrollInfo(es
);
3579 /*********************************************************************
3583 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3586 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3588 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3589 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3590 HANDLE16 oldDS
= stack16
->ds
;
3596 if (!(es
->style
& ES_MULTILINE
))
3600 WARN("called with NULL handle\n");
3604 EDIT_UnlockBuffer(es
, TRUE
);
3608 LocalFree(es
->hloc32A
);
3612 stack16
->ds
= hInstance
;
3613 countA
= LocalSize16(hloc
);
3614 textA
= MapSL(LocalLock16(hloc
));
3615 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3616 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3618 ERR("Could not allocate new unicode buffer\n");
3621 textW
= LocalLock(hloc32W_new
);
3622 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3623 LocalUnlock(hloc32W_new
);
3624 LocalUnlock16(hloc
);
3625 stack16
->ds
= oldDS
;
3628 LocalFree(es
->hloc32W
);
3630 es
->hloc32W
= hloc32W_new
;
3633 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3635 es
->flags
|= EF_APP_HAS_HANDLE
;
3636 EDIT_LockBuffer(es
);
3638 es
->x_offset
= es
->y_offset
= 0;
3639 es
->selection_start
= es
->selection_end
= 0;
3640 EDIT_EM_EmptyUndoBuffer(es
);
3641 es
->flags
&= ~EF_MODIFIED
;
3642 es
->flags
&= ~EF_UPDATE
;
3643 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3644 EDIT_UpdateText(es
, NULL
, TRUE
);
3645 EDIT_EM_ScrollCaret(es
);
3646 /* force scroll info update */
3647 EDIT_UpdateScrollInfo(es
);
3651 /*********************************************************************
3655 * NOTE: this version currently implements WinNT limits
3658 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
3660 if (!limit
) limit
= ~0u;
3661 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
3662 es
->buffer_limit
= limit
;
3666 /*********************************************************************
3670 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3671 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3672 * margin according to the textmetrics of the current font.
3674 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3675 * of the char's width as the margin, but this is not how Windows handles this.
3676 * For all other fonts Windows sets the margins to zero.
3678 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3679 * edit control is equal to or larger than a certain size.
3680 * Interestingly if one subtracts both the left and right margins from
3681 * this size one always seems to get an even number. The extents of
3682 * the (four character) string "'**'" match this quite closely, so
3683 * we'll use this until we come up with a better idea.
3685 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3687 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3690 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3691 return sz
.cx
+ left
+ right
;
3694 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3695 WORD left
, WORD right
, BOOL repaint
)
3698 INT default_left_margin
= 0; /* in pixels */
3699 INT default_right_margin
= 0; /* in pixels */
3701 /* Set the default margins depending on the font */
3702 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3703 HDC dc
= GetDC(es
->hwndSelf
);
3704 HFONT old_font
= SelectObject(dc
, es
->font
);
3705 GetTextMetricsW(dc
, &tm
);
3706 /* The default margins are only non zero for TrueType or Vector fonts */
3707 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3710 /* This must be calculated more exactly! But how? */
3711 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3712 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3713 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3714 GetClientRect(es
->hwndSelf
, &rc
);
3715 if(rc
.right
- rc
.left
< min_size
) {
3716 default_left_margin
= es
->left_margin
;
3717 default_right_margin
= es
->right_margin
;
3720 SelectObject(dc
, old_font
);
3721 ReleaseDC(es
->hwndSelf
, dc
);
3724 if (action
& EC_LEFTMARGIN
) {
3725 es
->format_rect
.left
-= es
->left_margin
;
3726 if (left
!= EC_USEFONTINFO
)
3727 es
->left_margin
= left
;
3729 es
->left_margin
= default_left_margin
;
3730 es
->format_rect
.left
+= es
->left_margin
;
3733 if (action
& EC_RIGHTMARGIN
) {
3734 es
->format_rect
.right
+= es
->right_margin
;
3735 if (right
!= EC_USEFONTINFO
)
3736 es
->right_margin
= right
;
3738 es
->right_margin
= default_right_margin
;
3739 es
->format_rect
.right
-= es
->right_margin
;
3742 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3743 EDIT_AdjustFormatRect(es
);
3744 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3747 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3751 /*********************************************************************
3753 * EM_SETPASSWORDCHAR
3756 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3760 if (es
->style
& ES_MULTILINE
)
3763 if (es
->password_char
== c
)
3766 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3767 es
->password_char
= c
;
3769 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3770 es
->style
|= ES_PASSWORD
;
3772 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3773 es
->style
&= ~ES_PASSWORD
;
3775 EDIT_UpdateText(es
, NULL
, TRUE
);
3779 /*********************************************************************
3783 * note: unlike the specs say: the order of start and end
3784 * _is_ preserved in Windows. (i.e. start can be > end)
3785 * In other words: this handler is OK
3788 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3790 UINT old_start
= es
->selection_start
;
3791 UINT old_end
= es
->selection_end
;
3792 UINT len
= get_text_length(es
);
3794 if (start
== (UINT
)-1) {
3795 start
= es
->selection_end
;
3796 end
= es
->selection_end
;
3798 start
= min(start
, len
);
3799 end
= min(end
, len
);
3801 es
->selection_start
= start
;
3802 es
->selection_end
= end
;
3804 es
->flags
|= EF_AFTER_WRAP
;
3806 es
->flags
&= ~EF_AFTER_WRAP
;
3807 /* Compute the necessary invalidation region. */
3808 /* Note that we don't need to invalidate regions which have
3809 * "never" been selected, or those which are "still" selected.
3810 * In fact, every time we hit a selection boundary, we can
3811 * *toggle* whether we need to invalidate. Thus we can optimize by
3812 * *sorting* the interval endpoints. Let's assume that we sort them
3814 * start <= end <= old_start <= old_end
3815 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3816 * in 5 comparisons; ie it's impossible to do better than the
3818 ORDER_UINT(end
, old_end
);
3819 ORDER_UINT(start
, old_start
);
3820 ORDER_UINT(old_start
, old_end
);
3821 ORDER_UINT(start
, end
);
3822 /* Note that at this point 'end' and 'old_start' are not in order, but
3823 * start is definitely the min. and old_end is definitely the max. */
3824 if (end
!= old_start
)
3828 * ORDER_UINT32(end, old_start);
3829 * EDIT_InvalidateText(es, start, end);
3830 * EDIT_InvalidateText(es, old_start, old_end);
3831 * in place of the following if statement.
3832 * (That would complete the optimal five-comparison four-element sort.)
3834 if (old_start
> end
)
3836 EDIT_InvalidateText(es
, start
, end
);
3837 EDIT_InvalidateText(es
, old_start
, old_end
);
3841 EDIT_InvalidateText(es
, start
, old_start
);
3842 EDIT_InvalidateText(es
, end
, old_end
);
3845 else EDIT_InvalidateText(es
, start
, old_end
);
3849 /*********************************************************************
3854 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3856 if (!(es
->style
& ES_MULTILINE
))
3858 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3859 es
->tabs_count
= count
;
3863 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3864 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3870 /*********************************************************************
3875 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3877 if (!(es
->style
& ES_MULTILINE
))
3879 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3880 es
->tabs_count
= count
;
3885 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3886 for (i
= 0 ; i
< count
; i
++)
3887 es
->tabs
[i
] = *tabs
++;
3893 /*********************************************************************
3895 * EM_SETWORDBREAKPROC
3898 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3900 if (es
->word_break_proc
== wbp
)
3903 es
->word_break_proc
= wbp
;
3904 es
->word_break_proc16
= NULL
;
3906 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3907 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3908 EDIT_UpdateText(es
, NULL
, TRUE
);
3913 /*********************************************************************
3915 * EM_SETWORDBREAKPROC16
3918 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3920 if (es
->word_break_proc16
== wbp
)
3923 es
->word_break_proc
= NULL
;
3924 es
->word_break_proc16
= wbp
;
3925 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3926 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3927 EDIT_UpdateText(es
, NULL
, TRUE
);
3932 /*********************************************************************
3937 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3942 /* As per MSDN spec, for a single-line edit control,
3943 the return value is always TRUE */
3944 if( es
->style
& ES_READONLY
)
3945 return !(es
->style
& ES_MULTILINE
);
3947 ulength
= strlenW(es
->undo_text
);
3949 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3951 strcpyW(utext
, es
->undo_text
);
3953 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3954 es
->undo_insert_count
, debugstr_w(utext
));
3956 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3957 EDIT_EM_EmptyUndoBuffer(es
);
3958 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3959 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3960 /* send the notification after the selection start and end are set */
3961 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3962 EDIT_EM_ScrollCaret(es
);
3963 HeapFree(GetProcessHeap(), 0, utext
);
3965 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3966 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3971 /*********************************************************************
3976 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3980 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3984 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3985 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3988 if (es
->style
& ES_MULTILINE
) {
3989 if (es
->style
& ES_READONLY
) {
3990 EDIT_MoveHome(es
, FALSE
);
3991 EDIT_MoveDown_ML(es
, FALSE
);
3993 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3994 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3999 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4001 static const WCHAR tabW
[] = {'\t',0};
4002 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4006 if (!(es
->style
& ES_READONLY
) && !control
) {
4007 if (es
->selection_start
!= es
->selection_end
)
4010 /* delete character left of caret */
4011 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4012 EDIT_MoveBackward(es
, TRUE
);
4018 if (!(es
->style
& ES_PASSWORD
))
4019 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4022 if (!(es
->style
& ES_READONLY
))
4023 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4026 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4027 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4030 if (!(es
->style
& ES_READONLY
))
4031 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4035 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4036 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4039 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4043 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4050 /*********************************************************************
4055 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4057 if (code
|| control
)
4077 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4078 EDIT_EM_ScrollCaret(es
);
4081 ERR("unknown menu item, please report\n");
4087 /*********************************************************************
4091 * Note: the resource files resource/sysres_??.rc cannot define a
4092 * single popup menu. Hence we use a (dummy) menubar
4093 * containing the single popup menu as its first item.
4095 * FIXME: the message identifiers have been chosen arbitrarily,
4096 * hence we use MF_BYPOSITION.
4097 * We might as well use the "real" values (anybody knows ?)
4098 * The menu definition is in resources/sysres_??.rc.
4099 * Once these are OK, we better use MF_BYCOMMAND here
4100 * (as we do in EDIT_WM_Command()).
4103 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4105 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4106 HMENU popup
= GetSubMenu(menu
, 0);
4107 UINT start
= es
->selection_start
;
4108 UINT end
= es
->selection_end
;
4110 ORDER_UINT(start
, end
);
4113 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4115 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4117 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4119 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4121 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4123 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4125 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4128 /* Windows places the menu at the edit's center in this case */
4129 GetClientRect(es
->hwndSelf
, &rc
);
4130 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4131 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4132 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4135 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4140 /*********************************************************************
4145 static void EDIT_WM_Copy(EDITSTATE
*es
)
4147 INT s
= min(es
->selection_start
, es
->selection_end
);
4148 INT e
= max(es
->selection_start
, es
->selection_end
);
4156 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4157 dst
= GlobalLock(hdst
);
4158 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4159 dst
[len
] = 0; /* ensure 0 termination */
4160 TRACE("%s\n", debugstr_w(dst
));
4162 OpenClipboard(es
->hwndSelf
);
4164 SetClipboardData(CF_UNICODETEXT
, hdst
);
4169 /*********************************************************************
4174 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4178 TRACE("%s\n", debugstr_w(name
));
4180 * To initialize some final structure members, we call some helper
4181 * functions. However, since the EDITSTATE is not consistent (i.e.
4182 * not fully initialized), we should be very careful which
4183 * functions can be called, and in what order.
4185 EDIT_WM_SetFont(es
, 0, FALSE
);
4186 EDIT_EM_EmptyUndoBuffer(es
);
4188 /* We need to calculate the format rect
4189 (applications may send EM_SETMARGINS before the control gets visible) */
4190 GetClientRect(es
->hwndSelf
, &clientRect
);
4191 EDIT_SetRectNP(es
, &clientRect
);
4193 if (name
&& *name
) {
4194 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4195 /* if we insert text to the editline, the text scrolls out
4196 * of the window, as the caret is placed after the insert
4197 * pos normally; thus we reset es->selection... to 0 and
4200 es
->selection_start
= es
->selection_end
= 0;
4201 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4202 * Messages are only to be sent when the USER does something to
4203 * change the contents. So I am removing this EN_CHANGE
4205 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4207 EDIT_EM_ScrollCaret(es
);
4209 /* force scroll info update */
4210 EDIT_UpdateScrollInfo(es
);
4211 /* The rule seems to return 1 here for success */
4212 /* Power Builder masked edit controls will crash */
4214 /* FIXME: is that in all cases so ? */
4219 /*********************************************************************
4224 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4229 while (LocalUnlock(es
->hloc32W
)) ;
4230 LocalFree(es
->hloc32W
);
4233 while (LocalUnlock(es
->hloc32A
)) ;
4234 LocalFree(es
->hloc32A
);
4237 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4238 HANDLE16 oldDS
= stack16
->ds
;
4240 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4241 while (LocalUnlock16(es
->hloc16
)) ;
4242 LocalFree16(es
->hloc16
);
4243 stack16
->ds
= oldDS
;
4246 pc
= es
->first_line_def
;
4250 HeapFree(GetProcessHeap(), 0, pc
);
4254 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4255 HeapFree(GetProcessHeap(), 0, es
);
4261 /*********************************************************************
4266 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4268 if(!count
) return 0;
4272 lstrcpynW(dst
, es
->text
, count
);
4273 return strlenW(dst
);
4277 LPSTR textA
= (LPSTR
)dst
;
4278 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4279 textA
[count
- 1] = 0; /* ensure 0 termination */
4280 return strlen(textA
);
4284 /*********************************************************************
4289 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4294 if (!(es
->style
& ES_MULTILINE
))
4297 if (!(es
->style
& ES_AUTOHSCROLL
))
4301 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4304 TRACE("SB_LINELEFT\n");
4306 dx
= -es
->char_width
;
4309 TRACE("SB_LINERIGHT\n");
4310 if (es
->x_offset
< es
->text_width
)
4311 dx
= es
->char_width
;
4314 TRACE("SB_PAGELEFT\n");
4316 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4319 TRACE("SB_PAGERIGHT\n");
4320 if (es
->x_offset
< es
->text_width
)
4321 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4329 TRACE("SB_RIGHT\n");
4330 if (es
->x_offset
< es
->text_width
)
4331 dx
= es
->text_width
- es
->x_offset
;
4334 TRACE("SB_THUMBTRACK %d\n", pos
);
4335 es
->flags
|= EF_HSCROLL_TRACK
;
4336 if(es
->style
& WS_HSCROLL
)
4337 dx
= pos
- es
->x_offset
;
4342 if(pos
< 0 || pos
> 100) return 0;
4343 /* Assume default scroll range 0-100 */
4344 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4345 new_x
= pos
* (es
->text_width
- fw
) / 100;
4346 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4349 case SB_THUMBPOSITION
:
4350 TRACE("SB_THUMBPOSITION %d\n", pos
);
4351 es
->flags
&= ~EF_HSCROLL_TRACK
;
4352 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4353 dx
= pos
- es
->x_offset
;
4358 if(pos
< 0 || pos
> 100) return 0;
4359 /* Assume default scroll range 0-100 */
4360 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4361 new_x
= pos
* (es
->text_width
- fw
) / 100;
4362 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4365 /* force scroll info update */
4366 EDIT_UpdateScrollInfo(es
);
4367 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4371 TRACE("SB_ENDSCROLL\n");
4374 * FIXME : the next two are undocumented !
4375 * Are we doing the right thing ?
4376 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4377 * although it's also a regular control message.
4379 case EM_GETTHUMB
: /* this one is used by NT notepad */
4383 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4384 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4387 /* Assume default scroll range 0-100 */
4388 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4389 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4391 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4394 case EM_LINESCROLL16
:
4395 TRACE("EM_LINESCROLL16\n");
4400 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4406 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4407 /* check if we are going to move too far */
4408 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4409 dx
= es
->text_width
- fw
- es
->x_offset
;
4411 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4417 /*********************************************************************
4422 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4424 HWND hLBox
= es
->hwndListBox
;
4432 hCombo
= GetParent(es
->hwndSelf
);
4436 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4438 if (key
== VK_UP
|| key
== VK_DOWN
)
4440 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4443 if (msg
== WM_KEYDOWN
|| nEUI
)
4444 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4450 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4452 /* make sure ComboLBox pops up */
4453 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4458 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4461 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4463 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4465 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4470 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4476 /*********************************************************************
4480 * Handling of special keys that don't produce a WM_CHAR
4481 * (i.e. non-printable keys) & Backspace & Delete
4484 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4489 if (GetKeyState(VK_MENU
) & 0x8000)
4492 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4493 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4498 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4503 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4504 EDIT_MoveUp_ML(es
, shift
);
4507 EDIT_MoveWordBackward(es
, shift
);
4509 EDIT_MoveBackward(es
, shift
);
4512 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4516 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4517 EDIT_MoveDown_ML(es
, shift
);
4519 EDIT_MoveWordForward(es
, shift
);
4521 EDIT_MoveForward(es
, shift
);
4524 EDIT_MoveHome(es
, shift
);
4527 EDIT_MoveEnd(es
, shift
);
4530 if (es
->style
& ES_MULTILINE
)
4531 EDIT_MovePageUp_ML(es
, shift
);
4533 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4536 if (es
->style
& ES_MULTILINE
)
4537 EDIT_MovePageDown_ML(es
, shift
);
4539 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4542 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4543 if (es
->selection_start
!= es
->selection_end
) {
4550 /* delete character left of caret */
4551 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4552 EDIT_MoveBackward(es
, TRUE
);
4554 } else if (control
) {
4555 /* delete to end of line */
4556 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4557 EDIT_MoveEnd(es
, TRUE
);
4560 /* delete character right of caret */
4561 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4562 EDIT_MoveForward(es
, TRUE
);
4570 if (!(es
->style
& ES_READONLY
))
4576 /* If the edit doesn't want the return send a message to the default object */
4577 if(!(es
->style
& ES_WANTRETURN
))
4579 HWND hwndParent
= GetParent(es
->hwndSelf
);
4580 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4581 if (HIWORD(dw
) == DC_HASDEFID
)
4583 SendMessageW( hwndParent
, WM_COMMAND
,
4584 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4585 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4594 /*********************************************************************
4599 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4601 es
->flags
&= ~EF_FOCUSED
;
4603 if(!(es
->style
& ES_NOHIDESEL
))
4604 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4605 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4610 /*********************************************************************
4614 * The caret position has been set on the WM_LBUTTONDOWN message
4617 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4620 INT e
= es
->selection_end
;
4625 es
->bCaptureState
= TRUE
;
4626 SetCapture(es
->hwndSelf
);
4628 l
= EDIT_EM_LineFromChar(es
, e
);
4629 li
= EDIT_EM_LineIndex(es
, l
);
4630 ll
= EDIT_EM_LineLength(es
, e
);
4631 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4632 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4633 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4634 EDIT_EM_ScrollCaret(es
);
4635 es
->region_posx
= es
->region_posy
= 0;
4636 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4641 /*********************************************************************
4646 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4651 es
->bCaptureState
= TRUE
;
4652 SetCapture(es
->hwndSelf
);
4653 EDIT_ConfinePoint(es
, &x
, &y
);
4654 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4655 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4656 EDIT_EM_ScrollCaret(es
);
4657 es
->region_posx
= es
->region_posy
= 0;
4658 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4660 if (!(es
->flags
& EF_FOCUSED
))
4661 SetFocus(es
->hwndSelf
);
4667 /*********************************************************************
4672 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4674 if (es
->bCaptureState
) {
4675 KillTimer(es
->hwndSelf
, 0);
4676 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4678 es
->bCaptureState
= FALSE
;
4683 /*********************************************************************
4688 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4690 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4695 /*********************************************************************
4700 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4706 /* If the mouse has been captured by process other than the edit control itself,
4707 * the windows edit controls will not select the strings with mouse move.
4709 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4713 * FIXME: gotta do some scrolling if outside client
4714 * area. Maybe reset the timer ?
4717 EDIT_ConfinePoint(es
, &x
, &y
);
4718 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4719 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4720 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4721 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4722 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4727 /*********************************************************************
4731 * See also EDIT_WM_StyleChanged
4733 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4738 TRACE("Creating %s edit control, style = %08x\n",
4739 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4741 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4743 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4746 * Note: since the EDITSTATE has not been fully initialized yet,
4747 * we can't use any API calls that may send
4748 * WM_XXX messages before WM_NCCREATE is completed.
4751 es
->is_unicode
= unicode
;
4752 es
->style
= lpcs
->style
;
4754 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4756 es
->hwndSelf
= hwnd
;
4757 /* Save parent, which will be notified by EN_* messages */
4758 es
->hwndParent
= lpcs
->hwndParent
;
4760 if (es
->style
& ES_COMBO
)
4761 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4763 /* Number overrides lowercase overrides uppercase (at least it
4764 * does in Win95). However I'll bet that ES_NUMBER would be
4765 * invalid under Win 3.1.
4767 if (es
->style
& ES_NUMBER
) {
4768 ; /* do not override the ES_NUMBER */
4769 } else if (es
->style
& ES_LOWERCASE
) {
4770 es
->style
&= ~ES_UPPERCASE
;
4772 if (es
->style
& ES_MULTILINE
) {
4773 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4774 if (es
->style
& WS_VSCROLL
)
4775 es
->style
|= ES_AUTOVSCROLL
;
4776 if (es
->style
& WS_HSCROLL
)
4777 es
->style
|= ES_AUTOHSCROLL
;
4778 es
->style
&= ~ES_PASSWORD
;
4779 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4780 /* Confirmed - RIGHT overrides CENTER */
4781 if (es
->style
& ES_RIGHT
)
4782 es
->style
&= ~ES_CENTER
;
4783 es
->style
&= ~WS_HSCROLL
;
4784 es
->style
&= ~ES_AUTOHSCROLL
;
4787 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4788 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4789 es
->style
&= ~ES_CENTER
;
4790 es
->style
&= ~WS_HSCROLL
;
4791 es
->style
&= ~WS_VSCROLL
;
4792 if (es
->style
& ES_PASSWORD
)
4793 es
->password_char
= '*';
4796 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4797 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4799 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4801 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4803 es
->undo_buffer_size
= es
->buffer_size
;
4805 if (es
->style
& ES_MULTILINE
)
4806 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4811 * In Win95 look and feel, the WS_BORDER style is replaced by the
4812 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4813 * control a nonclient area so we don't need to draw the border.
4814 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4815 * a nonclient area and we should handle painting the border ourselves.
4817 * When making modifications please ensure that the code still works
4818 * for edit controls created directly with style 0x50800000, exStyle 0
4819 * (which should have a single pixel border)
4821 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4822 es
->style
&= ~WS_BORDER
;
4823 else if (es
->style
& WS_BORDER
)
4824 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4829 /*********************************************************************
4834 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4847 BOOL rev
= es
->bEnableState
&&
4848 ((es
->flags
& EF_FOCUSED
) ||
4849 (es
->style
& ES_NOHIDESEL
));
4850 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4852 GetClientRect(es
->hwndSelf
, &rcClient
);
4854 /* get the background brush */
4855 brush
= EDIT_NotifyCtlColor(es
, dc
);
4857 /* paint the border and the background */
4858 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4860 if(es
->style
& WS_BORDER
) {
4861 bw
= GetSystemMetrics(SM_CXBORDER
);
4862 bh
= GetSystemMetrics(SM_CYBORDER
);
4864 if(es
->style
& ES_MULTILINE
) {
4865 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4866 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4869 /* Draw the frame. Same code as in nonclient.c */
4870 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
4871 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
4872 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4873 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
4874 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4875 SelectObject(dc
, old_brush
);
4877 /* Keep the border clean */
4878 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
4879 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
4882 GetClipBox(dc
, &rc
);
4883 FillRect(dc
, &rc
, brush
);
4885 IntersectClipRect(dc
, es
->format_rect
.left
,
4886 es
->format_rect
.top
,
4887 es
->format_rect
.right
,
4888 es
->format_rect
.bottom
);
4889 if (es
->style
& ES_MULTILINE
) {
4891 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4894 old_font
= SelectObject(dc
, es
->font
);
4896 if (!es
->bEnableState
)
4897 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4898 GetClipBox(dc
, &rcRgn
);
4899 if (es
->style
& ES_MULTILINE
) {
4900 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4901 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4902 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4903 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4904 EDIT_PaintLine(es
, dc
, i
, rev
);
4907 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4908 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4909 EDIT_PaintLine(es
, dc
, 0, rev
);
4912 SelectObject(dc
, old_font
);
4915 EndPaint(es
->hwndSelf
, &ps
);
4919 /*********************************************************************
4924 static void EDIT_WM_Paste(EDITSTATE
*es
)
4929 /* Protect read-only edit control from modification */
4930 if(es
->style
& ES_READONLY
)
4933 OpenClipboard(es
->hwndSelf
);
4934 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4935 src
= (LPWSTR
)GlobalLock(hsrc
);
4936 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4939 else if (es
->style
& ES_PASSWORD
) {
4940 /* clear selected text in password edit box even with empty clipboard */
4941 const WCHAR empty_strW
[] = { 0 };
4942 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
4948 /*********************************************************************
4953 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4955 es
->flags
|= EF_FOCUSED
;
4957 if (!(es
->style
& ES_NOHIDESEL
))
4958 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4960 /* single line edit updates itself */
4961 if (!(es
->style
& ES_MULTILINE
))
4963 HDC hdc
= GetDC(es
->hwndSelf
);
4964 EDIT_WM_Paint(es
, hdc
);
4965 ReleaseDC(es
->hwndSelf
, hdc
);
4968 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4969 EDIT_SetCaretPos(es
, es
->selection_end
,
4970 es
->flags
& EF_AFTER_WRAP
);
4971 ShowCaret(es
->hwndSelf
);
4972 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
4976 /*********************************************************************
4980 * With Win95 look the margins are set to default font value unless
4981 * the system font (font == 0) is being set, in which case they are left
4985 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4993 dc
= GetDC(es
->hwndSelf
);
4995 old_font
= SelectObject(dc
, font
);
4996 GetTextMetricsW(dc
, &tm
);
4997 es
->line_height
= tm
.tmHeight
;
4998 es
->char_width
= tm
.tmAveCharWidth
;
5000 SelectObject(dc
, old_font
);
5001 ReleaseDC(es
->hwndSelf
, dc
);
5003 /* Reset the format rect and the margins */
5004 GetClientRect(es
->hwndSelf
, &clientRect
);
5005 EDIT_SetRectNP(es
, &clientRect
);
5006 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5007 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5009 if (es
->style
& ES_MULTILINE
)
5010 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5012 EDIT_CalcLineWidth_SL(es
);
5015 EDIT_UpdateText(es
, NULL
, TRUE
);
5016 if (es
->flags
& EF_FOCUSED
) {
5018 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5019 EDIT_SetCaretPos(es
, es
->selection_end
,
5020 es
->flags
& EF_AFTER_WRAP
);
5021 ShowCaret(es
->hwndSelf
);
5026 /*********************************************************************
5031 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5032 * The modified flag is reset. No notifications are sent.
5034 * For single-line controls, reception of WM_SETTEXT triggers:
5035 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5038 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5040 LPWSTR textW
= NULL
;
5041 if (!unicode
&& text
)
5043 LPCSTR textA
= (LPCSTR
)text
;
5044 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5045 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5047 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5051 if (es
->flags
& EF_UPDATE
)
5052 /* fixed this bug once; complain if we see it about to happen again. */
5053 ERR("SetSel may generate UPDATE message whose handler may reset "
5056 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5059 TRACE("%s\n", debugstr_w(text
));
5060 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5062 HeapFree(GetProcessHeap(), 0, textW
);
5066 static const WCHAR empty_stringW
[] = {0};
5068 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5071 es
->flags
&= ~EF_MODIFIED
;
5072 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5074 /* Send the notification after the selection start and end have been set
5075 * edit control doesn't send notification on WM_SETTEXT
5076 * if it is multiline, or it is part of combobox
5078 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5080 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5081 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5083 EDIT_EM_ScrollCaret(es
);
5084 EDIT_UpdateScrollInfo(es
);
5088 /*********************************************************************
5093 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5095 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5097 TRACE("width = %d, height = %d\n", width
, height
);
5098 SetRect(&rc
, 0, 0, width
, height
);
5099 EDIT_SetRectNP(es
, &rc
);
5100 EDIT_UpdateText(es
, NULL
, TRUE
);
5105 /*********************************************************************
5109 * This message is sent by SetWindowLong on having changed either the Style
5110 * or the extended style.
5112 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5114 * See also EDIT_WM_NCCreate
5116 * It appears that the Windows version of the edit control allows the style
5117 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5118 * style variable which will generally be different. In this function we
5119 * update the internal style based on what changed in the externally visible
5122 * Much of this content as based upon the MSDN, especially:
5123 * Platform SDK Documentation -> User Interface Services ->
5124 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5125 * Edit Control Styles
5127 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5129 if (GWL_STYLE
== which
) {
5130 DWORD style_change_mask
;
5132 /* Only a subset of changes can be applied after the control
5135 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5137 if (es
->style
& ES_MULTILINE
)
5138 style_change_mask
|= ES_WANTRETURN
;
5140 new_style
= style
->styleNew
& style_change_mask
;
5142 /* Number overrides lowercase overrides uppercase (at least it
5143 * does in Win95). However I'll bet that ES_NUMBER would be
5144 * invalid under Win 3.1.
5146 if (new_style
& ES_NUMBER
) {
5147 ; /* do not override the ES_NUMBER */
5148 } else if (new_style
& ES_LOWERCASE
) {
5149 new_style
&= ~ES_UPPERCASE
;
5152 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5153 } else if (GWL_EXSTYLE
== which
) {
5154 ; /* FIXME - what is needed here */
5156 WARN ("Invalid style change %ld\n",which
);
5162 /*********************************************************************
5167 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5169 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5170 if (EDIT_EM_CanUndo(es
))
5173 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5174 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5177 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5181 /*********************************************************************
5186 static void EDIT_WM_Timer(EDITSTATE
*es
)
5188 if (es
->region_posx
< 0) {
5189 EDIT_MoveBackward(es
, TRUE
);
5190 } else if (es
->region_posx
> 0) {
5191 EDIT_MoveForward(es
, TRUE
);
5194 * FIXME: gotta do some vertical scrolling here, like
5195 * EDIT_EM_LineScroll(hwnd, 0, 1);
5199 /*********************************************************************
5204 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5208 if (!(es
->style
& ES_MULTILINE
))
5211 if (!(es
->style
& ES_AUTOVSCROLL
))
5220 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5221 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5222 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5224 EDIT_EM_Scroll(es
, action
);
5231 TRACE("SB_BOTTOM\n");
5232 dy
= es
->line_count
- 1 - es
->y_offset
;
5235 TRACE("SB_THUMBTRACK %d\n", pos
);
5236 es
->flags
|= EF_VSCROLL_TRACK
;
5237 if(es
->style
& WS_VSCROLL
)
5238 dy
= pos
- es
->y_offset
;
5241 /* Assume default scroll range 0-100 */
5244 if(pos
< 0 || pos
> 100) return 0;
5245 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5246 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5247 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5248 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5249 es
->line_count
, es
->y_offset
, pos
, dy
);
5252 case SB_THUMBPOSITION
:
5253 TRACE("SB_THUMBPOSITION %d\n", pos
);
5254 es
->flags
&= ~EF_VSCROLL_TRACK
;
5255 if(es
->style
& WS_VSCROLL
)
5256 dy
= pos
- es
->y_offset
;
5259 /* Assume default scroll range 0-100 */
5262 if(pos
< 0 || pos
> 100) return 0;
5263 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5264 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5265 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5266 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5267 es
->line_count
, es
->y_offset
, pos
, dy
);
5271 /* force scroll info update */
5272 EDIT_UpdateScrollInfo(es
);
5273 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5277 TRACE("SB_ENDSCROLL\n");
5280 * FIXME : the next two are undocumented !
5281 * Are we doing the right thing ?
5282 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5283 * although it's also a regular control message.
5285 case EM_GETTHUMB
: /* this one is used by NT notepad */
5289 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5290 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5293 /* Assume default scroll range 0-100 */
5294 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5295 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5297 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5300 case EM_LINESCROLL16
:
5301 TRACE("EM_LINESCROLL16 %d\n", pos
);
5306 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5311 EDIT_EM_LineScroll(es
, 0, dy
);
5315 /*********************************************************************
5320 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5322 if (es
->flags
& EF_UPDATE
) {
5323 es
->flags
&= ~EF_UPDATE
;
5324 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5326 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5330 /*********************************************************************
5335 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
5337 if (es
->flags
& EF_UPDATE
) {
5338 es
->flags
&= ~EF_UPDATE
;
5339 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5341 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5344 /********************************************************************
5346 * The Following code is to handle inline editing from IMEs
5349 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5352 LPWSTR lpCompStr
= NULL
;
5354 LPSTR lpCompStrAttr
= NULL
;
5357 if (!(hIMC
= ImmGetContext(hwnd
)))
5360 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5364 ImmReleaseContext(hwnd
, hIMC
);
5368 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
5371 ERR("Unable to allocate IME CompositionString\n");
5372 ImmReleaseContext(hwnd
,hIMC
);
5377 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
5378 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5380 if (CompFlag
& GCS_COMPATTR
)
5383 * We do not use the attributes yet. it would tell us what characters
5384 * are in transition and which are converted or decided upon
5386 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5390 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5393 ERR("Unable to allocate IME Attribute String\n");
5394 HeapFree(GetProcessHeap(),0,lpCompStr
);
5395 ImmReleaseContext(hwnd
,hIMC
);
5398 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5400 lpCompStrAttr
[dwBufLenAttr
] = 0;
5403 lpCompStrAttr
= NULL
;
5406 /* check for change in composition start */
5407 if (es
->selection_end
< es
->composition_start
)
5408 es
->composition_start
= es
->selection_end
;
5410 /* replace existing selection string */
5411 es
->selection_start
= es
->composition_start
;
5413 if (es
->composition_len
> 0)
5414 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5416 es
->selection_end
= es
->selection_start
;
5418 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5419 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5421 es
->selection_start
= es
->composition_start
;
5422 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5424 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5425 HeapFree(GetProcessHeap(),0,lpCompStr
);
5426 ImmReleaseContext(hwnd
,hIMC
);
5429 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5435 if ( !(hIMC
= ImmGetContext(hwnd
)))
5438 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5441 ImmReleaseContext(hwnd
, hIMC
);
5445 lpResultStr
= HeapAlloc(GetProcessHeap(),0, dwBufLen
+sizeof(WCHAR
));
5448 ERR("Unable to alloc buffer for IME string\n");
5449 ImmReleaseContext(hwnd
, hIMC
);
5453 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, dwBufLen
);
5454 lpResultStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5456 /* check for change in composition start */
5457 if (es
->selection_end
< es
->composition_start
)
5458 es
->composition_start
= es
->selection_end
;
5460 es
->selection_start
= es
->composition_start
;
5461 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5462 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5463 es
->composition_start
= es
->selection_end
;
5464 es
->composition_len
= 0;
5466 HeapFree(GetProcessHeap(),0,lpResultStr
);
5467 ImmReleaseContext(hwnd
, hIMC
);
5470 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5472 if (CompFlag
& GCS_RESULTSTR
)
5473 EDIT_GetResultStr(hwnd
,es
);
5474 if (CompFlag
& GCS_COMPSTR
)
5475 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);