4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
57 #include "wine/winbase16.h"
58 #include "wine/winuser16.h"
59 #include "wine/unicode.h"
61 #include "user_private.h"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
65 WINE_DECLARE_DEBUG_CHANNEL(combo
);
66 WINE_DECLARE_DEBUG_CHANNEL(relay
);
68 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
69 FIXME: BTW, new specs say 65535 (do you dare ???) */
70 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
71 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
72 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
73 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
76 * extra flags for EDITSTATE.flags field
78 #define EF_MODIFIED 0x0001 /* text has been modified */
79 #define EF_FOCUSED 0x0002 /* we have input focus */
80 #define EF_UPDATE 0x0004 /* notify parent of changed state */
81 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
82 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
83 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
84 wrapped line, instead of in front of the next character */
85 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
86 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
87 the text buffer if this is clear. */
90 END_0
= 0, /* line ends with terminating '\0' character */
91 END_WRAP
, /* line is wrapped */
92 END_HARD
, /* line ends with a hard return '\r\n' */
93 END_SOFT
, /* line ends with a soft return '\r\r\n' */
94 END_RICH
/* line ends with a single '\n' */
97 typedef struct tagLINEDEF
{
98 INT length
; /* bruto length of a line in bytes */
99 INT net_length
; /* netto length of a line in visible characters */
101 INT width
; /* width of the line in pixels */
102 INT index
; /* line index into the buffer */
103 struct tagLINEDEF
*next
;
108 BOOL is_unicode
; /* how the control was created */
109 LPWSTR text
; /* the actual contents of the control */
110 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
111 UINT buffer_size
; /* the size of the buffer in characters */
112 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
113 HFONT font
; /* NULL means standard system font */
114 INT x_offset
; /* scroll offset for multi lines this is in pixels
115 for single lines it's in characters */
116 INT line_height
; /* height of a screen line in pixels */
117 INT char_width
; /* average character width in pixels */
118 DWORD style
; /* sane version of wnd->dwStyle */
119 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
120 INT undo_insert_count
; /* number of characters inserted in sequence */
121 UINT undo_position
; /* character index of the insertion and deletion */
122 LPWSTR undo_text
; /* deleted text */
123 UINT undo_buffer_size
; /* size of the deleted text buffer */
124 INT selection_start
; /* == selection_end if no selection */
125 INT selection_end
; /* == current caret position */
126 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
127 INT left_margin
; /* in pixels */
128 INT right_margin
; /* in pixels */
130 INT text_width
; /* width of the widest line in pixels for multi line controls
131 and just line width for single line controls */
132 INT region_posx
; /* Position of cursor relative to region: */
133 INT region_posy
; /* -1: to left, 0: within, 1: to right */
134 EDITWORDBREAKPROC16 word_break_proc16
;
135 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
136 INT line_count
; /* number of lines */
137 INT y_offset
; /* scroll offset in number of lines */
138 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
139 BOOL bEnableState
; /* flag keeping the enable state */
140 HWND hwndSelf
; /* the our window handle */
141 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
142 Even if parent will change, EN_* messages
143 should be sent to the first parent. */
144 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
146 * only for multi line controls
148 INT lock_count
; /* amount of re-entries in the EditWndProc */
151 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
152 HLOCAL hloc32W
; /* our unicode local memory block */
153 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
155 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
160 UINT composition_len
; /* length of composition, 0 == no composition */
161 int composition_start
; /* the character position for the composition */
165 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
166 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
168 /* used for disabled or read-only edit control */
169 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
171 { /* Notify parent which has created this edit control */ \
172 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
173 SendMessageW(es->hwndParent, WM_COMMAND, \
174 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
175 (LPARAM)(es->hwndSelf)); \
178 /*********************************************************************
185 * These functions have trivial implementations
186 * We still like to call them internally
187 * "static inline" makes them more like macro's
189 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
190 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
191 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
192 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
195 * Helper functions only valid for one type of control
197 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
198 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
199 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
200 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
201 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
202 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
203 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
205 * Helper functions valid for both single line _and_ multi line controls
207 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
208 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
209 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
210 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
211 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
212 static void EDIT_LockBuffer(EDITSTATE
*es
);
213 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
214 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
215 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
216 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
217 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
218 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
219 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
220 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
221 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
222 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
223 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
224 static void EDIT_AdjustFormatRect(EDITSTATE
*es
);
225 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
226 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
227 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
228 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
230 * EM_XXX message handlers
232 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
233 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
234 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
235 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
236 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
237 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
238 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
239 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
240 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
241 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
242 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
243 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
244 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
245 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
246 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
247 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
248 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
249 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
250 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
251 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, WORD left
, WORD right
, BOOL repaint
);
252 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
253 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
254 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
255 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
256 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
257 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
258 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
260 * WM_XXX message handlers
262 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
263 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
264 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
265 static void EDIT_WM_Copy(EDITSTATE
*es
);
266 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
267 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
268 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
269 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
270 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
271 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
272 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
273 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
274 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
275 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
276 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
277 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
278 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
279 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
280 static void EDIT_WM_Paste(EDITSTATE
*es
);
281 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
282 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
283 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
284 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
285 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
286 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
287 static void EDIT_WM_Timer(EDITSTATE
*es
);
288 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
289 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
290 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
291 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
);
293 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
294 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
296 /*********************************************************************
297 * edit class descriptor
299 const struct builtin_class_descr EDIT_builtin_class
=
302 CS_DBLCLKS
| CS_PARENTDC
, /* style */
303 EditWndProcA
, /* procA */
304 EditWndProcW
, /* procW */
305 sizeof(EDITSTATE
*), /* extra */
306 IDC_IBEAM
, /* cursor */
311 /*********************************************************************
316 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
318 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
322 /*********************************************************************
327 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
329 es
->undo_insert_count
= 0;
330 *es
->undo_text
= '\0';
334 /*********************************************************************
339 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
341 static const WCHAR empty_stringW
[] = {0};
343 /* Protect read-only edit control from modification */
344 if(es
->style
& ES_READONLY
)
347 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
351 /*********************************************************************
356 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
363 /**********************************************************************
366 * Returns the window version in case Wine emulates a later version
367 * of windows than the application expects.
369 * In a number of cases when windows runs an application that was
370 * designed for an earlier windows version, windows reverts
371 * to "old" behaviour of that earlier version.
373 * An example is a disabled edit control that needs to be painted.
374 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
375 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
376 * applications with an expected version 0f 4.0 or higher.
379 static DWORD
get_app_version(void)
381 static DWORD version
;
384 DWORD dwEmulatedVersion
;
386 DWORD dwProcVersion
= GetProcessVersion(0);
388 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
389 GetVersionExW( &info
);
390 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
391 /* FIXME: this may not be 100% correct; see discussion on the
392 * wine developer list in Nov 1999 */
393 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
398 static inline UINT
get_text_length(EDITSTATE
*es
)
400 if(es
->text_length
== (UINT
)-1)
401 es
->text_length
= strlenW(es
->text
);
402 return es
->text_length
;
405 static inline void text_buffer_changed(EDITSTATE
*es
)
407 es
->text_length
= (UINT
)-1;
410 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
415 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
416 msg
= WM_CTLCOLORSTATIC
;
418 msg
= WM_CTLCOLOREDIT
;
420 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
421 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
423 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
427 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
430 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
432 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
435 /*********************************************************************
439 * The messages are in the order of the actual integer values
440 * (which can be found in include/windows.h)
441 * Wherever possible the 16 bit versions are converted to
442 * the 32 bit ones, so that we can 'fall through' to the
443 * helper functions. These are mostly 32 bit (with a few
444 * exceptions, clearly indicated by a '16' extension to their
448 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
449 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
451 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
454 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
456 if (!es
&& msg
!= WM_NCCREATE
)
457 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
459 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
467 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
471 if ((short)LOWORD(lParam
) == -1)
472 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
474 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
476 EDIT_EM_ScrollCaret(es
);
480 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
481 EDIT_EM_ScrollCaret(es
);
488 RECT16
*r16
= MapSL(lParam
);
489 r16
->left
= es
->format_rect
.left
;
490 r16
->top
= es
->format_rect
.top
;
491 r16
->right
= es
->format_rect
.right
;
492 r16
->bottom
= es
->format_rect
.bottom
;
497 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
501 if ((es
->style
& ES_MULTILINE
) && lParam
) {
503 RECT16
*r16
= MapSL(lParam
);
506 rc
.right
= r16
->right
;
507 rc
.bottom
= r16
->bottom
;
508 EDIT_SetRectNP(es
, &rc
);
509 EDIT_UpdateText(es
, NULL
, TRUE
);
513 if ((es
->style
& ES_MULTILINE
) && lParam
) {
514 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
515 EDIT_UpdateText(es
, NULL
, TRUE
);
520 if ((es
->style
& ES_MULTILINE
) && lParam
) {
522 RECT16
*r16
= MapSL(lParam
);
525 rc
.right
= r16
->right
;
526 rc
.bottom
= r16
->bottom
;
527 EDIT_SetRectNP(es
, &rc
);
531 if ((es
->style
& ES_MULTILINE
) && lParam
)
532 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
537 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
540 case EM_LINESCROLL16
:
541 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
542 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
545 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
548 case EM_SCROLLCARET16
:
550 EDIT_EM_ScrollCaret(es
);
556 result
= ((es
->flags
& EF_MODIFIED
) != 0);
562 es
->flags
|= EF_MODIFIED
;
564 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
567 case EM_GETLINECOUNT16
:
568 case EM_GETLINECOUNT
:
569 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
573 if ((INT16
)wParam
== -1)
577 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
581 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
584 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
588 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
591 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
596 result
= EDIT_EM_GetThumb(es
);
599 /* these messages missing from specs */
608 FIXME("undocumented message 0x%x, please report\n", msg
);
609 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
612 case EM_LINELENGTH16
:
614 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
617 case EM_REPLACESEL16
:
618 lParam
= (LPARAM
)MapSL(lParam
);
619 unicode
= FALSE
; /* 16-bit message is always ascii */
626 textW
= (LPWSTR
)lParam
;
629 LPSTR textA
= (LPSTR
)lParam
;
630 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
631 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
632 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
635 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
639 HeapFree(GetProcessHeap(), 0, textW
);
644 lParam
= (LPARAM
)MapSL(lParam
);
645 unicode
= FALSE
; /* 16-bit message is always ascii */
648 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
652 case EM_SETLIMITTEXT
:
653 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
658 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
664 result
= (LRESULT
)EDIT_EM_Undo(es
);
669 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
672 case EM_LINEFROMCHAR16
:
673 case EM_LINEFROMCHAR
:
674 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
677 case EM_SETTABSTOPS16
:
678 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
681 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
684 case EM_SETPASSWORDCHAR16
:
685 unicode
= FALSE
; /* 16-bit message is always ascii */
687 case EM_SETPASSWORDCHAR
:
692 charW
= (WCHAR
)wParam
;
696 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
699 EDIT_EM_SetPasswordChar(es
, charW
);
703 case EM_EMPTYUNDOBUFFER16
:
704 case EM_EMPTYUNDOBUFFER
:
705 EDIT_EM_EmptyUndoBuffer(es
);
708 case EM_GETFIRSTVISIBLELINE16
:
709 result
= es
->y_offset
;
711 case EM_GETFIRSTVISIBLELINE
:
712 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
715 case EM_SETREADONLY16
:
718 SetWindowLongW( hwnd
, GWL_STYLE
,
719 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
720 es
->style
|= ES_READONLY
;
722 SetWindowLongW( hwnd
, GWL_STYLE
,
723 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
724 es
->style
&= ~ES_READONLY
;
729 case EM_SETWORDBREAKPROC16
:
730 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
732 case EM_SETWORDBREAKPROC
:
733 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
736 case EM_GETWORDBREAKPROC16
:
737 result
= (LRESULT
)es
->word_break_proc16
;
739 case EM_GETWORDBREAKPROC
:
740 result
= (LRESULT
)es
->word_break_proc
;
743 case EM_GETPASSWORDCHAR16
:
744 unicode
= FALSE
; /* 16-bit message is always ascii */
746 case EM_GETPASSWORDCHAR
:
749 result
= es
->password_char
;
752 WCHAR charW
= es
->password_char
;
754 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
760 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
763 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
767 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
770 case EM_GETLIMITTEXT
:
771 result
= es
->buffer_limit
;
775 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
776 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
780 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
783 /* End of the EM_ messages which were in numerical order; what order
784 * are these in? vaguely alphabetical?
788 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
792 result
= EDIT_WM_Destroy(es
);
797 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
799 if (es
->style
& ES_MULTILINE
)
801 result
|= DLGC_WANTALLKEYS
;
805 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
807 int vk
= (int)((LPMSG
)lParam
)->wParam
;
809 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
811 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
812 result
|= DLGC_WANTMESSAGE
;
823 strng
[0] = wParam
>> 8;
824 strng
[1] = wParam
& 0xff;
825 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
826 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
827 EDIT_WM_Char(es
, charW
);
840 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
843 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
845 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
846 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
849 EDIT_WM_Char(es
, charW
);
858 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
862 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
871 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
874 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
878 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
879 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
880 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
882 result
= EDIT_WM_Create(es
, nameW
);
883 HeapFree(GetProcessHeap(), 0, nameW
);
892 es
->bEnableState
= (BOOL
) wParam
;
893 EDIT_UpdateText(es
, NULL
, TRUE
);
897 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
901 result
= (LRESULT
)es
->font
;
905 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
908 case WM_GETTEXTLENGTH
:
909 if (unicode
) result
= get_text_length(es
);
910 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
911 NULL
, 0, NULL
, NULL
);
915 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
919 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
923 result
= EDIT_WM_KillFocus(es
);
926 case WM_LBUTTONDBLCLK
:
927 result
= EDIT_WM_LButtonDblClk(es
);
931 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
935 result
= EDIT_WM_LButtonUp(es
);
939 result
= EDIT_WM_MButtonDown(es
);
943 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
948 EDIT_WM_Paint(es
, (HDC
)wParam
);
956 EDIT_WM_SetFocus(es
);
960 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
964 /* FIXME: actually set an internal flag and behave accordingly */
968 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
973 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
976 case WM_STYLECHANGED
:
977 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
980 case WM_STYLECHANGING
:
981 result
= 0; /* See EDIT_WM_StyleChanged */
985 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
993 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
998 int gcWheelDelta
= 0;
999 UINT pulScrollLines
= 3;
1000 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1002 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1003 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1006 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1007 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1009 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1010 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1011 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1017 /* IME messages to make the edit control IME aware */
1018 case WM_IME_SETCONTEXT
:
1021 case WM_IME_STARTCOMPOSITION
:
1023 * FIXME in IME: This message is not always sent like it should be
1025 if (es
->selection_start
!= es
->selection_end
)
1027 static const WCHAR empty_stringW
[] = {0};
1028 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1030 es
->composition_start
= es
->selection_end
;
1031 es
->composition_len
= 0;
1034 case WM_IME_COMPOSITION
:
1035 if (es
->composition_len
== 0)
1037 if (es
->selection_start
!= es
->selection_end
)
1039 static const WCHAR empty_stringW
[] = {0};
1040 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1043 es
->composition_start
= es
->selection_end
;
1045 EDIT_ImeComposition(hwnd
,lParam
,es
);
1048 case WM_IME_ENDCOMPOSITION
:
1049 es
->composition_len
= 0;
1052 case WM_IME_COMPOSITIONFULL
:
1058 case WM_IME_CONTROL
:
1062 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1066 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1068 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1073 /*********************************************************************
1075 * EditWndProcW (USER32.@)
1077 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1079 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1082 /*********************************************************************
1084 * EditWndProc (USER32.@)
1086 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1088 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1091 /*********************************************************************
1093 * EDIT_BuildLineDefs_ML
1095 * Build linked list of text lines.
1096 * Lines can end with '\0' (last line), a character (if it is wrapped),
1097 * a soft return '\r\r\n' or a hard return '\r\n'
1100 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1104 LPWSTR current_position
, cp
;
1106 LINEDEF
*current_line
;
1107 LINEDEF
*previous_line
;
1108 LINEDEF
*start_line
;
1109 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1110 INT line_count
= es
->line_count
;
1111 INT orig_net_length
;
1114 if (istart
== iend
&& delta
== 0)
1117 dc
= GetDC(es
->hwndSelf
);
1119 old_font
= SelectObject(dc
, es
->font
);
1121 previous_line
= NULL
;
1122 current_line
= es
->first_line_def
;
1124 /* Find starting line. istart must lie inside an existing line or
1125 * at the end of buffer */
1127 if (istart
< current_line
->index
+ current_line
->length
||
1128 current_line
->ending
== END_0
)
1131 previous_line
= current_line
;
1132 current_line
= current_line
->next
;
1134 } while (current_line
);
1136 if (!current_line
) /* Error occurred start is not inside previous buffer */
1138 FIXME(" modification occurred outside buffer\n");
1139 ReleaseDC(es
->hwndSelf
, dc
);
1143 /* Remember start of modifications in order to calculate update region */
1144 nstart_line
= line_index
;
1145 nstart_index
= current_line
->index
;
1147 /* We must start to reformat from the previous line since the modifications
1148 * may have caused the line to wrap upwards. */
1149 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1152 current_line
= previous_line
;
1154 start_line
= current_line
;
1156 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1157 current_position
= es
->text
+ current_line
->index
;
1159 if (current_line
!= start_line
)
1161 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1163 /* The buffer has been expanded, create a new line and
1164 insert it into the link list */
1165 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1166 new_line
->next
= previous_line
->next
;
1167 previous_line
->next
= new_line
;
1168 current_line
= new_line
;
1171 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1173 /* The previous line merged with this line so we delete this extra entry */
1174 previous_line
->next
= current_line
->next
;
1175 HeapFree(GetProcessHeap(), 0, current_line
);
1176 current_line
= previous_line
->next
;
1180 else /* current_line->index + delta == current_position */
1182 if (current_position
- es
->text
> iend
)
1183 break; /* We reached end of line modifications */
1184 /* else recalulate this line */
1188 current_line
->index
= current_position
- es
->text
;
1189 orig_net_length
= current_line
->net_length
;
1191 /* Find end of line */
1192 cp
= current_position
;
1194 if (*cp
== '\n') break;
1195 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1200 /* Mark type of line termination */
1202 current_line
->ending
= END_0
;
1203 current_line
->net_length
= strlenW(current_position
);
1204 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1205 current_line
->ending
= END_SOFT
;
1206 current_line
->net_length
= cp
- current_position
- 1;
1207 } else if (*cp
== '\n') {
1208 current_line
->ending
= END_RICH
;
1209 current_line
->net_length
= cp
- current_position
;
1211 current_line
->ending
= END_HARD
;
1212 current_line
->net_length
= cp
- current_position
;
1215 /* Calculate line width */
1216 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1217 current_position
, current_line
->net_length
,
1218 es
->tabs_count
, es
->tabs
));
1220 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1221 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1222 if (current_line
->width
> fw
) {
1227 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1228 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1229 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1230 current_position
, next
, es
->tabs_count
, es
->tabs
));
1231 } while (current_line
->width
<= fw
);
1232 if (!prev
) { /* Didn't find a line break so force a break */
1237 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1238 current_position
, next
, es
->tabs_count
, es
->tabs
));
1239 } while (current_line
->width
<= fw
);
1244 /* If the first line we are calculating, wrapped before istart, we must
1245 * adjust istart in order for this to be reflected in the update region. */
1246 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1247 istart
= current_line
->index
+ prev
;
1248 /* else if we are updating the previous line before the first line we
1249 * are re-calculating and it expanded */
1250 else if (current_line
== start_line
&&
1251 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1253 /* Line expanded due to an upwards line wrap so we must partially include
1254 * previous line in update region */
1255 nstart_line
= line_index
;
1256 nstart_index
= current_line
->index
;
1257 istart
= current_line
->index
+ orig_net_length
;
1260 current_line
->net_length
= prev
;
1261 current_line
->ending
= END_WRAP
;
1262 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1263 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1265 else if (orig_net_length
< current_line
->net_length
&&
1266 current_line
== start_line
&&
1267 current_line
->index
!= nstart_index
) {
1268 /* The previous line expanded but it's still not as wide as the client rect */
1269 /* The expansion is due to an upwards line wrap so we must partially include
1270 it in the update region */
1271 nstart_line
= line_index
;
1272 nstart_index
= current_line
->index
;
1273 istart
= current_line
->index
+ orig_net_length
;
1278 /* Adjust length to include line termination */
1279 switch (current_line
->ending
) {
1281 current_line
->length
= current_line
->net_length
+ 3;
1284 current_line
->length
= current_line
->net_length
+ 1;
1287 current_line
->length
= current_line
->net_length
+ 2;
1291 current_line
->length
= current_line
->net_length
;
1294 es
->text_width
= max(es
->text_width
, current_line
->width
);
1295 current_position
+= current_line
->length
;
1296 previous_line
= current_line
;
1297 current_line
= current_line
->next
;
1299 } while (previous_line
->ending
!= END_0
);
1301 /* Finish adjusting line indexes by delta or remove hanging lines */
1302 if (previous_line
->ending
== END_0
)
1304 LINEDEF
*pnext
= NULL
;
1306 previous_line
->next
= NULL
;
1307 while (current_line
)
1309 pnext
= current_line
->next
;
1310 HeapFree(GetProcessHeap(), 0, current_line
);
1311 current_line
= pnext
;
1315 else if (delta
!= 0)
1317 while (current_line
)
1319 current_line
->index
+= delta
;
1320 current_line
= current_line
->next
;
1324 /* Calculate rest of modification rectangle */
1329 * We calculate two rectangles. One for the first line which may have
1330 * an indent with respect to the format rect. The other is a format-width
1331 * rectangle that spans the rest of the lines that changed or moved.
1333 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1334 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1335 rc
.bottom
= rc
.top
+ es
->line_height
;
1336 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1337 rc
.left
= es
->format_rect
.left
;
1339 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1340 es
->text
+ nstart_index
, istart
- nstart_index
,
1341 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1342 rc
.right
= es
->format_rect
.right
;
1343 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1346 rc
.left
= es
->format_rect
.left
;
1347 rc
.right
= es
->format_rect
.right
;
1349 * If lines were added or removed we must re-paint the remainder of the
1350 * lines since the remaining lines were either shifted up or down.
1352 if (line_count
< es
->line_count
) /* We added lines */
1353 rc
.bottom
= es
->line_count
* es
->line_height
;
1354 else if (line_count
> es
->line_count
) /* We removed lines */
1355 rc
.bottom
= line_count
* es
->line_height
;
1357 rc
.bottom
= line_index
* es
->line_height
;
1358 rc
.bottom
+= es
->format_rect
.top
;
1359 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1360 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1361 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1362 DeleteObject(tmphrgn
);
1366 SelectObject(dc
, old_font
);
1368 ReleaseDC(es
->hwndSelf
, dc
);
1371 /*********************************************************************
1373 * EDIT_CalcLineWidth_SL
1376 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1383 text
= EDIT_GetPasswordPointer_SL(es
);
1385 dc
= GetDC(es
->hwndSelf
);
1387 old_font
= SelectObject(dc
, es
->font
);
1389 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1392 SelectObject(dc
, old_font
);
1393 ReleaseDC(es
->hwndSelf
, dc
);
1395 if (es
->style
& ES_PASSWORD
)
1396 HeapFree(GetProcessHeap(), 0, text
);
1398 es
->text_width
= size
.cx
;
1401 /*********************************************************************
1403 * EDIT_CallWordBreakProc
1405 * Call appropriate WordBreakProc (internal or external).
1407 * Note: The "start" argument should always be an index referring
1408 * to es->text. The actual wordbreak proc might be
1409 * 16 bit, so we can't always pass any 32 bit LPSTR.
1410 * Hence we assume that es->text is the buffer that holds
1411 * the string under examination (we can decide this for ourselves).
1414 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1418 if (es
->word_break_proc16
) {
1425 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1426 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1427 segptr
= WOWGlobalLock16(hglob16
);
1428 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1429 args
[4] = SELECTOROF(segptr
);
1430 args
[3] = OFFSETOF(segptr
);
1434 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1435 ret
= LOWORD(result
);
1436 GlobalUnlock16(hglob16
);
1437 GlobalFree16(hglob16
);
1439 else if (es
->word_break_proc
)
1443 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1445 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1446 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1447 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1451 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1455 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1456 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1457 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1458 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1459 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1460 ret
= wbpA(textA
, index
, countA
, action
);
1461 HeapFree(GetProcessHeap(), 0, textA
);
1465 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1471 /*********************************************************************
1475 * Beware: This is not the function called on EM_CHARFROMPOS
1476 * The position _can_ be outside the formatting / client
1478 * The return value is only the character index
1481 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1486 INT x_high
= 0, x_low
= 0;
1488 if (es
->style
& ES_MULTILINE
) {
1489 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1491 LINEDEF
*line_def
= es
->first_line_def
;
1493 while ((line
> 0) && line_def
->next
) {
1494 line_index
+= line_def
->length
;
1495 line_def
= line_def
->next
;
1498 x
+= es
->x_offset
- es
->format_rect
.left
;
1499 if (es
->style
& ES_RIGHT
)
1500 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1501 else if (es
->style
& ES_CENTER
)
1502 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1503 if (x
>= line_def
->width
) {
1505 *after_wrap
= (line_def
->ending
== END_WRAP
);
1506 return line_index
+ line_def
->net_length
;
1510 *after_wrap
= FALSE
;
1513 dc
= GetDC(es
->hwndSelf
);
1515 old_font
= SelectObject(dc
, es
->font
);
1517 high
= line_index
+ line_def
->net_length
+ 1;
1518 while (low
< high
- 1)
1520 INT mid
= (low
+ high
) / 2;
1521 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1530 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1536 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1537 (line_def
->ending
== END_WRAP
));
1542 *after_wrap
= FALSE
;
1543 x
-= es
->format_rect
.left
;
1545 return es
->x_offset
;
1549 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1550 if (es
->style
& ES_RIGHT
)
1552 else if (es
->style
& ES_CENTER
)
1556 text
= EDIT_GetPasswordPointer_SL(es
);
1557 dc
= GetDC(es
->hwndSelf
);
1559 old_font
= SelectObject(dc
, es
->font
);
1563 INT high
= es
->x_offset
;
1564 while (low
< high
- 1)
1566 INT mid
= (low
+ high
) / 2;
1567 GetTextExtentPoint32W( dc
, text
+ mid
,
1568 es
->x_offset
- mid
, &size
);
1577 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1584 INT low
= es
->x_offset
;
1585 INT high
= get_text_length(es
) + 1;
1586 while (low
< high
- 1)
1588 INT mid
= (low
+ high
) / 2;
1589 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1590 mid
- es
->x_offset
, &size
);
1599 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1604 if (es
->style
& ES_PASSWORD
)
1605 HeapFree(GetProcessHeap(), 0, text
);
1608 SelectObject(dc
, old_font
);
1609 ReleaseDC(es
->hwndSelf
, dc
);
1614 /*********************************************************************
1618 * adjusts the point to be within the formatting rectangle
1619 * (so CharFromPos returns the nearest _visible_ character)
1622 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1624 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1625 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1629 /*********************************************************************
1633 * Calculates the bounding rectangle for a line from a starting
1634 * column to an ending column.
1637 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1639 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1641 if (es
->style
& ES_MULTILINE
)
1642 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1644 rc
->top
= es
->format_rect
.top
;
1645 rc
->bottom
= rc
->top
+ es
->line_height
;
1646 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1647 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1651 /*********************************************************************
1653 * EDIT_GetPasswordPointer_SL
1655 * note: caller should free the (optionally) allocated buffer
1658 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1660 if (es
->style
& ES_PASSWORD
) {
1661 INT len
= get_text_length(es
);
1662 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1664 while(len
) text
[--len
] = es
->password_char
;
1671 /*********************************************************************
1675 * This acts as a LocalLock16(), but it locks only once. This way
1676 * you can call it whenever you like, without unlocking.
1678 * Initially the edit control allocates a HLOCAL32 buffer
1679 * (32 bit linear memory handler). However, 16 bit application
1680 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1681 * handler). From that moment on we have to keep using this 16 bit memory
1682 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1683 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1687 static void EDIT_LockBuffer(EDITSTATE
*es
)
1689 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1690 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1695 BOOL _16bit
= FALSE
;
1701 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1702 textA
= LocalLock(es
->hloc32A
);
1703 countA
= strlen(textA
) + 1;
1707 HANDLE16 oldDS
= stack16
->ds
;
1708 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1709 stack16
->ds
= hInstance
;
1710 textA
= MapSL(LocalLock16(es
->hloc16
));
1711 stack16
->ds
= oldDS
;
1712 countA
= strlen(textA
) + 1;
1717 ERR("no buffer ... please report\n");
1724 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1725 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1726 if(countW_new
> es
->buffer_size
+ 1)
1728 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1729 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1730 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1733 es
->hloc32W
= hloc32W_new
;
1734 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1735 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1738 WARN("FAILED! Will synchronize partially\n");
1742 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1743 es
->text
= LocalLock(es
->hloc32W
);
1747 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1750 HANDLE16 oldDS
= stack16
->ds
;
1751 stack16
->ds
= hInstance
;
1752 LocalUnlock16(es
->hloc16
);
1753 stack16
->ds
= oldDS
;
1756 LocalUnlock(es
->hloc32A
);
1759 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1764 /*********************************************************************
1766 * EDIT_SL_InvalidateText
1768 * Called from EDIT_InvalidateText().
1769 * Does the job for single-line controls only.
1772 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1777 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1778 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1779 EDIT_UpdateText(es
, &rc
, TRUE
);
1783 /*********************************************************************
1785 * EDIT_ML_InvalidateText
1787 * Called from EDIT_InvalidateText().
1788 * Does the job for multi-line controls only.
1791 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1793 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1794 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1795 INT el
= EDIT_EM_LineFromChar(es
, end
);
1804 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1807 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1808 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1809 if (sl
< es
->y_offset
) {
1813 if (el
> es
->y_offset
+ vlc
) {
1814 el
= es
->y_offset
+ vlc
;
1815 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1817 GetClientRect(es
->hwndSelf
, &rc1
);
1818 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1820 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1821 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1822 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1824 EDIT_GetLineRect(es
, sl
, sc
,
1825 EDIT_EM_LineLength(es
,
1826 EDIT_EM_LineIndex(es
, sl
)),
1828 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1829 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1830 for (l
= sl
+ 1 ; l
< el
; l
++) {
1831 EDIT_GetLineRect(es
, l
, 0,
1832 EDIT_EM_LineLength(es
,
1833 EDIT_EM_LineIndex(es
, l
)),
1835 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1836 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1838 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1839 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1840 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1845 /*********************************************************************
1847 * EDIT_InvalidateText
1849 * Invalidate the text from offset start up to, but not including,
1850 * offset end. Useful for (re)painting the selection.
1851 * Regions outside the linewidth are not invalidated.
1852 * end == -1 means end == TextLength.
1853 * start and end need not be ordered.
1856 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1862 end
= get_text_length(es
);
1870 if (es
->style
& ES_MULTILINE
)
1871 EDIT_ML_InvalidateText(es
, start
, end
);
1873 EDIT_SL_InvalidateText(es
, start
, end
);
1877 /*********************************************************************
1881 * Try to fit size + 1 characters in the buffer.
1883 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1887 if (size
<= es
->buffer_size
)
1890 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1892 /* Force edit to unlock it's buffer. es->text now NULL */
1893 EDIT_UnlockBuffer(es
, TRUE
);
1896 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1897 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1898 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1899 es
->hloc32W
= hNew32W
;
1900 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1904 EDIT_LockBuffer(es
);
1906 if (es
->buffer_size
< size
) {
1907 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1908 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1911 TRACE("We now have %d+1\n", es
->buffer_size
);
1917 /*********************************************************************
1921 * Try to fit size + 1 bytes in the undo buffer.
1924 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1928 if (size
<= es
->undo_buffer_size
)
1931 TRACE("trying to ReAlloc to %d+1\n", size
);
1933 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1934 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1935 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1940 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1946 /*********************************************************************
1951 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1953 INT e
= es
->selection_end
;
1957 if ((es
->style
& ES_MULTILINE
) && e
&&
1958 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1960 if (e
&& (es
->text
[e
- 1] == '\r'))
1964 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1965 EDIT_EM_ScrollCaret(es
);
1969 /*********************************************************************
1973 * Only for multi line controls
1974 * Move the caret one line down, on a column with the nearest
1975 * x coordinate on the screen (might be a different column).
1978 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1980 INT s
= es
->selection_start
;
1981 INT e
= es
->selection_end
;
1982 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1983 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1984 INT x
= (short)LOWORD(pos
);
1985 INT y
= (short)HIWORD(pos
);
1987 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1990 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1991 EDIT_EM_ScrollCaret(es
);
1995 /*********************************************************************
2000 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
2002 BOOL after_wrap
= FALSE
;
2005 /* Pass a high value in x to make sure of receiving the end of the line */
2006 if (es
->style
& ES_MULTILINE
)
2007 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2008 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2010 e
= get_text_length(es
);
2011 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2012 EDIT_EM_ScrollCaret(es
);
2016 /*********************************************************************
2021 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2023 INT e
= es
->selection_end
;
2027 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2028 if (es
->text
[e
] == '\n')
2030 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2034 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2035 EDIT_EM_ScrollCaret(es
);
2039 /*********************************************************************
2043 * Home key: move to beginning of line.
2046 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2050 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2051 if (es
->style
& ES_MULTILINE
)
2052 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2053 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2056 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2057 EDIT_EM_ScrollCaret(es
);
2061 /*********************************************************************
2063 * EDIT_MovePageDown_ML
2065 * Only for multi line controls
2066 * Move the caret one page down, on a column with the nearest
2067 * x coordinate on the screen (might be a different column).
2070 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2072 INT s
= es
->selection_start
;
2073 INT e
= es
->selection_end
;
2074 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2075 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2076 INT x
= (short)LOWORD(pos
);
2077 INT y
= (short)HIWORD(pos
);
2079 e
= EDIT_CharFromPos(es
, x
,
2080 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2084 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2085 EDIT_EM_ScrollCaret(es
);
2089 /*********************************************************************
2091 * EDIT_MovePageUp_ML
2093 * Only for multi line controls
2094 * Move the caret one page up, on a column with the nearest
2095 * x coordinate on the screen (might be a different column).
2098 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2100 INT s
= es
->selection_start
;
2101 INT e
= es
->selection_end
;
2102 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2103 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2104 INT x
= (short)LOWORD(pos
);
2105 INT y
= (short)HIWORD(pos
);
2107 e
= EDIT_CharFromPos(es
, x
,
2108 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2112 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2113 EDIT_EM_ScrollCaret(es
);
2117 /*********************************************************************
2121 * Only for multi line controls
2122 * Move the caret one line up, on a column with the nearest
2123 * x coordinate on the screen (might be a different column).
2126 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2128 INT s
= es
->selection_start
;
2129 INT e
= es
->selection_end
;
2130 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2131 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2132 INT x
= (short)LOWORD(pos
);
2133 INT y
= (short)HIWORD(pos
);
2135 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2138 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2139 EDIT_EM_ScrollCaret(es
);
2143 /*********************************************************************
2145 * EDIT_MoveWordBackward
2148 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2150 INT s
= es
->selection_start
;
2151 INT e
= es
->selection_end
;
2156 l
= EDIT_EM_LineFromChar(es
, e
);
2157 ll
= EDIT_EM_LineLength(es
, e
);
2158 li
= EDIT_EM_LineIndex(es
, l
);
2161 li
= EDIT_EM_LineIndex(es
, l
- 1);
2162 e
= li
+ EDIT_EM_LineLength(es
, li
);
2165 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2166 li
, e
- li
, ll
, WB_LEFT
);
2170 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2171 EDIT_EM_ScrollCaret(es
);
2175 /*********************************************************************
2177 * EDIT_MoveWordForward
2180 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2182 INT s
= es
->selection_start
;
2183 INT e
= es
->selection_end
;
2188 l
= EDIT_EM_LineFromChar(es
, e
);
2189 ll
= EDIT_EM_LineLength(es
, e
);
2190 li
= EDIT_EM_LineIndex(es
, l
);
2192 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2193 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2195 e
= li
+ EDIT_CallWordBreakProc(es
,
2196 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2200 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2201 EDIT_EM_ScrollCaret(es
);
2205 /*********************************************************************
2210 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2212 INT s
= es
->selection_start
;
2213 INT e
= es
->selection_end
;
2220 if (es
->style
& ES_MULTILINE
) {
2221 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2222 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2227 TRACE("line=%d\n", line
);
2229 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2230 x
= (short)LOWORD(pos
);
2231 y
= (short)HIWORD(pos
);
2232 li
= EDIT_EM_LineIndex(es
, line
);
2233 ll
= EDIT_EM_LineLength(es
, li
);
2234 s
= min(es
->selection_start
, es
->selection_end
);
2235 e
= max(es
->selection_start
, es
->selection_end
);
2236 s
= min(li
+ ll
, max(li
, s
));
2237 e
= min(li
+ ll
, max(li
, e
));
2238 if (rev
&& (s
!= e
) &&
2239 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2240 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2241 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2242 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2244 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2248 /*********************************************************************
2253 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2257 LOGFONTW underline_font
;
2258 HFONT hUnderline
= 0;
2267 BkMode
= GetBkMode(dc
);
2268 BkColor
= GetBkColor(dc
);
2269 TextColor
= GetTextColor(dc
);
2271 if (es
->composition_len
== 0)
2273 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2274 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2275 SetBkMode( dc
, OPAQUE
);
2279 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2280 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2281 underline_font
.lfUnderline
= TRUE
;
2282 hUnderline
= CreateFontIndirectW(&underline_font
);
2283 old_font
= SelectObject(dc
,hUnderline
);
2286 li
= EDIT_EM_LineIndex(es
, line
);
2287 if (es
->style
& ES_MULTILINE
) {
2288 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2289 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2291 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2292 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2293 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2295 if (es
->style
& ES_PASSWORD
)
2296 HeapFree(GetProcessHeap(), 0, text
);
2299 if (es
->composition_len
== 0)
2301 SetBkColor(dc
, BkColor
);
2302 SetTextColor(dc
, TextColor
);
2303 SetBkMode( dc
, BkMode
);
2308 SelectObject(dc
,old_font
);
2310 DeleteObject(hUnderline
);
2317 /*********************************************************************
2322 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2325 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2326 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2327 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2331 /*********************************************************************
2333 * EDIT_AdjustFormatRect
2335 * Adjusts the format rectangle for the current font and the
2336 * current client rectangle.
2339 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2343 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2344 if (es
->style
& ES_MULTILINE
)
2346 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2348 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2349 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2351 /* correct es->x_offset */
2352 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2353 max_x_offset
= es
->text_width
- fw
;
2354 if(max_x_offset
< 0) max_x_offset
= 0;
2355 if(es
->x_offset
> max_x_offset
)
2356 es
->x_offset
= max_x_offset
;
2358 /* correct es->y_offset */
2359 max_y_offset
= es
->line_count
- vlc
;
2360 if(max_y_offset
< 0) max_y_offset
= 0;
2361 if(es
->y_offset
> max_y_offset
)
2362 es
->y_offset
= max_y_offset
;
2364 /* force scroll info update */
2365 EDIT_UpdateScrollInfo(es
);
2368 /* Windows doesn't care to fix text placement for SL controls */
2369 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2371 /* Always stay within the client area */
2372 GetClientRect(es
->hwndSelf
, &ClientRect
);
2373 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2375 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2376 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2378 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2382 /*********************************************************************
2386 * note: this is not (exactly) the handler called on EM_SETRECTNP
2387 * it is also used to set the rect of a single line control
2390 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2394 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2396 CopyRect(&es
->format_rect
, rc
);
2398 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2399 es
->format_rect
.left
++;
2400 es
->format_rect
.right
--;
2402 if (es
->format_rect
.bottom
- es
->format_rect
.top
2403 >= es
->line_height
+ 2)
2405 es
->format_rect
.top
++;
2406 es
->format_rect
.bottom
--;
2409 else if (es
->style
& WS_BORDER
) {
2410 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2411 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2412 es
->format_rect
.left
+= bw
;
2413 es
->format_rect
.right
-= bw
;
2414 if (es
->format_rect
.bottom
- es
->format_rect
.top
2415 >= es
->line_height
+ 2 * bh
)
2417 es
->format_rect
.top
+= bh
;
2418 es
->format_rect
.bottom
-= bh
;
2422 es
->format_rect
.left
+= es
->left_margin
;
2423 es
->format_rect
.right
-= es
->right_margin
;
2424 EDIT_AdjustFormatRect(es
);
2428 /*********************************************************************
2433 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2436 /* Edit window might be already destroyed */
2437 if(!IsWindow(es
->hwndSelf
))
2439 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2443 if (!es
->lock_count
) {
2444 ERR("lock_count == 0 ... please report\n");
2448 ERR("es->text == 0 ... please report\n");
2452 if (force
|| (es
->lock_count
== 1)) {
2456 UINT countW
= get_text_length(es
) + 1;
2457 STACK16FRAME
* stack16
= NULL
;
2462 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2463 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2464 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2465 countA
= LocalSize(es
->hloc32A
);
2466 if(countA_new
> countA
)
2469 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2470 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2471 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2474 es
->hloc32A
= hloc32A_new
;
2475 countA
= LocalSize(hloc32A_new
);
2476 TRACE("Real new size %d bytes\n", countA
);
2479 WARN("FAILED! Will synchronize partially\n");
2481 textA
= LocalLock(es
->hloc32A
);
2485 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2487 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2488 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2490 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2491 oldDS
= stack16
->ds
;
2492 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2494 countA
= LocalSize16(es
->hloc16
);
2495 if(countA_new
> countA
)
2497 HLOCAL16 hloc16_new
;
2498 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2499 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2500 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2503 es
->hloc16
= hloc16_new
;
2504 countA
= LocalSize16(hloc16_new
);
2505 TRACE("Real new size %d bytes\n", countA
);
2508 WARN("FAILED! Will synchronize partially\n");
2510 textA
= MapSL(LocalLock16(es
->hloc16
));
2515 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2517 LocalUnlock16(es
->hloc16
);
2519 LocalUnlock(es
->hloc32A
);
2522 if (stack16
) stack16
->ds
= oldDS
;
2523 LocalUnlock(es
->hloc32W
);
2527 ERR("no buffer ... please report\n");
2535 /*********************************************************************
2537 * EDIT_UpdateScrollInfo
2540 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2542 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2545 si
.cbSize
= sizeof(SCROLLINFO
);
2546 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2548 si
.nMax
= es
->line_count
- 1;
2549 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2550 si
.nPos
= es
->y_offset
;
2551 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2552 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2553 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2556 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2559 si
.cbSize
= sizeof(SCROLLINFO
);
2560 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2562 si
.nMax
= es
->text_width
- 1;
2563 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2564 si
.nPos
= es
->x_offset
;
2565 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2566 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2567 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2571 /*********************************************************************
2573 * EDIT_WordBreakProc
2575 * Find the beginning of words.
2576 * Note: unlike the specs for a WordBreakProc, this function only
2577 * allows to be called without linebreaks between s[0] up to
2578 * s[count - 1]. Remember it is only called
2579 * internally, so we can decide this for ourselves.
2582 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2586 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2596 if (s
[index
] == ' ') {
2597 while (index
&& (s
[index
] == ' '))
2600 while (index
&& (s
[index
] != ' '))
2602 if (s
[index
] == ' ')
2606 while (index
&& (s
[index
] != ' '))
2608 if (s
[index
] == ' ')
2618 if (s
[index
] == ' ')
2619 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2621 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2623 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2627 case WB_ISDELIMITER
:
2628 ret
= (s
[index
] == ' ');
2631 ERR("unknown action code, please report !\n");
2638 /*********************************************************************
2642 * returns line number (not index) in high-order word of result.
2643 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2644 * to Richedit, not to the edit control. Original documentation is valid.
2645 * FIXME: do the specs mean to return -1 if outside client area or
2646 * if outside formatting rectangle ???
2649 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2657 GetClientRect(es
->hwndSelf
, &rc
);
2658 if (!PtInRect(&rc
, pt
))
2661 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2662 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2666 /*********************************************************************
2670 * Enable or disable soft breaks.
2672 * This means: insert or remove the soft linebreak character (\r\r\n).
2673 * Take care to check if the text still fits the buffer after insertion.
2674 * If not, notify with EN_ERRSPACE.
2677 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2679 es
->flags
&= ~EF_USE_SOFTBRK
;
2681 es
->flags
|= EF_USE_SOFTBRK
;
2682 FIXME("soft break enabled, not implemented\n");
2688 /*********************************************************************
2692 * Hopefully this won't fire back at us.
2693 * We always start with a fixed buffer in the local heap.
2694 * Despite of the documentation says that the local heap is used
2695 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2696 * buffer on the local heap.
2699 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2703 if (!(es
->style
& ES_MULTILINE
))
2707 hLocal
= es
->hloc32W
;
2713 UINT countA
, alloc_size
;
2714 TRACE("Allocating 32-bit ANSI alias buffer\n");
2715 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2716 alloc_size
= ROUND_TO_GROW(countA
);
2717 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2719 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2722 textA
= LocalLock(es
->hloc32A
);
2723 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2724 LocalUnlock(es
->hloc32A
);
2726 hLocal
= es
->hloc32A
;
2729 es
->flags
|= EF_APP_HAS_HANDLE
;
2730 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2735 /*********************************************************************
2739 * Hopefully this won't fire back at us.
2740 * We always start with a buffer in 32 bit linear memory.
2741 * However, with this message a 16 bit application requests
2742 * a handle of 16 bit local heap memory, where it expects to find
2744 * It's a pitty that from this moment on we have to use this
2745 * local heap, because applications may rely on the handle
2748 * In this function we'll try to switch to local heap.
2750 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2753 UINT countA
, alloc_size
;
2754 STACK16FRAME
* stack16
;
2757 if (!(es
->style
& ES_MULTILINE
))
2763 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2764 oldDS
= stack16
->ds
;
2765 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2767 if (!LocalHeapSize16()) {
2769 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2770 ERR("could not initialize local heap\n");
2773 TRACE("local heap initialized\n");
2776 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2777 alloc_size
= ROUND_TO_GROW(countA
);
2779 TRACE("Allocating 16-bit ANSI alias buffer\n");
2780 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2781 ERR("could not allocate new 16 bit buffer\n");
2785 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2786 ERR("could not lock new 16 bit buffer\n");
2787 LocalFree16(es
->hloc16
);
2792 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2793 LocalUnlock16(es
->hloc16
);
2794 es
->flags
|= EF_APP_HAS_HANDLE
;
2796 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2799 stack16
->ds
= oldDS
;
2804 /*********************************************************************
2809 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2812 INT line_len
, dst_len
;
2815 if (es
->style
& ES_MULTILINE
) {
2816 if (line
>= es
->line_count
)
2820 i
= EDIT_EM_LineIndex(es
, line
);
2822 line_len
= EDIT_EM_LineLength(es
, i
);
2823 dst_len
= *(WORD
*)dst
;
2826 if(dst_len
<= line_len
)
2828 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2831 else /* Append 0 if enough space */
2833 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2840 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2841 if(!ret
&& line_len
) /* Insufficient buffer size */
2843 if(ret
< dst_len
) /* Append 0 if enough space */
2844 ((LPSTR
)dst
)[ret
] = 0;
2850 /*********************************************************************
2855 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2857 UINT s
= es
->selection_start
;
2858 UINT e
= es
->selection_end
;
2865 return MAKELONG(s
, e
);
2869 /*********************************************************************
2873 * FIXME: is this right ? (or should it be only VSCROLL)
2874 * (and maybe only for edit controls that really have their
2875 * own scrollbars) (and maybe only for multiline controls ?)
2876 * All in all: very poorly documented
2879 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2881 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2882 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2886 /*********************************************************************
2891 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2896 if (!(es
->style
& ES_MULTILINE
))
2898 if (index
> (INT
)get_text_length(es
))
2899 return es
->line_count
- 1;
2901 index
= min(es
->selection_start
, es
->selection_end
);
2904 line_def
= es
->first_line_def
;
2905 index
-= line_def
->length
;
2906 while ((index
>= 0) && line_def
->next
) {
2908 line_def
= line_def
->next
;
2909 index
-= line_def
->length
;
2915 /*********************************************************************
2920 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2925 if (!(es
->style
& ES_MULTILINE
))
2927 if (line
>= es
->line_count
)
2931 line_def
= es
->first_line_def
;
2933 INT index
= es
->selection_end
- line_def
->length
;
2934 while ((index
>= 0) && line_def
->next
) {
2935 line_index
+= line_def
->length
;
2936 line_def
= line_def
->next
;
2937 index
-= line_def
->length
;
2941 line_index
+= line_def
->length
;
2942 line_def
= line_def
->next
;
2950 /*********************************************************************
2955 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2959 if (!(es
->style
& ES_MULTILINE
))
2960 return get_text_length(es
);
2963 /* get the number of remaining non-selected chars of selected lines */
2964 INT32 l
; /* line number */
2965 INT32 li
; /* index of first char in line */
2967 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2968 /* # chars before start of selection area */
2969 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2970 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2971 /* # chars after end of selection */
2972 li
= EDIT_EM_LineIndex(es
, l
);
2973 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2976 line_def
= es
->first_line_def
;
2977 index
-= line_def
->length
;
2978 while ((index
>= 0) && line_def
->next
) {
2979 line_def
= line_def
->next
;
2980 index
-= line_def
->length
;
2982 return line_def
->net_length
;
2986 /*********************************************************************
2990 * NOTE: dx is in average character widths, dy - in lines;
2993 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2995 if (!(es
->style
& ES_MULTILINE
))
2998 dx
*= es
->char_width
;
2999 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3002 /*********************************************************************
3004 * EDIT_EM_LineScroll_internal
3006 * Version of EDIT_EM_LineScroll for internal use.
3007 * It doesn't refuse if ES_MULTILINE is set and assumes that
3008 * dx is in pixels, dy - in lines.
3011 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3014 INT x_offset_in_pixels
;
3015 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3018 if (es
->style
& ES_MULTILINE
)
3020 x_offset_in_pixels
= es
->x_offset
;
3025 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3028 if (-dx
> x_offset_in_pixels
)
3029 dx
= -x_offset_in_pixels
;
3030 if (dx
> es
->text_width
- x_offset_in_pixels
)
3031 dx
= es
->text_width
- x_offset_in_pixels
;
3032 nyoff
= max(0, es
->y_offset
+ dy
);
3033 if (nyoff
>= es
->line_count
- lines_per_page
)
3034 nyoff
= max(0, es
->line_count
- lines_per_page
);
3035 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3040 es
->y_offset
= nyoff
;
3041 if(es
->style
& ES_MULTILINE
)
3044 es
->x_offset
+= dx
/ es
->char_width
;
3046 GetClientRect(es
->hwndSelf
, &rc1
);
3047 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3048 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3049 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3050 /* force scroll info update */
3051 EDIT_UpdateScrollInfo(es
);
3053 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3054 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3055 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3056 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3061 /*********************************************************************
3066 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3068 INT len
= get_text_length(es
);
3081 index
= min(index
, len
);
3082 dc
= GetDC(es
->hwndSelf
);
3084 old_font
= SelectObject(dc
, es
->font
);
3085 if (es
->style
& ES_MULTILINE
) {
3086 l
= EDIT_EM_LineFromChar(es
, index
);
3087 y
= (l
- es
->y_offset
) * es
->line_height
;
3088 li
= EDIT_EM_LineIndex(es
, l
);
3089 if (after_wrap
&& (li
== index
) && l
) {
3091 line_def
= es
->first_line_def
;
3093 line_def
= line_def
->next
;
3096 if (line_def
->ending
== END_WRAP
) {
3098 y
-= es
->line_height
;
3099 li
= EDIT_EM_LineIndex(es
, l
);
3103 line_def
= es
->first_line_def
;
3104 while (line_def
->index
!= li
)
3105 line_def
= line_def
->next
;
3107 ll
= line_def
->net_length
;
3108 lw
= line_def
->width
;
3110 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3111 if (es
->style
& ES_RIGHT
)
3113 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3114 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3117 else if (es
->style
& ES_CENTER
)
3119 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3120 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3125 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3126 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3129 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3130 if (index
< es
->x_offset
) {
3131 GetTextExtentPoint32W(dc
, text
+ index
,
3132 es
->x_offset
- index
, &size
);
3135 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3136 index
- es
->x_offset
, &size
);
3139 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3141 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3142 if (w
> es
->text_width
)
3144 if (es
->style
& ES_RIGHT
)
3145 x
+= w
- es
->text_width
;
3146 else if (es
->style
& ES_CENTER
)
3147 x
+= (w
- es
->text_width
) / 2;
3152 if (es
->style
& ES_PASSWORD
)
3153 HeapFree(GetProcessHeap(), 0, text
);
3155 x
+= es
->format_rect
.left
;
3156 y
+= es
->format_rect
.top
;
3158 SelectObject(dc
, old_font
);
3159 ReleaseDC(es
->hwndSelf
, dc
);
3160 return MAKELONG((INT16
)x
, (INT16
)y
);
3164 /*********************************************************************
3168 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3171 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3173 UINT strl
= strlenW(lpsz_replace
);
3174 UINT tl
= get_text_length(es
);
3185 TRACE("%s, can_undo %d, send_update %d\n",
3186 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3188 s
= es
->selection_start
;
3189 e
= es
->selection_end
;
3191 if ((s
== e
) && !strl
)
3196 size
= tl
- (e
- s
) + strl
;
3200 /* Issue the EN_MAXTEXT notification and continue with replacing text
3201 * such that buffer limit is honored. */
3202 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
3203 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3204 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3207 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3211 /* there is something to be deleted */
3212 TRACE("deleting stuff.\n");
3214 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3216 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3217 buf
[bufl
] = 0; /* ensure 0 termination */
3219 strcpyW(es
->text
+ s
, es
->text
+ e
);
3220 text_buffer_changed(es
);
3223 /* there is an insertion */
3224 tl
= get_text_length(es
);
3225 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
));
3226 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3228 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3229 p
[i
] = lpsz_replace
[i
];
3230 if(es
->style
& ES_UPPERCASE
)
3231 CharUpperBuffW(p
, strl
);
3232 else if(es
->style
& ES_LOWERCASE
)
3233 CharLowerBuffW(p
, strl
);
3234 text_buffer_changed(es
);
3236 if (es
->style
& ES_MULTILINE
)
3238 INT st
= min(es
->selection_start
, es
->selection_end
);
3239 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3241 hrgn
= CreateRectRgn(0, 0, 0, 0);
3242 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3243 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3244 /* if text is too long undo all changes */
3245 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3247 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3249 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3251 text_buffer_changed(es
);
3252 EDIT_BuildLineDefs_ML(es
, s
, e
,
3253 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3256 hrgn
= CreateRectRgn(0, 0, 0, 0);
3257 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3261 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3262 EDIT_CalcLineWidth_SL(es
);
3263 /* remove chars that don't fit */
3264 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3265 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3266 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3268 EDIT_CalcLineWidth_SL(es
);
3270 text_buffer_changed(es
);
3271 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3277 utl
= strlenW(es
->undo_text
);
3278 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3279 /* undo-buffer is extended to the right */
3280 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3281 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3282 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3283 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3284 /* undo-buffer is extended to the left */
3285 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3286 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3288 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3290 es
->undo_position
= s
;
3292 /* new undo-buffer */
3293 EDIT_MakeUndoFit(es
, e
- s
);
3294 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3295 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3296 es
->undo_position
= s
;
3298 /* any deletion makes the old insertion-undo invalid */
3299 es
->undo_insert_count
= 0;
3301 EDIT_EM_EmptyUndoBuffer(es
);
3305 if ((s
== es
->undo_position
) ||
3306 ((es
->undo_insert_count
) &&
3307 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3309 * insertion is new and at delete position or
3310 * an extension to either left or right
3312 es
->undo_insert_count
+= strl
;
3314 /* new insertion undo */
3315 es
->undo_position
= s
;
3316 es
->undo_insert_count
= strl
;
3317 /* new insertion makes old delete-buffer invalid */
3318 *es
->undo_text
= '\0';
3321 EDIT_EM_EmptyUndoBuffer(es
);
3325 HeapFree(GetProcessHeap(), 0, buf
);
3329 /* If text has been deleted and we're right or center aligned then scroll rightward */
3330 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3332 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3334 if (delta
< 0 && es
->x_offset
)
3336 if (abs(delta
) > es
->x_offset
)
3339 es
->x_offset
+= delta
;
3343 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3344 es
->flags
|= EF_MODIFIED
;
3345 if (send_update
) es
->flags
|= EF_UPDATE
;
3348 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3352 EDIT_UpdateText(es
, NULL
, TRUE
);
3354 EDIT_EM_ScrollCaret(es
);
3356 /* force scroll info update */
3357 EDIT_UpdateScrollInfo(es
);
3360 if(send_update
|| (es
->flags
& EF_UPDATE
))
3362 es
->flags
&= ~EF_UPDATE
;
3363 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3368 /*********************************************************************
3373 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3377 if (!(es
->style
& ES_MULTILINE
))
3378 return (LRESULT
)FALSE
;
3388 if (es
->y_offset
< es
->line_count
- 1)
3393 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3396 if (es
->y_offset
< es
->line_count
- 1)
3397 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3400 return (LRESULT
)FALSE
;
3403 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3404 /* check if we are going to move too far */
3405 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3406 dy
= es
->line_count
- vlc
- es
->y_offset
;
3408 /* Notification is done in EDIT_EM_LineScroll */
3410 EDIT_EM_LineScroll(es
, 0, dy
);
3412 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3416 /*********************************************************************
3421 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3423 if (es
->style
& ES_MULTILINE
) {
3428 INT cw
= es
->char_width
;
3433 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3434 li
= EDIT_EM_LineIndex(es
, l
);
3435 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3436 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3437 if (l
>= es
->y_offset
+ vlc
)
3438 dy
= l
- vlc
+ 1 - es
->y_offset
;
3439 if (l
< es
->y_offset
)
3440 dy
= l
- es
->y_offset
;
3441 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3442 if (x
< es
->format_rect
.left
)
3443 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3444 if (x
> es
->format_rect
.right
)
3445 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3446 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3448 /* check if we are going to move too far */
3449 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3450 dx
= es
->text_width
- ww
- es
->x_offset
;
3451 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3452 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3459 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3460 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3461 if (x
< es
->format_rect
.left
) {
3462 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3465 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3466 } while ((x
< goal
) && es
->x_offset
);
3467 /* FIXME: use ScrollWindow() somehow to improve performance */
3468 EDIT_UpdateText(es
, NULL
, TRUE
);
3469 } else if (x
> es
->format_rect
.right
) {
3471 INT len
= get_text_length(es
);
3472 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3475 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3476 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3477 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3478 /* FIXME: use ScrollWindow() somehow to improve performance */
3479 EDIT_UpdateText(es
, NULL
, TRUE
);
3483 if(es
->flags
& EF_FOCUSED
)
3484 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3488 /*********************************************************************
3492 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3495 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3497 if (!(es
->style
& ES_MULTILINE
))
3501 WARN("called with NULL handle\n");
3505 EDIT_UnlockBuffer(es
, TRUE
);
3509 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3510 HANDLE16 oldDS
= stack16
->ds
;
3512 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3513 LocalFree16(es
->hloc16
);
3514 stack16
->ds
= oldDS
;
3522 LocalFree(es
->hloc32A
);
3534 countA
= LocalSize(hloc
);
3535 textA
= LocalLock(hloc
);
3536 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3537 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3539 ERR("Could not allocate new unicode buffer\n");
3542 textW
= LocalLock(hloc32W_new
);
3543 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3544 LocalUnlock(hloc32W_new
);
3548 LocalFree(es
->hloc32W
);
3550 es
->hloc32W
= hloc32W_new
;
3554 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3556 es
->flags
|= EF_APP_HAS_HANDLE
;
3557 EDIT_LockBuffer(es
);
3559 es
->x_offset
= es
->y_offset
= 0;
3560 es
->selection_start
= es
->selection_end
= 0;
3561 EDIT_EM_EmptyUndoBuffer(es
);
3562 es
->flags
&= ~EF_MODIFIED
;
3563 es
->flags
&= ~EF_UPDATE
;
3564 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3565 EDIT_UpdateText(es
, NULL
, TRUE
);
3566 EDIT_EM_ScrollCaret(es
);
3567 /* force scroll info update */
3568 EDIT_UpdateScrollInfo(es
);
3572 /*********************************************************************
3576 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3579 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3581 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
3582 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3583 HANDLE16 oldDS
= stack16
->ds
;
3589 if (!(es
->style
& ES_MULTILINE
))
3593 WARN("called with NULL handle\n");
3597 EDIT_UnlockBuffer(es
, TRUE
);
3601 LocalFree(es
->hloc32A
);
3605 stack16
->ds
= hInstance
;
3606 countA
= LocalSize16(hloc
);
3607 textA
= MapSL(LocalLock16(hloc
));
3608 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3609 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3611 ERR("Could not allocate new unicode buffer\n");
3614 textW
= LocalLock(hloc32W_new
);
3615 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3616 LocalUnlock(hloc32W_new
);
3617 LocalUnlock16(hloc
);
3618 stack16
->ds
= oldDS
;
3621 LocalFree(es
->hloc32W
);
3623 es
->hloc32W
= hloc32W_new
;
3626 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3628 es
->flags
|= EF_APP_HAS_HANDLE
;
3629 EDIT_LockBuffer(es
);
3631 es
->x_offset
= es
->y_offset
= 0;
3632 es
->selection_start
= es
->selection_end
= 0;
3633 EDIT_EM_EmptyUndoBuffer(es
);
3634 es
->flags
&= ~EF_MODIFIED
;
3635 es
->flags
&= ~EF_UPDATE
;
3636 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3637 EDIT_UpdateText(es
, NULL
, TRUE
);
3638 EDIT_EM_ScrollCaret(es
);
3639 /* force scroll info update */
3640 EDIT_UpdateScrollInfo(es
);
3644 /*********************************************************************
3648 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3649 * However, the windows version is not complied to yet in all of edit.c
3651 * Additionally as the wrapper for RichEdit controls we need larger buffers
3652 * at present -1 will represent nolimit
3654 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3656 if (limit
== 0xFFFFFFFF)
3657 es
->buffer_limit
= -1;
3658 else if (es
->style
& ES_MULTILINE
) {
3660 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3662 es
->buffer_limit
= BUFLIMIT_MULTI
;
3665 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3667 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3672 /*********************************************************************
3676 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3677 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3678 * margin according to the textmetrics of the current font.
3680 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3681 * of the char's width as the margin, but this is not how Windows handles this.
3682 * For all other fonts Windows sets the margins to zero.
3684 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3685 * edit control is equal to or larger than a certain size.
3686 * Interestingly if one subtracts both the left and right margins from
3687 * this size one always seems to get an even number. The extents of
3688 * the (four character) string "'**'" match this quite closely, so
3689 * we'll use this until we come up with a better idea.
3691 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3693 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3696 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3697 return sz
.cx
+ left
+ right
;
3700 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3701 WORD left
, WORD right
, BOOL repaint
)
3704 INT default_left_margin
= 0; /* in pixels */
3705 INT default_right_margin
= 0; /* in pixels */
3707 /* Set the default margins depending on the font */
3708 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3709 HDC dc
= GetDC(es
->hwndSelf
);
3710 HFONT old_font
= SelectObject(dc
, es
->font
);
3711 GetTextMetricsW(dc
, &tm
);
3712 /* The default margins are only non zero for TrueType or Vector fonts */
3713 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3716 /* This must be calculated more exactly! But how? */
3717 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3718 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3719 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3720 GetClientRect(es
->hwndSelf
, &rc
);
3721 if(rc
.right
- rc
.left
< min_size
) {
3722 default_left_margin
= es
->left_margin
;
3723 default_right_margin
= es
->right_margin
;
3726 SelectObject(dc
, old_font
);
3727 ReleaseDC(es
->hwndSelf
, dc
);
3730 if (action
& EC_LEFTMARGIN
) {
3731 es
->format_rect
.left
-= es
->left_margin
;
3732 if (left
!= EC_USEFONTINFO
)
3733 es
->left_margin
= left
;
3735 es
->left_margin
= default_left_margin
;
3736 es
->format_rect
.left
+= es
->left_margin
;
3739 if (action
& EC_RIGHTMARGIN
) {
3740 es
->format_rect
.right
+= es
->right_margin
;
3741 if (right
!= EC_USEFONTINFO
)
3742 es
->right_margin
= right
;
3744 es
->right_margin
= default_right_margin
;
3745 es
->format_rect
.right
-= es
->right_margin
;
3748 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3749 EDIT_AdjustFormatRect(es
);
3750 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3753 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3757 /*********************************************************************
3759 * EM_SETPASSWORDCHAR
3762 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3766 if (es
->style
& ES_MULTILINE
)
3769 if (es
->password_char
== c
)
3772 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3773 es
->password_char
= c
;
3775 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3776 es
->style
|= ES_PASSWORD
;
3778 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3779 es
->style
&= ~ES_PASSWORD
;
3781 EDIT_UpdateText(es
, NULL
, TRUE
);
3785 /*********************************************************************
3789 * note: unlike the specs say: the order of start and end
3790 * _is_ preserved in Windows. (i.e. start can be > end)
3791 * In other words: this handler is OK
3794 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3796 UINT old_start
= es
->selection_start
;
3797 UINT old_end
= es
->selection_end
;
3798 UINT len
= get_text_length(es
);
3800 if (start
== (UINT
)-1) {
3801 start
= es
->selection_end
;
3802 end
= es
->selection_end
;
3804 start
= min(start
, len
);
3805 end
= min(end
, len
);
3807 es
->selection_start
= start
;
3808 es
->selection_end
= end
;
3810 es
->flags
|= EF_AFTER_WRAP
;
3812 es
->flags
&= ~EF_AFTER_WRAP
;
3813 /* Compute the necessary invalidation region. */
3814 /* Note that we don't need to invalidate regions which have
3815 * "never" been selected, or those which are "still" selected.
3816 * In fact, every time we hit a selection boundary, we can
3817 * *toggle* whether we need to invalidate. Thus we can optimize by
3818 * *sorting* the interval endpoints. Let's assume that we sort them
3820 * start <= end <= old_start <= old_end
3821 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3822 * in 5 comparisons; ie it's impossible to do better than the
3824 ORDER_UINT(end
, old_end
);
3825 ORDER_UINT(start
, old_start
);
3826 ORDER_UINT(old_start
, old_end
);
3827 ORDER_UINT(start
, end
);
3828 /* Note that at this point 'end' and 'old_start' are not in order, but
3829 * start is definitely the min. and old_end is definitely the max. */
3830 if (end
!= old_start
)
3834 * ORDER_UINT32(end, old_start);
3835 * EDIT_InvalidateText(es, start, end);
3836 * EDIT_InvalidateText(es, old_start, old_end);
3837 * in place of the following if statement.
3838 * (That would complete the optimal five-comparison four-element sort.)
3840 if (old_start
> end
)
3842 EDIT_InvalidateText(es
, start
, end
);
3843 EDIT_InvalidateText(es
, old_start
, old_end
);
3847 EDIT_InvalidateText(es
, start
, old_start
);
3848 EDIT_InvalidateText(es
, end
, old_end
);
3851 else EDIT_InvalidateText(es
, start
, old_end
);
3855 /*********************************************************************
3860 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3862 if (!(es
->style
& ES_MULTILINE
))
3864 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3865 es
->tabs_count
= count
;
3869 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3870 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3876 /*********************************************************************
3881 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3883 if (!(es
->style
& ES_MULTILINE
))
3885 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3886 es
->tabs_count
= count
;
3891 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3892 for (i
= 0 ; i
< count
; i
++)
3893 es
->tabs
[i
] = *tabs
++;
3899 /*********************************************************************
3901 * EM_SETWORDBREAKPROC
3904 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3906 if (es
->word_break_proc
== wbp
)
3909 es
->word_break_proc
= wbp
;
3910 es
->word_break_proc16
= NULL
;
3912 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3913 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3914 EDIT_UpdateText(es
, NULL
, TRUE
);
3919 /*********************************************************************
3921 * EM_SETWORDBREAKPROC16
3924 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3926 if (es
->word_break_proc16
== wbp
)
3929 es
->word_break_proc
= NULL
;
3930 es
->word_break_proc16
= wbp
;
3931 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3932 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3933 EDIT_UpdateText(es
, NULL
, TRUE
);
3938 /*********************************************************************
3943 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3948 /* As per MSDN spec, for a single-line edit control,
3949 the return value is always TRUE */
3950 if( es
->style
& ES_READONLY
)
3951 return !(es
->style
& ES_MULTILINE
);
3953 ulength
= strlenW(es
->undo_text
);
3955 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3957 strcpyW(utext
, es
->undo_text
);
3959 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3960 es
->undo_insert_count
, debugstr_w(utext
));
3962 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3963 EDIT_EM_EmptyUndoBuffer(es
);
3964 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3965 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3966 /* send the notification after the selection start and end are set */
3967 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3968 EDIT_EM_ScrollCaret(es
);
3969 HeapFree(GetProcessHeap(), 0, utext
);
3971 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3972 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3977 /*********************************************************************
3982 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3986 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3990 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3991 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3994 if (es
->style
& ES_MULTILINE
) {
3995 if (es
->style
& ES_READONLY
) {
3996 EDIT_MoveHome(es
, FALSE
);
3997 EDIT_MoveDown_ML(es
, FALSE
);
3999 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4000 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4005 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4007 static const WCHAR tabW
[] = {'\t',0};
4008 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4012 if (!(es
->style
& ES_READONLY
) && !control
) {
4013 if (es
->selection_start
!= es
->selection_end
)
4016 /* delete character left of caret */
4017 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4018 EDIT_MoveBackward(es
, TRUE
);
4024 if (!(es
->style
& ES_PASSWORD
))
4025 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4028 if (!(es
->style
& ES_READONLY
))
4029 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4032 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
4033 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4037 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4038 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4041 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4045 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4052 /*********************************************************************
4057 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4059 if (code
|| control
)
4079 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4080 EDIT_EM_ScrollCaret(es
);
4083 ERR("unknown menu item, please report\n");
4089 /*********************************************************************
4093 * Note: the resource files resource/sysres_??.rc cannot define a
4094 * single popup menu. Hence we use a (dummy) menubar
4095 * containing the single popup menu as its first item.
4097 * FIXME: the message identifiers have been chosen arbitrarily,
4098 * hence we use MF_BYPOSITION.
4099 * We might as well use the "real" values (anybody knows ?)
4100 * The menu definition is in resources/sysres_??.rc.
4101 * Once these are OK, we better use MF_BYCOMMAND here
4102 * (as we do in EDIT_WM_Command()).
4105 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4107 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4108 HMENU popup
= GetSubMenu(menu
, 0);
4109 UINT start
= es
->selection_start
;
4110 UINT end
= es
->selection_end
;
4112 ORDER_UINT(start
, end
);
4115 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4117 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4119 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4121 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4123 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4125 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
4127 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4130 /* Windows places the menu at the edit's center in this case */
4131 GetClientRect(es
->hwndSelf
, &rc
);
4132 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4133 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4134 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4137 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4142 /*********************************************************************
4147 static void EDIT_WM_Copy(EDITSTATE
*es
)
4149 INT s
= min(es
->selection_start
, es
->selection_end
);
4150 INT e
= max(es
->selection_start
, es
->selection_end
);
4158 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4159 dst
= GlobalLock(hdst
);
4160 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4161 dst
[len
] = 0; /* ensure 0 termination */
4162 TRACE("%s\n", debugstr_w(dst
));
4164 OpenClipboard(es
->hwndSelf
);
4166 SetClipboardData(CF_UNICODETEXT
, hdst
);
4171 /*********************************************************************
4176 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4180 TRACE("%s\n", debugstr_w(name
));
4182 * To initialize some final structure members, we call some helper
4183 * functions. However, since the EDITSTATE is not consistent (i.e.
4184 * not fully initialized), we should be very careful which
4185 * functions can be called, and in what order.
4187 EDIT_WM_SetFont(es
, 0, FALSE
);
4188 EDIT_EM_EmptyUndoBuffer(es
);
4190 /* We need to calculate the format rect
4191 (applications may send EM_SETMARGINS before the control gets visible) */
4192 GetClientRect(es
->hwndSelf
, &clientRect
);
4193 EDIT_SetRectNP(es
, &clientRect
);
4195 if (name
&& *name
) {
4196 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4197 /* if we insert text to the editline, the text scrolls out
4198 * of the window, as the caret is placed after the insert
4199 * pos normally; thus we reset es->selection... to 0 and
4202 es
->selection_start
= es
->selection_end
= 0;
4203 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4204 * Messages are only to be sent when the USER does something to
4205 * change the contents. So I am removing this EN_CHANGE
4207 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4209 EDIT_EM_ScrollCaret(es
);
4211 /* force scroll info update */
4212 EDIT_UpdateScrollInfo(es
);
4213 /* The rule seems to return 1 here for success */
4214 /* Power Builder masked edit controls will crash */
4216 /* FIXME: is that in all cases so ? */
4221 /*********************************************************************
4226 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4231 while (LocalUnlock(es
->hloc32W
)) ;
4232 LocalFree(es
->hloc32W
);
4235 while (LocalUnlock(es
->hloc32A
)) ;
4236 LocalFree(es
->hloc32A
);
4239 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4240 HANDLE16 oldDS
= stack16
->ds
;
4242 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4243 while (LocalUnlock16(es
->hloc16
)) ;
4244 LocalFree16(es
->hloc16
);
4245 stack16
->ds
= oldDS
;
4248 pc
= es
->first_line_def
;
4252 HeapFree(GetProcessHeap(), 0, pc
);
4256 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4257 HeapFree(GetProcessHeap(), 0, es
);
4263 /*********************************************************************
4268 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4270 /* we do the proper erase in EDIT_WM_Paint */
4275 /*********************************************************************
4280 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4282 if(!count
) return 0;
4286 lstrcpynW(dst
, es
->text
, count
);
4287 return strlenW(dst
);
4291 LPSTR textA
= (LPSTR
)dst
;
4292 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4293 textA
[count
- 1] = 0; /* ensure 0 termination */
4294 return strlen(textA
);
4298 /*********************************************************************
4303 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4308 if (!(es
->style
& ES_MULTILINE
))
4311 if (!(es
->style
& ES_AUTOHSCROLL
))
4315 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4318 TRACE("SB_LINELEFT\n");
4320 dx
= -es
->char_width
;
4323 TRACE("SB_LINERIGHT\n");
4324 if (es
->x_offset
< es
->text_width
)
4325 dx
= es
->char_width
;
4328 TRACE("SB_PAGELEFT\n");
4330 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4333 TRACE("SB_PAGERIGHT\n");
4334 if (es
->x_offset
< es
->text_width
)
4335 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4343 TRACE("SB_RIGHT\n");
4344 if (es
->x_offset
< es
->text_width
)
4345 dx
= es
->text_width
- es
->x_offset
;
4348 TRACE("SB_THUMBTRACK %d\n", pos
);
4349 es
->flags
|= EF_HSCROLL_TRACK
;
4350 if(es
->style
& WS_HSCROLL
)
4351 dx
= pos
- es
->x_offset
;
4356 if(pos
< 0 || pos
> 100) return 0;
4357 /* Assume default scroll range 0-100 */
4358 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4359 new_x
= pos
* (es
->text_width
- fw
) / 100;
4360 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4363 case SB_THUMBPOSITION
:
4364 TRACE("SB_THUMBPOSITION %d\n", pos
);
4365 es
->flags
&= ~EF_HSCROLL_TRACK
;
4366 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4367 dx
= pos
- es
->x_offset
;
4372 if(pos
< 0 || pos
> 100) return 0;
4373 /* Assume default scroll range 0-100 */
4374 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4375 new_x
= pos
* (es
->text_width
- fw
) / 100;
4376 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4379 /* force scroll info update */
4380 EDIT_UpdateScrollInfo(es
);
4381 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4385 TRACE("SB_ENDSCROLL\n");
4388 * FIXME : the next two are undocumented !
4389 * Are we doing the right thing ?
4390 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4391 * although it's also a regular control message.
4393 case EM_GETTHUMB
: /* this one is used by NT notepad */
4397 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4398 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4401 /* Assume default scroll range 0-100 */
4402 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4403 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4405 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4408 case EM_LINESCROLL16
:
4409 TRACE("EM_LINESCROLL16\n");
4414 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4420 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4421 /* check if we are going to move too far */
4422 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4423 dx
= es
->text_width
- fw
- es
->x_offset
;
4425 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4431 /*********************************************************************
4436 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4438 HWND hLBox
= es
->hwndListBox
;
4446 hCombo
= GetParent(es
->hwndSelf
);
4450 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4452 if (key
== VK_UP
|| key
== VK_DOWN
)
4454 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4457 if (msg
== WM_KEYDOWN
|| nEUI
)
4458 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4464 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4466 /* make sure ComboLBox pops up */
4467 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4472 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4475 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4477 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4479 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4484 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4490 /*********************************************************************
4494 * Handling of special keys that don't produce a WM_CHAR
4495 * (i.e. non-printable keys) & Backspace & Delete
4498 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4503 if (GetKeyState(VK_MENU
) & 0x8000)
4506 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4507 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4512 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4517 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4518 EDIT_MoveUp_ML(es
, shift
);
4521 EDIT_MoveWordBackward(es
, shift
);
4523 EDIT_MoveBackward(es
, shift
);
4526 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4530 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4531 EDIT_MoveDown_ML(es
, shift
);
4533 EDIT_MoveWordForward(es
, shift
);
4535 EDIT_MoveForward(es
, shift
);
4538 EDIT_MoveHome(es
, shift
);
4541 EDIT_MoveEnd(es
, shift
);
4544 if (es
->style
& ES_MULTILINE
)
4545 EDIT_MovePageUp_ML(es
, shift
);
4547 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4550 if (es
->style
& ES_MULTILINE
)
4551 EDIT_MovePageDown_ML(es
, shift
);
4553 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4556 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4557 if (es
->selection_start
!= es
->selection_end
) {
4564 /* delete character left of caret */
4565 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4566 EDIT_MoveBackward(es
, TRUE
);
4568 } else if (control
) {
4569 /* delete to end of line */
4570 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4571 EDIT_MoveEnd(es
, TRUE
);
4574 /* delete character right of caret */
4575 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4576 EDIT_MoveForward(es
, TRUE
);
4584 if (!(es
->style
& ES_READONLY
))
4590 /* If the edit doesn't want the return send a message to the default object */
4591 if(!(es
->style
& ES_WANTRETURN
))
4593 HWND hwndParent
= GetParent(es
->hwndSelf
);
4594 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4595 if (HIWORD(dw
) == DC_HASDEFID
)
4597 SendMessageW( hwndParent
, WM_COMMAND
,
4598 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4599 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4608 /*********************************************************************
4613 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4615 es
->flags
&= ~EF_FOCUSED
;
4617 if(!(es
->style
& ES_NOHIDESEL
))
4618 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4619 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4624 /*********************************************************************
4628 * The caret position has been set on the WM_LBUTTONDOWN message
4631 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4634 INT e
= es
->selection_end
;
4639 es
->bCaptureState
= TRUE
;
4640 SetCapture(es
->hwndSelf
);
4642 l
= EDIT_EM_LineFromChar(es
, e
);
4643 li
= EDIT_EM_LineIndex(es
, l
);
4644 ll
= EDIT_EM_LineLength(es
, e
);
4645 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4646 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4647 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4648 EDIT_EM_ScrollCaret(es
);
4649 es
->region_posx
= es
->region_posy
= 0;
4650 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4655 /*********************************************************************
4660 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4665 es
->bCaptureState
= TRUE
;
4666 SetCapture(es
->hwndSelf
);
4667 EDIT_ConfinePoint(es
, &x
, &y
);
4668 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4669 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4670 EDIT_EM_ScrollCaret(es
);
4671 es
->region_posx
= es
->region_posy
= 0;
4672 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4674 if (!(es
->flags
& EF_FOCUSED
))
4675 SetFocus(es
->hwndSelf
);
4681 /*********************************************************************
4686 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4688 if (es
->bCaptureState
) {
4689 KillTimer(es
->hwndSelf
, 0);
4690 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4692 es
->bCaptureState
= FALSE
;
4697 /*********************************************************************
4702 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4704 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4709 /*********************************************************************
4714 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4720 /* If the mouse has been captured by process other than the edit control itself,
4721 * the windows edit controls will not select the strings with mouse move.
4723 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4727 * FIXME: gotta do some scrolling if outside client
4728 * area. Maybe reset the timer ?
4731 EDIT_ConfinePoint(es
, &x
, &y
);
4732 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4733 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4734 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4735 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4736 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4741 /*********************************************************************
4745 * See also EDIT_WM_StyleChanged
4747 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4752 TRACE("Creating %s edit control, style = %08x\n",
4753 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4755 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4757 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4760 * Note: since the EDITSTATE has not been fully initialized yet,
4761 * we can't use any API calls that may send
4762 * WM_XXX messages before WM_NCCREATE is completed.
4765 es
->is_unicode
= unicode
;
4766 es
->style
= lpcs
->style
;
4768 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4770 es
->hwndSelf
= hwnd
;
4771 /* Save parent, which will be notified by EN_* messages */
4772 es
->hwndParent
= lpcs
->hwndParent
;
4774 if (es
->style
& ES_COMBO
)
4775 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4777 /* Number overrides lowercase overrides uppercase (at least it
4778 * does in Win95). However I'll bet that ES_NUMBER would be
4779 * invalid under Win 3.1.
4781 if (es
->style
& ES_NUMBER
) {
4782 ; /* do not override the ES_NUMBER */
4783 } else if (es
->style
& ES_LOWERCASE
) {
4784 es
->style
&= ~ES_UPPERCASE
;
4786 if (es
->style
& ES_MULTILINE
) {
4787 es
->buffer_limit
= BUFLIMIT_MULTI
;
4788 if (es
->style
& WS_VSCROLL
)
4789 es
->style
|= ES_AUTOVSCROLL
;
4790 if (es
->style
& WS_HSCROLL
)
4791 es
->style
|= ES_AUTOHSCROLL
;
4792 es
->style
&= ~ES_PASSWORD
;
4793 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4794 /* Confirmed - RIGHT overrides CENTER */
4795 if (es
->style
& ES_RIGHT
)
4796 es
->style
&= ~ES_CENTER
;
4797 es
->style
&= ~WS_HSCROLL
;
4798 es
->style
&= ~ES_AUTOHSCROLL
;
4801 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4802 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4803 es
->style
&= ~ES_CENTER
;
4804 es
->style
&= ~WS_HSCROLL
;
4805 es
->style
&= ~WS_VSCROLL
;
4806 if (es
->style
& ES_PASSWORD
)
4807 es
->password_char
= '*';
4810 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4811 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4813 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4815 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4817 es
->undo_buffer_size
= es
->buffer_size
;
4819 if (es
->style
& ES_MULTILINE
)
4820 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4825 * In Win95 look and feel, the WS_BORDER style is replaced by the
4826 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4827 * control a nonclient area so we don't need to draw the border.
4828 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4829 * a nonclient area and we should handle painting the border ourselves.
4831 * When making modifications please ensure that the code still works
4832 * for edit controls created directly with style 0x50800000, exStyle 0
4833 * (which should have a single pixel border)
4835 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4836 es
->style
&= ~WS_BORDER
;
4837 else if (es
->style
& WS_BORDER
)
4838 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4843 /*********************************************************************
4848 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4861 BOOL rev
= es
->bEnableState
&&
4862 ((es
->flags
& EF_FOCUSED
) ||
4863 (es
->style
& ES_NOHIDESEL
));
4864 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4866 GetClientRect(es
->hwndSelf
, &rcClient
);
4868 /* get the background brush */
4869 brush
= EDIT_NotifyCtlColor(es
, dc
);
4871 /* paint the border and the background */
4872 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4874 if(es
->style
& WS_BORDER
) {
4875 bw
= GetSystemMetrics(SM_CXBORDER
);
4876 bh
= GetSystemMetrics(SM_CYBORDER
);
4878 if(es
->style
& ES_MULTILINE
) {
4879 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4880 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4883 /* Draw the frame. Same code as in nonclient.c */
4884 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
4885 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
4886 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4887 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
4888 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4889 SelectObject(dc
, old_brush
);
4891 /* Keep the border clean */
4892 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
4893 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
4896 GetClipBox(dc
, &rc
);
4897 FillRect(dc
, &rc
, brush
);
4899 IntersectClipRect(dc
, es
->format_rect
.left
,
4900 es
->format_rect
.top
,
4901 es
->format_rect
.right
,
4902 es
->format_rect
.bottom
);
4903 if (es
->style
& ES_MULTILINE
) {
4905 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4908 old_font
= SelectObject(dc
, es
->font
);
4910 if (!es
->bEnableState
)
4911 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4912 GetClipBox(dc
, &rcRgn
);
4913 if (es
->style
& ES_MULTILINE
) {
4914 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4915 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4916 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4917 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4918 EDIT_PaintLine(es
, dc
, i
, rev
);
4921 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4922 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4923 EDIT_PaintLine(es
, dc
, 0, rev
);
4926 SelectObject(dc
, old_font
);
4929 EndPaint(es
->hwndSelf
, &ps
);
4933 /*********************************************************************
4938 static void EDIT_WM_Paste(EDITSTATE
*es
)
4943 /* Protect read-only edit control from modification */
4944 if(es
->style
& ES_READONLY
)
4947 OpenClipboard(es
->hwndSelf
);
4948 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4949 src
= (LPWSTR
)GlobalLock(hsrc
);
4950 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4953 else if (es
->style
& ES_PASSWORD
) {
4954 /* clear selected text in password edit box even with empty clipboard */
4955 const WCHAR empty_strW
[] = { 0 };
4956 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
4962 /*********************************************************************
4967 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4969 es
->flags
|= EF_FOCUSED
;
4971 if (!(es
->style
& ES_NOHIDESEL
))
4972 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4974 /* single line edit updates itself */
4975 if (!(es
->style
& ES_MULTILINE
))
4977 HDC hdc
= GetDC(es
->hwndSelf
);
4978 EDIT_WM_Paint(es
, hdc
);
4979 ReleaseDC(es
->hwndSelf
, hdc
);
4982 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4983 EDIT_SetCaretPos(es
, es
->selection_end
,
4984 es
->flags
& EF_AFTER_WRAP
);
4985 ShowCaret(es
->hwndSelf
);
4986 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
4990 /*********************************************************************
4994 * With Win95 look the margins are set to default font value unless
4995 * the system font (font == 0) is being set, in which case they are left
4999 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5007 dc
= GetDC(es
->hwndSelf
);
5009 old_font
= SelectObject(dc
, font
);
5010 GetTextMetricsW(dc
, &tm
);
5011 es
->line_height
= tm
.tmHeight
;
5012 es
->char_width
= tm
.tmAveCharWidth
;
5014 SelectObject(dc
, old_font
);
5015 ReleaseDC(es
->hwndSelf
, dc
);
5017 /* Reset the format rect and the margins */
5018 GetClientRect(es
->hwndSelf
, &clientRect
);
5019 EDIT_SetRectNP(es
, &clientRect
);
5020 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5021 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5023 if (es
->style
& ES_MULTILINE
)
5024 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
5026 EDIT_CalcLineWidth_SL(es
);
5029 EDIT_UpdateText(es
, NULL
, TRUE
);
5030 if (es
->flags
& EF_FOCUSED
) {
5032 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5033 EDIT_SetCaretPos(es
, es
->selection_end
,
5034 es
->flags
& EF_AFTER_WRAP
);
5035 ShowCaret(es
->hwndSelf
);
5040 /*********************************************************************
5045 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5046 * The modified flag is reset. No notifications are sent.
5048 * For single-line controls, reception of WM_SETTEXT triggers:
5049 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5052 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5054 LPWSTR textW
= NULL
;
5055 if (!unicode
&& text
)
5057 LPCSTR textA
= (LPCSTR
)text
;
5058 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5059 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5061 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5065 if (es
->flags
& EF_UPDATE
)
5066 /* fixed this bug once; complain if we see it about to happen again. */
5067 ERR("SetSel may generate UPDATE message whose handler may reset "
5070 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5073 TRACE("%s\n", debugstr_w(text
));
5074 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5076 HeapFree(GetProcessHeap(), 0, textW
);
5080 static const WCHAR empty_stringW
[] = {0};
5082 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5085 es
->flags
&= ~EF_MODIFIED
;
5086 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5088 /* Send the notification after the selection start and end have been set
5089 * edit control doesn't send notification on WM_SETTEXT
5090 * if it is multiline, or it is part of combobox
5092 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5094 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5095 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5097 EDIT_EM_ScrollCaret(es
);
5098 EDIT_UpdateScrollInfo(es
);
5102 /*********************************************************************
5107 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5109 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5111 TRACE("width = %d, height = %d\n", width
, height
);
5112 SetRect(&rc
, 0, 0, width
, height
);
5113 EDIT_SetRectNP(es
, &rc
);
5114 EDIT_UpdateText(es
, NULL
, TRUE
);
5119 /*********************************************************************
5123 * This message is sent by SetWindowLong on having changed either the Style
5124 * or the extended style.
5126 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5128 * See also EDIT_WM_NCCreate
5130 * It appears that the Windows version of the edit control allows the style
5131 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5132 * style variable which will generally be different. In this function we
5133 * update the internal style based on what changed in the externally visible
5136 * Much of this content as based upon the MSDN, especially:
5137 * Platform SDK Documentation -> User Interface Services ->
5138 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5139 * Edit Control Styles
5141 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5143 if (GWL_STYLE
== which
) {
5144 DWORD style_change_mask
;
5146 /* Only a subset of changes can be applied after the control
5149 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5151 if (es
->style
& ES_MULTILINE
)
5152 style_change_mask
|= ES_WANTRETURN
;
5154 new_style
= style
->styleNew
& style_change_mask
;
5156 /* Number overrides lowercase overrides uppercase (at least it
5157 * does in Win95). However I'll bet that ES_NUMBER would be
5158 * invalid under Win 3.1.
5160 if (new_style
& ES_NUMBER
) {
5161 ; /* do not override the ES_NUMBER */
5162 } else if (new_style
& ES_LOWERCASE
) {
5163 new_style
&= ~ES_UPPERCASE
;
5166 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5167 } else if (GWL_EXSTYLE
== which
) {
5168 ; /* FIXME - what is needed here */
5170 WARN ("Invalid style change %ld\n",which
);
5176 /*********************************************************************
5181 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5183 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5184 if (EDIT_EM_CanUndo(es
))
5187 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5188 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5191 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5195 /*********************************************************************
5200 static void EDIT_WM_Timer(EDITSTATE
*es
)
5202 if (es
->region_posx
< 0) {
5203 EDIT_MoveBackward(es
, TRUE
);
5204 } else if (es
->region_posx
> 0) {
5205 EDIT_MoveForward(es
, TRUE
);
5208 * FIXME: gotta do some vertical scrolling here, like
5209 * EDIT_EM_LineScroll(hwnd, 0, 1);
5213 /*********************************************************************
5218 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5222 if (!(es
->style
& ES_MULTILINE
))
5225 if (!(es
->style
& ES_AUTOVSCROLL
))
5234 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5235 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5236 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5238 EDIT_EM_Scroll(es
, action
);
5245 TRACE("SB_BOTTOM\n");
5246 dy
= es
->line_count
- 1 - es
->y_offset
;
5249 TRACE("SB_THUMBTRACK %d\n", pos
);
5250 es
->flags
|= EF_VSCROLL_TRACK
;
5251 if(es
->style
& WS_VSCROLL
)
5252 dy
= pos
- es
->y_offset
;
5255 /* Assume default scroll range 0-100 */
5258 if(pos
< 0 || pos
> 100) return 0;
5259 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5260 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5261 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5262 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5263 es
->line_count
, es
->y_offset
, pos
, dy
);
5266 case SB_THUMBPOSITION
:
5267 TRACE("SB_THUMBPOSITION %d\n", pos
);
5268 es
->flags
&= ~EF_VSCROLL_TRACK
;
5269 if(es
->style
& WS_VSCROLL
)
5270 dy
= pos
- es
->y_offset
;
5273 /* Assume default scroll range 0-100 */
5276 if(pos
< 0 || pos
> 100) return 0;
5277 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5278 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5279 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5280 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5281 es
->line_count
, es
->y_offset
, pos
, dy
);
5285 /* force scroll info update */
5286 EDIT_UpdateScrollInfo(es
);
5287 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5291 TRACE("SB_ENDSCROLL\n");
5294 * FIXME : the next two are undocumented !
5295 * Are we doing the right thing ?
5296 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5297 * although it's also a regular control message.
5299 case EM_GETTHUMB
: /* this one is used by NT notepad */
5303 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5304 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5307 /* Assume default scroll range 0-100 */
5308 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5309 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5311 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5314 case EM_LINESCROLL16
:
5315 TRACE("EM_LINESCROLL16 %d\n", pos
);
5320 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5325 EDIT_EM_LineScroll(es
, 0, dy
);
5329 /*********************************************************************
5334 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5336 if (es
->flags
& EF_UPDATE
) {
5337 es
->flags
&= ~EF_UPDATE
;
5338 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5340 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5344 /*********************************************************************
5349 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5351 if (es
->flags
& EF_UPDATE
) {
5352 es
->flags
&= ~EF_UPDATE
;
5353 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5355 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5358 /********************************************************************
5360 * The Following code is to handle inline editing from IMEs
5363 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5366 LPWSTR lpCompStr
= NULL
;
5368 LPSTR lpCompStrAttr
= NULL
;
5371 if (!(hIMC
= ImmGetContext(hwnd
)))
5374 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5378 ImmReleaseContext(hwnd
, hIMC
);
5382 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
5385 ERR("Unable to allocate IME CompositionString\n");
5386 ImmReleaseContext(hwnd
,hIMC
);
5391 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
5392 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5394 if (CompFlag
& GCS_COMPATTR
)
5397 * We do not use the attributes yet. it would tell us what characters
5398 * are in transition and which are converted or decided upon
5400 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5404 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5407 ERR("Unable to allocate IME Attribute String\n");
5408 HeapFree(GetProcessHeap(),0,lpCompStr
);
5409 ImmReleaseContext(hwnd
,hIMC
);
5412 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5414 lpCompStrAttr
[dwBufLenAttr
] = 0;
5417 lpCompStrAttr
= NULL
;
5420 /* check for change in composition start */
5421 if (es
->selection_end
< es
->composition_start
)
5422 es
->composition_start
= es
->selection_end
;
5424 /* replace existing selection string */
5425 es
->selection_start
= es
->composition_start
;
5427 if (es
->composition_len
> 0)
5428 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5430 es
->selection_end
= es
->selection_start
;
5432 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5433 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5435 es
->selection_start
= es
->composition_start
;
5436 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5438 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5439 HeapFree(GetProcessHeap(),0,lpCompStr
);
5440 ImmReleaseContext(hwnd
,hIMC
);
5443 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5449 if ( !(hIMC
= ImmGetContext(hwnd
)))
5452 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5455 ImmReleaseContext(hwnd
, hIMC
);
5459 lpResultStr
= HeapAlloc(GetProcessHeap(),0, dwBufLen
+sizeof(WCHAR
));
5462 ERR("Unable to alloc buffer for IME string\n");
5463 ImmReleaseContext(hwnd
, hIMC
);
5467 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, dwBufLen
);
5468 lpResultStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5470 /* check for change in composition start */
5471 if (es
->selection_end
< es
->composition_start
)
5472 es
->composition_start
= es
->selection_end
;
5474 es
->selection_start
= es
->composition_start
;
5475 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5476 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5477 es
->composition_start
= es
->selection_end
;
5478 es
->composition_len
= 0;
5480 HeapFree(GetProcessHeap(),0,lpResultStr
);
5481 ImmReleaseContext(hwnd
, hIMC
);
5484 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5486 if (CompFlag
& GCS_RESULTSTR
)
5487 EDIT_GetResultStr(hwnd
,es
);
5488 if (CompFlag
& GCS_COMPSTR
)
5489 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);