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
45 * -!ES_AUTOVSCROLL (every multi line control *is* auto vscroll)
46 * -!ES_AUTOHSCROLL (every single line control *is* auto hscroll)
48 * When there is no autoscrolling, the control should first check whether
49 * the new text would fit. If not, an EN_MAXTEXT should be sent.
50 * However, currently this would require the actual change to be made,
51 * then call EDIT_BuildLineDefs() and then find out that the new text doesn't
52 * fit. After all this, things should be put back in the state before the
53 * changes. Note that for multi line controls !ES_AUTOHSCROLL works : wordwrap.
68 #include "wine/winbase16.h"
69 #include "wine/winuser16.h"
70 #include "wine/unicode.h"
75 #include "wine/debug.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
78 WINE_DECLARE_DEBUG_CHANNEL(combo
);
79 WINE_DECLARE_DEBUG_CHANNEL(relay
);
81 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
82 FIXME: BTW, new specs say 65535 (do you dare ???) */
83 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
84 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
85 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
86 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
89 * extra flags for EDITSTATE.flags field
91 #define EF_MODIFIED 0x0001 /* text has been modified */
92 #define EF_FOCUSED 0x0002 /* we have input focus */
93 #define EF_UPDATE 0x0004 /* notify parent of changed state */
94 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
95 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
96 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
97 wrapped line, instead of in front of the next character */
98 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
102 END_0
= 0, /* line ends with terminating '\0' character */
103 END_WRAP
, /* line is wrapped */
104 END_HARD
, /* line ends with a hard return '\r\n' */
105 END_SOFT
, /* line ends with a soft return '\r\r\n' */
106 END_RICH
/* line ends with a single '\n' */
109 typedef struct tagLINEDEF
{
110 INT length
; /* bruto length of a line in bytes */
111 INT net_length
; /* netto length of a line in visible characters */
113 INT width
; /* width of the line in pixels */
114 INT index
; /* line index into the buffer */
115 struct tagLINEDEF
*next
;
120 BOOL is_unicode
; /* how the control was created */
121 LPWSTR text
; /* the actual contents of the control */
122 UINT buffer_size
; /* the size of the buffer in characters */
123 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
124 HFONT font
; /* NULL means standard system font */
125 INT x_offset
; /* scroll offset for multi lines this is in pixels
126 for single lines it's in characters */
127 INT line_height
; /* height of a screen line in pixels */
128 INT char_width
; /* average character width in pixels */
129 DWORD style
; /* sane version of wnd->dwStyle */
130 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
131 INT undo_insert_count
; /* number of characters inserted in sequence */
132 UINT undo_position
; /* character index of the insertion and deletion */
133 LPWSTR undo_text
; /* deleted text */
134 UINT undo_buffer_size
; /* size of the deleted text buffer */
135 INT selection_start
; /* == selection_end if no selection */
136 INT selection_end
; /* == current caret position */
137 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
138 INT left_margin
; /* in pixels */
139 INT right_margin
; /* in pixels */
141 INT text_width
; /* width of the widest line in pixels for multi line controls
142 and just line width for single line controls */
143 INT region_posx
; /* Position of cursor relative to region: */
144 INT region_posy
; /* -1: to left, 0: within, 1: to right */
145 EDITWORDBREAKPROC16 word_break_proc16
;
146 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
147 INT line_count
; /* number of lines */
148 INT y_offset
; /* scroll offset in number of lines */
149 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
150 BOOL bEnableState
; /* flag keeping the enable state */
151 HWND hwndSelf
; /* the our window handle */
152 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
153 Even if parent will change, EN_* messages
154 should be sent to the first parent. */
155 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
157 * only for multi line controls
159 INT lock_count
; /* amount of re-entries in the EditWndProc */
162 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
163 HLOCAL hloc32W
; /* our unicode local memory block */
164 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
166 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
171 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
172 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
174 /* used for disabled or read-only edit control */
175 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
177 { /* Notify parent which has created this edit control */ \
178 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
179 SendMessageW(es->hwndParent, WM_COMMAND, \
180 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
181 (LPARAM)(es->hwndSelf)); \
184 /*********************************************************************
191 * These functions have trivial implementations
192 * We still like to call them internally
193 * "static inline" makes them more like macro's
195 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
196 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
197 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
198 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
201 * Helper functions only valid for one type of control
203 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
204 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
205 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
206 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
207 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
208 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
209 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
211 * Helper functions valid for both single line _and_ multi line controls
213 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
214 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
215 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
216 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
217 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
218 static void EDIT_LockBuffer(EDITSTATE
*es
);
219 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
220 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
221 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
222 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
223 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
224 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
225 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
226 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
227 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
228 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
229 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
230 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
231 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
232 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
233 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
235 * EM_XXX message handlers
237 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
238 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
239 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
240 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
241 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
242 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
243 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
244 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
245 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
246 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
247 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
248 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
249 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
250 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
251 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
252 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
253 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
254 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
255 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
256 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
257 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
258 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
259 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
260 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
261 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
262 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
263 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
265 * WM_XXX message handlers
267 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
268 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
269 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
270 static void EDIT_WM_Copy(EDITSTATE
*es
);
271 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
272 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
273 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
274 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
275 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
276 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
277 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
278 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
279 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
280 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
281 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
282 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
283 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
284 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
285 static void EDIT_WM_Paste(EDITSTATE
*es
);
286 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
287 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
288 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
289 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
290 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
291 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
292 static void EDIT_WM_Timer(EDITSTATE
*es
);
293 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
294 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
295 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
297 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
298 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
300 /*********************************************************************
301 * edit class descriptor
303 const struct builtin_class_descr EDIT_builtin_class
=
306 CS_DBLCLKS
| CS_PARENTDC
, /* style */
307 EditWndProcA
, /* procA */
308 EditWndProcW
, /* procW */
309 sizeof(EDITSTATE
*), /* extra */
310 IDC_IBEAM
, /* cursor */
315 /*********************************************************************
320 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
322 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
326 /*********************************************************************
331 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
333 es
->undo_insert_count
= 0;
334 *es
->undo_text
= '\0';
338 /*********************************************************************
343 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
345 static const WCHAR empty_stringW
[] = {0};
347 /* Protect read-only edit control from modification */
348 if(es
->style
& ES_READONLY
)
351 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
355 /*********************************************************************
360 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
367 /**********************************************************************
370 * Returns the window version in case Wine emulates a later version
371 * of windows than the application expects.
373 * In a number of cases when windows runs an application that was
374 * designed for an earlier windows version, windows reverts
375 * to "old" behaviour of that earlier version.
377 * An example is a disabled edit control that needs to be painted.
378 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
379 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
380 * applications with an expected version 0f 4.0 or higher.
383 static DWORD
get_app_version(void)
385 static DWORD version
;
388 DWORD dwEmulatedVersion
;
390 DWORD dwProcVersion
= GetProcessVersion(0);
392 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
393 GetVersionExW( &info
);
394 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
395 /* FIXME: this may not be 100% correct; see discussion on the
396 * wine developer list in Nov 1999 */
397 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
403 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
407 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
408 msg
= WM_CTLCOLORSTATIC
;
410 msg
= WM_CTLCOLOREDIT
;
412 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
413 return (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
416 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
419 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
421 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
424 /*********************************************************************
428 * The messages are in the order of the actual integer values
429 * (which can be found in include/windows.h)
430 * Wherever possible the 16 bit versions are converted to
431 * the 32 bit ones, so that we can 'fall through' to the
432 * helper functions. These are mostly 32 bit (with a few
433 * exceptions, clearly indicated by a '16' extension to their
437 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
438 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
440 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongW( hwnd
, 0 );
443 TRACE("hwnd=%p msg=%x (%s) wparam=%x lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
445 if (!es
&& msg
!= WM_NCCREATE
)
446 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
447 else if (msg
== WM_NCCREATE
)
448 return EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
449 else if (msg
== WM_DESTROY
)
450 return EDIT_WM_Destroy(es
);
453 if (es
) EDIT_LockBuffer(es
);
461 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
465 if ((short)LOWORD(lParam
) == -1)
466 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
468 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
470 EDIT_EM_ScrollCaret(es
);
474 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
475 EDIT_EM_ScrollCaret(es
);
482 RECT16
*r16
= MapSL(lParam
);
483 r16
->left
= es
->format_rect
.left
;
484 r16
->top
= es
->format_rect
.top
;
485 r16
->right
= es
->format_rect
.right
;
486 r16
->bottom
= es
->format_rect
.bottom
;
491 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
495 if ((es
->style
& ES_MULTILINE
) && lParam
) {
497 RECT16
*r16
= MapSL(lParam
);
500 rc
.right
= r16
->right
;
501 rc
.bottom
= r16
->bottom
;
502 EDIT_SetRectNP(es
, &rc
);
503 EDIT_UpdateText(es
, NULL
, TRUE
);
507 if ((es
->style
& ES_MULTILINE
) && lParam
) {
508 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
509 EDIT_UpdateText(es
, NULL
, TRUE
);
514 if ((es
->style
& ES_MULTILINE
) && lParam
) {
516 RECT16
*r16
= MapSL(lParam
);
519 rc
.right
= r16
->right
;
520 rc
.bottom
= r16
->bottom
;
521 EDIT_SetRectNP(es
, &rc
);
525 if ((es
->style
& ES_MULTILINE
) && lParam
)
526 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
531 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
534 case EM_LINESCROLL16
:
535 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
536 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
539 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
542 case EM_SCROLLCARET16
:
544 EDIT_EM_ScrollCaret(es
);
550 result
= ((es
->flags
& EF_MODIFIED
) != 0);
556 es
->flags
|= EF_MODIFIED
;
558 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
561 case EM_GETLINECOUNT16
:
562 case EM_GETLINECOUNT
:
563 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
567 if ((INT16
)wParam
== -1)
571 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
575 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
578 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
582 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
585 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
590 result
= EDIT_EM_GetThumb(es
);
593 /* these messages missing from specs */
602 FIXME("undocumented message 0x%x, please report\n", msg
);
603 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
606 case EM_LINELENGTH16
:
608 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
611 case EM_REPLACESEL16
:
612 lParam
= (LPARAM
)MapSL(lParam
);
613 unicode
= FALSE
; /* 16-bit message is always ascii */
620 textW
= (LPWSTR
)lParam
;
623 LPSTR textA
= (LPSTR
)lParam
;
624 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
625 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
626 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
629 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
633 HeapFree(GetProcessHeap(), 0, textW
);
638 lParam
= (LPARAM
)MapSL(lParam
);
639 unicode
= FALSE
; /* 16-bit message is always ascii */
642 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
646 case EM_SETLIMITTEXT
:
647 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
652 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
658 result
= (LRESULT
)EDIT_EM_Undo(es
);
663 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
666 case EM_LINEFROMCHAR16
:
667 case EM_LINEFROMCHAR
:
668 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
671 case EM_SETTABSTOPS16
:
672 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
675 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
678 case EM_SETPASSWORDCHAR16
:
679 unicode
= FALSE
; /* 16-bit message is always ascii */
681 case EM_SETPASSWORDCHAR
:
686 charW
= (WCHAR
)wParam
;
690 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
693 EDIT_EM_SetPasswordChar(es
, charW
);
697 case EM_EMPTYUNDOBUFFER16
:
698 case EM_EMPTYUNDOBUFFER
:
699 EDIT_EM_EmptyUndoBuffer(es
);
702 case EM_GETFIRSTVISIBLELINE16
:
703 result
= es
->y_offset
;
705 case EM_GETFIRSTVISIBLELINE
:
706 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
709 case EM_SETREADONLY16
:
712 SetWindowLongW( hwnd
, GWL_STYLE
,
713 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
714 es
->style
|= ES_READONLY
;
716 SetWindowLongW( hwnd
, GWL_STYLE
,
717 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
718 es
->style
&= ~ES_READONLY
;
723 case EM_SETWORDBREAKPROC16
:
724 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
726 case EM_SETWORDBREAKPROC
:
727 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
730 case EM_GETWORDBREAKPROC16
:
731 result
= (LRESULT
)es
->word_break_proc16
;
733 case EM_GETWORDBREAKPROC
:
734 result
= (LRESULT
)es
->word_break_proc
;
737 case EM_GETPASSWORDCHAR16
:
738 unicode
= FALSE
; /* 16-bit message is always ascii */
740 case EM_GETPASSWORDCHAR
:
743 result
= es
->password_char
;
746 WCHAR charW
= es
->password_char
;
748 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
754 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
757 EDIT_EM_SetMargins(es
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
761 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
764 case EM_GETLIMITTEXT
:
765 result
= es
->buffer_limit
;
769 result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
773 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
776 /* End of the EM_ messages which were in numerical order; what order
777 * are these in? vaguely alphabetical?
781 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
783 if (es
->style
& ES_MULTILINE
)
785 result
|= DLGC_WANTALLKEYS
;
789 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
791 int vk
= (int)((LPMSG
)lParam
)->wParam
;
793 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
795 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
796 result
|= DLGC_WANTMESSAGE
;
807 strng
[0] = wParam
>> 8;
808 strng
[1] = wParam
& 0xff;
809 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
810 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
811 EDIT_WM_Char(es
, charW
);
824 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
827 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
829 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
830 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
833 EDIT_WM_Char(es
, charW
);
842 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
846 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
855 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
858 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
862 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
863 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
864 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
866 result
= EDIT_WM_Create(es
, nameW
);
868 HeapFree(GetProcessHeap(), 0, nameW
);
877 es
->bEnableState
= (BOOL
) wParam
;
878 EDIT_UpdateText(es
, NULL
, TRUE
);
882 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
886 result
= (LRESULT
)es
->font
;
890 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
893 case WM_GETTEXTLENGTH
:
894 if (unicode
) result
= strlenW(es
->text
);
895 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
896 NULL
, 0, NULL
, NULL
);
900 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
904 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
908 result
= EDIT_WM_KillFocus(es
);
911 case WM_LBUTTONDBLCLK
:
912 result
= EDIT_WM_LButtonDblClk(es
);
916 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
920 result
= EDIT_WM_LButtonUp(es
);
924 result
= EDIT_WM_MButtonDown(es
);
927 case WM_MOUSEACTIVATE
:
928 result
= MA_ACTIVATE
;
932 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
936 EDIT_WM_Paint(es
, (HDC
)wParam
);
944 EDIT_WM_SetFocus(es
);
948 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
952 /* FIXME: actually set an internal flag and behave accordingly */
956 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
961 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
964 case WM_STYLECHANGED
:
965 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
968 case WM_STYLECHANGING
:
969 result
= 0; /* See EDIT_WM_StyleChanged */
973 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
981 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
986 int gcWheelDelta
= 0;
987 UINT pulScrollLines
= 3;
988 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
990 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
991 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
994 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
995 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
997 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
998 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
999 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1004 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1008 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1010 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1015 /*********************************************************************
1017 * EditWndProcW (USER32.@)
1019 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1021 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1024 /*********************************************************************
1026 * EditWndProc (USER32.@)
1028 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1030 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1033 /*********************************************************************
1035 * EDIT_BuildLineDefs_ML
1037 * Build linked list of text lines.
1038 * Lines can end with '\0' (last line), a character (if it is wrapped),
1039 * a soft return '\r\r\n' or a hard return '\r\n'
1042 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1046 LPWSTR current_position
, cp
;
1048 LINEDEF
*current_line
;
1049 LINEDEF
*previous_line
;
1050 LINEDEF
*start_line
;
1051 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1052 INT line_count
= es
->line_count
;
1053 INT orig_net_length
;
1056 if (istart
== iend
&& delta
== 0)
1059 dc
= GetDC(es
->hwndSelf
);
1061 old_font
= SelectObject(dc
, es
->font
);
1063 previous_line
= NULL
;
1064 current_line
= es
->first_line_def
;
1066 /* Find starting line. istart must lie inside an existing line or
1067 * at the end of buffer */
1069 if (istart
< current_line
->index
+ current_line
->length
||
1070 current_line
->ending
== END_0
)
1073 previous_line
= current_line
;
1074 current_line
= current_line
->next
;
1076 } while (current_line
);
1078 if (!current_line
) /* Error occurred start is not inside previous buffer */
1080 FIXME(" modification occurred outside buffer\n");
1081 ReleaseDC(es
->hwndSelf
, dc
);
1085 /* Remember start of modifications in order to calculate update region */
1086 nstart_line
= line_index
;
1087 nstart_index
= current_line
->index
;
1089 /* We must start to reformat from the previous line since the modifications
1090 * may have caused the line to wrap upwards. */
1091 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1094 current_line
= previous_line
;
1096 start_line
= current_line
;
1098 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1099 current_position
= es
->text
+ current_line
->index
;
1101 if (current_line
!= start_line
)
1103 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1105 /* The buffer has been expanded, create a new line and
1106 insert it into the link list */
1107 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1108 new_line
->next
= previous_line
->next
;
1109 previous_line
->next
= new_line
;
1110 current_line
= new_line
;
1113 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1115 /* The previous line merged with this line so we delete this extra entry */
1116 previous_line
->next
= current_line
->next
;
1117 HeapFree(GetProcessHeap(), 0, current_line
);
1118 current_line
= previous_line
->next
;
1122 else /* current_line->index + delta == current_position */
1124 if (current_position
- es
->text
> iend
)
1125 break; /* We reached end of line modifications */
1126 /* else recalulate this line */
1130 current_line
->index
= current_position
- es
->text
;
1131 orig_net_length
= current_line
->net_length
;
1133 /* Find end of line */
1134 cp
= current_position
;
1136 if (*cp
== '\n') break;
1137 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1142 /* Mark type of line termination */
1144 current_line
->ending
= END_0
;
1145 current_line
->net_length
= strlenW(current_position
);
1146 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1147 current_line
->ending
= END_SOFT
;
1148 current_line
->net_length
= cp
- current_position
- 1;
1149 } else if (*cp
== '\n') {
1150 current_line
->ending
= END_RICH
;
1151 current_line
->net_length
= cp
- current_position
;
1153 current_line
->ending
= END_HARD
;
1154 current_line
->net_length
= cp
- current_position
;
1157 /* Calculate line width */
1158 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1159 current_position
, current_line
->net_length
,
1160 es
->tabs_count
, es
->tabs
));
1162 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1163 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1164 if (current_line
->width
> fw
) {
1169 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1170 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1171 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1172 current_position
, next
, es
->tabs_count
, es
->tabs
));
1173 } while (current_line
->width
<= fw
);
1174 if (!prev
) { /* Didn't find a line break so force a break */
1179 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1180 current_position
, next
, es
->tabs_count
, es
->tabs
));
1181 } while (current_line
->width
<= fw
);
1186 /* If the first line we are calculating, wrapped before istart, we must
1187 * adjust istart in order for this to be reflected in the update region. */
1188 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1189 istart
= current_line
->index
+ prev
;
1190 /* else if we are updating the previous line before the first line we
1191 * are re-calculating and it expanded */
1192 else if (current_line
== start_line
&&
1193 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1195 /* Line expanded due to an upwards line wrap so we must partially include
1196 * previous line in update region */
1197 nstart_line
= line_index
;
1198 nstart_index
= current_line
->index
;
1199 istart
= current_line
->index
+ orig_net_length
;
1202 current_line
->net_length
= prev
;
1203 current_line
->ending
= END_WRAP
;
1204 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1205 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1207 else if (orig_net_length
< current_line
->net_length
&&
1208 current_line
== start_line
&&
1209 current_line
->index
!= nstart_index
) {
1210 /* The previous line expanded but it's still not as wide as the client rect */
1211 /* The expansion is due to an upwards line wrap so we must partially include
1212 it in the update region */
1213 nstart_line
= line_index
;
1214 nstart_index
= current_line
->index
;
1215 istart
= current_line
->index
+ orig_net_length
;
1220 /* Adjust length to include line termination */
1221 switch (current_line
->ending
) {
1223 current_line
->length
= current_line
->net_length
+ 3;
1226 current_line
->length
= current_line
->net_length
+ 1;
1229 current_line
->length
= current_line
->net_length
+ 2;
1233 current_line
->length
= current_line
->net_length
;
1236 es
->text_width
= max(es
->text_width
, current_line
->width
);
1237 current_position
+= current_line
->length
;
1238 previous_line
= current_line
;
1239 current_line
= current_line
->next
;
1241 } while (previous_line
->ending
!= END_0
);
1243 /* Finish adjusting line indexes by delta or remove hanging lines */
1244 if (previous_line
->ending
== END_0
)
1246 LINEDEF
*pnext
= NULL
;
1248 previous_line
->next
= NULL
;
1249 while (current_line
)
1251 pnext
= current_line
->next
;
1252 HeapFree(GetProcessHeap(), 0, current_line
);
1253 current_line
= pnext
;
1259 while (current_line
)
1261 current_line
->index
+= delta
;
1262 current_line
= current_line
->next
;
1266 /* Calculate rest of modification rectangle */
1271 * We calculate two rectangles. One for the first line which may have
1272 * an indent with respect to the format rect. The other is a format-width
1273 * rectangle that spans the rest of the lines that changed or moved.
1275 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1276 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1277 rc
.bottom
= rc
.top
+ es
->line_height
;
1278 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1279 es
->text
+ nstart_index
, istart
- nstart_index
,
1280 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1281 rc
.right
= es
->format_rect
.right
;
1282 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1285 rc
.left
= es
->format_rect
.left
;
1286 rc
.right
= es
->format_rect
.right
;
1288 * If lines were added or removed we must re-paint the remainder of the
1289 * lines since the remaining lines were either shifted up or down.
1291 if (line_count
< es
->line_count
) /* We added lines */
1292 rc
.bottom
= es
->line_count
* es
->line_height
;
1293 else if (line_count
> es
->line_count
) /* We removed lines */
1294 rc
.bottom
= line_count
* es
->line_height
;
1296 rc
.bottom
= line_index
* es
->line_height
;
1297 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1298 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1299 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1300 DeleteObject(tmphrgn
);
1304 SelectObject(dc
, old_font
);
1306 ReleaseDC(es
->hwndSelf
, dc
);
1309 /*********************************************************************
1311 * EDIT_CalcLineWidth_SL
1314 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1316 es
->text_width
= (short)LOWORD(EDIT_EM_PosFromChar(es
, strlenW(es
->text
), FALSE
));
1319 /*********************************************************************
1321 * EDIT_CallWordBreakProc
1323 * Call appropriate WordBreakProc (internal or external).
1325 * Note: The "start" argument should always be an index referring
1326 * to es->text. The actual wordbreak proc might be
1327 * 16 bit, so we can't always pass any 32 bit LPSTR.
1328 * Hence we assume that es->text is the buffer that holds
1329 * the string under examination (we can decide this for ourselves).
1332 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1334 INT ret
, iWndsLocks
;
1336 /* To avoid any deadlocks, all the locks on the window structures
1337 must be suspended before the control is passed to the application */
1338 iWndsLocks
= WIN_SuspendWndsLock();
1340 if (es
->word_break_proc16
) {
1347 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1348 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1349 segptr
= K32WOWGlobalLock16(hglob16
);
1350 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1351 args
[4] = SELECTOROF(segptr
);
1352 args
[3] = OFFSETOF(segptr
);
1356 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1357 ret
= LOWORD(result
);
1358 GlobalUnlock16(hglob16
);
1359 GlobalFree16(hglob16
);
1361 else if (es
->word_break_proc
)
1365 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1367 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1368 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1369 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1373 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1377 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1378 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1379 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1380 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1381 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1382 ret
= wbpA(textA
, index
, countA
, action
);
1383 HeapFree(GetProcessHeap(), 0, textA
);
1387 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1389 WIN_RestoreWndsLock(iWndsLocks
);
1394 /*********************************************************************
1398 * Beware: This is not the function called on EM_CHARFROMPOS
1399 * The position _can_ be outside the formatting / client
1401 * The return value is only the character index
1404 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1410 if (es
->style
& ES_MULTILINE
) {
1411 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1413 LINEDEF
*line_def
= es
->first_line_def
;
1415 while ((line
> 0) && line_def
->next
) {
1416 line_index
+= line_def
->length
;
1417 line_def
= line_def
->next
;
1420 x
+= es
->x_offset
- es
->format_rect
.left
;
1421 if (x
>= line_def
->width
) {
1423 *after_wrap
= (line_def
->ending
== END_WRAP
);
1424 return line_index
+ line_def
->net_length
;
1428 *after_wrap
= FALSE
;
1431 dc
= GetDC(es
->hwndSelf
);
1433 old_font
= SelectObject(dc
, es
->font
);
1434 low
= line_index
+ 1;
1435 high
= line_index
+ line_def
->net_length
+ 1;
1436 while (low
< high
- 1)
1438 INT mid
= (low
+ high
) / 2;
1439 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1445 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1446 (line_def
->ending
== END_WRAP
));
1451 *after_wrap
= FALSE
;
1452 x
-= es
->format_rect
.left
;
1454 return es
->x_offset
;
1455 text
= EDIT_GetPasswordPointer_SL(es
);
1456 dc
= GetDC(es
->hwndSelf
);
1458 old_font
= SelectObject(dc
, es
->font
);
1462 INT high
= es
->x_offset
;
1463 while (low
< high
- 1)
1465 INT mid
= (low
+ high
) / 2;
1466 GetTextExtentPoint32W( dc
, text
+ mid
,
1467 es
->x_offset
- mid
, &size
);
1468 if (size
.cx
> -x
) low
= mid
;
1475 INT low
= es
->x_offset
;
1476 INT high
= strlenW(es
->text
) + 1;
1477 while (low
< high
- 1)
1479 INT mid
= (low
+ high
) / 2;
1480 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1481 mid
- es
->x_offset
, &size
);
1482 if (size
.cx
> x
) high
= mid
;
1487 if (es
->style
& ES_PASSWORD
)
1488 HeapFree(GetProcessHeap(), 0, text
);
1491 SelectObject(dc
, old_font
);
1492 ReleaseDC(es
->hwndSelf
, dc
);
1497 /*********************************************************************
1501 * adjusts the point to be within the formatting rectangle
1502 * (so CharFromPos returns the nearest _visible_ character)
1505 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1507 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1508 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1512 /*********************************************************************
1516 * Calculates the bounding rectangle for a line from a starting
1517 * column to an ending column.
1520 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1522 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1524 if (es
->style
& ES_MULTILINE
)
1525 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1527 rc
->top
= es
->format_rect
.top
;
1528 rc
->bottom
= rc
->top
+ es
->line_height
;
1529 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1530 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1534 /*********************************************************************
1536 * EDIT_GetPasswordPointer_SL
1538 * note: caller should free the (optionally) allocated buffer
1541 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1543 if (es
->style
& ES_PASSWORD
) {
1544 INT len
= strlenW(es
->text
);
1545 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1547 while(len
) text
[--len
] = es
->password_char
;
1554 /*********************************************************************
1558 * This acts as a LOCAL_Lock(), but it locks only once. This way
1559 * you can call it whenever you like, without unlocking.
1561 * Initially the edit control allocates a HLOCAL32 buffer
1562 * (32 bit linear memory handler). However, 16 bit application
1563 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1564 * handler). From that moment on we have to keep using this 16 bit memory
1565 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1566 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1570 static void EDIT_LockBuffer(EDITSTATE
*es
)
1572 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1576 BOOL _16bit
= FALSE
;
1582 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1583 textA
= LocalLock(es
->hloc32A
);
1584 countA
= strlen(textA
) + 1;
1588 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1589 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1590 countA
= strlen(textA
) + 1;
1595 ERR("no buffer ... please report\n");
1602 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1603 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1604 if(countW_new
> es
->buffer_size
+ 1)
1606 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1607 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1608 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1611 es
->hloc32W
= hloc32W_new
;
1612 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1613 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1616 WARN("FAILED! Will synchronize partially\n");
1620 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1621 es
->text
= LocalLock(es
->hloc32W
);
1625 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1627 LOCAL_Unlock(hInstance
, es
->hloc16
);
1629 LocalUnlock(es
->hloc32A
);
1636 /*********************************************************************
1638 * EDIT_SL_InvalidateText
1640 * Called from EDIT_InvalidateText().
1641 * Does the job for single-line controls only.
1644 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1649 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1650 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1651 EDIT_UpdateText(es
, &rc
, TRUE
);
1655 /*********************************************************************
1657 * EDIT_ML_InvalidateText
1659 * Called from EDIT_InvalidateText().
1660 * Does the job for multi-line controls only.
1663 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1665 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1666 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1667 INT el
= EDIT_EM_LineFromChar(es
, end
);
1676 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1679 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1680 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1681 if (sl
< es
->y_offset
) {
1685 if (el
> es
->y_offset
+ vlc
) {
1686 el
= es
->y_offset
+ vlc
;
1687 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1689 GetClientRect(es
->hwndSelf
, &rc1
);
1690 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1692 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1693 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1694 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1696 EDIT_GetLineRect(es
, sl
, sc
,
1697 EDIT_EM_LineLength(es
,
1698 EDIT_EM_LineIndex(es
, sl
)),
1700 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1701 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1702 for (l
= sl
+ 1 ; l
< el
; l
++) {
1703 EDIT_GetLineRect(es
, l
, 0,
1704 EDIT_EM_LineLength(es
,
1705 EDIT_EM_LineIndex(es
, l
)),
1707 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1708 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1710 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1711 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1712 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1717 /*********************************************************************
1719 * EDIT_InvalidateText
1721 * Invalidate the text from offset start upto, but not including,
1722 * offset end. Useful for (re)painting the selection.
1723 * Regions outside the linewidth are not invalidated.
1724 * end == -1 means end == TextLength.
1725 * start and end need not be ordered.
1728 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1734 end
= strlenW(es
->text
);
1742 if (es
->style
& ES_MULTILINE
)
1743 EDIT_ML_InvalidateText(es
, start
, end
);
1745 EDIT_SL_InvalidateText(es
, start
, end
);
1749 /*********************************************************************
1753 * Try to fit size + 1 characters in the buffer.
1755 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1759 if (size
<= es
->buffer_size
)
1762 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1764 /* Force edit to unlock it's buffer. es->text now NULL */
1765 EDIT_UnlockBuffer(es
, TRUE
);
1768 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1769 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1770 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1771 es
->hloc32W
= hNew32W
;
1772 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1776 EDIT_LockBuffer(es
);
1778 if (es
->buffer_size
< size
) {
1779 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1780 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1783 TRACE("We now have %d+1\n", es
->buffer_size
);
1789 /*********************************************************************
1793 * Try to fit size + 1 bytes in the undo buffer.
1796 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1800 if (size
<= es
->undo_buffer_size
)
1803 TRACE("trying to ReAlloc to %d+1\n", size
);
1805 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1806 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1807 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1812 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1818 /*********************************************************************
1823 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1825 INT e
= es
->selection_end
;
1829 if ((es
->style
& ES_MULTILINE
) && e
&&
1830 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1832 if (e
&& (es
->text
[e
- 1] == '\r'))
1836 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1837 EDIT_EM_ScrollCaret(es
);
1841 /*********************************************************************
1845 * Only for multi line controls
1846 * Move the caret one line down, on a column with the nearest
1847 * x coordinate on the screen (might be a different column).
1850 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1852 INT s
= es
->selection_start
;
1853 INT e
= es
->selection_end
;
1854 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1855 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1856 INT x
= (short)LOWORD(pos
);
1857 INT y
= (short)HIWORD(pos
);
1859 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1862 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1863 EDIT_EM_ScrollCaret(es
);
1867 /*********************************************************************
1872 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1874 BOOL after_wrap
= FALSE
;
1877 /* Pass a high value in x to make sure of receiving the end of the line */
1878 if (es
->style
& ES_MULTILINE
)
1879 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1880 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1882 e
= strlenW(es
->text
);
1883 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1884 EDIT_EM_ScrollCaret(es
);
1888 /*********************************************************************
1893 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1895 INT e
= es
->selection_end
;
1899 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1900 if (es
->text
[e
] == '\n')
1902 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1906 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1907 EDIT_EM_ScrollCaret(es
);
1911 /*********************************************************************
1915 * Home key: move to beginning of line.
1918 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1922 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1923 if (es
->style
& ES_MULTILINE
)
1924 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1925 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1928 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1929 EDIT_EM_ScrollCaret(es
);
1933 /*********************************************************************
1935 * EDIT_MovePageDown_ML
1937 * Only for multi line controls
1938 * Move the caret one page down, on a column with the nearest
1939 * x coordinate on the screen (might be a different column).
1942 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1944 INT s
= es
->selection_start
;
1945 INT e
= es
->selection_end
;
1946 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1947 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1948 INT x
= (short)LOWORD(pos
);
1949 INT y
= (short)HIWORD(pos
);
1951 e
= EDIT_CharFromPos(es
, x
,
1952 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1956 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1957 EDIT_EM_ScrollCaret(es
);
1961 /*********************************************************************
1963 * EDIT_MovePageUp_ML
1965 * Only for multi line controls
1966 * Move the caret one page up, on a column with the nearest
1967 * x coordinate on the screen (might be a different column).
1970 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1972 INT s
= es
->selection_start
;
1973 INT e
= es
->selection_end
;
1974 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1975 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1976 INT x
= (short)LOWORD(pos
);
1977 INT y
= (short)HIWORD(pos
);
1979 e
= EDIT_CharFromPos(es
, x
,
1980 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1984 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1985 EDIT_EM_ScrollCaret(es
);
1989 /*********************************************************************
1993 * Only for multi line controls
1994 * Move the caret one line up, on a column with the nearest
1995 * x coordinate on the screen (might be a different column).
1998 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2000 INT s
= es
->selection_start
;
2001 INT e
= es
->selection_end
;
2002 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2003 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2004 INT x
= (short)LOWORD(pos
);
2005 INT y
= (short)HIWORD(pos
);
2007 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2010 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2011 EDIT_EM_ScrollCaret(es
);
2015 /*********************************************************************
2017 * EDIT_MoveWordBackward
2020 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2022 INT s
= es
->selection_start
;
2023 INT e
= es
->selection_end
;
2028 l
= EDIT_EM_LineFromChar(es
, e
);
2029 ll
= EDIT_EM_LineLength(es
, e
);
2030 li
= EDIT_EM_LineIndex(es
, l
);
2033 li
= EDIT_EM_LineIndex(es
, l
- 1);
2034 e
= li
+ EDIT_EM_LineLength(es
, li
);
2037 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2038 li
, e
- li
, ll
, WB_LEFT
);
2042 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2043 EDIT_EM_ScrollCaret(es
);
2047 /*********************************************************************
2049 * EDIT_MoveWordForward
2052 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2054 INT s
= es
->selection_start
;
2055 INT e
= es
->selection_end
;
2060 l
= EDIT_EM_LineFromChar(es
, e
);
2061 ll
= EDIT_EM_LineLength(es
, e
);
2062 li
= EDIT_EM_LineIndex(es
, l
);
2064 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2065 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2067 e
= li
+ EDIT_CallWordBreakProc(es
,
2068 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2072 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2073 EDIT_EM_ScrollCaret(es
);
2077 /*********************************************************************
2082 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2084 INT s
= es
->selection_start
;
2085 INT e
= es
->selection_end
;
2092 if (es
->style
& ES_MULTILINE
) {
2093 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2094 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2099 TRACE("line=%d\n", line
);
2101 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2102 x
= (short)LOWORD(pos
);
2103 y
= (short)HIWORD(pos
);
2104 li
= EDIT_EM_LineIndex(es
, line
);
2105 ll
= EDIT_EM_LineLength(es
, li
);
2106 s
= min(es
->selection_start
, es
->selection_end
);
2107 e
= max(es
->selection_start
, es
->selection_end
);
2108 s
= min(li
+ ll
, max(li
, s
));
2109 e
= min(li
+ ll
, max(li
, e
));
2110 if (rev
&& (s
!= e
) &&
2111 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2112 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2113 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2114 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2116 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2120 /*********************************************************************
2125 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2136 BkMode
= GetBkMode(dc
);
2137 BkColor
= GetBkColor(dc
);
2138 TextColor
= GetTextColor(dc
);
2140 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2141 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2142 SetBkMode( dc
, OPAQUE
);
2144 li
= EDIT_EM_LineIndex(es
, line
);
2145 if (es
->style
& ES_MULTILINE
) {
2146 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2147 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2149 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2150 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2151 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2153 if (es
->style
& ES_PASSWORD
)
2154 HeapFree(GetProcessHeap(), 0, text
);
2157 SetBkColor(dc
, BkColor
);
2158 SetTextColor(dc
, TextColor
);
2159 SetBkMode( dc
, BkMode
);
2165 /*********************************************************************
2170 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2173 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2174 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2175 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2179 /*********************************************************************
2183 * note: this is not (exactly) the handler called on EM_SETRECTNP
2184 * it is also used to set the rect of a single line control
2187 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2189 CopyRect(&es
->format_rect
, rc
);
2190 if (es
->style
& WS_BORDER
) {
2191 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2192 es
->format_rect
.left
+= bw
;
2193 es
->format_rect
.top
+= bw
;
2194 es
->format_rect
.right
-= bw
;
2195 es
->format_rect
.bottom
-= bw
;
2197 es
->format_rect
.left
+= es
->left_margin
;
2198 es
->format_rect
.right
-= es
->right_margin
;
2199 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2200 if (es
->style
& ES_MULTILINE
)
2202 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2204 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2205 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2207 /* correct es->x_offset */
2208 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2209 max_x_offset
= es
->text_width
- fw
;
2210 if(max_x_offset
< 0) max_x_offset
= 0;
2211 if(es
->x_offset
> max_x_offset
)
2212 es
->x_offset
= max_x_offset
;
2214 /* correct es->y_offset */
2215 max_y_offset
= es
->line_count
- vlc
;
2216 if(max_y_offset
< 0) max_y_offset
= 0;
2217 if(es
->y_offset
> max_y_offset
)
2218 es
->y_offset
= max_y_offset
;
2220 /* force scroll info update */
2221 EDIT_UpdateScrollInfo(es
);
2224 /* Windows doesn't care to fix text placement for SL controls */
2225 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2227 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2228 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2232 /*********************************************************************
2237 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2239 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2241 /* Edit window might be already destroyed */
2242 if(!IsWindow(es
->hwndSelf
))
2244 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2248 if (!es
->lock_count
) {
2249 ERR("lock_count == 0 ... please report\n");
2253 ERR("es->text == 0 ... please report\n");
2257 if (force
|| (es
->lock_count
== 1)) {
2260 BOOL _16bit
= FALSE
;
2262 UINT countW
= strlenW(es
->text
) + 1;
2266 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2267 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2268 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2269 countA
= LocalSize(es
->hloc32A
);
2270 if(countA_new
> countA
)
2273 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2274 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2275 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2278 es
->hloc32A
= hloc32A_new
;
2279 countA
= LocalSize(hloc32A_new
);
2280 TRACE("Real new size %d bytes\n", countA
);
2283 WARN("FAILED! Will synchronize partially\n");
2285 textA
= LocalLock(es
->hloc32A
);
2289 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2290 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2291 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2292 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2293 if(countA_new
> countA
)
2295 HLOCAL16 hloc16_new
;
2296 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2297 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2298 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2301 es
->hloc16
= hloc16_new
;
2302 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2303 TRACE("Real new size %d bytes\n", countA
);
2306 WARN("FAILED! Will synchronize partially\n");
2308 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2314 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2316 LOCAL_Unlock(hInstance
, es
->hloc16
);
2318 LocalUnlock(es
->hloc32A
);
2321 LocalUnlock(es
->hloc32W
);
2325 ERR("no buffer ... please report\n");
2333 /*********************************************************************
2335 * EDIT_UpdateScrollInfo
2338 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2340 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2343 si
.cbSize
= sizeof(SCROLLINFO
);
2344 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2346 si
.nMax
= es
->line_count
- 1;
2347 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2348 si
.nPos
= es
->y_offset
;
2349 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2350 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2351 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2354 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2357 si
.cbSize
= sizeof(SCROLLINFO
);
2358 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2360 si
.nMax
= es
->text_width
- 1;
2361 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2362 si
.nPos
= es
->x_offset
;
2363 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2364 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2365 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2369 /*********************************************************************
2371 * EDIT_WordBreakProc
2373 * Find the beginning of words.
2374 * Note: unlike the specs for a WordBreakProc, this function only
2375 * allows to be called without linebreaks between s[0] upto
2376 * s[count - 1]. Remember it is only called
2377 * internally, so we can decide this for ourselves.
2380 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2384 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2394 if (s
[index
] == ' ') {
2395 while (index
&& (s
[index
] == ' '))
2398 while (index
&& (s
[index
] != ' '))
2400 if (s
[index
] == ' ')
2404 while (index
&& (s
[index
] != ' '))
2406 if (s
[index
] == ' ')
2416 if (s
[index
] == ' ')
2417 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2419 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2421 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2425 case WB_ISDELIMITER
:
2426 ret
= (s
[index
] == ' ');
2429 ERR("unknown action code, please report !\n");
2436 /*********************************************************************
2440 * returns line number (not index) in high-order word of result.
2441 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2442 * to Richedit, not to the edit control. Original documentation is valid.
2443 * FIXME: do the specs mean to return -1 if outside client area or
2444 * if outside formatting rectangle ???
2447 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2455 GetClientRect(es
->hwndSelf
, &rc
);
2456 if (!PtInRect(&rc
, pt
))
2459 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2460 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2464 /*********************************************************************
2468 * Enable or disable soft breaks.
2470 * This means: insert or remove the soft linebreak character (\r\r\n).
2471 * Take care to check if the text still fits the buffer after insertion.
2472 * If not, notify with EN_ERRSPACE.
2475 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2477 es
->flags
&= ~EF_USE_SOFTBRK
;
2479 es
->flags
|= EF_USE_SOFTBRK
;
2480 FIXME("soft break enabled, not implemented\n");
2486 /*********************************************************************
2490 * Hopefully this won't fire back at us.
2491 * We always start with a fixed buffer in the local heap.
2492 * Despite of the documentation says that the local heap is used
2493 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2494 * buffer on the local heap.
2497 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2501 if (!(es
->style
& ES_MULTILINE
))
2505 hLocal
= es
->hloc32W
;
2511 UINT countA
, alloc_size
;
2512 TRACE("Allocating 32-bit ANSI alias buffer\n");
2513 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2514 alloc_size
= ROUND_TO_GROW(countA
);
2515 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2517 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2520 textA
= LocalLock(es
->hloc32A
);
2521 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2522 LocalUnlock(es
->hloc32A
);
2524 hLocal
= es
->hloc32A
;
2527 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2532 /*********************************************************************
2536 * Hopefully this won't fire back at us.
2537 * We always start with a buffer in 32 bit linear memory.
2538 * However, with this message a 16 bit application requests
2539 * a handle of 16 bit local heap memory, where it expects to find
2541 * It's a pitty that from this moment on we have to use this
2542 * local heap, because applications may rely on the handle
2545 * In this function we'll try to switch to local heap.
2547 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2549 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2551 UINT countA
, alloc_size
;
2553 if (!(es
->style
& ES_MULTILINE
))
2559 if (!LOCAL_HeapSize(hInstance
)) {
2560 if (!LocalInit16(hInstance
, 0,
2561 GlobalSize16(hInstance
))) {
2562 ERR("could not initialize local heap\n");
2565 TRACE("local heap initialized\n");
2568 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2569 alloc_size
= ROUND_TO_GROW(countA
);
2571 TRACE("Allocating 16-bit ANSI alias buffer\n");
2572 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2573 ERR("could not allocate new 16 bit buffer\n");
2577 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2578 ERR("could not lock new 16 bit buffer\n");
2579 LOCAL_Free(hInstance
, es
->hloc16
);
2584 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2585 LOCAL_Unlock(hInstance
, es
->hloc16
);
2587 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2592 /*********************************************************************
2597 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2600 INT line_len
, dst_len
;
2603 if (es
->style
& ES_MULTILINE
) {
2604 if (line
>= es
->line_count
)
2608 i
= EDIT_EM_LineIndex(es
, line
);
2610 line_len
= EDIT_EM_LineLength(es
, i
);
2611 dst_len
= *(WORD
*)dst
;
2614 if(dst_len
<= line_len
)
2616 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2619 else /* Append 0 if enough space */
2621 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2628 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2629 if(!ret
) /* Insufficient buffer size */
2631 if(ret
< dst_len
) /* Append 0 if enough space */
2632 ((LPSTR
)dst
)[ret
] = 0;
2638 /*********************************************************************
2643 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2645 UINT s
= es
->selection_start
;
2646 UINT e
= es
->selection_end
;
2653 return MAKELONG(s
, e
);
2657 /*********************************************************************
2661 * FIXME: is this right ? (or should it be only VSCROLL)
2662 * (and maybe only for edit controls that really have their
2663 * own scrollbars) (and maybe only for multiline controls ?)
2664 * All in all: very poorly documented
2667 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2669 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2670 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2674 /*********************************************************************
2679 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2684 if (!(es
->style
& ES_MULTILINE
))
2686 if (index
> (INT
)strlenW(es
->text
))
2687 return es
->line_count
- 1;
2689 index
= min(es
->selection_start
, es
->selection_end
);
2692 line_def
= es
->first_line_def
;
2693 index
-= line_def
->length
;
2694 while ((index
>= 0) && line_def
->next
) {
2696 line_def
= line_def
->next
;
2697 index
-= line_def
->length
;
2703 /*********************************************************************
2708 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2713 if (!(es
->style
& ES_MULTILINE
))
2715 if (line
>= es
->line_count
)
2719 line_def
= es
->first_line_def
;
2721 INT index
= es
->selection_end
- line_def
->length
;
2722 while ((index
>= 0) && line_def
->next
) {
2723 line_index
+= line_def
->length
;
2724 line_def
= line_def
->next
;
2725 index
-= line_def
->length
;
2729 line_index
+= line_def
->length
;
2730 line_def
= line_def
->next
;
2738 /*********************************************************************
2743 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2747 if (!(es
->style
& ES_MULTILINE
))
2748 return strlenW(es
->text
);
2751 /* get the number of remaining non-selected chars of selected lines */
2752 INT32 l
; /* line number */
2753 INT32 li
; /* index of first char in line */
2755 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2756 /* # chars before start of selection area */
2757 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2758 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2759 /* # chars after end of selection */
2760 li
= EDIT_EM_LineIndex(es
, l
);
2761 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2764 line_def
= es
->first_line_def
;
2765 index
-= line_def
->length
;
2766 while ((index
>= 0) && line_def
->next
) {
2767 line_def
= line_def
->next
;
2768 index
-= line_def
->length
;
2770 return line_def
->net_length
;
2774 /*********************************************************************
2778 * NOTE: dx is in average character widths, dy - in lines;
2781 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2783 if (!(es
->style
& ES_MULTILINE
))
2786 dx
*= es
->char_width
;
2787 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2790 /*********************************************************************
2792 * EDIT_EM_LineScroll_internal
2794 * Version of EDIT_EM_LineScroll for internal use.
2795 * It doesn't refuse if ES_MULTILINE is set and assumes that
2796 * dx is in pixels, dy - in lines.
2799 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2802 INT x_offset_in_pixels
;
2803 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
2806 if (es
->style
& ES_MULTILINE
)
2808 x_offset_in_pixels
= es
->x_offset
;
2813 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2816 if (-dx
> x_offset_in_pixels
)
2817 dx
= -x_offset_in_pixels
;
2818 if (dx
> es
->text_width
- x_offset_in_pixels
)
2819 dx
= es
->text_width
- x_offset_in_pixels
;
2820 nyoff
= max(0, es
->y_offset
+ dy
);
2821 if (nyoff
>= es
->line_count
- lines_per_page
)
2822 nyoff
= es
->line_count
- lines_per_page
;
2823 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2828 es
->y_offset
= nyoff
;
2829 if(es
->style
& ES_MULTILINE
)
2832 es
->x_offset
+= dx
/ es
->char_width
;
2834 GetClientRect(es
->hwndSelf
, &rc1
);
2835 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2836 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2837 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2838 /* force scroll info update */
2839 EDIT_UpdateScrollInfo(es
);
2841 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2842 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2843 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2844 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2849 /*********************************************************************
2854 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2856 INT len
= strlenW(es
->text
);
2865 index
= min(index
, len
);
2866 dc
= GetDC(es
->hwndSelf
);
2868 old_font
= SelectObject(dc
, es
->font
);
2869 if (es
->style
& ES_MULTILINE
) {
2870 l
= EDIT_EM_LineFromChar(es
, index
);
2871 y
= (l
- es
->y_offset
) * es
->line_height
;
2872 li
= EDIT_EM_LineIndex(es
, l
);
2873 if (after_wrap
&& (li
== index
) && l
) {
2875 LINEDEF
*line_def
= es
->first_line_def
;
2877 line_def
= line_def
->next
;
2880 if (line_def
->ending
== END_WRAP
) {
2882 y
-= es
->line_height
;
2883 li
= EDIT_EM_LineIndex(es
, l
);
2886 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2887 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2889 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2890 if (index
< es
->x_offset
) {
2891 GetTextExtentPoint32W(dc
, text
+ index
,
2892 es
->x_offset
- index
, &size
);
2895 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2896 index
- es
->x_offset
, &size
);
2900 if (es
->style
& ES_PASSWORD
)
2901 HeapFree(GetProcessHeap(), 0, text
);
2903 x
+= es
->format_rect
.left
;
2904 y
+= es
->format_rect
.top
;
2906 SelectObject(dc
, old_font
);
2907 ReleaseDC(es
->hwndSelf
, dc
);
2908 return MAKELONG((INT16
)x
, (INT16
)y
);
2912 /*********************************************************************
2916 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2919 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2921 UINT strl
= strlenW(lpsz_replace
);
2922 UINT tl
= strlenW(es
->text
);
2931 TRACE("%s, can_undo %d, send_update %d\n",
2932 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2934 s
= es
->selection_start
;
2935 e
= es
->selection_end
;
2937 if ((s
== e
) && !strl
)
2942 /* Issue the EN_MAXTEXT notification and continue with replacing text
2943 * such that buffer limit is honored. */
2944 size
= tl
- (e
- s
) + strl
;
2945 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
2946 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
2947 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2950 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2954 /* there is something to be deleted */
2955 TRACE("deleting stuff.\n");
2957 utl
= strlenW(es
->undo_text
);
2958 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2959 /* undo-buffer is extended to the right */
2960 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2961 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2962 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2963 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2964 /* undo-buffer is extended to the left */
2965 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2966 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2968 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2969 p
[i
] = (es
->text
+ s
)[i
];
2970 es
->undo_position
= s
;
2972 /* new undo-buffer */
2973 EDIT_MakeUndoFit(es
, e
- s
);
2974 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2975 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2976 es
->undo_position
= s
;
2978 /* any deletion makes the old insertion-undo invalid */
2979 es
->undo_insert_count
= 0;
2981 EDIT_EM_EmptyUndoBuffer(es
);
2984 strcpyW(es
->text
+ s
, es
->text
+ e
);
2987 /* there is an insertion */
2989 if ((s
== es
->undo_position
) ||
2990 ((es
->undo_insert_count
) &&
2991 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2993 * insertion is new and at delete position or
2994 * an extension to either left or right
2996 es
->undo_insert_count
+= strl
;
2998 /* new insertion undo */
2999 es
->undo_position
= s
;
3000 es
->undo_insert_count
= strl
;
3001 /* new insertion makes old delete-buffer invalid */
3002 *es
->undo_text
= '\0';
3005 EDIT_EM_EmptyUndoBuffer(es
);
3008 tl
= strlenW(es
->text
);
3009 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
));
3010 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3012 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3013 p
[i
] = lpsz_replace
[i
];
3014 if(es
->style
& ES_UPPERCASE
)
3015 CharUpperBuffW(p
, strl
);
3016 else if(es
->style
& ES_LOWERCASE
)
3017 CharLowerBuffW(p
, strl
);
3020 if (es
->style
& ES_MULTILINE
)
3022 INT s
= min(es
->selection_start
, es
->selection_end
);
3024 hrgn
= CreateRectRgn(0, 0, 0, 0);
3025 EDIT_BuildLineDefs_ML(es
, s
, s
+ strl
,
3026 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3029 EDIT_CalcLineWidth_SL(es
);
3031 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3032 es
->flags
|= EF_MODIFIED
;
3033 if (send_update
) es
->flags
|= EF_UPDATE
;
3036 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3040 EDIT_UpdateText(es
, NULL
, TRUE
);
3042 EDIT_EM_ScrollCaret(es
);
3044 /* force scroll info update */
3045 EDIT_UpdateScrollInfo(es
);
3048 if(es
->flags
& EF_UPDATE
)
3050 es
->flags
&= ~EF_UPDATE
;
3051 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3056 /*********************************************************************
3061 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3065 if (!(es
->style
& ES_MULTILINE
))
3066 return (LRESULT
)FALSE
;
3076 if (es
->y_offset
< es
->line_count
- 1)
3081 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3084 if (es
->y_offset
< es
->line_count
- 1)
3085 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3088 return (LRESULT
)FALSE
;
3091 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3092 /* check if we are going to move too far */
3093 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3094 dy
= es
->line_count
- vlc
- es
->y_offset
;
3096 /* Notification is done in EDIT_EM_LineScroll */
3098 EDIT_EM_LineScroll(es
, 0, dy
);
3100 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3104 /*********************************************************************
3109 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3111 if (es
->style
& ES_MULTILINE
) {
3116 INT cw
= es
->char_width
;
3121 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3122 li
= EDIT_EM_LineIndex(es
, l
);
3123 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3124 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3125 if (l
>= es
->y_offset
+ vlc
)
3126 dy
= l
- vlc
+ 1 - es
->y_offset
;
3127 if (l
< es
->y_offset
)
3128 dy
= l
- es
->y_offset
;
3129 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3130 if (x
< es
->format_rect
.left
)
3131 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3132 if (x
> es
->format_rect
.right
)
3133 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3136 /* check if we are going to move too far */
3137 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3138 dx
= es
->text_width
- ww
- es
->x_offset
;
3140 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3147 if (!(es
->style
& ES_AUTOHSCROLL
))
3150 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3151 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3152 if (x
< es
->format_rect
.left
) {
3153 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3156 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3157 } while ((x
< goal
) && es
->x_offset
);
3158 /* FIXME: use ScrollWindow() somehow to improve performance */
3159 EDIT_UpdateText(es
, NULL
, TRUE
);
3160 } else if (x
> es
->format_rect
.right
) {
3162 INT len
= strlenW(es
->text
);
3163 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3166 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3167 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3168 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3169 /* FIXME: use ScrollWindow() somehow to improve performance */
3170 EDIT_UpdateText(es
, NULL
, TRUE
);
3174 if(es
->flags
& EF_FOCUSED
)
3175 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3179 /*********************************************************************
3183 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3186 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3188 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3190 if (!(es
->style
& ES_MULTILINE
))
3194 WARN("called with NULL handle\n");
3198 EDIT_UnlockBuffer(es
, TRUE
);
3202 LOCAL_Free(hInstance
, es
->hloc16
);
3203 es
->hloc16
= (HLOCAL16
)NULL
;
3210 LocalFree(es
->hloc32A
);
3222 countA
= LocalSize(hloc
);
3223 textA
= LocalLock(hloc
);
3224 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3225 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3227 ERR("Could not allocate new unicode buffer\n");
3230 textW
= LocalLock(hloc32W_new
);
3231 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3232 LocalUnlock(hloc32W_new
);
3236 LocalFree(es
->hloc32W
);
3238 es
->hloc32W
= hloc32W_new
;
3242 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3244 EDIT_LockBuffer(es
);
3246 es
->x_offset
= es
->y_offset
= 0;
3247 es
->selection_start
= es
->selection_end
= 0;
3248 EDIT_EM_EmptyUndoBuffer(es
);
3249 es
->flags
&= ~EF_MODIFIED
;
3250 es
->flags
&= ~EF_UPDATE
;
3251 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3252 EDIT_UpdateText(es
, NULL
, TRUE
);
3253 EDIT_EM_ScrollCaret(es
);
3254 /* force scroll info update */
3255 EDIT_UpdateScrollInfo(es
);
3259 /*********************************************************************
3263 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3266 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3268 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3274 if (!(es
->style
& ES_MULTILINE
))
3278 WARN("called with NULL handle\n");
3282 EDIT_UnlockBuffer(es
, TRUE
);
3286 LocalFree(es
->hloc32A
);
3290 countA
= LOCAL_Size(hInstance
, hloc
);
3291 textA
= LOCAL_Lock(hInstance
, hloc
);
3292 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3293 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3295 ERR("Could not allocate new unicode buffer\n");
3298 textW
= LocalLock(hloc32W_new
);
3299 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3300 LocalUnlock(hloc32W_new
);
3301 LOCAL_Unlock(hInstance
, hloc
);
3304 LocalFree(es
->hloc32W
);
3306 es
->hloc32W
= hloc32W_new
;
3309 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3311 EDIT_LockBuffer(es
);
3313 es
->x_offset
= es
->y_offset
= 0;
3314 es
->selection_start
= es
->selection_end
= 0;
3315 EDIT_EM_EmptyUndoBuffer(es
);
3316 es
->flags
&= ~EF_MODIFIED
;
3317 es
->flags
&= ~EF_UPDATE
;
3318 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3319 EDIT_UpdateText(es
, NULL
, TRUE
);
3320 EDIT_EM_ScrollCaret(es
);
3321 /* force scroll info update */
3322 EDIT_UpdateScrollInfo(es
);
3326 /*********************************************************************
3330 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3331 * However, the windows version is not complied to yet in all of edit.c
3333 * Additionally as the wrapper for RichEdit controls we need larger buffers
3334 * at present -1 will represent nolimit
3336 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3338 if (limit
== 0xFFFFFFFF)
3339 es
->buffer_limit
= -1;
3340 else if (es
->style
& ES_MULTILINE
) {
3342 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3344 es
->buffer_limit
= BUFLIMIT_MULTI
;
3347 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3349 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3354 /*********************************************************************
3358 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3359 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3360 * margin according to the textmetrics of the current font.
3362 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3363 * of the char's width as the margin, but this is not how Windows handles this.
3364 * For all other fonts Windows sets the margins to zero.
3367 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3368 INT left
, INT right
)
3371 INT default_left_margin
= 0; /* in pixels */
3372 INT default_right_margin
= 0; /* in pixels */
3374 /* Set the default margins depending on the font */
3375 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3376 HDC dc
= GetDC(es
->hwndSelf
);
3377 HFONT old_font
= SelectObject(dc
, es
->font
);
3378 GetTextMetricsW(dc
, &tm
);
3379 /* The default margins are only non zero for TrueType or Vector fonts */
3380 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3381 /* This must be calculated more exactly! But how? */
3382 default_left_margin
= tm
.tmAveCharWidth
/ 3;
3383 default_right_margin
= tm
.tmAveCharWidth
/ 3;
3385 SelectObject(dc
, old_font
);
3386 ReleaseDC(es
->hwndSelf
, dc
);
3389 if (action
& EC_LEFTMARGIN
) {
3390 if (left
!= EC_USEFONTINFO
)
3391 es
->left_margin
= left
;
3393 es
->left_margin
= default_left_margin
;
3396 if (action
& EC_RIGHTMARGIN
) {
3397 if (right
!= EC_USEFONTINFO
)
3398 es
->right_margin
= right
;
3400 es
->right_margin
= default_right_margin
;
3402 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3406 /*********************************************************************
3408 * EM_SETPASSWORDCHAR
3411 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3415 if (es
->style
& ES_MULTILINE
)
3418 if (es
->password_char
== c
)
3421 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3422 es
->password_char
= c
;
3424 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3425 es
->style
|= ES_PASSWORD
;
3427 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3428 es
->style
&= ~ES_PASSWORD
;
3430 EDIT_UpdateText(es
, NULL
, TRUE
);
3434 /*********************************************************************
3438 * note: unlike the specs say: the order of start and end
3439 * _is_ preserved in Windows. (i.e. start can be > end)
3440 * In other words: this handler is OK
3443 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3445 UINT old_start
= es
->selection_start
;
3446 UINT old_end
= es
->selection_end
;
3447 UINT len
= strlenW(es
->text
);
3449 if (start
== (UINT
)-1) {
3450 start
= es
->selection_end
;
3451 end
= es
->selection_end
;
3453 start
= min(start
, len
);
3454 end
= min(end
, len
);
3456 es
->selection_start
= start
;
3457 es
->selection_end
= end
;
3459 es
->flags
|= EF_AFTER_WRAP
;
3461 es
->flags
&= ~EF_AFTER_WRAP
;
3462 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3463 ORDER_UINT(start
, end
);
3464 ORDER_UINT(end
, old_end
);
3465 ORDER_UINT(start
, old_start
);
3466 ORDER_UINT(old_start
, old_end
);
3467 if (end
!= old_start
)
3471 * ORDER_UINT32(end, old_start);
3472 * EDIT_InvalidateText(es, start, end);
3473 * EDIT_InvalidateText(es, old_start, old_end);
3474 * in place of the following if statement.
3476 if (old_start
> end
)
3478 EDIT_InvalidateText(es
, start
, end
);
3479 EDIT_InvalidateText(es
, old_start
, old_end
);
3483 EDIT_InvalidateText(es
, start
, old_start
);
3484 EDIT_InvalidateText(es
, end
, old_end
);
3487 else EDIT_InvalidateText(es
, start
, old_end
);
3491 /*********************************************************************
3496 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3498 if (!(es
->style
& ES_MULTILINE
))
3501 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3502 es
->tabs_count
= count
;
3506 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3507 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3513 /*********************************************************************
3518 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3520 if (!(es
->style
& ES_MULTILINE
))
3523 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3524 es
->tabs_count
= count
;
3529 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3530 for (i
= 0 ; i
< count
; i
++)
3531 es
->tabs
[i
] = *tabs
++;
3537 /*********************************************************************
3539 * EM_SETWORDBREAKPROC
3542 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3544 if (es
->word_break_proc
== wbp
)
3547 es
->word_break_proc
= wbp
;
3548 es
->word_break_proc16
= NULL
;
3550 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3551 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3552 EDIT_UpdateText(es
, NULL
, TRUE
);
3557 /*********************************************************************
3559 * EM_SETWORDBREAKPROC16
3562 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3564 if (es
->word_break_proc16
== wbp
)
3567 es
->word_break_proc
= NULL
;
3568 es
->word_break_proc16
= wbp
;
3569 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3570 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3571 EDIT_UpdateText(es
, NULL
, TRUE
);
3576 /*********************************************************************
3581 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3586 /* As per MSDN spec, for a single-line edit control,
3587 the return value is always TRUE */
3588 if( es
->style
& ES_READONLY
)
3589 return !(es
->style
& ES_MULTILINE
);
3591 ulength
= strlenW(es
->undo_text
);
3593 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3595 strcpyW(utext
, es
->undo_text
);
3597 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3598 es
->undo_insert_count
, debugstr_w(utext
));
3600 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3601 EDIT_EM_EmptyUndoBuffer(es
);
3602 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3603 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3604 /* send the notification after the selection start and end are set */
3605 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3606 EDIT_EM_ScrollCaret(es
);
3607 HeapFree(GetProcessHeap(), 0, utext
);
3609 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3610 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3615 /*********************************************************************
3620 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3624 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3628 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3629 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3632 if (es
->style
& ES_MULTILINE
) {
3633 if (es
->style
& ES_READONLY
) {
3634 EDIT_MoveHome(es
, FALSE
);
3635 EDIT_MoveDown_ML(es
, FALSE
);
3637 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3638 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3643 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3645 static const WCHAR tabW
[] = {'\t',0};
3646 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3650 if (!(es
->style
& ES_READONLY
) && !control
) {
3651 if (es
->selection_start
!= es
->selection_end
)
3654 /* delete character left of caret */
3655 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3656 EDIT_MoveBackward(es
, TRUE
);
3662 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3665 if (!(es
->style
& ES_READONLY
))
3666 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3669 if (!(es
->style
& ES_READONLY
))
3670 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3674 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3675 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3678 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3682 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3689 /*********************************************************************
3694 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3696 if (code
|| control
)
3716 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3717 EDIT_EM_ScrollCaret(es
);
3720 ERR("unknown menu item, please report\n");
3726 /*********************************************************************
3730 * Note: the resource files resource/sysres_??.rc cannot define a
3731 * single popup menu. Hence we use a (dummy) menubar
3732 * containing the single popup menu as its first item.
3734 * FIXME: the message identifiers have been chosen arbitrarily,
3735 * hence we use MF_BYPOSITION.
3736 * We might as well use the "real" values (anybody knows ?)
3737 * The menu definition is in resources/sysres_??.rc.
3738 * Once these are OK, we better use MF_BYCOMMAND here
3739 * (as we do in EDIT_WM_Command()).
3742 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3744 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3745 HMENU popup
= GetSubMenu(menu
, 0);
3746 UINT start
= es
->selection_start
;
3747 UINT end
= es
->selection_end
;
3749 ORDER_UINT(start
, end
);
3752 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3754 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3756 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3758 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3760 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3762 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3764 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3769 /*********************************************************************
3774 static void EDIT_WM_Copy(EDITSTATE
*es
)
3776 INT s
= min(es
->selection_start
, es
->selection_end
);
3777 INT e
= max(es
->selection_start
, es
->selection_end
);
3783 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3784 dst
= GlobalLock(hdst
);
3785 strncpyW(dst
, es
->text
+ s
, e
- s
);
3786 dst
[e
- s
] = 0; /* ensure 0 termination */
3787 TRACE("%s\n", debugstr_w(dst
));
3789 OpenClipboard(es
->hwndSelf
);
3791 SetClipboardData(CF_UNICODETEXT
, hdst
);
3796 /*********************************************************************
3801 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3803 TRACE("%s\n", debugstr_w(name
));
3805 * To initialize some final structure members, we call some helper
3806 * functions. However, since the EDITSTATE is not consistent (i.e.
3807 * not fully initialized), we should be very careful which
3808 * functions can be called, and in what order.
3810 EDIT_WM_SetFont(es
, 0, FALSE
);
3811 EDIT_EM_EmptyUndoBuffer(es
);
3813 if (name
&& *name
) {
3814 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3815 /* if we insert text to the editline, the text scrolls out
3816 * of the window, as the caret is placed after the insert
3817 * pos normally; thus we reset es->selection... to 0 and
3820 es
->selection_start
= es
->selection_end
= 0;
3821 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3822 * Messages are only to be sent when the USER does something to
3823 * change the contents. So I am removing this EN_CHANGE
3825 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3827 EDIT_EM_ScrollCaret(es
);
3829 /* force scroll info update */
3830 EDIT_UpdateScrollInfo(es
);
3831 /* The rule seems to return 1 here for success */
3832 /* Power Builder masked edit controls will crash */
3834 /* FIXME: is that in all cases so ? */
3839 /*********************************************************************
3844 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
3849 while (LocalUnlock(es
->hloc32W
)) ;
3850 LocalFree(es
->hloc32W
);
3853 while (LocalUnlock(es
->hloc32A
)) ;
3854 LocalFree(es
->hloc32A
);
3857 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3858 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3859 LOCAL_Free(hInstance
, es
->hloc16
);
3862 pc
= es
->first_line_def
;
3866 HeapFree(GetProcessHeap(), 0, pc
);
3870 SetWindowLongW( es
->hwndSelf
, 0, 0 );
3871 HeapFree(GetProcessHeap(), 0, es
);
3877 /*********************************************************************
3882 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
3884 /* we do the proper erase in EDIT_WM_Paint */
3889 /*********************************************************************
3894 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3896 if(!count
) return 0;
3900 lstrcpynW(dst
, es
->text
, count
);
3901 return strlenW(dst
);
3905 LPSTR textA
= (LPSTR
)dst
;
3906 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3907 textA
[count
- 1] = 0; /* ensure 0 termination */
3908 return strlen(textA
);
3912 /*********************************************************************
3917 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3922 if (!(es
->style
& ES_MULTILINE
))
3925 if (!(es
->style
& ES_AUTOHSCROLL
))
3929 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3932 TRACE("SB_LINELEFT\n");
3934 dx
= -es
->char_width
;
3937 TRACE("SB_LINERIGHT\n");
3938 if (es
->x_offset
< es
->text_width
)
3939 dx
= es
->char_width
;
3942 TRACE("SB_PAGELEFT\n");
3944 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3947 TRACE("SB_PAGERIGHT\n");
3948 if (es
->x_offset
< es
->text_width
)
3949 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3957 TRACE("SB_RIGHT\n");
3958 if (es
->x_offset
< es
->text_width
)
3959 dx
= es
->text_width
- es
->x_offset
;
3962 TRACE("SB_THUMBTRACK %d\n", pos
);
3963 es
->flags
|= EF_HSCROLL_TRACK
;
3964 if(es
->style
& WS_HSCROLL
)
3965 dx
= pos
- es
->x_offset
;
3970 if(pos
< 0 || pos
> 100) return 0;
3971 /* Assume default scroll range 0-100 */
3972 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3973 new_x
= pos
* (es
->text_width
- fw
) / 100;
3974 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3977 case SB_THUMBPOSITION
:
3978 TRACE("SB_THUMBPOSITION %d\n", pos
);
3979 es
->flags
&= ~EF_HSCROLL_TRACK
;
3980 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3981 dx
= pos
- es
->x_offset
;
3986 if(pos
< 0 || pos
> 100) return 0;
3987 /* Assume default scroll range 0-100 */
3988 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3989 new_x
= pos
* (es
->text_width
- fw
) / 100;
3990 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3993 /* force scroll info update */
3994 EDIT_UpdateScrollInfo(es
);
3995 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
3999 TRACE("SB_ENDSCROLL\n");
4002 * FIXME : the next two are undocumented !
4003 * Are we doing the right thing ?
4004 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4005 * although it's also a regular control message.
4007 case EM_GETTHUMB
: /* this one is used by NT notepad */
4011 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4012 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4015 /* Assume default scroll range 0-100 */
4016 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4017 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4019 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4022 case EM_LINESCROLL16
:
4023 TRACE("EM_LINESCROLL16\n");
4028 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4034 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4035 /* check if we are going to move too far */
4036 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4037 dx
= es
->text_width
- fw
- es
->x_offset
;
4039 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4045 /*********************************************************************
4050 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4052 HWND hLBox
= es
->hwndListBox
;
4060 hCombo
= GetParent(es
->hwndSelf
);
4064 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4066 if (key
== VK_UP
|| key
== VK_DOWN
)
4068 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4071 if (msg
== WM_KEYDOWN
|| nEUI
)
4072 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4078 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4080 /* make sure ComboLBox pops up */
4081 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4086 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4089 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4091 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4093 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4098 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4104 /*********************************************************************
4108 * Handling of special keys that don't produce a WM_CHAR
4109 * (i.e. non-printable keys) & Backspace & Delete
4112 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4117 if (GetKeyState(VK_MENU
) & 0x8000)
4120 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4121 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4126 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4131 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4132 EDIT_MoveUp_ML(es
, shift
);
4135 EDIT_MoveWordBackward(es
, shift
);
4137 EDIT_MoveBackward(es
, shift
);
4140 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4144 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4145 EDIT_MoveDown_ML(es
, shift
);
4147 EDIT_MoveWordForward(es
, shift
);
4149 EDIT_MoveForward(es
, shift
);
4152 EDIT_MoveHome(es
, shift
);
4155 EDIT_MoveEnd(es
, shift
);
4158 if (es
->style
& ES_MULTILINE
)
4159 EDIT_MovePageUp_ML(es
, shift
);
4161 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4164 if (es
->style
& ES_MULTILINE
)
4165 EDIT_MovePageDown_ML(es
, shift
);
4167 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4170 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4171 if (es
->selection_start
!= es
->selection_end
) {
4178 /* delete character left of caret */
4179 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4180 EDIT_MoveBackward(es
, TRUE
);
4182 } else if (control
) {
4183 /* delete to end of line */
4184 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4185 EDIT_MoveEnd(es
, TRUE
);
4188 /* delete character right of caret */
4189 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4190 EDIT_MoveForward(es
, TRUE
);
4198 if (!(es
->style
& ES_READONLY
))
4204 /* If the edit doesn't want the return send a message to the default object */
4205 if(!(es
->style
& ES_WANTRETURN
))
4207 HWND hwndParent
= GetParent(es
->hwndSelf
);
4208 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4209 if (HIWORD(dw
) == DC_HASDEFID
)
4211 SendMessageW( hwndParent
, WM_COMMAND
,
4212 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4213 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4222 /*********************************************************************
4227 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4229 es
->flags
&= ~EF_FOCUSED
;
4231 if(!(es
->style
& ES_NOHIDESEL
))
4232 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4233 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4238 /*********************************************************************
4242 * The caret position has been set on the WM_LBUTTONDOWN message
4245 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4248 INT e
= es
->selection_end
;
4253 if (!(es
->flags
& EF_FOCUSED
))
4256 l
= EDIT_EM_LineFromChar(es
, e
);
4257 li
= EDIT_EM_LineIndex(es
, l
);
4258 ll
= EDIT_EM_LineLength(es
, e
);
4259 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4260 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4261 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4262 EDIT_EM_ScrollCaret(es
);
4267 /*********************************************************************
4272 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4277 SetFocus(es
->hwndSelf
);
4278 if (!(es
->flags
& EF_FOCUSED
))
4281 es
->bCaptureState
= TRUE
;
4282 SetCapture(es
->hwndSelf
);
4283 EDIT_ConfinePoint(es
, &x
, &y
);
4284 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4285 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4286 EDIT_EM_ScrollCaret(es
);
4287 es
->region_posx
= es
->region_posy
= 0;
4288 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4293 /*********************************************************************
4298 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4300 if (es
->bCaptureState
) {
4301 KillTimer(es
->hwndSelf
, 0);
4302 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4304 es
->bCaptureState
= FALSE
;
4309 /*********************************************************************
4314 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4316 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4321 /*********************************************************************
4326 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4332 if (GetCapture() != es
->hwndSelf
)
4336 * FIXME: gotta do some scrolling if outside client
4337 * area. Maybe reset the timer ?
4340 EDIT_ConfinePoint(es
, &x
, &y
);
4341 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4342 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4343 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4344 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4345 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4350 /*********************************************************************
4354 * See also EDIT_WM_StyleChanged
4356 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4361 TRACE("Creating %s edit control, style = %08lx\n",
4362 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4364 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4366 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4369 * Note: since the EDITSTATE has not been fully initialized yet,
4370 * we can't use any API calls that may send
4371 * WM_XXX messages before WM_NCCREATE is completed.
4374 es
->is_unicode
= unicode
;
4375 es
->style
= lpcs
->style
;
4377 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4379 es
->hwndSelf
= hwnd
;
4380 /* Save parent, which will be notified by EN_* messages */
4381 es
->hwndParent
= lpcs
->hwndParent
;
4383 if (es
->style
& ES_COMBO
)
4384 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4386 /* Number overrides lowercase overrides uppercase (at least it
4387 * does in Win95). However I'll bet that ES_NUMBER would be
4388 * invalid under Win 3.1.
4390 if (es
->style
& ES_NUMBER
) {
4391 ; /* do not override the ES_NUMBER */
4392 } else if (es
->style
& ES_LOWERCASE
) {
4393 es
->style
&= ~ES_UPPERCASE
;
4395 if (es
->style
& ES_MULTILINE
) {
4396 es
->buffer_limit
= BUFLIMIT_MULTI
;
4397 if (es
->style
& WS_VSCROLL
)
4398 es
->style
|= ES_AUTOVSCROLL
;
4399 if (es
->style
& WS_HSCROLL
)
4400 es
->style
|= ES_AUTOHSCROLL
;
4401 es
->style
&= ~ES_PASSWORD
;
4402 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4403 /* Confirmed - RIGHT overrides CENTER */
4404 if (es
->style
& ES_RIGHT
)
4405 es
->style
&= ~ES_CENTER
;
4406 es
->style
&= ~WS_HSCROLL
;
4409 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4410 es
->style
|= ES_AUTOVSCROLL
;
4412 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4413 es
->style
&= ~ES_CENTER
;
4414 es
->style
&= ~ES_RIGHT
;
4415 es
->style
&= ~WS_HSCROLL
;
4416 es
->style
&= ~WS_VSCROLL
;
4417 if (es
->style
& ES_PASSWORD
)
4418 es
->password_char
= '*';
4420 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4421 es
->style
|= ES_AUTOHSCROLL
;
4424 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4425 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4427 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4429 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4431 es
->undo_buffer_size
= es
->buffer_size
;
4433 if (es
->style
& ES_MULTILINE
)
4434 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4439 * In Win95 look and feel, the WS_BORDER style is replaced by the
4440 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4441 * control a nonclient area so we don't need to draw the border.
4442 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4443 * a nonclient area and we should handle painting the border ourselves.
4445 * When making modifications please ensure that the code still works
4446 * for edit controls created directly with style 0x50800000, exStyle 0
4447 * (which should have a single pixel border)
4449 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4450 es
->style
&= ~WS_BORDER
;
4451 else if (es
->style
& WS_BORDER
)
4452 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4457 /*********************************************************************
4462 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4473 BOOL rev
= es
->bEnableState
&&
4474 ((es
->flags
& EF_FOCUSED
) ||
4475 (es
->style
& ES_NOHIDESEL
));
4476 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4478 GetClientRect(es
->hwndSelf
, &rcClient
);
4480 /* paint the background */
4481 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
4482 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
4483 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4484 GetClipBox(dc
, &rc
);
4485 FillRect(dc
, &rc
, brush
);
4487 /* draw the border */
4488 if(es
->style
& WS_BORDER
) {
4490 if(es
->style
& ES_MULTILINE
) {
4491 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4492 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4494 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4496 IntersectClipRect(dc
, es
->format_rect
.left
,
4497 es
->format_rect
.top
,
4498 es
->format_rect
.right
,
4499 es
->format_rect
.bottom
);
4500 if (es
->style
& ES_MULTILINE
) {
4502 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4505 old_font
= SelectObject(dc
, es
->font
);
4506 EDIT_NotifyCtlColor(es
, dc
);
4508 if (!es
->bEnableState
)
4509 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4510 GetClipBox(dc
, &rcRgn
);
4511 if (es
->style
& ES_MULTILINE
) {
4512 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4513 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4514 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4515 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4516 EDIT_PaintLine(es
, dc
, i
, rev
);
4519 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4520 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4521 EDIT_PaintLine(es
, dc
, 0, rev
);
4524 SelectObject(dc
, old_font
);
4527 EndPaint(es
->hwndSelf
, &ps
);
4531 /*********************************************************************
4536 static void EDIT_WM_Paste(EDITSTATE
*es
)
4541 /* Protect read-only edit control from modification */
4542 if(es
->style
& ES_READONLY
)
4545 OpenClipboard(es
->hwndSelf
);
4546 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4547 src
= (LPWSTR
)GlobalLock(hsrc
);
4548 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4555 /*********************************************************************
4560 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4562 es
->flags
|= EF_FOCUSED
;
4563 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4564 EDIT_SetCaretPos(es
, es
->selection_end
,
4565 es
->flags
& EF_AFTER_WRAP
);
4566 if(!(es
->style
& ES_NOHIDESEL
))
4567 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4568 ShowCaret(es
->hwndSelf
);
4569 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4573 /*********************************************************************
4577 * With Win95 look the margins are set to default font value unless
4578 * the system font (font == 0) is being set, in which case they are left
4582 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4590 dc
= GetDC(es
->hwndSelf
);
4592 old_font
= SelectObject(dc
, font
);
4593 GetTextMetricsW(dc
, &tm
);
4594 es
->line_height
= tm
.tmHeight
;
4595 es
->char_width
= tm
.tmAveCharWidth
;
4597 SelectObject(dc
, old_font
);
4598 ReleaseDC(es
->hwndSelf
, dc
);
4599 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4600 EC_USEFONTINFO
, EC_USEFONTINFO
);
4602 /* Force the recalculation of the format rect for each font change */
4603 GetClientRect(es
->hwndSelf
, &r
);
4604 EDIT_SetRectNP(es
, &r
);
4606 if (es
->style
& ES_MULTILINE
)
4607 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4609 EDIT_CalcLineWidth_SL(es
);
4612 EDIT_UpdateText(es
, NULL
, TRUE
);
4613 if (es
->flags
& EF_FOCUSED
) {
4615 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4616 EDIT_SetCaretPos(es
, es
->selection_end
,
4617 es
->flags
& EF_AFTER_WRAP
);
4618 ShowCaret(es
->hwndSelf
);
4623 /*********************************************************************
4628 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4629 * The modified flag is reset. No notifications are sent.
4631 * For single-line controls, reception of WM_SETTEXT triggers:
4632 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4635 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
4637 if (!unicode
&& text
)
4639 LPCSTR textA
= (LPCSTR
)text
;
4640 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4641 LPWSTR textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
4643 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4647 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4650 TRACE("%s\n", debugstr_w(text
));
4651 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4653 HeapFree(GetProcessHeap(), 0, (LPWSTR
)text
);
4657 static const WCHAR empty_stringW
[] = {0};
4659 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4662 es
->flags
&= ~EF_MODIFIED
;
4663 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4665 /* Send the notification after the selection start and end have been set
4666 * edit control doesn't send notification on WM_SETTEXT
4667 * if it is multiline, or it is part of combobox
4669 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4671 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4672 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4674 EDIT_EM_ScrollCaret(es
);
4678 /*********************************************************************
4683 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4685 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4687 TRACE("width = %d, height = %d\n", width
, height
);
4688 SetRect(&rc
, 0, 0, width
, height
);
4689 EDIT_SetRectNP(es
, &rc
);
4690 EDIT_UpdateText(es
, NULL
, TRUE
);
4695 /*********************************************************************
4699 * This message is sent by SetWindowLong on having changed either the Style
4700 * or the extended style.
4702 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4704 * See also EDIT_WM_NCCreate
4706 * It appears that the Windows version of the edit control allows the style
4707 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4708 * style variable which will generally be different. In this function we
4709 * update the internal style based on what changed in the externally visible
4712 * Much of this content as based upon the MSDN, especially:
4713 * Platform SDK Documentation -> User Interface Services ->
4714 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4715 * Edit Control Styles
4717 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4719 if (GWL_STYLE
== which
) {
4720 DWORD style_change_mask
;
4722 /* Only a subset of changes can be applied after the control
4725 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4727 if (es
->style
& ES_MULTILINE
)
4728 style_change_mask
|= ES_WANTRETURN
;
4730 new_style
= style
->styleNew
& style_change_mask
;
4732 /* Number overrides lowercase overrides uppercase (at least it
4733 * does in Win95). However I'll bet that ES_NUMBER would be
4734 * invalid under Win 3.1.
4736 if (new_style
& ES_NUMBER
) {
4737 ; /* do not override the ES_NUMBER */
4738 } else if (new_style
& ES_LOWERCASE
) {
4739 new_style
&= ~ES_UPPERCASE
;
4742 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4743 } else if (GWL_EXSTYLE
== which
) {
4744 ; /* FIXME - what is needed here */
4746 WARN ("Invalid style change %d\n",which
);
4752 /*********************************************************************
4757 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4759 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4760 if (EDIT_EM_CanUndo(es
))
4763 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4764 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4767 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4771 /*********************************************************************
4776 static void EDIT_WM_Timer(EDITSTATE
*es
)
4778 if (es
->region_posx
< 0) {
4779 EDIT_MoveBackward(es
, TRUE
);
4780 } else if (es
->region_posx
> 0) {
4781 EDIT_MoveForward(es
, TRUE
);
4784 * FIXME: gotta do some vertical scrolling here, like
4785 * EDIT_EM_LineScroll(hwnd, 0, 1);
4789 /*********************************************************************
4794 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4798 if (!(es
->style
& ES_MULTILINE
))
4801 if (!(es
->style
& ES_AUTOVSCROLL
))
4810 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4811 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4812 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4814 EDIT_EM_Scroll(es
, action
);
4821 TRACE("SB_BOTTOM\n");
4822 dy
= es
->line_count
- 1 - es
->y_offset
;
4825 TRACE("SB_THUMBTRACK %d\n", pos
);
4826 es
->flags
|= EF_VSCROLL_TRACK
;
4827 if(es
->style
& WS_VSCROLL
)
4828 dy
= pos
- es
->y_offset
;
4831 /* Assume default scroll range 0-100 */
4834 if(pos
< 0 || pos
> 100) return 0;
4835 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4836 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4837 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4838 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4839 es
->line_count
, es
->y_offset
, pos
, dy
);
4842 case SB_THUMBPOSITION
:
4843 TRACE("SB_THUMBPOSITION %d\n", pos
);
4844 es
->flags
&= ~EF_VSCROLL_TRACK
;
4845 if(es
->style
& WS_VSCROLL
)
4846 dy
= pos
- es
->y_offset
;
4849 /* Assume default scroll range 0-100 */
4852 if(pos
< 0 || pos
> 100) return 0;
4853 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4854 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4855 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4856 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4857 es
->line_count
, es
->y_offset
, pos
, dy
);
4861 /* force scroll info update */
4862 EDIT_UpdateScrollInfo(es
);
4863 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4867 TRACE("SB_ENDSCROLL\n");
4870 * FIXME : the next two are undocumented !
4871 * Are we doing the right thing ?
4872 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4873 * although it's also a regular control message.
4875 case EM_GETTHUMB
: /* this one is used by NT notepad */
4879 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4880 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4883 /* Assume default scroll range 0-100 */
4884 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4885 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4887 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4890 case EM_LINESCROLL16
:
4891 TRACE("EM_LINESCROLL16 %d\n", pos
);
4896 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4901 EDIT_EM_LineScroll(es
, 0, dy
);
4905 /*********************************************************************
4910 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4912 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4913 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
4917 /*********************************************************************
4922 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4924 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4925 InvalidateRect(es
->hwndSelf
, rc
, bErase
);