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
26 * - ES_NUMBER (new since win95)
28 * -!ES_AUTOVSCROLL (every multi line control *is* auto vscroll)
29 * -!ES_AUTOHSCROLL (every single line control *is* auto hscroll)
31 * When there is no autoscrolling, the control should first check whether
32 * the new text would fit. If not, an EN_MAXTEXT should be sent.
33 * However, currently this would require the actual change to be made,
34 * then call EDIT_BuildLineDefs() and then find out that the new text doesn't
35 * fit. After all this, things should be put back in the state before the
36 * changes. Note that for multi line controls !ES_AUTOHSCROLL works : wordwrap.
49 #include "wine/winbase16.h"
50 #include "wine/winuser16.h"
51 #include "wine/unicode.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
58 WINE_DECLARE_DEBUG_CHANNEL(combo
);
59 WINE_DECLARE_DEBUG_CHANNEL(relay
);
61 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
62 FIXME: BTW, new specs say 65535 (do you dare ???) */
63 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
64 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
65 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
66 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
69 * extra flags for EDITSTATE.flags field
71 #define EF_MODIFIED 0x0001 /* text has been modified */
72 #define EF_FOCUSED 0x0002 /* we have input focus */
73 #define EF_UPDATE 0x0004 /* notify parent of changed state */
74 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
75 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
76 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
77 wrapped line, instead of in front of the next character */
78 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
82 END_0
= 0, /* line ends with terminating '\0' character */
83 END_WRAP
, /* line is wrapped */
84 END_HARD
, /* line ends with a hard return '\r\n' */
85 END_SOFT
, /* line ends with a soft return '\r\r\n' */
86 END_RICH
/* line ends with a single '\n' */
89 typedef struct tagLINEDEF
{
90 INT length
; /* bruto length of a line in bytes */
91 INT net_length
; /* netto length of a line in visible characters */
93 INT width
; /* width of the line in pixels */
94 INT index
; /* line index into the buffer */
95 struct tagLINEDEF
*next
;
100 BOOL is_unicode
; /* how the control was created */
101 LPWSTR text
; /* the actual contents of the control */
102 UINT buffer_size
; /* the size of the buffer in characters */
103 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
104 HFONT font
; /* NULL means standard system font */
105 INT x_offset
; /* scroll offset for multi lines this is in pixels
106 for single lines it's in characters */
107 INT line_height
; /* height of a screen line in pixels */
108 INT char_width
; /* average character width in pixels */
109 DWORD style
; /* sane version of wnd->dwStyle */
110 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
111 INT undo_insert_count
; /* number of characters inserted in sequence */
112 UINT undo_position
; /* character index of the insertion and deletion */
113 LPWSTR undo_text
; /* deleted text */
114 UINT undo_buffer_size
; /* size of the deleted text buffer */
115 INT selection_start
; /* == selection_end if no selection */
116 INT selection_end
; /* == current caret position */
117 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
118 INT left_margin
; /* in pixels */
119 INT right_margin
; /* in pixels */
121 INT text_width
; /* width of the widest line in pixels for multi line controls
122 and just line width for single line controls */
123 INT region_posx
; /* Position of cursor relative to region: */
124 INT region_posy
; /* -1: to left, 0: within, 1: to right */
125 EDITWORDBREAKPROC16 word_break_proc16
;
126 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
127 INT line_count
; /* number of lines */
128 INT y_offset
; /* scroll offset in number of lines */
129 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
130 BOOL bEnableState
; /* flag keeping the enable state */
131 HWND hwndSelf
; /* the our window handle */
132 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
133 Even if parent will change, EN_* messages
134 should be sent to the first parent. */
135 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
137 * only for multi line controls
139 INT lock_count
; /* amount of re-entries in the EditWndProc */
142 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
143 HLOCAL hloc32W
; /* our unicode local memory block */
144 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
146 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
151 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
152 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
154 /* used for disabled or read-only edit control */
155 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
157 { /* Notify parent which has created this edit control */ \
158 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
159 SendMessageW(es->hwndParent, WM_COMMAND, \
160 MAKEWPARAM(GetWindowLongW((es->hwndSelf),GWL_ID), wNotifyCode), \
161 (LPARAM)(es->hwndSelf)); \
164 /*********************************************************************
171 * These functions have trivial implementations
172 * We still like to call them internally
173 * "static inline" makes them more like macro's
175 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
176 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
177 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
178 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
181 * Helper functions only valid for one type of control
183 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
184 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
185 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
186 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
187 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
191 * Helper functions valid for both single line _and_ multi line controls
193 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
194 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
195 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
196 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
197 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
198 static void EDIT_LockBuffer(EDITSTATE
*es
);
199 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
);
200 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
201 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
202 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
203 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
204 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
205 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
206 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
207 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
208 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
209 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
210 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
211 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
212 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
213 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
215 * EM_XXX message handlers
217 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
218 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
219 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
220 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
221 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
);
222 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
223 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
224 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
225 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
226 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
227 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
228 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
229 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
230 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
231 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
232 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
233 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
234 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
235 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
236 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
237 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
238 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
239 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
240 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
241 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
);
242 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
243 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
245 * WM_XXX message handlers
247 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
248 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
249 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
250 static void EDIT_WM_Copy(EDITSTATE
*es
);
251 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
252 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
253 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
254 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
255 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
256 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
257 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
258 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
259 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
260 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
261 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
262 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
263 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
264 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
);
265 static void EDIT_WM_Paste(EDITSTATE
*es
);
266 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
267 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
268 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
269 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
270 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
271 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
272 static void EDIT_WM_Timer(EDITSTATE
*es
);
273 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
274 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
275 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
277 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
278 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
280 /*********************************************************************
281 * edit class descriptor
283 const struct builtin_class_descr EDIT_builtin_class
=
286 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_PARENTDC
, /* style */
287 EditWndProcA
, /* procA */
288 EditWndProcW
, /* procW */
289 sizeof(EDITSTATE
*), /* extra */
290 IDC_IBEAMA
, /* cursor */
295 /*********************************************************************
300 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
302 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
306 /*********************************************************************
311 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
313 es
->undo_insert_count
= 0;
314 *es
->undo_text
= '\0';
318 /*********************************************************************
323 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
325 static const WCHAR empty_stringW
[] = {0};
327 /* Protect read-only edit control from modification */
328 if(es
->style
& ES_READONLY
)
331 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
335 /*********************************************************************
340 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
347 /**********************************************************************
350 * Returns the window version in case Wine emulates a later version
351 * of windows then the application expects.
353 * In a number of cases when windows runs an application that was
354 * designed for an earlier windows version, windows reverts
355 * to "old" behaviour of that earlier version.
357 * An example is a disabled edit control that needs to be painted.
358 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
359 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
360 * applications with an expected version 0f 4.0 or higher.
363 static DWORD
get_app_version(void)
365 static DWORD version
;
368 DWORD dwEmulatedVersion
;
370 DWORD dwProcVersion
= GetProcessVersion(0);
372 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
373 GetVersionExW( &info
);
374 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
375 /* FIXME: this may not be 100% correct; see discussion on the
376 * wine developer list in Nov 1999 */
377 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
383 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
387 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
388 msg
= WM_CTLCOLORSTATIC
;
390 msg
= WM_CTLCOLOREDIT
;
392 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
393 return (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
396 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
399 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
401 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
404 /*********************************************************************
408 * The messages are in the order of the actual integer values
409 * (which can be found in include/windows.h)
410 * Wherever possible the 16 bit versions are converted to
411 * the 32 bit ones, so that we can 'fall through' to the
412 * helper functions. These are mostly 32 bit (with a few
413 * exceptions, clearly indicated by a '16' extension to their
417 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
418 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
420 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongW( hwnd
, 0 );
423 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
425 if (!es
&& msg
!= WM_NCCREATE
)
426 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
427 else if (msg
== WM_NCCREATE
)
428 return EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
429 else if (msg
== WM_DESTROY
)
430 return EDIT_WM_Destroy(es
);
433 if (es
) EDIT_LockBuffer(es
);
441 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
445 if (SLOWORD(lParam
) == -1)
446 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
448 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
450 EDIT_EM_ScrollCaret(es
);
454 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
455 EDIT_EM_ScrollCaret(es
);
461 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
465 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
469 if ((es
->style
& ES_MULTILINE
) && lParam
) {
471 CONV_RECT16TO32(MapSL(lParam
), &rc
);
472 EDIT_SetRectNP(es
, &rc
);
473 EDIT_UpdateText(es
, NULL
, TRUE
);
477 if ((es
->style
& ES_MULTILINE
) && lParam
) {
478 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
479 EDIT_UpdateText(es
, NULL
, TRUE
);
484 if ((es
->style
& ES_MULTILINE
) && lParam
) {
486 CONV_RECT16TO32(MapSL(lParam
), &rc
);
487 EDIT_SetRectNP(es
, &rc
);
491 if ((es
->style
& ES_MULTILINE
) && lParam
)
492 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
497 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
500 case EM_LINESCROLL16
:
501 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
502 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
505 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
508 case EM_SCROLLCARET16
:
510 EDIT_EM_ScrollCaret(es
);
516 result
= ((es
->flags
& EF_MODIFIED
) != 0);
522 es
->flags
|= EF_MODIFIED
;
524 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
527 case EM_GETLINECOUNT16
:
528 case EM_GETLINECOUNT
:
529 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
533 if ((INT16
)wParam
== -1)
537 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
541 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
544 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
548 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
551 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
556 result
= EDIT_EM_GetThumb(es
);
559 /* these messages missing from specs */
568 FIXME("undocumented message 0x%x, please report\n", msg
);
569 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
572 case EM_LINELENGTH16
:
574 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
577 case EM_REPLACESEL16
:
578 lParam
= (LPARAM
)MapSL(lParam
);
579 unicode
= FALSE
; /* 16-bit message is always ascii */
586 textW
= (LPWSTR
)lParam
;
589 LPSTR textA
= (LPSTR
)lParam
;
590 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
591 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
592 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
595 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
599 HeapFree(GetProcessHeap(), 0, textW
);
604 lParam
= (LPARAM
)MapSL(lParam
);
605 unicode
= FALSE
; /* 16-bit message is always ascii */
608 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, lParam
, unicode
);
612 case EM_SETLIMITTEXT
:
613 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
618 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
624 result
= (LRESULT
)EDIT_EM_Undo(es
);
629 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
632 case EM_LINEFROMCHAR16
:
633 case EM_LINEFROMCHAR
:
634 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
637 case EM_SETTABSTOPS16
:
638 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
641 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
644 case EM_SETPASSWORDCHAR16
:
645 unicode
= FALSE
; /* 16-bit message is always ascii */
647 case EM_SETPASSWORDCHAR
:
652 charW
= (WCHAR
)wParam
;
656 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
659 EDIT_EM_SetPasswordChar(es
, charW
);
663 case EM_EMPTYUNDOBUFFER16
:
664 case EM_EMPTYUNDOBUFFER
:
665 EDIT_EM_EmptyUndoBuffer(es
);
668 case EM_GETFIRSTVISIBLELINE16
:
669 result
= es
->y_offset
;
671 case EM_GETFIRSTVISIBLELINE
:
672 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
675 case EM_SETREADONLY16
:
678 SetWindowLongW( hwnd
, GWL_STYLE
,
679 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
680 es
->style
|= ES_READONLY
;
682 SetWindowLongW( hwnd
, GWL_STYLE
,
683 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
684 es
->style
&= ~ES_READONLY
;
689 case EM_SETWORDBREAKPROC16
:
690 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
692 case EM_SETWORDBREAKPROC
:
693 EDIT_EM_SetWordBreakProc(es
, lParam
);
696 case EM_GETWORDBREAKPROC16
:
697 result
= (LRESULT
)es
->word_break_proc16
;
699 case EM_GETWORDBREAKPROC
:
700 result
= (LRESULT
)es
->word_break_proc
;
703 case EM_GETPASSWORDCHAR16
:
704 unicode
= FALSE
; /* 16-bit message is always ascii */
706 case EM_GETPASSWORDCHAR
:
709 result
= es
->password_char
;
712 WCHAR charW
= es
->password_char
;
714 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
720 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
723 EDIT_EM_SetMargins(es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
727 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
730 case EM_GETLIMITTEXT
:
731 result
= es
->buffer_limit
;
735 result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
739 result
= EDIT_EM_CharFromPos(es
, SLOWORD(lParam
), SHIWORD(lParam
));
742 /* End of the EM_ messages which were in numerical order; what order
743 * are these in? vaguely alphabetical?
747 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
749 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
751 int vk
= (int)((LPMSG
)lParam
)->wParam
;
753 if (vk
== VK_RETURN
&& (GetWindowLongW( hwnd
, GWL_STYLE
) & ES_WANTRETURN
))
755 result
|= DLGC_WANTMESSAGE
;
757 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
759 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
760 result
|= DLGC_WANTMESSAGE
;
774 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
777 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
779 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
780 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
783 EDIT_WM_Char(es
, charW
);
792 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
796 EDIT_WM_ContextMenu(es
, SLOWORD(lParam
), SHIWORD(lParam
));
805 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
808 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
812 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
813 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
814 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
816 result
= EDIT_WM_Create(es
, nameW
);
818 HeapFree(GetProcessHeap(), 0, nameW
);
827 es
->bEnableState
= (BOOL
) wParam
;
828 EDIT_UpdateText(es
, NULL
, TRUE
);
832 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
836 result
= (LRESULT
)es
->font
;
840 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
843 case WM_GETTEXTLENGTH
:
844 if (unicode
) result
= strlenW(es
->text
);
845 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
846 NULL
, 0, NULL
, NULL
);
850 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), SHIWORD(wParam
));
854 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
858 result
= EDIT_WM_KillFocus(es
);
861 case WM_LBUTTONDBLCLK
:
862 result
= EDIT_WM_LButtonDblClk(es
);
866 result
= EDIT_WM_LButtonDown(es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
870 result
= EDIT_WM_LButtonUp(es
);
874 result
= EDIT_WM_MButtonDown(es
);
877 case WM_MOUSEACTIVATE
:
879 * FIXME: maybe DefWindowProc() screws up, but it seems that
880 * modeless dialog boxes need this. If we don't do this, the focus
881 * will _not_ be set by DefWindowProc() for edit controls in a
882 * modeless dialog box ???
885 result
= MA_ACTIVATE
;
889 result
= EDIT_WM_MouseMove(es
, SLOWORD(lParam
), SHIWORD(lParam
));
893 EDIT_WM_Paint(es
, wParam
);
901 EDIT_WM_SetFocus(es
);
905 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
909 /* FIXME: actually set an internal flag and behave accordingly */
913 EDIT_WM_SetText(es
, lParam
, unicode
);
918 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
921 case WM_STYLECHANGED
:
922 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
925 case WM_STYLECHANGING
:
926 result
= 0; /* See EDIT_WM_StyleChanged */
930 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
938 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), SHIWORD(wParam
));
943 int gcWheelDelta
= 0;
944 UINT pulScrollLines
= 3;
945 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
947 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
948 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
951 gcWheelDelta
-= SHIWORD(wParam
);
952 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
954 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
955 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
956 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
961 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
965 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
970 /*********************************************************************
972 * EditWndProcW (USER32.@)
974 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
976 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
979 /*********************************************************************
981 * EditWndProc (USER32.@)
983 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
985 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
988 /*********************************************************************
990 * EDIT_BuildLineDefs_ML
992 * Build linked list of text lines.
993 * Lines can end with '\0' (last line), a character (if it is wrapped),
994 * a soft return '\r\r\n' or a hard return '\r\n'
997 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1001 LPWSTR current_position
, cp
;
1003 LINEDEF
*current_line
;
1004 LINEDEF
*previous_line
;
1005 LINEDEF
*start_line
;
1006 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1007 INT line_count
= es
->line_count
;
1008 INT orig_net_length
;
1011 if (istart
== iend
&& delta
== 0)
1014 dc
= GetDC(es
->hwndSelf
);
1016 old_font
= SelectObject(dc
, es
->font
);
1018 previous_line
= NULL
;
1019 current_line
= es
->first_line_def
;
1021 /* Find starting line. istart must lie inside an existing line or
1022 * at the end of buffer */
1024 if (istart
< current_line
->index
+ current_line
->length
||
1025 current_line
->ending
== END_0
)
1028 previous_line
= current_line
;
1029 current_line
= current_line
->next
;
1031 } while (current_line
);
1033 if (!current_line
) /* Error occurred start is not inside previous buffer */
1035 FIXME(" modification occurred outside buffer\n");
1039 /* Remember start of modifications in order to calculate update region */
1040 nstart_line
= line_index
;
1041 nstart_index
= current_line
->index
;
1043 /* We must start to reformat from the previous line since the modifications
1044 * may have caused the line to wrap upwards. */
1045 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1048 current_line
= previous_line
;
1050 start_line
= current_line
;
1052 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1053 current_position
= es
->text
+ current_line
->index
;
1055 if (current_line
!= start_line
)
1057 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1059 /* The buffer has been expanded, create a new line and
1060 insert it into the link list */
1061 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1062 new_line
->next
= previous_line
->next
;
1063 previous_line
->next
= new_line
;
1064 current_line
= new_line
;
1067 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1069 /* The previous line merged with this line so we delete this extra entry */
1070 previous_line
->next
= current_line
->next
;
1071 HeapFree(GetProcessHeap(), 0, current_line
);
1072 current_line
= previous_line
->next
;
1076 else /* current_line->index + delta == current_position */
1078 if (current_position
- es
->text
> iend
)
1079 break; /* We reached end of line modifications */
1080 /* else recalulate this line */
1084 current_line
->index
= current_position
- es
->text
;
1085 orig_net_length
= current_line
->net_length
;
1087 /* Find end of line */
1088 cp
= current_position
;
1090 if (*cp
== '\n') break;
1091 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1096 /* Mark type of line termination */
1098 current_line
->ending
= END_0
;
1099 current_line
->net_length
= strlenW(current_position
);
1100 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1101 current_line
->ending
= END_SOFT
;
1102 current_line
->net_length
= cp
- current_position
- 1;
1103 } else if (*cp
== '\n') {
1104 current_line
->ending
= END_RICH
;
1105 current_line
->net_length
= cp
- current_position
;
1107 current_line
->ending
= END_HARD
;
1108 current_line
->net_length
= cp
- current_position
;
1111 /* Calculate line width */
1112 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1113 current_position
, current_line
->net_length
,
1114 es
->tabs_count
, es
->tabs
));
1116 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1117 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1122 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1123 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1124 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1125 current_position
, next
, es
->tabs_count
, es
->tabs
));
1126 } while (current_line
->width
<= fw
);
1127 if (!prev
) { /* Didn't find a line break so force a break */
1132 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1133 current_position
, next
, es
->tabs_count
, es
->tabs
));
1134 } while (current_line
->width
<= fw
);
1139 /* If the first line we are calculating, wrapped before istart, we must
1140 * adjust istart in order for this to be reflected in the update region. */
1141 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1142 istart
= current_line
->index
+ prev
;
1143 /* else if we are updating the previous line before the first line we
1144 * are re-calculating and it expanded */
1145 else if (current_line
== start_line
&&
1146 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1148 /* Line expanded due to an upwards line wrap so we must partially include
1149 * previous line in update region */
1150 nstart_line
= line_index
;
1151 nstart_index
= current_line
->index
;
1152 istart
= current_line
->index
+ orig_net_length
;
1155 current_line
->net_length
= prev
;
1156 current_line
->ending
= END_WRAP
;
1157 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1158 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1162 /* Adjust length to include line termination */
1163 switch (current_line
->ending
) {
1165 current_line
->length
= current_line
->net_length
+ 3;
1168 current_line
->length
= current_line
->net_length
+ 1;
1171 current_line
->length
= current_line
->net_length
+ 2;
1175 current_line
->length
= current_line
->net_length
;
1178 es
->text_width
= max(es
->text_width
, current_line
->width
);
1179 current_position
+= current_line
->length
;
1180 previous_line
= current_line
;
1181 current_line
= current_line
->next
;
1183 } while (previous_line
->ending
!= END_0
);
1185 /* Finish adjusting line indexes by delta or remove hanging lines */
1186 if (previous_line
->ending
== END_0
)
1188 LINEDEF
*pnext
= NULL
;
1190 previous_line
->next
= NULL
;
1191 while (current_line
)
1193 pnext
= current_line
->next
;
1194 HeapFree(GetProcessHeap(), 0, current_line
);
1195 current_line
= pnext
;
1201 while (current_line
)
1203 current_line
->index
+= delta
;
1204 current_line
= current_line
->next
;
1208 /* Calculate rest of modification rectangle */
1213 * We calculate two rectangles. One for the first line which may have
1214 * an indent with respect to the format rect. The other is a format-width
1215 * rectangle that spans the rest of the lines that changed or moved.
1217 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1218 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1219 rc
.bottom
= rc
.top
+ es
->line_height
;
1220 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1221 es
->text
+ nstart_index
, istart
- nstart_index
,
1222 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1223 rc
.right
= es
->format_rect
.right
;
1224 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1227 rc
.left
= es
->format_rect
.left
;
1228 rc
.right
= es
->format_rect
.right
;
1230 * If lines were added or removed we must re-paint the remainder of the
1231 * lines since the remaining lines were either shifted up or down.
1233 if (line_count
< es
->line_count
) /* We added lines */
1234 rc
.bottom
= es
->line_count
* es
->line_height
;
1235 else if (line_count
> es
->line_count
) /* We removed lines */
1236 rc
.bottom
= line_count
* es
->line_height
;
1238 rc
.bottom
= line_index
* es
->line_height
;
1239 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1240 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1241 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1242 DeleteObject(tmphrgn
);
1246 SelectObject(dc
, old_font
);
1248 ReleaseDC(es
->hwndSelf
, dc
);
1251 /*********************************************************************
1253 * EDIT_CalcLineWidth_SL
1256 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1258 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(es
, strlenW(es
->text
), FALSE
));
1261 /*********************************************************************
1263 * EDIT_CallWordBreakProc
1265 * Call appropriate WordBreakProc (internal or external).
1267 * Note: The "start" argument should always be an index referring
1268 * to es->text. The actual wordbreak proc might be
1269 * 16 bit, so we can't always pass any 32 bit LPSTR.
1270 * Hence we assume that es->text is the buffer that holds
1271 * the string under examination (we can decide this for ourselves).
1274 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1276 INT ret
, iWndsLocks
;
1278 /* To avoid any deadlocks, all the locks on the window structures
1279 must be suspended before the control is passed to the application */
1280 iWndsLocks
= WIN_SuspendWndsLock();
1282 if (es
->word_break_proc16
) {
1289 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1290 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1291 segptr
= K32WOWGlobalLock16(hglob16
);
1292 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1293 args
[4] = SELECTOROF(segptr
);
1294 args
[3] = OFFSETOF(segptr
);
1298 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1299 ret
= LOWORD(result
);
1300 GlobalUnlock16(hglob16
);
1301 GlobalFree16(hglob16
);
1303 else if (es
->word_break_proc
)
1307 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1309 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1310 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1311 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1315 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1319 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1320 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1321 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1322 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1323 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1324 ret
= wbpA(textA
, index
, countA
, action
);
1325 HeapFree(GetProcessHeap(), 0, textA
);
1329 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1331 WIN_RestoreWndsLock(iWndsLocks
);
1336 /*********************************************************************
1340 * Beware: This is not the function called on EM_CHARFROMPOS
1341 * The position _can_ be outside the formatting / client
1343 * The return value is only the character index
1346 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1352 if (es
->style
& ES_MULTILINE
) {
1353 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1355 LINEDEF
*line_def
= es
->first_line_def
;
1357 while ((line
> 0) && line_def
->next
) {
1358 line_index
+= line_def
->length
;
1359 line_def
= line_def
->next
;
1362 x
+= es
->x_offset
- es
->format_rect
.left
;
1363 if (x
>= line_def
->width
) {
1365 *after_wrap
= (line_def
->ending
== END_WRAP
);
1366 return line_index
+ line_def
->net_length
;
1370 *after_wrap
= FALSE
;
1373 dc
= GetDC(es
->hwndSelf
);
1375 old_font
= SelectObject(dc
, es
->font
);
1376 low
= line_index
+ 1;
1377 high
= line_index
+ line_def
->net_length
+ 1;
1378 while (low
< high
- 1)
1380 INT mid
= (low
+ high
) / 2;
1381 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1387 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1388 (line_def
->ending
== END_WRAP
));
1393 *after_wrap
= FALSE
;
1394 x
-= es
->format_rect
.left
;
1396 return es
->x_offset
;
1397 text
= EDIT_GetPasswordPointer_SL(es
);
1398 dc
= GetDC(es
->hwndSelf
);
1400 old_font
= SelectObject(dc
, es
->font
);
1404 INT high
= es
->x_offset
;
1405 while (low
< high
- 1)
1407 INT mid
= (low
+ high
) / 2;
1408 GetTextExtentPoint32W( dc
, text
+ mid
,
1409 es
->x_offset
- mid
, &size
);
1410 if (size
.cx
> -x
) low
= mid
;
1417 INT low
= es
->x_offset
;
1418 INT high
= strlenW(es
->text
) + 1;
1419 while (low
< high
- 1)
1421 INT mid
= (low
+ high
) / 2;
1422 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1423 mid
- es
->x_offset
, &size
);
1424 if (size
.cx
> x
) high
= mid
;
1429 if (es
->style
& ES_PASSWORD
)
1430 HeapFree(GetProcessHeap(), 0, text
);
1433 SelectObject(dc
, old_font
);
1434 ReleaseDC(es
->hwndSelf
, dc
);
1439 /*********************************************************************
1443 * adjusts the point to be within the formatting rectangle
1444 * (so CharFromPos returns the nearest _visible_ character)
1447 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1449 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1450 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1454 /*********************************************************************
1458 * Calculates the bounding rectangle for a line from a starting
1459 * column to an ending column.
1462 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1464 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1466 if (es
->style
& ES_MULTILINE
)
1467 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1469 rc
->top
= es
->format_rect
.top
;
1470 rc
->bottom
= rc
->top
+ es
->line_height
;
1471 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1472 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1476 /*********************************************************************
1478 * EDIT_GetPasswordPointer_SL
1480 * note: caller should free the (optionally) allocated buffer
1483 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1485 if (es
->style
& ES_PASSWORD
) {
1486 INT len
= strlenW(es
->text
);
1487 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1489 while(len
) text
[--len
] = es
->password_char
;
1496 /*********************************************************************
1500 * This acts as a LOCAL_Lock(), but it locks only once. This way
1501 * you can call it whenever you like, without unlocking.
1503 * Initially the edit control allocates a HLOCAL32 buffer
1504 * (32 bit linear memory handler). However, 16 bit application
1505 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1506 * handler). From that moment on we have to keep using this 16 bit memory
1507 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1508 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1512 static void EDIT_LockBuffer(EDITSTATE
*es
)
1514 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1518 BOOL _16bit
= FALSE
;
1524 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1525 textA
= LocalLock(es
->hloc32A
);
1526 countA
= strlen(textA
) + 1;
1530 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1531 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1532 countA
= strlen(textA
) + 1;
1537 ERR("no buffer ... please report\n");
1544 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1545 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1546 if(countW_new
> es
->buffer_size
+ 1)
1548 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1549 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1550 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1553 es
->hloc32W
= hloc32W_new
;
1554 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1555 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1558 WARN("FAILED! Will synchronize partially\n");
1562 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1563 es
->text
= LocalLock(es
->hloc32W
);
1567 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1569 LOCAL_Unlock(hInstance
, es
->hloc16
);
1571 LocalUnlock(es
->hloc32A
);
1578 /*********************************************************************
1580 * EDIT_SL_InvalidateText
1582 * Called from EDIT_InvalidateText().
1583 * Does the job for single-line controls only.
1586 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1591 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1592 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1593 EDIT_UpdateText(es
, &rc
, TRUE
);
1597 /*********************************************************************
1599 * EDIT_ML_InvalidateText
1601 * Called from EDIT_InvalidateText().
1602 * Does the job for multi-line controls only.
1605 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1607 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1608 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1609 INT el
= EDIT_EM_LineFromChar(es
, end
);
1618 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1621 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1622 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1623 if (sl
< es
->y_offset
) {
1627 if (el
> es
->y_offset
+ vlc
) {
1628 el
= es
->y_offset
+ vlc
;
1629 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1631 GetClientRect(es
->hwndSelf
, &rc1
);
1632 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1634 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1635 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1636 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1638 EDIT_GetLineRect(es
, sl
, sc
,
1639 EDIT_EM_LineLength(es
,
1640 EDIT_EM_LineIndex(es
, sl
)),
1642 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1643 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1644 for (l
= sl
+ 1 ; l
< el
; l
++) {
1645 EDIT_GetLineRect(es
, l
, 0,
1646 EDIT_EM_LineLength(es
,
1647 EDIT_EM_LineIndex(es
, l
)),
1649 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1650 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1652 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1653 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1654 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1659 /*********************************************************************
1661 * EDIT_InvalidateText
1663 * Invalidate the text from offset start upto, but not including,
1664 * offset end. Useful for (re)painting the selection.
1665 * Regions outside the linewidth are not invalidated.
1666 * end == -1 means end == TextLength.
1667 * start and end need not be ordered.
1670 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1676 end
= strlenW(es
->text
);
1684 if (es
->style
& ES_MULTILINE
)
1685 EDIT_ML_InvalidateText(es
, start
, end
);
1687 EDIT_SL_InvalidateText(es
, start
, end
);
1691 /*********************************************************************
1695 * Try to fit size + 1 characters in the buffer.
1696 * Constrain to limits if honor_limit is TRUE.
1698 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
)
1702 if (size
<= es
->buffer_size
)
1705 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
1706 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
1710 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1712 /* Force edit to unlock it's buffer. es->text now NULL */
1713 EDIT_UnlockBuffer(es
, TRUE
);
1716 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1717 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1718 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1719 es
->hloc32W
= hNew32W
;
1720 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1724 EDIT_LockBuffer(es
);
1726 if (es
->buffer_size
< size
) {
1727 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1728 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1731 TRACE("We now have %d+1\n", es
->buffer_size
);
1737 /*********************************************************************
1741 * Try to fit size + 1 bytes in the undo buffer.
1744 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1748 if (size
<= es
->undo_buffer_size
)
1751 TRACE("trying to ReAlloc to %d+1\n", size
);
1753 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1754 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1755 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1760 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1766 /*********************************************************************
1771 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1773 INT e
= es
->selection_end
;
1777 if ((es
->style
& ES_MULTILINE
) && e
&&
1778 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1780 if (e
&& (es
->text
[e
- 1] == '\r'))
1784 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1785 EDIT_EM_ScrollCaret(es
);
1789 /*********************************************************************
1793 * Only for multi line controls
1794 * Move the caret one line down, on a column with the nearest
1795 * x coordinate on the screen (might be a different column).
1798 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1800 INT s
= es
->selection_start
;
1801 INT e
= es
->selection_end
;
1802 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1803 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1804 INT x
= SLOWORD(pos
);
1805 INT y
= SHIWORD(pos
);
1807 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1810 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1811 EDIT_EM_ScrollCaret(es
);
1815 /*********************************************************************
1820 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1822 BOOL after_wrap
= FALSE
;
1825 /* Pass a high value in x to make sure of receiving the end of the line */
1826 if (es
->style
& ES_MULTILINE
)
1827 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1828 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1830 e
= strlenW(es
->text
);
1831 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1832 EDIT_EM_ScrollCaret(es
);
1836 /*********************************************************************
1841 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1843 INT e
= es
->selection_end
;
1847 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1848 if (es
->text
[e
] == '\n')
1850 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1854 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1855 EDIT_EM_ScrollCaret(es
);
1859 /*********************************************************************
1863 * Home key: move to beginning of line.
1866 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1870 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1871 if (es
->style
& ES_MULTILINE
)
1872 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1873 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1876 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1877 EDIT_EM_ScrollCaret(es
);
1881 /*********************************************************************
1883 * EDIT_MovePageDown_ML
1885 * Only for multi line controls
1886 * Move the caret one page down, on a column with the nearest
1887 * x coordinate on the screen (might be a different column).
1890 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1892 INT s
= es
->selection_start
;
1893 INT e
= es
->selection_end
;
1894 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1895 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1896 INT x
= SLOWORD(pos
);
1897 INT y
= SHIWORD(pos
);
1899 e
= EDIT_CharFromPos(es
, x
,
1900 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1904 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1905 EDIT_EM_ScrollCaret(es
);
1909 /*********************************************************************
1911 * EDIT_MovePageUp_ML
1913 * Only for multi line controls
1914 * Move the caret one page up, on a column with the nearest
1915 * x coordinate on the screen (might be a different column).
1918 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1920 INT s
= es
->selection_start
;
1921 INT e
= es
->selection_end
;
1922 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1923 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1924 INT x
= SLOWORD(pos
);
1925 INT y
= SHIWORD(pos
);
1927 e
= EDIT_CharFromPos(es
, x
,
1928 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1932 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1933 EDIT_EM_ScrollCaret(es
);
1937 /*********************************************************************
1941 * Only for multi line controls
1942 * Move the caret one line up, on a column with the nearest
1943 * x coordinate on the screen (might be a different column).
1946 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1948 INT s
= es
->selection_start
;
1949 INT e
= es
->selection_end
;
1950 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1951 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1952 INT x
= SLOWORD(pos
);
1953 INT y
= SHIWORD(pos
);
1955 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1958 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1959 EDIT_EM_ScrollCaret(es
);
1963 /*********************************************************************
1965 * EDIT_MoveWordBackward
1968 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1970 INT s
= es
->selection_start
;
1971 INT e
= es
->selection_end
;
1976 l
= EDIT_EM_LineFromChar(es
, e
);
1977 ll
= EDIT_EM_LineLength(es
, e
);
1978 li
= EDIT_EM_LineIndex(es
, l
);
1981 li
= EDIT_EM_LineIndex(es
, l
- 1);
1982 e
= li
+ EDIT_EM_LineLength(es
, li
);
1985 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
1986 li
, e
- li
, ll
, WB_LEFT
);
1990 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
1991 EDIT_EM_ScrollCaret(es
);
1995 /*********************************************************************
1997 * EDIT_MoveWordForward
2000 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2002 INT s
= es
->selection_start
;
2003 INT e
= es
->selection_end
;
2008 l
= EDIT_EM_LineFromChar(es
, e
);
2009 ll
= EDIT_EM_LineLength(es
, e
);
2010 li
= EDIT_EM_LineIndex(es
, l
);
2012 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2013 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2015 e
= li
+ EDIT_CallWordBreakProc(es
,
2016 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2020 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2021 EDIT_EM_ScrollCaret(es
);
2025 /*********************************************************************
2030 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2032 INT s
= es
->selection_start
;
2033 INT e
= es
->selection_end
;
2040 if (es
->style
& ES_MULTILINE
) {
2041 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2042 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2047 TRACE("line=%d\n", line
);
2049 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2052 li
= EDIT_EM_LineIndex(es
, line
);
2053 ll
= EDIT_EM_LineLength(es
, li
);
2054 s
= min(es
->selection_start
, es
->selection_end
);
2055 e
= max(es
->selection_start
, es
->selection_end
);
2056 s
= min(li
+ ll
, max(li
, s
));
2057 e
= min(li
+ ll
, max(li
, e
));
2058 if (rev
&& (s
!= e
) &&
2059 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2060 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2061 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2062 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2064 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2068 /*********************************************************************
2073 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2084 BkMode
= GetBkMode(dc
);
2085 BkColor
= GetBkColor(dc
);
2086 TextColor
= GetTextColor(dc
);
2088 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2089 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2090 SetBkMode( dc
, OPAQUE
);
2092 li
= EDIT_EM_LineIndex(es
, line
);
2093 if (es
->style
& ES_MULTILINE
) {
2094 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2095 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2097 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2098 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2099 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2101 if (es
->style
& ES_PASSWORD
)
2102 HeapFree(GetProcessHeap(), 0, text
);
2105 SetBkColor(dc
, BkColor
);
2106 SetTextColor(dc
, TextColor
);
2107 SetBkMode( dc
, BkMode
);
2113 /*********************************************************************
2118 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2121 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2122 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2126 /*********************************************************************
2130 * note: this is not (exactly) the handler called on EM_SETRECTNP
2131 * it is also used to set the rect of a single line control
2134 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2136 CopyRect(&es
->format_rect
, rc
);
2137 if (es
->style
& WS_BORDER
) {
2138 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2139 if(TWEAK_WineLook
== WIN31_LOOK
)
2141 es
->format_rect
.left
+= bw
;
2142 es
->format_rect
.top
+= bw
;
2143 es
->format_rect
.right
-= bw
;
2144 es
->format_rect
.bottom
-= bw
;
2146 es
->format_rect
.left
+= es
->left_margin
;
2147 es
->format_rect
.right
-= es
->right_margin
;
2148 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2149 if (es
->style
& ES_MULTILINE
)
2151 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2153 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2154 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2156 /* correct es->x_offset */
2157 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2158 max_x_offset
= es
->text_width
- fw
;
2159 if(max_x_offset
< 0) max_x_offset
= 0;
2160 if(es
->x_offset
> max_x_offset
)
2161 es
->x_offset
= max_x_offset
;
2163 /* correct es->y_offset */
2164 max_y_offset
= es
->line_count
- vlc
;
2165 if(max_y_offset
< 0) max_y_offset
= 0;
2166 if(es
->y_offset
> max_y_offset
)
2167 es
->y_offset
= max_y_offset
;
2169 /* force scroll info update */
2170 EDIT_UpdateScrollInfo(es
);
2173 /* Windows doesn't care to fix text placement for SL controls */
2174 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2176 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2177 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2181 /*********************************************************************
2186 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2188 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2190 /* Edit window might be already destroyed */
2191 if(!IsWindow(es
->hwndSelf
))
2193 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2197 if (!es
->lock_count
) {
2198 ERR("lock_count == 0 ... please report\n");
2202 ERR("es->text == 0 ... please report\n");
2206 if (force
|| (es
->lock_count
== 1)) {
2209 BOOL _16bit
= FALSE
;
2211 UINT countW
= strlenW(es
->text
) + 1;
2215 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2216 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2217 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2218 countA
= LocalSize(es
->hloc32A
);
2219 if(countA_new
> countA
)
2222 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2223 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2224 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2227 es
->hloc32A
= hloc32A_new
;
2228 countA
= LocalSize(hloc32A_new
);
2229 TRACE("Real new size %d bytes\n", countA
);
2232 WARN("FAILED! Will synchronize partially\n");
2234 textA
= LocalLock(es
->hloc32A
);
2238 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2239 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2240 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2241 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2242 if(countA_new
> countA
)
2244 HLOCAL16 hloc16_new
;
2245 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2246 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2247 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2250 es
->hloc16
= hloc16_new
;
2251 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2252 TRACE("Real new size %d bytes\n", countA
);
2255 WARN("FAILED! Will synchronize partially\n");
2257 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2263 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2265 LOCAL_Unlock(hInstance
, es
->hloc16
);
2267 LocalUnlock(es
->hloc32A
);
2270 LocalUnlock(es
->hloc32W
);
2274 ERR("no buffer ... please report\n");
2282 /*********************************************************************
2284 * EDIT_UpdateScrollInfo
2287 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2289 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2292 si
.cbSize
= sizeof(SCROLLINFO
);
2293 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2295 si
.nMax
= es
->line_count
- 1;
2296 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2297 si
.nPos
= es
->y_offset
;
2298 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2299 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2300 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2303 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2306 si
.cbSize
= sizeof(SCROLLINFO
);
2307 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2309 si
.nMax
= es
->text_width
- 1;
2310 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2311 si
.nPos
= es
->x_offset
;
2312 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2313 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2314 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2318 /*********************************************************************
2320 * EDIT_WordBreakProc
2322 * Find the beginning of words.
2323 * Note: unlike the specs for a WordBreakProc, this function only
2324 * allows to be called without linebreaks between s[0] upto
2325 * s[count - 1]. Remember it is only called
2326 * internally, so we can decide this for ourselves.
2329 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2333 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2343 if (s
[index
] == ' ') {
2344 while (index
&& (s
[index
] == ' '))
2347 while (index
&& (s
[index
] != ' '))
2349 if (s
[index
] == ' ')
2353 while (index
&& (s
[index
] != ' '))
2355 if (s
[index
] == ' ')
2365 if (s
[index
] == ' ')
2366 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2368 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2370 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2374 case WB_ISDELIMITER
:
2375 ret
= (s
[index
] == ' ');
2378 ERR("unknown action code, please report !\n");
2385 /*********************************************************************
2389 * returns line number (not index) in high-order word of result.
2390 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2391 * to Richedit, not to the edit control. Original documentation is valid.
2392 * FIXME: do the specs mean to return -1 if outside client area or
2393 * if outside formatting rectangle ???
2396 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2404 GetClientRect(es
->hwndSelf
, &rc
);
2405 if (!PtInRect(&rc
, pt
))
2408 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2409 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2413 /*********************************************************************
2417 * Enable or disable soft breaks.
2419 * This means: insert or remove the soft linebreak character (\r\r\n).
2420 * Take care to check if the text still fits the buffer after insertion.
2421 * If not, notify with EN_ERRSPACE.
2424 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2426 es
->flags
&= ~EF_USE_SOFTBRK
;
2428 es
->flags
|= EF_USE_SOFTBRK
;
2429 FIXME("soft break enabled, not implemented\n");
2435 /*********************************************************************
2439 * Hopefully this won't fire back at us.
2440 * We always start with a fixed buffer in the local heap.
2441 * Despite of the documentation says that the local heap is used
2442 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2443 * buffer on the local heap.
2446 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2450 if (!(es
->style
& ES_MULTILINE
))
2454 hLocal
= es
->hloc32W
;
2460 UINT countA
, alloc_size
;
2461 TRACE("Allocating 32-bit ANSI alias buffer\n");
2462 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2463 alloc_size
= ROUND_TO_GROW(countA
);
2464 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2466 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2469 textA
= LocalLock(es
->hloc32A
);
2470 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2471 LocalUnlock(es
->hloc32A
);
2473 hLocal
= es
->hloc32A
;
2476 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2481 /*********************************************************************
2485 * Hopefully this won't fire back at us.
2486 * We always start with a buffer in 32 bit linear memory.
2487 * However, with this message a 16 bit application requests
2488 * a handle of 16 bit local heap memory, where it expects to find
2490 * It's a pitty that from this moment on we have to use this
2491 * local heap, because applications may rely on the handle
2494 * In this function we'll try to switch to local heap.
2496 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2498 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2500 UINT countA
, alloc_size
;
2502 if (!(es
->style
& ES_MULTILINE
))
2508 if (!LOCAL_HeapSize(hInstance
)) {
2509 if (!LocalInit16(hInstance
, 0,
2510 GlobalSize16(hInstance
))) {
2511 ERR("could not initialize local heap\n");
2514 TRACE("local heap initialized\n");
2517 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2518 alloc_size
= ROUND_TO_GROW(countA
);
2520 TRACE("Allocating 16-bit ANSI alias buffer\n");
2521 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2522 ERR("could not allocate new 16 bit buffer\n");
2526 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2527 ERR("could not lock new 16 bit buffer\n");
2528 LOCAL_Free(hInstance
, es
->hloc16
);
2533 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2534 LOCAL_Unlock(hInstance
, es
->hloc16
);
2536 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2541 /*********************************************************************
2546 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2549 INT line_len
, dst_len
;
2552 if (es
->style
& ES_MULTILINE
) {
2553 if (line
>= es
->line_count
)
2557 i
= EDIT_EM_LineIndex(es
, line
);
2559 line_len
= EDIT_EM_LineLength(es
, i
);
2560 dst_len
= *(WORD
*)lParam
;
2563 LPWSTR dst
= (LPWSTR
)lParam
;
2564 if(dst_len
<= line_len
)
2566 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2569 else /* Append 0 if enough space */
2571 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2578 LPSTR dst
= (LPSTR
)lParam
;
2580 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2581 if(!ret
) /* Insufficient buffer size */
2583 if(ret
< dst_len
) /* Append 0 if enough space */
2590 /*********************************************************************
2595 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2597 UINT s
= es
->selection_start
;
2598 UINT e
= es
->selection_end
;
2605 return MAKELONG(s
, e
);
2609 /*********************************************************************
2613 * FIXME: is this right ? (or should it be only VSCROLL)
2614 * (and maybe only for edit controls that really have their
2615 * own scrollbars) (and maybe only for multiline controls ?)
2616 * All in all: very poorly documented
2619 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2621 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2622 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2626 /*********************************************************************
2631 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2636 if (!(es
->style
& ES_MULTILINE
))
2638 if (index
> (INT
)strlenW(es
->text
))
2639 return es
->line_count
- 1;
2641 index
= min(es
->selection_start
, es
->selection_end
);
2644 line_def
= es
->first_line_def
;
2645 index
-= line_def
->length
;
2646 while ((index
>= 0) && line_def
->next
) {
2648 line_def
= line_def
->next
;
2649 index
-= line_def
->length
;
2655 /*********************************************************************
2660 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2665 if (!(es
->style
& ES_MULTILINE
))
2667 if (line
>= es
->line_count
)
2671 line_def
= es
->first_line_def
;
2673 INT index
= es
->selection_end
- line_def
->length
;
2674 while ((index
>= 0) && line_def
->next
) {
2675 line_index
+= line_def
->length
;
2676 line_def
= line_def
->next
;
2677 index
-= line_def
->length
;
2681 line_index
+= line_def
->length
;
2682 line_def
= line_def
->next
;
2690 /*********************************************************************
2695 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2699 if (!(es
->style
& ES_MULTILINE
))
2700 return strlenW(es
->text
);
2703 /* get the number of remaining non-selected chars of selected lines */
2704 INT32 l
; /* line number */
2705 INT32 li
; /* index of first char in line */
2707 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2708 /* # chars before start of selection area */
2709 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2710 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2711 /* # chars after end of selection */
2712 li
= EDIT_EM_LineIndex(es
, l
);
2713 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2716 line_def
= es
->first_line_def
;
2717 index
-= line_def
->length
;
2718 while ((index
>= 0) && line_def
->next
) {
2719 line_def
= line_def
->next
;
2720 index
-= line_def
->length
;
2722 return line_def
->net_length
;
2726 /*********************************************************************
2730 * NOTE: dx is in average character widths, dy - in lines;
2733 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2735 if (!(es
->style
& ES_MULTILINE
))
2738 dx
*= es
->char_width
;
2739 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2742 /*********************************************************************
2744 * EDIT_EM_LineScroll_internal
2746 * Version of EDIT_EM_LineScroll for internal use.
2747 * It doesn't refuse if ES_MULTILINE is set and assumes that
2748 * dx is in pixels, dy - in lines.
2751 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2754 INT x_offset_in_pixels
;
2756 if (es
->style
& ES_MULTILINE
)
2758 x_offset_in_pixels
= es
->x_offset
;
2763 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2766 if (-dx
> x_offset_in_pixels
)
2767 dx
= -x_offset_in_pixels
;
2768 if (dx
> es
->text_width
- x_offset_in_pixels
)
2769 dx
= es
->text_width
- x_offset_in_pixels
;
2770 nyoff
= max(0, es
->y_offset
+ dy
);
2771 if (nyoff
>= es
->line_count
)
2772 nyoff
= es
->line_count
- 1;
2773 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2778 es
->y_offset
= nyoff
;
2779 if(es
->style
& ES_MULTILINE
)
2782 es
->x_offset
+= dx
/ es
->char_width
;
2784 GetClientRect(es
->hwndSelf
, &rc1
);
2785 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2786 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2787 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2788 /* force scroll info update */
2789 EDIT_UpdateScrollInfo(es
);
2791 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2792 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2793 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2794 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2799 /*********************************************************************
2804 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2806 INT len
= strlenW(es
->text
);
2815 index
= min(index
, len
);
2816 dc
= GetDC(es
->hwndSelf
);
2818 old_font
= SelectObject(dc
, es
->font
);
2819 if (es
->style
& ES_MULTILINE
) {
2820 l
= EDIT_EM_LineFromChar(es
, index
);
2821 y
= (l
- es
->y_offset
) * es
->line_height
;
2822 li
= EDIT_EM_LineIndex(es
, l
);
2823 if (after_wrap
&& (li
== index
) && l
) {
2825 LINEDEF
*line_def
= es
->first_line_def
;
2827 line_def
= line_def
->next
;
2830 if (line_def
->ending
== END_WRAP
) {
2832 y
-= es
->line_height
;
2833 li
= EDIT_EM_LineIndex(es
, l
);
2836 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2837 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2839 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2840 if (index
< es
->x_offset
) {
2841 GetTextExtentPoint32W(dc
, text
+ index
,
2842 es
->x_offset
- index
, &size
);
2845 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2846 index
- es
->x_offset
, &size
);
2850 if (es
->style
& ES_PASSWORD
)
2851 HeapFree(GetProcessHeap(), 0, text
);
2853 x
+= es
->format_rect
.left
;
2854 y
+= es
->format_rect
.top
;
2856 SelectObject(dc
, old_font
);
2857 ReleaseDC(es
->hwndSelf
, dc
);
2858 return MAKELONG((INT16
)x
, (INT16
)y
);
2862 /*********************************************************************
2866 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2869 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2871 UINT strl
= strlenW(lpsz_replace
);
2872 UINT tl
= strlenW(es
->text
);
2880 TRACE("%s, can_undo %d, send_update %d\n",
2881 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2883 s
= es
->selection_start
;
2884 e
= es
->selection_end
;
2886 if ((s
== e
) && !strl
)
2891 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
, honor_limit
))
2895 /* there is something to be deleted */
2896 TRACE("deleting stuff.\n");
2898 utl
= strlenW(es
->undo_text
);
2899 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2900 /* undo-buffer is extended to the right */
2901 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2902 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2903 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2904 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2905 /* undo-buffer is extended to the left */
2906 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2907 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2909 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2910 p
[i
] = (es
->text
+ s
)[i
];
2911 es
->undo_position
= s
;
2913 /* new undo-buffer */
2914 EDIT_MakeUndoFit(es
, e
- s
);
2915 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2916 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2917 es
->undo_position
= s
;
2919 /* any deletion makes the old insertion-undo invalid */
2920 es
->undo_insert_count
= 0;
2922 EDIT_EM_EmptyUndoBuffer(es
);
2925 strcpyW(es
->text
+ s
, es
->text
+ e
);
2928 /* there is an insertion */
2930 if ((s
== es
->undo_position
) ||
2931 ((es
->undo_insert_count
) &&
2932 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2934 * insertion is new and at delete position or
2935 * an extension to either left or right
2937 es
->undo_insert_count
+= strl
;
2939 /* new insertion undo */
2940 es
->undo_position
= s
;
2941 es
->undo_insert_count
= strl
;
2942 /* new insertion makes old delete-buffer invalid */
2943 *es
->undo_text
= '\0';
2946 EDIT_EM_EmptyUndoBuffer(es
);
2949 tl
= strlenW(es
->text
);
2950 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
));
2951 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2953 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2954 p
[i
] = lpsz_replace
[i
];
2955 if(es
->style
& ES_UPPERCASE
)
2956 CharUpperBuffW(p
, strl
);
2957 else if(es
->style
& ES_LOWERCASE
)
2958 CharLowerBuffW(p
, strl
);
2961 if (es
->style
& ES_MULTILINE
)
2963 INT s
= min(es
->selection_start
, es
->selection_end
);
2965 hrgn
= CreateRectRgn(0, 0, 0, 0);
2966 EDIT_BuildLineDefs_ML(es
, s
, s
+ strl
,
2967 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2970 EDIT_CalcLineWidth_SL(es
);
2972 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2973 es
->flags
|= EF_MODIFIED
;
2974 if (send_update
) es
->flags
|= EF_UPDATE
;
2975 EDIT_EM_ScrollCaret(es
);
2977 /* force scroll info update */
2978 EDIT_UpdateScrollInfo(es
);
2982 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2986 EDIT_UpdateText(es
, NULL
, TRUE
);
2988 if(es
->flags
& EF_UPDATE
)
2990 es
->flags
&= ~EF_UPDATE
;
2991 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
2996 /*********************************************************************
3001 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3005 if (!(es
->style
& ES_MULTILINE
))
3006 return (LRESULT
)FALSE
;
3016 if (es
->y_offset
< es
->line_count
- 1)
3021 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3024 if (es
->y_offset
< es
->line_count
- 1)
3025 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3028 return (LRESULT
)FALSE
;
3031 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3032 /* check if we are going to move too far */
3033 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3034 dy
= es
->line_count
- vlc
- es
->y_offset
;
3036 /* Notification is done in EDIT_EM_LineScroll */
3038 EDIT_EM_LineScroll(es
, 0, dy
);
3040 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3044 /*********************************************************************
3049 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3051 if (es
->style
& ES_MULTILINE
) {
3056 INT cw
= es
->char_width
;
3061 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3062 li
= EDIT_EM_LineIndex(es
, l
);
3063 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3064 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3065 if (l
>= es
->y_offset
+ vlc
)
3066 dy
= l
- vlc
+ 1 - es
->y_offset
;
3067 if (l
< es
->y_offset
)
3068 dy
= l
- es
->y_offset
;
3069 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3070 if (x
< es
->format_rect
.left
)
3071 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3072 if (x
> es
->format_rect
.right
)
3073 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3076 /* check if we are going to move too far */
3077 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3078 dx
= es
->text_width
- ww
- es
->x_offset
;
3080 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3087 if (!(es
->style
& ES_AUTOHSCROLL
))
3090 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3091 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3092 if (x
< es
->format_rect
.left
) {
3093 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3096 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3097 } while ((x
< goal
) && es
->x_offset
);
3098 /* FIXME: use ScrollWindow() somehow to improve performance */
3099 EDIT_UpdateText(es
, NULL
, TRUE
);
3100 } else if (x
> es
->format_rect
.right
) {
3102 INT len
= strlenW(es
->text
);
3103 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3106 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3107 x_last
= SLOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3108 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3109 /* FIXME: use ScrollWindow() somehow to improve performance */
3110 EDIT_UpdateText(es
, NULL
, TRUE
);
3114 if(es
->flags
& EF_FOCUSED
)
3115 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3119 /*********************************************************************
3123 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3126 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3128 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3130 if (!(es
->style
& ES_MULTILINE
))
3134 WARN("called with NULL handle\n");
3138 EDIT_UnlockBuffer(es
, TRUE
);
3142 LOCAL_Free(hInstance
, es
->hloc16
);
3143 es
->hloc16
= (HLOCAL16
)NULL
;
3150 LocalFree(es
->hloc32A
);
3162 countA
= LocalSize(hloc
);
3163 textA
= LocalLock(hloc
);
3164 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3165 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3167 ERR("Could not allocate new unicode buffer\n");
3170 textW
= LocalLock(hloc32W_new
);
3171 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3172 LocalUnlock(hloc32W_new
);
3176 LocalFree(es
->hloc32W
);
3178 es
->hloc32W
= hloc32W_new
;
3182 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3184 EDIT_LockBuffer(es
);
3186 es
->x_offset
= es
->y_offset
= 0;
3187 es
->selection_start
= es
->selection_end
= 0;
3188 EDIT_EM_EmptyUndoBuffer(es
);
3189 es
->flags
&= ~EF_MODIFIED
;
3190 es
->flags
&= ~EF_UPDATE
;
3191 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3192 EDIT_UpdateText(es
, NULL
, TRUE
);
3193 EDIT_EM_ScrollCaret(es
);
3194 /* force scroll info update */
3195 EDIT_UpdateScrollInfo(es
);
3199 /*********************************************************************
3203 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3206 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3208 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3214 if (!(es
->style
& ES_MULTILINE
))
3218 WARN("called with NULL handle\n");
3222 EDIT_UnlockBuffer(es
, TRUE
);
3226 LocalFree(es
->hloc32A
);
3230 countA
= LOCAL_Size(hInstance
, hloc
);
3231 textA
= LOCAL_Lock(hInstance
, hloc
);
3232 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3233 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3235 ERR("Could not allocate new unicode buffer\n");
3238 textW
= LocalLock(hloc32W_new
);
3239 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3240 LocalUnlock(hloc32W_new
);
3241 LOCAL_Unlock(hInstance
, hloc
);
3244 LocalFree(es
->hloc32W
);
3246 es
->hloc32W
= hloc32W_new
;
3249 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3251 EDIT_LockBuffer(es
);
3253 es
->x_offset
= es
->y_offset
= 0;
3254 es
->selection_start
= es
->selection_end
= 0;
3255 EDIT_EM_EmptyUndoBuffer(es
);
3256 es
->flags
&= ~EF_MODIFIED
;
3257 es
->flags
&= ~EF_UPDATE
;
3258 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3259 EDIT_UpdateText(es
, NULL
, TRUE
);
3260 EDIT_EM_ScrollCaret(es
);
3261 /* force scroll info update */
3262 EDIT_UpdateScrollInfo(es
);
3266 /*********************************************************************
3270 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3271 * However, the windows version is not complied to yet in all of edit.c
3273 * Additionally as the wrapper for RichEdit controls we need larger buffers
3274 * at present -1 will represent nolimit
3276 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3278 if (limit
== 0xFFFFFFFF)
3279 es
->buffer_limit
= -1;
3280 else if (es
->style
& ES_MULTILINE
) {
3282 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3284 es
->buffer_limit
= BUFLIMIT_MULTI
;
3287 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3289 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3294 /*********************************************************************
3298 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3299 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3300 * of the char's width, according to the new docs.
3303 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3304 INT left
, INT right
)
3306 if (action
& EC_LEFTMARGIN
) {
3307 if (left
!= EC_USEFONTINFO
)
3308 es
->left_margin
= left
;
3310 es
->left_margin
= es
->char_width
/ 3;
3313 if (action
& EC_RIGHTMARGIN
) {
3314 if (right
!= EC_USEFONTINFO
)
3315 es
->right_margin
= right
;
3317 es
->right_margin
= es
->char_width
/ 3;
3319 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3323 /*********************************************************************
3325 * EM_SETPASSWORDCHAR
3328 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3332 if (es
->style
& ES_MULTILINE
)
3335 if (es
->password_char
== c
)
3338 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3339 es
->password_char
= c
;
3341 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3342 es
->style
|= ES_PASSWORD
;
3344 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3345 es
->style
&= ~ES_PASSWORD
;
3347 EDIT_UpdateText(es
, NULL
, TRUE
);
3351 /*********************************************************************
3355 * note: unlike the specs say: the order of start and end
3356 * _is_ preserved in Windows. (i.e. start can be > end)
3357 * In other words: this handler is OK
3360 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3362 UINT old_start
= es
->selection_start
;
3363 UINT old_end
= es
->selection_end
;
3364 UINT len
= strlenW(es
->text
);
3366 if (start
== (UINT
)-1) {
3367 start
= es
->selection_end
;
3368 end
= es
->selection_end
;
3370 start
= min(start
, len
);
3371 end
= min(end
, len
);
3373 es
->selection_start
= start
;
3374 es
->selection_end
= end
;
3376 es
->flags
|= EF_AFTER_WRAP
;
3378 es
->flags
&= ~EF_AFTER_WRAP
;
3379 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3380 ORDER_UINT(start
, end
);
3381 ORDER_UINT(end
, old_end
);
3382 ORDER_UINT(start
, old_start
);
3383 ORDER_UINT(old_start
, old_end
);
3384 if (end
!= old_start
)
3388 * ORDER_UINT32(end, old_start);
3389 * EDIT_InvalidateText(es, start, end);
3390 * EDIT_InvalidateText(es, old_start, old_end);
3391 * in place of the following if statement.
3393 if (old_start
> end
)
3395 EDIT_InvalidateText(es
, start
, end
);
3396 EDIT_InvalidateText(es
, old_start
, old_end
);
3400 EDIT_InvalidateText(es
, start
, old_start
);
3401 EDIT_InvalidateText(es
, end
, old_end
);
3404 else EDIT_InvalidateText(es
, start
, old_end
);
3408 /*********************************************************************
3413 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3415 if (!(es
->style
& ES_MULTILINE
))
3418 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3419 es
->tabs_count
= count
;
3423 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3424 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3430 /*********************************************************************
3435 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3437 if (!(es
->style
& ES_MULTILINE
))
3440 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3441 es
->tabs_count
= count
;
3446 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3447 for (i
= 0 ; i
< count
; i
++)
3448 es
->tabs
[i
] = *tabs
++;
3454 /*********************************************************************
3456 * EM_SETWORDBREAKPROC
3459 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
)
3461 if (es
->word_break_proc
== (void *)lParam
)
3464 es
->word_break_proc
= (void *)lParam
;
3465 es
->word_break_proc16
= NULL
;
3467 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3468 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3469 EDIT_UpdateText(es
, NULL
, TRUE
);
3474 /*********************************************************************
3476 * EM_SETWORDBREAKPROC16
3479 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3481 if (es
->word_break_proc16
== wbp
)
3484 es
->word_break_proc
= NULL
;
3485 es
->word_break_proc16
= wbp
;
3486 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3487 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3488 EDIT_UpdateText(es
, NULL
, TRUE
);
3493 /*********************************************************************
3498 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3503 /* Protect read-only edit control from modification */
3504 if(es
->style
& ES_READONLY
)
3507 ulength
= strlenW(es
->undo_text
);
3508 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3510 strcpyW(utext
, es
->undo_text
);
3512 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3513 es
->undo_insert_count
, debugstr_w(utext
));
3515 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3516 EDIT_EM_EmptyUndoBuffer(es
);
3517 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, FALSE
, TRUE
);
3518 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3519 /* send the notification after the selection start and end are set */
3520 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3521 EDIT_EM_ScrollCaret(es
);
3522 HeapFree(GetProcessHeap(), 0, utext
);
3524 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3525 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3530 /*********************************************************************
3535 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3539 /* Protect read-only edit control from modification */
3540 if(es
->style
& ES_READONLY
)
3543 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3547 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3548 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3551 if (es
->style
& ES_MULTILINE
) {
3552 if (es
->style
& ES_READONLY
) {
3553 EDIT_MoveHome(es
, FALSE
);
3554 EDIT_MoveDown_ML(es
, FALSE
);
3556 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3557 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3562 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3564 static const WCHAR tabW
[] = {'\t',0};
3565 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3569 if (!(es
->style
& ES_READONLY
) && !control
) {
3570 if (es
->selection_start
!= es
->selection_end
)
3573 /* delete character left of caret */
3574 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3575 EDIT_MoveBackward(es
, TRUE
);
3581 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3584 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3587 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3591 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3595 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3602 /*********************************************************************
3607 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3609 if (code
|| control
)
3629 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3630 EDIT_EM_ScrollCaret(es
);
3633 ERR("unknown menu item, please report\n");
3639 /*********************************************************************
3643 * Note: the resource files resource/sysres_??.rc cannot define a
3644 * single popup menu. Hence we use a (dummy) menubar
3645 * containing the single popup menu as its first item.
3647 * FIXME: the message identifiers have been chosen arbitrarily,
3648 * hence we use MF_BYPOSITION.
3649 * We might as well use the "real" values (anybody knows ?)
3650 * The menu definition is in resources/sysres_??.rc.
3651 * Once these are OK, we better use MF_BYCOMMAND here
3652 * (as we do in EDIT_WM_Command()).
3655 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3657 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3658 HMENU popup
= GetSubMenu(menu
, 0);
3659 UINT start
= es
->selection_start
;
3660 UINT end
= es
->selection_end
;
3662 ORDER_UINT(start
, end
);
3665 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3667 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3669 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3671 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3673 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3675 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3677 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3682 /*********************************************************************
3687 static void EDIT_WM_Copy(EDITSTATE
*es
)
3689 INT s
= min(es
->selection_start
, es
->selection_end
);
3690 INT e
= max(es
->selection_start
, es
->selection_end
);
3696 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3697 dst
= GlobalLock(hdst
);
3698 strncpyW(dst
, es
->text
+ s
, e
- s
);
3699 dst
[e
- s
] = 0; /* ensure 0 termination */
3700 TRACE("%s\n", debugstr_w(dst
));
3702 OpenClipboard(es
->hwndSelf
);
3704 SetClipboardData(CF_UNICODETEXT
, hdst
);
3709 /*********************************************************************
3714 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3716 TRACE("%s\n", debugstr_w(name
));
3718 * To initialize some final structure members, we call some helper
3719 * functions. However, since the EDITSTATE is not consistent (i.e.
3720 * not fully initialized), we should be very careful which
3721 * functions can be called, and in what order.
3723 EDIT_WM_SetFont(es
, 0, FALSE
);
3724 EDIT_EM_EmptyUndoBuffer(es
);
3726 if (name
&& *name
) {
3727 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3728 /* if we insert text to the editline, the text scrolls out
3729 * of the window, as the caret is placed after the insert
3730 * pos normally; thus we reset es->selection... to 0 and
3733 es
->selection_start
= es
->selection_end
= 0;
3734 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3735 * Messages are only to be sent when the USER does something to
3736 * change the contents. So I am removing this EN_CHANGE
3738 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3740 EDIT_EM_ScrollCaret(es
);
3742 /* force scroll info update */
3743 EDIT_UpdateScrollInfo(es
);
3748 /*********************************************************************
3753 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
3758 while (LocalUnlock(es
->hloc32W
)) ;
3759 LocalFree(es
->hloc32W
);
3762 while (LocalUnlock(es
->hloc32A
)) ;
3763 LocalFree(es
->hloc32A
);
3766 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
3767 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3768 LOCAL_Free(hInstance
, es
->hloc16
);
3771 pc
= es
->first_line_def
;
3775 HeapFree(GetProcessHeap(), 0, pc
);
3779 SetWindowLongW( es
->hwndSelf
, 0, 0 );
3780 HeapFree(GetProcessHeap(), 0, es
);
3786 /*********************************************************************
3791 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
3796 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
3797 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3799 GetClientRect(es
->hwndSelf
, &rc
);
3800 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3801 GetClipBox(dc
, &rc
);
3803 * FIXME: specs say that we should UnrealizeObject() the brush,
3804 * but the specs of UnrealizeObject() say that we shouldn't
3805 * unrealize a stock object. The default brush that
3806 * DefWndProc() returns is ... a stock object.
3808 FillRect(dc
, &rc
, brush
);
3813 /*********************************************************************
3818 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3820 if(!count
) return 0;
3824 LPWSTR textW
= (LPWSTR
)lParam
;
3825 lstrcpynW(textW
, es
->text
, count
);
3826 return strlenW(textW
);
3830 LPSTR textA
= (LPSTR
)lParam
;
3831 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3832 textA
[count
- 1] = 0; /* ensure 0 termination */
3833 return strlen(textA
);
3837 /*********************************************************************
3842 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3847 if (!(es
->style
& ES_MULTILINE
))
3850 if (!(es
->style
& ES_AUTOHSCROLL
))
3854 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3857 TRACE("SB_LINELEFT\n");
3859 dx
= -es
->char_width
;
3862 TRACE("SB_LINERIGHT\n");
3863 if (es
->x_offset
< es
->text_width
)
3864 dx
= es
->char_width
;
3867 TRACE("SB_PAGELEFT\n");
3869 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3872 TRACE("SB_PAGERIGHT\n");
3873 if (es
->x_offset
< es
->text_width
)
3874 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3882 TRACE("SB_RIGHT\n");
3883 if (es
->x_offset
< es
->text_width
)
3884 dx
= es
->text_width
- es
->x_offset
;
3887 TRACE("SB_THUMBTRACK %d\n", pos
);
3888 es
->flags
|= EF_HSCROLL_TRACK
;
3889 if(es
->style
& WS_HSCROLL
)
3890 dx
= pos
- es
->x_offset
;
3895 if(pos
< 0 || pos
> 100) return 0;
3896 /* Assume default scroll range 0-100 */
3897 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3898 new_x
= pos
* (es
->text_width
- fw
) / 100;
3899 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3902 case SB_THUMBPOSITION
:
3903 TRACE("SB_THUMBPOSITION %d\n", pos
);
3904 es
->flags
&= ~EF_HSCROLL_TRACK
;
3905 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3906 dx
= pos
- es
->x_offset
;
3911 if(pos
< 0 || pos
> 100) return 0;
3912 /* Assume default scroll range 0-100 */
3913 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3914 new_x
= pos
* (es
->text_width
- fw
) / 100;
3915 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3918 /* force scroll info update */
3919 EDIT_UpdateScrollInfo(es
);
3920 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
3924 TRACE("SB_ENDSCROLL\n");
3927 * FIXME : the next two are undocumented !
3928 * Are we doing the right thing ?
3929 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3930 * although it's also a regular control message.
3932 case EM_GETTHUMB
: /* this one is used by NT notepad */
3936 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3937 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3940 /* Assume default scroll range 0-100 */
3941 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3942 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3944 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3947 case EM_LINESCROLL16
:
3948 TRACE("EM_LINESCROLL16\n");
3953 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3959 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3960 /* check if we are going to move too far */
3961 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3962 dx
= es
->text_width
- fw
- es
->x_offset
;
3964 EDIT_EM_LineScroll_internal(es
, dx
, 0);
3970 /*********************************************************************
3975 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3977 HWND hLBox
= es
->hwndListBox
;
3985 hCombo
= GetParent(es
->hwndSelf
);
3989 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3991 if (key
== VK_UP
|| key
== VK_DOWN
)
3993 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3996 if (msg
== WM_KEYDOWN
|| nEUI
)
3997 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4003 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4005 /* make sure ComboLBox pops up */
4006 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4011 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4014 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4016 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4018 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4023 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4029 /*********************************************************************
4033 * Handling of special keys that don't produce a WM_CHAR
4034 * (i.e. non-printable keys) & Backspace & Delete
4037 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4042 if (GetKeyState(VK_MENU
) & 0x8000)
4045 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4046 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4051 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4056 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4057 EDIT_MoveUp_ML(es
, shift
);
4060 EDIT_MoveWordBackward(es
, shift
);
4062 EDIT_MoveBackward(es
, shift
);
4065 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4069 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4070 EDIT_MoveDown_ML(es
, shift
);
4072 EDIT_MoveWordForward(es
, shift
);
4074 EDIT_MoveForward(es
, shift
);
4077 EDIT_MoveHome(es
, shift
);
4080 EDIT_MoveEnd(es
, shift
);
4083 if (es
->style
& ES_MULTILINE
)
4084 EDIT_MovePageUp_ML(es
, shift
);
4086 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4089 if (es
->style
& ES_MULTILINE
)
4090 EDIT_MovePageDown_ML(es
, shift
);
4092 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4095 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4096 if (es
->selection_start
!= es
->selection_end
) {
4103 /* delete character left of caret */
4104 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4105 EDIT_MoveBackward(es
, TRUE
);
4107 } else if (control
) {
4108 /* delete to end of line */
4109 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4110 EDIT_MoveEnd(es
, TRUE
);
4113 /* delete character right of caret */
4114 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4115 EDIT_MoveForward(es
, TRUE
);
4123 if (!(es
->style
& ES_READONLY
))
4129 /* If the edit doesn't want the return send a message to the default object */
4130 if(!(es
->style
& ES_WANTRETURN
))
4132 HWND hwndParent
= GetParent(es
->hwndSelf
);
4133 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4134 if (HIWORD(dw
) == DC_HASDEFID
)
4136 SendMessageW( hwndParent
, WM_COMMAND
,
4137 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4138 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4147 /*********************************************************************
4152 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4154 es
->flags
&= ~EF_FOCUSED
;
4156 if(!(es
->style
& ES_NOHIDESEL
))
4157 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4158 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4163 /*********************************************************************
4167 * The caret position has been set on the WM_LBUTTONDOWN message
4170 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4173 INT e
= es
->selection_end
;
4178 if (!(es
->flags
& EF_FOCUSED
))
4181 l
= EDIT_EM_LineFromChar(es
, e
);
4182 li
= EDIT_EM_LineIndex(es
, l
);
4183 ll
= EDIT_EM_LineLength(es
, e
);
4184 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4185 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4186 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4187 EDIT_EM_ScrollCaret(es
);
4192 /*********************************************************************
4197 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4202 if (!(es
->flags
& EF_FOCUSED
))
4205 es
->bCaptureState
= TRUE
;
4206 SetCapture(es
->hwndSelf
);
4207 EDIT_ConfinePoint(es
, &x
, &y
);
4208 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4209 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4210 EDIT_EM_ScrollCaret(es
);
4211 es
->region_posx
= es
->region_posy
= 0;
4212 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4217 /*********************************************************************
4222 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4224 if (es
->bCaptureState
) {
4225 KillTimer(es
->hwndSelf
, 0);
4226 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4228 es
->bCaptureState
= FALSE
;
4233 /*********************************************************************
4238 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4240 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4245 /*********************************************************************
4250 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4256 if (GetCapture() != es
->hwndSelf
)
4260 * FIXME: gotta do some scrolling if outside client
4261 * area. Maybe reset the timer ?
4264 EDIT_ConfinePoint(es
, &x
, &y
);
4265 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4266 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4267 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4268 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4269 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4274 /*********************************************************************
4278 * See also EDIT_WM_StyleChanged
4280 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4285 TRACE("Creating %s edit control, style = %08lx\n",
4286 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4288 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4290 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4293 * Note: since the EDITSTATE has not been fully initialized yet,
4294 * we can't use any API calls that may send
4295 * WM_XXX messages before WM_NCCREATE is completed.
4298 es
->is_unicode
= unicode
;
4299 es
->style
= lpcs
->style
;
4301 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4303 es
->hwndSelf
= hwnd
;
4304 /* Save parent, which will be notified by EN_* messages */
4305 es
->hwndParent
= lpcs
->hwndParent
;
4307 if (es
->style
& ES_COMBO
)
4308 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4310 /* Number overrides lowercase overrides uppercase (at least it
4311 * does in Win95). However I'll bet that ES_NUMBER would be
4312 * invalid under Win 3.1.
4314 if (es
->style
& ES_NUMBER
) {
4315 ; /* do not override the ES_NUMBER */
4316 } else if (es
->style
& ES_LOWERCASE
) {
4317 es
->style
&= ~ES_UPPERCASE
;
4319 if (es
->style
& ES_MULTILINE
) {
4320 es
->buffer_limit
= BUFLIMIT_MULTI
;
4321 if (es
->style
& WS_VSCROLL
)
4322 es
->style
|= ES_AUTOVSCROLL
;
4323 if (es
->style
& WS_HSCROLL
)
4324 es
->style
|= ES_AUTOHSCROLL
;
4325 es
->style
&= ~ES_PASSWORD
;
4326 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4327 /* Confirmed - RIGHT overrides CENTER */
4328 if (es
->style
& ES_RIGHT
)
4329 es
->style
&= ~ES_CENTER
;
4330 es
->style
&= ~WS_HSCROLL
;
4331 es
->style
&= ~ES_AUTOHSCROLL
;
4334 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4335 es
->style
|= ES_AUTOVSCROLL
;
4337 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4338 if (WIN31_LOOK
== TWEAK_WineLook
||
4339 WIN95_LOOK
== TWEAK_WineLook
) {
4340 es
->style
&= ~ES_CENTER
;
4341 es
->style
&= ~ES_RIGHT
;
4343 if (es
->style
& ES_RIGHT
)
4344 es
->style
&= ~ES_CENTER
;
4346 es
->style
&= ~WS_HSCROLL
;
4347 es
->style
&= ~WS_VSCROLL
;
4348 es
->style
&= ~ES_AUTOVSCROLL
;
4349 es
->style
&= ~ES_WANTRETURN
;
4350 if (es
->style
& ES_PASSWORD
)
4351 es
->password_char
= '*';
4353 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4354 es
->style
|= ES_AUTOHSCROLL
;
4357 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4358 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4360 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4362 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4364 es
->undo_buffer_size
= es
->buffer_size
;
4366 if (es
->style
& ES_MULTILINE
)
4367 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4372 * In Win95 look and feel, the WS_BORDER style is replaced by the
4373 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4374 * control a non client area. Not always. This coordinates in some
4375 * way with the window creation code in dialog.c When making
4376 * modifications please ensure that the code still works for edit
4377 * controls created directly with style 0x50800000, exStyle 0 (
4378 * which should have a single pixel border)
4380 if (TWEAK_WineLook
!= WIN31_LOOK
)
4382 es
->style
&= ~WS_BORDER
;
4386 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4387 SetWindowLongW( hwnd
, GWL_STYLE
,
4388 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4394 /*********************************************************************
4399 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
)
4408 BOOL rev
= es
->bEnableState
&&
4409 ((es
->flags
& EF_FOCUSED
) ||
4410 (es
->style
& ES_NOHIDESEL
));
4412 dc
= BeginPaint(es
->hwndSelf
, &ps
);
4415 if(es
->style
& WS_BORDER
) {
4416 GetClientRect(es
->hwndSelf
, &rc
);
4417 if(es
->style
& ES_MULTILINE
) {
4418 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4419 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4421 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4423 IntersectClipRect(dc
, es
->format_rect
.left
,
4424 es
->format_rect
.top
,
4425 es
->format_rect
.right
,
4426 es
->format_rect
.bottom
);
4427 if (es
->style
& ES_MULTILINE
) {
4428 GetClientRect(es
->hwndSelf
, &rc
);
4429 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4432 old_font
= SelectObject(dc
, es
->font
);
4433 EDIT_NotifyCtlColor(es
, dc
);
4435 if (!es
->bEnableState
)
4436 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4437 GetClipBox(dc
, &rcRgn
);
4438 if (es
->style
& ES_MULTILINE
) {
4439 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4440 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4441 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4442 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4443 EDIT_PaintLine(es
, dc
, i
, rev
);
4446 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4447 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4448 EDIT_PaintLine(es
, dc
, 0, rev
);
4451 SelectObject(dc
, old_font
);
4454 EndPaint(es
->hwndSelf
, &ps
);
4458 /*********************************************************************
4463 static void EDIT_WM_Paste(EDITSTATE
*es
)
4468 /* Protect read-only edit control from modification */
4469 if(es
->style
& ES_READONLY
)
4472 OpenClipboard(es
->hwndSelf
);
4473 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4474 src
= (LPWSTR
)GlobalLock(hsrc
);
4475 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4482 /*********************************************************************
4487 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4489 es
->flags
|= EF_FOCUSED
;
4490 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4491 EDIT_SetCaretPos(es
, es
->selection_end
,
4492 es
->flags
& EF_AFTER_WRAP
);
4493 if(!(es
->style
& ES_NOHIDESEL
))
4494 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4495 ShowCaret(es
->hwndSelf
);
4496 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4500 /*********************************************************************
4504 * With Win95 look the margins are set to default font value unless
4505 * the system font (font == 0) is being set, in which case they are left
4509 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4517 dc
= GetDC(es
->hwndSelf
);
4519 old_font
= SelectObject(dc
, font
);
4520 GetTextMetricsW(dc
, &tm
);
4521 es
->line_height
= tm
.tmHeight
;
4522 es
->char_width
= tm
.tmAveCharWidth
;
4524 SelectObject(dc
, old_font
);
4525 ReleaseDC(es
->hwndSelf
, dc
);
4526 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4527 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4528 EC_USEFONTINFO
, EC_USEFONTINFO
);
4530 /* Force the recalculation of the format rect for each font change */
4531 GetClientRect(es
->hwndSelf
, &r
);
4532 EDIT_SetRectNP(es
, &r
);
4534 if (es
->style
& ES_MULTILINE
)
4535 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4537 EDIT_CalcLineWidth_SL(es
);
4540 EDIT_UpdateText(es
, NULL
, TRUE
);
4541 if (es
->flags
& EF_FOCUSED
) {
4543 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4544 EDIT_SetCaretPos(es
, es
->selection_end
,
4545 es
->flags
& EF_AFTER_WRAP
);
4546 ShowCaret(es
->hwndSelf
);
4551 /*********************************************************************
4556 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4557 * The modified flag is reset. No notifications are sent.
4559 * For single-line controls, reception of WM_SETTEXT triggers:
4560 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4563 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4568 text
= (LPWSTR
)lParam
;
4571 LPCSTR textA
= (LPCSTR
)lParam
;
4572 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4573 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4574 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4577 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4579 TRACE("%s\n", debugstr_w(text
));
4580 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4582 HeapFree(GetProcessHeap(), 0, text
);
4584 static const WCHAR empty_stringW
[] = {0};
4586 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4589 es
->flags
&= ~EF_MODIFIED
;
4590 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4591 /* Send the notification after the selection start and end have been set
4592 * edit control doesn't send notification on WM_SETTEXT
4593 * if it is multiline, or it is part of combobox
4595 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4597 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4598 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4600 EDIT_EM_ScrollCaret(es
);
4604 /*********************************************************************
4609 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4611 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4613 TRACE("width = %d, height = %d\n", width
, height
);
4614 SetRect(&rc
, 0, 0, width
, height
);
4615 EDIT_SetRectNP(es
, &rc
);
4616 EDIT_UpdateText(es
, NULL
, TRUE
);
4621 /*********************************************************************
4625 * This message is sent by SetWindowLong on having changed either the Style
4626 * or the extended style.
4628 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4630 * See also EDIT_WM_NCCreate
4632 * It appears that the Windows version of the edit control allows the style
4633 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4634 * style variable which will generally be different. In this function we
4635 * update the internal style based on what changed in the externally visible
4638 * Much of this content as based upon the MSDN, especially:
4639 * Platform SDK Documentation -> User Interface Services ->
4640 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4641 * Edit Control Styles
4643 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4645 if (GWL_STYLE
== which
) {
4646 DWORD style_change_mask
;
4648 /* Only a subset of changes can be applied after the control
4651 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4653 if (es
->style
& ES_MULTILINE
)
4654 style_change_mask
|= ES_WANTRETURN
;
4656 new_style
= style
->styleNew
& style_change_mask
;
4658 /* Number overrides lowercase overrides uppercase (at least it
4659 * does in Win95). However I'll bet that ES_NUMBER would be
4660 * invalid under Win 3.1.
4662 if (new_style
& ES_NUMBER
) {
4663 ; /* do not override the ES_NUMBER */
4664 } else if (new_style
& ES_LOWERCASE
) {
4665 new_style
&= ~ES_UPPERCASE
;
4668 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4669 } else if (GWL_EXSTYLE
== which
) {
4670 ; /* FIXME - what is needed here */
4672 WARN ("Invalid style change %d\n",which
);
4678 /*********************************************************************
4683 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4685 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4686 if (EDIT_EM_CanUndo(es
))
4689 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4690 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4693 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4697 /*********************************************************************
4702 static void EDIT_WM_Timer(EDITSTATE
*es
)
4704 if (es
->region_posx
< 0) {
4705 EDIT_MoveBackward(es
, TRUE
);
4706 } else if (es
->region_posx
> 0) {
4707 EDIT_MoveForward(es
, TRUE
);
4710 * FIXME: gotta do some vertical scrolling here, like
4711 * EDIT_EM_LineScroll(hwnd, 0, 1);
4715 /*********************************************************************
4720 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4724 if (!(es
->style
& ES_MULTILINE
))
4727 if (!(es
->style
& ES_AUTOVSCROLL
))
4736 TRACE("action %d\n", action
);
4737 EDIT_EM_Scroll(es
, action
);
4744 TRACE("SB_BOTTOM\n");
4745 dy
= es
->line_count
- 1 - es
->y_offset
;
4748 TRACE("SB_THUMBTRACK %d\n", pos
);
4749 es
->flags
|= EF_VSCROLL_TRACK
;
4750 if(es
->style
& WS_VSCROLL
)
4751 dy
= pos
- es
->y_offset
;
4754 /* Assume default scroll range 0-100 */
4757 if(pos
< 0 || pos
> 100) return 0;
4758 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4759 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4760 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4761 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4762 es
->line_count
, es
->y_offset
, pos
, dy
);
4765 case SB_THUMBPOSITION
:
4766 TRACE("SB_THUMBPOSITION %d\n", pos
);
4767 es
->flags
&= ~EF_VSCROLL_TRACK
;
4768 if(es
->style
& WS_VSCROLL
)
4769 dy
= pos
- es
->y_offset
;
4772 /* Assume default scroll range 0-100 */
4775 if(pos
< 0 || pos
> 100) return 0;
4776 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4777 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4778 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4779 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4780 es
->line_count
, es
->y_offset
, pos
, dy
);
4784 /* force scroll info update */
4785 EDIT_UpdateScrollInfo(es
);
4786 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4790 TRACE("SB_ENDSCROLL\n");
4793 * FIXME : the next two are undocumented !
4794 * Are we doing the right thing ?
4795 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4796 * although it's also a regular control message.
4798 case EM_GETTHUMB
: /* this one is used by NT notepad */
4802 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4803 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4806 /* Assume default scroll range 0-100 */
4807 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4808 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4810 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4813 case EM_LINESCROLL16
:
4814 TRACE("EM_LINESCROLL16 %d\n", pos
);
4819 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4824 EDIT_EM_LineScroll(es
, 0, dy
);
4828 /*********************************************************************
4833 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4835 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4836 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
4840 /*********************************************************************
4845 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4847 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4848 InvalidateRect(es
->hwndSelf
, rc
, bErase
);