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 BOOL
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 result
= 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 result
= 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 if (new_line
== NULL
)
1227 new_line
->next
= previous_line
->next
;
1228 previous_line
->next
= new_line
;
1229 current_line
= new_line
;
1232 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1234 /* The previous line merged with this line so we delete this extra entry */
1235 previous_line
->next
= current_line
->next
;
1236 HeapFree(GetProcessHeap(), 0, current_line
);
1237 current_line
= previous_line
->next
;
1241 else /* current_line->index + delta == current_position */
1243 if (current_position
- es
->text
> iend
)
1244 break; /* We reached end of line modifications */
1245 /* else recalulate this line */
1249 current_line
->index
= current_position
- es
->text
;
1250 orig_net_length
= current_line
->net_length
;
1252 /* Find end of line */
1253 cp
= current_position
;
1255 if (*cp
== '\n') break;
1256 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1261 /* Mark type of line termination */
1263 current_line
->ending
= END_0
;
1264 current_line
->net_length
= strlenW(current_position
);
1265 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1266 current_line
->ending
= END_SOFT
;
1267 current_line
->net_length
= cp
- current_position
- 1;
1268 } else if (*cp
== '\n') {
1269 current_line
->ending
= END_RICH
;
1270 current_line
->net_length
= cp
- current_position
;
1272 current_line
->ending
= END_HARD
;
1273 current_line
->net_length
= cp
- current_position
;
1276 /* Calculate line width */
1277 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1278 current_position
, current_line
->net_length
,
1279 es
->tabs_count
, es
->tabs
));
1281 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1282 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1283 if (current_line
->width
> fw
) {
1288 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1289 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1290 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1291 current_position
, next
, es
->tabs_count
, es
->tabs
));
1292 } while (current_line
->width
<= fw
);
1293 if (!prev
) { /* Didn't find a line break so force a break */
1298 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1299 current_position
, next
, es
->tabs_count
, es
->tabs
));
1300 } while (current_line
->width
<= fw
);
1305 /* If the first line we are calculating, wrapped before istart, we must
1306 * adjust istart in order for this to be reflected in the update region. */
1307 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1308 istart
= current_line
->index
+ prev
;
1309 /* else if we are updating the previous line before the first line we
1310 * are re-calculating and it expanded */
1311 else if (current_line
== start_line
&&
1312 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1314 /* Line expanded due to an upwards line wrap so we must partially include
1315 * previous line in update region */
1316 nstart_line
= line_index
;
1317 nstart_index
= current_line
->index
;
1318 istart
= current_line
->index
+ orig_net_length
;
1321 current_line
->net_length
= prev
;
1322 current_line
->ending
= END_WRAP
;
1323 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1324 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1326 else if (orig_net_length
< current_line
->net_length
&&
1327 current_line
== start_line
&&
1328 current_line
->index
!= nstart_index
) {
1329 /* The previous line expanded but it's still not as wide as the client rect */
1330 /* The expansion is due to an upwards line wrap so we must partially include
1331 it in the update region */
1332 nstart_line
= line_index
;
1333 nstart_index
= current_line
->index
;
1334 istart
= current_line
->index
+ orig_net_length
;
1339 /* Adjust length to include line termination */
1340 switch (current_line
->ending
) {
1342 current_line
->length
= current_line
->net_length
+ 3;
1345 current_line
->length
= current_line
->net_length
+ 1;
1348 current_line
->length
= current_line
->net_length
+ 2;
1352 current_line
->length
= current_line
->net_length
;
1355 es
->text_width
= max(es
->text_width
, current_line
->width
);
1356 current_position
+= current_line
->length
;
1357 previous_line
= current_line
;
1358 current_line
= current_line
->next
;
1360 } while (previous_line
->ending
!= END_0
);
1362 /* Finish adjusting line indexes by delta or remove hanging lines */
1363 if (previous_line
->ending
== END_0
)
1365 LINEDEF
*pnext
= NULL
;
1367 previous_line
->next
= NULL
;
1368 while (current_line
)
1370 pnext
= current_line
->next
;
1371 HeapFree(GetProcessHeap(), 0, current_line
);
1372 current_line
= pnext
;
1376 else if (delta
!= 0)
1378 while (current_line
)
1380 current_line
->index
+= delta
;
1381 current_line
= current_line
->next
;
1385 /* Calculate rest of modification rectangle */
1390 * We calculate two rectangles. One for the first line which may have
1391 * an indent with respect to the format rect. The other is a format-width
1392 * rectangle that spans the rest of the lines that changed or moved.
1394 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1395 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1396 rc
.bottom
= rc
.top
+ es
->line_height
;
1397 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1398 rc
.left
= es
->format_rect
.left
;
1400 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1401 es
->text
+ nstart_index
, istart
- nstart_index
,
1402 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1403 rc
.right
= es
->format_rect
.right
;
1404 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1407 rc
.left
= es
->format_rect
.left
;
1408 rc
.right
= es
->format_rect
.right
;
1410 * If lines were added or removed we must re-paint the remainder of the
1411 * lines since the remaining lines were either shifted up or down.
1413 if (line_count
< es
->line_count
) /* We added lines */
1414 rc
.bottom
= es
->line_count
* es
->line_height
;
1415 else if (line_count
> es
->line_count
) /* We removed lines */
1416 rc
.bottom
= line_count
* es
->line_height
;
1418 rc
.bottom
= line_index
* es
->line_height
;
1419 rc
.bottom
+= es
->format_rect
.top
;
1420 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1421 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1422 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1423 DeleteObject(tmphrgn
);
1427 SelectObject(dc
, old_font
);
1429 ReleaseDC(es
->hwndSelf
, dc
);
1432 /*********************************************************************
1434 * EDIT_CalcLineWidth_SL
1437 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1444 text
= EDIT_GetPasswordPointer_SL(es
);
1446 dc
= GetDC(es
->hwndSelf
);
1448 old_font
= SelectObject(dc
, es
->font
);
1450 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1453 SelectObject(dc
, old_font
);
1454 ReleaseDC(es
->hwndSelf
, dc
);
1456 if (es
->style
& ES_PASSWORD
)
1457 HeapFree(GetProcessHeap(), 0, text
);
1459 es
->text_width
= size
.cx
;
1462 /*********************************************************************
1464 * EDIT_CallWordBreakProc
1466 * Call appropriate WordBreakProc (internal or external).
1468 * Note: The "start" argument should always be an index referring
1469 * to es->text. The actual wordbreak proc might be
1470 * 16 bit, so we can't always pass any 32 bit LPSTR.
1471 * Hence we assume that es->text is the buffer that holds
1472 * the string under examination (we can decide this for ourselves).
1475 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1480 if (es
->word_break_proc16
) {
1487 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1488 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1489 segptr
= K32WOWGlobalLock16(hglob16
);
1490 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1491 args
[4] = SELECTOROF(segptr
);
1492 args
[3] = OFFSETOF(segptr
);
1496 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1497 ret
= LOWORD(result
);
1498 GlobalUnlock16(hglob16
);
1499 GlobalFree16(hglob16
);
1501 else if (es
->word_break_proc
)
1503 if (es
->word_break_proc
)
1508 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1510 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1511 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1512 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1516 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1520 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1521 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1524 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1525 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1526 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1527 ret
= wbpA(textA
, index
, countA
, action
);
1528 HeapFree(GetProcessHeap(), 0, textA
);
1532 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1538 /*********************************************************************
1542 * Beware: This is not the function called on EM_CHARFROMPOS
1543 * The position _can_ be outside the formatting / client
1545 * The return value is only the character index
1548 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1553 INT x_high
= 0, x_low
= 0;
1555 if (es
->style
& ES_MULTILINE
) {
1556 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1558 LINEDEF
*line_def
= es
->first_line_def
;
1560 while ((line
> 0) && line_def
->next
) {
1561 line_index
+= line_def
->length
;
1562 line_def
= line_def
->next
;
1565 x
+= es
->x_offset
- es
->format_rect
.left
;
1566 if (es
->style
& ES_RIGHT
)
1567 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1568 else if (es
->style
& ES_CENTER
)
1569 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1570 if (x
>= line_def
->width
) {
1572 *after_wrap
= (line_def
->ending
== END_WRAP
);
1573 return line_index
+ line_def
->net_length
;
1577 *after_wrap
= FALSE
;
1580 dc
= GetDC(es
->hwndSelf
);
1582 old_font
= SelectObject(dc
, es
->font
);
1584 high
= line_index
+ line_def
->net_length
+ 1;
1585 while (low
< high
- 1)
1587 INT mid
= (low
+ high
) / 2;
1588 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1597 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1603 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1604 (line_def
->ending
== END_WRAP
));
1609 *after_wrap
= FALSE
;
1610 x
-= es
->format_rect
.left
;
1612 return es
->x_offset
;
1616 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1617 if (es
->style
& ES_RIGHT
)
1619 else if (es
->style
& ES_CENTER
)
1623 text
= EDIT_GetPasswordPointer_SL(es
);
1624 dc
= GetDC(es
->hwndSelf
);
1626 old_font
= SelectObject(dc
, es
->font
);
1630 INT high
= es
->x_offset
;
1631 while (low
< high
- 1)
1633 INT mid
= (low
+ high
) / 2;
1634 GetTextExtentPoint32W( dc
, text
+ mid
,
1635 es
->x_offset
- mid
, &size
);
1644 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1651 INT low
= es
->x_offset
;
1652 INT high
= get_text_length(es
) + 1;
1653 while (low
< high
- 1)
1655 INT mid
= (low
+ high
) / 2;
1656 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1657 mid
- es
->x_offset
, &size
);
1666 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1671 if (es
->style
& ES_PASSWORD
)
1672 HeapFree(GetProcessHeap(), 0, text
);
1675 SelectObject(dc
, old_font
);
1676 ReleaseDC(es
->hwndSelf
, dc
);
1681 /*********************************************************************
1685 * adjusts the point to be within the formatting rectangle
1686 * (so CharFromPos returns the nearest _visible_ character)
1689 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1691 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1692 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1696 /*********************************************************************
1700 * Calculates the bounding rectangle for a line from a starting
1701 * column to an ending column.
1704 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1706 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1708 if (es
->style
& ES_MULTILINE
)
1709 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1711 rc
->top
= es
->format_rect
.top
;
1712 rc
->bottom
= rc
->top
+ es
->line_height
;
1713 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1714 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1718 /*********************************************************************
1720 * EDIT_GetPasswordPointer_SL
1722 * note: caller should free the (optionally) allocated buffer
1725 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1727 if (es
->style
& ES_PASSWORD
) {
1728 INT len
= get_text_length(es
);
1729 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1733 while(len
) text
[--len
] = es
->password_char
;
1740 /*********************************************************************
1744 * This acts as a LOCAL_Lock(), but it locks only once. This way
1745 * you can call it whenever you like, without unlocking.
1747 * Initially the edit control allocates a HLOCAL32 buffer
1748 * (32 bit linear memory handler). However, 16 bit application
1749 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1750 * handler). From that moment on we have to keep using this 16 bit memory
1751 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1752 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1756 static void EDIT_LockBuffer(EDITSTATE
*es
)
1759 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1765 BOOL _16bit
= FALSE
;
1772 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1773 textA
= LocalLock(es
->hloc32A
);
1774 countA
= strlen(textA
) + 1;
1779 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1780 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1781 countA
= strlen(textA
) + 1;
1787 ERR("no buffer ... please report\n");
1794 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1795 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1796 if(countW_new
> es
->buffer_size
+ 1)
1798 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1799 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1800 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1803 es
->hloc32W
= hloc32W_new
;
1804 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1805 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1808 WARN("FAILED! Will synchronize partially\n");
1812 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1813 es
->text
= LocalLock(es
->hloc32W
);
1817 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1820 LOCAL_Unlock(hInstance
, es
->hloc16
);
1823 LocalUnlock(es
->hloc32A
);
1826 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1831 /*********************************************************************
1833 * EDIT_SL_InvalidateText
1835 * Called from EDIT_InvalidateText().
1836 * Does the job for single-line controls only.
1839 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1844 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1845 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1846 EDIT_UpdateText(es
, &rc
, TRUE
);
1850 /*********************************************************************
1852 * EDIT_ML_InvalidateText
1854 * Called from EDIT_InvalidateText().
1855 * Does the job for multi-line controls only.
1858 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1860 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1861 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1862 INT el
= EDIT_EM_LineFromChar(es
, end
);
1871 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1874 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1875 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1876 if (sl
< es
->y_offset
) {
1880 if (el
> es
->y_offset
+ vlc
) {
1881 el
= es
->y_offset
+ vlc
;
1882 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1884 GetClientRect(es
->hwndSelf
, &rc1
);
1885 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1887 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1888 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1889 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1891 EDIT_GetLineRect(es
, sl
, sc
,
1892 EDIT_EM_LineLength(es
,
1893 EDIT_EM_LineIndex(es
, sl
)),
1895 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1896 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1897 for (l
= sl
+ 1 ; l
< el
; l
++) {
1898 EDIT_GetLineRect(es
, l
, 0,
1899 EDIT_EM_LineLength(es
,
1900 EDIT_EM_LineIndex(es
, l
)),
1902 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1903 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1905 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1906 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1907 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1912 /*********************************************************************
1914 * EDIT_InvalidateText
1916 * Invalidate the text from offset start up to, but not including,
1917 * offset end. Useful for (re)painting the selection.
1918 * Regions outside the linewidth are not invalidated.
1919 * end == -1 means end == TextLength.
1920 * start and end need not be ordered.
1923 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1929 end
= get_text_length(es
);
1937 if (es
->style
& ES_MULTILINE
)
1938 EDIT_ML_InvalidateText(es
, start
, end
);
1940 EDIT_SL_InvalidateText(es
, start
, end
);
1944 /*********************************************************************
1948 * Try to fit size + 1 characters in the buffer.
1950 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1954 if (size
<= es
->buffer_size
)
1957 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1959 /* Force edit to unlock it's buffer. es->text now NULL */
1960 EDIT_UnlockBuffer(es
, TRUE
);
1963 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1964 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1965 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1966 es
->hloc32W
= hNew32W
;
1967 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1971 EDIT_LockBuffer(es
);
1973 if (es
->buffer_size
< size
) {
1974 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1975 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1978 TRACE("We now have %d+1\n", es
->buffer_size
);
1984 /*********************************************************************
1988 * Try to fit size + 1 bytes in the undo buffer.
1991 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1995 if (size
<= es
->undo_buffer_size
)
1998 TRACE("trying to ReAlloc to %d+1\n", size
);
2000 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
2001 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
2002 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
2007 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
2013 /*********************************************************************
2018 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
2020 INT e
= es
->selection_end
;
2024 if ((es
->style
& ES_MULTILINE
) && e
&&
2025 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
2027 if (e
&& (es
->text
[e
- 1] == '\r'))
2031 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2032 EDIT_EM_ScrollCaret(es
);
2036 /*********************************************************************
2040 * Only for multi line controls
2041 * Move the caret one line down, on a column with the nearest
2042 * x coordinate on the screen (might be a different column).
2045 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
2047 INT s
= es
->selection_start
;
2048 INT e
= es
->selection_end
;
2049 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2050 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2051 INT x
= (short)LOWORD(pos
);
2052 INT y
= (short)HIWORD(pos
);
2054 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
2057 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2058 EDIT_EM_ScrollCaret(es
);
2062 /*********************************************************************
2067 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
2069 BOOL after_wrap
= FALSE
;
2072 /* Pass a high value in x to make sure of receiving the end of the line */
2073 if (es
->style
& ES_MULTILINE
)
2074 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2075 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2077 e
= get_text_length(es
);
2078 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2079 EDIT_EM_ScrollCaret(es
);
2083 /*********************************************************************
2085 * EDIT_MoveEndOfText
2087 * Handler for Ctrl+End. Move to end of text. Only for multiline.
2090 static void EDIT_MoveEndOfText(EDITSTATE
*es
, BOOL extend
)
2092 BOOL after_wrap
= FALSE
;
2095 assert(es
->style
& ES_MULTILINE
);
2097 /* Just give it impossible high x&y to get the index of the last char */
2098 e
= EDIT_CharFromPos(es
, 0x3fffffff, 0x3fffffff, &after_wrap
);
2100 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2101 EDIT_EM_ScrollCaret(es
);
2105 /*********************************************************************
2110 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2112 INT e
= es
->selection_end
;
2116 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2117 if (es
->text
[e
] == '\n')
2119 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2123 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2124 EDIT_EM_ScrollCaret(es
);
2128 /*********************************************************************
2130 * EDIT_MoveStartOfText
2132 * Handler for Ctr+Home. Move to start of text. Only for multiline.
2135 static void EDIT_MoveStartOfText(EDITSTATE
*es
, BOOL extend
)
2137 BOOL after_wrap
= FALSE
;
2139 assert(es
->style
& ES_MULTILINE
);
2141 /* use CharFromPos instead of just plain zero, to get the wrap_flag */
2142 EDIT_CharFromPos(es
, 0, 0, &after_wrap
);
2145 EDIT_EM_SetSel(es
, 0, extend
? es
->selection_end
: 0, FALSE
);
2146 EDIT_EM_ScrollCaret(es
);
2150 /*********************************************************************
2154 * Home key: move to beginning of line.
2157 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2161 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2162 if (es
->style
& ES_MULTILINE
)
2163 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2164 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2167 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2168 EDIT_EM_ScrollCaret(es
);
2172 /*********************************************************************
2174 * EDIT_MovePageDown_ML
2176 * Only for multi line controls
2177 * Move the caret one page down, on a column with the nearest
2178 * x coordinate on the screen (might be a different column).
2181 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2183 INT s
= es
->selection_start
;
2184 INT e
= es
->selection_end
;
2185 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2186 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2187 INT x
= (short)LOWORD(pos
);
2188 INT y
= (short)HIWORD(pos
);
2190 e
= EDIT_CharFromPos(es
, x
,
2191 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2195 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2196 EDIT_EM_ScrollCaret(es
);
2200 /*********************************************************************
2202 * EDIT_MovePageUp_ML
2204 * Only for multi line controls
2205 * Move the caret one page up, on a column with the nearest
2206 * x coordinate on the screen (might be a different column).
2209 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2211 INT s
= es
->selection_start
;
2212 INT e
= es
->selection_end
;
2213 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2214 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2215 INT x
= (short)LOWORD(pos
);
2216 INT y
= (short)HIWORD(pos
);
2218 e
= EDIT_CharFromPos(es
, x
,
2219 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2223 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2224 EDIT_EM_ScrollCaret(es
);
2228 /*********************************************************************
2232 * Only for multi line controls
2233 * Move the caret one line up, on a column with the nearest
2234 * x coordinate on the screen (might be a different column).
2237 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2239 INT s
= es
->selection_start
;
2240 INT e
= es
->selection_end
;
2241 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2242 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2243 INT x
= (short)LOWORD(pos
);
2244 INT y
= (short)HIWORD(pos
);
2246 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2249 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2250 EDIT_EM_ScrollCaret(es
);
2254 /*********************************************************************
2256 * EDIT_MoveWordBackward
2259 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2261 INT s
= es
->selection_start
;
2262 INT e
= es
->selection_end
;
2267 l
= EDIT_EM_LineFromChar(es
, e
);
2268 ll
= EDIT_EM_LineLength(es
, e
);
2269 li
= EDIT_EM_LineIndex(es
, l
);
2272 li
= EDIT_EM_LineIndex(es
, l
- 1);
2273 e
= li
+ EDIT_EM_LineLength(es
, li
);
2276 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2277 li
, e
- li
, ll
, WB_LEFT
);
2281 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2282 EDIT_EM_ScrollCaret(es
);
2286 /*********************************************************************
2288 * EDIT_MoveWordForward
2291 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2293 INT s
= es
->selection_start
;
2294 INT e
= es
->selection_end
;
2299 l
= EDIT_EM_LineFromChar(es
, e
);
2300 ll
= EDIT_EM_LineLength(es
, e
);
2301 li
= EDIT_EM_LineIndex(es
, l
);
2303 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2304 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2306 e
= li
+ EDIT_CallWordBreakProc(es
,
2307 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2311 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2312 EDIT_EM_ScrollCaret(es
);
2316 /*********************************************************************
2321 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2323 INT s
= es
->selection_start
;
2324 INT e
= es
->selection_end
;
2331 if (es
->style
& ES_MULTILINE
) {
2332 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2333 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2338 TRACE("line=%d\n", line
);
2340 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2341 x
= (short)LOWORD(pos
);
2342 y
= (short)HIWORD(pos
);
2343 li
= EDIT_EM_LineIndex(es
, line
);
2344 ll
= EDIT_EM_LineLength(es
, li
);
2345 s
= min(es
->selection_start
, es
->selection_end
);
2346 e
= max(es
->selection_start
, es
->selection_end
);
2347 s
= min(li
+ ll
, max(li
, s
));
2348 e
= min(li
+ ll
, max(li
, e
));
2349 if (rev
&& (s
!= e
) &&
2350 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2351 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2352 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2353 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2355 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2359 /*********************************************************************
2364 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2368 LOGFONTW underline_font
;
2369 HFONT hUnderline
= 0;
2378 BkMode
= GetBkMode(dc
);
2379 BkColor
= GetBkColor(dc
);
2380 TextColor
= GetTextColor(dc
);
2382 if (es
->composition_len
== 0)
2384 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2385 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2386 SetBkMode( dc
, OPAQUE
);
2390 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2391 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2392 underline_font
.lfUnderline
= TRUE
;
2393 hUnderline
= CreateFontIndirectW(&underline_font
);
2394 old_font
= SelectObject(dc
,hUnderline
);
2397 li
= EDIT_EM_LineIndex(es
, line
);
2398 if (es
->style
& ES_MULTILINE
) {
2399 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2400 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2402 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2403 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2404 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2406 if (es
->style
& ES_PASSWORD
)
2407 HeapFree(GetProcessHeap(), 0, text
);
2410 if (es
->composition_len
== 0)
2412 SetBkColor(dc
, BkColor
);
2413 SetTextColor(dc
, TextColor
);
2414 SetBkMode( dc
, BkMode
);
2419 SelectObject(dc
,old_font
);
2421 DeleteObject(hUnderline
);
2428 /*********************************************************************
2433 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2436 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2437 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2438 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2442 /*********************************************************************
2444 * EDIT_AdjustFormatRect
2446 * Adjusts the format rectangle for the current font and the
2447 * current client rectangle.
2450 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2454 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2455 if (es
->style
& ES_MULTILINE
)
2457 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2459 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2460 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2462 /* correct es->x_offset */
2463 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2464 max_x_offset
= es
->text_width
- fw
;
2465 if(max_x_offset
< 0) max_x_offset
= 0;
2466 if(es
->x_offset
> max_x_offset
)
2467 es
->x_offset
= max_x_offset
;
2469 /* correct es->y_offset */
2470 max_y_offset
= es
->line_count
- vlc
;
2471 if(max_y_offset
< 0) max_y_offset
= 0;
2472 if(es
->y_offset
> max_y_offset
)
2473 es
->y_offset
= max_y_offset
;
2475 /* force scroll info update */
2476 EDIT_UpdateScrollInfo(es
);
2479 /* Windows doesn't care to fix text placement for SL controls */
2480 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2482 /* Always stay within the client area */
2483 GetClientRect(es
->hwndSelf
, &ClientRect
);
2484 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2486 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2487 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2489 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2493 /*********************************************************************
2497 * note: this is not (exactly) the handler called on EM_SETRECTNP
2498 * it is also used to set the rect of a single line control
2501 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2505 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2507 CopyRect(&es
->format_rect
, rc
);
2509 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2510 es
->format_rect
.left
++;
2511 es
->format_rect
.right
--;
2513 if (es
->format_rect
.bottom
- es
->format_rect
.top
2514 >= es
->line_height
+ 2)
2516 es
->format_rect
.top
++;
2517 es
->format_rect
.bottom
--;
2520 else if (es
->style
& WS_BORDER
) {
2521 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2522 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2523 es
->format_rect
.left
+= bw
;
2524 es
->format_rect
.right
-= bw
;
2525 if (es
->format_rect
.bottom
- es
->format_rect
.top
2526 >= es
->line_height
+ 2 * bh
)
2528 es
->format_rect
.top
+= bh
;
2529 es
->format_rect
.bottom
-= bh
;
2533 es
->format_rect
.left
+= es
->left_margin
;
2534 es
->format_rect
.right
-= es
->right_margin
;
2535 EDIT_AdjustFormatRect(es
);
2539 /*********************************************************************
2544 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2547 /* Edit window might be already destroyed */
2548 if(!IsWindow(es
->hwndSelf
))
2550 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2554 if (!es
->lock_count
) {
2555 ERR("lock_count == 0 ... please report\n");
2559 ERR("es->text == 0 ... please report\n");
2563 if (force
|| (es
->lock_count
== 1)) {
2567 UINT countW
= get_text_length(es
) + 1;
2569 STACK16FRAME
* stack16
= NULL
;
2575 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2576 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2577 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2578 countA
= LocalSize(es
->hloc32A
);
2579 if(countA_new
> countA
)
2582 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2583 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2584 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2587 es
->hloc32A
= hloc32A_new
;
2588 countA
= LocalSize(hloc32A_new
);
2589 TRACE("Real new size %d bytes\n", countA
);
2592 WARN("FAILED! Will synchronize partially\n");
2594 textA
= LocalLock(es
->hloc32A
);
2599 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2600 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2601 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2602 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2603 if(countA_new
> countA
)
2605 HLOCAL16 hloc16_new
;
2606 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2607 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2608 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2611 es
->hloc16
= hloc16_new
;
2612 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2613 TRACE("Real new size %d bytes\n", countA
);
2616 WARN("FAILED! Will synchronize partially\n");
2618 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2625 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2628 LOCAL_Unlock(hInstance
, es
->hloc16
);
2631 LocalUnlock(es
->hloc32A
);
2634 LocalUnlock(es
->hloc32W
);
2638 ERR("no buffer ... please report\n");
2646 /*********************************************************************
2648 * EDIT_UpdateScrollInfo
2651 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2653 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2656 si
.cbSize
= sizeof(SCROLLINFO
);
2657 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2659 si
.nMax
= es
->line_count
- 1;
2660 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2661 si
.nPos
= es
->y_offset
;
2662 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2663 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2664 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2667 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2670 si
.cbSize
= sizeof(SCROLLINFO
);
2671 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2673 si
.nMax
= es
->text_width
- 1;
2674 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2675 si
.nPos
= es
->x_offset
;
2676 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2677 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2678 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2682 /*********************************************************************
2684 * EDIT_WordBreakProc
2686 * Find the beginning of words.
2687 * Note: unlike the specs for a WordBreakProc, this function only
2688 * allows to be called without linebreaks between s[0] up to
2689 * s[count - 1]. Remember it is only called
2690 * internally, so we can decide this for ourselves.
2693 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2697 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2707 if (s
[index
] == ' ') {
2708 while (index
&& (s
[index
] == ' '))
2711 while (index
&& (s
[index
] != ' '))
2713 if (s
[index
] == ' ')
2717 while (index
&& (s
[index
] != ' '))
2719 if (s
[index
] == ' ')
2729 if (s
[index
] == ' ')
2730 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2732 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2734 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2738 case WB_ISDELIMITER
:
2739 ret
= (s
[index
] == ' ');
2742 ERR("unknown action code, please report !\n");
2749 /*********************************************************************
2753 * returns line number (not index) in high-order word of result.
2754 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2755 * to Richedit, not to the edit control. Original documentation is valid.
2756 * FIXME: do the specs mean to return -1 if outside client area or
2757 * if outside formatting rectangle ???
2760 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2768 GetClientRect(es
->hwndSelf
, &rc
);
2769 if (!PtInRect(&rc
, pt
))
2772 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2773 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2777 /*********************************************************************
2781 * Enable or disable soft breaks.
2783 * This means: insert or remove the soft linebreak character (\r\r\n).
2784 * Take care to check if the text still fits the buffer after insertion.
2785 * If not, notify with EN_ERRSPACE.
2788 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2790 es
->flags
&= ~EF_USE_SOFTBRK
;
2792 es
->flags
|= EF_USE_SOFTBRK
;
2793 FIXME("soft break enabled, not implemented\n");
2799 /*********************************************************************
2803 * Hopefully this won't fire back at us.
2804 * We always start with a fixed buffer in the local heap.
2805 * Despite of the documentation says that the local heap is used
2806 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2807 * buffer on the local heap.
2810 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2814 if (!(es
->style
& ES_MULTILINE
))
2818 hLocal
= es
->hloc32W
;
2824 UINT countA
, alloc_size
;
2825 TRACE("Allocating 32-bit ANSI alias buffer\n");
2826 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2827 alloc_size
= ROUND_TO_GROW(countA
);
2828 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2830 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2833 textA
= LocalLock(es
->hloc32A
);
2834 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2835 LocalUnlock(es
->hloc32A
);
2837 hLocal
= es
->hloc32A
;
2840 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2846 /*********************************************************************
2850 * Hopefully this won't fire back at us.
2851 * We always start with a buffer in 32 bit linear memory.
2852 * However, with this message a 16 bit application requests
2853 * a handle of 16 bit local heap memory, where it expects to find
2855 * It's a pitty that from this moment on we have to use this
2856 * local heap, because applications may rely on the handle
2859 * In this function we'll try to switch to local heap.
2861 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2863 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2865 UINT countA
, alloc_size
;
2867 if (!(es
->style
& ES_MULTILINE
))
2873 if (!LOCAL_HeapSize(hInstance
)) {
2874 if (!LocalInit16(hInstance
, 0,
2875 GlobalSize16(hInstance
))) {
2876 ERR("could not initialize local heap\n");
2879 TRACE("local heap initialized\n");
2882 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2883 alloc_size
= ROUND_TO_GROW(countA
);
2885 TRACE("Allocating 16-bit ANSI alias buffer\n");
2886 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2887 ERR("could not allocate new 16 bit buffer\n");
2891 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2892 ERR("could not lock new 16 bit buffer\n");
2893 LOCAL_Free(hInstance
, es
->hloc16
);
2898 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2899 LOCAL_Unlock(hInstance
, es
->hloc16
);
2901 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2907 /*********************************************************************
2912 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2915 INT line_len
, dst_len
;
2918 if (es
->style
& ES_MULTILINE
) {
2919 if (line
>= es
->line_count
)
2923 i
= EDIT_EM_LineIndex(es
, line
);
2925 line_len
= EDIT_EM_LineLength(es
, i
);
2926 dst_len
= *(WORD
*)dst
;
2929 if(dst_len
<= line_len
)
2931 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2934 else /* Append 0 if enough space */
2936 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2943 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2944 if(!ret
&& line_len
) /* Insufficient buffer size */
2946 if(ret
< dst_len
) /* Append 0 if enough space */
2947 ((LPSTR
)dst
)[ret
] = 0;
2953 /*********************************************************************
2958 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2960 UINT s
= es
->selection_start
;
2961 UINT e
= es
->selection_end
;
2968 return MAKELONG(s
, e
);
2972 /*********************************************************************
2976 * FIXME: is this right ? (or should it be only VSCROLL)
2977 * (and maybe only for edit controls that really have their
2978 * own scrollbars) (and maybe only for multiline controls ?)
2979 * All in all: very poorly documented
2982 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2985 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
2986 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
2988 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2989 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2994 /*********************************************************************
2999 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
3004 if (!(es
->style
& ES_MULTILINE
))
3006 if (index
> (INT
)get_text_length(es
))
3007 return es
->line_count
- 1;
3009 index
= min(es
->selection_start
, es
->selection_end
);
3012 line_def
= es
->first_line_def
;
3013 index
-= line_def
->length
;
3014 while ((index
>= 0) && line_def
->next
) {
3016 line_def
= line_def
->next
;
3017 index
-= line_def
->length
;
3023 /*********************************************************************
3028 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
3033 if (!(es
->style
& ES_MULTILINE
))
3035 if (line
>= es
->line_count
)
3039 line_def
= es
->first_line_def
;
3041 INT index
= es
->selection_end
- line_def
->length
;
3042 while ((index
>= 0) && line_def
->next
) {
3043 line_index
+= line_def
->length
;
3044 line_def
= line_def
->next
;
3045 index
-= line_def
->length
;
3049 line_index
+= line_def
->length
;
3050 line_def
= line_def
->next
;
3058 /*********************************************************************
3063 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
3067 if (!(es
->style
& ES_MULTILINE
))
3068 return get_text_length(es
);
3071 /* get the number of remaining non-selected chars of selected lines */
3072 INT32 l
; /* line number */
3073 INT32 li
; /* index of first char in line */
3075 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
3076 /* # chars before start of selection area */
3077 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
3078 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3079 /* # chars after end of selection */
3080 li
= EDIT_EM_LineIndex(es
, l
);
3081 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
3084 line_def
= es
->first_line_def
;
3085 index
-= line_def
->length
;
3086 while ((index
>= 0) && line_def
->next
) {
3087 line_def
= line_def
->next
;
3088 index
-= line_def
->length
;
3090 return line_def
->net_length
;
3094 /*********************************************************************
3098 * NOTE: dx is in average character widths, dy - in lines;
3101 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
3103 if (!(es
->style
& ES_MULTILINE
))
3106 dx
*= es
->char_width
;
3107 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3110 /*********************************************************************
3112 * EDIT_EM_LineScroll_internal
3114 * Version of EDIT_EM_LineScroll for internal use.
3115 * It doesn't refuse if ES_MULTILINE is set and assumes that
3116 * dx is in pixels, dy - in lines.
3119 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3122 INT x_offset_in_pixels
;
3123 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3126 if (es
->style
& ES_MULTILINE
)
3128 x_offset_in_pixels
= es
->x_offset
;
3133 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3136 if (-dx
> x_offset_in_pixels
)
3137 dx
= -x_offset_in_pixels
;
3138 if (dx
> es
->text_width
- x_offset_in_pixels
)
3139 dx
= es
->text_width
- x_offset_in_pixels
;
3140 nyoff
= max(0, es
->y_offset
+ dy
);
3141 if (nyoff
>= es
->line_count
- lines_per_page
)
3142 nyoff
= max(0, es
->line_count
- lines_per_page
);
3143 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3148 es
->y_offset
= nyoff
;
3149 if(es
->style
& ES_MULTILINE
)
3152 es
->x_offset
+= dx
/ es
->char_width
;
3154 GetClientRect(es
->hwndSelf
, &rc1
);
3155 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3156 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3157 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3158 /* force scroll info update */
3159 EDIT_UpdateScrollInfo(es
);
3161 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3162 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3163 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3164 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3169 /*********************************************************************
3174 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3176 INT len
= get_text_length(es
);
3189 index
= min(index
, len
);
3190 dc
= GetDC(es
->hwndSelf
);
3192 old_font
= SelectObject(dc
, es
->font
);
3193 if (es
->style
& ES_MULTILINE
) {
3194 l
= EDIT_EM_LineFromChar(es
, index
);
3195 y
= (l
- es
->y_offset
) * es
->line_height
;
3196 li
= EDIT_EM_LineIndex(es
, l
);
3197 if (after_wrap
&& (li
== index
) && l
) {
3199 line_def
= es
->first_line_def
;
3201 line_def
= line_def
->next
;
3204 if (line_def
->ending
== END_WRAP
) {
3206 y
-= es
->line_height
;
3207 li
= EDIT_EM_LineIndex(es
, l
);
3211 line_def
= es
->first_line_def
;
3212 while (line_def
->index
!= li
)
3213 line_def
= line_def
->next
;
3215 ll
= line_def
->net_length
;
3216 lw
= line_def
->width
;
3218 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3219 if (es
->style
& ES_RIGHT
)
3221 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3222 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3225 else if (es
->style
& ES_CENTER
)
3227 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3228 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3233 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3234 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3237 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3238 if (index
< es
->x_offset
) {
3239 GetTextExtentPoint32W(dc
, text
+ index
,
3240 es
->x_offset
- index
, &size
);
3243 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3244 index
- es
->x_offset
, &size
);
3247 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3249 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3250 if (w
> es
->text_width
)
3252 if (es
->style
& ES_RIGHT
)
3253 x
+= w
- es
->text_width
;
3254 else if (es
->style
& ES_CENTER
)
3255 x
+= (w
- es
->text_width
) / 2;
3260 if (es
->style
& ES_PASSWORD
)
3261 HeapFree(GetProcessHeap(), 0, text
);
3263 x
+= es
->format_rect
.left
;
3264 y
+= es
->format_rect
.top
;
3266 SelectObject(dc
, old_font
);
3267 ReleaseDC(es
->hwndSelf
, dc
);
3268 return MAKELONG((INT16
)x
, (INT16
)y
);
3272 /*********************************************************************
3276 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3279 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3281 UINT strl
= strlenW(lpsz_replace
);
3282 UINT tl
= get_text_length(es
);
3293 TRACE("%s, can_undo %d, send_update %d\n",
3294 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3296 s
= es
->selection_start
;
3297 e
= es
->selection_end
;
3299 if ((s
== e
) && !strl
)
3304 size
= tl
- (e
- s
) + strl
;
3308 /* Issue the EN_MAXTEXT notification and continue with replacing text
3309 * such that buffer limit is honored. */
3310 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
3311 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3312 /* Buffer limit can be smaller than the actual length of text in combobox */
3313 if (es
->buffer_limit
< (tl
- (e
-s
)))
3316 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3319 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3323 /* there is something to be deleted */
3324 TRACE("deleting stuff.\n");
3326 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3328 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3329 buf
[bufl
] = 0; /* ensure 0 termination */
3331 strcpyW(es
->text
+ s
, es
->text
+ e
);
3332 text_buffer_changed(es
);
3335 /* there is an insertion */
3336 tl
= get_text_length(es
);
3337 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
));
3338 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3340 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3341 p
[i
] = lpsz_replace
[i
];
3342 if(es
->style
& ES_UPPERCASE
)
3343 CharUpperBuffW(p
, strl
);
3344 else if(es
->style
& ES_LOWERCASE
)
3345 CharLowerBuffW(p
, strl
);
3346 text_buffer_changed(es
);
3348 if (es
->style
& ES_MULTILINE
)
3350 INT st
= min(es
->selection_start
, es
->selection_end
);
3351 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3353 hrgn
= CreateRectRgn(0, 0, 0, 0);
3354 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3355 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3356 /* if text is too long undo all changes */
3357 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3359 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3361 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3363 text_buffer_changed(es
);
3364 EDIT_BuildLineDefs_ML(es
, s
, e
,
3365 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3368 hrgn
= CreateRectRgn(0, 0, 0, 0);
3369 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3373 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3374 EDIT_CalcLineWidth_SL(es
);
3375 /* remove chars that don't fit */
3376 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3377 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3378 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3380 EDIT_CalcLineWidth_SL(es
);
3382 text_buffer_changed(es
);
3383 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3389 utl
= strlenW(es
->undo_text
);
3390 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3391 /* undo-buffer is extended to the right */
3392 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3393 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3394 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3395 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3396 /* undo-buffer is extended to the left */
3397 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3398 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3400 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3402 es
->undo_position
= s
;
3404 /* new undo-buffer */
3405 EDIT_MakeUndoFit(es
, e
- s
);
3406 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3407 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3408 es
->undo_position
= s
;
3410 /* any deletion makes the old insertion-undo invalid */
3411 es
->undo_insert_count
= 0;
3413 EDIT_EM_EmptyUndoBuffer(es
);
3417 if ((s
== es
->undo_position
) ||
3418 ((es
->undo_insert_count
) &&
3419 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3421 * insertion is new and at delete position or
3422 * an extension to either left or right
3424 es
->undo_insert_count
+= strl
;
3426 /* new insertion undo */
3427 es
->undo_position
= s
;
3428 es
->undo_insert_count
= strl
;
3429 /* new insertion makes old delete-buffer invalid */
3430 *es
->undo_text
= '\0';
3433 EDIT_EM_EmptyUndoBuffer(es
);
3437 HeapFree(GetProcessHeap(), 0, buf
);
3441 /* If text has been deleted and we're right or center aligned then scroll rightward */
3442 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3444 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3446 if (delta
< 0 && es
->x_offset
)
3448 if (abs(delta
) > es
->x_offset
)
3451 es
->x_offset
+= delta
;
3455 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3456 es
->flags
|= EF_MODIFIED
;
3457 if (send_update
) es
->flags
|= EF_UPDATE
;
3460 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3464 EDIT_UpdateText(es
, NULL
, TRUE
);
3466 EDIT_EM_ScrollCaret(es
);
3468 /* force scroll info update */
3469 EDIT_UpdateScrollInfo(es
);
3472 if(send_update
|| (es
->flags
& EF_UPDATE
))
3474 es
->flags
&= ~EF_UPDATE
;
3475 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3480 /*********************************************************************
3485 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3489 if (!(es
->style
& ES_MULTILINE
))
3490 return (LRESULT
)FALSE
;
3500 if (es
->y_offset
< es
->line_count
- 1)
3505 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3508 if (es
->y_offset
< es
->line_count
- 1)
3509 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3512 return (LRESULT
)FALSE
;
3515 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3516 /* check if we are going to move too far */
3517 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3518 dy
= es
->line_count
- vlc
- es
->y_offset
;
3520 /* Notification is done in EDIT_EM_LineScroll */
3522 EDIT_EM_LineScroll(es
, 0, dy
);
3525 return MAKELONG((SHORT
)dy
, (BOOL
)TRUE
);
3527 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3532 /*********************************************************************
3537 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3539 if (es
->style
& ES_MULTILINE
) {
3544 INT cw
= es
->char_width
;
3549 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3550 li
= EDIT_EM_LineIndex(es
, l
);
3551 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3552 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3553 if (l
>= es
->y_offset
+ vlc
)
3554 dy
= l
- vlc
+ 1 - es
->y_offset
;
3555 if (l
< es
->y_offset
)
3556 dy
= l
- es
->y_offset
;
3557 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3558 if (x
< es
->format_rect
.left
)
3559 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3560 if (x
> es
->format_rect
.right
)
3561 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3562 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3564 /* check if we are going to move too far */
3565 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3566 dx
= es
->text_width
- ww
- es
->x_offset
;
3567 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3568 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3575 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3576 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3577 if (x
< es
->format_rect
.left
) {
3578 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3581 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3582 } while ((x
< goal
) && es
->x_offset
);
3583 /* FIXME: use ScrollWindow() somehow to improve performance */
3584 EDIT_UpdateText(es
, NULL
, TRUE
);
3585 } else if (x
> es
->format_rect
.right
) {
3587 INT len
= get_text_length(es
);
3588 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3591 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3592 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3593 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3594 /* FIXME: use ScrollWindow() somehow to improve performance */
3595 EDIT_UpdateText(es
, NULL
, TRUE
);
3599 if(es
->flags
& EF_FOCUSED
)
3600 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3604 /*********************************************************************
3608 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3611 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3613 if (!(es
->style
& ES_MULTILINE
))
3617 WARN("called with NULL handle\n");
3621 EDIT_UnlockBuffer(es
, TRUE
);
3626 LOCAL_Free(hInstance
, es
->hloc16
);
3627 es
->hloc16
= (HLOCAL16
)NULL
;
3635 LocalFree(es
->hloc32A
);
3647 countA
= LocalSize(hloc
);
3648 textA
= LocalLock(hloc
);
3649 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3650 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3652 ERR("Could not allocate new unicode buffer\n");
3655 textW
= LocalLock(hloc32W_new
);
3656 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3657 LocalUnlock(hloc32W_new
);
3661 LocalFree(es
->hloc32W
);
3663 es
->hloc32W
= hloc32W_new
;
3667 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3669 es
->flags
|= EF_APP_HAS_HANDLE
;
3670 EDIT_LockBuffer(es
);
3672 es
->x_offset
= es
->y_offset
= 0;
3673 es
->selection_start
= es
->selection_end
= 0;
3674 EDIT_EM_EmptyUndoBuffer(es
);
3675 es
->flags
&= ~EF_MODIFIED
;
3676 es
->flags
&= ~EF_UPDATE
;
3677 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3678 EDIT_UpdateText(es
, NULL
, TRUE
);
3679 EDIT_EM_ScrollCaret(es
);
3680 /* force scroll info update */
3681 EDIT_UpdateScrollInfo(es
);
3686 /*********************************************************************
3690 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3693 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3695 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3701 if (!(es
->style
& ES_MULTILINE
))
3705 WARN("called with NULL handle\n");
3709 EDIT_UnlockBuffer(es
, TRUE
);
3713 LocalFree(es
->hloc32A
);
3717 countA
= LOCAL_Size(hInstance
, hloc
);
3718 textA
= LOCAL_Lock(hInstance
, hloc
);
3719 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3720 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3722 ERR("Could not allocate new unicode buffer\n");
3725 textW
= LocalLock(hloc32W_new
);
3726 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3727 LocalUnlock(hloc32W_new
);
3728 LOCAL_Unlock(hInstance
, hloc
);
3731 LocalFree(es
->hloc32W
);
3733 es
->hloc32W
= hloc32W_new
;
3736 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3738 EDIT_LockBuffer(es
);
3740 es
->x_offset
= es
->y_offset
= 0;
3741 es
->selection_start
= es
->selection_end
= 0;
3742 EDIT_EM_EmptyUndoBuffer(es
);
3743 es
->flags
&= ~EF_MODIFIED
;
3744 es
->flags
&= ~EF_UPDATE
;
3745 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3746 EDIT_UpdateText(es
, NULL
, TRUE
);
3747 EDIT_EM_ScrollCaret(es
);
3748 /* force scroll info update */
3749 EDIT_UpdateScrollInfo(es
);
3754 /*********************************************************************
3758 * NOTE: this version currently implements WinNT limits
3761 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
3763 if (!limit
) limit
= ~0u;
3764 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
3765 es
->buffer_limit
= limit
;
3769 /*********************************************************************
3773 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3774 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3775 * margin according to the textmetrics of the current font.
3777 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3778 * of the char's width as the margin, but this is not how Windows handles this.
3779 * For all other fonts Windows sets the margins to zero.
3781 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3782 * edit control is equal to or larger than a certain size.
3783 * Interestingly if one subtracts both the left and right margins from
3784 * this size one always seems to get an even number. The extents of
3785 * the (four character) string "'**'" match this quite closely, so
3786 * we'll use this until we come up with a better idea.
3788 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3790 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3793 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3794 return sz
.cx
+ left
+ right
;
3797 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3798 WORD left
, WORD right
, BOOL repaint
)
3801 INT default_left_margin
= 0; /* in pixels */
3802 INT default_right_margin
= 0; /* in pixels */
3804 /* Set the default margins depending on the font */
3805 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3806 HDC dc
= GetDC(es
->hwndSelf
);
3807 HFONT old_font
= SelectObject(dc
, es
->font
);
3808 GetTextMetricsW(dc
, &tm
);
3809 /* The default margins are only non zero for TrueType or Vector fonts */
3810 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3813 /* This must be calculated more exactly! But how? */
3814 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3815 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3816 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3817 GetClientRect(es
->hwndSelf
, &rc
);
3818 if(rc
.right
- rc
.left
< min_size
) {
3819 default_left_margin
= es
->left_margin
;
3820 default_right_margin
= es
->right_margin
;
3823 SelectObject(dc
, old_font
);
3824 ReleaseDC(es
->hwndSelf
, dc
);
3827 if (action
& EC_LEFTMARGIN
) {
3828 es
->format_rect
.left
-= es
->left_margin
;
3829 if (left
!= EC_USEFONTINFO
)
3830 es
->left_margin
= left
;
3832 es
->left_margin
= default_left_margin
;
3833 es
->format_rect
.left
+= es
->left_margin
;
3836 if (action
& EC_RIGHTMARGIN
) {
3837 es
->format_rect
.right
+= es
->right_margin
;
3838 if (right
!= EC_USEFONTINFO
)
3839 es
->right_margin
= right
;
3841 es
->right_margin
= default_right_margin
;
3842 es
->format_rect
.right
-= es
->right_margin
;
3845 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3846 EDIT_AdjustFormatRect(es
);
3847 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3850 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3854 /*********************************************************************
3856 * EM_SETPASSWORDCHAR
3859 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3863 if (es
->style
& ES_MULTILINE
)
3866 if (es
->password_char
== c
)
3869 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3870 es
->password_char
= c
;
3872 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3873 es
->style
|= ES_PASSWORD
;
3875 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3876 es
->style
&= ~ES_PASSWORD
;
3878 EDIT_UpdateText(es
, NULL
, TRUE
);
3882 /*********************************************************************
3886 * note: unlike the specs say: the order of start and end
3887 * _is_ preserved in Windows. (i.e. start can be > end)
3888 * In other words: this handler is OK
3891 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3893 UINT old_start
= es
->selection_start
;
3894 UINT old_end
= es
->selection_end
;
3895 UINT len
= get_text_length(es
);
3897 if (start
== (UINT
)-1) {
3898 start
= es
->selection_end
;
3899 end
= es
->selection_end
;
3901 start
= min(start
, len
);
3902 end
= min(end
, len
);
3904 es
->selection_start
= start
;
3905 es
->selection_end
= end
;
3907 es
->flags
|= EF_AFTER_WRAP
;
3909 es
->flags
&= ~EF_AFTER_WRAP
;
3910 /* Compute the necessary invalidation region. */
3911 /* Note that we don't need to invalidate regions which have
3912 * "never" been selected, or those which are "still" selected.
3913 * In fact, every time we hit a selection boundary, we can
3914 * *toggle* whether we need to invalidate. Thus we can optimize by
3915 * *sorting* the interval endpoints. Let's assume that we sort them
3917 * start <= end <= old_start <= old_end
3918 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3919 * in 5 comparisons; ie it's impossible to do better than the
3921 ORDER_UINT(end
, old_end
);
3922 ORDER_UINT(start
, old_start
);
3923 ORDER_UINT(old_start
, old_end
);
3924 ORDER_UINT(start
, end
);
3925 /* Note that at this point 'end' and 'old_start' are not in order, but
3926 * start is definitely the min. and old_end is definitely the max. */
3927 if (end
!= old_start
)
3931 * ORDER_UINT32(end, old_start);
3932 * EDIT_InvalidateText(es, start, end);
3933 * EDIT_InvalidateText(es, old_start, old_end);
3934 * in place of the following if statement.
3935 * (That would complete the optimal five-comparison four-element sort.)
3937 if (old_start
> end
)
3939 EDIT_InvalidateText(es
, start
, end
);
3940 EDIT_InvalidateText(es
, old_start
, old_end
);
3944 EDIT_InvalidateText(es
, start
, old_start
);
3945 EDIT_InvalidateText(es
, end
, old_end
);
3948 else EDIT_InvalidateText(es
, start
, old_end
);
3952 /*********************************************************************
3957 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3959 if (!(es
->style
& ES_MULTILINE
))
3961 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3962 es
->tabs_count
= count
;
3966 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3967 if (es
->tabs
== NULL
)
3972 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3979 /*********************************************************************
3984 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3986 if (!(es
->style
& ES_MULTILINE
))
3989 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3990 es
->tabs_count
= count
;
3995 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3996 for (i
= 0 ; i
< count
; i
++)
3997 es
->tabs
[i
] = *tabs
++;
4004 /*********************************************************************
4006 * EM_SETWORDBREAKPROC
4009 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
4011 if (es
->word_break_proc
== wbp
)
4014 es
->word_break_proc
= wbp
;
4016 es
->word_break_proc16
= NULL
;
4019 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
4020 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
4021 EDIT_UpdateText(es
, NULL
, TRUE
);
4027 /*********************************************************************
4029 * EM_SETWORDBREAKPROC16
4032 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
4034 if (es
->word_break_proc16
== wbp
)
4037 es
->word_break_proc
= NULL
;
4038 es
->word_break_proc16
= wbp
;
4039 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
4040 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
4041 EDIT_UpdateText(es
, NULL
, TRUE
);
4047 /*********************************************************************
4052 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
4057 /* As per MSDN spec, for a single-line edit control,
4058 the return value is always TRUE */
4059 if( es
->style
& ES_READONLY
)
4060 return !(es
->style
& ES_MULTILINE
);
4062 ulength
= strlenW(es
->undo_text
);
4064 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
4068 strcpyW(utext
, es
->undo_text
);
4070 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
4071 es
->undo_insert_count
, debugstr_w(utext
));
4073 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
4074 EDIT_EM_EmptyUndoBuffer(es
);
4075 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
4076 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
4077 /* send the notification after the selection start and end are set */
4078 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4079 EDIT_EM_ScrollCaret(es
);
4080 HeapFree(GetProcessHeap(), 0, utext
);
4082 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
4083 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
4087 /* Helper function for WM_CHAR
4089 * According to an MSDN blog article titled "Just because you're a control
4090 * doesn't mean that you're necessarily inside a dialog box," multiline edit
4091 * controls without ES_WANTRETURN would attempt to detect whether it is inside
4092 * a dialog box or not.
4094 static BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
4096 if (es
->hwndParent
&& es
->hwndParent
!= GetDesktopWindow())
4098 if (GetClassLongW (es
->hwndParent
, GCW_ATOM
) == (DWORD
)MAKEINTATOM(32770))
4104 /*********************************************************************
4109 static BOOL
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
4113 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4117 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
4118 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
4121 if (es
->style
& ES_MULTILINE
) {
4122 if (es
->style
& ES_READONLY
) {
4123 EDIT_MoveHome(es
, FALSE
);
4124 EDIT_MoveDown_ML(es
, FALSE
);
4126 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4127 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4132 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4134 static const WCHAR tabW
[] = {'\t',0};
4135 if (EDIT_IsInsideDialog(es
))
4137 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4141 if (!(es
->style
& ES_READONLY
) && !control
) {
4142 if (es
->selection_start
!= es
->selection_end
)
4145 /* delete character left of caret */
4146 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4147 EDIT_MoveBackward(es
, TRUE
);
4153 if (!(es
->style
& ES_PASSWORD
))
4154 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4157 if (!(es
->style
& ES_READONLY
))
4158 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4161 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4162 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4165 if (!(es
->style
& ES_READONLY
))
4166 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
4170 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4171 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4174 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4178 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4187 /*********************************************************************
4192 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4194 if (code
|| control
)
4214 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4215 EDIT_EM_ScrollCaret(es
);
4218 ERR("unknown menu item, please report\n");
4224 /*********************************************************************
4228 * Note: the resource files resource/sysres_??.rc cannot define a
4229 * single popup menu. Hence we use a (dummy) menubar
4230 * containing the single popup menu as its first item.
4232 * FIXME: the message identifiers have been chosen arbitrarily,
4233 * hence we use MF_BYPOSITION.
4234 * We might as well use the "real" values (anybody knows ?)
4235 * The menu definition is in resources/sysres_??.rc.
4236 * Once these are OK, we better use MF_BYCOMMAND here
4237 * (as we do in EDIT_WM_Command()).
4240 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4243 HMENU menu
= LoadMenuA(User32Instance
, "EDITMENU");
4245 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4247 HMENU popup
= GetSubMenu(menu
, 0);
4248 UINT start
= es
->selection_start
;
4249 UINT end
= es
->selection_end
;
4251 ORDER_UINT(start
, end
);
4254 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4256 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4258 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4260 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4262 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4264 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4266 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4269 /* Windows places the menu at the edit's center in this case */
4270 GetClientRect(es
->hwndSelf
, &rc
);
4271 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4272 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4273 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4276 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4281 /*********************************************************************
4286 static void EDIT_WM_Copy(EDITSTATE
*es
)
4288 INT s
= min(es
->selection_start
, es
->selection_end
);
4289 INT e
= max(es
->selection_start
, es
->selection_end
);
4297 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4298 dst
= GlobalLock(hdst
);
4299 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4300 dst
[len
] = 0; /* ensure 0 termination */
4301 TRACE("%s\n", debugstr_w(dst
));
4303 OpenClipboard(es
->hwndSelf
);
4305 SetClipboardData(CF_UNICODETEXT
, hdst
);
4310 /*********************************************************************
4315 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4319 TRACE("%s\n", debugstr_w(name
));
4321 * To initialize some final structure members, we call some helper
4322 * functions. However, since the EDITSTATE is not consistent (i.e.
4323 * not fully initialized), we should be very careful which
4324 * functions can be called, and in what order.
4326 EDIT_WM_SetFont(es
, 0, FALSE
);
4327 EDIT_EM_EmptyUndoBuffer(es
);
4329 /* We need to calculate the format rect
4330 (applications may send EM_SETMARGINS before the control gets visible) */
4331 GetClientRect(es
->hwndSelf
, &clientRect
);
4332 EDIT_SetRectNP(es
, &clientRect
);
4334 if (name
&& *name
) {
4335 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4336 /* if we insert text to the editline, the text scrolls out
4337 * of the window, as the caret is placed after the insert
4338 * pos normally; thus we reset es->selection... to 0 and
4341 es
->selection_start
= es
->selection_end
= 0;
4342 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4343 * Messages are only to be sent when the USER does something to
4344 * change the contents. So I am removing this EN_CHANGE
4346 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4348 EDIT_EM_ScrollCaret(es
);
4350 /* force scroll info update */
4351 EDIT_UpdateScrollInfo(es
);
4352 /* The rule seems to return 1 here for success */
4353 /* Power Builder masked edit controls will crash */
4355 /* FIXME: is that in all cases so ? */
4360 /*********************************************************************
4365 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4370 while (LocalUnlock(es
->hloc32W
)) ;
4371 LocalFree(es
->hloc32W
);
4374 while (LocalUnlock(es
->hloc32A
)) ;
4375 LocalFree(es
->hloc32A
);
4379 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
4380 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
4381 LOCAL_Free(hInstance
, es
->hloc16
);
4385 pc
= es
->first_line_def
;
4389 HeapFree(GetProcessHeap(), 0, pc
);
4393 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4394 HeapFree(GetProcessHeap(), 0, es
);
4400 /*********************************************************************
4405 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4407 /* we do the proper erase in EDIT_WM_Paint */
4412 /*********************************************************************
4417 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4419 if(!count
) return 0;
4423 lstrcpynW(dst
, es
->text
, count
);
4424 return strlenW(dst
);
4428 LPSTR textA
= (LPSTR
)dst
;
4429 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4430 textA
[count
- 1] = 0; /* ensure 0 termination */
4431 return strlen(textA
);
4435 /*********************************************************************
4440 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4445 if (!(es
->style
& ES_MULTILINE
))
4448 if (!(es
->style
& ES_AUTOHSCROLL
))
4452 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4455 TRACE("SB_LINELEFT\n");
4457 dx
= -es
->char_width
;
4460 TRACE("SB_LINERIGHT\n");
4461 if (es
->x_offset
< es
->text_width
)
4462 dx
= es
->char_width
;
4465 TRACE("SB_PAGELEFT\n");
4467 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4470 TRACE("SB_PAGERIGHT\n");
4471 if (es
->x_offset
< es
->text_width
)
4472 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4480 TRACE("SB_RIGHT\n");
4481 if (es
->x_offset
< es
->text_width
)
4482 dx
= es
->text_width
- es
->x_offset
;
4485 TRACE("SB_THUMBTRACK %d\n", pos
);
4486 es
->flags
|= EF_HSCROLL_TRACK
;
4487 if(es
->style
& WS_HSCROLL
)
4488 dx
= pos
- es
->x_offset
;
4493 if(pos
< 0 || pos
> 100) return 0;
4494 /* Assume default scroll range 0-100 */
4495 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4496 new_x
= pos
* (es
->text_width
- fw
) / 100;
4497 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4500 case SB_THUMBPOSITION
:
4501 TRACE("SB_THUMBPOSITION %d\n", pos
);
4502 es
->flags
&= ~EF_HSCROLL_TRACK
;
4503 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4504 dx
= pos
- es
->x_offset
;
4509 if(pos
< 0 || pos
> 100) return 0;
4510 /* Assume default scroll range 0-100 */
4511 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4512 new_x
= pos
* (es
->text_width
- fw
) / 100;
4513 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4516 /* force scroll info update */
4517 EDIT_UpdateScrollInfo(es
);
4518 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4522 TRACE("SB_ENDSCROLL\n");
4525 * FIXME : the next two are undocumented !
4526 * Are we doing the right thing ?
4527 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4528 * although it's also a regular control message.
4530 case EM_GETTHUMB
: /* this one is used by NT notepad */
4536 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4537 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4540 /* Assume default scroll range 0-100 */
4541 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4542 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4544 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4548 case EM_LINESCROLL16
:
4549 TRACE("EM_LINESCROLL16\n");
4555 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4561 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4562 /* check if we are going to move too far */
4563 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4564 dx
= es
->text_width
- fw
- es
->x_offset
;
4566 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4572 /*********************************************************************
4577 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4579 HWND hLBox
= es
->hwndListBox
;
4587 hCombo
= GetParent(es
->hwndSelf
);
4591 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4593 if (key
== VK_UP
|| key
== VK_DOWN
)
4595 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4598 if (msg
== WM_KEYDOWN
|| nEUI
)
4599 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4605 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4607 /* make sure ComboLBox pops up */
4608 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4613 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4616 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4618 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4620 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4625 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4631 /*********************************************************************
4635 * Handling of special keys that don't produce a WM_CHAR
4636 * (i.e. non-printable keys) & Backspace & Delete
4639 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4644 if (GetKeyState(VK_MENU
) & 0x8000)
4647 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4648 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4653 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4658 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4659 EDIT_MoveUp_ML(es
, shift
);
4662 EDIT_MoveWordBackward(es
, shift
);
4664 EDIT_MoveBackward(es
, shift
);
4667 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4671 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4672 EDIT_MoveDown_ML(es
, shift
);
4674 EDIT_MoveWordForward(es
, shift
);
4676 EDIT_MoveForward(es
, shift
);
4679 if (control
&& (es
->style
& ES_MULTILINE
)) {
4680 EDIT_MoveStartOfText(es
, shift
);
4682 EDIT_MoveHome(es
, shift
); /* start of line */
4686 if (control
&& (es
->style
& ES_MULTILINE
)) {
4687 EDIT_MoveEndOfText(es
, shift
);
4689 EDIT_MoveEnd(es
, shift
); /* end of line */
4693 if (es
->style
& ES_MULTILINE
)
4694 EDIT_MovePageUp_ML(es
, shift
);
4696 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4699 if (es
->style
& ES_MULTILINE
)
4700 EDIT_MovePageDown_ML(es
, shift
);
4702 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4705 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4706 if (es
->selection_start
!= es
->selection_end
) {
4713 /* delete character left of caret */
4714 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4715 EDIT_MoveBackward(es
, TRUE
);
4717 } else if (control
) {
4718 /* delete to end of line */
4719 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4720 EDIT_MoveEnd(es
, TRUE
);
4723 /* delete character right of caret */
4724 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4725 EDIT_MoveForward(es
, TRUE
);
4733 if (!(es
->style
& ES_READONLY
))
4739 /* If the edit doesn't want the return send a message to the default object */
4740 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
4745 if (!EDIT_IsInsideDialog(es
)) return 1;
4748 hwndParent
= GetParent(es
->hwndSelf
);
4749 dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4750 if (HIWORD(dw
) == DC_HASDEFID
)
4752 SendMessageW( hwndParent
, WM_COMMAND
,
4753 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4754 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4757 SendMessageW( hwndParent
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndParent
, IDOK
) );
4761 if (!(es
->style
& ES_MULTILINE
))
4762 SendMessageW(GetParent(es
->hwndSelf
), WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( GetParent(es
->hwndSelf
), IDCANCEL
) );
4765 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
4772 /*********************************************************************
4777 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4779 es
->flags
&= ~EF_FOCUSED
;
4781 if(!(es
->style
& ES_NOHIDESEL
))
4782 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4783 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4788 /*********************************************************************
4792 * The caret position has been set on the WM_LBUTTONDOWN message
4795 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4798 INT e
= es
->selection_end
;
4803 es
->bCaptureState
= TRUE
;
4804 SetCapture(es
->hwndSelf
);
4806 l
= EDIT_EM_LineFromChar(es
, e
);
4807 li
= EDIT_EM_LineIndex(es
, l
);
4808 ll
= EDIT_EM_LineLength(es
, e
);
4809 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4810 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4811 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4812 EDIT_EM_ScrollCaret(es
);
4813 es
->region_posx
= es
->region_posy
= 0;
4814 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4819 /*********************************************************************
4824 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4829 es
->bCaptureState
= TRUE
;
4830 SetCapture(es
->hwndSelf
);
4831 EDIT_ConfinePoint(es
, &x
, &y
);
4832 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4833 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4834 EDIT_EM_ScrollCaret(es
);
4835 es
->region_posx
= es
->region_posy
= 0;
4836 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4838 if (!(es
->flags
& EF_FOCUSED
))
4839 SetFocus(es
->hwndSelf
);
4845 /*********************************************************************
4850 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4852 if (es
->bCaptureState
) {
4853 KillTimer(es
->hwndSelf
, 0);
4854 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4856 es
->bCaptureState
= FALSE
;
4861 /*********************************************************************
4866 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4868 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4873 /*********************************************************************
4878 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4884 /* If the mouse has been captured by process other than the edit control itself,
4885 * the windows edit controls will not select the strings with mouse move.
4887 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4891 * FIXME: gotta do some scrolling if outside client
4892 * area. Maybe reset the timer ?
4895 EDIT_ConfinePoint(es
, &x
, &y
);
4896 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4897 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4898 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4899 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4900 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4905 /*********************************************************************
4909 * See also EDIT_WM_StyleChanged
4911 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4916 TRACE("Creating %s edit control, style = %08lx\n",
4917 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4919 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4921 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4924 * Note: since the EDITSTATE has not been fully initialized yet,
4925 * we can't use any API calls that may send
4926 * WM_XXX messages before WM_NCCREATE is completed.
4929 es
->is_unicode
= unicode
;
4930 es
->style
= lpcs
->style
;
4932 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4934 es
->hwndSelf
= hwnd
;
4935 /* Save parent, which will be notified by EN_* messages */
4936 es
->hwndParent
= lpcs
->hwndParent
;
4938 if (es
->style
& ES_COMBO
)
4939 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4941 /* Number overrides lowercase overrides uppercase (at least it
4942 * does in Win95). However I'll bet that ES_NUMBER would be
4943 * invalid under Win 3.1.
4945 if (es
->style
& ES_NUMBER
) {
4946 ; /* do not override the ES_NUMBER */
4947 } else if (es
->style
& ES_LOWERCASE
) {
4948 es
->style
&= ~ES_UPPERCASE
;
4950 if (es
->style
& ES_MULTILINE
) {
4951 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4952 if (es
->style
& WS_VSCROLL
)
4953 es
->style
|= ES_AUTOVSCROLL
;
4954 if (es
->style
& WS_HSCROLL
)
4955 es
->style
|= ES_AUTOHSCROLL
;
4956 es
->style
&= ~ES_PASSWORD
;
4957 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4958 /* Confirmed - RIGHT overrides CENTER */
4959 if (es
->style
& ES_RIGHT
)
4960 es
->style
&= ~ES_CENTER
;
4961 es
->style
&= ~WS_HSCROLL
;
4962 es
->style
&= ~ES_AUTOHSCROLL
;
4965 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4966 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4967 es
->style
&= ~ES_CENTER
;
4968 es
->style
&= ~WS_HSCROLL
;
4969 es
->style
&= ~WS_VSCROLL
;
4970 if (es
->style
& ES_PASSWORD
)
4971 es
->password_char
= '*';
4974 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4975 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4977 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4979 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4981 es
->undo_buffer_size
= es
->buffer_size
;
4983 if (es
->style
& ES_MULTILINE
)
4984 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4989 * In Win95 look and feel, the WS_BORDER style is replaced by the
4990 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4991 * control a nonclient area so we don't need to draw the border.
4992 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4993 * a nonclient area and we should handle painting the border ourselves.
4995 * When making modifications please ensure that the code still works
4996 * for edit controls created directly with style 0x50800000, exStyle 0
4997 * (which should have a single pixel border)
4999 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
5000 es
->style
&= ~WS_BORDER
;
5001 else if (es
->style
& WS_BORDER
)
5002 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
5007 /*********************************************************************
5012 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
5025 BOOL rev
= es
->bEnableState
&&
5026 ((es
->flags
& EF_FOCUSED
) ||
5027 (es
->style
& ES_NOHIDESEL
));
5028 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
5030 GetClientRect(es
->hwndSelf
, &rcClient
);
5032 /* get the background brush */
5033 brush
= EDIT_NotifyCtlColor(es
, dc
);
5035 /* paint the border and the background */
5036 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5038 if(es
->style
& WS_BORDER
) {
5039 bw
= GetSystemMetrics(SM_CXBORDER
);
5040 bh
= GetSystemMetrics(SM_CYBORDER
);
5042 if(es
->style
& ES_MULTILINE
) {
5043 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
5044 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
5047 /* Draw the frame. Same code as in nonclient.c */
5048 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
5049 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
5050 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
5051 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
5052 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
5053 SelectObject(dc
, old_brush
);
5055 /* Keep the border clean */
5056 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
5057 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
5060 GetClipBox(dc
, &rc
);
5061 FillRect(dc
, &rc
, brush
);
5063 IntersectClipRect(dc
, es
->format_rect
.left
,
5064 es
->format_rect
.top
,
5065 es
->format_rect
.right
,
5066 es
->format_rect
.bottom
);
5067 if (es
->style
& ES_MULTILINE
) {
5069 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5072 old_font
= SelectObject(dc
, es
->font
);
5074 if (!es
->bEnableState
)
5075 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
5076 GetClipBox(dc
, &rcRgn
);
5077 if (es
->style
& ES_MULTILINE
) {
5078 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5079 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
5080 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
5081 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
5082 EDIT_PaintLine(es
, dc
, i
, rev
);
5085 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
5086 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
5087 EDIT_PaintLine(es
, dc
, 0, rev
);
5090 SelectObject(dc
, old_font
);
5093 EndPaint(es
->hwndSelf
, &ps
);
5097 /*********************************************************************
5102 static void EDIT_WM_Paste(EDITSTATE
*es
)
5107 /* Protect read-only edit control from modification */
5108 if(es
->style
& ES_READONLY
)
5111 OpenClipboard(es
->hwndSelf
);
5112 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
5113 src
= (LPWSTR
)GlobalLock(hsrc
);
5114 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
5117 else if (es
->style
& ES_PASSWORD
) {
5118 /* clear selected text in password edit box even with empty clipboard */
5119 const WCHAR empty_strW
[] = { 0 };
5120 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
5126 /*********************************************************************
5131 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
5133 es
->flags
|= EF_FOCUSED
;
5135 if (!(es
->style
& ES_NOHIDESEL
))
5136 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
5138 /* single line edit updates itself */
5139 if (!(es
->style
& ES_MULTILINE
))
5141 HDC hdc
= GetDC(es
->hwndSelf
);
5142 EDIT_WM_Paint(es
, hdc
);
5143 ReleaseDC(es
->hwndSelf
, hdc
);
5146 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5147 EDIT_SetCaretPos(es
, es
->selection_end
,
5148 es
->flags
& EF_AFTER_WRAP
);
5149 ShowCaret(es
->hwndSelf
);
5150 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
5154 /*********************************************************************
5158 * With Win95 look the margins are set to default font value unless
5159 * the system font (font == 0) is being set, in which case they are left
5163 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5171 dc
= GetDC(es
->hwndSelf
);
5173 old_font
= SelectObject(dc
, font
);
5174 GetTextMetricsW(dc
, &tm
);
5175 es
->line_height
= tm
.tmHeight
;
5176 es
->char_width
= tm
.tmAveCharWidth
;
5178 SelectObject(dc
, old_font
);
5179 ReleaseDC(es
->hwndSelf
, dc
);
5181 /* Reset the format rect and the margins */
5182 GetClientRect(es
->hwndSelf
, &clientRect
);
5183 EDIT_SetRectNP(es
, &clientRect
);
5184 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5185 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5187 if (es
->style
& ES_MULTILINE
)
5188 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5190 EDIT_CalcLineWidth_SL(es
);
5193 EDIT_UpdateText(es
, NULL
, TRUE
);
5194 if (es
->flags
& EF_FOCUSED
) {
5196 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5197 EDIT_SetCaretPos(es
, es
->selection_end
,
5198 es
->flags
& EF_AFTER_WRAP
);
5199 ShowCaret(es
->hwndSelf
);
5204 /*********************************************************************
5209 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5210 * The modified flag is reset. No notifications are sent.
5212 * For single-line controls, reception of WM_SETTEXT triggers:
5213 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5216 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5218 LPWSTR textW
= NULL
;
5219 if (!unicode
&& text
)
5221 LPCSTR textA
= (LPCSTR
)text
;
5222 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5223 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5225 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5229 if (es
->flags
& EF_UPDATE
)
5230 /* fixed this bug once; complain if we see it about to happen again. */
5231 ERR("SetSel may generate UPDATE message whose handler may reset "
5234 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5237 TRACE("%s\n", debugstr_w(text
));
5238 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5240 HeapFree(GetProcessHeap(), 0, textW
);
5244 static const WCHAR empty_stringW
[] = {0};
5246 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5249 es
->flags
&= ~EF_MODIFIED
;
5250 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5252 /* Send the notification after the selection start and end have been set
5253 * edit control doesn't send notification on WM_SETTEXT
5254 * if it is multiline, or it is part of combobox
5256 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5258 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5259 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5261 EDIT_EM_ScrollCaret(es
);
5262 EDIT_UpdateScrollInfo(es
);
5266 /*********************************************************************
5271 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5273 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5275 TRACE("width = %d, height = %d\n", width
, height
);
5276 SetRect(&rc
, 0, 0, width
, height
);
5277 EDIT_SetRectNP(es
, &rc
);
5278 EDIT_UpdateText(es
, NULL
, TRUE
);
5283 /*********************************************************************
5287 * This message is sent by SetWindowLong on having changed either the Style
5288 * or the extended style.
5290 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5292 * See also EDIT_WM_NCCreate
5294 * It appears that the Windows version of the edit control allows the style
5295 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5296 * style variable which will generally be different. In this function we
5297 * update the internal style based on what changed in the externally visible
5300 * Much of this content as based upon the MSDN, especially:
5301 * Platform SDK Documentation -> User Interface Services ->
5302 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5303 * Edit Control Styles
5305 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5307 if (GWL_STYLE
== which
) {
5308 DWORD style_change_mask
;
5310 /* Only a subset of changes can be applied after the control
5313 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5315 if (es
->style
& ES_MULTILINE
)
5316 style_change_mask
|= ES_WANTRETURN
;
5318 new_style
= style
->styleNew
& style_change_mask
;
5320 /* Number overrides lowercase overrides uppercase (at least it
5321 * does in Win95). However I'll bet that ES_NUMBER would be
5322 * invalid under Win 3.1.
5324 if (new_style
& ES_NUMBER
) {
5325 ; /* do not override the ES_NUMBER */
5326 } else if (new_style
& ES_LOWERCASE
) {
5327 new_style
&= ~ES_UPPERCASE
;
5330 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5331 } else if (GWL_EXSTYLE
== which
) {
5332 ; /* FIXME - what is needed here */
5334 WARN ("Invalid style change %ld\n",which
);
5340 /*********************************************************************
5345 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5347 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5348 if (EDIT_EM_CanUndo(es
))
5351 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5352 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5355 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5359 /*********************************************************************
5364 static void EDIT_WM_Timer(EDITSTATE
*es
)
5366 if (es
->region_posx
< 0) {
5367 EDIT_MoveBackward(es
, TRUE
);
5368 } else if (es
->region_posx
> 0) {
5369 EDIT_MoveForward(es
, TRUE
);
5372 * FIXME: gotta do some vertical scrolling here, like
5373 * EDIT_EM_LineScroll(hwnd, 0, 1);
5377 /*********************************************************************
5382 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5386 if (!(es
->style
& ES_MULTILINE
))
5389 if (!(es
->style
& ES_AUTOVSCROLL
))
5398 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5399 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5400 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5402 EDIT_EM_Scroll(es
, action
);
5409 TRACE("SB_BOTTOM\n");
5410 dy
= es
->line_count
- 1 - es
->y_offset
;
5413 TRACE("SB_THUMBTRACK %d\n", pos
);
5414 es
->flags
|= EF_VSCROLL_TRACK
;
5415 if(es
->style
& WS_VSCROLL
)
5416 dy
= pos
- es
->y_offset
;
5419 /* Assume default scroll range 0-100 */
5422 if(pos
< 0 || pos
> 100) return 0;
5423 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5424 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5425 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5426 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5427 es
->line_count
, es
->y_offset
, pos
, dy
);
5430 case SB_THUMBPOSITION
:
5431 TRACE("SB_THUMBPOSITION %d\n", pos
);
5432 es
->flags
&= ~EF_VSCROLL_TRACK
;
5433 if(es
->style
& WS_VSCROLL
)
5434 dy
= pos
- es
->y_offset
;
5437 /* Assume default scroll range 0-100 */
5440 if(pos
< 0 || pos
> 100) return 0;
5441 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5442 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5443 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5444 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5445 es
->line_count
, es
->y_offset
, pos
, dy
);
5449 /* force scroll info update */
5450 EDIT_UpdateScrollInfo(es
);
5451 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5455 TRACE("SB_ENDSCROLL\n");
5458 * FIXME : the next two are undocumented !
5459 * Are we doing the right thing ?
5460 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5461 * although it's also a regular control message.
5463 case EM_GETTHUMB
: /* this one is used by NT notepad */
5469 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5470 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5473 /* Assume default scroll range 0-100 */
5474 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5475 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5477 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5481 case EM_LINESCROLL16
:
5482 TRACE("EM_LINESCROLL16 %d\n", pos
);
5488 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5493 EDIT_EM_LineScroll(es
, 0, dy
);
5497 /*********************************************************************
5502 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5504 if (es
->flags
& EF_UPDATE
) {
5505 es
->flags
&= ~EF_UPDATE
;
5506 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5508 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5512 /*********************************************************************
5517 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5519 if (es
->flags
& EF_UPDATE
) {
5520 es
->flags
&= ~EF_UPDATE
;
5521 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5523 NtUserInvalidateRect(es
->hwndSelf
, rc
, bErase
);
5526 /********************************************************************
5528 * The Following code is to handle inline editing from IMEs
5531 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5534 LPWSTR lpCompStr
= NULL
;
5536 LPSTR lpCompStrAttr
= NULL
;
5539 if (!(hIMC
= ImmGetContext(hwnd
)))
5542 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5546 ImmReleaseContext(hwnd
, hIMC
);
5550 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
);
5553 ERR("Unable to allocate IME CompositionString\n");
5554 ImmReleaseContext(hwnd
,hIMC
);
5559 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
5560 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5562 if (CompFlag
& GCS_COMPATTR
)
5565 * We do not use the attributes yet. it would tell us what characters
5566 * are in transition and which are converted or decided upon
5568 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5572 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
);
5575 ERR("Unable to allocate IME Attribute String\n");
5576 HeapFree(GetProcessHeap(),0,lpCompStr
);
5577 ImmReleaseContext(hwnd
,hIMC
);
5580 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5582 lpCompStrAttr
[dwBufLenAttr
] = 0;
5585 lpCompStrAttr
= NULL
;
5588 /* check for change in composition start */
5589 if (es
->selection_end
< es
->composition_start
)
5590 es
->composition_start
= es
->selection_end
;
5592 /* replace existing selection string */
5593 es
->selection_start
= es
->composition_start
;
5595 if (es
->composition_len
> 0)
5596 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5598 es
->selection_end
= es
->selection_start
;
5600 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5601 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5603 es
->selection_start
= es
->composition_start
;
5604 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5606 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5607 HeapFree(GetProcessHeap(),0,lpCompStr
);
5608 ImmReleaseContext(hwnd
,hIMC
);
5611 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5617 if ( !(hIMC
= ImmGetContext(hwnd
)))
5620 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5623 ImmReleaseContext(hwnd
, hIMC
);
5627 lpResultStr
= HeapAlloc(GetProcessHeap(),0, dwBufLen
);
5630 ERR("Unable to alloc buffer for IME string\n");
5631 ImmReleaseContext(hwnd
, hIMC
);
5635 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, dwBufLen
);
5636 lpResultStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5638 /* check for change in composition start */
5639 if (es
->selection_end
< es
->composition_start
)
5640 es
->composition_start
= es
->selection_end
;
5642 es
->selection_start
= es
->composition_start
;
5643 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5644 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5645 es
->composition_start
= es
->selection_end
;
5646 es
->composition_len
= 0;
5648 HeapFree(GetProcessHeap(),0,lpResultStr
);
5649 ImmReleaseContext(hwnd
, hIMC
);
5652 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5654 if (CompFlag
& GCS_RESULTSTR
)
5655 EDIT_GetResultStr(hwnd
,es
);
5656 if (CompFlag
& GCS_COMPSTR
)
5657 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);