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"
62 #include "user_private.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
66 WINE_DECLARE_DEBUG_CHANNEL(combo
);
67 WINE_DECLARE_DEBUG_CHANNEL(relay
);
69 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
70 FIXME: BTW, new specs say 65535 (do you dare ???) */
71 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
72 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
73 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
74 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
77 * extra flags for EDITSTATE.flags field
79 #define EF_MODIFIED 0x0001 /* text has been modified */
80 #define EF_FOCUSED 0x0002 /* we have input focus */
81 #define EF_UPDATE 0x0004 /* notify parent of changed state */
82 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
83 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
84 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
85 wrapped line, instead of in front of the next character */
86 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
90 END_0
= 0, /* line ends with terminating '\0' character */
91 END_WRAP
, /* line is wrapped */
92 END_HARD
, /* line ends with a hard return '\r\n' */
93 END_SOFT
, /* line ends with a soft return '\r\r\n' */
94 END_RICH
/* line ends with a single '\n' */
97 typedef struct tagLINEDEF
{
98 INT length
; /* bruto length of a line in bytes */
99 INT net_length
; /* netto length of a line in visible characters */
101 INT width
; /* width of the line in pixels */
102 INT index
; /* line index into the buffer */
103 struct tagLINEDEF
*next
;
108 BOOL is_unicode
; /* how the control was created */
109 LPWSTR text
; /* the actual contents of the control */
110 UINT buffer_size
; /* the size of the buffer in characters */
111 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
112 HFONT font
; /* NULL means standard system font */
113 INT x_offset
; /* scroll offset for multi lines this is in pixels
114 for single lines it's in characters */
115 INT line_height
; /* height of a screen line in pixels */
116 INT char_width
; /* average character width in pixels */
117 DWORD style
; /* sane version of wnd->dwStyle */
118 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
119 INT undo_insert_count
; /* number of characters inserted in sequence */
120 UINT undo_position
; /* character index of the insertion and deletion */
121 LPWSTR undo_text
; /* deleted text */
122 UINT undo_buffer_size
; /* size of the deleted text buffer */
123 INT selection_start
; /* == selection_end if no selection */
124 INT selection_end
; /* == current caret position */
125 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
126 INT left_margin
; /* in pixels */
127 INT right_margin
; /* in pixels */
129 INT text_width
; /* width of the widest line in pixels for multi line controls
130 and just line width for single line controls */
131 INT region_posx
; /* Position of cursor relative to region: */
132 INT region_posy
; /* -1: to left, 0: within, 1: to right */
133 EDITWORDBREAKPROC16 word_break_proc16
;
134 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
135 INT line_count
; /* number of lines */
136 INT y_offset
; /* scroll offset in number of lines */
137 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
138 BOOL bEnableState
; /* flag keeping the enable state */
139 HWND hwndSelf
; /* the our window handle */
140 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
141 Even if parent will change, EN_* messages
142 should be sent to the first parent. */
143 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
145 * only for multi line controls
147 INT lock_count
; /* amount of re-entries in the EditWndProc */
150 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
151 HLOCAL hloc32W
; /* our unicode local memory block */
152 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
154 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
159 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
160 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
162 /* used for disabled or read-only edit control */
163 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
165 { /* Notify parent which has created this edit control */ \
166 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
167 SendMessageW(es->hwndParent, WM_COMMAND, \
168 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
169 (LPARAM)(es->hwndSelf)); \
172 /*********************************************************************
179 * These functions have trivial implementations
180 * We still like to call them internally
181 * "static inline" makes them more like macro's
183 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
184 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
185 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
186 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
189 * Helper functions only valid for one type of control
191 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
192 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
193 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
194 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
195 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
196 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
197 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
199 * Helper functions valid for both single line _and_ multi line controls
201 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
202 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
203 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
204 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
205 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
206 static void EDIT_LockBuffer(EDITSTATE
*es
);
207 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
208 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
209 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
210 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
211 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
212 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
213 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
214 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
215 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
216 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
217 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
218 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
219 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
220 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
221 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
223 * EM_XXX message handlers
225 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
226 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
227 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
228 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
229 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
230 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
231 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
232 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
233 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
234 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
235 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
236 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
237 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
238 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
239 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
240 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
241 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
242 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
243 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
244 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
245 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
246 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
247 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
248 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
249 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
250 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
251 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
253 * WM_XXX message handlers
255 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
256 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
257 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
258 static void EDIT_WM_Copy(EDITSTATE
*es
);
259 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
260 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
261 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
262 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
263 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
264 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
265 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
266 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
267 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
268 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
269 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
270 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
271 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
272 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
273 static void EDIT_WM_Paste(EDITSTATE
*es
);
274 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
275 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
276 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
277 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
278 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
279 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
280 static void EDIT_WM_Timer(EDITSTATE
*es
);
281 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
282 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
283 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
285 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
286 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
288 /*********************************************************************
289 * edit class descriptor
291 const struct builtin_class_descr EDIT_builtin_class
=
294 CS_DBLCLKS
| CS_PARENTDC
, /* style */
295 EditWndProcA
, /* procA */
296 EditWndProcW
, /* procW */
297 sizeof(EDITSTATE
*), /* extra */
298 IDC_IBEAM
, /* cursor */
303 /*********************************************************************
308 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
310 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
314 /*********************************************************************
319 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
321 es
->undo_insert_count
= 0;
322 *es
->undo_text
= '\0';
326 /*********************************************************************
331 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
333 static const WCHAR empty_stringW
[] = {0};
335 /* Protect read-only edit control from modification */
336 if(es
->style
& ES_READONLY
)
339 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
343 /*********************************************************************
348 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
355 /**********************************************************************
358 * Returns the window version in case Wine emulates a later version
359 * of windows than the application expects.
361 * In a number of cases when windows runs an application that was
362 * designed for an earlier windows version, windows reverts
363 * to "old" behaviour of that earlier version.
365 * An example is a disabled edit control that needs to be painted.
366 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
367 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
368 * applications with an expected version 0f 4.0 or higher.
371 static DWORD
get_app_version(void)
373 static DWORD version
;
376 DWORD dwEmulatedVersion
;
378 DWORD dwProcVersion
= GetProcessVersion(0);
380 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
381 GetVersionExW( &info
);
382 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
383 /* FIXME: this may not be 100% correct; see discussion on the
384 * wine developer list in Nov 1999 */
385 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
391 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
395 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
396 msg
= WM_CTLCOLORSTATIC
;
398 msg
= WM_CTLCOLOREDIT
;
400 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
401 return (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
404 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
407 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
409 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
412 /*********************************************************************
416 * The messages are in the order of the actual integer values
417 * (which can be found in include/windows.h)
418 * Wherever possible the 16 bit versions are converted to
419 * the 32 bit ones, so that we can 'fall through' to the
420 * helper functions. These are mostly 32 bit (with a few
421 * exceptions, clearly indicated by a '16' extension to their
425 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
426 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
428 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongW( hwnd
, 0 );
431 TRACE("hwnd=%p msg=%x (%s) wparam=%x lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
433 if (!es
&& msg
!= WM_NCCREATE
)
434 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
435 else if (msg
== WM_NCCREATE
)
436 return EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
437 else if (msg
== WM_DESTROY
)
438 return EDIT_WM_Destroy(es
);
441 if (es
) EDIT_LockBuffer(es
);
449 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
453 if ((short)LOWORD(lParam
) == -1)
454 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
456 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
458 EDIT_EM_ScrollCaret(es
);
462 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
463 EDIT_EM_ScrollCaret(es
);
470 RECT16
*r16
= MapSL(lParam
);
471 r16
->left
= es
->format_rect
.left
;
472 r16
->top
= es
->format_rect
.top
;
473 r16
->right
= es
->format_rect
.right
;
474 r16
->bottom
= es
->format_rect
.bottom
;
479 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
483 if ((es
->style
& ES_MULTILINE
) && lParam
) {
485 RECT16
*r16
= MapSL(lParam
);
488 rc
.right
= r16
->right
;
489 rc
.bottom
= r16
->bottom
;
490 EDIT_SetRectNP(es
, &rc
);
491 EDIT_UpdateText(es
, NULL
, TRUE
);
495 if ((es
->style
& ES_MULTILINE
) && lParam
) {
496 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
497 EDIT_UpdateText(es
, NULL
, TRUE
);
502 if ((es
->style
& ES_MULTILINE
) && lParam
) {
504 RECT16
*r16
= MapSL(lParam
);
507 rc
.right
= r16
->right
;
508 rc
.bottom
= r16
->bottom
;
509 EDIT_SetRectNP(es
, &rc
);
513 if ((es
->style
& ES_MULTILINE
) && lParam
)
514 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
519 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
522 case EM_LINESCROLL16
:
523 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
524 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
527 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
530 case EM_SCROLLCARET16
:
532 EDIT_EM_ScrollCaret(es
);
538 result
= ((es
->flags
& EF_MODIFIED
) != 0);
544 es
->flags
|= EF_MODIFIED
;
546 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
549 case EM_GETLINECOUNT16
:
550 case EM_GETLINECOUNT
:
551 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
555 if ((INT16
)wParam
== -1)
559 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
563 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
566 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
570 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
573 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
578 result
= EDIT_EM_GetThumb(es
);
581 /* these messages missing from specs */
590 FIXME("undocumented message 0x%x, please report\n", msg
);
591 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
594 case EM_LINELENGTH16
:
596 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
599 case EM_REPLACESEL16
:
600 lParam
= (LPARAM
)MapSL(lParam
);
601 unicode
= FALSE
; /* 16-bit message is always ascii */
608 textW
= (LPWSTR
)lParam
;
611 LPSTR textA
= (LPSTR
)lParam
;
612 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
613 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
614 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
617 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
621 HeapFree(GetProcessHeap(), 0, textW
);
626 lParam
= (LPARAM
)MapSL(lParam
);
627 unicode
= FALSE
; /* 16-bit message is always ascii */
630 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
634 case EM_SETLIMITTEXT
:
635 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
640 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
646 result
= (LRESULT
)EDIT_EM_Undo(es
);
651 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
654 case EM_LINEFROMCHAR16
:
655 case EM_LINEFROMCHAR
:
656 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
659 case EM_SETTABSTOPS16
:
660 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
663 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
666 case EM_SETPASSWORDCHAR16
:
667 unicode
= FALSE
; /* 16-bit message is always ascii */
669 case EM_SETPASSWORDCHAR
:
674 charW
= (WCHAR
)wParam
;
678 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
681 EDIT_EM_SetPasswordChar(es
, charW
);
685 case EM_EMPTYUNDOBUFFER16
:
686 case EM_EMPTYUNDOBUFFER
:
687 EDIT_EM_EmptyUndoBuffer(es
);
690 case EM_GETFIRSTVISIBLELINE16
:
691 result
= es
->y_offset
;
693 case EM_GETFIRSTVISIBLELINE
:
694 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
697 case EM_SETREADONLY16
:
700 SetWindowLongW( hwnd
, GWL_STYLE
,
701 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
702 es
->style
|= ES_READONLY
;
704 SetWindowLongW( hwnd
, GWL_STYLE
,
705 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
706 es
->style
&= ~ES_READONLY
;
711 case EM_SETWORDBREAKPROC16
:
712 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
714 case EM_SETWORDBREAKPROC
:
715 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
718 case EM_GETWORDBREAKPROC16
:
719 result
= (LRESULT
)es
->word_break_proc16
;
721 case EM_GETWORDBREAKPROC
:
722 result
= (LRESULT
)es
->word_break_proc
;
725 case EM_GETPASSWORDCHAR16
:
726 unicode
= FALSE
; /* 16-bit message is always ascii */
728 case EM_GETPASSWORDCHAR
:
731 result
= es
->password_char
;
734 WCHAR charW
= es
->password_char
;
736 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
742 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
745 EDIT_EM_SetMargins(es
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
749 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
752 case EM_GETLIMITTEXT
:
753 result
= es
->buffer_limit
;
757 result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
761 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
764 /* End of the EM_ messages which were in numerical order; what order
765 * are these in? vaguely alphabetical?
769 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
771 if (es
->style
& ES_MULTILINE
)
773 result
|= DLGC_WANTALLKEYS
;
777 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
779 int vk
= (int)((LPMSG
)lParam
)->wParam
;
781 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
783 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
784 result
|= DLGC_WANTMESSAGE
;
795 strng
[0] = wParam
>> 8;
796 strng
[1] = wParam
& 0xff;
797 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
798 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
799 EDIT_WM_Char(es
, charW
);
812 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
815 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
817 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
818 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
821 EDIT_WM_Char(es
, charW
);
830 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
834 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
843 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
846 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
850 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
851 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
852 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
854 result
= EDIT_WM_Create(es
, nameW
);
855 HeapFree(GetProcessHeap(), 0, nameW
);
864 es
->bEnableState
= (BOOL
) wParam
;
865 EDIT_UpdateText(es
, NULL
, TRUE
);
869 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
873 result
= (LRESULT
)es
->font
;
877 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
880 case WM_GETTEXTLENGTH
:
881 if (unicode
) result
= strlenW(es
->text
);
882 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
883 NULL
, 0, NULL
, NULL
);
887 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
891 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
895 result
= EDIT_WM_KillFocus(es
);
898 case WM_LBUTTONDBLCLK
:
899 result
= EDIT_WM_LButtonDblClk(es
);
903 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
907 result
= EDIT_WM_LButtonUp(es
);
911 result
= EDIT_WM_MButtonDown(es
);
914 case WM_MOUSEACTIVATE
:
915 result
= MA_ACTIVATE
;
919 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
923 EDIT_WM_Paint(es
, (HDC
)wParam
);
931 EDIT_WM_SetFocus(es
);
935 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
939 /* FIXME: actually set an internal flag and behave accordingly */
943 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
948 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
951 case WM_STYLECHANGED
:
952 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
955 case WM_STYLECHANGING
:
956 result
= 0; /* See EDIT_WM_StyleChanged */
960 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
968 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
973 int gcWheelDelta
= 0;
974 UINT pulScrollLines
= 3;
975 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
977 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
978 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
981 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
982 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
984 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
985 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
986 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
991 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
995 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
997 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1002 /*********************************************************************
1004 * EditWndProcW (USER32.@)
1006 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1008 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1011 /*********************************************************************
1013 * EditWndProc (USER32.@)
1015 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1017 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1020 /*********************************************************************
1022 * EDIT_BuildLineDefs_ML
1024 * Build linked list of text lines.
1025 * Lines can end with '\0' (last line), a character (if it is wrapped),
1026 * a soft return '\r\r\n' or a hard return '\r\n'
1029 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1033 LPWSTR current_position
, cp
;
1035 LINEDEF
*current_line
;
1036 LINEDEF
*previous_line
;
1037 LINEDEF
*start_line
;
1038 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1039 INT line_count
= es
->line_count
;
1040 INT orig_net_length
;
1043 if (istart
== iend
&& delta
== 0)
1046 dc
= GetDC(es
->hwndSelf
);
1048 old_font
= SelectObject(dc
, es
->font
);
1050 previous_line
= NULL
;
1051 current_line
= es
->first_line_def
;
1053 /* Find starting line. istart must lie inside an existing line or
1054 * at the end of buffer */
1056 if (istart
< current_line
->index
+ current_line
->length
||
1057 current_line
->ending
== END_0
)
1060 previous_line
= current_line
;
1061 current_line
= current_line
->next
;
1063 } while (current_line
);
1065 if (!current_line
) /* Error occurred start is not inside previous buffer */
1067 FIXME(" modification occurred outside buffer\n");
1068 ReleaseDC(es
->hwndSelf
, dc
);
1072 /* Remember start of modifications in order to calculate update region */
1073 nstart_line
= line_index
;
1074 nstart_index
= current_line
->index
;
1076 /* We must start to reformat from the previous line since the modifications
1077 * may have caused the line to wrap upwards. */
1078 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1081 current_line
= previous_line
;
1083 start_line
= current_line
;
1085 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1086 current_position
= es
->text
+ current_line
->index
;
1088 if (current_line
!= start_line
)
1090 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1092 /* The buffer has been expanded, create a new line and
1093 insert it into the link list */
1094 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1095 new_line
->next
= previous_line
->next
;
1096 previous_line
->next
= new_line
;
1097 current_line
= new_line
;
1100 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1102 /* The previous line merged with this line so we delete this extra entry */
1103 previous_line
->next
= current_line
->next
;
1104 HeapFree(GetProcessHeap(), 0, current_line
);
1105 current_line
= previous_line
->next
;
1109 else /* current_line->index + delta == current_position */
1111 if (current_position
- es
->text
> iend
)
1112 break; /* We reached end of line modifications */
1113 /* else recalulate this line */
1117 current_line
->index
= current_position
- es
->text
;
1118 orig_net_length
= current_line
->net_length
;
1120 /* Find end of line */
1121 cp
= current_position
;
1123 if (*cp
== '\n') break;
1124 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1129 /* Mark type of line termination */
1131 current_line
->ending
= END_0
;
1132 current_line
->net_length
= strlenW(current_position
);
1133 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1134 current_line
->ending
= END_SOFT
;
1135 current_line
->net_length
= cp
- current_position
- 1;
1136 } else if (*cp
== '\n') {
1137 current_line
->ending
= END_RICH
;
1138 current_line
->net_length
= cp
- current_position
;
1140 current_line
->ending
= END_HARD
;
1141 current_line
->net_length
= cp
- current_position
;
1144 /* Calculate line width */
1145 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1146 current_position
, current_line
->net_length
,
1147 es
->tabs_count
, es
->tabs
));
1149 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1150 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1151 if (current_line
->width
> fw
) {
1156 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1157 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1158 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1159 current_position
, next
, es
->tabs_count
, es
->tabs
));
1160 } while (current_line
->width
<= fw
);
1161 if (!prev
) { /* Didn't find a line break so force a break */
1166 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1167 current_position
, next
, es
->tabs_count
, es
->tabs
));
1168 } while (current_line
->width
<= fw
);
1173 /* If the first line we are calculating, wrapped before istart, we must
1174 * adjust istart in order for this to be reflected in the update region. */
1175 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1176 istart
= current_line
->index
+ prev
;
1177 /* else if we are updating the previous line before the first line we
1178 * are re-calculating and it expanded */
1179 else if (current_line
== start_line
&&
1180 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1182 /* Line expanded due to an upwards line wrap so we must partially include
1183 * previous line in update region */
1184 nstart_line
= line_index
;
1185 nstart_index
= current_line
->index
;
1186 istart
= current_line
->index
+ orig_net_length
;
1189 current_line
->net_length
= prev
;
1190 current_line
->ending
= END_WRAP
;
1191 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1192 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1194 else if (orig_net_length
< current_line
->net_length
&&
1195 current_line
== start_line
&&
1196 current_line
->index
!= nstart_index
) {
1197 /* The previous line expanded but it's still not as wide as the client rect */
1198 /* The expansion is due to an upwards line wrap so we must partially include
1199 it in the update region */
1200 nstart_line
= line_index
;
1201 nstart_index
= current_line
->index
;
1202 istart
= current_line
->index
+ orig_net_length
;
1207 /* Adjust length to include line termination */
1208 switch (current_line
->ending
) {
1210 current_line
->length
= current_line
->net_length
+ 3;
1213 current_line
->length
= current_line
->net_length
+ 1;
1216 current_line
->length
= current_line
->net_length
+ 2;
1220 current_line
->length
= current_line
->net_length
;
1223 es
->text_width
= max(es
->text_width
, current_line
->width
);
1224 current_position
+= current_line
->length
;
1225 previous_line
= current_line
;
1226 current_line
= current_line
->next
;
1228 } while (previous_line
->ending
!= END_0
);
1230 /* Finish adjusting line indexes by delta or remove hanging lines */
1231 if (previous_line
->ending
== END_0
)
1233 LINEDEF
*pnext
= NULL
;
1235 previous_line
->next
= NULL
;
1236 while (current_line
)
1238 pnext
= current_line
->next
;
1239 HeapFree(GetProcessHeap(), 0, current_line
);
1240 current_line
= pnext
;
1244 else if (delta
!= 0)
1246 while (current_line
)
1248 current_line
->index
+= delta
;
1249 current_line
= current_line
->next
;
1253 /* Calculate rest of modification rectangle */
1258 * We calculate two rectangles. One for the first line which may have
1259 * an indent with respect to the format rect. The other is a format-width
1260 * rectangle that spans the rest of the lines that changed or moved.
1262 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1263 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1264 rc
.bottom
= rc
.top
+ es
->line_height
;
1265 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1266 rc
.left
= es
->format_rect
.left
;
1268 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1269 es
->text
+ nstart_index
, istart
- nstart_index
,
1270 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1271 rc
.right
= es
->format_rect
.right
;
1272 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1275 rc
.left
= es
->format_rect
.left
;
1276 rc
.right
= es
->format_rect
.right
;
1278 * If lines were added or removed we must re-paint the remainder of the
1279 * lines since the remaining lines were either shifted up or down.
1281 if (line_count
< es
->line_count
) /* We added lines */
1282 rc
.bottom
= es
->line_count
* es
->line_height
;
1283 else if (line_count
> es
->line_count
) /* We removed lines */
1284 rc
.bottom
= line_count
* es
->line_height
;
1286 rc
.bottom
= line_index
* es
->line_height
;
1287 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1288 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1289 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1290 DeleteObject(tmphrgn
);
1294 SelectObject(dc
, old_font
);
1296 ReleaseDC(es
->hwndSelf
, dc
);
1299 /*********************************************************************
1301 * EDIT_CalcLineWidth_SL
1304 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1311 text
= EDIT_GetPasswordPointer_SL(es
);
1313 dc
= GetDC(es
->hwndSelf
);
1315 old_font
= SelectObject(dc
, es
->font
);
1317 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1320 SelectObject(dc
, old_font
);
1321 ReleaseDC(es
->hwndSelf
, dc
);
1323 if (es
->style
& ES_PASSWORD
)
1324 HeapFree(GetProcessHeap(), 0, text
);
1326 es
->text_width
= size
.cx
;
1329 /*********************************************************************
1331 * EDIT_CallWordBreakProc
1333 * Call appropriate WordBreakProc (internal or external).
1335 * Note: The "start" argument should always be an index referring
1336 * to es->text. The actual wordbreak proc might be
1337 * 16 bit, so we can't always pass any 32 bit LPSTR.
1338 * Hence we assume that es->text is the buffer that holds
1339 * the string under examination (we can decide this for ourselves).
1342 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1346 if (es
->word_break_proc16
) {
1353 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1354 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1355 segptr
= K32WOWGlobalLock16(hglob16
);
1356 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1357 args
[4] = SELECTOROF(segptr
);
1358 args
[3] = OFFSETOF(segptr
);
1362 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1363 ret
= LOWORD(result
);
1364 GlobalUnlock16(hglob16
);
1365 GlobalFree16(hglob16
);
1367 else if (es
->word_break_proc
)
1371 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1373 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1374 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1375 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1379 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1383 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1384 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1385 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1386 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1387 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1388 ret
= wbpA(textA
, index
, countA
, action
);
1389 HeapFree(GetProcessHeap(), 0, textA
);
1393 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1399 /*********************************************************************
1403 * Beware: This is not the function called on EM_CHARFROMPOS
1404 * The position _can_ be outside the formatting / client
1406 * The return value is only the character index
1409 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1415 if (es
->style
& ES_MULTILINE
) {
1416 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1418 LINEDEF
*line_def
= es
->first_line_def
;
1420 while ((line
> 0) && line_def
->next
) {
1421 line_index
+= line_def
->length
;
1422 line_def
= line_def
->next
;
1425 x
+= es
->x_offset
- es
->format_rect
.left
;
1426 if (es
->style
& ES_RIGHT
)
1427 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1428 else if (es
->style
& ES_CENTER
)
1429 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1430 if (x
>= line_def
->width
) {
1432 *after_wrap
= (line_def
->ending
== END_WRAP
);
1433 return line_index
+ line_def
->net_length
;
1437 *after_wrap
= FALSE
;
1440 dc
= GetDC(es
->hwndSelf
);
1442 old_font
= SelectObject(dc
, es
->font
);
1443 low
= line_index
+ 1;
1444 high
= line_index
+ line_def
->net_length
+ 1;
1445 while (low
< high
- 1)
1447 INT mid
= (low
+ high
) / 2;
1448 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1454 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1455 (line_def
->ending
== END_WRAP
));
1460 *after_wrap
= FALSE
;
1461 x
-= es
->format_rect
.left
;
1463 return es
->x_offset
;
1467 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1468 if (es
->style
& ES_RIGHT
)
1470 else if (es
->style
& ES_CENTER
)
1474 text
= EDIT_GetPasswordPointer_SL(es
);
1475 dc
= GetDC(es
->hwndSelf
);
1477 old_font
= SelectObject(dc
, es
->font
);
1481 INT high
= es
->x_offset
;
1482 while (low
< high
- 1)
1484 INT mid
= (low
+ high
) / 2;
1485 GetTextExtentPoint32W( dc
, text
+ mid
,
1486 es
->x_offset
- mid
, &size
);
1487 if (size
.cx
> -x
) low
= mid
;
1494 INT low
= es
->x_offset
;
1495 INT high
= strlenW(es
->text
) + 1;
1496 while (low
< high
- 1)
1498 INT mid
= (low
+ high
) / 2;
1499 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1500 mid
- es
->x_offset
, &size
);
1501 if (size
.cx
> x
) high
= mid
;
1506 if (es
->style
& ES_PASSWORD
)
1507 HeapFree(GetProcessHeap(), 0, text
);
1510 SelectObject(dc
, old_font
);
1511 ReleaseDC(es
->hwndSelf
, dc
);
1516 /*********************************************************************
1520 * adjusts the point to be within the formatting rectangle
1521 * (so CharFromPos returns the nearest _visible_ character)
1524 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1526 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1527 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1531 /*********************************************************************
1535 * Calculates the bounding rectangle for a line from a starting
1536 * column to an ending column.
1539 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1541 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1543 if (es
->style
& ES_MULTILINE
)
1544 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1546 rc
->top
= es
->format_rect
.top
;
1547 rc
->bottom
= rc
->top
+ es
->line_height
;
1548 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1549 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1553 /*********************************************************************
1555 * EDIT_GetPasswordPointer_SL
1557 * note: caller should free the (optionally) allocated buffer
1560 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1562 if (es
->style
& ES_PASSWORD
) {
1563 INT len
= strlenW(es
->text
);
1564 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1566 while(len
) text
[--len
] = es
->password_char
;
1573 /*********************************************************************
1577 * This acts as a LOCAL_Lock(), but it locks only once. This way
1578 * you can call it whenever you like, without unlocking.
1580 * Initially the edit control allocates a HLOCAL32 buffer
1581 * (32 bit linear memory handler). However, 16 bit application
1582 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1583 * handler). From that moment on we have to keep using this 16 bit memory
1584 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1585 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1589 static void EDIT_LockBuffer(EDITSTATE
*es
)
1591 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1595 BOOL _16bit
= FALSE
;
1601 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1602 textA
= LocalLock(es
->hloc32A
);
1603 countA
= strlen(textA
) + 1;
1607 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1608 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1609 countA
= strlen(textA
) + 1;
1614 ERR("no buffer ... please report\n");
1621 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1622 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1623 if(countW_new
> es
->buffer_size
+ 1)
1625 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1626 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1627 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1630 es
->hloc32W
= hloc32W_new
;
1631 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1632 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1635 WARN("FAILED! Will synchronize partially\n");
1639 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1640 es
->text
= LocalLock(es
->hloc32W
);
1644 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1646 LOCAL_Unlock(hInstance
, es
->hloc16
);
1648 LocalUnlock(es
->hloc32A
);
1655 /*********************************************************************
1657 * EDIT_SL_InvalidateText
1659 * Called from EDIT_InvalidateText().
1660 * Does the job for single-line controls only.
1663 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1668 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1669 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1670 EDIT_UpdateText(es
, &rc
, TRUE
);
1674 /*********************************************************************
1676 * EDIT_ML_InvalidateText
1678 * Called from EDIT_InvalidateText().
1679 * Does the job for multi-line controls only.
1682 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1684 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1685 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1686 INT el
= EDIT_EM_LineFromChar(es
, end
);
1695 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1698 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1699 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1700 if (sl
< es
->y_offset
) {
1704 if (el
> es
->y_offset
+ vlc
) {
1705 el
= es
->y_offset
+ vlc
;
1706 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1708 GetClientRect(es
->hwndSelf
, &rc1
);
1709 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1711 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1712 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1713 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1715 EDIT_GetLineRect(es
, sl
, sc
,
1716 EDIT_EM_LineLength(es
,
1717 EDIT_EM_LineIndex(es
, sl
)),
1719 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1720 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1721 for (l
= sl
+ 1 ; l
< el
; l
++) {
1722 EDIT_GetLineRect(es
, l
, 0,
1723 EDIT_EM_LineLength(es
,
1724 EDIT_EM_LineIndex(es
, l
)),
1726 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1727 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1729 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1730 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1731 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1736 /*********************************************************************
1738 * EDIT_InvalidateText
1740 * Invalidate the text from offset start upto, but not including,
1741 * offset end. Useful for (re)painting the selection.
1742 * Regions outside the linewidth are not invalidated.
1743 * end == -1 means end == TextLength.
1744 * start and end need not be ordered.
1747 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1753 end
= strlenW(es
->text
);
1761 if (es
->style
& ES_MULTILINE
)
1762 EDIT_ML_InvalidateText(es
, start
, end
);
1764 EDIT_SL_InvalidateText(es
, start
, end
);
1768 /*********************************************************************
1772 * Try to fit size + 1 characters in the buffer.
1774 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1778 if (size
<= es
->buffer_size
)
1781 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1783 /* Force edit to unlock it's buffer. es->text now NULL */
1784 EDIT_UnlockBuffer(es
, TRUE
);
1787 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1788 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1789 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1790 es
->hloc32W
= hNew32W
;
1791 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1795 EDIT_LockBuffer(es
);
1797 if (es
->buffer_size
< size
) {
1798 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1799 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1802 TRACE("We now have %d+1\n", es
->buffer_size
);
1808 /*********************************************************************
1812 * Try to fit size + 1 bytes in the undo buffer.
1815 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1819 if (size
<= es
->undo_buffer_size
)
1822 TRACE("trying to ReAlloc to %d+1\n", size
);
1824 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1825 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1826 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1831 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1837 /*********************************************************************
1842 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1844 INT e
= es
->selection_end
;
1848 if ((es
->style
& ES_MULTILINE
) && e
&&
1849 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1851 if (e
&& (es
->text
[e
- 1] == '\r'))
1855 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1856 EDIT_EM_ScrollCaret(es
);
1860 /*********************************************************************
1864 * Only for multi line controls
1865 * Move the caret one line down, on a column with the nearest
1866 * x coordinate on the screen (might be a different column).
1869 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1871 INT s
= es
->selection_start
;
1872 INT e
= es
->selection_end
;
1873 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1874 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1875 INT x
= (short)LOWORD(pos
);
1876 INT y
= (short)HIWORD(pos
);
1878 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1881 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1882 EDIT_EM_ScrollCaret(es
);
1886 /*********************************************************************
1891 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1893 BOOL after_wrap
= FALSE
;
1896 /* Pass a high value in x to make sure of receiving the end of the line */
1897 if (es
->style
& ES_MULTILINE
)
1898 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1899 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1901 e
= strlenW(es
->text
);
1902 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1903 EDIT_EM_ScrollCaret(es
);
1907 /*********************************************************************
1912 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1914 INT e
= es
->selection_end
;
1918 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1919 if (es
->text
[e
] == '\n')
1921 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1925 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1926 EDIT_EM_ScrollCaret(es
);
1930 /*********************************************************************
1934 * Home key: move to beginning of line.
1937 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1941 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1942 if (es
->style
& ES_MULTILINE
)
1943 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1944 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1947 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1948 EDIT_EM_ScrollCaret(es
);
1952 /*********************************************************************
1954 * EDIT_MovePageDown_ML
1956 * Only for multi line controls
1957 * Move the caret one page down, on a column with the nearest
1958 * x coordinate on the screen (might be a different column).
1961 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1963 INT s
= es
->selection_start
;
1964 INT e
= es
->selection_end
;
1965 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1966 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1967 INT x
= (short)LOWORD(pos
);
1968 INT y
= (short)HIWORD(pos
);
1970 e
= EDIT_CharFromPos(es
, x
,
1971 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1975 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1976 EDIT_EM_ScrollCaret(es
);
1980 /*********************************************************************
1982 * EDIT_MovePageUp_ML
1984 * Only for multi line controls
1985 * Move the caret one page up, on a column with the nearest
1986 * x coordinate on the screen (might be a different column).
1989 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1991 INT s
= es
->selection_start
;
1992 INT e
= es
->selection_end
;
1993 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1994 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1995 INT x
= (short)LOWORD(pos
);
1996 INT y
= (short)HIWORD(pos
);
1998 e
= EDIT_CharFromPos(es
, x
,
1999 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2003 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2004 EDIT_EM_ScrollCaret(es
);
2008 /*********************************************************************
2012 * Only for multi line controls
2013 * Move the caret one line up, on a column with the nearest
2014 * x coordinate on the screen (might be a different column).
2017 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2019 INT s
= es
->selection_start
;
2020 INT e
= es
->selection_end
;
2021 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2022 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2023 INT x
= (short)LOWORD(pos
);
2024 INT y
= (short)HIWORD(pos
);
2026 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2029 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2030 EDIT_EM_ScrollCaret(es
);
2034 /*********************************************************************
2036 * EDIT_MoveWordBackward
2039 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2041 INT s
= es
->selection_start
;
2042 INT e
= es
->selection_end
;
2047 l
= EDIT_EM_LineFromChar(es
, e
);
2048 ll
= EDIT_EM_LineLength(es
, e
);
2049 li
= EDIT_EM_LineIndex(es
, l
);
2052 li
= EDIT_EM_LineIndex(es
, l
- 1);
2053 e
= li
+ EDIT_EM_LineLength(es
, li
);
2056 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2057 li
, e
- li
, ll
, WB_LEFT
);
2061 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2062 EDIT_EM_ScrollCaret(es
);
2066 /*********************************************************************
2068 * EDIT_MoveWordForward
2071 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2073 INT s
= es
->selection_start
;
2074 INT e
= es
->selection_end
;
2079 l
= EDIT_EM_LineFromChar(es
, e
);
2080 ll
= EDIT_EM_LineLength(es
, e
);
2081 li
= EDIT_EM_LineIndex(es
, l
);
2083 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2084 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2086 e
= li
+ EDIT_CallWordBreakProc(es
,
2087 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2091 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2092 EDIT_EM_ScrollCaret(es
);
2096 /*********************************************************************
2101 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2103 INT s
= es
->selection_start
;
2104 INT e
= es
->selection_end
;
2111 if (es
->style
& ES_MULTILINE
) {
2112 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2113 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2118 TRACE("line=%d\n", line
);
2120 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2121 x
= (short)LOWORD(pos
);
2122 y
= (short)HIWORD(pos
);
2123 li
= EDIT_EM_LineIndex(es
, line
);
2124 ll
= EDIT_EM_LineLength(es
, li
);
2125 s
= min(es
->selection_start
, es
->selection_end
);
2126 e
= max(es
->selection_start
, es
->selection_end
);
2127 s
= min(li
+ ll
, max(li
, s
));
2128 e
= min(li
+ ll
, max(li
, e
));
2129 if (rev
&& (s
!= e
) &&
2130 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2131 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2132 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2133 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2135 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2139 /*********************************************************************
2144 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2155 BkMode
= GetBkMode(dc
);
2156 BkColor
= GetBkColor(dc
);
2157 TextColor
= GetTextColor(dc
);
2159 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2160 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2161 SetBkMode( dc
, OPAQUE
);
2163 li
= EDIT_EM_LineIndex(es
, line
);
2164 if (es
->style
& ES_MULTILINE
) {
2165 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2166 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2168 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2169 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2170 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2172 if (es
->style
& ES_PASSWORD
)
2173 HeapFree(GetProcessHeap(), 0, text
);
2176 SetBkColor(dc
, BkColor
);
2177 SetTextColor(dc
, TextColor
);
2178 SetBkMode( dc
, BkMode
);
2184 /*********************************************************************
2189 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2192 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2193 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2194 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2198 /*********************************************************************
2202 * note: this is not (exactly) the handler called on EM_SETRECTNP
2203 * it is also used to set the rect of a single line control
2206 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2211 CopyRect(&es
->format_rect
, rc
);
2212 if (es
->style
& ES_MULTILINE
)
2214 if (es
->style
& WS_BORDER
) {
2215 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2216 es
->format_rect
.left
+= bw
;
2217 es
->format_rect
.right
-= bw
;
2218 es
->format_rect
.top
+= bw
;
2219 es
->format_rect
.bottom
-= bw
;
2224 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2225 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2226 if (es
->line_height
+ 2 <=
2227 es
->format_rect
.bottom
- es
->format_rect
.top
) {
2228 es
->format_rect
.top
++;
2229 es
->format_rect
.bottom
--;
2231 } else if (es
->style
& WS_BORDER
) {
2232 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2233 es
->format_rect
.left
+= bw
;
2234 es
->format_rect
.right
-= bw
;
2235 if (es
->line_height
+ 2 * bw
<=
2236 es
->format_rect
.bottom
- es
->format_rect
.top
) {
2237 es
->format_rect
.top
+= bw
;
2238 es
->format_rect
.bottom
-= bw
;
2242 es
->format_rect
.left
+= es
->left_margin
;
2243 es
->format_rect
.right
-= es
->right_margin
;
2244 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2245 if (es
->style
& ES_MULTILINE
)
2247 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2249 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2250 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2252 /* correct es->x_offset */
2253 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2254 max_x_offset
= es
->text_width
- fw
;
2255 if(max_x_offset
< 0) max_x_offset
= 0;
2256 if(es
->x_offset
> max_x_offset
)
2257 es
->x_offset
= max_x_offset
;
2259 /* correct es->y_offset */
2260 max_y_offset
= es
->line_count
- vlc
;
2261 if(max_y_offset
< 0) max_y_offset
= 0;
2262 if(es
->y_offset
> max_y_offset
)
2263 es
->y_offset
= max_y_offset
;
2265 /* force scroll info update */
2266 EDIT_UpdateScrollInfo(es
);
2269 /* Windows doesn't care to fix text placement for SL controls */
2270 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2272 /* Always stay within the client area */
2273 GetClientRect(es
->hwndSelf
, &ClientRect
);
2274 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2276 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2277 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2279 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2283 /*********************************************************************
2288 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2290 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2292 /* Edit window might be already destroyed */
2293 if(!IsWindow(es
->hwndSelf
))
2295 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2299 if (!es
->lock_count
) {
2300 ERR("lock_count == 0 ... please report\n");
2304 ERR("es->text == 0 ... please report\n");
2308 if (force
|| (es
->lock_count
== 1)) {
2311 BOOL _16bit
= FALSE
;
2313 UINT countW
= strlenW(es
->text
) + 1;
2317 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2318 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2319 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2320 countA
= LocalSize(es
->hloc32A
);
2321 if(countA_new
> countA
)
2324 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2325 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2326 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2329 es
->hloc32A
= hloc32A_new
;
2330 countA
= LocalSize(hloc32A_new
);
2331 TRACE("Real new size %d bytes\n", countA
);
2334 WARN("FAILED! Will synchronize partially\n");
2336 textA
= LocalLock(es
->hloc32A
);
2340 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2341 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2342 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2343 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2344 if(countA_new
> countA
)
2346 HLOCAL16 hloc16_new
;
2347 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2348 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2349 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2352 es
->hloc16
= hloc16_new
;
2353 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2354 TRACE("Real new size %d bytes\n", countA
);
2357 WARN("FAILED! Will synchronize partially\n");
2359 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2365 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2367 LOCAL_Unlock(hInstance
, es
->hloc16
);
2369 LocalUnlock(es
->hloc32A
);
2372 LocalUnlock(es
->hloc32W
);
2376 ERR("no buffer ... please report\n");
2384 /*********************************************************************
2386 * EDIT_UpdateScrollInfo
2389 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2391 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2394 si
.cbSize
= sizeof(SCROLLINFO
);
2395 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2397 si
.nMax
= es
->line_count
- 1;
2398 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2399 si
.nPos
= es
->y_offset
;
2400 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2401 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2402 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2405 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2408 si
.cbSize
= sizeof(SCROLLINFO
);
2409 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2411 si
.nMax
= es
->text_width
- 1;
2412 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2413 si
.nPos
= es
->x_offset
;
2414 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2415 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2416 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2420 /*********************************************************************
2422 * EDIT_WordBreakProc
2424 * Find the beginning of words.
2425 * Note: unlike the specs for a WordBreakProc, this function only
2426 * allows to be called without linebreaks between s[0] upto
2427 * s[count - 1]. Remember it is only called
2428 * internally, so we can decide this for ourselves.
2431 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2435 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2445 if (s
[index
] == ' ') {
2446 while (index
&& (s
[index
] == ' '))
2449 while (index
&& (s
[index
] != ' '))
2451 if (s
[index
] == ' ')
2455 while (index
&& (s
[index
] != ' '))
2457 if (s
[index
] == ' ')
2467 if (s
[index
] == ' ')
2468 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2470 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2472 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2476 case WB_ISDELIMITER
:
2477 ret
= (s
[index
] == ' ');
2480 ERR("unknown action code, please report !\n");
2487 /*********************************************************************
2491 * returns line number (not index) in high-order word of result.
2492 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2493 * to Richedit, not to the edit control. Original documentation is valid.
2494 * FIXME: do the specs mean to return -1 if outside client area or
2495 * if outside formatting rectangle ???
2498 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2506 GetClientRect(es
->hwndSelf
, &rc
);
2507 if (!PtInRect(&rc
, pt
))
2510 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2511 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2515 /*********************************************************************
2519 * Enable or disable soft breaks.
2521 * This means: insert or remove the soft linebreak character (\r\r\n).
2522 * Take care to check if the text still fits the buffer after insertion.
2523 * If not, notify with EN_ERRSPACE.
2526 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2528 es
->flags
&= ~EF_USE_SOFTBRK
;
2530 es
->flags
|= EF_USE_SOFTBRK
;
2531 FIXME("soft break enabled, not implemented\n");
2537 /*********************************************************************
2541 * Hopefully this won't fire back at us.
2542 * We always start with a fixed buffer in the local heap.
2543 * Despite of the documentation says that the local heap is used
2544 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2545 * buffer on the local heap.
2548 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2552 if (!(es
->style
& ES_MULTILINE
))
2556 hLocal
= es
->hloc32W
;
2562 UINT countA
, alloc_size
;
2563 TRACE("Allocating 32-bit ANSI alias buffer\n");
2564 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2565 alloc_size
= ROUND_TO_GROW(countA
);
2566 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2568 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2571 textA
= LocalLock(es
->hloc32A
);
2572 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2573 LocalUnlock(es
->hloc32A
);
2575 hLocal
= es
->hloc32A
;
2578 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2583 /*********************************************************************
2587 * Hopefully this won't fire back at us.
2588 * We always start with a buffer in 32 bit linear memory.
2589 * However, with this message a 16 bit application requests
2590 * a handle of 16 bit local heap memory, where it expects to find
2592 * It's a pitty that from this moment on we have to use this
2593 * local heap, because applications may rely on the handle
2596 * In this function we'll try to switch to local heap.
2598 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2600 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2602 UINT countA
, alloc_size
;
2604 if (!(es
->style
& ES_MULTILINE
))
2610 if (!LOCAL_HeapSize(hInstance
)) {
2611 if (!LocalInit16(hInstance
, 0,
2612 GlobalSize16(hInstance
))) {
2613 ERR("could not initialize local heap\n");
2616 TRACE("local heap initialized\n");
2619 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2620 alloc_size
= ROUND_TO_GROW(countA
);
2622 TRACE("Allocating 16-bit ANSI alias buffer\n");
2623 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2624 ERR("could not allocate new 16 bit buffer\n");
2628 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2629 ERR("could not lock new 16 bit buffer\n");
2630 LOCAL_Free(hInstance
, es
->hloc16
);
2635 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2636 LOCAL_Unlock(hInstance
, es
->hloc16
);
2638 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2643 /*********************************************************************
2648 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2651 INT line_len
, dst_len
;
2654 if (es
->style
& ES_MULTILINE
) {
2655 if (line
>= es
->line_count
)
2659 i
= EDIT_EM_LineIndex(es
, line
);
2661 line_len
= EDIT_EM_LineLength(es
, i
);
2662 dst_len
= *(WORD
*)dst
;
2665 if(dst_len
<= line_len
)
2667 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2670 else /* Append 0 if enough space */
2672 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2679 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2680 if(!ret
) /* Insufficient buffer size */
2682 if(ret
< dst_len
) /* Append 0 if enough space */
2683 ((LPSTR
)dst
)[ret
] = 0;
2689 /*********************************************************************
2694 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2696 UINT s
= es
->selection_start
;
2697 UINT e
= es
->selection_end
;
2704 return MAKELONG(s
, e
);
2708 /*********************************************************************
2712 * FIXME: is this right ? (or should it be only VSCROLL)
2713 * (and maybe only for edit controls that really have their
2714 * own scrollbars) (and maybe only for multiline controls ?)
2715 * All in all: very poorly documented
2718 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2720 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2721 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2725 /*********************************************************************
2730 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2735 if (!(es
->style
& ES_MULTILINE
))
2737 if (index
> (INT
)strlenW(es
->text
))
2738 return es
->line_count
- 1;
2740 index
= min(es
->selection_start
, es
->selection_end
);
2743 line_def
= es
->first_line_def
;
2744 index
-= line_def
->length
;
2745 while ((index
>= 0) && line_def
->next
) {
2747 line_def
= line_def
->next
;
2748 index
-= line_def
->length
;
2754 /*********************************************************************
2759 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2764 if (!(es
->style
& ES_MULTILINE
))
2766 if (line
>= es
->line_count
)
2770 line_def
= es
->first_line_def
;
2772 INT index
= es
->selection_end
- line_def
->length
;
2773 while ((index
>= 0) && line_def
->next
) {
2774 line_index
+= line_def
->length
;
2775 line_def
= line_def
->next
;
2776 index
-= line_def
->length
;
2780 line_index
+= line_def
->length
;
2781 line_def
= line_def
->next
;
2789 /*********************************************************************
2794 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2798 if (!(es
->style
& ES_MULTILINE
))
2799 return strlenW(es
->text
);
2802 /* get the number of remaining non-selected chars of selected lines */
2803 INT32 l
; /* line number */
2804 INT32 li
; /* index of first char in line */
2806 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2807 /* # chars before start of selection area */
2808 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2809 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2810 /* # chars after end of selection */
2811 li
= EDIT_EM_LineIndex(es
, l
);
2812 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2815 line_def
= es
->first_line_def
;
2816 index
-= line_def
->length
;
2817 while ((index
>= 0) && line_def
->next
) {
2818 line_def
= line_def
->next
;
2819 index
-= line_def
->length
;
2821 return line_def
->net_length
;
2825 /*********************************************************************
2829 * NOTE: dx is in average character widths, dy - in lines;
2832 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2834 if (!(es
->style
& ES_MULTILINE
))
2837 dx
*= es
->char_width
;
2838 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2841 /*********************************************************************
2843 * EDIT_EM_LineScroll_internal
2845 * Version of EDIT_EM_LineScroll for internal use.
2846 * It doesn't refuse if ES_MULTILINE is set and assumes that
2847 * dx is in pixels, dy - in lines.
2850 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2853 INT x_offset_in_pixels
;
2854 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
2857 if (es
->style
& ES_MULTILINE
)
2859 x_offset_in_pixels
= es
->x_offset
;
2864 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2867 if (-dx
> x_offset_in_pixels
)
2868 dx
= -x_offset_in_pixels
;
2869 if (dx
> es
->text_width
- x_offset_in_pixels
)
2870 dx
= es
->text_width
- x_offset_in_pixels
;
2871 nyoff
= max(0, es
->y_offset
+ dy
);
2872 if (nyoff
>= es
->line_count
- lines_per_page
)
2873 nyoff
= max(0, es
->line_count
- lines_per_page
);
2874 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2879 es
->y_offset
= nyoff
;
2880 if(es
->style
& ES_MULTILINE
)
2883 es
->x_offset
+= dx
/ es
->char_width
;
2885 GetClientRect(es
->hwndSelf
, &rc1
);
2886 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2887 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2888 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2889 /* force scroll info update */
2890 EDIT_UpdateScrollInfo(es
);
2892 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2893 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2894 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2895 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2900 /*********************************************************************
2905 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2907 INT len
= strlenW(es
->text
);
2920 index
= min(index
, len
);
2921 dc
= GetDC(es
->hwndSelf
);
2923 old_font
= SelectObject(dc
, es
->font
);
2924 if (es
->style
& ES_MULTILINE
) {
2925 l
= EDIT_EM_LineFromChar(es
, index
);
2926 y
= (l
- es
->y_offset
) * es
->line_height
;
2927 li
= EDIT_EM_LineIndex(es
, l
);
2928 if (after_wrap
&& (li
== index
) && l
) {
2930 line_def
= es
->first_line_def
;
2932 line_def
= line_def
->next
;
2935 if (line_def
->ending
== END_WRAP
) {
2937 y
-= es
->line_height
;
2938 li
= EDIT_EM_LineIndex(es
, l
);
2942 line_def
= es
->first_line_def
;
2943 while (line_def
->index
!= li
)
2944 line_def
= line_def
->next
;
2946 ll
= line_def
->net_length
;
2947 lw
= line_def
->width
;
2949 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2950 if (es
->style
& ES_RIGHT
)
2952 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
2953 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2956 else if (es
->style
& ES_CENTER
)
2958 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2959 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2964 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2965 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2968 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2969 if (index
< es
->x_offset
) {
2970 GetTextExtentPoint32W(dc
, text
+ index
,
2971 es
->x_offset
- index
, &size
);
2974 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2975 index
- es
->x_offset
, &size
);
2978 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
2980 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2981 if (w
> es
->text_width
)
2983 if (es
->style
& ES_RIGHT
)
2984 x
+= w
- es
->text_width
;
2985 else if (es
->style
& ES_CENTER
)
2986 x
+= (w
- es
->text_width
) / 2;
2991 if (es
->style
& ES_PASSWORD
)
2992 HeapFree(GetProcessHeap(), 0, text
);
2994 x
+= es
->format_rect
.left
;
2995 y
+= es
->format_rect
.top
;
2997 SelectObject(dc
, old_font
);
2998 ReleaseDC(es
->hwndSelf
, dc
);
2999 return MAKELONG((INT16
)x
, (INT16
)y
);
3003 /*********************************************************************
3007 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3010 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3012 UINT strl
= strlenW(lpsz_replace
);
3013 UINT tl
= strlenW(es
->text
);
3024 TRACE("%s, can_undo %d, send_update %d\n",
3025 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3027 s
= es
->selection_start
;
3028 e
= es
->selection_end
;
3030 if ((s
== e
) && !strl
)
3035 size
= tl
- (e
- s
) + strl
;
3039 /* Issue the EN_MAXTEXT notification and continue with replacing text
3040 * such that buffer limit is honored. */
3041 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
3042 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
3043 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3046 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3050 /* there is something to be deleted */
3051 TRACE("deleting stuff.\n");
3053 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3055 strncpyW(buf
, es
->text
+ s
, bufl
);
3056 buf
[bufl
] = 0; /* ensure 0 termination */
3058 strcpyW(es
->text
+ s
, es
->text
+ e
);
3061 /* there is an insertion */
3062 tl
= strlenW(es
->text
);
3063 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
));
3064 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3066 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3067 p
[i
] = lpsz_replace
[i
];
3068 if(es
->style
& ES_UPPERCASE
)
3069 CharUpperBuffW(p
, strl
);
3070 else if(es
->style
& ES_LOWERCASE
)
3071 CharLowerBuffW(p
, strl
);
3073 if (es
->style
& ES_MULTILINE
)
3075 INT st
= min(es
->selection_start
, es
->selection_end
);
3076 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3078 hrgn
= CreateRectRgn(0, 0, 0, 0);
3079 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3080 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3081 /* if text is too long undo all changes */
3082 if (!(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3084 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3086 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3088 EDIT_BuildLineDefs_ML(es
, s
, e
,
3089 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3092 hrgn
= CreateRectRgn(0, 0, 0, 0);
3093 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
3097 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3098 EDIT_CalcLineWidth_SL(es
);
3099 /* remove chars that don't fit */
3100 if (!(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3101 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3102 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3104 EDIT_CalcLineWidth_SL(es
);
3106 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
3112 utl
= strlenW(es
->undo_text
);
3113 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3114 /* undo-buffer is extended to the right */
3115 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3116 strncpyW(es
->undo_text
+ utl
, buf
, e
- s
+ 1);
3117 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3118 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3119 /* undo-buffer is extended to the left */
3120 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3121 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3123 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3125 es
->undo_position
= s
;
3127 /* new undo-buffer */
3128 EDIT_MakeUndoFit(es
, e
- s
);
3129 strncpyW(es
->undo_text
, buf
, e
- s
+ 1);
3130 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3131 es
->undo_position
= s
;
3133 /* any deletion makes the old insertion-undo invalid */
3134 es
->undo_insert_count
= 0;
3136 EDIT_EM_EmptyUndoBuffer(es
);
3140 if ((s
== es
->undo_position
) ||
3141 ((es
->undo_insert_count
) &&
3142 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3144 * insertion is new and at delete position or
3145 * an extension to either left or right
3147 es
->undo_insert_count
+= strl
;
3149 /* new insertion undo */
3150 es
->undo_position
= s
;
3151 es
->undo_insert_count
= strl
;
3152 /* new insertion makes old delete-buffer invalid */
3153 *es
->undo_text
= '\0';
3156 EDIT_EM_EmptyUndoBuffer(es
);
3160 HeapFree(GetProcessHeap(), 0, buf
);
3164 /* If text has been deleted and we're right or center aligned then scroll rightward */
3165 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3167 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3169 if (delta
< 0 && es
->x_offset
)
3171 if (abs(delta
) > es
->x_offset
)
3174 es
->x_offset
+= delta
;
3178 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3179 es
->flags
|= EF_MODIFIED
;
3180 if (send_update
) es
->flags
|= EF_UPDATE
;
3183 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3187 EDIT_UpdateText(es
, NULL
, TRUE
);
3189 EDIT_EM_ScrollCaret(es
);
3191 /* force scroll info update */
3192 EDIT_UpdateScrollInfo(es
);
3195 if(send_update
|| (es
->flags
& EF_UPDATE
))
3197 es
->flags
&= ~EF_UPDATE
;
3198 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3203 /*********************************************************************
3208 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3212 if (!(es
->style
& ES_MULTILINE
))
3213 return (LRESULT
)FALSE
;
3223 if (es
->y_offset
< es
->line_count
- 1)
3228 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3231 if (es
->y_offset
< es
->line_count
- 1)
3232 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3235 return (LRESULT
)FALSE
;
3238 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3239 /* check if we are going to move too far */
3240 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3241 dy
= es
->line_count
- vlc
- es
->y_offset
;
3243 /* Notification is done in EDIT_EM_LineScroll */
3245 EDIT_EM_LineScroll(es
, 0, dy
);
3247 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3251 /*********************************************************************
3256 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3258 if (es
->style
& ES_MULTILINE
) {
3263 INT cw
= es
->char_width
;
3268 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3269 li
= EDIT_EM_LineIndex(es
, l
);
3270 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3271 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3272 if (l
>= es
->y_offset
+ vlc
)
3273 dy
= l
- vlc
+ 1 - es
->y_offset
;
3274 if (l
< es
->y_offset
)
3275 dy
= l
- es
->y_offset
;
3276 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3277 if (x
< es
->format_rect
.left
)
3278 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3279 if (x
> es
->format_rect
.right
)
3280 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3281 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3283 /* check if we are going to move too far */
3284 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3285 dx
= es
->text_width
- ww
- es
->x_offset
;
3286 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3287 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3294 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3295 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3296 if (x
< es
->format_rect
.left
) {
3297 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3300 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3301 } while ((x
< goal
) && es
->x_offset
);
3302 /* FIXME: use ScrollWindow() somehow to improve performance */
3303 EDIT_UpdateText(es
, NULL
, TRUE
);
3304 } else if (x
> es
->format_rect
.right
) {
3306 INT len
= strlenW(es
->text
);
3307 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3310 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3311 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3312 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3313 /* FIXME: use ScrollWindow() somehow to improve performance */
3314 EDIT_UpdateText(es
, NULL
, TRUE
);
3318 if(es
->flags
& EF_FOCUSED
)
3319 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3323 /*********************************************************************
3327 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3330 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3332 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3334 if (!(es
->style
& ES_MULTILINE
))
3338 WARN("called with NULL handle\n");
3342 EDIT_UnlockBuffer(es
, TRUE
);
3346 LOCAL_Free(hInstance
, es
->hloc16
);
3347 es
->hloc16
= (HLOCAL16
)NULL
;
3354 LocalFree(es
->hloc32A
);
3366 countA
= LocalSize(hloc
);
3367 textA
= LocalLock(hloc
);
3368 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3369 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3371 ERR("Could not allocate new unicode buffer\n");
3374 textW
= LocalLock(hloc32W_new
);
3375 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3376 LocalUnlock(hloc32W_new
);
3380 LocalFree(es
->hloc32W
);
3382 es
->hloc32W
= hloc32W_new
;
3386 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3388 EDIT_LockBuffer(es
);
3390 es
->x_offset
= es
->y_offset
= 0;
3391 es
->selection_start
= es
->selection_end
= 0;
3392 EDIT_EM_EmptyUndoBuffer(es
);
3393 es
->flags
&= ~EF_MODIFIED
;
3394 es
->flags
&= ~EF_UPDATE
;
3395 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3396 EDIT_UpdateText(es
, NULL
, TRUE
);
3397 EDIT_EM_ScrollCaret(es
);
3398 /* force scroll info update */
3399 EDIT_UpdateScrollInfo(es
);
3403 /*********************************************************************
3407 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3410 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3412 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3418 if (!(es
->style
& ES_MULTILINE
))
3422 WARN("called with NULL handle\n");
3426 EDIT_UnlockBuffer(es
, TRUE
);
3430 LocalFree(es
->hloc32A
);
3434 countA
= LOCAL_Size(hInstance
, hloc
);
3435 textA
= LOCAL_Lock(hInstance
, hloc
);
3436 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3437 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3439 ERR("Could not allocate new unicode buffer\n");
3442 textW
= LocalLock(hloc32W_new
);
3443 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3444 LocalUnlock(hloc32W_new
);
3445 LOCAL_Unlock(hInstance
, hloc
);
3448 LocalFree(es
->hloc32W
);
3450 es
->hloc32W
= hloc32W_new
;
3453 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3455 EDIT_LockBuffer(es
);
3457 es
->x_offset
= es
->y_offset
= 0;
3458 es
->selection_start
= es
->selection_end
= 0;
3459 EDIT_EM_EmptyUndoBuffer(es
);
3460 es
->flags
&= ~EF_MODIFIED
;
3461 es
->flags
&= ~EF_UPDATE
;
3462 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3463 EDIT_UpdateText(es
, NULL
, TRUE
);
3464 EDIT_EM_ScrollCaret(es
);
3465 /* force scroll info update */
3466 EDIT_UpdateScrollInfo(es
);
3470 /*********************************************************************
3474 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3475 * However, the windows version is not complied to yet in all of edit.c
3477 * Additionally as the wrapper for RichEdit controls we need larger buffers
3478 * at present -1 will represent nolimit
3480 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3482 if (limit
== 0xFFFFFFFF)
3483 es
->buffer_limit
= -1;
3484 else if (es
->style
& ES_MULTILINE
) {
3486 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3488 es
->buffer_limit
= BUFLIMIT_MULTI
;
3491 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3493 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3498 /*********************************************************************
3502 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3503 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3504 * margin according to the textmetrics of the current font.
3506 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3507 * of the char's width as the margin, but this is not how Windows handles this.
3508 * For all other fonts Windows sets the margins to zero.
3511 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3512 INT left
, INT right
)
3515 INT default_left_margin
= 0; /* in pixels */
3516 INT default_right_margin
= 0; /* in pixels */
3518 /* Set the default margins depending on the font */
3519 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3520 HDC dc
= GetDC(es
->hwndSelf
);
3521 HFONT old_font
= SelectObject(dc
, es
->font
);
3522 GetTextMetricsW(dc
, &tm
);
3523 /* The default margins are only non zero for TrueType or Vector fonts */
3524 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3525 /* This must be calculated more exactly! But how? */
3526 default_left_margin
= tm
.tmAveCharWidth
/ 3;
3527 default_right_margin
= tm
.tmAveCharWidth
/ 3;
3529 SelectObject(dc
, old_font
);
3530 ReleaseDC(es
->hwndSelf
, dc
);
3533 if (action
& EC_LEFTMARGIN
) {
3534 if (left
!= EC_USEFONTINFO
)
3535 es
->left_margin
= left
;
3537 es
->left_margin
= default_left_margin
;
3540 if (action
& EC_RIGHTMARGIN
) {
3541 if (right
!= EC_USEFONTINFO
)
3542 es
->right_margin
= right
;
3544 es
->right_margin
= default_right_margin
;
3546 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3550 /*********************************************************************
3552 * EM_SETPASSWORDCHAR
3555 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3559 if (es
->style
& ES_MULTILINE
)
3562 if (es
->password_char
== c
)
3565 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3566 es
->password_char
= c
;
3568 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3569 es
->style
|= ES_PASSWORD
;
3571 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3572 es
->style
&= ~ES_PASSWORD
;
3574 EDIT_UpdateText(es
, NULL
, TRUE
);
3578 /*********************************************************************
3582 * note: unlike the specs say: the order of start and end
3583 * _is_ preserved in Windows. (i.e. start can be > end)
3584 * In other words: this handler is OK
3587 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3589 UINT old_start
= es
->selection_start
;
3590 UINT old_end
= es
->selection_end
;
3591 UINT len
= strlenW(es
->text
);
3593 if (start
== (UINT
)-1) {
3594 start
= es
->selection_end
;
3595 end
= es
->selection_end
;
3597 start
= min(start
, len
);
3598 end
= min(end
, len
);
3600 es
->selection_start
= start
;
3601 es
->selection_end
= end
;
3603 es
->flags
|= EF_AFTER_WRAP
;
3605 es
->flags
&= ~EF_AFTER_WRAP
;
3606 /* Compute the necessary invalidation region. */
3607 /* Note that we don't need to invalidate regions which have
3608 * "never" been selected, or those which are "still" selected.
3609 * In fact, every time we hit a selection boundary, we can
3610 * *toggle* whether we need to invalidate. Thus we can optimize by
3611 * *sorting* the interval endpoints. Let's assume that we sort them
3613 * start <= end <= old_start <= old_end
3614 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3615 * in 5 comparisons; ie it's impossible to do better than the
3617 ORDER_UINT(end
, old_end
);
3618 ORDER_UINT(start
, old_start
);
3619 ORDER_UINT(old_start
, old_end
);
3620 ORDER_UINT(start
, end
);
3621 /* Note that at this point 'end' and 'old_start' are not in order, but
3622 * start is definitely the min. and old_end is definitely the max. */
3623 if (end
!= old_start
)
3627 * ORDER_UINT32(end, old_start);
3628 * EDIT_InvalidateText(es, start, end);
3629 * EDIT_InvalidateText(es, old_start, old_end);
3630 * in place of the following if statement.
3631 * (That would complete the optimal five-comparison four-element sort.)
3633 if (old_start
> end
)
3635 EDIT_InvalidateText(es
, start
, end
);
3636 EDIT_InvalidateText(es
, old_start
, old_end
);
3640 EDIT_InvalidateText(es
, start
, old_start
);
3641 EDIT_InvalidateText(es
, end
, old_end
);
3644 else EDIT_InvalidateText(es
, start
, old_end
);
3648 /*********************************************************************
3653 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3655 if (!(es
->style
& ES_MULTILINE
))
3657 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3658 es
->tabs_count
= count
;
3662 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3663 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3669 /*********************************************************************
3674 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3676 if (!(es
->style
& ES_MULTILINE
))
3678 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3679 es
->tabs_count
= count
;
3684 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3685 for (i
= 0 ; i
< count
; i
++)
3686 es
->tabs
[i
] = *tabs
++;
3692 /*********************************************************************
3694 * EM_SETWORDBREAKPROC
3697 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3699 if (es
->word_break_proc
== wbp
)
3702 es
->word_break_proc
= wbp
;
3703 es
->word_break_proc16
= NULL
;
3705 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3706 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3707 EDIT_UpdateText(es
, NULL
, TRUE
);
3712 /*********************************************************************
3714 * EM_SETWORDBREAKPROC16
3717 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3719 if (es
->word_break_proc16
== wbp
)
3722 es
->word_break_proc
= NULL
;
3723 es
->word_break_proc16
= wbp
;
3724 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3725 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3726 EDIT_UpdateText(es
, NULL
, TRUE
);
3731 /*********************************************************************
3736 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3741 /* As per MSDN spec, for a single-line edit control,
3742 the return value is always TRUE */
3743 if( es
->style
& ES_READONLY
)
3744 return !(es
->style
& ES_MULTILINE
);
3746 ulength
= strlenW(es
->undo_text
);
3748 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3750 strcpyW(utext
, es
->undo_text
);
3752 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3753 es
->undo_insert_count
, debugstr_w(utext
));
3755 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3756 EDIT_EM_EmptyUndoBuffer(es
);
3757 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3758 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3759 /* send the notification after the selection start and end are set */
3760 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3761 EDIT_EM_ScrollCaret(es
);
3762 HeapFree(GetProcessHeap(), 0, utext
);
3764 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3765 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3770 /*********************************************************************
3775 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3779 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3783 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3784 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3787 if (es
->style
& ES_MULTILINE
) {
3788 if (es
->style
& ES_READONLY
) {
3789 EDIT_MoveHome(es
, FALSE
);
3790 EDIT_MoveDown_ML(es
, FALSE
);
3792 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3793 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3798 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3800 static const WCHAR tabW
[] = {'\t',0};
3801 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3805 if (!(es
->style
& ES_READONLY
) && !control
) {
3806 if (es
->selection_start
!= es
->selection_end
)
3809 /* delete character left of caret */
3810 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3811 EDIT_MoveBackward(es
, TRUE
);
3817 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3820 if (!(es
->style
& ES_READONLY
))
3821 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3824 if (!(es
->style
& ES_READONLY
))
3825 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3829 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3830 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3833 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3837 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3844 /*********************************************************************
3849 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3851 if (code
|| control
)
3871 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3872 EDIT_EM_ScrollCaret(es
);
3875 ERR("unknown menu item, please report\n");
3881 /*********************************************************************
3885 * Note: the resource files resource/sysres_??.rc cannot define a
3886 * single popup menu. Hence we use a (dummy) menubar
3887 * containing the single popup menu as its first item.
3889 * FIXME: the message identifiers have been chosen arbitrarily,
3890 * hence we use MF_BYPOSITION.
3891 * We might as well use the "real" values (anybody knows ?)
3892 * The menu definition is in resources/sysres_??.rc.
3893 * Once these are OK, we better use MF_BYCOMMAND here
3894 * (as we do in EDIT_WM_Command()).
3897 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3899 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3900 HMENU popup
= GetSubMenu(menu
, 0);
3901 UINT start
= es
->selection_start
;
3902 UINT end
= es
->selection_end
;
3904 ORDER_UINT(start
, end
);
3907 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3909 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3911 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3913 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3915 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3917 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3919 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3924 /*********************************************************************
3929 static void EDIT_WM_Copy(EDITSTATE
*es
)
3931 INT s
= min(es
->selection_start
, es
->selection_end
);
3932 INT e
= max(es
->selection_start
, es
->selection_end
);
3938 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3939 dst
= GlobalLock(hdst
);
3940 strncpyW(dst
, es
->text
+ s
, e
- s
);
3941 dst
[e
- s
] = 0; /* ensure 0 termination */
3942 TRACE("%s\n", debugstr_w(dst
));
3944 OpenClipboard(es
->hwndSelf
);
3946 SetClipboardData(CF_UNICODETEXT
, hdst
);
3951 /*********************************************************************
3956 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3958 TRACE("%s\n", debugstr_w(name
));
3960 * To initialize some final structure members, we call some helper
3961 * functions. However, since the EDITSTATE is not consistent (i.e.
3962 * not fully initialized), we should be very careful which
3963 * functions can be called, and in what order.
3965 EDIT_WM_SetFont(es
, 0, FALSE
);
3966 EDIT_EM_EmptyUndoBuffer(es
);
3968 if (name
&& *name
) {
3969 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3970 /* if we insert text to the editline, the text scrolls out
3971 * of the window, as the caret is placed after the insert
3972 * pos normally; thus we reset es->selection... to 0 and
3975 es
->selection_start
= es
->selection_end
= 0;
3976 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3977 * Messages are only to be sent when the USER does something to
3978 * change the contents. So I am removing this EN_CHANGE
3980 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3982 EDIT_EM_ScrollCaret(es
);
3984 /* force scroll info update */
3985 EDIT_UpdateScrollInfo(es
);
3986 /* The rule seems to return 1 here for success */
3987 /* Power Builder masked edit controls will crash */
3989 /* FIXME: is that in all cases so ? */
3994 /*********************************************************************
3999 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4004 while (LocalUnlock(es
->hloc32W
)) ;
4005 LocalFree(es
->hloc32W
);
4008 while (LocalUnlock(es
->hloc32A
)) ;
4009 LocalFree(es
->hloc32A
);
4012 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4013 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
4014 LOCAL_Free(hInstance
, es
->hloc16
);
4017 pc
= es
->first_line_def
;
4021 HeapFree(GetProcessHeap(), 0, pc
);
4025 SetWindowLongW( es
->hwndSelf
, 0, 0 );
4026 HeapFree(GetProcessHeap(), 0, es
);
4032 /*********************************************************************
4037 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4039 /* we do the proper erase in EDIT_WM_Paint */
4044 /*********************************************************************
4049 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4051 if(!count
) return 0;
4055 lstrcpynW(dst
, es
->text
, count
);
4056 return strlenW(dst
);
4060 LPSTR textA
= (LPSTR
)dst
;
4061 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4062 textA
[count
- 1] = 0; /* ensure 0 termination */
4063 return strlen(textA
);
4067 /*********************************************************************
4072 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4077 if (!(es
->style
& ES_MULTILINE
))
4080 if (!(es
->style
& ES_AUTOHSCROLL
))
4084 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4087 TRACE("SB_LINELEFT\n");
4089 dx
= -es
->char_width
;
4092 TRACE("SB_LINERIGHT\n");
4093 if (es
->x_offset
< es
->text_width
)
4094 dx
= es
->char_width
;
4097 TRACE("SB_PAGELEFT\n");
4099 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4102 TRACE("SB_PAGERIGHT\n");
4103 if (es
->x_offset
< es
->text_width
)
4104 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4112 TRACE("SB_RIGHT\n");
4113 if (es
->x_offset
< es
->text_width
)
4114 dx
= es
->text_width
- es
->x_offset
;
4117 TRACE("SB_THUMBTRACK %d\n", pos
);
4118 es
->flags
|= EF_HSCROLL_TRACK
;
4119 if(es
->style
& WS_HSCROLL
)
4120 dx
= pos
- es
->x_offset
;
4125 if(pos
< 0 || pos
> 100) return 0;
4126 /* Assume default scroll range 0-100 */
4127 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4128 new_x
= pos
* (es
->text_width
- fw
) / 100;
4129 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4132 case SB_THUMBPOSITION
:
4133 TRACE("SB_THUMBPOSITION %d\n", pos
);
4134 es
->flags
&= ~EF_HSCROLL_TRACK
;
4135 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4136 dx
= pos
- es
->x_offset
;
4141 if(pos
< 0 || pos
> 100) return 0;
4142 /* Assume default scroll range 0-100 */
4143 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4144 new_x
= pos
* (es
->text_width
- fw
) / 100;
4145 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4148 /* force scroll info update */
4149 EDIT_UpdateScrollInfo(es
);
4150 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
4154 TRACE("SB_ENDSCROLL\n");
4157 * FIXME : the next two are undocumented !
4158 * Are we doing the right thing ?
4159 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4160 * although it's also a regular control message.
4162 case EM_GETTHUMB
: /* this one is used by NT notepad */
4166 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4167 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4170 /* Assume default scroll range 0-100 */
4171 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4172 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4174 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4177 case EM_LINESCROLL16
:
4178 TRACE("EM_LINESCROLL16\n");
4183 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4189 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4190 /* check if we are going to move too far */
4191 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4192 dx
= es
->text_width
- fw
- es
->x_offset
;
4194 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4200 /*********************************************************************
4205 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4207 HWND hLBox
= es
->hwndListBox
;
4215 hCombo
= GetParent(es
->hwndSelf
);
4219 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4221 if (key
== VK_UP
|| key
== VK_DOWN
)
4223 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4226 if (msg
== WM_KEYDOWN
|| nEUI
)
4227 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4233 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4235 /* make sure ComboLBox pops up */
4236 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4241 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4244 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4246 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4248 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4253 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4259 /*********************************************************************
4263 * Handling of special keys that don't produce a WM_CHAR
4264 * (i.e. non-printable keys) & Backspace & Delete
4267 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4272 if (GetKeyState(VK_MENU
) & 0x8000)
4275 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4276 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4281 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4286 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4287 EDIT_MoveUp_ML(es
, shift
);
4290 EDIT_MoveWordBackward(es
, shift
);
4292 EDIT_MoveBackward(es
, shift
);
4295 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4299 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4300 EDIT_MoveDown_ML(es
, shift
);
4302 EDIT_MoveWordForward(es
, shift
);
4304 EDIT_MoveForward(es
, shift
);
4307 EDIT_MoveHome(es
, shift
);
4310 EDIT_MoveEnd(es
, shift
);
4313 if (es
->style
& ES_MULTILINE
)
4314 EDIT_MovePageUp_ML(es
, shift
);
4316 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4319 if (es
->style
& ES_MULTILINE
)
4320 EDIT_MovePageDown_ML(es
, shift
);
4322 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4325 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4326 if (es
->selection_start
!= es
->selection_end
) {
4333 /* delete character left of caret */
4334 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4335 EDIT_MoveBackward(es
, TRUE
);
4337 } else if (control
) {
4338 /* delete to end of line */
4339 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4340 EDIT_MoveEnd(es
, TRUE
);
4343 /* delete character right of caret */
4344 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4345 EDIT_MoveForward(es
, TRUE
);
4353 if (!(es
->style
& ES_READONLY
))
4359 /* If the edit doesn't want the return send a message to the default object */
4360 if(!(es
->style
& ES_WANTRETURN
))
4362 HWND hwndParent
= GetParent(es
->hwndSelf
);
4363 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4364 if (HIWORD(dw
) == DC_HASDEFID
)
4366 SendMessageW( hwndParent
, WM_COMMAND
,
4367 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4368 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4377 /*********************************************************************
4382 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4384 es
->flags
&= ~EF_FOCUSED
;
4386 if(!(es
->style
& ES_NOHIDESEL
))
4387 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4388 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4393 /*********************************************************************
4397 * The caret position has been set on the WM_LBUTTONDOWN message
4400 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4403 INT e
= es
->selection_end
;
4408 if (!(es
->flags
& EF_FOCUSED
))
4411 l
= EDIT_EM_LineFromChar(es
, e
);
4412 li
= EDIT_EM_LineIndex(es
, l
);
4413 ll
= EDIT_EM_LineLength(es
, e
);
4414 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4415 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4416 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4417 EDIT_EM_ScrollCaret(es
);
4422 /*********************************************************************
4427 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4432 SetFocus(es
->hwndSelf
);
4433 if (!(es
->flags
& EF_FOCUSED
))
4436 es
->bCaptureState
= TRUE
;
4437 SetCapture(es
->hwndSelf
);
4438 EDIT_ConfinePoint(es
, &x
, &y
);
4439 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4440 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4441 EDIT_EM_ScrollCaret(es
);
4442 es
->region_posx
= es
->region_posy
= 0;
4443 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4448 /*********************************************************************
4453 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4455 if (es
->bCaptureState
) {
4456 KillTimer(es
->hwndSelf
, 0);
4457 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4459 es
->bCaptureState
= FALSE
;
4464 /*********************************************************************
4469 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4471 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4476 /*********************************************************************
4481 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4487 if (GetCapture() != es
->hwndSelf
)
4491 * FIXME: gotta do some scrolling if outside client
4492 * area. Maybe reset the timer ?
4495 EDIT_ConfinePoint(es
, &x
, &y
);
4496 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4497 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4498 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4499 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4500 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4505 /*********************************************************************
4509 * See also EDIT_WM_StyleChanged
4511 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4516 TRACE("Creating %s edit control, style = %08lx\n",
4517 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4519 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4521 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4524 * Note: since the EDITSTATE has not been fully initialized yet,
4525 * we can't use any API calls that may send
4526 * WM_XXX messages before WM_NCCREATE is completed.
4529 es
->is_unicode
= unicode
;
4530 es
->style
= lpcs
->style
;
4532 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4534 es
->hwndSelf
= hwnd
;
4535 /* Save parent, which will be notified by EN_* messages */
4536 es
->hwndParent
= lpcs
->hwndParent
;
4538 if (es
->style
& ES_COMBO
)
4539 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4541 /* Number overrides lowercase overrides uppercase (at least it
4542 * does in Win95). However I'll bet that ES_NUMBER would be
4543 * invalid under Win 3.1.
4545 if (es
->style
& ES_NUMBER
) {
4546 ; /* do not override the ES_NUMBER */
4547 } else if (es
->style
& ES_LOWERCASE
) {
4548 es
->style
&= ~ES_UPPERCASE
;
4550 if (es
->style
& ES_MULTILINE
) {
4551 es
->buffer_limit
= BUFLIMIT_MULTI
;
4552 if (es
->style
& WS_VSCROLL
)
4553 es
->style
|= ES_AUTOVSCROLL
;
4554 if (es
->style
& WS_HSCROLL
)
4555 es
->style
|= ES_AUTOHSCROLL
;
4556 es
->style
&= ~ES_PASSWORD
;
4557 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4558 /* Confirmed - RIGHT overrides CENTER */
4559 if (es
->style
& ES_RIGHT
)
4560 es
->style
&= ~ES_CENTER
;
4561 es
->style
&= ~WS_HSCROLL
;
4562 es
->style
&= ~ES_AUTOHSCROLL
;
4565 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4566 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4567 es
->style
&= ~ES_CENTER
;
4568 es
->style
&= ~WS_HSCROLL
;
4569 es
->style
&= ~WS_VSCROLL
;
4570 if (es
->style
& ES_PASSWORD
)
4571 es
->password_char
= '*';
4574 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4575 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4577 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4579 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4581 es
->undo_buffer_size
= es
->buffer_size
;
4583 if (es
->style
& ES_MULTILINE
)
4584 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4589 * In Win95 look and feel, the WS_BORDER style is replaced by the
4590 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4591 * control a nonclient area so we don't need to draw the border.
4592 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4593 * a nonclient area and we should handle painting the border ourselves.
4595 * When making modifications please ensure that the code still works
4596 * for edit controls created directly with style 0x50800000, exStyle 0
4597 * (which should have a single pixel border)
4599 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4600 es
->style
&= ~WS_BORDER
;
4601 else if (es
->style
& WS_BORDER
)
4602 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4607 /*********************************************************************
4612 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4623 BOOL rev
= es
->bEnableState
&&
4624 ((es
->flags
& EF_FOCUSED
) ||
4625 (es
->style
& ES_NOHIDESEL
));
4626 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4628 GetClientRect(es
->hwndSelf
, &rcClient
);
4630 /* paint the background */
4631 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
4632 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
4633 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4634 GetClipBox(dc
, &rc
);
4635 FillRect(dc
, &rc
, brush
);
4637 /* draw the border */
4638 if(es
->style
& WS_BORDER
) {
4640 if(es
->style
& ES_MULTILINE
) {
4641 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4642 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4644 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4646 IntersectClipRect(dc
, es
->format_rect
.left
,
4647 es
->format_rect
.top
,
4648 es
->format_rect
.right
,
4649 es
->format_rect
.bottom
);
4650 if (es
->style
& ES_MULTILINE
) {
4652 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4655 old_font
= SelectObject(dc
, es
->font
);
4656 EDIT_NotifyCtlColor(es
, dc
);
4658 if (!es
->bEnableState
)
4659 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4660 GetClipBox(dc
, &rcRgn
);
4661 if (es
->style
& ES_MULTILINE
) {
4662 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4663 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4664 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4665 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4666 EDIT_PaintLine(es
, dc
, i
, rev
);
4669 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4670 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4671 EDIT_PaintLine(es
, dc
, 0, rev
);
4674 SelectObject(dc
, old_font
);
4677 EndPaint(es
->hwndSelf
, &ps
);
4681 /*********************************************************************
4686 static void EDIT_WM_Paste(EDITSTATE
*es
)
4691 /* Protect read-only edit control from modification */
4692 if(es
->style
& ES_READONLY
)
4695 OpenClipboard(es
->hwndSelf
);
4696 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4697 src
= (LPWSTR
)GlobalLock(hsrc
);
4698 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4705 /*********************************************************************
4710 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4712 es
->flags
|= EF_FOCUSED
;
4713 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4714 EDIT_SetCaretPos(es
, es
->selection_end
,
4715 es
->flags
& EF_AFTER_WRAP
);
4716 if(!(es
->style
& ES_NOHIDESEL
))
4717 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4718 ShowCaret(es
->hwndSelf
);
4719 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4723 /*********************************************************************
4727 * With Win95 look the margins are set to default font value unless
4728 * the system font (font == 0) is being set, in which case they are left
4732 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4740 dc
= GetDC(es
->hwndSelf
);
4742 old_font
= SelectObject(dc
, font
);
4743 GetTextMetricsW(dc
, &tm
);
4744 es
->line_height
= tm
.tmHeight
;
4745 es
->char_width
= tm
.tmAveCharWidth
;
4747 SelectObject(dc
, old_font
);
4748 ReleaseDC(es
->hwndSelf
, dc
);
4749 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4750 EC_USEFONTINFO
, EC_USEFONTINFO
);
4752 /* Force the recalculation of the format rect for each font change */
4753 GetClientRect(es
->hwndSelf
, &r
);
4754 EDIT_SetRectNP(es
, &r
);
4756 if (es
->style
& ES_MULTILINE
)
4757 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4759 EDIT_CalcLineWidth_SL(es
);
4762 EDIT_UpdateText(es
, NULL
, TRUE
);
4763 if (es
->flags
& EF_FOCUSED
) {
4765 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4766 EDIT_SetCaretPos(es
, es
->selection_end
,
4767 es
->flags
& EF_AFTER_WRAP
);
4768 ShowCaret(es
->hwndSelf
);
4773 /*********************************************************************
4778 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4779 * The modified flag is reset. No notifications are sent.
4781 * For single-line controls, reception of WM_SETTEXT triggers:
4782 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4785 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
4787 if (!unicode
&& text
)
4789 LPCSTR textA
= (LPCSTR
)text
;
4790 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4791 LPWSTR textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
4793 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4797 if (es
->flags
& EF_UPDATE
)
4798 /* fixed this bug once; complain if we see it about to happen again. */
4799 ERR("SetSel may generate UPDATE message whose handler may reset "
4802 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4805 TRACE("%s\n", debugstr_w(text
));
4806 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4808 HeapFree(GetProcessHeap(), 0, (LPWSTR
)text
);
4812 static const WCHAR empty_stringW
[] = {0};
4814 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4817 es
->flags
&= ~EF_MODIFIED
;
4818 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4820 /* Send the notification after the selection start and end have been set
4821 * edit control doesn't send notification on WM_SETTEXT
4822 * if it is multiline, or it is part of combobox
4824 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4826 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4827 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4829 EDIT_EM_ScrollCaret(es
);
4830 EDIT_UpdateScrollInfo(es
);
4834 /*********************************************************************
4839 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4841 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4843 TRACE("width = %d, height = %d\n", width
, height
);
4844 SetRect(&rc
, 0, 0, width
, height
);
4845 EDIT_SetRectNP(es
, &rc
);
4846 EDIT_UpdateText(es
, NULL
, TRUE
);
4851 /*********************************************************************
4855 * This message is sent by SetWindowLong on having changed either the Style
4856 * or the extended style.
4858 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4860 * See also EDIT_WM_NCCreate
4862 * It appears that the Windows version of the edit control allows the style
4863 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4864 * style variable which will generally be different. In this function we
4865 * update the internal style based on what changed in the externally visible
4868 * Much of this content as based upon the MSDN, especially:
4869 * Platform SDK Documentation -> User Interface Services ->
4870 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4871 * Edit Control Styles
4873 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4875 if (GWL_STYLE
== which
) {
4876 DWORD style_change_mask
;
4878 /* Only a subset of changes can be applied after the control
4881 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4883 if (es
->style
& ES_MULTILINE
)
4884 style_change_mask
|= ES_WANTRETURN
;
4886 new_style
= style
->styleNew
& style_change_mask
;
4888 /* Number overrides lowercase overrides uppercase (at least it
4889 * does in Win95). However I'll bet that ES_NUMBER would be
4890 * invalid under Win 3.1.
4892 if (new_style
& ES_NUMBER
) {
4893 ; /* do not override the ES_NUMBER */
4894 } else if (new_style
& ES_LOWERCASE
) {
4895 new_style
&= ~ES_UPPERCASE
;
4898 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4899 } else if (GWL_EXSTYLE
== which
) {
4900 ; /* FIXME - what is needed here */
4902 WARN ("Invalid style change %d\n",which
);
4908 /*********************************************************************
4913 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4915 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4916 if (EDIT_EM_CanUndo(es
))
4919 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4920 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4923 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4927 /*********************************************************************
4932 static void EDIT_WM_Timer(EDITSTATE
*es
)
4934 if (es
->region_posx
< 0) {
4935 EDIT_MoveBackward(es
, TRUE
);
4936 } else if (es
->region_posx
> 0) {
4937 EDIT_MoveForward(es
, TRUE
);
4940 * FIXME: gotta do some vertical scrolling here, like
4941 * EDIT_EM_LineScroll(hwnd, 0, 1);
4945 /*********************************************************************
4950 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4954 if (!(es
->style
& ES_MULTILINE
))
4957 if (!(es
->style
& ES_AUTOVSCROLL
))
4966 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4967 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4968 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4970 EDIT_EM_Scroll(es
, action
);
4977 TRACE("SB_BOTTOM\n");
4978 dy
= es
->line_count
- 1 - es
->y_offset
;
4981 TRACE("SB_THUMBTRACK %d\n", pos
);
4982 es
->flags
|= EF_VSCROLL_TRACK
;
4983 if(es
->style
& WS_VSCROLL
)
4984 dy
= pos
- es
->y_offset
;
4987 /* Assume default scroll range 0-100 */
4990 if(pos
< 0 || pos
> 100) return 0;
4991 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4992 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4993 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4994 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4995 es
->line_count
, es
->y_offset
, pos
, dy
);
4998 case SB_THUMBPOSITION
:
4999 TRACE("SB_THUMBPOSITION %d\n", pos
);
5000 es
->flags
&= ~EF_VSCROLL_TRACK
;
5001 if(es
->style
& WS_VSCROLL
)
5002 dy
= pos
- es
->y_offset
;
5005 /* Assume default scroll range 0-100 */
5008 if(pos
< 0 || pos
> 100) return 0;
5009 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5010 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5011 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5012 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5013 es
->line_count
, es
->y_offset
, pos
, dy
);
5017 /* force scroll info update */
5018 EDIT_UpdateScrollInfo(es
);
5019 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
5023 TRACE("SB_ENDSCROLL\n");
5026 * FIXME : the next two are undocumented !
5027 * Are we doing the right thing ?
5028 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5029 * although it's also a regular control message.
5031 case EM_GETTHUMB
: /* this one is used by NT notepad */
5035 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5036 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5039 /* Assume default scroll range 0-100 */
5040 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5041 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5043 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5046 case EM_LINESCROLL16
:
5047 TRACE("EM_LINESCROLL16 %d\n", pos
);
5052 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5057 EDIT_EM_LineScroll(es
, 0, dy
);
5061 /*********************************************************************
5066 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5068 if (es
->flags
& EF_UPDATE
) {
5069 es
->flags
&= ~EF_UPDATE
;
5070 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
5072 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5076 /*********************************************************************
5081 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5083 if (es
->flags
& EF_UPDATE
) {
5084 es
->flags
&= ~EF_UPDATE
;
5085 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
5087 InvalidateRect(es
->hwndSelf
, rc
, bErase
);