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. */
89 END_0
= 0, /* line ends with terminating '\0' character */
90 END_WRAP
, /* line is wrapped */
91 END_HARD
, /* line ends with a hard return '\r\n' */
92 END_SOFT
, /* line ends with a soft return '\r\r\n' */
93 END_RICH
/* line ends with a single '\n' */
96 typedef struct tagLINEDEF
{
97 INT length
; /* bruto length of a line in bytes */
98 INT net_length
; /* netto length of a line in visible characters */
100 INT width
; /* width of the line in pixels */
101 INT index
; /* line index into the buffer */
102 struct tagLINEDEF
*next
;
107 BOOL is_unicode
; /* how the control was created */
108 LPWSTR text
; /* the actual contents of the control */
109 UINT buffer_size
; /* the size of the buffer in characters */
110 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
111 HFONT font
; /* NULL means standard system font */
112 INT x_offset
; /* scroll offset for multi lines this is in pixels
113 for single lines it's in characters */
114 INT line_height
; /* height of a screen line in pixels */
115 INT char_width
; /* average character width in pixels */
116 DWORD style
; /* sane version of wnd->dwStyle */
117 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
118 INT undo_insert_count
; /* number of characters inserted in sequence */
119 UINT undo_position
; /* character index of the insertion and deletion */
120 LPWSTR undo_text
; /* deleted text */
121 UINT undo_buffer_size
; /* size of the deleted text buffer */
122 INT selection_start
; /* == selection_end if no selection */
123 INT selection_end
; /* == current caret position */
124 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
125 INT left_margin
; /* in pixels */
126 INT right_margin
; /* in pixels */
128 INT text_width
; /* width of the widest line in pixels for multi line controls
129 and just line width for single line controls */
130 INT region_posx
; /* Position of cursor relative to region: */
131 INT region_posy
; /* -1: to left, 0: within, 1: to right */
132 EDITWORDBREAKPROC16 word_break_proc16
;
133 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
134 INT line_count
; /* number of lines */
135 INT y_offset
; /* scroll offset in number of lines */
136 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
137 BOOL bEnableState
; /* flag keeping the enable state */
138 HWND hwndSelf
; /* the our window handle */
139 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
140 Even if parent will change, EN_* messages
141 should be sent to the first parent. */
142 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
144 * only for multi line controls
146 INT lock_count
; /* amount of re-entries in the EditWndProc */
149 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
150 HLOCAL hloc32W
; /* our unicode local memory block */
151 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
153 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
158 UINT composition_len
; /* length of composition, 0 == no composition */
159 int composition_start
; /* the character position for the composition */
163 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
164 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
166 /* used for disabled or read-only edit control */
167 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
169 { /* Notify parent which has created this edit control */ \
170 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
171 SendMessageW(es->hwndParent, WM_COMMAND, \
172 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
173 (LPARAM)(es->hwndSelf)); \
176 /*********************************************************************
183 * These functions have trivial implementations
184 * We still like to call them internally
185 * "static inline" makes them more like macro's
187 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
188 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
189 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
190 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
193 * Helper functions only valid for one type of control
195 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
196 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
197 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
198 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
199 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
200 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
201 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
203 * Helper functions valid for both single line _and_ multi line controls
205 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
206 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
207 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
208 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
209 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
210 static void EDIT_LockBuffer(EDITSTATE
*es
);
211 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
212 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
213 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
214 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
215 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
216 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
217 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
218 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
219 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
220 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
221 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
222 static void EDIT_AdjustFormatRect(EDITSTATE
*es
);
223 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
224 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
225 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
226 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
228 * EM_XXX message handlers
230 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
231 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
232 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
233 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
234 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
235 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
236 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
237 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
238 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
239 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
240 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
241 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
242 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
243 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
244 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
245 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
246 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
247 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
248 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
249 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, WORD left
, WORD right
, BOOL repaint
);
250 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
251 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
252 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
253 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
254 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
255 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
256 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
258 * WM_XXX message handlers
260 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
261 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
262 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
263 static void EDIT_WM_Copy(EDITSTATE
*es
);
264 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
265 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
266 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
267 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
268 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
269 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
270 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
271 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
272 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
273 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
274 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
275 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
276 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
277 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
278 static void EDIT_WM_Paste(EDITSTATE
*es
);
279 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
280 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
281 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
282 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
283 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
284 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
285 static void EDIT_WM_Timer(EDITSTATE
*es
);
286 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
287 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
288 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
289 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
);
291 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
292 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
294 /*********************************************************************
295 * edit class descriptor
297 const struct builtin_class_descr EDIT_builtin_class
=
300 CS_DBLCLKS
| CS_PARENTDC
, /* style */
301 EditWndProcA
, /* procA */
302 EditWndProcW
, /* procW */
303 sizeof(EDITSTATE
*), /* extra */
304 IDC_IBEAM
, /* cursor */
309 /*********************************************************************
314 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
316 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
320 /*********************************************************************
325 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
327 es
->undo_insert_count
= 0;
328 *es
->undo_text
= '\0';
332 /*********************************************************************
337 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
339 static const WCHAR empty_stringW
[] = {0};
341 /* Protect read-only edit control from modification */
342 if(es
->style
& ES_READONLY
)
345 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
349 /*********************************************************************
354 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
361 /**********************************************************************
364 * Returns the window version in case Wine emulates a later version
365 * of windows than the application expects.
367 * In a number of cases when windows runs an application that was
368 * designed for an earlier windows version, windows reverts
369 * to "old" behaviour of that earlier version.
371 * An example is a disabled edit control that needs to be painted.
372 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
373 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
374 * applications with an expected version 0f 4.0 or higher.
377 static DWORD
get_app_version(void)
379 static DWORD version
;
382 DWORD dwEmulatedVersion
;
384 DWORD dwProcVersion
= GetProcessVersion(0);
386 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
387 GetVersionExW( &info
);
388 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
389 /* FIXME: this may not be 100% correct; see discussion on the
390 * wine developer list in Nov 1999 */
391 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
397 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
402 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
403 msg
= WM_CTLCOLORSTATIC
;
405 msg
= WM_CTLCOLOREDIT
;
407 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
408 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
410 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
414 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
417 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
419 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
422 /*********************************************************************
426 * The messages are in the order of the actual integer values
427 * (which can be found in include/windows.h)
428 * Wherever possible the 16 bit versions are converted to
429 * the 32 bit ones, so that we can 'fall through' to the
430 * helper functions. These are mostly 32 bit (with a few
431 * exceptions, clearly indicated by a '16' extension to their
435 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
436 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
438 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
441 TRACE("hwnd=%p msg=%x (%s) wparam=%x lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
443 if (!es
&& msg
!= WM_NCCREATE
)
444 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
446 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
454 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
458 if ((short)LOWORD(lParam
) == -1)
459 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
461 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
463 EDIT_EM_ScrollCaret(es
);
467 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
468 EDIT_EM_ScrollCaret(es
);
475 RECT16
*r16
= MapSL(lParam
);
476 r16
->left
= es
->format_rect
.left
;
477 r16
->top
= es
->format_rect
.top
;
478 r16
->right
= es
->format_rect
.right
;
479 r16
->bottom
= es
->format_rect
.bottom
;
484 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
488 if ((es
->style
& ES_MULTILINE
) && lParam
) {
490 RECT16
*r16
= MapSL(lParam
);
493 rc
.right
= r16
->right
;
494 rc
.bottom
= r16
->bottom
;
495 EDIT_SetRectNP(es
, &rc
);
496 EDIT_UpdateText(es
, NULL
, TRUE
);
500 if ((es
->style
& ES_MULTILINE
) && lParam
) {
501 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
502 EDIT_UpdateText(es
, NULL
, TRUE
);
507 if ((es
->style
& ES_MULTILINE
) && lParam
) {
509 RECT16
*r16
= MapSL(lParam
);
512 rc
.right
= r16
->right
;
513 rc
.bottom
= r16
->bottom
;
514 EDIT_SetRectNP(es
, &rc
);
518 if ((es
->style
& ES_MULTILINE
) && lParam
)
519 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
524 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
527 case EM_LINESCROLL16
:
528 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
529 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
532 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
535 case EM_SCROLLCARET16
:
537 EDIT_EM_ScrollCaret(es
);
543 result
= ((es
->flags
& EF_MODIFIED
) != 0);
549 es
->flags
|= EF_MODIFIED
;
551 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
554 case EM_GETLINECOUNT16
:
555 case EM_GETLINECOUNT
:
556 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
560 if ((INT16
)wParam
== -1)
564 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
568 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
571 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
575 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
578 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
583 result
= EDIT_EM_GetThumb(es
);
586 /* these messages missing from specs */
595 FIXME("undocumented message 0x%x, please report\n", msg
);
596 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
599 case EM_LINELENGTH16
:
601 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
604 case EM_REPLACESEL16
:
605 lParam
= (LPARAM
)MapSL(lParam
);
606 unicode
= FALSE
; /* 16-bit message is always ascii */
613 textW
= (LPWSTR
)lParam
;
616 LPSTR textA
= (LPSTR
)lParam
;
617 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
618 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
619 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
622 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
626 HeapFree(GetProcessHeap(), 0, textW
);
631 lParam
= (LPARAM
)MapSL(lParam
);
632 unicode
= FALSE
; /* 16-bit message is always ascii */
635 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
639 case EM_SETLIMITTEXT
:
640 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
645 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
651 result
= (LRESULT
)EDIT_EM_Undo(es
);
656 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
659 case EM_LINEFROMCHAR16
:
660 case EM_LINEFROMCHAR
:
661 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
664 case EM_SETTABSTOPS16
:
665 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
668 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
671 case EM_SETPASSWORDCHAR16
:
672 unicode
= FALSE
; /* 16-bit message is always ascii */
674 case EM_SETPASSWORDCHAR
:
679 charW
= (WCHAR
)wParam
;
683 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
686 EDIT_EM_SetPasswordChar(es
, charW
);
690 case EM_EMPTYUNDOBUFFER16
:
691 case EM_EMPTYUNDOBUFFER
:
692 EDIT_EM_EmptyUndoBuffer(es
);
695 case EM_GETFIRSTVISIBLELINE16
:
696 result
= es
->y_offset
;
698 case EM_GETFIRSTVISIBLELINE
:
699 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
702 case EM_SETREADONLY16
:
705 SetWindowLongW( hwnd
, GWL_STYLE
,
706 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
707 es
->style
|= ES_READONLY
;
709 SetWindowLongW( hwnd
, GWL_STYLE
,
710 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
711 es
->style
&= ~ES_READONLY
;
716 case EM_SETWORDBREAKPROC16
:
717 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
719 case EM_SETWORDBREAKPROC
:
720 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
723 case EM_GETWORDBREAKPROC16
:
724 result
= (LRESULT
)es
->word_break_proc16
;
726 case EM_GETWORDBREAKPROC
:
727 result
= (LRESULT
)es
->word_break_proc
;
730 case EM_GETPASSWORDCHAR16
:
731 unicode
= FALSE
; /* 16-bit message is always ascii */
733 case EM_GETPASSWORDCHAR
:
736 result
= es
->password_char
;
739 WCHAR charW
= es
->password_char
;
741 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
747 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
750 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
754 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
757 case EM_GETLIMITTEXT
:
758 result
= es
->buffer_limit
;
762 result
= strlenW(es
->text
);
763 if ((INT
)wParam
>= result
) result
= -1;
764 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
768 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
771 /* End of the EM_ messages which were in numerical order; what order
772 * are these in? vaguely alphabetical?
776 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
780 result
= EDIT_WM_Destroy(es
);
785 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
787 if (es
->style
& ES_MULTILINE
)
789 result
|= DLGC_WANTALLKEYS
;
793 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
795 int vk
= (int)((LPMSG
)lParam
)->wParam
;
797 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
799 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
800 result
|= DLGC_WANTMESSAGE
;
811 strng
[0] = wParam
>> 8;
812 strng
[1] = wParam
& 0xff;
813 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
814 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
815 EDIT_WM_Char(es
, charW
);
828 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
831 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
833 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
834 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
837 EDIT_WM_Char(es
, charW
);
846 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
850 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
859 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
862 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
866 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
867 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
868 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
870 result
= EDIT_WM_Create(es
, nameW
);
871 HeapFree(GetProcessHeap(), 0, nameW
);
880 es
->bEnableState
= (BOOL
) wParam
;
881 EDIT_UpdateText(es
, NULL
, TRUE
);
885 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
889 result
= (LRESULT
)es
->font
;
893 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
896 case WM_GETTEXTLENGTH
:
897 if (unicode
) result
= strlenW(es
->text
);
898 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
899 NULL
, 0, NULL
, NULL
);
903 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
907 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
911 result
= EDIT_WM_KillFocus(es
);
914 case WM_LBUTTONDBLCLK
:
915 result
= EDIT_WM_LButtonDblClk(es
);
919 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
923 result
= EDIT_WM_LButtonUp(es
);
927 result
= EDIT_WM_MButtonDown(es
);
931 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
936 EDIT_WM_Paint(es
, (HDC
)wParam
);
944 EDIT_WM_SetFocus(es
);
948 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
952 /* FIXME: actually set an internal flag and behave accordingly */
956 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
961 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
964 case WM_STYLECHANGED
:
965 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
968 case WM_STYLECHANGING
:
969 result
= 0; /* See EDIT_WM_StyleChanged */
973 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
981 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
986 int gcWheelDelta
= 0;
987 UINT pulScrollLines
= 3;
988 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
990 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
991 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
994 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
995 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
997 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
998 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
999 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1005 /* IME messages to make the edit control IME aware */
1006 case WM_IME_SETCONTEXT
:
1009 case WM_IME_STARTCOMPOSITION
:
1011 * FIXME in IME: This message is not always sent like it should be
1013 if (es
->selection_start
!= es
->selection_end
)
1015 static const WCHAR empty_stringW
[] = {0};
1016 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1018 es
->composition_start
= es
->selection_end
;
1019 es
->composition_len
= 0;
1022 case WM_IME_COMPOSITION
:
1023 if (es
->composition_len
== 0)
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
);
1031 es
->composition_start
= es
->selection_end
;
1033 EDIT_ImeComposition(hwnd
,lParam
,es
);
1036 case WM_IME_ENDCOMPOSITION
:
1037 es
->composition_len
= 0;
1040 case WM_IME_COMPOSITIONFULL
:
1046 case WM_IME_CONTROL
:
1050 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1054 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1056 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1061 /*********************************************************************
1063 * EditWndProcW (USER32.@)
1065 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1067 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1070 /*********************************************************************
1072 * EditWndProc (USER32.@)
1074 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1076 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1079 /*********************************************************************
1081 * EDIT_BuildLineDefs_ML
1083 * Build linked list of text lines.
1084 * Lines can end with '\0' (last line), a character (if it is wrapped),
1085 * a soft return '\r\r\n' or a hard return '\r\n'
1088 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1092 LPWSTR current_position
, cp
;
1094 LINEDEF
*current_line
;
1095 LINEDEF
*previous_line
;
1096 LINEDEF
*start_line
;
1097 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1098 INT line_count
= es
->line_count
;
1099 INT orig_net_length
;
1102 if (istart
== iend
&& delta
== 0)
1105 dc
= GetDC(es
->hwndSelf
);
1107 old_font
= SelectObject(dc
, es
->font
);
1109 previous_line
= NULL
;
1110 current_line
= es
->first_line_def
;
1112 /* Find starting line. istart must lie inside an existing line or
1113 * at the end of buffer */
1115 if (istart
< current_line
->index
+ current_line
->length
||
1116 current_line
->ending
== END_0
)
1119 previous_line
= current_line
;
1120 current_line
= current_line
->next
;
1122 } while (current_line
);
1124 if (!current_line
) /* Error occurred start is not inside previous buffer */
1126 FIXME(" modification occurred outside buffer\n");
1127 ReleaseDC(es
->hwndSelf
, dc
);
1131 /* Remember start of modifications in order to calculate update region */
1132 nstart_line
= line_index
;
1133 nstart_index
= current_line
->index
;
1135 /* We must start to reformat from the previous line since the modifications
1136 * may have caused the line to wrap upwards. */
1137 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1140 current_line
= previous_line
;
1142 start_line
= current_line
;
1144 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1145 current_position
= es
->text
+ current_line
->index
;
1147 if (current_line
!= start_line
)
1149 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1151 /* The buffer has been expanded, create a new line and
1152 insert it into the link list */
1153 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1154 new_line
->next
= previous_line
->next
;
1155 previous_line
->next
= new_line
;
1156 current_line
= new_line
;
1159 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1161 /* The previous line merged with this line so we delete this extra entry */
1162 previous_line
->next
= current_line
->next
;
1163 HeapFree(GetProcessHeap(), 0, current_line
);
1164 current_line
= previous_line
->next
;
1168 else /* current_line->index + delta == current_position */
1170 if (current_position
- es
->text
> iend
)
1171 break; /* We reached end of line modifications */
1172 /* else recalulate this line */
1176 current_line
->index
= current_position
- es
->text
;
1177 orig_net_length
= current_line
->net_length
;
1179 /* Find end of line */
1180 cp
= current_position
;
1182 if (*cp
== '\n') break;
1183 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1188 /* Mark type of line termination */
1190 current_line
->ending
= END_0
;
1191 current_line
->net_length
= strlenW(current_position
);
1192 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1193 current_line
->ending
= END_SOFT
;
1194 current_line
->net_length
= cp
- current_position
- 1;
1195 } else if (*cp
== '\n') {
1196 current_line
->ending
= END_RICH
;
1197 current_line
->net_length
= cp
- current_position
;
1199 current_line
->ending
= END_HARD
;
1200 current_line
->net_length
= cp
- current_position
;
1203 /* Calculate line width */
1204 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1205 current_position
, current_line
->net_length
,
1206 es
->tabs_count
, es
->tabs
));
1208 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1209 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1210 if (current_line
->width
> fw
) {
1215 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1216 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1217 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1218 current_position
, next
, es
->tabs_count
, es
->tabs
));
1219 } while (current_line
->width
<= fw
);
1220 if (!prev
) { /* Didn't find a line break so force a break */
1225 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1226 current_position
, next
, es
->tabs_count
, es
->tabs
));
1227 } while (current_line
->width
<= fw
);
1232 /* If the first line we are calculating, wrapped before istart, we must
1233 * adjust istart in order for this to be reflected in the update region. */
1234 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1235 istart
= current_line
->index
+ prev
;
1236 /* else if we are updating the previous line before the first line we
1237 * are re-calculating and it expanded */
1238 else if (current_line
== start_line
&&
1239 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1241 /* Line expanded due to an upwards line wrap so we must partially include
1242 * previous line in update region */
1243 nstart_line
= line_index
;
1244 nstart_index
= current_line
->index
;
1245 istart
= current_line
->index
+ orig_net_length
;
1248 current_line
->net_length
= prev
;
1249 current_line
->ending
= END_WRAP
;
1250 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1251 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1253 else if (orig_net_length
< current_line
->net_length
&&
1254 current_line
== start_line
&&
1255 current_line
->index
!= nstart_index
) {
1256 /* The previous line expanded but it's still not as wide as the client rect */
1257 /* The expansion is due to an upwards line wrap so we must partially include
1258 it in the update region */
1259 nstart_line
= line_index
;
1260 nstart_index
= current_line
->index
;
1261 istart
= current_line
->index
+ orig_net_length
;
1266 /* Adjust length to include line termination */
1267 switch (current_line
->ending
) {
1269 current_line
->length
= current_line
->net_length
+ 3;
1272 current_line
->length
= current_line
->net_length
+ 1;
1275 current_line
->length
= current_line
->net_length
+ 2;
1279 current_line
->length
= current_line
->net_length
;
1282 es
->text_width
= max(es
->text_width
, current_line
->width
);
1283 current_position
+= current_line
->length
;
1284 previous_line
= current_line
;
1285 current_line
= current_line
->next
;
1287 } while (previous_line
->ending
!= END_0
);
1289 /* Finish adjusting line indexes by delta or remove hanging lines */
1290 if (previous_line
->ending
== END_0
)
1292 LINEDEF
*pnext
= NULL
;
1294 previous_line
->next
= NULL
;
1295 while (current_line
)
1297 pnext
= current_line
->next
;
1298 HeapFree(GetProcessHeap(), 0, current_line
);
1299 current_line
= pnext
;
1303 else if (delta
!= 0)
1305 while (current_line
)
1307 current_line
->index
+= delta
;
1308 current_line
= current_line
->next
;
1312 /* Calculate rest of modification rectangle */
1317 * We calculate two rectangles. One for the first line which may have
1318 * an indent with respect to the format rect. The other is a format-width
1319 * rectangle that spans the rest of the lines that changed or moved.
1321 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1322 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1323 rc
.bottom
= rc
.top
+ es
->line_height
;
1324 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1325 rc
.left
= es
->format_rect
.left
;
1327 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1328 es
->text
+ nstart_index
, istart
- nstart_index
,
1329 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1330 rc
.right
= es
->format_rect
.right
;
1331 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1334 rc
.left
= es
->format_rect
.left
;
1335 rc
.right
= es
->format_rect
.right
;
1337 * If lines were added or removed we must re-paint the remainder of the
1338 * lines since the remaining lines were either shifted up or down.
1340 if (line_count
< es
->line_count
) /* We added lines */
1341 rc
.bottom
= es
->line_count
* es
->line_height
;
1342 else if (line_count
> es
->line_count
) /* We removed lines */
1343 rc
.bottom
= line_count
* es
->line_height
;
1345 rc
.bottom
= line_index
* es
->line_height
;
1346 rc
.bottom
+= es
->format_rect
.top
;
1347 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1348 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1349 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1350 DeleteObject(tmphrgn
);
1354 SelectObject(dc
, old_font
);
1356 ReleaseDC(es
->hwndSelf
, dc
);
1359 /*********************************************************************
1361 * EDIT_CalcLineWidth_SL
1364 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1371 text
= EDIT_GetPasswordPointer_SL(es
);
1373 dc
= GetDC(es
->hwndSelf
);
1375 old_font
= SelectObject(dc
, es
->font
);
1377 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1380 SelectObject(dc
, old_font
);
1381 ReleaseDC(es
->hwndSelf
, dc
);
1383 if (es
->style
& ES_PASSWORD
)
1384 HeapFree(GetProcessHeap(), 0, text
);
1386 es
->text_width
= size
.cx
;
1389 /*********************************************************************
1391 * EDIT_CallWordBreakProc
1393 * Call appropriate WordBreakProc (internal or external).
1395 * Note: The "start" argument should always be an index referring
1396 * to es->text. The actual wordbreak proc might be
1397 * 16 bit, so we can't always pass any 32 bit LPSTR.
1398 * Hence we assume that es->text is the buffer that holds
1399 * the string under examination (we can decide this for ourselves).
1402 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1406 if (es
->word_break_proc16
) {
1413 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1414 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1415 segptr
= WOWGlobalLock16(hglob16
);
1416 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1417 args
[4] = SELECTOROF(segptr
);
1418 args
[3] = OFFSETOF(segptr
);
1422 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1423 ret
= LOWORD(result
);
1424 GlobalUnlock16(hglob16
);
1425 GlobalFree16(hglob16
);
1427 else if (es
->word_break_proc
)
1431 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1433 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1434 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1435 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1439 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1443 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1444 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1445 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1446 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1447 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1448 ret
= wbpA(textA
, index
, countA
, action
);
1449 HeapFree(GetProcessHeap(), 0, textA
);
1453 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1459 /*********************************************************************
1463 * Beware: This is not the function called on EM_CHARFROMPOS
1464 * The position _can_ be outside the formatting / client
1466 * The return value is only the character index
1469 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1474 INT x_high
= 0, x_low
= 0;
1476 if (es
->style
& ES_MULTILINE
) {
1477 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1479 LINEDEF
*line_def
= es
->first_line_def
;
1481 while ((line
> 0) && line_def
->next
) {
1482 line_index
+= line_def
->length
;
1483 line_def
= line_def
->next
;
1486 x
+= es
->x_offset
- es
->format_rect
.left
;
1487 if (es
->style
& ES_RIGHT
)
1488 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1489 else if (es
->style
& ES_CENTER
)
1490 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1491 if (x
>= line_def
->width
) {
1493 *after_wrap
= (line_def
->ending
== END_WRAP
);
1494 return line_index
+ line_def
->net_length
;
1498 *after_wrap
= FALSE
;
1501 dc
= GetDC(es
->hwndSelf
);
1503 old_font
= SelectObject(dc
, es
->font
);
1505 high
= line_index
+ line_def
->net_length
+ 1;
1506 while (low
< high
- 1)
1508 INT mid
= (low
+ high
) / 2;
1509 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1518 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1524 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1525 (line_def
->ending
== END_WRAP
));
1530 *after_wrap
= FALSE
;
1531 x
-= es
->format_rect
.left
;
1533 return es
->x_offset
;
1537 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1538 if (es
->style
& ES_RIGHT
)
1540 else if (es
->style
& ES_CENTER
)
1544 text
= EDIT_GetPasswordPointer_SL(es
);
1545 dc
= GetDC(es
->hwndSelf
);
1547 old_font
= SelectObject(dc
, es
->font
);
1551 INT high
= es
->x_offset
;
1552 while (low
< high
- 1)
1554 INT mid
= (low
+ high
) / 2;
1555 GetTextExtentPoint32W( dc
, text
+ mid
,
1556 es
->x_offset
- mid
, &size
);
1565 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1572 INT low
= es
->x_offset
;
1573 INT high
= strlenW(es
->text
) + 1;
1574 while (low
< high
- 1)
1576 INT mid
= (low
+ high
) / 2;
1577 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1578 mid
- es
->x_offset
, &size
);
1587 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1592 if (es
->style
& ES_PASSWORD
)
1593 HeapFree(GetProcessHeap(), 0, text
);
1596 SelectObject(dc
, old_font
);
1597 ReleaseDC(es
->hwndSelf
, dc
);
1602 /*********************************************************************
1606 * adjusts the point to be within the formatting rectangle
1607 * (so CharFromPos returns the nearest _visible_ character)
1610 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1612 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1613 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1617 /*********************************************************************
1621 * Calculates the bounding rectangle for a line from a starting
1622 * column to an ending column.
1625 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1627 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1629 if (es
->style
& ES_MULTILINE
)
1630 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1632 rc
->top
= es
->format_rect
.top
;
1633 rc
->bottom
= rc
->top
+ es
->line_height
;
1634 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1635 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1639 /*********************************************************************
1641 * EDIT_GetPasswordPointer_SL
1643 * note: caller should free the (optionally) allocated buffer
1646 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1648 if (es
->style
& ES_PASSWORD
) {
1649 INT len
= strlenW(es
->text
);
1650 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1652 while(len
) text
[--len
] = es
->password_char
;
1659 /*********************************************************************
1663 * This acts as a LocalLock16(), but it locks only once. This way
1664 * you can call it whenever you like, without unlocking.
1666 * Initially the edit control allocates a HLOCAL32 buffer
1667 * (32 bit linear memory handler). However, 16 bit application
1668 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1669 * handler). From that moment on we have to keep using this 16 bit memory
1670 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1671 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1675 static void EDIT_LockBuffer(EDITSTATE
*es
)
1677 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
1678 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1683 BOOL _16bit
= FALSE
;
1689 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1690 textA
= LocalLock(es
->hloc32A
);
1691 countA
= strlen(textA
) + 1;
1695 HANDLE16 oldDS
= stack16
->ds
;
1696 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1697 stack16
->ds
= hInstance
;
1698 textA
= MapSL(LocalLock16(es
->hloc16
));
1699 stack16
->ds
= oldDS
;
1700 countA
= strlen(textA
) + 1;
1705 ERR("no buffer ... please report\n");
1712 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1713 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1714 if(countW_new
> es
->buffer_size
+ 1)
1716 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1717 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1718 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1721 es
->hloc32W
= hloc32W_new
;
1722 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1723 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1726 WARN("FAILED! Will synchronize partially\n");
1730 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1731 es
->text
= LocalLock(es
->hloc32W
);
1735 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1738 HANDLE16 oldDS
= stack16
->ds
;
1739 stack16
->ds
= hInstance
;
1740 LocalUnlock16(es
->hloc16
);
1741 stack16
->ds
= oldDS
;
1744 LocalUnlock(es
->hloc32A
);
1751 /*********************************************************************
1753 * EDIT_SL_InvalidateText
1755 * Called from EDIT_InvalidateText().
1756 * Does the job for single-line controls only.
1759 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1764 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1765 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1766 EDIT_UpdateText(es
, &rc
, TRUE
);
1770 /*********************************************************************
1772 * EDIT_ML_InvalidateText
1774 * Called from EDIT_InvalidateText().
1775 * Does the job for multi-line controls only.
1778 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1780 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1781 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1782 INT el
= EDIT_EM_LineFromChar(es
, end
);
1791 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1794 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1795 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1796 if (sl
< es
->y_offset
) {
1800 if (el
> es
->y_offset
+ vlc
) {
1801 el
= es
->y_offset
+ vlc
;
1802 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1804 GetClientRect(es
->hwndSelf
, &rc1
);
1805 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1807 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1808 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1809 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1811 EDIT_GetLineRect(es
, sl
, sc
,
1812 EDIT_EM_LineLength(es
,
1813 EDIT_EM_LineIndex(es
, sl
)),
1815 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1816 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1817 for (l
= sl
+ 1 ; l
< el
; l
++) {
1818 EDIT_GetLineRect(es
, l
, 0,
1819 EDIT_EM_LineLength(es
,
1820 EDIT_EM_LineIndex(es
, l
)),
1822 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1823 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1825 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1826 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1827 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1832 /*********************************************************************
1834 * EDIT_InvalidateText
1836 * Invalidate the text from offset start up to, but not including,
1837 * offset end. Useful for (re)painting the selection.
1838 * Regions outside the linewidth are not invalidated.
1839 * end == -1 means end == TextLength.
1840 * start and end need not be ordered.
1843 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1849 end
= strlenW(es
->text
);
1857 if (es
->style
& ES_MULTILINE
)
1858 EDIT_ML_InvalidateText(es
, start
, end
);
1860 EDIT_SL_InvalidateText(es
, start
, end
);
1864 /*********************************************************************
1868 * Try to fit size + 1 characters in the buffer.
1870 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1874 if (size
<= es
->buffer_size
)
1877 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1879 /* Force edit to unlock it's buffer. es->text now NULL */
1880 EDIT_UnlockBuffer(es
, TRUE
);
1883 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1884 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1885 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1886 es
->hloc32W
= hNew32W
;
1887 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1891 EDIT_LockBuffer(es
);
1893 if (es
->buffer_size
< size
) {
1894 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1895 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1898 TRACE("We now have %d+1\n", es
->buffer_size
);
1904 /*********************************************************************
1908 * Try to fit size + 1 bytes in the undo buffer.
1911 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1915 if (size
<= es
->undo_buffer_size
)
1918 TRACE("trying to ReAlloc to %d+1\n", size
);
1920 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1921 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1922 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1927 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1933 /*********************************************************************
1938 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1940 INT e
= es
->selection_end
;
1944 if ((es
->style
& ES_MULTILINE
) && e
&&
1945 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1947 if (e
&& (es
->text
[e
- 1] == '\r'))
1951 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1952 EDIT_EM_ScrollCaret(es
);
1956 /*********************************************************************
1960 * Only for multi line controls
1961 * Move the caret one line down, on a column with the nearest
1962 * x coordinate on the screen (might be a different column).
1965 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1967 INT s
= es
->selection_start
;
1968 INT e
= es
->selection_end
;
1969 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1970 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1971 INT x
= (short)LOWORD(pos
);
1972 INT y
= (short)HIWORD(pos
);
1974 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1977 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1978 EDIT_EM_ScrollCaret(es
);
1982 /*********************************************************************
1987 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1989 BOOL after_wrap
= FALSE
;
1992 /* Pass a high value in x to make sure of receiving the end of the line */
1993 if (es
->style
& ES_MULTILINE
)
1994 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1995 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1997 e
= strlenW(es
->text
);
1998 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1999 EDIT_EM_ScrollCaret(es
);
2003 /*********************************************************************
2008 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2010 INT e
= es
->selection_end
;
2014 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2015 if (es
->text
[e
] == '\n')
2017 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2021 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2022 EDIT_EM_ScrollCaret(es
);
2026 /*********************************************************************
2030 * Home key: move to beginning of line.
2033 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2037 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2038 if (es
->style
& ES_MULTILINE
)
2039 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2040 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2043 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2044 EDIT_EM_ScrollCaret(es
);
2048 /*********************************************************************
2050 * EDIT_MovePageDown_ML
2052 * Only for multi line controls
2053 * Move the caret one page down, on a column with the nearest
2054 * x coordinate on the screen (might be a different column).
2057 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2059 INT s
= es
->selection_start
;
2060 INT e
= es
->selection_end
;
2061 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2062 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2063 INT x
= (short)LOWORD(pos
);
2064 INT y
= (short)HIWORD(pos
);
2066 e
= EDIT_CharFromPos(es
, x
,
2067 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2071 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2072 EDIT_EM_ScrollCaret(es
);
2076 /*********************************************************************
2078 * EDIT_MovePageUp_ML
2080 * Only for multi line controls
2081 * Move the caret one page up, on a column with the nearest
2082 * x coordinate on the screen (might be a different column).
2085 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2087 INT s
= es
->selection_start
;
2088 INT e
= es
->selection_end
;
2089 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2090 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2091 INT x
= (short)LOWORD(pos
);
2092 INT y
= (short)HIWORD(pos
);
2094 e
= EDIT_CharFromPos(es
, x
,
2095 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2099 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2100 EDIT_EM_ScrollCaret(es
);
2104 /*********************************************************************
2108 * Only for multi line controls
2109 * Move the caret one line up, on a column with the nearest
2110 * x coordinate on the screen (might be a different column).
2113 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2115 INT s
= es
->selection_start
;
2116 INT e
= es
->selection_end
;
2117 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2118 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2119 INT x
= (short)LOWORD(pos
);
2120 INT y
= (short)HIWORD(pos
);
2122 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2125 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2126 EDIT_EM_ScrollCaret(es
);
2130 /*********************************************************************
2132 * EDIT_MoveWordBackward
2135 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2137 INT s
= es
->selection_start
;
2138 INT e
= es
->selection_end
;
2143 l
= EDIT_EM_LineFromChar(es
, e
);
2144 ll
= EDIT_EM_LineLength(es
, e
);
2145 li
= EDIT_EM_LineIndex(es
, l
);
2148 li
= EDIT_EM_LineIndex(es
, l
- 1);
2149 e
= li
+ EDIT_EM_LineLength(es
, li
);
2152 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2153 li
, e
- li
, ll
, WB_LEFT
);
2157 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2158 EDIT_EM_ScrollCaret(es
);
2162 /*********************************************************************
2164 * EDIT_MoveWordForward
2167 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2169 INT s
= es
->selection_start
;
2170 INT e
= es
->selection_end
;
2175 l
= EDIT_EM_LineFromChar(es
, e
);
2176 ll
= EDIT_EM_LineLength(es
, e
);
2177 li
= EDIT_EM_LineIndex(es
, l
);
2179 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2180 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2182 e
= li
+ EDIT_CallWordBreakProc(es
,
2183 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2187 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2188 EDIT_EM_ScrollCaret(es
);
2192 /*********************************************************************
2197 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2199 INT s
= es
->selection_start
;
2200 INT e
= es
->selection_end
;
2207 if (es
->style
& ES_MULTILINE
) {
2208 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2209 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2214 TRACE("line=%d\n", line
);
2216 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2217 x
= (short)LOWORD(pos
);
2218 y
= (short)HIWORD(pos
);
2219 li
= EDIT_EM_LineIndex(es
, line
);
2220 ll
= EDIT_EM_LineLength(es
, li
);
2221 s
= min(es
->selection_start
, es
->selection_end
);
2222 e
= max(es
->selection_start
, es
->selection_end
);
2223 s
= min(li
+ ll
, max(li
, s
));
2224 e
= min(li
+ ll
, max(li
, e
));
2225 if (rev
&& (s
!= e
) &&
2226 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2227 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2228 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2229 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2231 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2235 /*********************************************************************
2240 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2244 LOGFONTW underline_font
;
2245 HFONT hUnderline
= 0;
2254 BkMode
= GetBkMode(dc
);
2255 BkColor
= GetBkColor(dc
);
2256 TextColor
= GetTextColor(dc
);
2258 if (es
->composition_len
== 0)
2260 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2261 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2262 SetBkMode( dc
, OPAQUE
);
2266 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2267 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2268 underline_font
.lfUnderline
= TRUE
;
2269 hUnderline
= CreateFontIndirectW(&underline_font
);
2270 old_font
= SelectObject(dc
,hUnderline
);
2273 li
= EDIT_EM_LineIndex(es
, line
);
2274 if (es
->style
& ES_MULTILINE
) {
2275 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2276 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2278 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2279 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2280 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2282 if (es
->style
& ES_PASSWORD
)
2283 HeapFree(GetProcessHeap(), 0, text
);
2286 if (es
->composition_len
== 0)
2288 SetBkColor(dc
, BkColor
);
2289 SetTextColor(dc
, TextColor
);
2290 SetBkMode( dc
, BkMode
);
2295 SelectObject(dc
,old_font
);
2297 DeleteObject(hUnderline
);
2304 /*********************************************************************
2309 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2312 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2313 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2314 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2318 /*********************************************************************
2320 * EDIT_AdjustFormatRect
2322 * Adjusts the format rectangle for the current font and the
2323 * current client rectangle.
2326 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2330 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2331 if (es
->style
& ES_MULTILINE
)
2333 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2335 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2336 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2338 /* correct es->x_offset */
2339 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2340 max_x_offset
= es
->text_width
- fw
;
2341 if(max_x_offset
< 0) max_x_offset
= 0;
2342 if(es
->x_offset
> max_x_offset
)
2343 es
->x_offset
= max_x_offset
;
2345 /* correct es->y_offset */
2346 max_y_offset
= es
->line_count
- vlc
;
2347 if(max_y_offset
< 0) max_y_offset
= 0;
2348 if(es
->y_offset
> max_y_offset
)
2349 es
->y_offset
= max_y_offset
;
2351 /* force scroll info update */
2352 EDIT_UpdateScrollInfo(es
);
2355 /* Windows doesn't care to fix text placement for SL controls */
2356 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2358 /* Always stay within the client area */
2359 GetClientRect(es
->hwndSelf
, &ClientRect
);
2360 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2362 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2363 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2365 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2369 /*********************************************************************
2373 * note: this is not (exactly) the handler called on EM_SETRECTNP
2374 * it is also used to set the rect of a single line control
2377 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2381 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2383 CopyRect(&es
->format_rect
, rc
);
2385 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2386 es
->format_rect
.left
++;
2387 es
->format_rect
.right
--;
2389 if (es
->format_rect
.bottom
- es
->format_rect
.top
2390 >= es
->line_height
+ 2)
2392 es
->format_rect
.top
++;
2393 es
->format_rect
.bottom
--;
2396 else if (es
->style
& WS_BORDER
) {
2397 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2398 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2399 es
->format_rect
.left
+= bw
;
2400 es
->format_rect
.right
-= bw
;
2401 if (es
->format_rect
.bottom
- es
->format_rect
.top
2402 >= es
->line_height
+ 2 * bh
)
2404 es
->format_rect
.top
+= bh
;
2405 es
->format_rect
.bottom
-= bh
;
2409 es
->format_rect
.left
+= es
->left_margin
;
2410 es
->format_rect
.right
-= es
->right_margin
;
2411 EDIT_AdjustFormatRect(es
);
2415 /*********************************************************************
2420 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2423 /* Edit window might be already destroyed */
2424 if(!IsWindow(es
->hwndSelf
))
2426 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2430 if (!es
->lock_count
) {
2431 ERR("lock_count == 0 ... please report\n");
2435 ERR("es->text == 0 ... please report\n");
2439 if (force
|| (es
->lock_count
== 1)) {
2443 UINT countW
= strlenW(es
->text
) + 1;
2444 STACK16FRAME
* stack16
= NULL
;
2449 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2450 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2451 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2452 countA
= LocalSize(es
->hloc32A
);
2453 if(countA_new
> countA
)
2456 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2457 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2458 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2461 es
->hloc32A
= hloc32A_new
;
2462 countA
= LocalSize(hloc32A_new
);
2463 TRACE("Real new size %d bytes\n", countA
);
2466 WARN("FAILED! Will synchronize partially\n");
2468 textA
= LocalLock(es
->hloc32A
);
2472 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2474 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2475 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2477 stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
2478 oldDS
= stack16
->ds
;
2479 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2481 countA
= LocalSize16(es
->hloc16
);
2482 if(countA_new
> countA
)
2484 HLOCAL16 hloc16_new
;
2485 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2486 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2487 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2490 es
->hloc16
= hloc16_new
;
2491 countA
= LocalSize16(hloc16_new
);
2492 TRACE("Real new size %d bytes\n", countA
);
2495 WARN("FAILED! Will synchronize partially\n");
2497 textA
= MapSL(LocalLock16(es
->hloc16
));
2502 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2504 LocalUnlock16(es
->hloc16
);
2506 LocalUnlock(es
->hloc32A
);
2509 if (stack16
) stack16
->ds
= oldDS
;
2510 LocalUnlock(es
->hloc32W
);
2514 ERR("no buffer ... please report\n");
2522 /*********************************************************************
2524 * EDIT_UpdateScrollInfo
2527 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2529 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2532 si
.cbSize
= sizeof(SCROLLINFO
);
2533 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2535 si
.nMax
= es
->line_count
- 1;
2536 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2537 si
.nPos
= es
->y_offset
;
2538 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2539 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2540 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2543 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2546 si
.cbSize
= sizeof(SCROLLINFO
);
2547 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2549 si
.nMax
= es
->text_width
- 1;
2550 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2551 si
.nPos
= es
->x_offset
;
2552 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2553 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2554 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2558 /*********************************************************************
2560 * EDIT_WordBreakProc
2562 * Find the beginning of words.
2563 * Note: unlike the specs for a WordBreakProc, this function only
2564 * allows to be called without linebreaks between s[0] up to
2565 * s[count - 1]. Remember it is only called
2566 * internally, so we can decide this for ourselves.
2569 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2573 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2583 if (s
[index
] == ' ') {
2584 while (index
&& (s
[index
] == ' '))
2587 while (index
&& (s
[index
] != ' '))
2589 if (s
[index
] == ' ')
2593 while (index
&& (s
[index
] != ' '))
2595 if (s
[index
] == ' ')
2605 if (s
[index
] == ' ')
2606 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2608 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2610 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2614 case WB_ISDELIMITER
:
2615 ret
= (s
[index
] == ' ');
2618 ERR("unknown action code, please report !\n");
2625 /*********************************************************************
2629 * returns line number (not index) in high-order word of result.
2630 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2631 * to Richedit, not to the edit control. Original documentation is valid.
2632 * FIXME: do the specs mean to return -1 if outside client area or
2633 * if outside formatting rectangle ???
2636 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2644 GetClientRect(es
->hwndSelf
, &rc
);
2645 if (!PtInRect(&rc
, pt
))
2648 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2649 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2653 /*********************************************************************
2657 * Enable or disable soft breaks.
2659 * This means: insert or remove the soft linebreak character (\r\r\n).
2660 * Take care to check if the text still fits the buffer after insertion.
2661 * If not, notify with EN_ERRSPACE.
2664 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2666 es
->flags
&= ~EF_USE_SOFTBRK
;
2668 es
->flags
|= EF_USE_SOFTBRK
;
2669 FIXME("soft break enabled, not implemented\n");
2675 /*********************************************************************
2679 * Hopefully this won't fire back at us.
2680 * We always start with a fixed buffer in the local heap.
2681 * Despite of the documentation says that the local heap is used
2682 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2683 * buffer on the local heap.
2686 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2690 if (!(es
->style
& ES_MULTILINE
))
2694 hLocal
= es
->hloc32W
;
2700 UINT countA
, alloc_size
;
2701 TRACE("Allocating 32-bit ANSI alias buffer\n");
2702 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2703 alloc_size
= ROUND_TO_GROW(countA
);
2704 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2706 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2709 textA
= LocalLock(es
->hloc32A
);
2710 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2711 LocalUnlock(es
->hloc32A
);
2713 hLocal
= es
->hloc32A
;
2716 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2721 /*********************************************************************
2725 * Hopefully this won't fire back at us.
2726 * We always start with a buffer in 32 bit linear memory.
2727 * However, with this message a 16 bit application requests
2728 * a handle of 16 bit local heap memory, where it expects to find
2730 * It's a pitty that from this moment on we have to use this
2731 * local heap, because applications may rely on the handle
2734 * In this function we'll try to switch to local heap.
2736 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2739 UINT countA
, alloc_size
;
2740 STACK16FRAME
* stack16
;
2743 if (!(es
->style
& ES_MULTILINE
))
2749 stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
2750 oldDS
= stack16
->ds
;
2751 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2753 if (!LocalHeapSize16()) {
2755 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2756 ERR("could not initialize local heap\n");
2759 TRACE("local heap initialized\n");
2762 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2763 alloc_size
= ROUND_TO_GROW(countA
);
2765 TRACE("Allocating 16-bit ANSI alias buffer\n");
2766 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2767 ERR("could not allocate new 16 bit buffer\n");
2771 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2772 ERR("could not lock new 16 bit buffer\n");
2773 LocalFree16(es
->hloc16
);
2778 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2779 LocalUnlock16(es
->hloc16
);
2781 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2784 stack16
->ds
= oldDS
;
2789 /*********************************************************************
2794 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2797 INT line_len
, dst_len
;
2800 if (es
->style
& ES_MULTILINE
) {
2801 if (line
>= es
->line_count
)
2805 i
= EDIT_EM_LineIndex(es
, line
);
2807 line_len
= EDIT_EM_LineLength(es
, i
);
2808 dst_len
= *(WORD
*)dst
;
2811 if(dst_len
<= line_len
)
2813 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2816 else /* Append 0 if enough space */
2818 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2825 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2826 if(!ret
&& line_len
) /* Insufficient buffer size */
2828 if(ret
< dst_len
) /* Append 0 if enough space */
2829 ((LPSTR
)dst
)[ret
] = 0;
2835 /*********************************************************************
2840 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2842 UINT s
= es
->selection_start
;
2843 UINT e
= es
->selection_end
;
2850 return MAKELONG(s
, e
);
2854 /*********************************************************************
2858 * FIXME: is this right ? (or should it be only VSCROLL)
2859 * (and maybe only for edit controls that really have their
2860 * own scrollbars) (and maybe only for multiline controls ?)
2861 * All in all: very poorly documented
2864 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2866 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2867 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2871 /*********************************************************************
2876 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2881 if (!(es
->style
& ES_MULTILINE
))
2883 if (index
> (INT
)strlenW(es
->text
))
2884 return es
->line_count
- 1;
2886 index
= min(es
->selection_start
, es
->selection_end
);
2889 line_def
= es
->first_line_def
;
2890 index
-= line_def
->length
;
2891 while ((index
>= 0) && line_def
->next
) {
2893 line_def
= line_def
->next
;
2894 index
-= line_def
->length
;
2900 /*********************************************************************
2905 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2910 if (!(es
->style
& ES_MULTILINE
))
2912 if (line
>= es
->line_count
)
2916 line_def
= es
->first_line_def
;
2918 INT index
= es
->selection_end
- line_def
->length
;
2919 while ((index
>= 0) && line_def
->next
) {
2920 line_index
+= line_def
->length
;
2921 line_def
= line_def
->next
;
2922 index
-= line_def
->length
;
2926 line_index
+= line_def
->length
;
2927 line_def
= line_def
->next
;
2935 /*********************************************************************
2940 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2944 if (!(es
->style
& ES_MULTILINE
))
2945 return strlenW(es
->text
);
2948 /* get the number of remaining non-selected chars of selected lines */
2949 INT32 l
; /* line number */
2950 INT32 li
; /* index of first char in line */
2952 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2953 /* # chars before start of selection area */
2954 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2955 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2956 /* # chars after end of selection */
2957 li
= EDIT_EM_LineIndex(es
, l
);
2958 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2961 line_def
= es
->first_line_def
;
2962 index
-= line_def
->length
;
2963 while ((index
>= 0) && line_def
->next
) {
2964 line_def
= line_def
->next
;
2965 index
-= line_def
->length
;
2967 return line_def
->net_length
;
2971 /*********************************************************************
2975 * NOTE: dx is in average character widths, dy - in lines;
2978 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2980 if (!(es
->style
& ES_MULTILINE
))
2983 dx
*= es
->char_width
;
2984 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2987 /*********************************************************************
2989 * EDIT_EM_LineScroll_internal
2991 * Version of EDIT_EM_LineScroll for internal use.
2992 * It doesn't refuse if ES_MULTILINE is set and assumes that
2993 * dx is in pixels, dy - in lines.
2996 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2999 INT x_offset_in_pixels
;
3000 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3003 if (es
->style
& ES_MULTILINE
)
3005 x_offset_in_pixels
= es
->x_offset
;
3010 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3013 if (-dx
> x_offset_in_pixels
)
3014 dx
= -x_offset_in_pixels
;
3015 if (dx
> es
->text_width
- x_offset_in_pixels
)
3016 dx
= es
->text_width
- x_offset_in_pixels
;
3017 nyoff
= max(0, es
->y_offset
+ dy
);
3018 if (nyoff
>= es
->line_count
- lines_per_page
)
3019 nyoff
= max(0, es
->line_count
- lines_per_page
);
3020 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3025 es
->y_offset
= nyoff
;
3026 if(es
->style
& ES_MULTILINE
)
3029 es
->x_offset
+= dx
/ es
->char_width
;
3031 GetClientRect(es
->hwndSelf
, &rc1
);
3032 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3033 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3034 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3035 /* force scroll info update */
3036 EDIT_UpdateScrollInfo(es
);
3038 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3039 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3040 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3041 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3046 /*********************************************************************
3051 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3053 INT len
= strlenW(es
->text
);
3066 index
= min(index
, len
);
3067 dc
= GetDC(es
->hwndSelf
);
3069 old_font
= SelectObject(dc
, es
->font
);
3070 if (es
->style
& ES_MULTILINE
) {
3071 l
= EDIT_EM_LineFromChar(es
, index
);
3072 y
= (l
- es
->y_offset
) * es
->line_height
;
3073 li
= EDIT_EM_LineIndex(es
, l
);
3074 if (after_wrap
&& (li
== index
) && l
) {
3076 line_def
= es
->first_line_def
;
3078 line_def
= line_def
->next
;
3081 if (line_def
->ending
== END_WRAP
) {
3083 y
-= es
->line_height
;
3084 li
= EDIT_EM_LineIndex(es
, l
);
3088 line_def
= es
->first_line_def
;
3089 while (line_def
->index
!= li
)
3090 line_def
= line_def
->next
;
3092 ll
= line_def
->net_length
;
3093 lw
= line_def
->width
;
3095 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3096 if (es
->style
& ES_RIGHT
)
3098 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3099 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3102 else if (es
->style
& ES_CENTER
)
3104 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3105 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3110 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3111 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3114 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3115 if (index
< es
->x_offset
) {
3116 GetTextExtentPoint32W(dc
, text
+ index
,
3117 es
->x_offset
- index
, &size
);
3120 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3121 index
- es
->x_offset
, &size
);
3124 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3126 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3127 if (w
> es
->text_width
)
3129 if (es
->style
& ES_RIGHT
)
3130 x
+= w
- es
->text_width
;
3131 else if (es
->style
& ES_CENTER
)
3132 x
+= (w
- es
->text_width
) / 2;
3137 if (es
->style
& ES_PASSWORD
)
3138 HeapFree(GetProcessHeap(), 0, text
);
3140 x
+= es
->format_rect
.left
;
3141 y
+= es
->format_rect
.top
;
3143 SelectObject(dc
, old_font
);
3144 ReleaseDC(es
->hwndSelf
, dc
);
3145 return MAKELONG((INT16
)x
, (INT16
)y
);
3149 /*********************************************************************
3153 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3156 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3158 UINT strl
= strlenW(lpsz_replace
);
3159 UINT tl
= strlenW(es
->text
);
3170 TRACE("%s, can_undo %d, send_update %d\n",
3171 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3173 s
= es
->selection_start
;
3174 e
= es
->selection_end
;
3176 if ((s
== e
) && !strl
)
3181 size
= tl
- (e
- s
) + strl
;
3185 /* Issue the EN_MAXTEXT notification and continue with replacing text
3186 * such that buffer limit is honored. */
3187 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
3188 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3189 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3192 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3196 /* there is something to be deleted */
3197 TRACE("deleting stuff.\n");
3199 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3201 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3202 buf
[bufl
] = 0; /* ensure 0 termination */
3204 strcpyW(es
->text
+ s
, es
->text
+ e
);
3207 /* there is an insertion */
3208 tl
= strlenW(es
->text
);
3209 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
));
3210 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3212 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3213 p
[i
] = lpsz_replace
[i
];
3214 if(es
->style
& ES_UPPERCASE
)
3215 CharUpperBuffW(p
, strl
);
3216 else if(es
->style
& ES_LOWERCASE
)
3217 CharLowerBuffW(p
, strl
);
3219 if (es
->style
& ES_MULTILINE
)
3221 INT st
= min(es
->selection_start
, es
->selection_end
);
3222 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3224 hrgn
= CreateRectRgn(0, 0, 0, 0);
3225 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3226 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3227 /* if text is too long undo all changes */
3228 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3230 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3232 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3234 EDIT_BuildLineDefs_ML(es
, s
, e
,
3235 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3238 hrgn
= CreateRectRgn(0, 0, 0, 0);
3239 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3243 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3244 EDIT_CalcLineWidth_SL(es
);
3245 /* remove chars that don't fit */
3246 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3247 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3248 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3250 EDIT_CalcLineWidth_SL(es
);
3252 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3258 utl
= strlenW(es
->undo_text
);
3259 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3260 /* undo-buffer is extended to the right */
3261 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3262 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3263 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3264 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3265 /* undo-buffer is extended to the left */
3266 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3267 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3269 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3271 es
->undo_position
= s
;
3273 /* new undo-buffer */
3274 EDIT_MakeUndoFit(es
, e
- s
);
3275 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3276 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3277 es
->undo_position
= s
;
3279 /* any deletion makes the old insertion-undo invalid */
3280 es
->undo_insert_count
= 0;
3282 EDIT_EM_EmptyUndoBuffer(es
);
3286 if ((s
== es
->undo_position
) ||
3287 ((es
->undo_insert_count
) &&
3288 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3290 * insertion is new and at delete position or
3291 * an extension to either left or right
3293 es
->undo_insert_count
+= strl
;
3295 /* new insertion undo */
3296 es
->undo_position
= s
;
3297 es
->undo_insert_count
= strl
;
3298 /* new insertion makes old delete-buffer invalid */
3299 *es
->undo_text
= '\0';
3302 EDIT_EM_EmptyUndoBuffer(es
);
3306 HeapFree(GetProcessHeap(), 0, buf
);
3310 /* If text has been deleted and we're right or center aligned then scroll rightward */
3311 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3313 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3315 if (delta
< 0 && es
->x_offset
)
3317 if (abs(delta
) > es
->x_offset
)
3320 es
->x_offset
+= delta
;
3324 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3325 es
->flags
|= EF_MODIFIED
;
3326 if (send_update
) es
->flags
|= EF_UPDATE
;
3329 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3333 EDIT_UpdateText(es
, NULL
, TRUE
);
3335 EDIT_EM_ScrollCaret(es
);
3337 /* force scroll info update */
3338 EDIT_UpdateScrollInfo(es
);
3341 if(send_update
|| (es
->flags
& EF_UPDATE
))
3343 es
->flags
&= ~EF_UPDATE
;
3344 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3349 /*********************************************************************
3354 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3358 if (!(es
->style
& ES_MULTILINE
))
3359 return (LRESULT
)FALSE
;
3369 if (es
->y_offset
< es
->line_count
- 1)
3374 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3377 if (es
->y_offset
< es
->line_count
- 1)
3378 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3381 return (LRESULT
)FALSE
;
3384 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3385 /* check if we are going to move too far */
3386 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3387 dy
= es
->line_count
- vlc
- es
->y_offset
;
3389 /* Notification is done in EDIT_EM_LineScroll */
3391 EDIT_EM_LineScroll(es
, 0, dy
);
3393 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3397 /*********************************************************************
3402 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3404 if (es
->style
& ES_MULTILINE
) {
3409 INT cw
= es
->char_width
;
3414 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3415 li
= EDIT_EM_LineIndex(es
, l
);
3416 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3417 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3418 if (l
>= es
->y_offset
+ vlc
)
3419 dy
= l
- vlc
+ 1 - es
->y_offset
;
3420 if (l
< es
->y_offset
)
3421 dy
= l
- es
->y_offset
;
3422 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3423 if (x
< es
->format_rect
.left
)
3424 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3425 if (x
> es
->format_rect
.right
)
3426 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3427 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3429 /* check if we are going to move too far */
3430 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3431 dx
= es
->text_width
- ww
- es
->x_offset
;
3432 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3433 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3440 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3441 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3442 if (x
< es
->format_rect
.left
) {
3443 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3446 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3447 } while ((x
< goal
) && es
->x_offset
);
3448 /* FIXME: use ScrollWindow() somehow to improve performance */
3449 EDIT_UpdateText(es
, NULL
, TRUE
);
3450 } else if (x
> es
->format_rect
.right
) {
3452 INT len
= strlenW(es
->text
);
3453 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3456 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3457 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3458 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3459 /* FIXME: use ScrollWindow() somehow to improve performance */
3460 EDIT_UpdateText(es
, NULL
, TRUE
);
3464 if(es
->flags
& EF_FOCUSED
)
3465 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3469 /*********************************************************************
3473 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3476 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3478 if (!(es
->style
& ES_MULTILINE
))
3482 WARN("called with NULL handle\n");
3486 EDIT_UnlockBuffer(es
, TRUE
);
3490 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
3491 HANDLE16 oldDS
= stack16
->ds
;
3493 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3494 LocalFree16(es
->hloc16
);
3495 stack16
->ds
= oldDS
;
3503 LocalFree(es
->hloc32A
);
3515 countA
= LocalSize(hloc
);
3516 textA
= LocalLock(hloc
);
3517 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3518 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3520 ERR("Could not allocate new unicode buffer\n");
3523 textW
= LocalLock(hloc32W_new
);
3524 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3525 LocalUnlock(hloc32W_new
);
3529 LocalFree(es
->hloc32W
);
3531 es
->hloc32W
= hloc32W_new
;
3535 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3537 EDIT_LockBuffer(es
);
3539 es
->x_offset
= es
->y_offset
= 0;
3540 es
->selection_start
= es
->selection_end
= 0;
3541 EDIT_EM_EmptyUndoBuffer(es
);
3542 es
->flags
&= ~EF_MODIFIED
;
3543 es
->flags
&= ~EF_UPDATE
;
3544 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3545 EDIT_UpdateText(es
, NULL
, TRUE
);
3546 EDIT_EM_ScrollCaret(es
);
3547 /* force scroll info update */
3548 EDIT_UpdateScrollInfo(es
);
3552 /*********************************************************************
3556 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3559 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3561 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
3562 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3563 HANDLE16 oldDS
= stack16
->ds
;
3569 if (!(es
->style
& ES_MULTILINE
))
3573 WARN("called with NULL handle\n");
3577 EDIT_UnlockBuffer(es
, TRUE
);
3581 LocalFree(es
->hloc32A
);
3585 stack16
->ds
= hInstance
;
3586 countA
= LocalSize16(hloc
);
3587 textA
= MapSL(LocalLock16(hloc
));
3588 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3589 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3591 ERR("Could not allocate new unicode buffer\n");
3594 textW
= LocalLock(hloc32W_new
);
3595 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3596 LocalUnlock(hloc32W_new
);
3597 LocalUnlock16(hloc
);
3598 stack16
->ds
= oldDS
;
3601 LocalFree(es
->hloc32W
);
3603 es
->hloc32W
= hloc32W_new
;
3606 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3608 EDIT_LockBuffer(es
);
3610 es
->x_offset
= es
->y_offset
= 0;
3611 es
->selection_start
= es
->selection_end
= 0;
3612 EDIT_EM_EmptyUndoBuffer(es
);
3613 es
->flags
&= ~EF_MODIFIED
;
3614 es
->flags
&= ~EF_UPDATE
;
3615 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3616 EDIT_UpdateText(es
, NULL
, TRUE
);
3617 EDIT_EM_ScrollCaret(es
);
3618 /* force scroll info update */
3619 EDIT_UpdateScrollInfo(es
);
3623 /*********************************************************************
3627 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3628 * However, the windows version is not complied to yet in all of edit.c
3630 * Additionally as the wrapper for RichEdit controls we need larger buffers
3631 * at present -1 will represent nolimit
3633 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3635 if (limit
== 0xFFFFFFFF)
3636 es
->buffer_limit
= -1;
3637 else if (es
->style
& ES_MULTILINE
) {
3639 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3641 es
->buffer_limit
= BUFLIMIT_MULTI
;
3644 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3646 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3651 /*********************************************************************
3655 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3656 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3657 * margin according to the textmetrics of the current font.
3659 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3660 * of the char's width as the margin, but this is not how Windows handles this.
3661 * For all other fonts Windows sets the margins to zero.
3663 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3664 * edit control is equal to or larger than a certain size.
3665 * Interestingly if one subtracts both the left and right margins from
3666 * this size one always seems to get an even number. The extents of
3667 * the (four character) string "'**'" match this quite closely, so
3668 * we'll use this until we come up with a better idea.
3670 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3672 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3675 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3676 return sz
.cx
+ left
+ right
;
3679 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3680 WORD left
, WORD right
, BOOL repaint
)
3683 INT default_left_margin
= 0; /* in pixels */
3684 INT default_right_margin
= 0; /* in pixels */
3686 /* Set the default margins depending on the font */
3687 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3688 HDC dc
= GetDC(es
->hwndSelf
);
3689 HFONT old_font
= SelectObject(dc
, es
->font
);
3690 GetTextMetricsW(dc
, &tm
);
3691 /* The default margins are only non zero for TrueType or Vector fonts */
3692 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3695 /* This must be calculated more exactly! But how? */
3696 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3697 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3698 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3699 GetClientRect(es
->hwndSelf
, &rc
);
3700 if(rc
.right
- rc
.left
< min_size
) {
3701 default_left_margin
= es
->left_margin
;
3702 default_right_margin
= es
->right_margin
;
3705 SelectObject(dc
, old_font
);
3706 ReleaseDC(es
->hwndSelf
, dc
);
3709 if (action
& EC_LEFTMARGIN
) {
3710 es
->format_rect
.left
-= es
->left_margin
;
3711 if (left
!= EC_USEFONTINFO
)
3712 es
->left_margin
= left
;
3714 es
->left_margin
= default_left_margin
;
3715 es
->format_rect
.left
+= es
->left_margin
;
3718 if (action
& EC_RIGHTMARGIN
) {
3719 es
->format_rect
.right
+= es
->right_margin
;
3720 if (right
!= EC_USEFONTINFO
)
3721 es
->right_margin
= right
;
3723 es
->right_margin
= default_right_margin
;
3724 es
->format_rect
.right
-= es
->right_margin
;
3727 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3728 EDIT_AdjustFormatRect(es
);
3729 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3732 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3736 /*********************************************************************
3738 * EM_SETPASSWORDCHAR
3741 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3745 if (es
->style
& ES_MULTILINE
)
3748 if (es
->password_char
== c
)
3751 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3752 es
->password_char
= c
;
3754 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3755 es
->style
|= ES_PASSWORD
;
3757 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3758 es
->style
&= ~ES_PASSWORD
;
3760 EDIT_UpdateText(es
, NULL
, TRUE
);
3764 /*********************************************************************
3768 * note: unlike the specs say: the order of start and end
3769 * _is_ preserved in Windows. (i.e. start can be > end)
3770 * In other words: this handler is OK
3773 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3775 UINT old_start
= es
->selection_start
;
3776 UINT old_end
= es
->selection_end
;
3777 UINT len
= strlenW(es
->text
);
3779 if (start
== (UINT
)-1) {
3780 start
= es
->selection_end
;
3781 end
= es
->selection_end
;
3783 start
= min(start
, len
);
3784 end
= min(end
, len
);
3786 es
->selection_start
= start
;
3787 es
->selection_end
= end
;
3789 es
->flags
|= EF_AFTER_WRAP
;
3791 es
->flags
&= ~EF_AFTER_WRAP
;
3792 /* Compute the necessary invalidation region. */
3793 /* Note that we don't need to invalidate regions which have
3794 * "never" been selected, or those which are "still" selected.
3795 * In fact, every time we hit a selection boundary, we can
3796 * *toggle* whether we need to invalidate. Thus we can optimize by
3797 * *sorting* the interval endpoints. Let's assume that we sort them
3799 * start <= end <= old_start <= old_end
3800 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3801 * in 5 comparisons; ie it's impossible to do better than the
3803 ORDER_UINT(end
, old_end
);
3804 ORDER_UINT(start
, old_start
);
3805 ORDER_UINT(old_start
, old_end
);
3806 ORDER_UINT(start
, end
);
3807 /* Note that at this point 'end' and 'old_start' are not in order, but
3808 * start is definitely the min. and old_end is definitely the max. */
3809 if (end
!= old_start
)
3813 * ORDER_UINT32(end, old_start);
3814 * EDIT_InvalidateText(es, start, end);
3815 * EDIT_InvalidateText(es, old_start, old_end);
3816 * in place of the following if statement.
3817 * (That would complete the optimal five-comparison four-element sort.)
3819 if (old_start
> end
)
3821 EDIT_InvalidateText(es
, start
, end
);
3822 EDIT_InvalidateText(es
, old_start
, old_end
);
3826 EDIT_InvalidateText(es
, start
, old_start
);
3827 EDIT_InvalidateText(es
, end
, old_end
);
3830 else EDIT_InvalidateText(es
, start
, old_end
);
3834 /*********************************************************************
3839 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3841 if (!(es
->style
& ES_MULTILINE
))
3843 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3844 es
->tabs_count
= count
;
3848 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3849 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3855 /*********************************************************************
3860 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3862 if (!(es
->style
& ES_MULTILINE
))
3864 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3865 es
->tabs_count
= count
;
3870 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3871 for (i
= 0 ; i
< count
; i
++)
3872 es
->tabs
[i
] = *tabs
++;
3878 /*********************************************************************
3880 * EM_SETWORDBREAKPROC
3883 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3885 if (es
->word_break_proc
== wbp
)
3888 es
->word_break_proc
= wbp
;
3889 es
->word_break_proc16
= NULL
;
3891 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3892 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3893 EDIT_UpdateText(es
, NULL
, TRUE
);
3898 /*********************************************************************
3900 * EM_SETWORDBREAKPROC16
3903 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3905 if (es
->word_break_proc16
== wbp
)
3908 es
->word_break_proc
= NULL
;
3909 es
->word_break_proc16
= wbp
;
3910 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3911 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3912 EDIT_UpdateText(es
, NULL
, TRUE
);
3917 /*********************************************************************
3922 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3927 /* As per MSDN spec, for a single-line edit control,
3928 the return value is always TRUE */
3929 if( es
->style
& ES_READONLY
)
3930 return !(es
->style
& ES_MULTILINE
);
3932 ulength
= strlenW(es
->undo_text
);
3934 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3936 strcpyW(utext
, es
->undo_text
);
3938 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3939 es
->undo_insert_count
, debugstr_w(utext
));
3941 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3942 EDIT_EM_EmptyUndoBuffer(es
);
3943 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3944 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3945 /* send the notification after the selection start and end are set */
3946 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3947 EDIT_EM_ScrollCaret(es
);
3948 HeapFree(GetProcessHeap(), 0, utext
);
3950 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3951 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3956 /*********************************************************************
3961 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3965 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3969 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3970 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3973 if (es
->style
& ES_MULTILINE
) {
3974 if (es
->style
& ES_READONLY
) {
3975 EDIT_MoveHome(es
, FALSE
);
3976 EDIT_MoveDown_ML(es
, FALSE
);
3978 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3979 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3984 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3986 static const WCHAR tabW
[] = {'\t',0};
3987 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3991 if (!(es
->style
& ES_READONLY
) && !control
) {
3992 if (es
->selection_start
!= es
->selection_end
)
3995 /* delete character left of caret */
3996 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3997 EDIT_MoveBackward(es
, TRUE
);
4003 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4006 if (!(es
->style
& ES_READONLY
))
4007 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4010 if (!(es
->style
& ES_READONLY
))
4011 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4015 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4016 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4019 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4023 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4030 /*********************************************************************
4035 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4037 if (code
|| control
)
4057 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4058 EDIT_EM_ScrollCaret(es
);
4061 ERR("unknown menu item, please report\n");
4067 /*********************************************************************
4071 * Note: the resource files resource/sysres_??.rc cannot define a
4072 * single popup menu. Hence we use a (dummy) menubar
4073 * containing the single popup menu as its first item.
4075 * FIXME: the message identifiers have been chosen arbitrarily,
4076 * hence we use MF_BYPOSITION.
4077 * We might as well use the "real" values (anybody knows ?)
4078 * The menu definition is in resources/sysres_??.rc.
4079 * Once these are OK, we better use MF_BYCOMMAND here
4080 * (as we do in EDIT_WM_Command()).
4083 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4085 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4086 HMENU popup
= GetSubMenu(menu
, 0);
4087 UINT start
= es
->selection_start
;
4088 UINT end
= es
->selection_end
;
4090 ORDER_UINT(start
, end
);
4093 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4095 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4097 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4099 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4101 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4103 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
4105 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4108 /* Windows places the menu at the edit's center in this case */
4109 GetClientRect(es
->hwndSelf
, &rc
);
4110 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4111 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4112 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4115 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4120 /*********************************************************************
4125 static void EDIT_WM_Copy(EDITSTATE
*es
)
4127 INT s
= min(es
->selection_start
, es
->selection_end
);
4128 INT e
= max(es
->selection_start
, es
->selection_end
);
4136 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4137 dst
= GlobalLock(hdst
);
4138 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4139 dst
[len
] = 0; /* ensure 0 termination */
4140 TRACE("%s\n", debugstr_w(dst
));
4142 OpenClipboard(es
->hwndSelf
);
4144 SetClipboardData(CF_UNICODETEXT
, hdst
);
4149 /*********************************************************************
4154 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4158 TRACE("%s\n", debugstr_w(name
));
4160 * To initialize some final structure members, we call some helper
4161 * functions. However, since the EDITSTATE is not consistent (i.e.
4162 * not fully initialized), we should be very careful which
4163 * functions can be called, and in what order.
4165 EDIT_WM_SetFont(es
, 0, FALSE
);
4166 EDIT_EM_EmptyUndoBuffer(es
);
4168 /* We need to calculate the format rect
4169 (applications may send EM_SETMARGINS before the control gets visible) */
4170 GetClientRect(es
->hwndSelf
, &clientRect
);
4171 EDIT_SetRectNP(es
, &clientRect
);
4173 if (name
&& *name
) {
4174 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4175 /* if we insert text to the editline, the text scrolls out
4176 * of the window, as the caret is placed after the insert
4177 * pos normally; thus we reset es->selection... to 0 and
4180 es
->selection_start
= es
->selection_end
= 0;
4181 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4182 * Messages are only to be sent when the USER does something to
4183 * change the contents. So I am removing this EN_CHANGE
4185 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4187 EDIT_EM_ScrollCaret(es
);
4189 /* force scroll info update */
4190 EDIT_UpdateScrollInfo(es
);
4191 /* The rule seems to return 1 here for success */
4192 /* Power Builder masked edit controls will crash */
4194 /* FIXME: is that in all cases so ? */
4199 /*********************************************************************
4204 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4209 while (LocalUnlock(es
->hloc32W
)) ;
4210 LocalFree(es
->hloc32W
);
4213 while (LocalUnlock(es
->hloc32A
)) ;
4214 LocalFree(es
->hloc32A
);
4217 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
4218 HANDLE16 oldDS
= stack16
->ds
;
4220 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4221 while (LocalUnlock16(es
->hloc16
)) ;
4222 LocalFree16(es
->hloc16
);
4223 stack16
->ds
= oldDS
;
4226 pc
= es
->first_line_def
;
4230 HeapFree(GetProcessHeap(), 0, pc
);
4234 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4235 HeapFree(GetProcessHeap(), 0, es
);
4241 /*********************************************************************
4246 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4248 /* we do the proper erase in EDIT_WM_Paint */
4253 /*********************************************************************
4258 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4260 if(!count
) return 0;
4264 lstrcpynW(dst
, es
->text
, count
);
4265 return strlenW(dst
);
4269 LPSTR textA
= (LPSTR
)dst
;
4270 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4271 textA
[count
- 1] = 0; /* ensure 0 termination */
4272 return strlen(textA
);
4276 /*********************************************************************
4281 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4286 if (!(es
->style
& ES_MULTILINE
))
4289 if (!(es
->style
& ES_AUTOHSCROLL
))
4293 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4296 TRACE("SB_LINELEFT\n");
4298 dx
= -es
->char_width
;
4301 TRACE("SB_LINERIGHT\n");
4302 if (es
->x_offset
< es
->text_width
)
4303 dx
= es
->char_width
;
4306 TRACE("SB_PAGELEFT\n");
4308 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4311 TRACE("SB_PAGERIGHT\n");
4312 if (es
->x_offset
< es
->text_width
)
4313 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4321 TRACE("SB_RIGHT\n");
4322 if (es
->x_offset
< es
->text_width
)
4323 dx
= es
->text_width
- es
->x_offset
;
4326 TRACE("SB_THUMBTRACK %d\n", pos
);
4327 es
->flags
|= EF_HSCROLL_TRACK
;
4328 if(es
->style
& WS_HSCROLL
)
4329 dx
= pos
- es
->x_offset
;
4334 if(pos
< 0 || pos
> 100) return 0;
4335 /* Assume default scroll range 0-100 */
4336 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4337 new_x
= pos
* (es
->text_width
- fw
) / 100;
4338 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4341 case SB_THUMBPOSITION
:
4342 TRACE("SB_THUMBPOSITION %d\n", pos
);
4343 es
->flags
&= ~EF_HSCROLL_TRACK
;
4344 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4345 dx
= pos
- es
->x_offset
;
4350 if(pos
< 0 || pos
> 100) return 0;
4351 /* Assume default scroll range 0-100 */
4352 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4353 new_x
= pos
* (es
->text_width
- fw
) / 100;
4354 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4357 /* force scroll info update */
4358 EDIT_UpdateScrollInfo(es
);
4359 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4363 TRACE("SB_ENDSCROLL\n");
4366 * FIXME : the next two are undocumented !
4367 * Are we doing the right thing ?
4368 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4369 * although it's also a regular control message.
4371 case EM_GETTHUMB
: /* this one is used by NT notepad */
4375 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4376 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4379 /* Assume default scroll range 0-100 */
4380 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4381 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4383 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4386 case EM_LINESCROLL16
:
4387 TRACE("EM_LINESCROLL16\n");
4392 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4398 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4399 /* check if we are going to move too far */
4400 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4401 dx
= es
->text_width
- fw
- es
->x_offset
;
4403 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4409 /*********************************************************************
4414 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4416 HWND hLBox
= es
->hwndListBox
;
4424 hCombo
= GetParent(es
->hwndSelf
);
4428 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4430 if (key
== VK_UP
|| key
== VK_DOWN
)
4432 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4435 if (msg
== WM_KEYDOWN
|| nEUI
)
4436 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4442 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4444 /* make sure ComboLBox pops up */
4445 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4450 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4453 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4455 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4457 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4462 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4468 /*********************************************************************
4472 * Handling of special keys that don't produce a WM_CHAR
4473 * (i.e. non-printable keys) & Backspace & Delete
4476 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4481 if (GetKeyState(VK_MENU
) & 0x8000)
4484 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4485 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4490 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4495 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4496 EDIT_MoveUp_ML(es
, shift
);
4499 EDIT_MoveWordBackward(es
, shift
);
4501 EDIT_MoveBackward(es
, shift
);
4504 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4508 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4509 EDIT_MoveDown_ML(es
, shift
);
4511 EDIT_MoveWordForward(es
, shift
);
4513 EDIT_MoveForward(es
, shift
);
4516 EDIT_MoveHome(es
, shift
);
4519 EDIT_MoveEnd(es
, shift
);
4522 if (es
->style
& ES_MULTILINE
)
4523 EDIT_MovePageUp_ML(es
, shift
);
4525 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4528 if (es
->style
& ES_MULTILINE
)
4529 EDIT_MovePageDown_ML(es
, shift
);
4531 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4534 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4535 if (es
->selection_start
!= es
->selection_end
) {
4542 /* delete character left of caret */
4543 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4544 EDIT_MoveBackward(es
, TRUE
);
4546 } else if (control
) {
4547 /* delete to end of line */
4548 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4549 EDIT_MoveEnd(es
, TRUE
);
4552 /* delete character right of caret */
4553 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4554 EDIT_MoveForward(es
, TRUE
);
4562 if (!(es
->style
& ES_READONLY
))
4568 /* If the edit doesn't want the return send a message to the default object */
4569 if(!(es
->style
& ES_WANTRETURN
))
4571 HWND hwndParent
= GetParent(es
->hwndSelf
);
4572 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4573 if (HIWORD(dw
) == DC_HASDEFID
)
4575 SendMessageW( hwndParent
, WM_COMMAND
,
4576 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4577 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4586 /*********************************************************************
4591 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4593 es
->flags
&= ~EF_FOCUSED
;
4595 if(!(es
->style
& ES_NOHIDESEL
))
4596 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4597 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4602 /*********************************************************************
4606 * The caret position has been set on the WM_LBUTTONDOWN message
4609 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4612 INT e
= es
->selection_end
;
4617 es
->bCaptureState
= TRUE
;
4618 SetCapture(es
->hwndSelf
);
4620 l
= EDIT_EM_LineFromChar(es
, e
);
4621 li
= EDIT_EM_LineIndex(es
, l
);
4622 ll
= EDIT_EM_LineLength(es
, e
);
4623 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4624 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4625 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4626 EDIT_EM_ScrollCaret(es
);
4627 es
->region_posx
= es
->region_posy
= 0;
4628 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4633 /*********************************************************************
4638 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4643 es
->bCaptureState
= TRUE
;
4644 SetCapture(es
->hwndSelf
);
4645 EDIT_ConfinePoint(es
, &x
, &y
);
4646 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4647 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4648 EDIT_EM_ScrollCaret(es
);
4649 es
->region_posx
= es
->region_posy
= 0;
4650 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4652 if (!(es
->flags
& EF_FOCUSED
))
4653 SetFocus(es
->hwndSelf
);
4659 /*********************************************************************
4664 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4666 if (es
->bCaptureState
) {
4667 KillTimer(es
->hwndSelf
, 0);
4668 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4670 es
->bCaptureState
= FALSE
;
4675 /*********************************************************************
4680 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4682 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4687 /*********************************************************************
4692 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4698 /* If the mouse has been captured by process other than the edit control itself,
4699 * the windows edit controls will not select the strings with mouse move.
4701 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4705 * FIXME: gotta do some scrolling if outside client
4706 * area. Maybe reset the timer ?
4709 EDIT_ConfinePoint(es
, &x
, &y
);
4710 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4711 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4712 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4713 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4714 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4719 /*********************************************************************
4723 * See also EDIT_WM_StyleChanged
4725 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4730 TRACE("Creating %s edit control, style = %08x\n",
4731 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4733 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4735 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4738 * Note: since the EDITSTATE has not been fully initialized yet,
4739 * we can't use any API calls that may send
4740 * WM_XXX messages before WM_NCCREATE is completed.
4743 es
->is_unicode
= unicode
;
4744 es
->style
= lpcs
->style
;
4746 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4748 es
->hwndSelf
= hwnd
;
4749 /* Save parent, which will be notified by EN_* messages */
4750 es
->hwndParent
= lpcs
->hwndParent
;
4752 if (es
->style
& ES_COMBO
)
4753 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4755 /* Number overrides lowercase overrides uppercase (at least it
4756 * does in Win95). However I'll bet that ES_NUMBER would be
4757 * invalid under Win 3.1.
4759 if (es
->style
& ES_NUMBER
) {
4760 ; /* do not override the ES_NUMBER */
4761 } else if (es
->style
& ES_LOWERCASE
) {
4762 es
->style
&= ~ES_UPPERCASE
;
4764 if (es
->style
& ES_MULTILINE
) {
4765 es
->buffer_limit
= BUFLIMIT_MULTI
;
4766 if (es
->style
& WS_VSCROLL
)
4767 es
->style
|= ES_AUTOVSCROLL
;
4768 if (es
->style
& WS_HSCROLL
)
4769 es
->style
|= ES_AUTOHSCROLL
;
4770 es
->style
&= ~ES_PASSWORD
;
4771 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4772 /* Confirmed - RIGHT overrides CENTER */
4773 if (es
->style
& ES_RIGHT
)
4774 es
->style
&= ~ES_CENTER
;
4775 es
->style
&= ~WS_HSCROLL
;
4776 es
->style
&= ~ES_AUTOHSCROLL
;
4779 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4780 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4781 es
->style
&= ~ES_CENTER
;
4782 es
->style
&= ~WS_HSCROLL
;
4783 es
->style
&= ~WS_VSCROLL
;
4784 if (es
->style
& ES_PASSWORD
)
4785 es
->password_char
= '*';
4788 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4789 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4791 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4793 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4795 es
->undo_buffer_size
= es
->buffer_size
;
4797 if (es
->style
& ES_MULTILINE
)
4798 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4803 * In Win95 look and feel, the WS_BORDER style is replaced by the
4804 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4805 * control a nonclient area so we don't need to draw the border.
4806 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4807 * a nonclient area and we should handle painting the border ourselves.
4809 * When making modifications please ensure that the code still works
4810 * for edit controls created directly with style 0x50800000, exStyle 0
4811 * (which should have a single pixel border)
4813 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4814 es
->style
&= ~WS_BORDER
;
4815 else if (es
->style
& WS_BORDER
)
4816 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4821 /*********************************************************************
4826 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4839 BOOL rev
= es
->bEnableState
&&
4840 ((es
->flags
& EF_FOCUSED
) ||
4841 (es
->style
& ES_NOHIDESEL
));
4842 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4844 GetClientRect(es
->hwndSelf
, &rcClient
);
4846 /* get the background brush */
4847 brush
= EDIT_NotifyCtlColor(es
, dc
);
4849 /* paint the border and the background */
4850 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4852 if(es
->style
& WS_BORDER
) {
4853 bw
= GetSystemMetrics(SM_CXBORDER
);
4854 bh
= GetSystemMetrics(SM_CYBORDER
);
4856 if(es
->style
& ES_MULTILINE
) {
4857 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4858 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4861 /* Draw the frame. Same code as in nonclient.c */
4862 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
4863 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
4864 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4865 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
4866 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4867 SelectObject(dc
, old_brush
);
4869 /* Keep the border clean */
4870 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
4871 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
4874 GetClipBox(dc
, &rc
);
4875 FillRect(dc
, &rc
, brush
);
4877 IntersectClipRect(dc
, es
->format_rect
.left
,
4878 es
->format_rect
.top
,
4879 es
->format_rect
.right
,
4880 es
->format_rect
.bottom
);
4881 if (es
->style
& ES_MULTILINE
) {
4883 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4886 old_font
= SelectObject(dc
, es
->font
);
4888 if (!es
->bEnableState
)
4889 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4890 GetClipBox(dc
, &rcRgn
);
4891 if (es
->style
& ES_MULTILINE
) {
4892 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4893 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4894 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4895 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4896 EDIT_PaintLine(es
, dc
, i
, rev
);
4899 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4900 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4901 EDIT_PaintLine(es
, dc
, 0, rev
);
4904 SelectObject(dc
, old_font
);
4907 EndPaint(es
->hwndSelf
, &ps
);
4911 /*********************************************************************
4916 static void EDIT_WM_Paste(EDITSTATE
*es
)
4921 /* Protect read-only edit control from modification */
4922 if(es
->style
& ES_READONLY
)
4925 OpenClipboard(es
->hwndSelf
);
4926 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4927 src
= (LPWSTR
)GlobalLock(hsrc
);
4928 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4935 /*********************************************************************
4940 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4942 es
->flags
|= EF_FOCUSED
;
4944 if (!(es
->style
& ES_NOHIDESEL
))
4945 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4947 /* single line edit updates itself */
4948 if (!(es
->style
& ES_MULTILINE
))
4950 HDC hdc
= GetDC(es
->hwndSelf
);
4951 EDIT_WM_Paint(es
, hdc
);
4952 ReleaseDC(es
->hwndSelf
, hdc
);
4955 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4956 EDIT_SetCaretPos(es
, es
->selection_end
,
4957 es
->flags
& EF_AFTER_WRAP
);
4958 ShowCaret(es
->hwndSelf
);
4959 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
4963 /*********************************************************************
4967 * With Win95 look the margins are set to default font value unless
4968 * the system font (font == 0) is being set, in which case they are left
4972 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4980 dc
= GetDC(es
->hwndSelf
);
4982 old_font
= SelectObject(dc
, font
);
4983 GetTextMetricsW(dc
, &tm
);
4984 es
->line_height
= tm
.tmHeight
;
4985 es
->char_width
= tm
.tmAveCharWidth
;
4987 SelectObject(dc
, old_font
);
4988 ReleaseDC(es
->hwndSelf
, dc
);
4990 /* Reset the format rect and the margins */
4991 GetClientRect(es
->hwndSelf
, &clientRect
);
4992 EDIT_SetRectNP(es
, &clientRect
);
4993 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4994 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
4996 if (es
->style
& ES_MULTILINE
)
4997 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4999 EDIT_CalcLineWidth_SL(es
);
5002 EDIT_UpdateText(es
, NULL
, TRUE
);
5003 if (es
->flags
& EF_FOCUSED
) {
5005 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5006 EDIT_SetCaretPos(es
, es
->selection_end
,
5007 es
->flags
& EF_AFTER_WRAP
);
5008 ShowCaret(es
->hwndSelf
);
5013 /*********************************************************************
5018 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5019 * The modified flag is reset. No notifications are sent.
5021 * For single-line controls, reception of WM_SETTEXT triggers:
5022 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5025 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5027 LPWSTR textW
= NULL
;
5028 if (!unicode
&& text
)
5030 LPCSTR textA
= (LPCSTR
)text
;
5031 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5032 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5034 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5038 if (es
->flags
& EF_UPDATE
)
5039 /* fixed this bug once; complain if we see it about to happen again. */
5040 ERR("SetSel may generate UPDATE message whose handler may reset "
5043 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5046 TRACE("%s\n", debugstr_w(text
));
5047 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5049 HeapFree(GetProcessHeap(), 0, textW
);
5053 static const WCHAR empty_stringW
[] = {0};
5055 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5058 es
->flags
&= ~EF_MODIFIED
;
5059 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5061 /* Send the notification after the selection start and end have been set
5062 * edit control doesn't send notification on WM_SETTEXT
5063 * if it is multiline, or it is part of combobox
5065 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5067 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5068 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5070 EDIT_EM_ScrollCaret(es
);
5071 EDIT_UpdateScrollInfo(es
);
5075 /*********************************************************************
5080 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5082 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5084 TRACE("width = %d, height = %d\n", width
, height
);
5085 SetRect(&rc
, 0, 0, width
, height
);
5086 EDIT_SetRectNP(es
, &rc
);
5087 EDIT_UpdateText(es
, NULL
, TRUE
);
5092 /*********************************************************************
5096 * This message is sent by SetWindowLong on having changed either the Style
5097 * or the extended style.
5099 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5101 * See also EDIT_WM_NCCreate
5103 * It appears that the Windows version of the edit control allows the style
5104 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5105 * style variable which will generally be different. In this function we
5106 * update the internal style based on what changed in the externally visible
5109 * Much of this content as based upon the MSDN, especially:
5110 * Platform SDK Documentation -> User Interface Services ->
5111 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5112 * Edit Control Styles
5114 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5116 if (GWL_STYLE
== which
) {
5117 DWORD style_change_mask
;
5119 /* Only a subset of changes can be applied after the control
5122 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5124 if (es
->style
& ES_MULTILINE
)
5125 style_change_mask
|= ES_WANTRETURN
;
5127 new_style
= style
->styleNew
& style_change_mask
;
5129 /* Number overrides lowercase overrides uppercase (at least it
5130 * does in Win95). However I'll bet that ES_NUMBER would be
5131 * invalid under Win 3.1.
5133 if (new_style
& ES_NUMBER
) {
5134 ; /* do not override the ES_NUMBER */
5135 } else if (new_style
& ES_LOWERCASE
) {
5136 new_style
&= ~ES_UPPERCASE
;
5139 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5140 } else if (GWL_EXSTYLE
== which
) {
5141 ; /* FIXME - what is needed here */
5143 WARN ("Invalid style change %d\n",which
);
5149 /*********************************************************************
5154 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5156 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5157 if (EDIT_EM_CanUndo(es
))
5160 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5161 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5164 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5168 /*********************************************************************
5173 static void EDIT_WM_Timer(EDITSTATE
*es
)
5175 if (es
->region_posx
< 0) {
5176 EDIT_MoveBackward(es
, TRUE
);
5177 } else if (es
->region_posx
> 0) {
5178 EDIT_MoveForward(es
, TRUE
);
5181 * FIXME: gotta do some vertical scrolling here, like
5182 * EDIT_EM_LineScroll(hwnd, 0, 1);
5186 /*********************************************************************
5191 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5195 if (!(es
->style
& ES_MULTILINE
))
5198 if (!(es
->style
& ES_AUTOVSCROLL
))
5207 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5208 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5209 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5211 EDIT_EM_Scroll(es
, action
);
5218 TRACE("SB_BOTTOM\n");
5219 dy
= es
->line_count
- 1 - es
->y_offset
;
5222 TRACE("SB_THUMBTRACK %d\n", pos
);
5223 es
->flags
|= EF_VSCROLL_TRACK
;
5224 if(es
->style
& WS_VSCROLL
)
5225 dy
= pos
- es
->y_offset
;
5228 /* Assume default scroll range 0-100 */
5231 if(pos
< 0 || pos
> 100) return 0;
5232 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5233 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5234 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5235 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5236 es
->line_count
, es
->y_offset
, pos
, dy
);
5239 case SB_THUMBPOSITION
:
5240 TRACE("SB_THUMBPOSITION %d\n", pos
);
5241 es
->flags
&= ~EF_VSCROLL_TRACK
;
5242 if(es
->style
& WS_VSCROLL
)
5243 dy
= pos
- es
->y_offset
;
5246 /* Assume default scroll range 0-100 */
5249 if(pos
< 0 || pos
> 100) return 0;
5250 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5251 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5252 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5253 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5254 es
->line_count
, es
->y_offset
, pos
, dy
);
5258 /* force scroll info update */
5259 EDIT_UpdateScrollInfo(es
);
5260 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5264 TRACE("SB_ENDSCROLL\n");
5267 * FIXME : the next two are undocumented !
5268 * Are we doing the right thing ?
5269 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5270 * although it's also a regular control message.
5272 case EM_GETTHUMB
: /* this one is used by NT notepad */
5276 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5277 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5280 /* Assume default scroll range 0-100 */
5281 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5282 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5284 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5287 case EM_LINESCROLL16
:
5288 TRACE("EM_LINESCROLL16 %d\n", pos
);
5293 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5298 EDIT_EM_LineScroll(es
, 0, dy
);
5302 /*********************************************************************
5307 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5309 if (es
->flags
& EF_UPDATE
) {
5310 es
->flags
&= ~EF_UPDATE
;
5311 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5313 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5317 /*********************************************************************
5322 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5324 if (es
->flags
& EF_UPDATE
) {
5325 es
->flags
&= ~EF_UPDATE
;
5326 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5328 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5331 /********************************************************************
5333 * The Following code is to handle inline editing from IMEs
5336 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5339 LPWSTR lpCompStr
= NULL
;
5341 LPSTR lpCompStrAttr
= NULL
;
5344 if (!(hIMC
= ImmGetContext(hwnd
)))
5347 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5351 ImmReleaseContext(hwnd
, hIMC
);
5355 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
5358 ERR("Unable to allocate IME CompositionString\n");
5359 ImmReleaseContext(hwnd
,hIMC
);
5364 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
5365 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5367 if (CompFlag
& GCS_COMPATTR
)
5370 * We do not use the attributes yet. it would tell us what characters
5371 * are in transition and which are converted or decided upon
5373 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5377 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5380 ERR("Unable to allocate IME Attribute String\n");
5381 HeapFree(GetProcessHeap(),0,lpCompStr
);
5382 ImmReleaseContext(hwnd
,hIMC
);
5385 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5387 lpCompStrAttr
[dwBufLenAttr
] = 0;
5390 lpCompStrAttr
= NULL
;
5393 /* check for change in composition start */
5394 if (es
->selection_end
< es
->composition_start
)
5395 es
->composition_start
= es
->selection_end
;
5397 /* replace existing selection string */
5398 es
->selection_start
= es
->composition_start
;
5400 if (es
->composition_len
> 0)
5401 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5403 es
->selection_end
= es
->selection_start
;
5405 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5406 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5408 es
->selection_start
= es
->composition_start
;
5409 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5411 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5412 HeapFree(GetProcessHeap(),0,lpCompStr
);
5413 ImmReleaseContext(hwnd
,hIMC
);
5416 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5422 if ( !(hIMC
= ImmGetContext(hwnd
)))
5425 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5428 ImmReleaseContext(hwnd
, hIMC
);
5432 lpResultStr
= HeapAlloc(GetProcessHeap(),0, dwBufLen
+sizeof(WCHAR
));
5435 ERR("Unable to alloc buffer for IME string\n");
5436 ImmReleaseContext(hwnd
, hIMC
);
5440 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, dwBufLen
);
5441 lpResultStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5443 /* check for change in composition start */
5444 if (es
->selection_end
< es
->composition_start
)
5445 es
->composition_start
= es
->selection_end
;
5447 es
->selection_start
= es
->composition_start
;
5448 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5449 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5450 es
->composition_start
= es
->selection_end
;
5451 es
->composition_len
= 0;
5453 HeapFree(GetProcessHeap(),0,lpResultStr
);
5454 ImmReleaseContext(hwnd
, hIMC
);
5457 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5459 if (CompFlag
& GCS_RESULTSTR
)
5460 EDIT_GetResultStr(hwnd
,es
);
5461 if (CompFlag
& GCS_COMPSTR
)
5462 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);