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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
56 #include "wine/winbase16.h"
57 #include "wine/winuser16.h"
58 #include "wine/unicode.h"
60 #include "user_private.h"
61 #include "wine/debug.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
64 WINE_DECLARE_DEBUG_CHANNEL(combo
);
65 WINE_DECLARE_DEBUG_CHANNEL(relay
);
67 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
68 FIXME: BTW, new specs say 65535 (do you dare ???) */
69 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
70 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
71 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
72 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
75 * extra flags for EDITSTATE.flags field
77 #define EF_MODIFIED 0x0001 /* text has been modified */
78 #define EF_FOCUSED 0x0002 /* we have input focus */
79 #define EF_UPDATE 0x0004 /* notify parent of changed state */
80 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
81 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
82 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
83 wrapped line, instead of in front of the next character */
84 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
88 END_0
= 0, /* line ends with terminating '\0' character */
89 END_WRAP
, /* line is wrapped */
90 END_HARD
, /* line ends with a hard return '\r\n' */
91 END_SOFT
, /* line ends with a soft return '\r\r\n' */
92 END_RICH
/* line ends with a single '\n' */
95 typedef struct tagLINEDEF
{
96 INT length
; /* bruto length of a line in bytes */
97 INT net_length
; /* netto length of a line in visible characters */
99 INT width
; /* width of the line in pixels */
100 INT index
; /* line index into the buffer */
101 struct tagLINEDEF
*next
;
106 BOOL is_unicode
; /* how the control was created */
107 LPWSTR text
; /* the actual contents of the control */
108 UINT buffer_size
; /* the size of the buffer in characters */
109 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
110 HFONT font
; /* NULL means standard system font */
111 INT x_offset
; /* scroll offset for multi lines this is in pixels
112 for single lines it's in characters */
113 INT line_height
; /* height of a screen line in pixels */
114 INT char_width
; /* average character width in pixels */
115 DWORD style
; /* sane version of wnd->dwStyle */
116 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
117 INT undo_insert_count
; /* number of characters inserted in sequence */
118 UINT undo_position
; /* character index of the insertion and deletion */
119 LPWSTR undo_text
; /* deleted text */
120 UINT undo_buffer_size
; /* size of the deleted text buffer */
121 INT selection_start
; /* == selection_end if no selection */
122 INT selection_end
; /* == current caret position */
123 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
124 INT left_margin
; /* in pixels */
125 INT right_margin
; /* in pixels */
127 INT text_width
; /* width of the widest line in pixels for multi line controls
128 and just line width for single line controls */
129 INT region_posx
; /* Position of cursor relative to region: */
130 INT region_posy
; /* -1: to left, 0: within, 1: to right */
131 EDITWORDBREAKPROC16 word_break_proc16
;
132 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
133 INT line_count
; /* number of lines */
134 INT y_offset
; /* scroll offset in number of lines */
135 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
136 BOOL bEnableState
; /* flag keeping the enable state */
137 HWND hwndSelf
; /* the our window handle */
138 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
139 Even if parent will change, EN_* messages
140 should be sent to the first parent. */
141 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
143 * only for multi line controls
145 INT lock_count
; /* amount of re-entries in the EditWndProc */
148 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
149 HLOCAL hloc32W
; /* our unicode local memory block */
150 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
152 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
157 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
158 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
160 /* used for disabled or read-only edit control */
161 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
163 { /* Notify parent which has created this edit control */ \
164 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
165 SendMessageW(es->hwndParent, WM_COMMAND, \
166 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
167 (LPARAM)(es->hwndSelf)); \
170 /*********************************************************************
177 * These functions have trivial implementations
178 * We still like to call them internally
179 * "static inline" makes them more like macro's
181 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
182 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
183 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
184 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
187 * Helper functions only valid for one type of control
189 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
190 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
191 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
192 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
193 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
194 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
195 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
197 * Helper functions valid for both single line _and_ multi line controls
199 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
200 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
201 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
202 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
203 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
204 static void EDIT_LockBuffer(EDITSTATE
*es
);
205 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
206 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
207 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
208 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
209 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
210 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
211 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
212 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
213 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
214 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
215 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
216 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
217 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
218 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
219 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
221 * EM_XXX message handlers
223 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
224 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
225 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
226 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
227 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
228 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
229 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
230 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
231 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
232 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
233 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
234 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
235 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
236 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
237 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
238 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
239 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
240 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
241 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
242 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
243 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
244 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
245 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
246 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
247 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
248 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
249 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
251 * WM_XXX message handlers
253 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
254 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
255 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
256 static void EDIT_WM_Copy(EDITSTATE
*es
);
257 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
258 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
259 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
260 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
261 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
262 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
263 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
264 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
265 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
266 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
267 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
268 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
269 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
270 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
271 static void EDIT_WM_Paste(EDITSTATE
*es
);
272 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
273 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
274 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
275 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
276 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
277 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
278 static void EDIT_WM_Timer(EDITSTATE
*es
);
279 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
280 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
281 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
283 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
284 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
286 /*********************************************************************
287 * edit class descriptor
289 const struct builtin_class_descr EDIT_builtin_class
=
292 CS_DBLCLKS
| CS_PARENTDC
, /* style */
293 EditWndProcA
, /* procA */
294 EditWndProcW
, /* procW */
295 sizeof(EDITSTATE
*), /* extra */
296 IDC_IBEAM
, /* cursor */
301 /*********************************************************************
306 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
308 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
312 /*********************************************************************
317 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
319 es
->undo_insert_count
= 0;
320 *es
->undo_text
= '\0';
324 /*********************************************************************
329 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
331 static const WCHAR empty_stringW
[] = {0};
333 /* Protect read-only edit control from modification */
334 if(es
->style
& ES_READONLY
)
337 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
341 /*********************************************************************
346 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
353 /**********************************************************************
356 * Returns the window version in case Wine emulates a later version
357 * of windows than the application expects.
359 * In a number of cases when windows runs an application that was
360 * designed for an earlier windows version, windows reverts
361 * to "old" behaviour of that earlier version.
363 * An example is a disabled edit control that needs to be painted.
364 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
365 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
366 * applications with an expected version 0f 4.0 or higher.
369 static DWORD
get_app_version(void)
371 static DWORD version
;
374 DWORD dwEmulatedVersion
;
376 DWORD dwProcVersion
= GetProcessVersion(0);
378 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
379 GetVersionExW( &info
);
380 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
381 /* FIXME: this may not be 100% correct; see discussion on the
382 * wine developer list in Nov 1999 */
383 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
389 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
393 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
394 msg
= WM_CTLCOLORSTATIC
;
396 msg
= WM_CTLCOLOREDIT
;
398 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
399 return (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
402 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
405 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
407 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
410 /*********************************************************************
414 * The messages are in the order of the actual integer values
415 * (which can be found in include/windows.h)
416 * Wherever possible the 16 bit versions are converted to
417 * the 32 bit ones, so that we can 'fall through' to the
418 * helper functions. These are mostly 32 bit (with a few
419 * exceptions, clearly indicated by a '16' extension to their
423 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
424 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
426 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongW( hwnd
, 0 );
429 TRACE("hwnd=%p msg=%x (%s) wparam=%x lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
431 if (!es
&& msg
!= WM_NCCREATE
)
432 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
434 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
442 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
446 if ((short)LOWORD(lParam
) == -1)
447 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
449 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
451 EDIT_EM_ScrollCaret(es
);
455 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
456 EDIT_EM_ScrollCaret(es
);
463 RECT16
*r16
= MapSL(lParam
);
464 r16
->left
= es
->format_rect
.left
;
465 r16
->top
= es
->format_rect
.top
;
466 r16
->right
= es
->format_rect
.right
;
467 r16
->bottom
= es
->format_rect
.bottom
;
472 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
476 if ((es
->style
& ES_MULTILINE
) && lParam
) {
478 RECT16
*r16
= MapSL(lParam
);
481 rc
.right
= r16
->right
;
482 rc
.bottom
= r16
->bottom
;
483 EDIT_SetRectNP(es
, &rc
);
484 EDIT_UpdateText(es
, NULL
, TRUE
);
488 if ((es
->style
& ES_MULTILINE
) && lParam
) {
489 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
490 EDIT_UpdateText(es
, NULL
, TRUE
);
495 if ((es
->style
& ES_MULTILINE
) && lParam
) {
497 RECT16
*r16
= MapSL(lParam
);
500 rc
.right
= r16
->right
;
501 rc
.bottom
= r16
->bottom
;
502 EDIT_SetRectNP(es
, &rc
);
506 if ((es
->style
& ES_MULTILINE
) && lParam
)
507 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
512 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
515 case EM_LINESCROLL16
:
516 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
517 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
520 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
523 case EM_SCROLLCARET16
:
525 EDIT_EM_ScrollCaret(es
);
531 result
= ((es
->flags
& EF_MODIFIED
) != 0);
537 es
->flags
|= EF_MODIFIED
;
539 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
542 case EM_GETLINECOUNT16
:
543 case EM_GETLINECOUNT
:
544 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
548 if ((INT16
)wParam
== -1)
552 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
556 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
559 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
563 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
566 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
571 result
= EDIT_EM_GetThumb(es
);
574 /* these messages missing from specs */
583 FIXME("undocumented message 0x%x, please report\n", msg
);
584 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
587 case EM_LINELENGTH16
:
589 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
592 case EM_REPLACESEL16
:
593 lParam
= (LPARAM
)MapSL(lParam
);
594 unicode
= FALSE
; /* 16-bit message is always ascii */
601 textW
= (LPWSTR
)lParam
;
604 LPSTR textA
= (LPSTR
)lParam
;
605 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
606 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
607 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
610 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
614 HeapFree(GetProcessHeap(), 0, textW
);
619 lParam
= (LPARAM
)MapSL(lParam
);
620 unicode
= FALSE
; /* 16-bit message is always ascii */
623 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
627 case EM_SETLIMITTEXT
:
628 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
633 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
639 result
= (LRESULT
)EDIT_EM_Undo(es
);
644 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
647 case EM_LINEFROMCHAR16
:
648 case EM_LINEFROMCHAR
:
649 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
652 case EM_SETTABSTOPS16
:
653 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
656 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
659 case EM_SETPASSWORDCHAR16
:
660 unicode
= FALSE
; /* 16-bit message is always ascii */
662 case EM_SETPASSWORDCHAR
:
667 charW
= (WCHAR
)wParam
;
671 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
674 EDIT_EM_SetPasswordChar(es
, charW
);
678 case EM_EMPTYUNDOBUFFER16
:
679 case EM_EMPTYUNDOBUFFER
:
680 EDIT_EM_EmptyUndoBuffer(es
);
683 case EM_GETFIRSTVISIBLELINE16
:
684 result
= es
->y_offset
;
686 case EM_GETFIRSTVISIBLELINE
:
687 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
690 case EM_SETREADONLY16
:
693 SetWindowLongW( hwnd
, GWL_STYLE
,
694 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
695 es
->style
|= ES_READONLY
;
697 SetWindowLongW( hwnd
, GWL_STYLE
,
698 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
699 es
->style
&= ~ES_READONLY
;
704 case EM_SETWORDBREAKPROC16
:
705 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
707 case EM_SETWORDBREAKPROC
:
708 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
711 case EM_GETWORDBREAKPROC16
:
712 result
= (LRESULT
)es
->word_break_proc16
;
714 case EM_GETWORDBREAKPROC
:
715 result
= (LRESULT
)es
->word_break_proc
;
718 case EM_GETPASSWORDCHAR16
:
719 unicode
= FALSE
; /* 16-bit message is always ascii */
721 case EM_GETPASSWORDCHAR
:
724 result
= es
->password_char
;
727 WCHAR charW
= es
->password_char
;
729 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
735 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
738 EDIT_EM_SetMargins(es
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
742 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
745 case EM_GETLIMITTEXT
:
746 result
= es
->buffer_limit
;
750 result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
754 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
757 /* End of the EM_ messages which were in numerical order; what order
758 * are these in? vaguely alphabetical?
762 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
766 result
= EDIT_WM_Destroy(es
);
771 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
773 if (es
->style
& ES_MULTILINE
)
775 result
|= DLGC_WANTALLKEYS
;
779 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
781 int vk
= (int)((LPMSG
)lParam
)->wParam
;
783 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
785 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
786 result
|= DLGC_WANTMESSAGE
;
797 strng
[0] = wParam
>> 8;
798 strng
[1] = wParam
& 0xff;
799 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
800 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
801 EDIT_WM_Char(es
, charW
);
814 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
817 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
819 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
820 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
823 EDIT_WM_Char(es
, charW
);
832 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
836 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
845 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
848 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
852 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
853 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
854 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
856 result
= EDIT_WM_Create(es
, nameW
);
857 HeapFree(GetProcessHeap(), 0, nameW
);
866 es
->bEnableState
= (BOOL
) wParam
;
867 EDIT_UpdateText(es
, NULL
, TRUE
);
871 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
875 result
= (LRESULT
)es
->font
;
879 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
882 case WM_GETTEXTLENGTH
:
883 if (unicode
) result
= strlenW(es
->text
);
884 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
885 NULL
, 0, NULL
, NULL
);
889 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
893 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
897 result
= EDIT_WM_KillFocus(es
);
900 case WM_LBUTTONDBLCLK
:
901 result
= EDIT_WM_LButtonDblClk(es
);
905 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
909 result
= EDIT_WM_LButtonUp(es
);
913 result
= EDIT_WM_MButtonDown(es
);
917 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
921 EDIT_WM_Paint(es
, (HDC
)wParam
);
929 EDIT_WM_SetFocus(es
);
933 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
937 /* FIXME: actually set an internal flag and behave accordingly */
941 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
946 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
949 case WM_STYLECHANGED
:
950 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
953 case WM_STYLECHANGING
:
954 result
= 0; /* See EDIT_WM_StyleChanged */
958 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
966 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
971 int gcWheelDelta
= 0;
972 UINT pulScrollLines
= 3;
973 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
975 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
976 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
979 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
980 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
982 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
983 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
984 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
989 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
993 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
995 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1000 /*********************************************************************
1002 * EditWndProcW (USER32.@)
1004 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1006 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1009 /*********************************************************************
1011 * EditWndProc (USER32.@)
1013 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1015 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1018 /*********************************************************************
1020 * EDIT_BuildLineDefs_ML
1022 * Build linked list of text lines.
1023 * Lines can end with '\0' (last line), a character (if it is wrapped),
1024 * a soft return '\r\r\n' or a hard return '\r\n'
1027 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1031 LPWSTR current_position
, cp
;
1033 LINEDEF
*current_line
;
1034 LINEDEF
*previous_line
;
1035 LINEDEF
*start_line
;
1036 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1037 INT line_count
= es
->line_count
;
1038 INT orig_net_length
;
1041 if (istart
== iend
&& delta
== 0)
1044 dc
= GetDC(es
->hwndSelf
);
1046 old_font
= SelectObject(dc
, es
->font
);
1048 previous_line
= NULL
;
1049 current_line
= es
->first_line_def
;
1051 /* Find starting line. istart must lie inside an existing line or
1052 * at the end of buffer */
1054 if (istart
< current_line
->index
+ current_line
->length
||
1055 current_line
->ending
== END_0
)
1058 previous_line
= current_line
;
1059 current_line
= current_line
->next
;
1061 } while (current_line
);
1063 if (!current_line
) /* Error occurred start is not inside previous buffer */
1065 FIXME(" modification occurred outside buffer\n");
1066 ReleaseDC(es
->hwndSelf
, dc
);
1070 /* Remember start of modifications in order to calculate update region */
1071 nstart_line
= line_index
;
1072 nstart_index
= current_line
->index
;
1074 /* We must start to reformat from the previous line since the modifications
1075 * may have caused the line to wrap upwards. */
1076 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1079 current_line
= previous_line
;
1081 start_line
= current_line
;
1083 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1084 current_position
= es
->text
+ current_line
->index
;
1086 if (current_line
!= start_line
)
1088 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1090 /* The buffer has been expanded, create a new line and
1091 insert it into the link list */
1092 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1093 new_line
->next
= previous_line
->next
;
1094 previous_line
->next
= new_line
;
1095 current_line
= new_line
;
1098 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1100 /* The previous line merged with this line so we delete this extra entry */
1101 previous_line
->next
= current_line
->next
;
1102 HeapFree(GetProcessHeap(), 0, current_line
);
1103 current_line
= previous_line
->next
;
1107 else /* current_line->index + delta == current_position */
1109 if (current_position
- es
->text
> iend
)
1110 break; /* We reached end of line modifications */
1111 /* else recalulate this line */
1115 current_line
->index
= current_position
- es
->text
;
1116 orig_net_length
= current_line
->net_length
;
1118 /* Find end of line */
1119 cp
= current_position
;
1121 if (*cp
== '\n') break;
1122 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1127 /* Mark type of line termination */
1129 current_line
->ending
= END_0
;
1130 current_line
->net_length
= strlenW(current_position
);
1131 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1132 current_line
->ending
= END_SOFT
;
1133 current_line
->net_length
= cp
- current_position
- 1;
1134 } else if (*cp
== '\n') {
1135 current_line
->ending
= END_RICH
;
1136 current_line
->net_length
= cp
- current_position
;
1138 current_line
->ending
= END_HARD
;
1139 current_line
->net_length
= cp
- current_position
;
1142 /* Calculate line width */
1143 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1144 current_position
, current_line
->net_length
,
1145 es
->tabs_count
, es
->tabs
));
1147 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1148 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1149 if (current_line
->width
> fw
) {
1154 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1155 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1156 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1157 current_position
, next
, es
->tabs_count
, es
->tabs
));
1158 } while (current_line
->width
<= fw
);
1159 if (!prev
) { /* Didn't find a line break so force a break */
1164 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1165 current_position
, next
, es
->tabs_count
, es
->tabs
));
1166 } while (current_line
->width
<= fw
);
1171 /* If the first line we are calculating, wrapped before istart, we must
1172 * adjust istart in order for this to be reflected in the update region. */
1173 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1174 istart
= current_line
->index
+ prev
;
1175 /* else if we are updating the previous line before the first line we
1176 * are re-calculating and it expanded */
1177 else if (current_line
== start_line
&&
1178 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1180 /* Line expanded due to an upwards line wrap so we must partially include
1181 * previous line in update region */
1182 nstart_line
= line_index
;
1183 nstart_index
= current_line
->index
;
1184 istart
= current_line
->index
+ orig_net_length
;
1187 current_line
->net_length
= prev
;
1188 current_line
->ending
= END_WRAP
;
1189 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1190 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1192 else if (orig_net_length
< current_line
->net_length
&&
1193 current_line
== start_line
&&
1194 current_line
->index
!= nstart_index
) {
1195 /* The previous line expanded but it's still not as wide as the client rect */
1196 /* The expansion is due to an upwards line wrap so we must partially include
1197 it in the update region */
1198 nstart_line
= line_index
;
1199 nstart_index
= current_line
->index
;
1200 istart
= current_line
->index
+ orig_net_length
;
1205 /* Adjust length to include line termination */
1206 switch (current_line
->ending
) {
1208 current_line
->length
= current_line
->net_length
+ 3;
1211 current_line
->length
= current_line
->net_length
+ 1;
1214 current_line
->length
= current_line
->net_length
+ 2;
1218 current_line
->length
= current_line
->net_length
;
1221 es
->text_width
= max(es
->text_width
, current_line
->width
);
1222 current_position
+= current_line
->length
;
1223 previous_line
= current_line
;
1224 current_line
= current_line
->next
;
1226 } while (previous_line
->ending
!= END_0
);
1228 /* Finish adjusting line indexes by delta or remove hanging lines */
1229 if (previous_line
->ending
== END_0
)
1231 LINEDEF
*pnext
= NULL
;
1233 previous_line
->next
= NULL
;
1234 while (current_line
)
1236 pnext
= current_line
->next
;
1237 HeapFree(GetProcessHeap(), 0, current_line
);
1238 current_line
= pnext
;
1242 else if (delta
!= 0)
1244 while (current_line
)
1246 current_line
->index
+= delta
;
1247 current_line
= current_line
->next
;
1251 /* Calculate rest of modification rectangle */
1256 * We calculate two rectangles. One for the first line which may have
1257 * an indent with respect to the format rect. The other is a format-width
1258 * rectangle that spans the rest of the lines that changed or moved.
1260 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1261 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1262 rc
.bottom
= rc
.top
+ es
->line_height
;
1263 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1264 rc
.left
= es
->format_rect
.left
;
1266 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1267 es
->text
+ nstart_index
, istart
- nstart_index
,
1268 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1269 rc
.right
= es
->format_rect
.right
;
1270 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1273 rc
.left
= es
->format_rect
.left
;
1274 rc
.right
= es
->format_rect
.right
;
1276 * If lines were added or removed we must re-paint the remainder of the
1277 * lines since the remaining lines were either shifted up or down.
1279 if (line_count
< es
->line_count
) /* We added lines */
1280 rc
.bottom
= es
->line_count
* es
->line_height
;
1281 else if (line_count
> es
->line_count
) /* We removed lines */
1282 rc
.bottom
= line_count
* es
->line_height
;
1284 rc
.bottom
= line_index
* es
->line_height
;
1285 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1286 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1287 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1288 DeleteObject(tmphrgn
);
1292 SelectObject(dc
, old_font
);
1294 ReleaseDC(es
->hwndSelf
, dc
);
1297 /*********************************************************************
1299 * EDIT_CalcLineWidth_SL
1302 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1309 text
= EDIT_GetPasswordPointer_SL(es
);
1311 dc
= GetDC(es
->hwndSelf
);
1313 old_font
= SelectObject(dc
, es
->font
);
1315 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1318 SelectObject(dc
, old_font
);
1319 ReleaseDC(es
->hwndSelf
, dc
);
1321 if (es
->style
& ES_PASSWORD
)
1322 HeapFree(GetProcessHeap(), 0, text
);
1324 es
->text_width
= size
.cx
;
1327 /*********************************************************************
1329 * EDIT_CallWordBreakProc
1331 * Call appropriate WordBreakProc (internal or external).
1333 * Note: The "start" argument should always be an index referring
1334 * to es->text. The actual wordbreak proc might be
1335 * 16 bit, so we can't always pass any 32 bit LPSTR.
1336 * Hence we assume that es->text is the buffer that holds
1337 * the string under examination (we can decide this for ourselves).
1340 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1344 if (es
->word_break_proc16
) {
1351 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1352 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1353 segptr
= K32WOWGlobalLock16(hglob16
);
1354 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1355 args
[4] = SELECTOROF(segptr
);
1356 args
[3] = OFFSETOF(segptr
);
1360 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1361 ret
= LOWORD(result
);
1362 GlobalUnlock16(hglob16
);
1363 GlobalFree16(hglob16
);
1365 else if (es
->word_break_proc
)
1369 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1371 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1372 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1373 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1377 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1381 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1382 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1383 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1384 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1385 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1386 ret
= wbpA(textA
, index
, countA
, action
);
1387 HeapFree(GetProcessHeap(), 0, textA
);
1391 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1397 /*********************************************************************
1401 * Beware: This is not the function called on EM_CHARFROMPOS
1402 * The position _can_ be outside the formatting / client
1404 * The return value is only the character index
1407 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1413 if (es
->style
& ES_MULTILINE
) {
1414 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1416 LINEDEF
*line_def
= es
->first_line_def
;
1418 while ((line
> 0) && line_def
->next
) {
1419 line_index
+= line_def
->length
;
1420 line_def
= line_def
->next
;
1423 x
+= es
->x_offset
- es
->format_rect
.left
;
1424 if (es
->style
& ES_RIGHT
)
1425 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1426 else if (es
->style
& ES_CENTER
)
1427 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1428 if (x
>= line_def
->width
) {
1430 *after_wrap
= (line_def
->ending
== END_WRAP
);
1431 return line_index
+ line_def
->net_length
;
1435 *after_wrap
= FALSE
;
1438 dc
= GetDC(es
->hwndSelf
);
1440 old_font
= SelectObject(dc
, es
->font
);
1441 low
= line_index
+ 1;
1442 high
= line_index
+ line_def
->net_length
+ 1;
1443 while (low
< high
- 1)
1445 INT mid
= (low
+ high
) / 2;
1446 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1452 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1453 (line_def
->ending
== END_WRAP
));
1458 *after_wrap
= FALSE
;
1459 x
-= es
->format_rect
.left
;
1461 return es
->x_offset
;
1465 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1466 if (es
->style
& ES_RIGHT
)
1468 else if (es
->style
& ES_CENTER
)
1472 text
= EDIT_GetPasswordPointer_SL(es
);
1473 dc
= GetDC(es
->hwndSelf
);
1475 old_font
= SelectObject(dc
, es
->font
);
1479 INT high
= es
->x_offset
;
1480 while (low
< high
- 1)
1482 INT mid
= (low
+ high
) / 2;
1483 GetTextExtentPoint32W( dc
, text
+ mid
,
1484 es
->x_offset
- mid
, &size
);
1485 if (size
.cx
> -x
) low
= mid
;
1492 INT low
= es
->x_offset
;
1493 INT high
= strlenW(es
->text
) + 1;
1494 while (low
< high
- 1)
1496 INT mid
= (low
+ high
) / 2;
1497 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1498 mid
- es
->x_offset
, &size
);
1499 if (size
.cx
> x
) high
= mid
;
1504 if (es
->style
& ES_PASSWORD
)
1505 HeapFree(GetProcessHeap(), 0, text
);
1508 SelectObject(dc
, old_font
);
1509 ReleaseDC(es
->hwndSelf
, dc
);
1514 /*********************************************************************
1518 * adjusts the point to be within the formatting rectangle
1519 * (so CharFromPos returns the nearest _visible_ character)
1522 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1524 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1525 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1529 /*********************************************************************
1533 * Calculates the bounding rectangle for a line from a starting
1534 * column to an ending column.
1537 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1539 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1541 if (es
->style
& ES_MULTILINE
)
1542 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1544 rc
->top
= es
->format_rect
.top
;
1545 rc
->bottom
= rc
->top
+ es
->line_height
;
1546 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1547 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1551 /*********************************************************************
1553 * EDIT_GetPasswordPointer_SL
1555 * note: caller should free the (optionally) allocated buffer
1558 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1560 if (es
->style
& ES_PASSWORD
) {
1561 INT len
= strlenW(es
->text
);
1562 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1564 while(len
) text
[--len
] = es
->password_char
;
1571 /*********************************************************************
1575 * This acts as a LocalLock16(), but it locks only once. This way
1576 * you can call it whenever you like, without unlocking.
1578 * Initially the edit control allocates a HLOCAL32 buffer
1579 * (32 bit linear memory handler). However, 16 bit application
1580 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1581 * handler). From that moment on we have to keep using this 16 bit memory
1582 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1583 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1587 static void EDIT_LockBuffer(EDITSTATE
*es
)
1589 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
1590 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1591 HANDLE16 oldDS
= stack16
->ds
;
1596 BOOL _16bit
= FALSE
;
1602 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1603 textA
= LocalLock(es
->hloc32A
);
1604 countA
= strlen(textA
) + 1;
1608 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1609 stack16
->ds
= hInstance
;
1610 textA
= MapSL(LocalLock16(es
->hloc16
));
1611 stack16
->ds
= oldDS
;
1612 countA
= strlen(textA
) + 1;
1617 ERR("no buffer ... please report\n");
1624 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1625 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1626 if(countW_new
> es
->buffer_size
+ 1)
1628 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1629 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1630 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1633 es
->hloc32W
= hloc32W_new
;
1634 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1635 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1638 WARN("FAILED! Will synchronize partially\n");
1642 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1643 es
->text
= LocalLock(es
->hloc32W
);
1647 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1650 stack16
->ds
= hInstance
;
1651 LocalUnlock16(es
->hloc16
);
1652 stack16
->ds
= oldDS
;
1655 LocalUnlock(es
->hloc32A
);
1662 /*********************************************************************
1664 * EDIT_SL_InvalidateText
1666 * Called from EDIT_InvalidateText().
1667 * Does the job for single-line controls only.
1670 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1675 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1676 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1677 EDIT_UpdateText(es
, &rc
, TRUE
);
1681 /*********************************************************************
1683 * EDIT_ML_InvalidateText
1685 * Called from EDIT_InvalidateText().
1686 * Does the job for multi-line controls only.
1689 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1691 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1692 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1693 INT el
= EDIT_EM_LineFromChar(es
, end
);
1702 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1705 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1706 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1707 if (sl
< es
->y_offset
) {
1711 if (el
> es
->y_offset
+ vlc
) {
1712 el
= es
->y_offset
+ vlc
;
1713 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1715 GetClientRect(es
->hwndSelf
, &rc1
);
1716 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1718 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1719 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1720 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1722 EDIT_GetLineRect(es
, sl
, sc
,
1723 EDIT_EM_LineLength(es
,
1724 EDIT_EM_LineIndex(es
, sl
)),
1726 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1727 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1728 for (l
= sl
+ 1 ; l
< el
; l
++) {
1729 EDIT_GetLineRect(es
, l
, 0,
1730 EDIT_EM_LineLength(es
,
1731 EDIT_EM_LineIndex(es
, l
)),
1733 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1734 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1736 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1737 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1738 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1743 /*********************************************************************
1745 * EDIT_InvalidateText
1747 * Invalidate the text from offset start upto, but not including,
1748 * offset end. Useful for (re)painting the selection.
1749 * Regions outside the linewidth are not invalidated.
1750 * end == -1 means end == TextLength.
1751 * start and end need not be ordered.
1754 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1760 end
= strlenW(es
->text
);
1768 if (es
->style
& ES_MULTILINE
)
1769 EDIT_ML_InvalidateText(es
, start
, end
);
1771 EDIT_SL_InvalidateText(es
, start
, end
);
1775 /*********************************************************************
1779 * Try to fit size + 1 characters in the buffer.
1781 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1785 if (size
<= es
->buffer_size
)
1788 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1790 /* Force edit to unlock it's buffer. es->text now NULL */
1791 EDIT_UnlockBuffer(es
, TRUE
);
1794 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1795 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1796 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1797 es
->hloc32W
= hNew32W
;
1798 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1802 EDIT_LockBuffer(es
);
1804 if (es
->buffer_size
< size
) {
1805 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1806 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1809 TRACE("We now have %d+1\n", es
->buffer_size
);
1815 /*********************************************************************
1819 * Try to fit size + 1 bytes in the undo buffer.
1822 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1826 if (size
<= es
->undo_buffer_size
)
1829 TRACE("trying to ReAlloc to %d+1\n", size
);
1831 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1832 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1833 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1838 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1844 /*********************************************************************
1849 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1851 INT e
= es
->selection_end
;
1855 if ((es
->style
& ES_MULTILINE
) && e
&&
1856 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1858 if (e
&& (es
->text
[e
- 1] == '\r'))
1862 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1863 EDIT_EM_ScrollCaret(es
);
1867 /*********************************************************************
1871 * Only for multi line controls
1872 * Move the caret one line down, on a column with the nearest
1873 * x coordinate on the screen (might be a different column).
1876 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1878 INT s
= es
->selection_start
;
1879 INT e
= es
->selection_end
;
1880 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1881 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1882 INT x
= (short)LOWORD(pos
);
1883 INT y
= (short)HIWORD(pos
);
1885 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1888 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1889 EDIT_EM_ScrollCaret(es
);
1893 /*********************************************************************
1898 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1900 BOOL after_wrap
= FALSE
;
1903 /* Pass a high value in x to make sure of receiving the end of the line */
1904 if (es
->style
& ES_MULTILINE
)
1905 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1906 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1908 e
= strlenW(es
->text
);
1909 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1910 EDIT_EM_ScrollCaret(es
);
1914 /*********************************************************************
1919 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1921 INT e
= es
->selection_end
;
1925 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1926 if (es
->text
[e
] == '\n')
1928 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1932 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1933 EDIT_EM_ScrollCaret(es
);
1937 /*********************************************************************
1941 * Home key: move to beginning of line.
1944 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1948 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1949 if (es
->style
& ES_MULTILINE
)
1950 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1951 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1954 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1955 EDIT_EM_ScrollCaret(es
);
1959 /*********************************************************************
1961 * EDIT_MovePageDown_ML
1963 * Only for multi line controls
1964 * Move the caret one page down, on a column with the nearest
1965 * x coordinate on the screen (might be a different column).
1968 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1970 INT s
= es
->selection_start
;
1971 INT e
= es
->selection_end
;
1972 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1973 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1974 INT x
= (short)LOWORD(pos
);
1975 INT y
= (short)HIWORD(pos
);
1977 e
= EDIT_CharFromPos(es
, x
,
1978 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1982 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1983 EDIT_EM_ScrollCaret(es
);
1987 /*********************************************************************
1989 * EDIT_MovePageUp_ML
1991 * Only for multi line controls
1992 * Move the caret one page up, on a column with the nearest
1993 * x coordinate on the screen (might be a different column).
1996 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1998 INT s
= es
->selection_start
;
1999 INT e
= es
->selection_end
;
2000 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2001 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2002 INT x
= (short)LOWORD(pos
);
2003 INT y
= (short)HIWORD(pos
);
2005 e
= EDIT_CharFromPos(es
, x
,
2006 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2010 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2011 EDIT_EM_ScrollCaret(es
);
2015 /*********************************************************************
2019 * Only for multi line controls
2020 * Move the caret one line up, on a column with the nearest
2021 * x coordinate on the screen (might be a different column).
2024 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2026 INT s
= es
->selection_start
;
2027 INT e
= es
->selection_end
;
2028 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2029 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2030 INT x
= (short)LOWORD(pos
);
2031 INT y
= (short)HIWORD(pos
);
2033 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2036 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2037 EDIT_EM_ScrollCaret(es
);
2041 /*********************************************************************
2043 * EDIT_MoveWordBackward
2046 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2048 INT s
= es
->selection_start
;
2049 INT e
= es
->selection_end
;
2054 l
= EDIT_EM_LineFromChar(es
, e
);
2055 ll
= EDIT_EM_LineLength(es
, e
);
2056 li
= EDIT_EM_LineIndex(es
, l
);
2059 li
= EDIT_EM_LineIndex(es
, l
- 1);
2060 e
= li
+ EDIT_EM_LineLength(es
, li
);
2063 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2064 li
, e
- li
, ll
, WB_LEFT
);
2068 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2069 EDIT_EM_ScrollCaret(es
);
2073 /*********************************************************************
2075 * EDIT_MoveWordForward
2078 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2080 INT s
= es
->selection_start
;
2081 INT e
= es
->selection_end
;
2086 l
= EDIT_EM_LineFromChar(es
, e
);
2087 ll
= EDIT_EM_LineLength(es
, e
);
2088 li
= EDIT_EM_LineIndex(es
, l
);
2090 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2091 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2093 e
= li
+ EDIT_CallWordBreakProc(es
,
2094 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2098 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2099 EDIT_EM_ScrollCaret(es
);
2103 /*********************************************************************
2108 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2110 INT s
= es
->selection_start
;
2111 INT e
= es
->selection_end
;
2118 if (es
->style
& ES_MULTILINE
) {
2119 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2120 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2125 TRACE("line=%d\n", line
);
2127 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2128 x
= (short)LOWORD(pos
);
2129 y
= (short)HIWORD(pos
);
2130 li
= EDIT_EM_LineIndex(es
, line
);
2131 ll
= EDIT_EM_LineLength(es
, li
);
2132 s
= min(es
->selection_start
, es
->selection_end
);
2133 e
= max(es
->selection_start
, es
->selection_end
);
2134 s
= min(li
+ ll
, max(li
, s
));
2135 e
= min(li
+ ll
, max(li
, e
));
2136 if (rev
&& (s
!= e
) &&
2137 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2138 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2139 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2140 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2142 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2146 /*********************************************************************
2151 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2162 BkMode
= GetBkMode(dc
);
2163 BkColor
= GetBkColor(dc
);
2164 TextColor
= GetTextColor(dc
);
2166 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2167 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2168 SetBkMode( dc
, OPAQUE
);
2170 li
= EDIT_EM_LineIndex(es
, line
);
2171 if (es
->style
& ES_MULTILINE
) {
2172 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2173 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2175 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2176 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2177 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2179 if (es
->style
& ES_PASSWORD
)
2180 HeapFree(GetProcessHeap(), 0, text
);
2183 SetBkColor(dc
, BkColor
);
2184 SetTextColor(dc
, TextColor
);
2185 SetBkMode( dc
, BkMode
);
2191 /*********************************************************************
2196 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2199 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2200 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2201 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2205 /*********************************************************************
2209 * note: this is not (exactly) the handler called on EM_SETRECTNP
2210 * it is also used to set the rect of a single line control
2213 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2218 CopyRect(&es
->format_rect
, rc
);
2219 if (es
->style
& ES_MULTILINE
)
2221 if (es
->style
& WS_BORDER
) {
2222 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2223 es
->format_rect
.left
+= bw
;
2224 es
->format_rect
.right
-= bw
;
2225 es
->format_rect
.top
+= bw
;
2226 es
->format_rect
.bottom
-= bw
;
2231 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2232 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2233 if (es
->line_height
+ 2 <=
2234 es
->format_rect
.bottom
- es
->format_rect
.top
) {
2235 es
->format_rect
.top
++;
2236 es
->format_rect
.bottom
--;
2238 } else if (es
->style
& WS_BORDER
) {
2239 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2240 es
->format_rect
.left
+= bw
;
2241 es
->format_rect
.right
-= bw
;
2242 if (es
->line_height
+ 2 * bw
<=
2243 es
->format_rect
.bottom
- es
->format_rect
.top
) {
2244 es
->format_rect
.top
+= bw
;
2245 es
->format_rect
.bottom
-= bw
;
2249 es
->format_rect
.left
+= es
->left_margin
;
2250 es
->format_rect
.right
-= es
->right_margin
;
2251 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2252 if (es
->style
& ES_MULTILINE
)
2254 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2256 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2257 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2259 /* correct es->x_offset */
2260 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2261 max_x_offset
= es
->text_width
- fw
;
2262 if(max_x_offset
< 0) max_x_offset
= 0;
2263 if(es
->x_offset
> max_x_offset
)
2264 es
->x_offset
= max_x_offset
;
2266 /* correct es->y_offset */
2267 max_y_offset
= es
->line_count
- vlc
;
2268 if(max_y_offset
< 0) max_y_offset
= 0;
2269 if(es
->y_offset
> max_y_offset
)
2270 es
->y_offset
= max_y_offset
;
2272 /* force scroll info update */
2273 EDIT_UpdateScrollInfo(es
);
2276 /* Windows doesn't care to fix text placement for SL controls */
2277 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2279 /* Always stay within the client area */
2280 GetClientRect(es
->hwndSelf
, &ClientRect
);
2281 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2283 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2284 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2286 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2290 /*********************************************************************
2295 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2298 /* Edit window might be already destroyed */
2299 if(!IsWindow(es
->hwndSelf
))
2301 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2305 if (!es
->lock_count
) {
2306 ERR("lock_count == 0 ... please report\n");
2310 ERR("es->text == 0 ... please report\n");
2314 if (force
|| (es
->lock_count
== 1)) {
2318 UINT countW
= strlenW(es
->text
) + 1;
2319 STACK16FRAME
* stack16
= NULL
;
2324 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2325 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2326 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2327 countA
= LocalSize(es
->hloc32A
);
2328 if(countA_new
> countA
)
2331 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2332 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2333 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2336 es
->hloc32A
= hloc32A_new
;
2337 countA
= LocalSize(hloc32A_new
);
2338 TRACE("Real new size %d bytes\n", countA
);
2341 WARN("FAILED! Will synchronize partially\n");
2343 textA
= LocalLock(es
->hloc32A
);
2347 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2349 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2350 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2352 stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
2353 oldDS
= stack16
->ds
;
2354 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2356 countA
= LocalSize16(es
->hloc16
);
2357 if(countA_new
> countA
)
2359 HLOCAL16 hloc16_new
;
2360 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2361 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2362 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2365 es
->hloc16
= hloc16_new
;
2366 countA
= LocalSize16(hloc16_new
);
2367 TRACE("Real new size %d bytes\n", countA
);
2370 WARN("FAILED! Will synchronize partially\n");
2372 textA
= MapSL(LocalLock16(es
->hloc16
));
2377 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2379 LocalUnlock16(es
->hloc16
);
2381 LocalUnlock(es
->hloc32A
);
2384 if (stack16
) stack16
->ds
= oldDS
;
2385 LocalUnlock(es
->hloc32W
);
2389 ERR("no buffer ... please report\n");
2397 /*********************************************************************
2399 * EDIT_UpdateScrollInfo
2402 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2404 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2407 si
.cbSize
= sizeof(SCROLLINFO
);
2408 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2410 si
.nMax
= es
->line_count
- 1;
2411 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2412 si
.nPos
= es
->y_offset
;
2413 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2414 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2415 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2418 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2421 si
.cbSize
= sizeof(SCROLLINFO
);
2422 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2424 si
.nMax
= es
->text_width
- 1;
2425 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2426 si
.nPos
= es
->x_offset
;
2427 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2428 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2429 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2433 /*********************************************************************
2435 * EDIT_WordBreakProc
2437 * Find the beginning of words.
2438 * Note: unlike the specs for a WordBreakProc, this function only
2439 * allows to be called without linebreaks between s[0] upto
2440 * s[count - 1]. Remember it is only called
2441 * internally, so we can decide this for ourselves.
2444 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2448 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2458 if (s
[index
] == ' ') {
2459 while (index
&& (s
[index
] == ' '))
2462 while (index
&& (s
[index
] != ' '))
2464 if (s
[index
] == ' ')
2468 while (index
&& (s
[index
] != ' '))
2470 if (s
[index
] == ' ')
2480 if (s
[index
] == ' ')
2481 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2483 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2485 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2489 case WB_ISDELIMITER
:
2490 ret
= (s
[index
] == ' ');
2493 ERR("unknown action code, please report !\n");
2500 /*********************************************************************
2504 * returns line number (not index) in high-order word of result.
2505 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2506 * to Richedit, not to the edit control. Original documentation is valid.
2507 * FIXME: do the specs mean to return -1 if outside client area or
2508 * if outside formatting rectangle ???
2511 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2519 GetClientRect(es
->hwndSelf
, &rc
);
2520 if (!PtInRect(&rc
, pt
))
2523 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2524 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2528 /*********************************************************************
2532 * Enable or disable soft breaks.
2534 * This means: insert or remove the soft linebreak character (\r\r\n).
2535 * Take care to check if the text still fits the buffer after insertion.
2536 * If not, notify with EN_ERRSPACE.
2539 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2541 es
->flags
&= ~EF_USE_SOFTBRK
;
2543 es
->flags
|= EF_USE_SOFTBRK
;
2544 FIXME("soft break enabled, not implemented\n");
2550 /*********************************************************************
2554 * Hopefully this won't fire back at us.
2555 * We always start with a fixed buffer in the local heap.
2556 * Despite of the documentation says that the local heap is used
2557 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2558 * buffer on the local heap.
2561 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2565 if (!(es
->style
& ES_MULTILINE
))
2569 hLocal
= es
->hloc32W
;
2575 UINT countA
, alloc_size
;
2576 TRACE("Allocating 32-bit ANSI alias buffer\n");
2577 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2578 alloc_size
= ROUND_TO_GROW(countA
);
2579 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2581 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2584 textA
= LocalLock(es
->hloc32A
);
2585 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2586 LocalUnlock(es
->hloc32A
);
2588 hLocal
= es
->hloc32A
;
2591 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2596 /*********************************************************************
2600 * Hopefully this won't fire back at us.
2601 * We always start with a buffer in 32 bit linear memory.
2602 * However, with this message a 16 bit application requests
2603 * a handle of 16 bit local heap memory, where it expects to find
2605 * It's a pitty that from this moment on we have to use this
2606 * local heap, because applications may rely on the handle
2609 * In this function we'll try to switch to local heap.
2611 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2614 UINT countA
, alloc_size
;
2615 STACK16FRAME
* stack16
;
2618 if (!(es
->style
& ES_MULTILINE
))
2624 stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
2625 oldDS
= stack16
->ds
;
2626 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2628 if (!LocalHeapSize16()) {
2630 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2631 ERR("could not initialize local heap\n");
2634 TRACE("local heap initialized\n");
2637 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2638 alloc_size
= ROUND_TO_GROW(countA
);
2640 TRACE("Allocating 16-bit ANSI alias buffer\n");
2641 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2642 ERR("could not allocate new 16 bit buffer\n");
2646 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2647 ERR("could not lock new 16 bit buffer\n");
2648 LocalFree16(es
->hloc16
);
2653 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2654 LocalUnlock16(es
->hloc16
);
2656 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2659 stack16
->ds
= oldDS
;
2664 /*********************************************************************
2669 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2672 INT line_len
, dst_len
;
2675 if (es
->style
& ES_MULTILINE
) {
2676 if (line
>= es
->line_count
)
2680 i
= EDIT_EM_LineIndex(es
, line
);
2682 line_len
= EDIT_EM_LineLength(es
, i
);
2683 dst_len
= *(WORD
*)dst
;
2686 if(dst_len
<= line_len
)
2688 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2691 else /* Append 0 if enough space */
2693 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2700 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2701 if(!ret
) /* Insufficient buffer size */
2703 if(ret
< dst_len
) /* Append 0 if enough space */
2704 ((LPSTR
)dst
)[ret
] = 0;
2710 /*********************************************************************
2715 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2717 UINT s
= es
->selection_start
;
2718 UINT e
= es
->selection_end
;
2725 return MAKELONG(s
, e
);
2729 /*********************************************************************
2733 * FIXME: is this right ? (or should it be only VSCROLL)
2734 * (and maybe only for edit controls that really have their
2735 * own scrollbars) (and maybe only for multiline controls ?)
2736 * All in all: very poorly documented
2739 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2741 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2742 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2746 /*********************************************************************
2751 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2756 if (!(es
->style
& ES_MULTILINE
))
2758 if (index
> (INT
)strlenW(es
->text
))
2759 return es
->line_count
- 1;
2761 index
= min(es
->selection_start
, es
->selection_end
);
2764 line_def
= es
->first_line_def
;
2765 index
-= line_def
->length
;
2766 while ((index
>= 0) && line_def
->next
) {
2768 line_def
= line_def
->next
;
2769 index
-= line_def
->length
;
2775 /*********************************************************************
2780 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2785 if (!(es
->style
& ES_MULTILINE
))
2787 if (line
>= es
->line_count
)
2791 line_def
= es
->first_line_def
;
2793 INT index
= es
->selection_end
- line_def
->length
;
2794 while ((index
>= 0) && line_def
->next
) {
2795 line_index
+= line_def
->length
;
2796 line_def
= line_def
->next
;
2797 index
-= line_def
->length
;
2801 line_index
+= line_def
->length
;
2802 line_def
= line_def
->next
;
2810 /*********************************************************************
2815 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2819 if (!(es
->style
& ES_MULTILINE
))
2820 return strlenW(es
->text
);
2823 /* get the number of remaining non-selected chars of selected lines */
2824 INT32 l
; /* line number */
2825 INT32 li
; /* index of first char in line */
2827 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2828 /* # chars before start of selection area */
2829 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2830 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2831 /* # chars after end of selection */
2832 li
= EDIT_EM_LineIndex(es
, l
);
2833 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2836 line_def
= es
->first_line_def
;
2837 index
-= line_def
->length
;
2838 while ((index
>= 0) && line_def
->next
) {
2839 line_def
= line_def
->next
;
2840 index
-= line_def
->length
;
2842 return line_def
->net_length
;
2846 /*********************************************************************
2850 * NOTE: dx is in average character widths, dy - in lines;
2853 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2855 if (!(es
->style
& ES_MULTILINE
))
2858 dx
*= es
->char_width
;
2859 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2862 /*********************************************************************
2864 * EDIT_EM_LineScroll_internal
2866 * Version of EDIT_EM_LineScroll for internal use.
2867 * It doesn't refuse if ES_MULTILINE is set and assumes that
2868 * dx is in pixels, dy - in lines.
2871 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2874 INT x_offset_in_pixels
;
2875 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
2878 if (es
->style
& ES_MULTILINE
)
2880 x_offset_in_pixels
= es
->x_offset
;
2885 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2888 if (-dx
> x_offset_in_pixels
)
2889 dx
= -x_offset_in_pixels
;
2890 if (dx
> es
->text_width
- x_offset_in_pixels
)
2891 dx
= es
->text_width
- x_offset_in_pixels
;
2892 nyoff
= max(0, es
->y_offset
+ dy
);
2893 if (nyoff
>= es
->line_count
- lines_per_page
)
2894 nyoff
= max(0, es
->line_count
- lines_per_page
);
2895 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2900 es
->y_offset
= nyoff
;
2901 if(es
->style
& ES_MULTILINE
)
2904 es
->x_offset
+= dx
/ es
->char_width
;
2906 GetClientRect(es
->hwndSelf
, &rc1
);
2907 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2908 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2909 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2910 /* force scroll info update */
2911 EDIT_UpdateScrollInfo(es
);
2913 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2914 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2915 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2916 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2921 /*********************************************************************
2926 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2928 INT len
= strlenW(es
->text
);
2941 index
= min(index
, len
);
2942 dc
= GetDC(es
->hwndSelf
);
2944 old_font
= SelectObject(dc
, es
->font
);
2945 if (es
->style
& ES_MULTILINE
) {
2946 l
= EDIT_EM_LineFromChar(es
, index
);
2947 y
= (l
- es
->y_offset
) * es
->line_height
;
2948 li
= EDIT_EM_LineIndex(es
, l
);
2949 if (after_wrap
&& (li
== index
) && l
) {
2951 line_def
= es
->first_line_def
;
2953 line_def
= line_def
->next
;
2956 if (line_def
->ending
== END_WRAP
) {
2958 y
-= es
->line_height
;
2959 li
= EDIT_EM_LineIndex(es
, l
);
2963 line_def
= es
->first_line_def
;
2964 while (line_def
->index
!= li
)
2965 line_def
= line_def
->next
;
2967 ll
= line_def
->net_length
;
2968 lw
= line_def
->width
;
2970 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2971 if (es
->style
& ES_RIGHT
)
2973 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
2974 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2977 else if (es
->style
& ES_CENTER
)
2979 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2980 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2985 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2986 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2989 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2990 if (index
< es
->x_offset
) {
2991 GetTextExtentPoint32W(dc
, text
+ index
,
2992 es
->x_offset
- index
, &size
);
2995 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2996 index
- es
->x_offset
, &size
);
2999 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3001 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3002 if (w
> es
->text_width
)
3004 if (es
->style
& ES_RIGHT
)
3005 x
+= w
- es
->text_width
;
3006 else if (es
->style
& ES_CENTER
)
3007 x
+= (w
- es
->text_width
) / 2;
3012 if (es
->style
& ES_PASSWORD
)
3013 HeapFree(GetProcessHeap(), 0, text
);
3015 x
+= es
->format_rect
.left
;
3016 y
+= es
->format_rect
.top
;
3018 SelectObject(dc
, old_font
);
3019 ReleaseDC(es
->hwndSelf
, dc
);
3020 return MAKELONG((INT16
)x
, (INT16
)y
);
3024 /*********************************************************************
3028 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3031 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3033 UINT strl
= strlenW(lpsz_replace
);
3034 UINT tl
= strlenW(es
->text
);
3045 TRACE("%s, can_undo %d, send_update %d\n",
3046 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3048 s
= es
->selection_start
;
3049 e
= es
->selection_end
;
3051 if ((s
== e
) && !strl
)
3056 size
= tl
- (e
- s
) + strl
;
3060 /* Issue the EN_MAXTEXT notification and continue with replacing text
3061 * such that buffer limit is honored. */
3062 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
3063 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
3064 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3067 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3071 /* there is something to be deleted */
3072 TRACE("deleting stuff.\n");
3074 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3076 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3077 buf
[bufl
] = 0; /* ensure 0 termination */
3079 strcpyW(es
->text
+ s
, es
->text
+ e
);
3082 /* there is an insertion */
3083 tl
= strlenW(es
->text
);
3084 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
));
3085 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3087 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3088 p
[i
] = lpsz_replace
[i
];
3089 if(es
->style
& ES_UPPERCASE
)
3090 CharUpperBuffW(p
, strl
);
3091 else if(es
->style
& ES_LOWERCASE
)
3092 CharLowerBuffW(p
, strl
);
3094 if (es
->style
& ES_MULTILINE
)
3096 INT st
= min(es
->selection_start
, es
->selection_end
);
3097 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3099 hrgn
= CreateRectRgn(0, 0, 0, 0);
3100 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3101 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3102 /* if text is too long undo all changes */
3103 if (!(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3105 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3107 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3109 EDIT_BuildLineDefs_ML(es
, s
, e
,
3110 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3113 hrgn
= CreateRectRgn(0, 0, 0, 0);
3114 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
3118 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3119 EDIT_CalcLineWidth_SL(es
);
3120 /* remove chars that don't fit */
3121 if (!(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3122 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3123 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3125 EDIT_CalcLineWidth_SL(es
);
3127 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
3133 utl
= strlenW(es
->undo_text
);
3134 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3135 /* undo-buffer is extended to the right */
3136 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3137 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3138 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3139 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3140 /* undo-buffer is extended to the left */
3141 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3142 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3144 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3146 es
->undo_position
= s
;
3148 /* new undo-buffer */
3149 EDIT_MakeUndoFit(es
, e
- s
);
3150 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3151 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3152 es
->undo_position
= s
;
3154 /* any deletion makes the old insertion-undo invalid */
3155 es
->undo_insert_count
= 0;
3157 EDIT_EM_EmptyUndoBuffer(es
);
3161 if ((s
== es
->undo_position
) ||
3162 ((es
->undo_insert_count
) &&
3163 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3165 * insertion is new and at delete position or
3166 * an extension to either left or right
3168 es
->undo_insert_count
+= strl
;
3170 /* new insertion undo */
3171 es
->undo_position
= s
;
3172 es
->undo_insert_count
= strl
;
3173 /* new insertion makes old delete-buffer invalid */
3174 *es
->undo_text
= '\0';
3177 EDIT_EM_EmptyUndoBuffer(es
);
3181 HeapFree(GetProcessHeap(), 0, buf
);
3185 /* If text has been deleted and we're right or center aligned then scroll rightward */
3186 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3188 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3190 if (delta
< 0 && es
->x_offset
)
3192 if (abs(delta
) > es
->x_offset
)
3195 es
->x_offset
+= delta
;
3199 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3200 es
->flags
|= EF_MODIFIED
;
3201 if (send_update
) es
->flags
|= EF_UPDATE
;
3204 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3208 EDIT_UpdateText(es
, NULL
, TRUE
);
3210 EDIT_EM_ScrollCaret(es
);
3212 /* force scroll info update */
3213 EDIT_UpdateScrollInfo(es
);
3216 if(send_update
|| (es
->flags
& EF_UPDATE
))
3218 es
->flags
&= ~EF_UPDATE
;
3219 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3224 /*********************************************************************
3229 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3233 if (!(es
->style
& ES_MULTILINE
))
3234 return (LRESULT
)FALSE
;
3244 if (es
->y_offset
< es
->line_count
- 1)
3249 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3252 if (es
->y_offset
< es
->line_count
- 1)
3253 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3256 return (LRESULT
)FALSE
;
3259 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3260 /* check if we are going to move too far */
3261 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3262 dy
= es
->line_count
- vlc
- es
->y_offset
;
3264 /* Notification is done in EDIT_EM_LineScroll */
3266 EDIT_EM_LineScroll(es
, 0, dy
);
3268 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3272 /*********************************************************************
3277 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3279 if (es
->style
& ES_MULTILINE
) {
3284 INT cw
= es
->char_width
;
3289 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3290 li
= EDIT_EM_LineIndex(es
, l
);
3291 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3292 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3293 if (l
>= es
->y_offset
+ vlc
)
3294 dy
= l
- vlc
+ 1 - es
->y_offset
;
3295 if (l
< es
->y_offset
)
3296 dy
= l
- es
->y_offset
;
3297 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3298 if (x
< es
->format_rect
.left
)
3299 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3300 if (x
> es
->format_rect
.right
)
3301 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3302 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3304 /* check if we are going to move too far */
3305 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3306 dx
= es
->text_width
- ww
- es
->x_offset
;
3307 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3308 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3315 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3316 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3317 if (x
< es
->format_rect
.left
) {
3318 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3321 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3322 } while ((x
< goal
) && es
->x_offset
);
3323 /* FIXME: use ScrollWindow() somehow to improve performance */
3324 EDIT_UpdateText(es
, NULL
, TRUE
);
3325 } else if (x
> es
->format_rect
.right
) {
3327 INT len
= strlenW(es
->text
);
3328 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3331 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3332 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3333 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3334 /* FIXME: use ScrollWindow() somehow to improve performance */
3335 EDIT_UpdateText(es
, NULL
, TRUE
);
3339 if(es
->flags
& EF_FOCUSED
)
3340 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3344 /*********************************************************************
3348 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3351 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3353 if (!(es
->style
& ES_MULTILINE
))
3357 WARN("called with NULL handle\n");
3361 EDIT_UnlockBuffer(es
, TRUE
);
3365 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
3366 HANDLE16 oldDS
= stack16
->ds
;
3368 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3369 LocalFree16(es
->hloc16
);
3370 stack16
->ds
= oldDS
;
3378 LocalFree(es
->hloc32A
);
3390 countA
= LocalSize(hloc
);
3391 textA
= LocalLock(hloc
);
3392 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3393 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3395 ERR("Could not allocate new unicode buffer\n");
3398 textW
= LocalLock(hloc32W_new
);
3399 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3400 LocalUnlock(hloc32W_new
);
3404 LocalFree(es
->hloc32W
);
3406 es
->hloc32W
= hloc32W_new
;
3410 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3412 EDIT_LockBuffer(es
);
3414 es
->x_offset
= es
->y_offset
= 0;
3415 es
->selection_start
= es
->selection_end
= 0;
3416 EDIT_EM_EmptyUndoBuffer(es
);
3417 es
->flags
&= ~EF_MODIFIED
;
3418 es
->flags
&= ~EF_UPDATE
;
3419 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3420 EDIT_UpdateText(es
, NULL
, TRUE
);
3421 EDIT_EM_ScrollCaret(es
);
3422 /* force scroll info update */
3423 EDIT_UpdateScrollInfo(es
);
3427 /*********************************************************************
3431 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3434 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3436 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
3437 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3438 HANDLE16 oldDS
= stack16
->ds
;
3444 if (!(es
->style
& ES_MULTILINE
))
3448 WARN("called with NULL handle\n");
3452 EDIT_UnlockBuffer(es
, TRUE
);
3456 LocalFree(es
->hloc32A
);
3460 stack16
->ds
= hInstance
;
3461 countA
= LocalSize16(hloc
);
3462 textA
= MapSL(LocalLock16(hloc
));
3463 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3464 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3466 ERR("Could not allocate new unicode buffer\n");
3469 textW
= LocalLock(hloc32W_new
);
3470 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3471 LocalUnlock(hloc32W_new
);
3472 LocalUnlock16(hloc
);
3473 stack16
->ds
= oldDS
;
3476 LocalFree(es
->hloc32W
);
3478 es
->hloc32W
= hloc32W_new
;
3481 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3483 EDIT_LockBuffer(es
);
3485 es
->x_offset
= es
->y_offset
= 0;
3486 es
->selection_start
= es
->selection_end
= 0;
3487 EDIT_EM_EmptyUndoBuffer(es
);
3488 es
->flags
&= ~EF_MODIFIED
;
3489 es
->flags
&= ~EF_UPDATE
;
3490 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3491 EDIT_UpdateText(es
, NULL
, TRUE
);
3492 EDIT_EM_ScrollCaret(es
);
3493 /* force scroll info update */
3494 EDIT_UpdateScrollInfo(es
);
3498 /*********************************************************************
3502 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3503 * However, the windows version is not complied to yet in all of edit.c
3505 * Additionally as the wrapper for RichEdit controls we need larger buffers
3506 * at present -1 will represent nolimit
3508 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3510 if (limit
== 0xFFFFFFFF)
3511 es
->buffer_limit
= -1;
3512 else if (es
->style
& ES_MULTILINE
) {
3514 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3516 es
->buffer_limit
= BUFLIMIT_MULTI
;
3519 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3521 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3526 /*********************************************************************
3530 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3531 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3532 * margin according to the textmetrics of the current font.
3534 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3535 * of the char's width as the margin, but this is not how Windows handles this.
3536 * For all other fonts Windows sets the margins to zero.
3539 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3540 INT left
, INT right
)
3543 INT default_left_margin
= 0; /* in pixels */
3544 INT default_right_margin
= 0; /* in pixels */
3546 /* Set the default margins depending on the font */
3547 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3548 HDC dc
= GetDC(es
->hwndSelf
);
3549 HFONT old_font
= SelectObject(dc
, es
->font
);
3550 GetTextMetricsW(dc
, &tm
);
3551 /* The default margins are only non zero for TrueType or Vector fonts */
3552 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3553 /* This must be calculated more exactly! But how? */
3554 default_left_margin
= tm
.tmAveCharWidth
/ 3;
3555 default_right_margin
= tm
.tmAveCharWidth
/ 3;
3557 SelectObject(dc
, old_font
);
3558 ReleaseDC(es
->hwndSelf
, dc
);
3561 if (action
& EC_LEFTMARGIN
) {
3562 if (left
!= EC_USEFONTINFO
)
3563 es
->left_margin
= left
;
3565 es
->left_margin
= default_left_margin
;
3568 if (action
& EC_RIGHTMARGIN
) {
3569 if (right
!= EC_USEFONTINFO
)
3570 es
->right_margin
= right
;
3572 es
->right_margin
= default_right_margin
;
3574 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3578 /*********************************************************************
3580 * EM_SETPASSWORDCHAR
3583 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3587 if (es
->style
& ES_MULTILINE
)
3590 if (es
->password_char
== c
)
3593 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3594 es
->password_char
= c
;
3596 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3597 es
->style
|= ES_PASSWORD
;
3599 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3600 es
->style
&= ~ES_PASSWORD
;
3602 EDIT_UpdateText(es
, NULL
, TRUE
);
3606 /*********************************************************************
3610 * note: unlike the specs say: the order of start and end
3611 * _is_ preserved in Windows. (i.e. start can be > end)
3612 * In other words: this handler is OK
3615 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3617 UINT old_start
= es
->selection_start
;
3618 UINT old_end
= es
->selection_end
;
3619 UINT len
= strlenW(es
->text
);
3621 if (start
== (UINT
)-1) {
3622 start
= es
->selection_end
;
3623 end
= es
->selection_end
;
3625 start
= min(start
, len
);
3626 end
= min(end
, len
);
3628 es
->selection_start
= start
;
3629 es
->selection_end
= end
;
3631 es
->flags
|= EF_AFTER_WRAP
;
3633 es
->flags
&= ~EF_AFTER_WRAP
;
3634 /* Compute the necessary invalidation region. */
3635 /* Note that we don't need to invalidate regions which have
3636 * "never" been selected, or those which are "still" selected.
3637 * In fact, every time we hit a selection boundary, we can
3638 * *toggle* whether we need to invalidate. Thus we can optimize by
3639 * *sorting* the interval endpoints. Let's assume that we sort them
3641 * start <= end <= old_start <= old_end
3642 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3643 * in 5 comparisons; ie it's impossible to do better than the
3645 ORDER_UINT(end
, old_end
);
3646 ORDER_UINT(start
, old_start
);
3647 ORDER_UINT(old_start
, old_end
);
3648 ORDER_UINT(start
, end
);
3649 /* Note that at this point 'end' and 'old_start' are not in order, but
3650 * start is definitely the min. and old_end is definitely the max. */
3651 if (end
!= old_start
)
3655 * ORDER_UINT32(end, old_start);
3656 * EDIT_InvalidateText(es, start, end);
3657 * EDIT_InvalidateText(es, old_start, old_end);
3658 * in place of the following if statement.
3659 * (That would complete the optimal five-comparison four-element sort.)
3661 if (old_start
> end
)
3663 EDIT_InvalidateText(es
, start
, end
);
3664 EDIT_InvalidateText(es
, old_start
, old_end
);
3668 EDIT_InvalidateText(es
, start
, old_start
);
3669 EDIT_InvalidateText(es
, end
, old_end
);
3672 else EDIT_InvalidateText(es
, start
, old_end
);
3676 /*********************************************************************
3681 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3683 if (!(es
->style
& ES_MULTILINE
))
3685 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3686 es
->tabs_count
= count
;
3690 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3691 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3697 /*********************************************************************
3702 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3704 if (!(es
->style
& ES_MULTILINE
))
3706 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3707 es
->tabs_count
= count
;
3712 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3713 for (i
= 0 ; i
< count
; i
++)
3714 es
->tabs
[i
] = *tabs
++;
3720 /*********************************************************************
3722 * EM_SETWORDBREAKPROC
3725 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3727 if (es
->word_break_proc
== wbp
)
3730 es
->word_break_proc
= wbp
;
3731 es
->word_break_proc16
= NULL
;
3733 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3734 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3735 EDIT_UpdateText(es
, NULL
, TRUE
);
3740 /*********************************************************************
3742 * EM_SETWORDBREAKPROC16
3745 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3747 if (es
->word_break_proc16
== wbp
)
3750 es
->word_break_proc
= NULL
;
3751 es
->word_break_proc16
= wbp
;
3752 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3753 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3754 EDIT_UpdateText(es
, NULL
, TRUE
);
3759 /*********************************************************************
3764 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3769 /* As per MSDN spec, for a single-line edit control,
3770 the return value is always TRUE */
3771 if( es
->style
& ES_READONLY
)
3772 return !(es
->style
& ES_MULTILINE
);
3774 ulength
= strlenW(es
->undo_text
);
3776 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3778 strcpyW(utext
, es
->undo_text
);
3780 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3781 es
->undo_insert_count
, debugstr_w(utext
));
3783 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3784 EDIT_EM_EmptyUndoBuffer(es
);
3785 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3786 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3787 /* send the notification after the selection start and end are set */
3788 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3789 EDIT_EM_ScrollCaret(es
);
3790 HeapFree(GetProcessHeap(), 0, utext
);
3792 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3793 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3798 /*********************************************************************
3803 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3807 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3811 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3812 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3815 if (es
->style
& ES_MULTILINE
) {
3816 if (es
->style
& ES_READONLY
) {
3817 EDIT_MoveHome(es
, FALSE
);
3818 EDIT_MoveDown_ML(es
, FALSE
);
3820 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3821 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3826 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3828 static const WCHAR tabW
[] = {'\t',0};
3829 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3833 if (!(es
->style
& ES_READONLY
) && !control
) {
3834 if (es
->selection_start
!= es
->selection_end
)
3837 /* delete character left of caret */
3838 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3839 EDIT_MoveBackward(es
, TRUE
);
3845 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3848 if (!(es
->style
& ES_READONLY
))
3849 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3852 if (!(es
->style
& ES_READONLY
))
3853 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3857 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3858 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3861 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3865 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3872 /*********************************************************************
3877 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3879 if (code
|| control
)
3899 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3900 EDIT_EM_ScrollCaret(es
);
3903 ERR("unknown menu item, please report\n");
3909 /*********************************************************************
3913 * Note: the resource files resource/sysres_??.rc cannot define a
3914 * single popup menu. Hence we use a (dummy) menubar
3915 * containing the single popup menu as its first item.
3917 * FIXME: the message identifiers have been chosen arbitrarily,
3918 * hence we use MF_BYPOSITION.
3919 * We might as well use the "real" values (anybody knows ?)
3920 * The menu definition is in resources/sysres_??.rc.
3921 * Once these are OK, we better use MF_BYCOMMAND here
3922 * (as we do in EDIT_WM_Command()).
3925 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3927 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3928 HMENU popup
= GetSubMenu(menu
, 0);
3929 UINT start
= es
->selection_start
;
3930 UINT end
= es
->selection_end
;
3932 ORDER_UINT(start
, end
);
3935 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3937 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3939 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3941 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3943 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3945 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3947 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3952 /*********************************************************************
3957 static void EDIT_WM_Copy(EDITSTATE
*es
)
3959 INT s
= min(es
->selection_start
, es
->selection_end
);
3960 INT e
= max(es
->selection_start
, es
->selection_end
);
3968 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3969 dst
= GlobalLock(hdst
);
3970 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3971 dst
[len
] = 0; /* ensure 0 termination */
3972 TRACE("%s\n", debugstr_w(dst
));
3974 OpenClipboard(es
->hwndSelf
);
3976 SetClipboardData(CF_UNICODETEXT
, hdst
);
3981 /*********************************************************************
3986 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3988 TRACE("%s\n", debugstr_w(name
));
3990 * To initialize some final structure members, we call some helper
3991 * functions. However, since the EDITSTATE is not consistent (i.e.
3992 * not fully initialized), we should be very careful which
3993 * functions can be called, and in what order.
3995 EDIT_WM_SetFont(es
, 0, FALSE
);
3996 EDIT_EM_EmptyUndoBuffer(es
);
3998 if (name
&& *name
) {
3999 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
4000 /* if we insert text to the editline, the text scrolls out
4001 * of the window, as the caret is placed after the insert
4002 * pos normally; thus we reset es->selection... to 0 and
4005 es
->selection_start
= es
->selection_end
= 0;
4006 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4007 * Messages are only to be sent when the USER does something to
4008 * change the contents. So I am removing this EN_CHANGE
4010 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
4012 EDIT_EM_ScrollCaret(es
);
4014 /* force scroll info update */
4015 EDIT_UpdateScrollInfo(es
);
4016 /* The rule seems to return 1 here for success */
4017 /* Power Builder masked edit controls will crash */
4019 /* FIXME: is that in all cases so ? */
4024 /*********************************************************************
4029 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4034 while (LocalUnlock(es
->hloc32W
)) ;
4035 LocalFree(es
->hloc32W
);
4038 while (LocalUnlock(es
->hloc32A
)) ;
4039 LocalFree(es
->hloc32A
);
4042 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
4043 HANDLE16 oldDS
= stack16
->ds
;
4045 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4046 while (LocalUnlock16(es
->hloc16
)) ;
4047 LocalFree16(es
->hloc16
);
4048 stack16
->ds
= oldDS
;
4051 pc
= es
->first_line_def
;
4055 HeapFree(GetProcessHeap(), 0, pc
);
4059 SetWindowLongW( es
->hwndSelf
, 0, 0 );
4060 HeapFree(GetProcessHeap(), 0, es
);
4066 /*********************************************************************
4071 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4073 /* we do the proper erase in EDIT_WM_Paint */
4078 /*********************************************************************
4083 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4085 if(!count
) return 0;
4089 lstrcpynW(dst
, es
->text
, count
);
4090 return strlenW(dst
);
4094 LPSTR textA
= (LPSTR
)dst
;
4095 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4096 textA
[count
- 1] = 0; /* ensure 0 termination */
4097 return strlen(textA
);
4101 /*********************************************************************
4106 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4111 if (!(es
->style
& ES_MULTILINE
))
4114 if (!(es
->style
& ES_AUTOHSCROLL
))
4118 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4121 TRACE("SB_LINELEFT\n");
4123 dx
= -es
->char_width
;
4126 TRACE("SB_LINERIGHT\n");
4127 if (es
->x_offset
< es
->text_width
)
4128 dx
= es
->char_width
;
4131 TRACE("SB_PAGELEFT\n");
4133 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4136 TRACE("SB_PAGERIGHT\n");
4137 if (es
->x_offset
< es
->text_width
)
4138 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4146 TRACE("SB_RIGHT\n");
4147 if (es
->x_offset
< es
->text_width
)
4148 dx
= es
->text_width
- es
->x_offset
;
4151 TRACE("SB_THUMBTRACK %d\n", pos
);
4152 es
->flags
|= EF_HSCROLL_TRACK
;
4153 if(es
->style
& WS_HSCROLL
)
4154 dx
= pos
- es
->x_offset
;
4159 if(pos
< 0 || pos
> 100) return 0;
4160 /* Assume default scroll range 0-100 */
4161 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4162 new_x
= pos
* (es
->text_width
- fw
) / 100;
4163 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4166 case SB_THUMBPOSITION
:
4167 TRACE("SB_THUMBPOSITION %d\n", pos
);
4168 es
->flags
&= ~EF_HSCROLL_TRACK
;
4169 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4170 dx
= pos
- es
->x_offset
;
4175 if(pos
< 0 || pos
> 100) return 0;
4176 /* Assume default scroll range 0-100 */
4177 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4178 new_x
= pos
* (es
->text_width
- fw
) / 100;
4179 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4182 /* force scroll info update */
4183 EDIT_UpdateScrollInfo(es
);
4184 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
4188 TRACE("SB_ENDSCROLL\n");
4191 * FIXME : the next two are undocumented !
4192 * Are we doing the right thing ?
4193 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4194 * although it's also a regular control message.
4196 case EM_GETTHUMB
: /* this one is used by NT notepad */
4200 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4201 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4204 /* Assume default scroll range 0-100 */
4205 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4206 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4208 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4211 case EM_LINESCROLL16
:
4212 TRACE("EM_LINESCROLL16\n");
4217 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4223 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4224 /* check if we are going to move too far */
4225 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4226 dx
= es
->text_width
- fw
- es
->x_offset
;
4228 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4234 /*********************************************************************
4239 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4241 HWND hLBox
= es
->hwndListBox
;
4249 hCombo
= GetParent(es
->hwndSelf
);
4253 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4255 if (key
== VK_UP
|| key
== VK_DOWN
)
4257 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4260 if (msg
== WM_KEYDOWN
|| nEUI
)
4261 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4267 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4269 /* make sure ComboLBox pops up */
4270 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4275 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4278 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4280 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4282 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4287 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4293 /*********************************************************************
4297 * Handling of special keys that don't produce a WM_CHAR
4298 * (i.e. non-printable keys) & Backspace & Delete
4301 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4306 if (GetKeyState(VK_MENU
) & 0x8000)
4309 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4310 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4315 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4320 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4321 EDIT_MoveUp_ML(es
, shift
);
4324 EDIT_MoveWordBackward(es
, shift
);
4326 EDIT_MoveBackward(es
, shift
);
4329 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4333 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4334 EDIT_MoveDown_ML(es
, shift
);
4336 EDIT_MoveWordForward(es
, shift
);
4338 EDIT_MoveForward(es
, shift
);
4341 EDIT_MoveHome(es
, shift
);
4344 EDIT_MoveEnd(es
, shift
);
4347 if (es
->style
& ES_MULTILINE
)
4348 EDIT_MovePageUp_ML(es
, shift
);
4350 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4353 if (es
->style
& ES_MULTILINE
)
4354 EDIT_MovePageDown_ML(es
, shift
);
4356 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4359 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4360 if (es
->selection_start
!= es
->selection_end
) {
4367 /* delete character left of caret */
4368 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4369 EDIT_MoveBackward(es
, TRUE
);
4371 } else if (control
) {
4372 /* delete to end of line */
4373 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4374 EDIT_MoveEnd(es
, TRUE
);
4377 /* delete character right of caret */
4378 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4379 EDIT_MoveForward(es
, TRUE
);
4387 if (!(es
->style
& ES_READONLY
))
4393 /* If the edit doesn't want the return send a message to the default object */
4394 if(!(es
->style
& ES_WANTRETURN
))
4396 HWND hwndParent
= GetParent(es
->hwndSelf
);
4397 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4398 if (HIWORD(dw
) == DC_HASDEFID
)
4400 SendMessageW( hwndParent
, WM_COMMAND
,
4401 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4402 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4411 /*********************************************************************
4416 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4418 es
->flags
&= ~EF_FOCUSED
;
4420 if(!(es
->style
& ES_NOHIDESEL
))
4421 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4422 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4427 /*********************************************************************
4431 * The caret position has been set on the WM_LBUTTONDOWN message
4434 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4437 INT e
= es
->selection_end
;
4442 if (!(es
->flags
& EF_FOCUSED
))
4445 l
= EDIT_EM_LineFromChar(es
, e
);
4446 li
= EDIT_EM_LineIndex(es
, l
);
4447 ll
= EDIT_EM_LineLength(es
, e
);
4448 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4449 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4450 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4451 EDIT_EM_ScrollCaret(es
);
4456 /*********************************************************************
4461 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4466 SetFocus(es
->hwndSelf
);
4467 if (!(es
->flags
& EF_FOCUSED
))
4470 es
->bCaptureState
= TRUE
;
4471 SetCapture(es
->hwndSelf
);
4472 EDIT_ConfinePoint(es
, &x
, &y
);
4473 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4474 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4475 EDIT_EM_ScrollCaret(es
);
4476 es
->region_posx
= es
->region_posy
= 0;
4477 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4482 /*********************************************************************
4487 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4489 if (es
->bCaptureState
) {
4490 KillTimer(es
->hwndSelf
, 0);
4491 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4493 es
->bCaptureState
= FALSE
;
4498 /*********************************************************************
4503 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4505 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4510 /*********************************************************************
4515 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4521 if (GetCapture() != es
->hwndSelf
)
4525 * FIXME: gotta do some scrolling if outside client
4526 * area. Maybe reset the timer ?
4529 EDIT_ConfinePoint(es
, &x
, &y
);
4530 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4531 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4532 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4533 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4534 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4539 /*********************************************************************
4543 * See also EDIT_WM_StyleChanged
4545 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4550 TRACE("Creating %s edit control, style = %08lx\n",
4551 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4553 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4555 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4558 * Note: since the EDITSTATE has not been fully initialized yet,
4559 * we can't use any API calls that may send
4560 * WM_XXX messages before WM_NCCREATE is completed.
4563 es
->is_unicode
= unicode
;
4564 es
->style
= lpcs
->style
;
4566 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4568 es
->hwndSelf
= hwnd
;
4569 /* Save parent, which will be notified by EN_* messages */
4570 es
->hwndParent
= lpcs
->hwndParent
;
4572 if (es
->style
& ES_COMBO
)
4573 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4575 /* Number overrides lowercase overrides uppercase (at least it
4576 * does in Win95). However I'll bet that ES_NUMBER would be
4577 * invalid under Win 3.1.
4579 if (es
->style
& ES_NUMBER
) {
4580 ; /* do not override the ES_NUMBER */
4581 } else if (es
->style
& ES_LOWERCASE
) {
4582 es
->style
&= ~ES_UPPERCASE
;
4584 if (es
->style
& ES_MULTILINE
) {
4585 es
->buffer_limit
= BUFLIMIT_MULTI
;
4586 if (es
->style
& WS_VSCROLL
)
4587 es
->style
|= ES_AUTOVSCROLL
;
4588 if (es
->style
& WS_HSCROLL
)
4589 es
->style
|= ES_AUTOHSCROLL
;
4590 es
->style
&= ~ES_PASSWORD
;
4591 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4592 /* Confirmed - RIGHT overrides CENTER */
4593 if (es
->style
& ES_RIGHT
)
4594 es
->style
&= ~ES_CENTER
;
4595 es
->style
&= ~WS_HSCROLL
;
4596 es
->style
&= ~ES_AUTOHSCROLL
;
4599 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4600 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4601 es
->style
&= ~ES_CENTER
;
4602 es
->style
&= ~WS_HSCROLL
;
4603 es
->style
&= ~WS_VSCROLL
;
4604 if (es
->style
& ES_PASSWORD
)
4605 es
->password_char
= '*';
4608 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4609 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4611 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4613 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4615 es
->undo_buffer_size
= es
->buffer_size
;
4617 if (es
->style
& ES_MULTILINE
)
4618 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4623 * In Win95 look and feel, the WS_BORDER style is replaced by the
4624 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4625 * control a nonclient area so we don't need to draw the border.
4626 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4627 * a nonclient area and we should handle painting the border ourselves.
4629 * When making modifications please ensure that the code still works
4630 * for edit controls created directly with style 0x50800000, exStyle 0
4631 * (which should have a single pixel border)
4633 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4634 es
->style
&= ~WS_BORDER
;
4635 else if (es
->style
& WS_BORDER
)
4636 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4641 /*********************************************************************
4646 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4657 BOOL rev
= es
->bEnableState
&&
4658 ((es
->flags
& EF_FOCUSED
) ||
4659 (es
->style
& ES_NOHIDESEL
));
4660 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4662 GetClientRect(es
->hwndSelf
, &rcClient
);
4664 /* paint the background */
4665 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
4666 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
4667 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4668 GetClipBox(dc
, &rc
);
4669 FillRect(dc
, &rc
, brush
);
4671 /* draw the border */
4672 if(es
->style
& WS_BORDER
) {
4674 if(es
->style
& ES_MULTILINE
) {
4675 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4676 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4678 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4680 IntersectClipRect(dc
, es
->format_rect
.left
,
4681 es
->format_rect
.top
,
4682 es
->format_rect
.right
,
4683 es
->format_rect
.bottom
);
4684 if (es
->style
& ES_MULTILINE
) {
4686 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4689 old_font
= SelectObject(dc
, es
->font
);
4690 EDIT_NotifyCtlColor(es
, dc
);
4692 if (!es
->bEnableState
)
4693 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4694 GetClipBox(dc
, &rcRgn
);
4695 if (es
->style
& ES_MULTILINE
) {
4696 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4697 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4698 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4699 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4700 EDIT_PaintLine(es
, dc
, i
, rev
);
4703 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4704 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4705 EDIT_PaintLine(es
, dc
, 0, rev
);
4708 SelectObject(dc
, old_font
);
4711 EndPaint(es
->hwndSelf
, &ps
);
4715 /*********************************************************************
4720 static void EDIT_WM_Paste(EDITSTATE
*es
)
4725 /* Protect read-only edit control from modification */
4726 if(es
->style
& ES_READONLY
)
4729 OpenClipboard(es
->hwndSelf
);
4730 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4731 src
= (LPWSTR
)GlobalLock(hsrc
);
4732 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4739 /*********************************************************************
4744 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4746 es
->flags
|= EF_FOCUSED
;
4747 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4748 EDIT_SetCaretPos(es
, es
->selection_end
,
4749 es
->flags
& EF_AFTER_WRAP
);
4750 if(!(es
->style
& ES_NOHIDESEL
))
4751 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4752 ShowCaret(es
->hwndSelf
);
4753 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4757 /*********************************************************************
4761 * With Win95 look the margins are set to default font value unless
4762 * the system font (font == 0) is being set, in which case they are left
4766 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4774 dc
= GetDC(es
->hwndSelf
);
4776 old_font
= SelectObject(dc
, font
);
4777 GetTextMetricsW(dc
, &tm
);
4778 es
->line_height
= tm
.tmHeight
;
4779 es
->char_width
= tm
.tmAveCharWidth
;
4781 SelectObject(dc
, old_font
);
4782 ReleaseDC(es
->hwndSelf
, dc
);
4783 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4784 EC_USEFONTINFO
, EC_USEFONTINFO
);
4786 /* Force the recalculation of the format rect for each font change */
4787 GetClientRect(es
->hwndSelf
, &r
);
4788 EDIT_SetRectNP(es
, &r
);
4790 if (es
->style
& ES_MULTILINE
)
4791 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4793 EDIT_CalcLineWidth_SL(es
);
4796 EDIT_UpdateText(es
, NULL
, TRUE
);
4797 if (es
->flags
& EF_FOCUSED
) {
4799 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4800 EDIT_SetCaretPos(es
, es
->selection_end
,
4801 es
->flags
& EF_AFTER_WRAP
);
4802 ShowCaret(es
->hwndSelf
);
4807 /*********************************************************************
4812 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4813 * The modified flag is reset. No notifications are sent.
4815 * For single-line controls, reception of WM_SETTEXT triggers:
4816 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4819 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
4821 if (!unicode
&& text
)
4823 LPCSTR textA
= (LPCSTR
)text
;
4824 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4825 LPWSTR textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
4827 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4831 if (es
->flags
& EF_UPDATE
)
4832 /* fixed this bug once; complain if we see it about to happen again. */
4833 ERR("SetSel may generate UPDATE message whose handler may reset "
4836 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4839 TRACE("%s\n", debugstr_w(text
));
4840 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4842 HeapFree(GetProcessHeap(), 0, (LPWSTR
)text
);
4846 static const WCHAR empty_stringW
[] = {0};
4848 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4851 es
->flags
&= ~EF_MODIFIED
;
4852 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4854 /* Send the notification after the selection start and end have been set
4855 * edit control doesn't send notification on WM_SETTEXT
4856 * if it is multiline, or it is part of combobox
4858 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4860 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4861 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4863 EDIT_EM_ScrollCaret(es
);
4864 EDIT_UpdateScrollInfo(es
);
4868 /*********************************************************************
4873 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4875 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4877 TRACE("width = %d, height = %d\n", width
, height
);
4878 SetRect(&rc
, 0, 0, width
, height
);
4879 EDIT_SetRectNP(es
, &rc
);
4880 EDIT_UpdateText(es
, NULL
, TRUE
);
4885 /*********************************************************************
4889 * This message is sent by SetWindowLong on having changed either the Style
4890 * or the extended style.
4892 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4894 * See also EDIT_WM_NCCreate
4896 * It appears that the Windows version of the edit control allows the style
4897 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4898 * style variable which will generally be different. In this function we
4899 * update the internal style based on what changed in the externally visible
4902 * Much of this content as based upon the MSDN, especially:
4903 * Platform SDK Documentation -> User Interface Services ->
4904 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4905 * Edit Control Styles
4907 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4909 if (GWL_STYLE
== which
) {
4910 DWORD style_change_mask
;
4912 /* Only a subset of changes can be applied after the control
4915 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4917 if (es
->style
& ES_MULTILINE
)
4918 style_change_mask
|= ES_WANTRETURN
;
4920 new_style
= style
->styleNew
& style_change_mask
;
4922 /* Number overrides lowercase overrides uppercase (at least it
4923 * does in Win95). However I'll bet that ES_NUMBER would be
4924 * invalid under Win 3.1.
4926 if (new_style
& ES_NUMBER
) {
4927 ; /* do not override the ES_NUMBER */
4928 } else if (new_style
& ES_LOWERCASE
) {
4929 new_style
&= ~ES_UPPERCASE
;
4932 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4933 } else if (GWL_EXSTYLE
== which
) {
4934 ; /* FIXME - what is needed here */
4936 WARN ("Invalid style change %d\n",which
);
4942 /*********************************************************************
4947 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4949 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4950 if (EDIT_EM_CanUndo(es
))
4953 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4954 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4957 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4961 /*********************************************************************
4966 static void EDIT_WM_Timer(EDITSTATE
*es
)
4968 if (es
->region_posx
< 0) {
4969 EDIT_MoveBackward(es
, TRUE
);
4970 } else if (es
->region_posx
> 0) {
4971 EDIT_MoveForward(es
, TRUE
);
4974 * FIXME: gotta do some vertical scrolling here, like
4975 * EDIT_EM_LineScroll(hwnd, 0, 1);
4979 /*********************************************************************
4984 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4988 if (!(es
->style
& ES_MULTILINE
))
4991 if (!(es
->style
& ES_AUTOVSCROLL
))
5000 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5001 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5002 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5004 EDIT_EM_Scroll(es
, action
);
5011 TRACE("SB_BOTTOM\n");
5012 dy
= es
->line_count
- 1 - es
->y_offset
;
5015 TRACE("SB_THUMBTRACK %d\n", pos
);
5016 es
->flags
|= EF_VSCROLL_TRACK
;
5017 if(es
->style
& WS_VSCROLL
)
5018 dy
= pos
- es
->y_offset
;
5021 /* Assume default scroll range 0-100 */
5024 if(pos
< 0 || pos
> 100) return 0;
5025 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5026 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5027 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5028 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5029 es
->line_count
, es
->y_offset
, pos
, dy
);
5032 case SB_THUMBPOSITION
:
5033 TRACE("SB_THUMBPOSITION %d\n", pos
);
5034 es
->flags
&= ~EF_VSCROLL_TRACK
;
5035 if(es
->style
& WS_VSCROLL
)
5036 dy
= pos
- es
->y_offset
;
5039 /* Assume default scroll range 0-100 */
5042 if(pos
< 0 || pos
> 100) return 0;
5043 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5044 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5045 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5046 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5047 es
->line_count
, es
->y_offset
, pos
, dy
);
5051 /* force scroll info update */
5052 EDIT_UpdateScrollInfo(es
);
5053 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
5057 TRACE("SB_ENDSCROLL\n");
5060 * FIXME : the next two are undocumented !
5061 * Are we doing the right thing ?
5062 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5063 * although it's also a regular control message.
5065 case EM_GETTHUMB
: /* this one is used by NT notepad */
5069 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5070 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5073 /* Assume default scroll range 0-100 */
5074 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5075 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5077 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5080 case EM_LINESCROLL16
:
5081 TRACE("EM_LINESCROLL16 %d\n", pos
);
5086 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5091 EDIT_EM_LineScroll(es
, 0, dy
);
5095 /*********************************************************************
5100 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5102 if (es
->flags
& EF_UPDATE
) {
5103 es
->flags
&= ~EF_UPDATE
;
5104 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
5106 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5110 /*********************************************************************
5115 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5117 if (es
->flags
& EF_UPDATE
) {
5118 es
->flags
&= ~EF_UPDATE
;
5119 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
5121 InvalidateRect(es
->hwndSelf
, rc
, bErase
);