4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
47 #include <wine/debug.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
50 WINE_DECLARE_DEBUG_CHANNEL(combo
);
51 WINE_DECLARE_DEBUG_CHANNEL(relay
);
53 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
54 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
55 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
56 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
59 * extra flags for EDITSTATE.flags field
61 #define EF_MODIFIED 0x0001 /* text has been modified */
62 #define EF_FOCUSED 0x0002 /* we have input focus */
63 #define EF_UPDATE 0x0004 /* notify parent of changed state */
64 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
65 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
66 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
67 wrapped line, instead of in front of the next character */
68 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
69 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
70 the text buffer if this is clear. */
73 END_0
= 0, /* line ends with terminating '\0' character */
74 END_WRAP
, /* line is wrapped */
75 END_HARD
, /* line ends with a hard return '\r\n' */
76 END_SOFT
, /* line ends with a soft return '\r\r\n' */
77 END_RICH
/* line ends with a single '\n' */
80 typedef struct tagLINEDEF
{
81 INT length
; /* bruto length of a line in bytes */
82 INT net_length
; /* netto length of a line in visible characters */
84 INT width
; /* width of the line in pixels */
85 INT index
; /* line index into the buffer */
86 struct tagLINEDEF
*next
;
91 BOOL is_unicode
; /* how the control was created */
92 LPWSTR text
; /* the actual contents of the control */
93 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
94 UINT buffer_size
; /* the size of the buffer in characters */
95 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
96 HFONT font
; /* NULL means standard system font */
97 INT x_offset
; /* scroll offset for multi lines this is in pixels
98 for single lines it's in characters */
99 INT line_height
; /* height of a screen line in pixels */
100 INT char_width
; /* average character width in pixels */
101 DWORD style
; /* sane version of wnd->dwStyle */
102 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
103 INT undo_insert_count
; /* number of characters inserted in sequence */
104 UINT undo_position
; /* character index of the insertion and deletion */
105 LPWSTR undo_text
; /* deleted text */
106 UINT undo_buffer_size
; /* size of the deleted text buffer */
107 INT selection_start
; /* == selection_end if no selection */
108 INT selection_end
; /* == current caret position */
109 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
110 INT left_margin
; /* in pixels */
111 INT right_margin
; /* in pixels */
113 INT text_width
; /* width of the widest line in pixels for multi line controls
114 and just line width for single line controls */
115 INT region_posx
; /* Position of cursor relative to region: */
116 INT region_posy
; /* -1: to left, 0: within, 1: to right */
118 EDITWORDBREAKPROC16 word_break_proc16
;
120 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
121 INT line_count
; /* number of lines */
122 INT y_offset
; /* scroll offset in number of lines */
123 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
124 BOOL bEnableState
; /* flag keeping the enable state */
125 HWND hwndSelf
; /* the our window handle */
126 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
127 Even if parent will change, EN_* messages
128 should be sent to the first parent. */
129 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
131 * only for multi line controls
133 INT lock_count
; /* amount of re-entries in the EditWndProc */
136 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
137 HLOCAL hloc32W
; /* our unicode local memory block */
139 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
142 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
147 UINT composition_len
; /* length of composition, 0 == no composition */
148 int composition_start
; /* the character position for the composition */
152 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
153 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
155 /* used for disabled or read-only edit control */
156 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
158 { /* Notify parent which has created this edit control */ \
159 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
160 SendMessageW(es->hwndParent, WM_COMMAND, \
161 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
162 (LPARAM)(es->hwndSelf)); \
165 /*********************************************************************
172 * These functions have trivial implementations
173 * We still like to call them internally
174 * "static inline" makes them more like macro's
176 static __inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
177 static __inline
void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
178 static __inline
void EDIT_WM_Clear(EDITSTATE
*es
);
179 static __inline
void EDIT_WM_Cut(EDITSTATE
*es
);
182 * Helper functions only valid for one type of control
184 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
185 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
186 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
187 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
190 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
192 * Helper functions valid for both single line _and_ multi line controls
194 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
195 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
196 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
197 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
198 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
199 static void EDIT_LockBuffer(EDITSTATE
*es
);
200 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
201 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
202 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
203 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
204 static void EDIT_MoveEndOfText(EDITSTATE
*es
, BOOL extend
);
205 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
206 static void EDIT_MoveStartOfText(EDITSTATE
*es
, BOOL extend
);
207 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
208 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
209 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
210 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
211 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
212 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
213 static void EDIT_AdjustFormatRect(EDITSTATE
*es
);
214 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
215 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
216 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
217 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
219 * EM_XXX message handlers
221 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
222 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
223 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
225 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
227 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
228 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
229 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
230 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
231 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
232 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
233 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
234 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
235 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
236 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
237 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
238 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
239 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
241 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
243 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
);
244 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, WORD left
, WORD right
, BOOL repaint
);
245 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
246 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
247 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
249 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
251 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
253 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
255 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
257 * WM_XXX message handlers
259 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
260 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
261 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
262 static void EDIT_WM_Copy(EDITSTATE
*es
);
263 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
264 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
265 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
266 static INT
EDIT_WM_GetText(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
, LPRECT 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 const struct builtin_class_descr EDIT_builtin_class
=
300 CS_DBLCLKS
| CS_PARENTDC
, /* style */
301 (WNDPROC
)EditWndProcW
, /* procW */
302 (WNDPROC
)EditWndProcA
, /* procA */
303 sizeof(EDITSTATE
*), /* extra */
304 (LPWSTR
)IDC_IBEAM
, /* cursor */
308 CS_DBLCLKS
| CS_PARENTDC
, /* style */
309 EditWndProcA
, /* procA */
310 EditWndProcW
, /* procW */
311 sizeof(EDITSTATE
*), /* extra */
312 IDC_IBEAM
, /* cursor */
318 /*********************************************************************
323 static __inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
325 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
329 /*********************************************************************
334 static __inline
void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
336 es
->undo_insert_count
= 0;
337 *es
->undo_text
= '\0';
341 /*********************************************************************
346 static __inline
void EDIT_WM_Clear(EDITSTATE
*es
)
348 static const WCHAR empty_stringW
[] = {0};
350 /* Protect read-only edit control from modification */
351 if(es
->style
& ES_READONLY
)
354 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
358 /*********************************************************************
363 static __inline
void EDIT_WM_Cut(EDITSTATE
*es
)
370 /**********************************************************************
373 * Returns the window version in case Wine emulates a later version
374 * of windows than the application expects.
376 * In a number of cases when windows runs an application that was
377 * designed for an earlier windows version, windows reverts
378 * to "old" behaviour of that earlier version.
380 * An example is a disabled edit control that needs to be painted.
381 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
382 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
383 * applications with an expected version 0f 4.0 or higher.
386 static DWORD
get_app_version(void)
388 static DWORD version
;
391 DWORD dwEmulatedVersion
;
393 DWORD dwProcVersion
= GetProcessVersion(0);
395 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
396 GetVersionExW( &info
);
397 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
398 /* FIXME: this may not be 100% correct; see discussion on the
399 * wine developer list in Nov 1999 */
400 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
405 static inline UINT
get_text_length(EDITSTATE
*es
)
407 if(es
->text_length
== (UINT
)-1)
408 es
->text_length
= strlenW(es
->text
);
409 return es
->text_length
;
412 static inline void text_buffer_changed(EDITSTATE
*es
)
414 es
->text_length
= (UINT
)-1;
417 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
422 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
423 msg
= WM_CTLCOLORSTATIC
;
425 msg
= WM_CTLCOLOREDIT
;
427 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
428 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
430 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
434 static __inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
437 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
439 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
442 /*********************************************************************
446 * The messages are in the order of the actual integer values
447 * (which can be found in include/windows.h)
448 * Wherever possible the 16 bit versions are converted to
449 * the 32 bit ones, so that we can 'fall through' to the
450 * helper functions. These are mostly 32 bit (with a few
451 * exceptions, clearly indicated by a '16' extension to their
455 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
456 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
458 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
461 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
463 if (!es
&& msg
!= WM_NCCREATE
)
464 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
466 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
476 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
481 if ((short)LOWORD(lParam
) == -1)
482 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
484 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
486 EDIT_EM_ScrollCaret(es
);
491 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
492 EDIT_EM_ScrollCaret(es
);
499 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
504 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
509 if ((es
->style
& ES_MULTILINE
) && lParam
) {
511 CONV_RECT16TO32(MapSL(lParam
), &rc
);
512 EDIT_SetRectNP(es
, &rc
);
513 EDIT_UpdateText(es
, NULL
, TRUE
);
518 if ((es
->style
& ES_MULTILINE
) && lParam
) {
519 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
520 EDIT_UpdateText(es
, NULL
, TRUE
);
526 if ((es
->style
& ES_MULTILINE
) && lParam
) {
528 CONV_RECT16TO32(MapSL(lParam
), &rc
);
529 EDIT_SetRectNP(es
, &rc
);
534 if ((es
->style
& ES_MULTILINE
) && lParam
)
535 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
542 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
546 case EM_LINESCROLL16
:
547 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
548 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
552 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
556 case EM_SCROLLCARET16
:
559 EDIT_EM_ScrollCaret(es
);
567 result
= ((es
->flags
& EF_MODIFIED
) != 0);
575 es
->flags
|= EF_MODIFIED
;
577 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
581 case EM_GETLINECOUNT16
:
583 case EM_GETLINECOUNT
:
584 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
589 if ((INT16
)wParam
== -1)
594 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
599 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
603 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
608 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
612 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
619 result
= EDIT_EM_GetThumb(es
);
622 /* these messages missing from specs */
631 FIXME("undocumented message 0x%x, please report\n", msg
);
632 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
636 case EM_LINELENGTH16
:
639 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
643 case EM_REPLACESEL16
:
644 lParam
= (LPARAM
)MapSL(lParam
);
645 unicode
= FALSE
; /* 16-bit message is always ascii */
653 textW
= (LPWSTR
)lParam
;
656 LPSTR textA
= (LPSTR
)lParam
;
657 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
658 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
659 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
662 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
666 HeapFree(GetProcessHeap(), 0, textW
);
672 lParam
= (LPARAM
)MapSL(lParam
);
673 unicode
= FALSE
; /* 16-bit message is always ascii */
677 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
683 case EM_SETLIMITTEXT
:
684 EDIT_EM_SetLimitText(es
, wParam
);
691 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
699 result
= (LRESULT
)EDIT_EM_Undo(es
);
706 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
710 case EM_LINEFROMCHAR16
:
712 case EM_LINEFROMCHAR
:
713 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
717 case EM_SETTABSTOPS16
:
718 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
722 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
726 case EM_SETPASSWORDCHAR16
:
727 unicode
= FALSE
; /* 16-bit message is always ascii */
730 case EM_SETPASSWORDCHAR
:
735 charW
= (WCHAR
)wParam
;
739 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
742 EDIT_EM_SetPasswordChar(es
, charW
);
747 case EM_EMPTYUNDOBUFFER16
:
749 case EM_EMPTYUNDOBUFFER
:
750 EDIT_EM_EmptyUndoBuffer(es
);
754 case EM_GETFIRSTVISIBLELINE16
:
755 result
= es
->y_offset
;
758 case EM_GETFIRSTVISIBLELINE
:
759 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
763 case EM_SETREADONLY16
:
767 SetWindowLongW( hwnd
, GWL_STYLE
,
768 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
769 es
->style
|= ES_READONLY
;
771 SetWindowLongW( hwnd
, GWL_STYLE
,
772 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
773 es
->style
&= ~ES_READONLY
;
779 case EM_SETWORDBREAKPROC16
:
780 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
783 case EM_SETWORDBREAKPROC
:
784 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
788 case EM_GETWORDBREAKPROC16
:
789 result
= (LRESULT
)es
->word_break_proc16
;
792 case EM_GETWORDBREAKPROC
:
793 result
= (LRESULT
)es
->word_break_proc
;
797 case EM_GETPASSWORDCHAR16
:
798 unicode
= FALSE
; /* 16-bit message is always ascii */
801 case EM_GETPASSWORDCHAR
:
804 result
= es
->password_char
;
807 WCHAR charW
= es
->password_char
;
809 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
815 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
818 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
822 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
825 case EM_GETLIMITTEXT
:
826 result
= es
->buffer_limit
;
830 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
831 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
835 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
838 /* End of the EM_ messages which were in numerical order; what order
839 * are these in? vaguely alphabetical?
843 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
847 result
= EDIT_WM_Destroy(es
);
852 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
854 if (es
->style
& ES_MULTILINE
)
856 result
|= DLGC_WANTALLKEYS
;
860 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
862 int vk
= (int)((LPMSG
)lParam
)->wParam
;
864 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
866 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
867 result
|= DLGC_WANTMESSAGE
;
878 strng
[0] = wParam
>> 8;
879 strng
[1] = wParam
& 0xff;
880 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
881 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
882 EDIT_WM_Char(es
, charW
);
895 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
898 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
900 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
901 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
904 EDIT_WM_Char(es
, charW
);
913 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
917 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
926 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
929 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
933 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
934 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
935 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
937 result
= EDIT_WM_Create(es
, nameW
);
938 HeapFree(GetProcessHeap(), 0, nameW
);
947 es
->bEnableState
= (BOOL
) wParam
;
948 EDIT_UpdateText(es
, NULL
, TRUE
);
952 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
956 result
= (LRESULT
)es
->font
;
960 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
963 case WM_GETTEXTLENGTH
:
964 if (unicode
) result
= get_text_length(es
);
965 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
966 NULL
, 0, NULL
, NULL
);
970 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
974 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
978 result
= EDIT_WM_KillFocus(es
);
981 case WM_LBUTTONDBLCLK
:
982 result
= EDIT_WM_LButtonDblClk(es
);
986 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
990 result
= EDIT_WM_LButtonUp(es
);
994 result
= EDIT_WM_MButtonDown(es
);
998 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1001 case WM_PRINTCLIENT
:
1003 EDIT_WM_Paint(es
, (HDC
)wParam
);
1011 EDIT_WM_SetFocus(es
);
1015 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
1019 /* FIXME: actually set an internal flag and behave accordingly */
1023 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
1028 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1031 case WM_STYLECHANGED
:
1032 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
1035 case WM_STYLECHANGING
:
1036 result
= 0; /* See EDIT_WM_StyleChanged */
1040 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
1048 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
1053 int gcWheelDelta
= 0;
1054 UINT pulScrollLines
= 3;
1055 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1057 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1058 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1061 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1062 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1064 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1065 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1066 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1072 /* IME messages to make the edit control IME aware */
1073 case WM_IME_SETCONTEXT
:
1076 case WM_IME_STARTCOMPOSITION
:
1078 * FIXME in IME: This message is not always sent like it should be
1080 if (es
->selection_start
!= es
->selection_end
)
1082 static const WCHAR empty_stringW
[] = {0};
1083 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1085 es
->composition_start
= es
->selection_end
;
1086 es
->composition_len
= 0;
1089 case WM_IME_COMPOSITION
:
1091 int caret_pos
= es
->selection_end
;
1092 if (es
->composition_len
== 0)
1094 if (es
->selection_start
!= es
->selection_end
)
1096 static const WCHAR empty_stringW
[] = {0};
1097 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1100 es
->composition_start
= es
->selection_end
;
1102 EDIT_ImeComposition(hwnd
,lParam
,es
);
1103 EDIT_SetCaretPos(es
, caret_pos
, es
->flags
& EF_AFTER_WRAP
);
1107 case WM_IME_ENDCOMPOSITION
:
1108 es
->composition_len
= 0;
1111 case WM_IME_COMPOSITIONFULL
:
1117 case WM_IME_CONTROL
:
1121 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1125 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1127 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1132 /*********************************************************************
1134 * EditWndProcW (USER32.@)
1136 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1138 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1141 /*********************************************************************
1143 * EditWndProc (USER32.@)
1145 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1147 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1150 /*********************************************************************
1152 * EDIT_BuildLineDefs_ML
1154 * Build linked list of text lines.
1155 * Lines can end with '\0' (last line), a character (if it is wrapped),
1156 * a soft return '\r\r\n' or a hard return '\r\n'
1159 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1163 LPWSTR current_position
, cp
;
1165 LINEDEF
*current_line
;
1166 LINEDEF
*previous_line
;
1167 LINEDEF
*start_line
;
1168 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1169 INT line_count
= es
->line_count
;
1170 INT orig_net_length
;
1173 if (istart
== iend
&& delta
== 0)
1176 dc
= GetDC(es
->hwndSelf
);
1178 old_font
= SelectObject(dc
, es
->font
);
1180 previous_line
= NULL
;
1181 current_line
= es
->first_line_def
;
1183 /* Find starting line. istart must lie inside an existing line or
1184 * at the end of buffer */
1186 if (istart
< current_line
->index
+ current_line
->length
||
1187 current_line
->ending
== END_0
)
1190 previous_line
= current_line
;
1191 current_line
= current_line
->next
;
1193 } while (current_line
);
1195 if (!current_line
) /* Error occurred start is not inside previous buffer */
1197 FIXME(" modification occurred outside buffer\n");
1198 ReleaseDC(es
->hwndSelf
, dc
);
1202 /* Remember start of modifications in order to calculate update region */
1203 nstart_line
= line_index
;
1204 nstart_index
= current_line
->index
;
1206 /* We must start to reformat from the previous line since the modifications
1207 * may have caused the line to wrap upwards. */
1208 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1211 current_line
= previous_line
;
1213 start_line
= current_line
;
1215 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1216 current_position
= es
->text
+ current_line
->index
;
1218 if (current_line
!= start_line
)
1220 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1222 /* The buffer has been expanded, create a new line and
1223 insert it into the link list */
1224 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1225 new_line
->next
= previous_line
->next
;
1226 previous_line
->next
= new_line
;
1227 current_line
= new_line
;
1230 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1232 /* The previous line merged with this line so we delete this extra entry */
1233 previous_line
->next
= current_line
->next
;
1234 HeapFree(GetProcessHeap(), 0, current_line
);
1235 current_line
= previous_line
->next
;
1239 else /* current_line->index + delta == current_position */
1241 if (current_position
- es
->text
> iend
)
1242 break; /* We reached end of line modifications */
1243 /* else recalulate this line */
1247 current_line
->index
= current_position
- es
->text
;
1248 orig_net_length
= current_line
->net_length
;
1250 /* Find end of line */
1251 cp
= current_position
;
1253 if (*cp
== '\n') break;
1254 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1259 /* Mark type of line termination */
1261 current_line
->ending
= END_0
;
1262 current_line
->net_length
= strlenW(current_position
);
1263 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1264 current_line
->ending
= END_SOFT
;
1265 current_line
->net_length
= cp
- current_position
- 1;
1266 } else if (*cp
== '\n') {
1267 current_line
->ending
= END_RICH
;
1268 current_line
->net_length
= cp
- current_position
;
1270 current_line
->ending
= END_HARD
;
1271 current_line
->net_length
= cp
- current_position
;
1274 /* Calculate line width */
1275 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1276 current_position
, current_line
->net_length
,
1277 es
->tabs_count
, es
->tabs
));
1279 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1280 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1281 if (current_line
->width
> fw
) {
1286 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1287 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1288 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1289 current_position
, next
, es
->tabs_count
, es
->tabs
));
1290 } while (current_line
->width
<= fw
);
1291 if (!prev
) { /* Didn't find a line break so force a break */
1296 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1297 current_position
, next
, es
->tabs_count
, es
->tabs
));
1298 } while (current_line
->width
<= fw
);
1303 /* If the first line we are calculating, wrapped before istart, we must
1304 * adjust istart in order for this to be reflected in the update region. */
1305 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1306 istart
= current_line
->index
+ prev
;
1307 /* else if we are updating the previous line before the first line we
1308 * are re-calculating and it expanded */
1309 else if (current_line
== start_line
&&
1310 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1312 /* Line expanded due to an upwards line wrap so we must partially include
1313 * previous line in update region */
1314 nstart_line
= line_index
;
1315 nstart_index
= current_line
->index
;
1316 istart
= current_line
->index
+ orig_net_length
;
1319 current_line
->net_length
= prev
;
1320 current_line
->ending
= END_WRAP
;
1321 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1322 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1324 else if (orig_net_length
< current_line
->net_length
&&
1325 current_line
== start_line
&&
1326 current_line
->index
!= nstart_index
) {
1327 /* The previous line expanded but it's still not as wide as the client rect */
1328 /* The expansion is due to an upwards line wrap so we must partially include
1329 it in the update region */
1330 nstart_line
= line_index
;
1331 nstart_index
= current_line
->index
;
1332 istart
= current_line
->index
+ orig_net_length
;
1337 /* Adjust length to include line termination */
1338 switch (current_line
->ending
) {
1340 current_line
->length
= current_line
->net_length
+ 3;
1343 current_line
->length
= current_line
->net_length
+ 1;
1346 current_line
->length
= current_line
->net_length
+ 2;
1350 current_line
->length
= current_line
->net_length
;
1353 es
->text_width
= max(es
->text_width
, current_line
->width
);
1354 current_position
+= current_line
->length
;
1355 previous_line
= current_line
;
1356 current_line
= current_line
->next
;
1358 } while (previous_line
->ending
!= END_0
);
1360 /* Finish adjusting line indexes by delta or remove hanging lines */
1361 if (previous_line
->ending
== END_0
)
1363 LINEDEF
*pnext
= NULL
;
1365 previous_line
->next
= NULL
;
1366 while (current_line
)
1368 pnext
= current_line
->next
;
1369 HeapFree(GetProcessHeap(), 0, current_line
);
1370 current_line
= pnext
;
1374 else if (delta
!= 0)
1376 while (current_line
)
1378 current_line
->index
+= delta
;
1379 current_line
= current_line
->next
;
1383 /* Calculate rest of modification rectangle */
1388 * We calculate two rectangles. One for the first line which may have
1389 * an indent with respect to the format rect. The other is a format-width
1390 * rectangle that spans the rest of the lines that changed or moved.
1392 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1393 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1394 rc
.bottom
= rc
.top
+ es
->line_height
;
1395 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1396 rc
.left
= es
->format_rect
.left
;
1398 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1399 es
->text
+ nstart_index
, istart
- nstart_index
,
1400 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1401 rc
.right
= es
->format_rect
.right
;
1402 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1405 rc
.left
= es
->format_rect
.left
;
1406 rc
.right
= es
->format_rect
.right
;
1408 * If lines were added or removed we must re-paint the remainder of the
1409 * lines since the remaining lines were either shifted up or down.
1411 if (line_count
< es
->line_count
) /* We added lines */
1412 rc
.bottom
= es
->line_count
* es
->line_height
;
1413 else if (line_count
> es
->line_count
) /* We removed lines */
1414 rc
.bottom
= line_count
* es
->line_height
;
1416 rc
.bottom
= line_index
* es
->line_height
;
1417 rc
.bottom
+= es
->format_rect
.top
;
1418 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1419 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1420 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1421 DeleteObject(tmphrgn
);
1425 SelectObject(dc
, old_font
);
1427 ReleaseDC(es
->hwndSelf
, dc
);
1430 /*********************************************************************
1432 * EDIT_CalcLineWidth_SL
1435 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1442 text
= EDIT_GetPasswordPointer_SL(es
);
1444 dc
= GetDC(es
->hwndSelf
);
1446 old_font
= SelectObject(dc
, es
->font
);
1448 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1451 SelectObject(dc
, old_font
);
1452 ReleaseDC(es
->hwndSelf
, dc
);
1454 if (es
->style
& ES_PASSWORD
)
1455 HeapFree(GetProcessHeap(), 0, text
);
1457 es
->text_width
= size
.cx
;
1460 /*********************************************************************
1462 * EDIT_CallWordBreakProc
1464 * Call appropriate WordBreakProc (internal or external).
1466 * Note: The "start" argument should always be an index referring
1467 * to es->text. The actual wordbreak proc might be
1468 * 16 bit, so we can't always pass any 32 bit LPSTR.
1469 * Hence we assume that es->text is the buffer that holds
1470 * the string under examination (we can decide this for ourselves).
1473 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1478 if (es
->word_break_proc16
) {
1485 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1486 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1487 segptr
= K32WOWGlobalLock16(hglob16
);
1488 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1489 args
[4] = SELECTOROF(segptr
);
1490 args
[3] = OFFSETOF(segptr
);
1494 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1495 ret
= LOWORD(result
);
1496 GlobalUnlock16(hglob16
);
1497 GlobalFree16(hglob16
);
1499 else if (es
->word_break_proc
)
1501 if (es
->word_break_proc
)
1506 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1508 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1509 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1510 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1514 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1518 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1519 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1520 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1521 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1522 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1523 ret
= wbpA(textA
, index
, countA
, action
);
1524 HeapFree(GetProcessHeap(), 0, textA
);
1528 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1534 /*********************************************************************
1538 * Beware: This is not the function called on EM_CHARFROMPOS
1539 * The position _can_ be outside the formatting / client
1541 * The return value is only the character index
1544 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1549 INT x_high
= 0, x_low
= 0;
1551 if (es
->style
& ES_MULTILINE
) {
1552 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1554 LINEDEF
*line_def
= es
->first_line_def
;
1556 while ((line
> 0) && line_def
->next
) {
1557 line_index
+= line_def
->length
;
1558 line_def
= line_def
->next
;
1561 x
+= es
->x_offset
- es
->format_rect
.left
;
1562 if (es
->style
& ES_RIGHT
)
1563 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1564 else if (es
->style
& ES_CENTER
)
1565 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1566 if (x
>= line_def
->width
) {
1568 *after_wrap
= (line_def
->ending
== END_WRAP
);
1569 return line_index
+ line_def
->net_length
;
1573 *after_wrap
= FALSE
;
1576 dc
= GetDC(es
->hwndSelf
);
1578 old_font
= SelectObject(dc
, es
->font
);
1580 high
= line_index
+ line_def
->net_length
+ 1;
1581 while (low
< high
- 1)
1583 INT mid
= (low
+ high
) / 2;
1584 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1593 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1599 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1600 (line_def
->ending
== END_WRAP
));
1605 *after_wrap
= FALSE
;
1606 x
-= es
->format_rect
.left
;
1608 return es
->x_offset
;
1612 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1613 if (es
->style
& ES_RIGHT
)
1615 else if (es
->style
& ES_CENTER
)
1619 text
= EDIT_GetPasswordPointer_SL(es
);
1620 dc
= GetDC(es
->hwndSelf
);
1622 old_font
= SelectObject(dc
, es
->font
);
1626 INT high
= es
->x_offset
;
1627 while (low
< high
- 1)
1629 INT mid
= (low
+ high
) / 2;
1630 GetTextExtentPoint32W( dc
, text
+ mid
,
1631 es
->x_offset
- mid
, &size
);
1640 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1647 INT low
= es
->x_offset
;
1648 INT high
= get_text_length(es
) + 1;
1649 while (low
< high
- 1)
1651 INT mid
= (low
+ high
) / 2;
1652 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1653 mid
- es
->x_offset
, &size
);
1662 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1667 if (es
->style
& ES_PASSWORD
)
1668 HeapFree(GetProcessHeap(), 0, text
);
1671 SelectObject(dc
, old_font
);
1672 ReleaseDC(es
->hwndSelf
, dc
);
1677 /*********************************************************************
1681 * adjusts the point to be within the formatting rectangle
1682 * (so CharFromPos returns the nearest _visible_ character)
1685 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1687 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1688 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1692 /*********************************************************************
1696 * Calculates the bounding rectangle for a line from a starting
1697 * column to an ending column.
1700 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1702 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1704 if (es
->style
& ES_MULTILINE
)
1705 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1707 rc
->top
= es
->format_rect
.top
;
1708 rc
->bottom
= rc
->top
+ es
->line_height
;
1709 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1710 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1714 /*********************************************************************
1716 * EDIT_GetPasswordPointer_SL
1718 * note: caller should free the (optionally) allocated buffer
1721 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1723 if (es
->style
& ES_PASSWORD
) {
1724 INT len
= get_text_length(es
);
1725 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1727 while(len
) text
[--len
] = es
->password_char
;
1734 /*********************************************************************
1738 * This acts as a LOCAL_Lock(), but it locks only once. This way
1739 * you can call it whenever you like, without unlocking.
1741 * Initially the edit control allocates a HLOCAL32 buffer
1742 * (32 bit linear memory handler). However, 16 bit application
1743 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1744 * handler). From that moment on we have to keep using this 16 bit memory
1745 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1746 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1750 static void EDIT_LockBuffer(EDITSTATE
*es
)
1753 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1759 BOOL _16bit
= FALSE
;
1766 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1767 textA
= LocalLock(es
->hloc32A
);
1768 countA
= strlen(textA
) + 1;
1773 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1774 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1775 countA
= strlen(textA
) + 1;
1781 ERR("no buffer ... please report\n");
1788 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1789 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1790 if(countW_new
> es
->buffer_size
+ 1)
1792 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1793 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1794 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1797 es
->hloc32W
= hloc32W_new
;
1798 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1799 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1802 WARN("FAILED! Will synchronize partially\n");
1806 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1807 es
->text
= LocalLock(es
->hloc32W
);
1811 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1814 LOCAL_Unlock(hInstance
, es
->hloc16
);
1817 LocalUnlock(es
->hloc32A
);
1820 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1825 /*********************************************************************
1827 * EDIT_SL_InvalidateText
1829 * Called from EDIT_InvalidateText().
1830 * Does the job for single-line controls only.
1833 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1838 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1839 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1840 EDIT_UpdateText(es
, &rc
, TRUE
);
1844 /*********************************************************************
1846 * EDIT_ML_InvalidateText
1848 * Called from EDIT_InvalidateText().
1849 * Does the job for multi-line controls only.
1852 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1854 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1855 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1856 INT el
= EDIT_EM_LineFromChar(es
, end
);
1865 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1868 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1869 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1870 if (sl
< es
->y_offset
) {
1874 if (el
> es
->y_offset
+ vlc
) {
1875 el
= es
->y_offset
+ vlc
;
1876 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1878 GetClientRect(es
->hwndSelf
, &rc1
);
1879 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1881 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1882 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1883 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1885 EDIT_GetLineRect(es
, sl
, sc
,
1886 EDIT_EM_LineLength(es
,
1887 EDIT_EM_LineIndex(es
, sl
)),
1889 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1890 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1891 for (l
= sl
+ 1 ; l
< el
; l
++) {
1892 EDIT_GetLineRect(es
, l
, 0,
1893 EDIT_EM_LineLength(es
,
1894 EDIT_EM_LineIndex(es
, l
)),
1896 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1897 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1899 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1900 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1901 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1906 /*********************************************************************
1908 * EDIT_InvalidateText
1910 * Invalidate the text from offset start up to, but not including,
1911 * offset end. Useful for (re)painting the selection.
1912 * Regions outside the linewidth are not invalidated.
1913 * end == -1 means end == TextLength.
1914 * start and end need not be ordered.
1917 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1923 end
= get_text_length(es
);
1931 if (es
->style
& ES_MULTILINE
)
1932 EDIT_ML_InvalidateText(es
, start
, end
);
1934 EDIT_SL_InvalidateText(es
, start
, end
);
1938 /*********************************************************************
1942 * Try to fit size + 1 characters in the buffer.
1944 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1948 if (size
<= es
->buffer_size
)
1951 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1953 /* Force edit to unlock it's buffer. es->text now NULL */
1954 EDIT_UnlockBuffer(es
, TRUE
);
1957 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1958 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1959 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1960 es
->hloc32W
= hNew32W
;
1961 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1965 EDIT_LockBuffer(es
);
1967 if (es
->buffer_size
< size
) {
1968 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1969 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1972 TRACE("We now have %d+1\n", es
->buffer_size
);
1978 /*********************************************************************
1982 * Try to fit size + 1 bytes in the undo buffer.
1985 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1989 if (size
<= es
->undo_buffer_size
)
1992 TRACE("trying to ReAlloc to %d+1\n", size
);
1994 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1995 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1996 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
2001 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
2007 /*********************************************************************
2012 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
2014 INT e
= es
->selection_end
;
2018 if ((es
->style
& ES_MULTILINE
) && e
&&
2019 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
2021 if (e
&& (es
->text
[e
- 1] == '\r'))
2025 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2026 EDIT_EM_ScrollCaret(es
);
2030 /*********************************************************************
2034 * Only for multi line controls
2035 * Move the caret one line down, on a column with the nearest
2036 * x coordinate on the screen (might be a different column).
2039 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
2041 INT s
= es
->selection_start
;
2042 INT e
= es
->selection_end
;
2043 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2044 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2045 INT x
= (short)LOWORD(pos
);
2046 INT y
= (short)HIWORD(pos
);
2048 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
2051 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2052 EDIT_EM_ScrollCaret(es
);
2056 /*********************************************************************
2061 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
2063 BOOL after_wrap
= FALSE
;
2066 /* Pass a high value in x to make sure of receiving the end of the line */
2067 if (es
->style
& ES_MULTILINE
)
2068 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2069 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2071 e
= get_text_length(es
);
2072 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2073 EDIT_EM_ScrollCaret(es
);
2077 /*********************************************************************
2079 * EDIT_MoveEndOfText
2081 * Handler for Ctrl+End. Move to end of text. Only for multiline.
2084 static void EDIT_MoveEndOfText(EDITSTATE
*es
, BOOL extend
)
2086 BOOL after_wrap
= FALSE
;
2089 assert(es
->style
& ES_MULTILINE
);
2091 /* Just give it impossible high x&y to get the index of the last char */
2092 e
= EDIT_CharFromPos(es
, 0x3fffffff, 0x3fffffff, &after_wrap
);
2094 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2095 EDIT_EM_ScrollCaret(es
);
2099 /*********************************************************************
2104 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2106 INT e
= es
->selection_end
;
2110 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2111 if (es
->text
[e
] == '\n')
2113 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2117 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2118 EDIT_EM_ScrollCaret(es
);
2122 /*********************************************************************
2124 * EDIT_MoveStartOfText
2126 * Handler for Ctr+Home. Move to start of text. Only for multiline.
2129 static void EDIT_MoveStartOfText(EDITSTATE
*es
, BOOL extend
)
2131 BOOL after_wrap
= FALSE
;
2133 assert(es
->style
& ES_MULTILINE
);
2135 /* use CharFromPos instead of just plain zero, to get the wrap_flag */
2136 EDIT_CharFromPos(es
, 0, 0, &after_wrap
);
2139 EDIT_EM_SetSel(es
, 0, extend
? es
->selection_end
: 0, FALSE
);
2140 EDIT_EM_ScrollCaret(es
);
2144 /*********************************************************************
2148 * Home key: move to beginning of line.
2151 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2155 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2156 if (es
->style
& ES_MULTILINE
)
2157 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2158 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2161 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2162 EDIT_EM_ScrollCaret(es
);
2166 /*********************************************************************
2168 * EDIT_MovePageDown_ML
2170 * Only for multi line controls
2171 * Move the caret one page down, on a column with the nearest
2172 * x coordinate on the screen (might be a different column).
2175 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2177 INT s
= es
->selection_start
;
2178 INT e
= es
->selection_end
;
2179 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2180 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2181 INT x
= (short)LOWORD(pos
);
2182 INT y
= (short)HIWORD(pos
);
2184 e
= EDIT_CharFromPos(es
, x
,
2185 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2189 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2190 EDIT_EM_ScrollCaret(es
);
2194 /*********************************************************************
2196 * EDIT_MovePageUp_ML
2198 * Only for multi line controls
2199 * Move the caret one page up, on a column with the nearest
2200 * x coordinate on the screen (might be a different column).
2203 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2205 INT s
= es
->selection_start
;
2206 INT e
= es
->selection_end
;
2207 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2208 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2209 INT x
= (short)LOWORD(pos
);
2210 INT y
= (short)HIWORD(pos
);
2212 e
= EDIT_CharFromPos(es
, x
,
2213 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2217 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2218 EDIT_EM_ScrollCaret(es
);
2222 /*********************************************************************
2226 * Only for multi line controls
2227 * Move the caret one line up, on a column with the nearest
2228 * x coordinate on the screen (might be a different column).
2231 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2233 INT s
= es
->selection_start
;
2234 INT e
= es
->selection_end
;
2235 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2236 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2237 INT x
= (short)LOWORD(pos
);
2238 INT y
= (short)HIWORD(pos
);
2240 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2243 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2244 EDIT_EM_ScrollCaret(es
);
2248 /*********************************************************************
2250 * EDIT_MoveWordBackward
2253 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2255 INT s
= es
->selection_start
;
2256 INT e
= es
->selection_end
;
2261 l
= EDIT_EM_LineFromChar(es
, e
);
2262 ll
= EDIT_EM_LineLength(es
, e
);
2263 li
= EDIT_EM_LineIndex(es
, l
);
2266 li
= EDIT_EM_LineIndex(es
, l
- 1);
2267 e
= li
+ EDIT_EM_LineLength(es
, li
);
2270 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2271 li
, e
- li
, ll
, WB_LEFT
);
2275 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2276 EDIT_EM_ScrollCaret(es
);
2280 /*********************************************************************
2282 * EDIT_MoveWordForward
2285 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2287 INT s
= es
->selection_start
;
2288 INT e
= es
->selection_end
;
2293 l
= EDIT_EM_LineFromChar(es
, e
);
2294 ll
= EDIT_EM_LineLength(es
, e
);
2295 li
= EDIT_EM_LineIndex(es
, l
);
2297 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2298 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2300 e
= li
+ EDIT_CallWordBreakProc(es
,
2301 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2305 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2306 EDIT_EM_ScrollCaret(es
);
2310 /*********************************************************************
2315 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2317 INT s
= es
->selection_start
;
2318 INT e
= es
->selection_end
;
2325 if (es
->style
& ES_MULTILINE
) {
2326 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2327 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2332 TRACE("line=%d\n", line
);
2334 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2335 x
= (short)LOWORD(pos
);
2336 y
= (short)HIWORD(pos
);
2337 li
= EDIT_EM_LineIndex(es
, line
);
2338 ll
= EDIT_EM_LineLength(es
, li
);
2339 s
= min(es
->selection_start
, es
->selection_end
);
2340 e
= max(es
->selection_start
, es
->selection_end
);
2341 s
= min(li
+ ll
, max(li
, s
));
2342 e
= min(li
+ ll
, max(li
, e
));
2343 if (rev
&& (s
!= e
) &&
2344 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2345 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2346 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2347 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2349 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2353 /*********************************************************************
2358 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2362 LOGFONTW underline_font
;
2363 HFONT hUnderline
= 0;
2372 BkMode
= GetBkMode(dc
);
2373 BkColor
= GetBkColor(dc
);
2374 TextColor
= GetTextColor(dc
);
2376 if (es
->composition_len
== 0)
2378 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2379 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2380 SetBkMode( dc
, OPAQUE
);
2384 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2385 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2386 underline_font
.lfUnderline
= TRUE
;
2387 hUnderline
= CreateFontIndirectW(&underline_font
);
2388 old_font
= SelectObject(dc
,hUnderline
);
2391 li
= EDIT_EM_LineIndex(es
, line
);
2392 if (es
->style
& ES_MULTILINE
) {
2393 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2394 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2396 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2397 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2398 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2400 if (es
->style
& ES_PASSWORD
)
2401 HeapFree(GetProcessHeap(), 0, text
);
2404 if (es
->composition_len
== 0)
2406 SetBkColor(dc
, BkColor
);
2407 SetTextColor(dc
, TextColor
);
2408 SetBkMode( dc
, BkMode
);
2413 SelectObject(dc
,old_font
);
2415 DeleteObject(hUnderline
);
2422 /*********************************************************************
2427 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2430 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2431 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2432 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2436 /*********************************************************************
2438 * EDIT_AdjustFormatRect
2440 * Adjusts the format rectangle for the current font and the
2441 * current client rectangle.
2444 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2448 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2449 if (es
->style
& ES_MULTILINE
)
2451 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2453 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2454 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2456 /* correct es->x_offset */
2457 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2458 max_x_offset
= es
->text_width
- fw
;
2459 if(max_x_offset
< 0) max_x_offset
= 0;
2460 if(es
->x_offset
> max_x_offset
)
2461 es
->x_offset
= max_x_offset
;
2463 /* correct es->y_offset */
2464 max_y_offset
= es
->line_count
- vlc
;
2465 if(max_y_offset
< 0) max_y_offset
= 0;
2466 if(es
->y_offset
> max_y_offset
)
2467 es
->y_offset
= max_y_offset
;
2469 /* force scroll info update */
2470 EDIT_UpdateScrollInfo(es
);
2473 /* Windows doesn't care to fix text placement for SL controls */
2474 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2476 /* Always stay within the client area */
2477 GetClientRect(es
->hwndSelf
, &ClientRect
);
2478 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2480 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2481 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2483 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2487 /*********************************************************************
2491 * note: this is not (exactly) the handler called on EM_SETRECTNP
2492 * it is also used to set the rect of a single line control
2495 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2499 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2501 CopyRect(&es
->format_rect
, rc
);
2503 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2504 es
->format_rect
.left
++;
2505 es
->format_rect
.right
--;
2507 if (es
->format_rect
.bottom
- es
->format_rect
.top
2508 >= es
->line_height
+ 2)
2510 es
->format_rect
.top
++;
2511 es
->format_rect
.bottom
--;
2514 else if (es
->style
& WS_BORDER
) {
2515 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2516 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2517 es
->format_rect
.left
+= bw
;
2518 es
->format_rect
.right
-= bw
;
2519 if (es
->format_rect
.bottom
- es
->format_rect
.top
2520 >= es
->line_height
+ 2 * bh
)
2522 es
->format_rect
.top
+= bh
;
2523 es
->format_rect
.bottom
-= bh
;
2527 es
->format_rect
.left
+= es
->left_margin
;
2528 es
->format_rect
.right
-= es
->right_margin
;
2529 EDIT_AdjustFormatRect(es
);
2533 /*********************************************************************
2538 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2541 /* Edit window might be already destroyed */
2542 if(!IsWindow(es
->hwndSelf
))
2544 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2548 if (!es
->lock_count
) {
2549 ERR("lock_count == 0 ... please report\n");
2553 ERR("es->text == 0 ... please report\n");
2557 if (force
|| (es
->lock_count
== 1)) {
2561 UINT countW
= get_text_length(es
) + 1;
2563 STACK16FRAME
* stack16
= NULL
;
2569 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2570 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2571 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2572 countA
= LocalSize(es
->hloc32A
);
2573 if(countA_new
> countA
)
2576 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2577 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2578 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2581 es
->hloc32A
= hloc32A_new
;
2582 countA
= LocalSize(hloc32A_new
);
2583 TRACE("Real new size %d bytes\n", countA
);
2586 WARN("FAILED! Will synchronize partially\n");
2588 textA
= LocalLock(es
->hloc32A
);
2593 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2594 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2595 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2596 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2597 if(countA_new
> countA
)
2599 HLOCAL16 hloc16_new
;
2600 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2601 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2602 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2605 es
->hloc16
= hloc16_new
;
2606 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2607 TRACE("Real new size %d bytes\n", countA
);
2610 WARN("FAILED! Will synchronize partially\n");
2612 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2619 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2622 LOCAL_Unlock(hInstance
, es
->hloc16
);
2625 LocalUnlock(es
->hloc32A
);
2628 LocalUnlock(es
->hloc32W
);
2632 ERR("no buffer ... please report\n");
2640 /*********************************************************************
2642 * EDIT_UpdateScrollInfo
2645 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2647 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2650 si
.cbSize
= sizeof(SCROLLINFO
);
2651 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2653 si
.nMax
= es
->line_count
- 1;
2654 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2655 si
.nPos
= es
->y_offset
;
2656 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2657 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2658 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2661 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2664 si
.cbSize
= sizeof(SCROLLINFO
);
2665 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2667 si
.nMax
= es
->text_width
- 1;
2668 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2669 si
.nPos
= es
->x_offset
;
2670 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2671 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2672 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2676 /*********************************************************************
2678 * EDIT_WordBreakProc
2680 * Find the beginning of words.
2681 * Note: unlike the specs for a WordBreakProc, this function only
2682 * allows to be called without linebreaks between s[0] up to
2683 * s[count - 1]. Remember it is only called
2684 * internally, so we can decide this for ourselves.
2687 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2691 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2701 if (s
[index
] == ' ') {
2702 while (index
&& (s
[index
] == ' '))
2705 while (index
&& (s
[index
] != ' '))
2707 if (s
[index
] == ' ')
2711 while (index
&& (s
[index
] != ' '))
2713 if (s
[index
] == ' ')
2723 if (s
[index
] == ' ')
2724 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2726 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2728 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2732 case WB_ISDELIMITER
:
2733 ret
= (s
[index
] == ' ');
2736 ERR("unknown action code, please report !\n");
2743 /*********************************************************************
2747 * returns line number (not index) in high-order word of result.
2748 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2749 * to Richedit, not to the edit control. Original documentation is valid.
2750 * FIXME: do the specs mean to return -1 if outside client area or
2751 * if outside formatting rectangle ???
2754 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2762 GetClientRect(es
->hwndSelf
, &rc
);
2763 if (!PtInRect(&rc
, pt
))
2766 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2767 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2771 /*********************************************************************
2775 * Enable or disable soft breaks.
2777 * This means: insert or remove the soft linebreak character (\r\r\n).
2778 * Take care to check if the text still fits the buffer after insertion.
2779 * If not, notify with EN_ERRSPACE.
2782 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2784 es
->flags
&= ~EF_USE_SOFTBRK
;
2786 es
->flags
|= EF_USE_SOFTBRK
;
2787 FIXME("soft break enabled, not implemented\n");
2793 /*********************************************************************
2797 * Hopefully this won't fire back at us.
2798 * We always start with a fixed buffer in the local heap.
2799 * Despite of the documentation says that the local heap is used
2800 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2801 * buffer on the local heap.
2804 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2808 if (!(es
->style
& ES_MULTILINE
))
2812 hLocal
= es
->hloc32W
;
2818 UINT countA
, alloc_size
;
2819 TRACE("Allocating 32-bit ANSI alias buffer\n");
2820 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2821 alloc_size
= ROUND_TO_GROW(countA
);
2822 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2824 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2827 textA
= LocalLock(es
->hloc32A
);
2828 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2829 LocalUnlock(es
->hloc32A
);
2831 hLocal
= es
->hloc32A
;
2834 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2840 /*********************************************************************
2844 * Hopefully this won't fire back at us.
2845 * We always start with a buffer in 32 bit linear memory.
2846 * However, with this message a 16 bit application requests
2847 * a handle of 16 bit local heap memory, where it expects to find
2849 * It's a pitty that from this moment on we have to use this
2850 * local heap, because applications may rely on the handle
2853 * In this function we'll try to switch to local heap.
2855 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2857 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2859 UINT countA
, alloc_size
;
2861 if (!(es
->style
& ES_MULTILINE
))
2867 if (!LOCAL_HeapSize(hInstance
)) {
2868 if (!LocalInit16(hInstance
, 0,
2869 GlobalSize16(hInstance
))) {
2870 ERR("could not initialize local heap\n");
2873 TRACE("local heap initialized\n");
2876 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2877 alloc_size
= ROUND_TO_GROW(countA
);
2879 TRACE("Allocating 16-bit ANSI alias buffer\n");
2880 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2881 ERR("could not allocate new 16 bit buffer\n");
2885 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2886 ERR("could not lock new 16 bit buffer\n");
2887 LOCAL_Free(hInstance
, es
->hloc16
);
2892 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2893 LOCAL_Unlock(hInstance
, es
->hloc16
);
2895 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2901 /*********************************************************************
2906 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2909 INT line_len
, dst_len
;
2912 if (es
->style
& ES_MULTILINE
) {
2913 if (line
>= es
->line_count
)
2917 i
= EDIT_EM_LineIndex(es
, line
);
2919 line_len
= EDIT_EM_LineLength(es
, i
);
2920 dst_len
= *(WORD
*)dst
;
2923 if(dst_len
<= line_len
)
2925 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2928 else /* Append 0 if enough space */
2930 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2937 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2938 if(!ret
&& line_len
) /* Insufficient buffer size */
2940 if(ret
< dst_len
) /* Append 0 if enough space */
2941 ((LPSTR
)dst
)[ret
] = 0;
2947 /*********************************************************************
2952 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2954 UINT s
= es
->selection_start
;
2955 UINT e
= es
->selection_end
;
2962 return MAKELONG(s
, e
);
2966 /*********************************************************************
2970 * FIXME: is this right ? (or should it be only VSCROLL)
2971 * (and maybe only for edit controls that really have their
2972 * own scrollbars) (and maybe only for multiline controls ?)
2973 * All in all: very poorly documented
2976 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2979 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
2980 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
2982 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2983 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2988 /*********************************************************************
2993 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2998 if (!(es
->style
& ES_MULTILINE
))
3000 if (index
> (INT
)get_text_length(es
))
3001 return es
->line_count
- 1;
3003 index
= min(es
->selection_start
, es
->selection_end
);
3006 line_def
= es
->first_line_def
;
3007 index
-= line_def
->length
;
3008 while ((index
>= 0) && line_def
->next
) {
3010 line_def
= line_def
->next
;
3011 index
-= line_def
->length
;
3017 /*********************************************************************
3022 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
3027 if (!(es
->style
& ES_MULTILINE
))
3029 if (line
>= es
->line_count
)
3033 line_def
= es
->first_line_def
;
3035 INT index
= es
->selection_end
- line_def
->length
;
3036 while ((index
>= 0) && line_def
->next
) {
3037 line_index
+= line_def
->length
;
3038 line_def
= line_def
->next
;
3039 index
-= line_def
->length
;
3043 line_index
+= line_def
->length
;
3044 line_def
= line_def
->next
;
3052 /*********************************************************************
3057 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
3061 if (!(es
->style
& ES_MULTILINE
))
3062 return get_text_length(es
);
3065 /* get the number of remaining non-selected chars of selected lines */
3066 INT32 l
; /* line number */
3067 INT32 li
; /* index of first char in line */
3069 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
3070 /* # chars before start of selection area */
3071 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
3072 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3073 /* # chars after end of selection */
3074 li
= EDIT_EM_LineIndex(es
, l
);
3075 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
3078 line_def
= es
->first_line_def
;
3079 index
-= line_def
->length
;
3080 while ((index
>= 0) && line_def
->next
) {
3081 line_def
= line_def
->next
;
3082 index
-= line_def
->length
;
3084 return line_def
->net_length
;
3088 /*********************************************************************
3092 * NOTE: dx is in average character widths, dy - in lines;
3095 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
3097 if (!(es
->style
& ES_MULTILINE
))
3100 dx
*= es
->char_width
;
3101 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3104 /*********************************************************************
3106 * EDIT_EM_LineScroll_internal
3108 * Version of EDIT_EM_LineScroll for internal use.
3109 * It doesn't refuse if ES_MULTILINE is set and assumes that
3110 * dx is in pixels, dy - in lines.
3113 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3116 INT x_offset_in_pixels
;
3117 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3120 if (es
->style
& ES_MULTILINE
)
3122 x_offset_in_pixels
= es
->x_offset
;
3127 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3130 if (-dx
> x_offset_in_pixels
)
3131 dx
= -x_offset_in_pixels
;
3132 if (dx
> es
->text_width
- x_offset_in_pixels
)
3133 dx
= es
->text_width
- x_offset_in_pixels
;
3134 nyoff
= max(0, es
->y_offset
+ dy
);
3135 if (nyoff
>= es
->line_count
- lines_per_page
)
3136 nyoff
= max(0, es
->line_count
- lines_per_page
);
3137 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3142 es
->y_offset
= nyoff
;
3143 if(es
->style
& ES_MULTILINE
)
3146 es
->x_offset
+= dx
/ es
->char_width
;
3148 GetClientRect(es
->hwndSelf
, &rc1
);
3149 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3150 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3151 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3152 /* force scroll info update */
3153 EDIT_UpdateScrollInfo(es
);
3155 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3156 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3157 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3158 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3163 /*********************************************************************
3168 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3170 INT len
= get_text_length(es
);
3183 index
= min(index
, len
);
3184 dc
= GetDC(es
->hwndSelf
);
3186 old_font
= SelectObject(dc
, es
->font
);
3187 if (es
->style
& ES_MULTILINE
) {
3188 l
= EDIT_EM_LineFromChar(es
, index
);
3189 y
= (l
- es
->y_offset
) * es
->line_height
;
3190 li
= EDIT_EM_LineIndex(es
, l
);
3191 if (after_wrap
&& (li
== index
) && l
) {
3193 line_def
= es
->first_line_def
;
3195 line_def
= line_def
->next
;
3198 if (line_def
->ending
== END_WRAP
) {
3200 y
-= es
->line_height
;
3201 li
= EDIT_EM_LineIndex(es
, l
);
3205 line_def
= es
->first_line_def
;
3206 while (line_def
->index
!= li
)
3207 line_def
= line_def
->next
;
3209 ll
= line_def
->net_length
;
3210 lw
= line_def
->width
;
3212 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3213 if (es
->style
& ES_RIGHT
)
3215 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3216 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3219 else if (es
->style
& ES_CENTER
)
3221 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3222 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3227 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3228 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3231 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3232 if (index
< es
->x_offset
) {
3233 GetTextExtentPoint32W(dc
, text
+ index
,
3234 es
->x_offset
- index
, &size
);
3237 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3238 index
- es
->x_offset
, &size
);
3241 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3243 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3244 if (w
> es
->text_width
)
3246 if (es
->style
& ES_RIGHT
)
3247 x
+= w
- es
->text_width
;
3248 else if (es
->style
& ES_CENTER
)
3249 x
+= (w
- es
->text_width
) / 2;
3254 if (es
->style
& ES_PASSWORD
)
3255 HeapFree(GetProcessHeap(), 0, text
);
3257 x
+= es
->format_rect
.left
;
3258 y
+= es
->format_rect
.top
;
3260 SelectObject(dc
, old_font
);
3261 ReleaseDC(es
->hwndSelf
, dc
);
3262 return MAKELONG((INT16
)x
, (INT16
)y
);
3266 /*********************************************************************
3270 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3273 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3275 UINT strl
= strlenW(lpsz_replace
);
3276 UINT tl
= get_text_length(es
);
3287 TRACE("%s, can_undo %d, send_update %d\n",
3288 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3290 s
= es
->selection_start
;
3291 e
= es
->selection_end
;
3293 if ((s
== e
) && !strl
)
3298 size
= tl
- (e
- s
) + strl
;
3302 /* Issue the EN_MAXTEXT notification and continue with replacing text
3303 * such that buffer limit is honored. */
3304 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
3305 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3306 /* Buffer limit can be smaller than the actual length of text in combobox */
3307 if (es
->buffer_limit
< (tl
- (e
-s
)))
3310 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3313 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3317 /* there is something to be deleted */
3318 TRACE("deleting stuff.\n");
3320 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3322 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3323 buf
[bufl
] = 0; /* ensure 0 termination */
3325 strcpyW(es
->text
+ s
, es
->text
+ e
);
3326 text_buffer_changed(es
);
3329 /* there is an insertion */
3330 tl
= get_text_length(es
);
3331 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
));
3332 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3334 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3335 p
[i
] = lpsz_replace
[i
];
3336 if(es
->style
& ES_UPPERCASE
)
3337 CharUpperBuffW(p
, strl
);
3338 else if(es
->style
& ES_LOWERCASE
)
3339 CharLowerBuffW(p
, strl
);
3340 text_buffer_changed(es
);
3342 if (es
->style
& ES_MULTILINE
)
3344 INT st
= min(es
->selection_start
, es
->selection_end
);
3345 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3347 hrgn
= CreateRectRgn(0, 0, 0, 0);
3348 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3349 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3350 /* if text is too long undo all changes */
3351 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3353 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3355 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3357 text_buffer_changed(es
);
3358 EDIT_BuildLineDefs_ML(es
, s
, e
,
3359 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3362 hrgn
= CreateRectRgn(0, 0, 0, 0);
3363 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3367 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3368 EDIT_CalcLineWidth_SL(es
);
3369 /* remove chars that don't fit */
3370 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3371 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3372 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3374 EDIT_CalcLineWidth_SL(es
);
3376 text_buffer_changed(es
);
3377 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3383 utl
= strlenW(es
->undo_text
);
3384 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3385 /* undo-buffer is extended to the right */
3386 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3387 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3388 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3389 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3390 /* undo-buffer is extended to the left */
3391 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3392 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3394 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3396 es
->undo_position
= s
;
3398 /* new undo-buffer */
3399 EDIT_MakeUndoFit(es
, e
- s
);
3400 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3401 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3402 es
->undo_position
= s
;
3404 /* any deletion makes the old insertion-undo invalid */
3405 es
->undo_insert_count
= 0;
3407 EDIT_EM_EmptyUndoBuffer(es
);
3411 if ((s
== es
->undo_position
) ||
3412 ((es
->undo_insert_count
) &&
3413 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3415 * insertion is new and at delete position or
3416 * an extension to either left or right
3418 es
->undo_insert_count
+= strl
;
3420 /* new insertion undo */
3421 es
->undo_position
= s
;
3422 es
->undo_insert_count
= strl
;
3423 /* new insertion makes old delete-buffer invalid */
3424 *es
->undo_text
= '\0';
3427 EDIT_EM_EmptyUndoBuffer(es
);
3431 HeapFree(GetProcessHeap(), 0, buf
);
3435 /* If text has been deleted and we're right or center aligned then scroll rightward */
3436 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3438 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3440 if (delta
< 0 && es
->x_offset
)
3442 if (abs(delta
) > es
->x_offset
)
3445 es
->x_offset
+= delta
;
3449 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3450 es
->flags
|= EF_MODIFIED
;
3451 if (send_update
) es
->flags
|= EF_UPDATE
;
3454 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3458 EDIT_UpdateText(es
, NULL
, TRUE
);
3460 EDIT_EM_ScrollCaret(es
);
3462 /* force scroll info update */
3463 EDIT_UpdateScrollInfo(es
);
3466 if(send_update
|| (es
->flags
& EF_UPDATE
))
3468 es
->flags
&= ~EF_UPDATE
;
3469 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3474 /*********************************************************************
3479 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3483 if (!(es
->style
& ES_MULTILINE
))
3484 return (LRESULT
)FALSE
;
3494 if (es
->y_offset
< es
->line_count
- 1)
3499 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3502 if (es
->y_offset
< es
->line_count
- 1)
3503 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3506 return (LRESULT
)FALSE
;
3509 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3510 /* check if we are going to move too far */
3511 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3512 dy
= es
->line_count
- vlc
- es
->y_offset
;
3514 /* Notification is done in EDIT_EM_LineScroll */
3516 EDIT_EM_LineScroll(es
, 0, dy
);
3519 return MAKELONG((SHORT
)dy
, (BOOL
)TRUE
);
3521 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3526 /*********************************************************************
3531 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3533 if (es
->style
& ES_MULTILINE
) {
3538 INT cw
= es
->char_width
;
3543 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3544 li
= EDIT_EM_LineIndex(es
, l
);
3545 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3546 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3547 if (l
>= es
->y_offset
+ vlc
)
3548 dy
= l
- vlc
+ 1 - es
->y_offset
;
3549 if (l
< es
->y_offset
)
3550 dy
= l
- es
->y_offset
;
3551 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3552 if (x
< es
->format_rect
.left
)
3553 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3554 if (x
> es
->format_rect
.right
)
3555 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3556 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3558 /* check if we are going to move too far */
3559 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3560 dx
= es
->text_width
- ww
- es
->x_offset
;
3561 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3562 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3569 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3570 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3571 if (x
< es
->format_rect
.left
) {
3572 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3575 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3576 } while ((x
< goal
) && es
->x_offset
);
3577 /* FIXME: use ScrollWindow() somehow to improve performance */
3578 EDIT_UpdateText(es
, NULL
, TRUE
);
3579 } else if (x
> es
->format_rect
.right
) {
3581 INT len
= get_text_length(es
);
3582 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3585 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3586 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3587 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3588 /* FIXME: use ScrollWindow() somehow to improve performance */
3589 EDIT_UpdateText(es
, NULL
, TRUE
);
3593 if(es
->flags
& EF_FOCUSED
)
3594 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3598 /*********************************************************************
3602 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3605 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3607 if (!(es
->style
& ES_MULTILINE
))
3611 WARN("called with NULL handle\n");
3615 EDIT_UnlockBuffer(es
, TRUE
);
3620 LOCAL_Free(hInstance
, es
->hloc16
);
3621 es
->hloc16
= (HLOCAL16
)NULL
;
3629 LocalFree(es
->hloc32A
);
3641 countA
= LocalSize(hloc
);
3642 textA
= LocalLock(hloc
);
3643 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3644 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3646 ERR("Could not allocate new unicode buffer\n");
3649 textW
= LocalLock(hloc32W_new
);
3650 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3651 LocalUnlock(hloc32W_new
);
3655 LocalFree(es
->hloc32W
);
3657 es
->hloc32W
= hloc32W_new
;
3661 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3663 es
->flags
|= EF_APP_HAS_HANDLE
;
3664 EDIT_LockBuffer(es
);
3666 es
->x_offset
= es
->y_offset
= 0;
3667 es
->selection_start
= es
->selection_end
= 0;
3668 EDIT_EM_EmptyUndoBuffer(es
);
3669 es
->flags
&= ~EF_MODIFIED
;
3670 es
->flags
&= ~EF_UPDATE
;
3671 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3672 EDIT_UpdateText(es
, NULL
, TRUE
);
3673 EDIT_EM_ScrollCaret(es
);
3674 /* force scroll info update */
3675 EDIT_UpdateScrollInfo(es
);
3680 /*********************************************************************
3684 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3687 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3689 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3695 if (!(es
->style
& ES_MULTILINE
))
3699 WARN("called with NULL handle\n");
3703 EDIT_UnlockBuffer(es
, TRUE
);
3707 LocalFree(es
->hloc32A
);
3711 countA
= LOCAL_Size(hInstance
, hloc
);
3712 textA
= LOCAL_Lock(hInstance
, hloc
);
3713 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3714 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3716 ERR("Could not allocate new unicode buffer\n");
3719 textW
= LocalLock(hloc32W_new
);
3720 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3721 LocalUnlock(hloc32W_new
);
3722 LOCAL_Unlock(hInstance
, hloc
);
3725 LocalFree(es
->hloc32W
);
3727 es
->hloc32W
= hloc32W_new
;
3730 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3732 EDIT_LockBuffer(es
);
3734 es
->x_offset
= es
->y_offset
= 0;
3735 es
->selection_start
= es
->selection_end
= 0;
3736 EDIT_EM_EmptyUndoBuffer(es
);
3737 es
->flags
&= ~EF_MODIFIED
;
3738 es
->flags
&= ~EF_UPDATE
;
3739 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3740 EDIT_UpdateText(es
, NULL
, TRUE
);
3741 EDIT_EM_ScrollCaret(es
);
3742 /* force scroll info update */
3743 EDIT_UpdateScrollInfo(es
);
3748 /*********************************************************************
3752 * NOTE: this version currently implements WinNT limits
3755 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
3757 if (!limit
) limit
= ~0u;
3758 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
3759 es
->buffer_limit
= limit
;
3763 /*********************************************************************
3767 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3768 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3769 * margin according to the textmetrics of the current font.
3771 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3772 * of the char's width as the margin, but this is not how Windows handles this.
3773 * For all other fonts Windows sets the margins to zero.
3775 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3776 * edit control is equal to or larger than a certain size.
3777 * Interestingly if one subtracts both the left and right margins from
3778 * this size one always seems to get an even number. The extents of
3779 * the (four character) string "'**'" match this quite closely, so
3780 * we'll use this until we come up with a better idea.
3782 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3784 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3787 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3788 return sz
.cx
+ left
+ right
;
3791 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3792 WORD left
, WORD right
, BOOL repaint
)
3795 INT default_left_margin
= 0; /* in pixels */
3796 INT default_right_margin
= 0; /* in pixels */
3798 /* Set the default margins depending on the font */
3799 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3800 HDC dc
= GetDC(es
->hwndSelf
);
3801 HFONT old_font
= SelectObject(dc
, es
->font
);
3802 GetTextMetricsW(dc
, &tm
);
3803 /* The default margins are only non zero for TrueType or Vector fonts */
3804 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3807 /* This must be calculated more exactly! But how? */
3808 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3809 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3810 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3811 GetClientRect(es
->hwndSelf
, &rc
);
3812 if(rc
.right
- rc
.left
< min_size
) {
3813 default_left_margin
= es
->left_margin
;
3814 default_right_margin
= es
->right_margin
;
3817 SelectObject(dc
, old_font
);
3818 ReleaseDC(es
->hwndSelf
, dc
);
3821 if (action
& EC_LEFTMARGIN
) {
3822 es
->format_rect
.left
-= es
->left_margin
;
3823 if (left
!= EC_USEFONTINFO
)
3824 es
->left_margin
= left
;
3826 es
->left_margin
= default_left_margin
;
3827 es
->format_rect
.left
+= es
->left_margin
;
3830 if (action
& EC_RIGHTMARGIN
) {
3831 es
->format_rect
.right
+= es
->right_margin
;
3832 if (right
!= EC_USEFONTINFO
)
3833 es
->right_margin
= right
;
3835 es
->right_margin
= default_right_margin
;
3836 es
->format_rect
.right
-= es
->right_margin
;
3839 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3840 EDIT_AdjustFormatRect(es
);
3841 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3844 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3848 /*********************************************************************
3850 * EM_SETPASSWORDCHAR
3853 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3857 if (es
->style
& ES_MULTILINE
)
3860 if (es
->password_char
== c
)
3863 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3864 es
->password_char
= c
;
3866 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3867 es
->style
|= ES_PASSWORD
;
3869 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3870 es
->style
&= ~ES_PASSWORD
;
3872 EDIT_UpdateText(es
, NULL
, TRUE
);
3876 /*********************************************************************
3880 * note: unlike the specs say: the order of start and end
3881 * _is_ preserved in Windows. (i.e. start can be > end)
3882 * In other words: this handler is OK
3885 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3887 UINT old_start
= es
->selection_start
;
3888 UINT old_end
= es
->selection_end
;
3889 UINT len
= get_text_length(es
);
3891 if (start
== (UINT
)-1) {
3892 start
= es
->selection_end
;
3893 end
= es
->selection_end
;
3895 start
= min(start
, len
);
3896 end
= min(end
, len
);
3898 es
->selection_start
= start
;
3899 es
->selection_end
= end
;
3901 es
->flags
|= EF_AFTER_WRAP
;
3903 es
->flags
&= ~EF_AFTER_WRAP
;
3904 /* Compute the necessary invalidation region. */
3905 /* Note that we don't need to invalidate regions which have
3906 * "never" been selected, or those which are "still" selected.
3907 * In fact, every time we hit a selection boundary, we can
3908 * *toggle* whether we need to invalidate. Thus we can optimize by
3909 * *sorting* the interval endpoints. Let's assume that we sort them
3911 * start <= end <= old_start <= old_end
3912 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3913 * in 5 comparisons; ie it's impossible to do better than the
3915 ORDER_UINT(end
, old_end
);
3916 ORDER_UINT(start
, old_start
);
3917 ORDER_UINT(old_start
, old_end
);
3918 ORDER_UINT(start
, end
);
3919 /* Note that at this point 'end' and 'old_start' are not in order, but
3920 * start is definitely the min. and old_end is definitely the max. */
3921 if (end
!= old_start
)
3925 * ORDER_UINT32(end, old_start);
3926 * EDIT_InvalidateText(es, start, end);
3927 * EDIT_InvalidateText(es, old_start, old_end);
3928 * in place of the following if statement.
3929 * (That would complete the optimal five-comparison four-element sort.)
3931 if (old_start
> end
)
3933 EDIT_InvalidateText(es
, start
, end
);
3934 EDIT_InvalidateText(es
, old_start
, old_end
);
3938 EDIT_InvalidateText(es
, start
, old_start
);
3939 EDIT_InvalidateText(es
, end
, old_end
);
3942 else EDIT_InvalidateText(es
, start
, old_end
);
3946 /*********************************************************************
3951 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3953 if (!(es
->style
& ES_MULTILINE
))
3955 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3956 es
->tabs_count
= count
;
3960 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3961 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3968 /*********************************************************************
3973 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3975 if (!(es
->style
& ES_MULTILINE
))
3978 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3979 es
->tabs_count
= count
;
3984 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3985 for (i
= 0 ; i
< count
; i
++)
3986 es
->tabs
[i
] = *tabs
++;
3993 /*********************************************************************
3995 * EM_SETWORDBREAKPROC
3998 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
4000 if (es
->word_break_proc
== wbp
)
4003 es
->word_break_proc
= wbp
;
4005 es
->word_break_proc16
= NULL
;
4008 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
4009 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
4010 EDIT_UpdateText(es
, NULL
, TRUE
);
4016 /*********************************************************************
4018 * EM_SETWORDBREAKPROC16
4021 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
4023 if (es
->word_break_proc16
== wbp
)
4026 es
->word_break_proc
= NULL
;
4027 es
->word_break_proc16
= wbp
;
4028 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
4029 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
4030 EDIT_UpdateText(es
, NULL
, TRUE
);
4036 /*********************************************************************
4041 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
4046 /* As per MSDN spec, for a single-line edit control,
4047 the return value is always TRUE */
4048 if( es
->style
& ES_READONLY
)
4049 return !(es
->style
& ES_MULTILINE
);
4051 ulength
= strlenW(es
->undo_text
);
4053 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
4055 strcpyW(utext
, es
->undo_text
);
4057 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
4058 es
->undo_insert_count
, debugstr_w(utext
));
4060 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
4061 EDIT_EM_EmptyUndoBuffer(es
);
4062 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
4063 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
4064 /* send the notification after the selection start and end are set */
4065 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4066 EDIT_EM_ScrollCaret(es
);
4067 HeapFree(GetProcessHeap(), 0, utext
);
4069 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
4070 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
4075 /*********************************************************************
4080 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
4084 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4088 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
4089 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
4092 if (es
->style
& ES_MULTILINE
) {
4093 if (es
->style
& ES_READONLY
) {
4094 EDIT_MoveHome(es
, FALSE
);
4095 EDIT_MoveDown_ML(es
, FALSE
);
4097 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4098 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4103 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4105 static const WCHAR tabW
[] = {'\t',0};
4106 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4110 if (!(es
->style
& ES_READONLY
) && !control
) {
4111 if (es
->selection_start
!= es
->selection_end
)
4114 /* delete character left of caret */
4115 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4116 EDIT_MoveBackward(es
, TRUE
);
4122 if (!(es
->style
& ES_PASSWORD
))
4123 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4126 if (!(es
->style
& ES_READONLY
))
4127 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4130 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4131 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4134 if (!(es
->style
& ES_READONLY
))
4135 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4139 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4140 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4143 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4147 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4154 /*********************************************************************
4159 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4161 if (code
|| control
)
4181 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4182 EDIT_EM_ScrollCaret(es
);
4185 ERR("unknown menu item, please report\n");
4191 /*********************************************************************
4195 * Note: the resource files resource/sysres_??.rc cannot define a
4196 * single popup menu. Hence we use a (dummy) menubar
4197 * containing the single popup menu as its first item.
4199 * FIXME: the message identifiers have been chosen arbitrarily,
4200 * hence we use MF_BYPOSITION.
4201 * We might as well use the "real" values (anybody knows ?)
4202 * The menu definition is in resources/sysres_??.rc.
4203 * Once these are OK, we better use MF_BYCOMMAND here
4204 * (as we do in EDIT_WM_Command()).
4207 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4210 HMENU menu
= LoadMenuA(User32Instance
, "EDITMENU");
4212 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4214 HMENU popup
= GetSubMenu(menu
, 0);
4215 UINT start
= es
->selection_start
;
4216 UINT end
= es
->selection_end
;
4218 ORDER_UINT(start
, end
);
4221 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4223 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4225 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4227 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4229 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4231 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4233 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4236 /* Windows places the menu at the edit's center in this case */
4237 GetClientRect(es
->hwndSelf
, &rc
);
4238 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4239 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4240 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4243 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4248 /*********************************************************************
4253 static void EDIT_WM_Copy(EDITSTATE
*es
)
4255 INT s
= min(es
->selection_start
, es
->selection_end
);
4256 INT e
= max(es
->selection_start
, es
->selection_end
);
4264 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4265 dst
= GlobalLock(hdst
);
4266 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4267 dst
[len
] = 0; /* ensure 0 termination */
4268 TRACE("%s\n", debugstr_w(dst
));
4270 OpenClipboard(es
->hwndSelf
);
4272 SetClipboardData(CF_UNICODETEXT
, hdst
);
4277 /*********************************************************************
4282 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4286 TRACE("%s\n", debugstr_w(name
));
4288 * To initialize some final structure members, we call some helper
4289 * functions. However, since the EDITSTATE is not consistent (i.e.
4290 * not fully initialized), we should be very careful which
4291 * functions can be called, and in what order.
4293 EDIT_WM_SetFont(es
, 0, FALSE
);
4294 EDIT_EM_EmptyUndoBuffer(es
);
4296 /* We need to calculate the format rect
4297 (applications may send EM_SETMARGINS before the control gets visible) */
4298 GetClientRect(es
->hwndSelf
, &clientRect
);
4299 EDIT_SetRectNP(es
, &clientRect
);
4301 if (name
&& *name
) {
4302 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4303 /* if we insert text to the editline, the text scrolls out
4304 * of the window, as the caret is placed after the insert
4305 * pos normally; thus we reset es->selection... to 0 and
4308 es
->selection_start
= es
->selection_end
= 0;
4309 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4310 * Messages are only to be sent when the USER does something to
4311 * change the contents. So I am removing this EN_CHANGE
4313 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4315 EDIT_EM_ScrollCaret(es
);
4317 /* force scroll info update */
4318 EDIT_UpdateScrollInfo(es
);
4319 /* The rule seems to return 1 here for success */
4320 /* Power Builder masked edit controls will crash */
4322 /* FIXME: is that in all cases so ? */
4327 /*********************************************************************
4332 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4337 while (LocalUnlock(es
->hloc32W
)) ;
4338 LocalFree(es
->hloc32W
);
4341 while (LocalUnlock(es
->hloc32A
)) ;
4342 LocalFree(es
->hloc32A
);
4346 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
4347 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
4348 LOCAL_Free(hInstance
, es
->hloc16
);
4352 pc
= es
->first_line_def
;
4356 HeapFree(GetProcessHeap(), 0, pc
);
4360 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4361 HeapFree(GetProcessHeap(), 0, es
);
4367 /*********************************************************************
4372 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4374 /* we do the proper erase in EDIT_WM_Paint */
4379 /*********************************************************************
4384 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4386 if(!count
) return 0;
4390 lstrcpynW(dst
, es
->text
, count
);
4391 return strlenW(dst
);
4395 LPSTR textA
= (LPSTR
)dst
;
4396 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4397 textA
[count
- 1] = 0; /* ensure 0 termination */
4398 return strlen(textA
);
4402 /*********************************************************************
4407 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4412 if (!(es
->style
& ES_MULTILINE
))
4415 if (!(es
->style
& ES_AUTOHSCROLL
))
4419 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4422 TRACE("SB_LINELEFT\n");
4424 dx
= -es
->char_width
;
4427 TRACE("SB_LINERIGHT\n");
4428 if (es
->x_offset
< es
->text_width
)
4429 dx
= es
->char_width
;
4432 TRACE("SB_PAGELEFT\n");
4434 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4437 TRACE("SB_PAGERIGHT\n");
4438 if (es
->x_offset
< es
->text_width
)
4439 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4447 TRACE("SB_RIGHT\n");
4448 if (es
->x_offset
< es
->text_width
)
4449 dx
= es
->text_width
- es
->x_offset
;
4452 TRACE("SB_THUMBTRACK %d\n", pos
);
4453 es
->flags
|= EF_HSCROLL_TRACK
;
4454 if(es
->style
& WS_HSCROLL
)
4455 dx
= pos
- es
->x_offset
;
4460 if(pos
< 0 || pos
> 100) return 0;
4461 /* Assume default scroll range 0-100 */
4462 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4463 new_x
= pos
* (es
->text_width
- fw
) / 100;
4464 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4467 case SB_THUMBPOSITION
:
4468 TRACE("SB_THUMBPOSITION %d\n", pos
);
4469 es
->flags
&= ~EF_HSCROLL_TRACK
;
4470 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4471 dx
= pos
- es
->x_offset
;
4476 if(pos
< 0 || pos
> 100) return 0;
4477 /* Assume default scroll range 0-100 */
4478 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4479 new_x
= pos
* (es
->text_width
- fw
) / 100;
4480 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4483 /* force scroll info update */
4484 EDIT_UpdateScrollInfo(es
);
4485 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4489 TRACE("SB_ENDSCROLL\n");
4492 * FIXME : the next two are undocumented !
4493 * Are we doing the right thing ?
4494 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4495 * although it's also a regular control message.
4497 case EM_GETTHUMB
: /* this one is used by NT notepad */
4503 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4504 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4507 /* Assume default scroll range 0-100 */
4508 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4509 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4511 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4515 case EM_LINESCROLL16
:
4516 TRACE("EM_LINESCROLL16\n");
4522 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4528 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4529 /* check if we are going to move too far */
4530 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4531 dx
= es
->text_width
- fw
- es
->x_offset
;
4533 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4539 /*********************************************************************
4544 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4546 HWND hLBox
= es
->hwndListBox
;
4554 hCombo
= GetParent(es
->hwndSelf
);
4558 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4560 if (key
== VK_UP
|| key
== VK_DOWN
)
4562 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4565 if (msg
== WM_KEYDOWN
|| nEUI
)
4566 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4572 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4574 /* make sure ComboLBox pops up */
4575 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4580 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4583 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4585 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4587 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4592 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4598 /*********************************************************************
4602 * Handling of special keys that don't produce a WM_CHAR
4603 * (i.e. non-printable keys) & Backspace & Delete
4606 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4611 if (GetKeyState(VK_MENU
) & 0x8000)
4614 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4615 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4620 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4625 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4626 EDIT_MoveUp_ML(es
, shift
);
4629 EDIT_MoveWordBackward(es
, shift
);
4631 EDIT_MoveBackward(es
, shift
);
4634 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4638 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4639 EDIT_MoveDown_ML(es
, shift
);
4641 EDIT_MoveWordForward(es
, shift
);
4643 EDIT_MoveForward(es
, shift
);
4646 if (control
&& (es
->style
& ES_MULTILINE
)) {
4647 EDIT_MoveStartOfText(es
, shift
);
4649 EDIT_MoveHome(es
, shift
); /* start of line */
4653 if (control
&& (es
->style
& ES_MULTILINE
)) {
4654 EDIT_MoveEndOfText(es
, shift
);
4656 EDIT_MoveEnd(es
, shift
); /* end of line */
4660 if (es
->style
& ES_MULTILINE
)
4661 EDIT_MovePageUp_ML(es
, shift
);
4663 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4666 if (es
->style
& ES_MULTILINE
)
4667 EDIT_MovePageDown_ML(es
, shift
);
4669 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4672 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4673 if (es
->selection_start
!= es
->selection_end
) {
4680 /* delete character left of caret */
4681 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4682 EDIT_MoveBackward(es
, TRUE
);
4684 } else if (control
) {
4685 /* delete to end of line */
4686 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4687 EDIT_MoveEnd(es
, TRUE
);
4690 /* delete character right of caret */
4691 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4692 EDIT_MoveForward(es
, TRUE
);
4700 if (!(es
->style
& ES_READONLY
))
4706 /* If the edit doesn't want the return send a message to the default object */
4707 if(!(es
->style
& ES_WANTRETURN
))
4709 HWND hwndParent
= GetParent(es
->hwndSelf
);
4710 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4711 if (HIWORD(dw
) == DC_HASDEFID
)
4713 SendMessageW( hwndParent
, WM_COMMAND
,
4714 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4715 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4724 /*********************************************************************
4729 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4731 es
->flags
&= ~EF_FOCUSED
;
4733 if(!(es
->style
& ES_NOHIDESEL
))
4734 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4735 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4740 /*********************************************************************
4744 * The caret position has been set on the WM_LBUTTONDOWN message
4747 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4750 INT e
= es
->selection_end
;
4755 es
->bCaptureState
= TRUE
;
4756 SetCapture(es
->hwndSelf
);
4758 l
= EDIT_EM_LineFromChar(es
, e
);
4759 li
= EDIT_EM_LineIndex(es
, l
);
4760 ll
= EDIT_EM_LineLength(es
, e
);
4761 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4762 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4763 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4764 EDIT_EM_ScrollCaret(es
);
4765 es
->region_posx
= es
->region_posy
= 0;
4766 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4771 /*********************************************************************
4776 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4781 es
->bCaptureState
= TRUE
;
4782 SetCapture(es
->hwndSelf
);
4783 EDIT_ConfinePoint(es
, &x
, &y
);
4784 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4785 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4786 EDIT_EM_ScrollCaret(es
);
4787 es
->region_posx
= es
->region_posy
= 0;
4788 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4790 if (!(es
->flags
& EF_FOCUSED
))
4791 SetFocus(es
->hwndSelf
);
4797 /*********************************************************************
4802 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4804 if (es
->bCaptureState
) {
4805 KillTimer(es
->hwndSelf
, 0);
4806 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4808 es
->bCaptureState
= FALSE
;
4813 /*********************************************************************
4818 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4820 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4825 /*********************************************************************
4830 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4836 /* If the mouse has been captured by process other than the edit control itself,
4837 * the windows edit controls will not select the strings with mouse move.
4839 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4843 * FIXME: gotta do some scrolling if outside client
4844 * area. Maybe reset the timer ?
4847 EDIT_ConfinePoint(es
, &x
, &y
);
4848 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4849 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4850 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4851 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4852 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4857 /*********************************************************************
4861 * See also EDIT_WM_StyleChanged
4863 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4868 TRACE("Creating %s edit control, style = %08lx\n",
4869 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4871 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4873 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4876 * Note: since the EDITSTATE has not been fully initialized yet,
4877 * we can't use any API calls that may send
4878 * WM_XXX messages before WM_NCCREATE is completed.
4881 es
->is_unicode
= unicode
;
4882 es
->style
= lpcs
->style
;
4884 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4886 es
->hwndSelf
= hwnd
;
4887 /* Save parent, which will be notified by EN_* messages */
4888 es
->hwndParent
= lpcs
->hwndParent
;
4890 if (es
->style
& ES_COMBO
)
4891 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4893 /* Number overrides lowercase overrides uppercase (at least it
4894 * does in Win95). However I'll bet that ES_NUMBER would be
4895 * invalid under Win 3.1.
4897 if (es
->style
& ES_NUMBER
) {
4898 ; /* do not override the ES_NUMBER */
4899 } else if (es
->style
& ES_LOWERCASE
) {
4900 es
->style
&= ~ES_UPPERCASE
;
4902 if (es
->style
& ES_MULTILINE
) {
4903 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4904 if (es
->style
& WS_VSCROLL
)
4905 es
->style
|= ES_AUTOVSCROLL
;
4906 if (es
->style
& WS_HSCROLL
)
4907 es
->style
|= ES_AUTOHSCROLL
;
4908 es
->style
&= ~ES_PASSWORD
;
4909 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4910 /* Confirmed - RIGHT overrides CENTER */
4911 if (es
->style
& ES_RIGHT
)
4912 es
->style
&= ~ES_CENTER
;
4913 es
->style
&= ~WS_HSCROLL
;
4914 es
->style
&= ~ES_AUTOHSCROLL
;
4917 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4918 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4919 es
->style
&= ~ES_CENTER
;
4920 es
->style
&= ~WS_HSCROLL
;
4921 es
->style
&= ~WS_VSCROLL
;
4922 if (es
->style
& ES_PASSWORD
)
4923 es
->password_char
= '*';
4926 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4927 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4929 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4931 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4933 es
->undo_buffer_size
= es
->buffer_size
;
4935 if (es
->style
& ES_MULTILINE
)
4936 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4941 * In Win95 look and feel, the WS_BORDER style is replaced by the
4942 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4943 * control a nonclient area so we don't need to draw the border.
4944 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4945 * a nonclient area and we should handle painting the border ourselves.
4947 * When making modifications please ensure that the code still works
4948 * for edit controls created directly with style 0x50800000, exStyle 0
4949 * (which should have a single pixel border)
4951 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4952 es
->style
&= ~WS_BORDER
;
4953 else if (es
->style
& WS_BORDER
)
4954 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4959 /*********************************************************************
4964 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4977 BOOL rev
= es
->bEnableState
&&
4978 ((es
->flags
& EF_FOCUSED
) ||
4979 (es
->style
& ES_NOHIDESEL
));
4980 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4982 GetClientRect(es
->hwndSelf
, &rcClient
);
4984 /* get the background brush */
4985 brush
= EDIT_NotifyCtlColor(es
, dc
);
4987 /* paint the border and the background */
4988 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4990 if(es
->style
& WS_BORDER
) {
4991 bw
= GetSystemMetrics(SM_CXBORDER
);
4992 bh
= GetSystemMetrics(SM_CYBORDER
);
4994 if(es
->style
& ES_MULTILINE
) {
4995 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4996 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4999 /* Draw the frame. Same code as in nonclient.c */
5000 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
5001 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
5002 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
5003 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
5004 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
5005 SelectObject(dc
, old_brush
);
5007 /* Keep the border clean */
5008 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
5009 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
5012 GetClipBox(dc
, &rc
);
5013 FillRect(dc
, &rc
, brush
);
5015 IntersectClipRect(dc
, es
->format_rect
.left
,
5016 es
->format_rect
.top
,
5017 es
->format_rect
.right
,
5018 es
->format_rect
.bottom
);
5019 if (es
->style
& ES_MULTILINE
) {
5021 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5024 old_font
= SelectObject(dc
, es
->font
);
5026 if (!es
->bEnableState
)
5027 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
5028 GetClipBox(dc
, &rcRgn
);
5029 if (es
->style
& ES_MULTILINE
) {
5030 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5031 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
5032 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
5033 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
5034 EDIT_PaintLine(es
, dc
, i
, rev
);
5037 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
5038 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
5039 EDIT_PaintLine(es
, dc
, 0, rev
);
5042 SelectObject(dc
, old_font
);
5045 EndPaint(es
->hwndSelf
, &ps
);
5049 /*********************************************************************
5054 static void EDIT_WM_Paste(EDITSTATE
*es
)
5059 /* Protect read-only edit control from modification */
5060 if(es
->style
& ES_READONLY
)
5063 OpenClipboard(es
->hwndSelf
);
5064 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
5065 src
= (LPWSTR
)GlobalLock(hsrc
);
5066 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
5069 else if (es
->style
& ES_PASSWORD
) {
5070 /* clear selected text in password edit box even with empty clipboard */
5071 const WCHAR empty_strW
[] = { 0 };
5072 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
5078 /*********************************************************************
5083 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
5085 es
->flags
|= EF_FOCUSED
;
5087 if (!(es
->style
& ES_NOHIDESEL
))
5088 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
5090 /* single line edit updates itself */
5091 if (!(es
->style
& ES_MULTILINE
))
5093 HDC hdc
= GetDC(es
->hwndSelf
);
5094 EDIT_WM_Paint(es
, hdc
);
5095 ReleaseDC(es
->hwndSelf
, hdc
);
5098 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5099 EDIT_SetCaretPos(es
, es
->selection_end
,
5100 es
->flags
& EF_AFTER_WRAP
);
5101 ShowCaret(es
->hwndSelf
);
5102 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
5106 /*********************************************************************
5110 * With Win95 look the margins are set to default font value unless
5111 * the system font (font == 0) is being set, in which case they are left
5115 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5123 dc
= GetDC(es
->hwndSelf
);
5125 old_font
= SelectObject(dc
, font
);
5126 GetTextMetricsW(dc
, &tm
);
5127 es
->line_height
= tm
.tmHeight
;
5128 es
->char_width
= tm
.tmAveCharWidth
;
5130 SelectObject(dc
, old_font
);
5131 ReleaseDC(es
->hwndSelf
, dc
);
5133 /* Reset the format rect and the margins */
5134 GetClientRect(es
->hwndSelf
, &clientRect
);
5135 EDIT_SetRectNP(es
, &clientRect
);
5136 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5137 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5139 if (es
->style
& ES_MULTILINE
)
5140 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5142 EDIT_CalcLineWidth_SL(es
);
5145 EDIT_UpdateText(es
, NULL
, TRUE
);
5146 if (es
->flags
& EF_FOCUSED
) {
5148 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5149 EDIT_SetCaretPos(es
, es
->selection_end
,
5150 es
->flags
& EF_AFTER_WRAP
);
5151 ShowCaret(es
->hwndSelf
);
5156 /*********************************************************************
5161 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5162 * The modified flag is reset. No notifications are sent.
5164 * For single-line controls, reception of WM_SETTEXT triggers:
5165 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5168 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5170 LPWSTR textW
= NULL
;
5171 if (!unicode
&& text
)
5173 LPCSTR textA
= (LPCSTR
)text
;
5174 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5175 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5177 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5181 if (es
->flags
& EF_UPDATE
)
5182 /* fixed this bug once; complain if we see it about to happen again. */
5183 ERR("SetSel may generate UPDATE message whose handler may reset "
5186 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5189 TRACE("%s\n", debugstr_w(text
));
5190 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5192 HeapFree(GetProcessHeap(), 0, textW
);
5196 static const WCHAR empty_stringW
[] = {0};
5198 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5201 es
->flags
&= ~EF_MODIFIED
;
5202 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5204 /* Send the notification after the selection start and end have been set
5205 * edit control doesn't send notification on WM_SETTEXT
5206 * if it is multiline, or it is part of combobox
5208 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5210 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5211 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5213 EDIT_EM_ScrollCaret(es
);
5214 EDIT_UpdateScrollInfo(es
);
5218 /*********************************************************************
5223 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5225 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5227 TRACE("width = %d, height = %d\n", width
, height
);
5228 SetRect(&rc
, 0, 0, width
, height
);
5229 EDIT_SetRectNP(es
, &rc
);
5230 EDIT_UpdateText(es
, NULL
, TRUE
);
5235 /*********************************************************************
5239 * This message is sent by SetWindowLong on having changed either the Style
5240 * or the extended style.
5242 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5244 * See also EDIT_WM_NCCreate
5246 * It appears that the Windows version of the edit control allows the style
5247 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5248 * style variable which will generally be different. In this function we
5249 * update the internal style based on what changed in the externally visible
5252 * Much of this content as based upon the MSDN, especially:
5253 * Platform SDK Documentation -> User Interface Services ->
5254 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5255 * Edit Control Styles
5257 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5259 if (GWL_STYLE
== which
) {
5260 DWORD style_change_mask
;
5262 /* Only a subset of changes can be applied after the control
5265 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5267 if (es
->style
& ES_MULTILINE
)
5268 style_change_mask
|= ES_WANTRETURN
;
5270 new_style
= style
->styleNew
& style_change_mask
;
5272 /* Number overrides lowercase overrides uppercase (at least it
5273 * does in Win95). However I'll bet that ES_NUMBER would be
5274 * invalid under Win 3.1.
5276 if (new_style
& ES_NUMBER
) {
5277 ; /* do not override the ES_NUMBER */
5278 } else if (new_style
& ES_LOWERCASE
) {
5279 new_style
&= ~ES_UPPERCASE
;
5282 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5283 } else if (GWL_EXSTYLE
== which
) {
5284 ; /* FIXME - what is needed here */
5286 WARN ("Invalid style change %ld\n",which
);
5292 /*********************************************************************
5297 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5299 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5300 if (EDIT_EM_CanUndo(es
))
5303 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5304 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5307 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5311 /*********************************************************************
5316 static void EDIT_WM_Timer(EDITSTATE
*es
)
5318 if (es
->region_posx
< 0) {
5319 EDIT_MoveBackward(es
, TRUE
);
5320 } else if (es
->region_posx
> 0) {
5321 EDIT_MoveForward(es
, TRUE
);
5324 * FIXME: gotta do some vertical scrolling here, like
5325 * EDIT_EM_LineScroll(hwnd, 0, 1);
5329 /*********************************************************************
5334 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5338 if (!(es
->style
& ES_MULTILINE
))
5341 if (!(es
->style
& ES_AUTOVSCROLL
))
5350 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5351 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5352 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5354 EDIT_EM_Scroll(es
, action
);
5361 TRACE("SB_BOTTOM\n");
5362 dy
= es
->line_count
- 1 - es
->y_offset
;
5365 TRACE("SB_THUMBTRACK %d\n", pos
);
5366 es
->flags
|= EF_VSCROLL_TRACK
;
5367 if(es
->style
& WS_VSCROLL
)
5368 dy
= pos
- es
->y_offset
;
5371 /* Assume default scroll range 0-100 */
5374 if(pos
< 0 || pos
> 100) return 0;
5375 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5376 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5377 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5378 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5379 es
->line_count
, es
->y_offset
, pos
, dy
);
5382 case SB_THUMBPOSITION
:
5383 TRACE("SB_THUMBPOSITION %d\n", pos
);
5384 es
->flags
&= ~EF_VSCROLL_TRACK
;
5385 if(es
->style
& WS_VSCROLL
)
5386 dy
= pos
- es
->y_offset
;
5389 /* Assume default scroll range 0-100 */
5392 if(pos
< 0 || pos
> 100) return 0;
5393 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5394 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5395 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5396 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5397 es
->line_count
, es
->y_offset
, pos
, dy
);
5401 /* force scroll info update */
5402 EDIT_UpdateScrollInfo(es
);
5403 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5407 TRACE("SB_ENDSCROLL\n");
5410 * FIXME : the next two are undocumented !
5411 * Are we doing the right thing ?
5412 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5413 * although it's also a regular control message.
5415 case EM_GETTHUMB
: /* this one is used by NT notepad */
5421 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5422 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5425 /* Assume default scroll range 0-100 */
5426 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5427 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5429 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5433 case EM_LINESCROLL16
:
5434 TRACE("EM_LINESCROLL16 %d\n", pos
);
5440 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5445 EDIT_EM_LineScroll(es
, 0, dy
);
5449 /*********************************************************************
5454 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5456 if (es
->flags
& EF_UPDATE
) {
5457 es
->flags
&= ~EF_UPDATE
;
5458 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5460 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5464 /*********************************************************************
5469 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5471 if (es
->flags
& EF_UPDATE
) {
5472 es
->flags
&= ~EF_UPDATE
;
5473 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5475 NtUserInvalidateRect(es
->hwndSelf
, rc
, bErase
);
5478 /********************************************************************
5480 * The Following code is to handle inline editing from IMEs
5483 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5486 LPWSTR lpCompStr
= NULL
;
5488 LPSTR lpCompStrAttr
= NULL
;
5491 if (!(hIMC
= ImmGetContext(hwnd
)))
5494 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5498 ImmReleaseContext(hwnd
, hIMC
);
5502 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
);
5505 ERR("Unable to allocate IME CompositionString\n");
5506 ImmReleaseContext(hwnd
,hIMC
);
5511 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
5512 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5514 if (CompFlag
& GCS_COMPATTR
)
5517 * We do not use the attributes yet. it would tell us what characters
5518 * are in transition and which are converted or decided upon
5520 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5524 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
);
5527 ERR("Unable to allocate IME Attribute String\n");
5528 HeapFree(GetProcessHeap(),0,lpCompStr
);
5529 ImmReleaseContext(hwnd
,hIMC
);
5532 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5534 lpCompStrAttr
[dwBufLenAttr
] = 0;
5537 lpCompStrAttr
= NULL
;
5540 /* check for change in composition start */
5541 if (es
->selection_end
< es
->composition_start
)
5542 es
->composition_start
= es
->selection_end
;
5544 /* replace existing selection string */
5545 es
->selection_start
= es
->composition_start
;
5547 if (es
->composition_len
> 0)
5548 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5550 es
->selection_end
= es
->selection_start
;
5552 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5553 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5555 es
->selection_start
= es
->composition_start
;
5556 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5558 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5559 HeapFree(GetProcessHeap(),0,lpCompStr
);
5560 ImmReleaseContext(hwnd
,hIMC
);
5563 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5569 if ( !(hIMC
= ImmGetContext(hwnd
)))
5572 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5575 ImmReleaseContext(hwnd
, hIMC
);
5579 lpResultStr
= HeapAlloc(GetProcessHeap(),0, dwBufLen
);
5582 ERR("Unable to alloc buffer for IME string\n");
5583 ImmReleaseContext(hwnd
, hIMC
);
5587 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, dwBufLen
);
5588 lpResultStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5590 /* check for change in composition start */
5591 if (es
->selection_end
< es
->composition_start
)
5592 es
->composition_start
= es
->selection_end
;
5594 es
->selection_start
= es
->composition_start
;
5595 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5596 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5597 es
->composition_start
= es
->selection_end
;
5598 es
->composition_len
= 0;
5600 HeapFree(GetProcessHeap(),0,lpResultStr
);
5601 ImmReleaseContext(hwnd
, hIMC
);
5604 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5606 if (CompFlag
& GCS_RESULTSTR
)
5607 EDIT_GetResultStr(hwnd
,es
);
5608 if (CompFlag
& GCS_COMPSTR
)
5609 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);