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");
1036 ReleaseDC(es
->hwndSelf
, dc
);
1040 /* Remember start of modifications in order to calculate update region */
1041 nstart_line
= line_index
;
1042 nstart_index
= current_line
->index
;
1044 /* We must start to reformat from the previous line since the modifications
1045 * may have caused the line to wrap upwards. */
1046 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1049 current_line
= previous_line
;
1051 start_line
= current_line
;
1053 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1054 current_position
= es
->text
+ current_line
->index
;
1056 if (current_line
!= start_line
)
1058 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1060 /* The buffer has been expanded, create a new line and
1061 insert it into the link list */
1062 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1063 new_line
->next
= previous_line
->next
;
1064 previous_line
->next
= new_line
;
1065 current_line
= new_line
;
1068 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1070 /* The previous line merged with this line so we delete this extra entry */
1071 previous_line
->next
= current_line
->next
;
1072 HeapFree(GetProcessHeap(), 0, current_line
);
1073 current_line
= previous_line
->next
;
1077 else /* current_line->index + delta == current_position */
1079 if (current_position
- es
->text
> iend
)
1080 break; /* We reached end of line modifications */
1081 /* else recalulate this line */
1085 current_line
->index
= current_position
- es
->text
;
1086 orig_net_length
= current_line
->net_length
;
1088 /* Find end of line */
1089 cp
= current_position
;
1091 if (*cp
== '\n') break;
1092 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1097 /* Mark type of line termination */
1099 current_line
->ending
= END_0
;
1100 current_line
->net_length
= strlenW(current_position
);
1101 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1102 current_line
->ending
= END_SOFT
;
1103 current_line
->net_length
= cp
- current_position
- 1;
1104 } else if (*cp
== '\n') {
1105 current_line
->ending
= END_RICH
;
1106 current_line
->net_length
= cp
- current_position
;
1108 current_line
->ending
= END_HARD
;
1109 current_line
->net_length
= cp
- current_position
;
1112 /* Calculate line width */
1113 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1114 current_position
, current_line
->net_length
,
1115 es
->tabs_count
, es
->tabs
));
1117 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1118 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1123 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1124 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1125 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1126 current_position
, next
, es
->tabs_count
, es
->tabs
));
1127 } while (current_line
->width
<= fw
);
1128 if (!prev
) { /* Didn't find a line break so force a break */
1133 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1134 current_position
, next
, es
->tabs_count
, es
->tabs
));
1135 } while (current_line
->width
<= fw
);
1140 /* If the first line we are calculating, wrapped before istart, we must
1141 * adjust istart in order for this to be reflected in the update region. */
1142 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1143 istart
= current_line
->index
+ prev
;
1144 /* else if we are updating the previous line before the first line we
1145 * are re-calculating and it expanded */
1146 else if (current_line
== start_line
&&
1147 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1149 /* Line expanded due to an upwards line wrap so we must partially include
1150 * previous line in update region */
1151 nstart_line
= line_index
;
1152 nstart_index
= current_line
->index
;
1153 istart
= current_line
->index
+ orig_net_length
;
1156 current_line
->net_length
= prev
;
1157 current_line
->ending
= END_WRAP
;
1158 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1159 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1163 /* Adjust length to include line termination */
1164 switch (current_line
->ending
) {
1166 current_line
->length
= current_line
->net_length
+ 3;
1169 current_line
->length
= current_line
->net_length
+ 1;
1172 current_line
->length
= current_line
->net_length
+ 2;
1176 current_line
->length
= current_line
->net_length
;
1179 es
->text_width
= max(es
->text_width
, current_line
->width
);
1180 current_position
+= current_line
->length
;
1181 previous_line
= current_line
;
1182 current_line
= current_line
->next
;
1184 } while (previous_line
->ending
!= END_0
);
1186 /* Finish adjusting line indexes by delta or remove hanging lines */
1187 if (previous_line
->ending
== END_0
)
1189 LINEDEF
*pnext
= NULL
;
1191 previous_line
->next
= NULL
;
1192 while (current_line
)
1194 pnext
= current_line
->next
;
1195 HeapFree(GetProcessHeap(), 0, current_line
);
1196 current_line
= pnext
;
1202 while (current_line
)
1204 current_line
->index
+= delta
;
1205 current_line
= current_line
->next
;
1209 /* Calculate rest of modification rectangle */
1214 * We calculate two rectangles. One for the first line which may have
1215 * an indent with respect to the format rect. The other is a format-width
1216 * rectangle that spans the rest of the lines that changed or moved.
1218 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1219 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1220 rc
.bottom
= rc
.top
+ es
->line_height
;
1221 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1222 es
->text
+ nstart_index
, istart
- nstart_index
,
1223 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1224 rc
.right
= es
->format_rect
.right
;
1225 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1228 rc
.left
= es
->format_rect
.left
;
1229 rc
.right
= es
->format_rect
.right
;
1231 * If lines were added or removed we must re-paint the remainder of the
1232 * lines since the remaining lines were either shifted up or down.
1234 if (line_count
< es
->line_count
) /* We added lines */
1235 rc
.bottom
= es
->line_count
* es
->line_height
;
1236 else if (line_count
> es
->line_count
) /* We removed lines */
1237 rc
.bottom
= line_count
* es
->line_height
;
1239 rc
.bottom
= line_index
* es
->line_height
;
1240 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1241 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1242 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1243 DeleteObject(tmphrgn
);
1247 SelectObject(dc
, old_font
);
1249 ReleaseDC(es
->hwndSelf
, dc
);
1252 /*********************************************************************
1254 * EDIT_CalcLineWidth_SL
1257 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1259 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(es
, strlenW(es
->text
), FALSE
));
1262 /*********************************************************************
1264 * EDIT_CallWordBreakProc
1266 * Call appropriate WordBreakProc (internal or external).
1268 * Note: The "start" argument should always be an index referring
1269 * to es->text. The actual wordbreak proc might be
1270 * 16 bit, so we can't always pass any 32 bit LPSTR.
1271 * Hence we assume that es->text is the buffer that holds
1272 * the string under examination (we can decide this for ourselves).
1275 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1277 INT ret
, iWndsLocks
;
1279 /* To avoid any deadlocks, all the locks on the window structures
1280 must be suspended before the control is passed to the application */
1281 iWndsLocks
= WIN_SuspendWndsLock();
1283 if (es
->word_break_proc16
) {
1290 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1291 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1292 segptr
= K32WOWGlobalLock16(hglob16
);
1293 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1294 args
[4] = SELECTOROF(segptr
);
1295 args
[3] = OFFSETOF(segptr
);
1299 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1300 ret
= LOWORD(result
);
1301 GlobalUnlock16(hglob16
);
1302 GlobalFree16(hglob16
);
1304 else if (es
->word_break_proc
)
1308 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1310 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1311 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1312 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1316 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1320 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1321 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1322 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1323 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1324 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1325 ret
= wbpA(textA
, index
, countA
, action
);
1326 HeapFree(GetProcessHeap(), 0, textA
);
1330 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1332 WIN_RestoreWndsLock(iWndsLocks
);
1337 /*********************************************************************
1341 * Beware: This is not the function called on EM_CHARFROMPOS
1342 * The position _can_ be outside the formatting / client
1344 * The return value is only the character index
1347 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1353 if (es
->style
& ES_MULTILINE
) {
1354 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1356 LINEDEF
*line_def
= es
->first_line_def
;
1358 while ((line
> 0) && line_def
->next
) {
1359 line_index
+= line_def
->length
;
1360 line_def
= line_def
->next
;
1363 x
+= es
->x_offset
- es
->format_rect
.left
;
1364 if (x
>= line_def
->width
) {
1366 *after_wrap
= (line_def
->ending
== END_WRAP
);
1367 return line_index
+ line_def
->net_length
;
1371 *after_wrap
= FALSE
;
1374 dc
= GetDC(es
->hwndSelf
);
1376 old_font
= SelectObject(dc
, es
->font
);
1377 low
= line_index
+ 1;
1378 high
= line_index
+ line_def
->net_length
+ 1;
1379 while (low
< high
- 1)
1381 INT mid
= (low
+ high
) / 2;
1382 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1388 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1389 (line_def
->ending
== END_WRAP
));
1394 *after_wrap
= FALSE
;
1395 x
-= es
->format_rect
.left
;
1397 return es
->x_offset
;
1398 text
= EDIT_GetPasswordPointer_SL(es
);
1399 dc
= GetDC(es
->hwndSelf
);
1401 old_font
= SelectObject(dc
, es
->font
);
1405 INT high
= es
->x_offset
;
1406 while (low
< high
- 1)
1408 INT mid
= (low
+ high
) / 2;
1409 GetTextExtentPoint32W( dc
, text
+ mid
,
1410 es
->x_offset
- mid
, &size
);
1411 if (size
.cx
> -x
) low
= mid
;
1418 INT low
= es
->x_offset
;
1419 INT high
= strlenW(es
->text
) + 1;
1420 while (low
< high
- 1)
1422 INT mid
= (low
+ high
) / 2;
1423 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1424 mid
- es
->x_offset
, &size
);
1425 if (size
.cx
> x
) high
= mid
;
1430 if (es
->style
& ES_PASSWORD
)
1431 HeapFree(GetProcessHeap(), 0, text
);
1434 SelectObject(dc
, old_font
);
1435 ReleaseDC(es
->hwndSelf
, dc
);
1440 /*********************************************************************
1444 * adjusts the point to be within the formatting rectangle
1445 * (so CharFromPos returns the nearest _visible_ character)
1448 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1450 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1451 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1455 /*********************************************************************
1459 * Calculates the bounding rectangle for a line from a starting
1460 * column to an ending column.
1463 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1465 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1467 if (es
->style
& ES_MULTILINE
)
1468 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1470 rc
->top
= es
->format_rect
.top
;
1471 rc
->bottom
= rc
->top
+ es
->line_height
;
1472 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1473 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1477 /*********************************************************************
1479 * EDIT_GetPasswordPointer_SL
1481 * note: caller should free the (optionally) allocated buffer
1484 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1486 if (es
->style
& ES_PASSWORD
) {
1487 INT len
= strlenW(es
->text
);
1488 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1490 while(len
) text
[--len
] = es
->password_char
;
1497 /*********************************************************************
1501 * This acts as a LOCAL_Lock(), but it locks only once. This way
1502 * you can call it whenever you like, without unlocking.
1504 * Initially the edit control allocates a HLOCAL32 buffer
1505 * (32 bit linear memory handler). However, 16 bit application
1506 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1507 * handler). From that moment on we have to keep using this 16 bit memory
1508 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1509 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1513 static void EDIT_LockBuffer(EDITSTATE
*es
)
1515 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1519 BOOL _16bit
= FALSE
;
1525 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1526 textA
= LocalLock(es
->hloc32A
);
1527 countA
= strlen(textA
) + 1;
1531 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1532 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1533 countA
= strlen(textA
) + 1;
1538 ERR("no buffer ... please report\n");
1545 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1546 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1547 if(countW_new
> es
->buffer_size
+ 1)
1549 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1550 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1551 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1554 es
->hloc32W
= hloc32W_new
;
1555 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1556 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1559 WARN("FAILED! Will synchronize partially\n");
1563 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1564 es
->text
= LocalLock(es
->hloc32W
);
1568 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1570 LOCAL_Unlock(hInstance
, es
->hloc16
);
1572 LocalUnlock(es
->hloc32A
);
1579 /*********************************************************************
1581 * EDIT_SL_InvalidateText
1583 * Called from EDIT_InvalidateText().
1584 * Does the job for single-line controls only.
1587 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1592 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1593 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1594 EDIT_UpdateText(es
, &rc
, TRUE
);
1598 /*********************************************************************
1600 * EDIT_ML_InvalidateText
1602 * Called from EDIT_InvalidateText().
1603 * Does the job for multi-line controls only.
1606 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1608 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1609 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1610 INT el
= EDIT_EM_LineFromChar(es
, end
);
1619 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1622 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1623 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1624 if (sl
< es
->y_offset
) {
1628 if (el
> es
->y_offset
+ vlc
) {
1629 el
= es
->y_offset
+ vlc
;
1630 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1632 GetClientRect(es
->hwndSelf
, &rc1
);
1633 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1635 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1636 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1637 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1639 EDIT_GetLineRect(es
, sl
, sc
,
1640 EDIT_EM_LineLength(es
,
1641 EDIT_EM_LineIndex(es
, sl
)),
1643 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1644 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1645 for (l
= sl
+ 1 ; l
< el
; l
++) {
1646 EDIT_GetLineRect(es
, l
, 0,
1647 EDIT_EM_LineLength(es
,
1648 EDIT_EM_LineIndex(es
, l
)),
1650 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1651 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1653 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1654 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1655 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1660 /*********************************************************************
1662 * EDIT_InvalidateText
1664 * Invalidate the text from offset start upto, but not including,
1665 * offset end. Useful for (re)painting the selection.
1666 * Regions outside the linewidth are not invalidated.
1667 * end == -1 means end == TextLength.
1668 * start and end need not be ordered.
1671 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1677 end
= strlenW(es
->text
);
1685 if (es
->style
& ES_MULTILINE
)
1686 EDIT_ML_InvalidateText(es
, start
, end
);
1688 EDIT_SL_InvalidateText(es
, start
, end
);
1692 /*********************************************************************
1696 * Try to fit size + 1 characters in the buffer.
1697 * Constrain to limits if honor_limit is TRUE.
1699 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
)
1703 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
1704 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
1708 if (size
<= es
->buffer_size
)
1711 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1713 /* Force edit to unlock it's buffer. es->text now NULL */
1714 EDIT_UnlockBuffer(es
, TRUE
);
1717 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1718 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1719 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1720 es
->hloc32W
= hNew32W
;
1721 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1725 EDIT_LockBuffer(es
);
1727 if (es
->buffer_size
< size
) {
1728 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1729 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1732 TRACE("We now have %d+1\n", es
->buffer_size
);
1738 /*********************************************************************
1742 * Try to fit size + 1 bytes in the undo buffer.
1745 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1749 if (size
<= es
->undo_buffer_size
)
1752 TRACE("trying to ReAlloc to %d+1\n", size
);
1754 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1755 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1756 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1761 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1767 /*********************************************************************
1772 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1774 INT e
= es
->selection_end
;
1778 if ((es
->style
& ES_MULTILINE
) && e
&&
1779 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1781 if (e
&& (es
->text
[e
- 1] == '\r'))
1785 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1786 EDIT_EM_ScrollCaret(es
);
1790 /*********************************************************************
1794 * Only for multi line controls
1795 * Move the caret one line down, on a column with the nearest
1796 * x coordinate on the screen (might be a different column).
1799 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1801 INT s
= es
->selection_start
;
1802 INT e
= es
->selection_end
;
1803 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1804 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1805 INT x
= SLOWORD(pos
);
1806 INT y
= SHIWORD(pos
);
1808 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1811 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1812 EDIT_EM_ScrollCaret(es
);
1816 /*********************************************************************
1821 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1823 BOOL after_wrap
= FALSE
;
1826 /* Pass a high value in x to make sure of receiving the end of the line */
1827 if (es
->style
& ES_MULTILINE
)
1828 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1829 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1831 e
= strlenW(es
->text
);
1832 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1833 EDIT_EM_ScrollCaret(es
);
1837 /*********************************************************************
1842 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1844 INT e
= es
->selection_end
;
1848 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1849 if (es
->text
[e
] == '\n')
1851 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1855 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1856 EDIT_EM_ScrollCaret(es
);
1860 /*********************************************************************
1864 * Home key: move to beginning of line.
1867 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1871 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1872 if (es
->style
& ES_MULTILINE
)
1873 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1874 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1877 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1878 EDIT_EM_ScrollCaret(es
);
1882 /*********************************************************************
1884 * EDIT_MovePageDown_ML
1886 * Only for multi line controls
1887 * Move the caret one page down, on a column with the nearest
1888 * x coordinate on the screen (might be a different column).
1891 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1893 INT s
= es
->selection_start
;
1894 INT e
= es
->selection_end
;
1895 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1896 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1897 INT x
= SLOWORD(pos
);
1898 INT y
= SHIWORD(pos
);
1900 e
= EDIT_CharFromPos(es
, x
,
1901 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1905 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1906 EDIT_EM_ScrollCaret(es
);
1910 /*********************************************************************
1912 * EDIT_MovePageUp_ML
1914 * Only for multi line controls
1915 * Move the caret one page up, on a column with the nearest
1916 * x coordinate on the screen (might be a different column).
1919 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1921 INT s
= es
->selection_start
;
1922 INT e
= es
->selection_end
;
1923 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1924 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1925 INT x
= SLOWORD(pos
);
1926 INT y
= SHIWORD(pos
);
1928 e
= EDIT_CharFromPos(es
, x
,
1929 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1933 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1934 EDIT_EM_ScrollCaret(es
);
1938 /*********************************************************************
1942 * Only for multi line controls
1943 * Move the caret one line up, on a column with the nearest
1944 * x coordinate on the screen (might be a different column).
1947 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1949 INT s
= es
->selection_start
;
1950 INT e
= es
->selection_end
;
1951 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1952 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1953 INT x
= SLOWORD(pos
);
1954 INT y
= SHIWORD(pos
);
1956 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1959 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1960 EDIT_EM_ScrollCaret(es
);
1964 /*********************************************************************
1966 * EDIT_MoveWordBackward
1969 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1971 INT s
= es
->selection_start
;
1972 INT e
= es
->selection_end
;
1977 l
= EDIT_EM_LineFromChar(es
, e
);
1978 ll
= EDIT_EM_LineLength(es
, e
);
1979 li
= EDIT_EM_LineIndex(es
, l
);
1982 li
= EDIT_EM_LineIndex(es
, l
- 1);
1983 e
= li
+ EDIT_EM_LineLength(es
, li
);
1986 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
1987 li
, e
- li
, ll
, WB_LEFT
);
1991 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
1992 EDIT_EM_ScrollCaret(es
);
1996 /*********************************************************************
1998 * EDIT_MoveWordForward
2001 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2003 INT s
= es
->selection_start
;
2004 INT e
= es
->selection_end
;
2009 l
= EDIT_EM_LineFromChar(es
, e
);
2010 ll
= EDIT_EM_LineLength(es
, e
);
2011 li
= EDIT_EM_LineIndex(es
, l
);
2013 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2014 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2016 e
= li
+ EDIT_CallWordBreakProc(es
,
2017 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2021 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2022 EDIT_EM_ScrollCaret(es
);
2026 /*********************************************************************
2031 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2033 INT s
= es
->selection_start
;
2034 INT e
= es
->selection_end
;
2041 if (es
->style
& ES_MULTILINE
) {
2042 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2043 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2048 TRACE("line=%d\n", line
);
2050 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2053 li
= EDIT_EM_LineIndex(es
, line
);
2054 ll
= EDIT_EM_LineLength(es
, li
);
2055 s
= min(es
->selection_start
, es
->selection_end
);
2056 e
= max(es
->selection_start
, es
->selection_end
);
2057 s
= min(li
+ ll
, max(li
, s
));
2058 e
= min(li
+ ll
, max(li
, e
));
2059 if (rev
&& (s
!= e
) &&
2060 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2061 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2062 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2063 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2065 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2069 /*********************************************************************
2074 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2085 BkMode
= GetBkMode(dc
);
2086 BkColor
= GetBkColor(dc
);
2087 TextColor
= GetTextColor(dc
);
2089 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2090 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2091 SetBkMode( dc
, OPAQUE
);
2093 li
= EDIT_EM_LineIndex(es
, line
);
2094 if (es
->style
& ES_MULTILINE
) {
2095 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2096 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2098 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2099 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2100 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2102 if (es
->style
& ES_PASSWORD
)
2103 HeapFree(GetProcessHeap(), 0, text
);
2106 SetBkColor(dc
, BkColor
);
2107 SetTextColor(dc
, TextColor
);
2108 SetBkMode( dc
, BkMode
);
2114 /*********************************************************************
2119 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2122 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2123 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2127 /*********************************************************************
2131 * note: this is not (exactly) the handler called on EM_SETRECTNP
2132 * it is also used to set the rect of a single line control
2135 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2137 CopyRect(&es
->format_rect
, rc
);
2138 if (es
->style
& WS_BORDER
) {
2139 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2140 if(TWEAK_WineLook
== WIN31_LOOK
)
2142 es
->format_rect
.left
+= bw
;
2143 es
->format_rect
.top
+= bw
;
2144 es
->format_rect
.right
-= bw
;
2145 es
->format_rect
.bottom
-= bw
;
2147 es
->format_rect
.left
+= es
->left_margin
;
2148 es
->format_rect
.right
-= es
->right_margin
;
2149 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2150 if (es
->style
& ES_MULTILINE
)
2152 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2154 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2155 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2157 /* correct es->x_offset */
2158 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2159 max_x_offset
= es
->text_width
- fw
;
2160 if(max_x_offset
< 0) max_x_offset
= 0;
2161 if(es
->x_offset
> max_x_offset
)
2162 es
->x_offset
= max_x_offset
;
2164 /* correct es->y_offset */
2165 max_y_offset
= es
->line_count
- vlc
;
2166 if(max_y_offset
< 0) max_y_offset
= 0;
2167 if(es
->y_offset
> max_y_offset
)
2168 es
->y_offset
= max_y_offset
;
2170 /* force scroll info update */
2171 EDIT_UpdateScrollInfo(es
);
2174 /* Windows doesn't care to fix text placement for SL controls */
2175 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2177 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2178 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2182 /*********************************************************************
2187 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2189 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2191 /* Edit window might be already destroyed */
2192 if(!IsWindow(es
->hwndSelf
))
2194 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2198 if (!es
->lock_count
) {
2199 ERR("lock_count == 0 ... please report\n");
2203 ERR("es->text == 0 ... please report\n");
2207 if (force
|| (es
->lock_count
== 1)) {
2210 BOOL _16bit
= FALSE
;
2212 UINT countW
= strlenW(es
->text
) + 1;
2216 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2217 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2218 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2219 countA
= LocalSize(es
->hloc32A
);
2220 if(countA_new
> countA
)
2223 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2224 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2225 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2228 es
->hloc32A
= hloc32A_new
;
2229 countA
= LocalSize(hloc32A_new
);
2230 TRACE("Real new size %d bytes\n", countA
);
2233 WARN("FAILED! Will synchronize partially\n");
2235 textA
= LocalLock(es
->hloc32A
);
2239 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2240 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2241 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2242 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2243 if(countA_new
> countA
)
2245 HLOCAL16 hloc16_new
;
2246 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2247 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2248 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2251 es
->hloc16
= hloc16_new
;
2252 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2253 TRACE("Real new size %d bytes\n", countA
);
2256 WARN("FAILED! Will synchronize partially\n");
2258 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2264 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2266 LOCAL_Unlock(hInstance
, es
->hloc16
);
2268 LocalUnlock(es
->hloc32A
);
2271 LocalUnlock(es
->hloc32W
);
2275 ERR("no buffer ... please report\n");
2283 /*********************************************************************
2285 * EDIT_UpdateScrollInfo
2288 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2290 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2293 si
.cbSize
= sizeof(SCROLLINFO
);
2294 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2296 si
.nMax
= es
->line_count
- 1;
2297 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2298 si
.nPos
= es
->y_offset
;
2299 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2300 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2301 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2304 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2307 si
.cbSize
= sizeof(SCROLLINFO
);
2308 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2310 si
.nMax
= es
->text_width
- 1;
2311 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2312 si
.nPos
= es
->x_offset
;
2313 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2314 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2315 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2319 /*********************************************************************
2321 * EDIT_WordBreakProc
2323 * Find the beginning of words.
2324 * Note: unlike the specs for a WordBreakProc, this function only
2325 * allows to be called without linebreaks between s[0] upto
2326 * s[count - 1]. Remember it is only called
2327 * internally, so we can decide this for ourselves.
2330 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2334 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2344 if (s
[index
] == ' ') {
2345 while (index
&& (s
[index
] == ' '))
2348 while (index
&& (s
[index
] != ' '))
2350 if (s
[index
] == ' ')
2354 while (index
&& (s
[index
] != ' '))
2356 if (s
[index
] == ' ')
2366 if (s
[index
] == ' ')
2367 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2369 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2371 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2375 case WB_ISDELIMITER
:
2376 ret
= (s
[index
] == ' ');
2379 ERR("unknown action code, please report !\n");
2386 /*********************************************************************
2390 * returns line number (not index) in high-order word of result.
2391 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2392 * to Richedit, not to the edit control. Original documentation is valid.
2393 * FIXME: do the specs mean to return -1 if outside client area or
2394 * if outside formatting rectangle ???
2397 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2405 GetClientRect(es
->hwndSelf
, &rc
);
2406 if (!PtInRect(&rc
, pt
))
2409 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2410 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2414 /*********************************************************************
2418 * Enable or disable soft breaks.
2420 * This means: insert or remove the soft linebreak character (\r\r\n).
2421 * Take care to check if the text still fits the buffer after insertion.
2422 * If not, notify with EN_ERRSPACE.
2425 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2427 es
->flags
&= ~EF_USE_SOFTBRK
;
2429 es
->flags
|= EF_USE_SOFTBRK
;
2430 FIXME("soft break enabled, not implemented\n");
2436 /*********************************************************************
2440 * Hopefully this won't fire back at us.
2441 * We always start with a fixed buffer in the local heap.
2442 * Despite of the documentation says that the local heap is used
2443 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2444 * buffer on the local heap.
2447 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2451 if (!(es
->style
& ES_MULTILINE
))
2455 hLocal
= es
->hloc32W
;
2461 UINT countA
, alloc_size
;
2462 TRACE("Allocating 32-bit ANSI alias buffer\n");
2463 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2464 alloc_size
= ROUND_TO_GROW(countA
);
2465 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2467 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2470 textA
= LocalLock(es
->hloc32A
);
2471 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2472 LocalUnlock(es
->hloc32A
);
2474 hLocal
= es
->hloc32A
;
2477 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2482 /*********************************************************************
2486 * Hopefully this won't fire back at us.
2487 * We always start with a buffer in 32 bit linear memory.
2488 * However, with this message a 16 bit application requests
2489 * a handle of 16 bit local heap memory, where it expects to find
2491 * It's a pitty that from this moment on we have to use this
2492 * local heap, because applications may rely on the handle
2495 * In this function we'll try to switch to local heap.
2497 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2499 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2501 UINT countA
, alloc_size
;
2503 if (!(es
->style
& ES_MULTILINE
))
2509 if (!LOCAL_HeapSize(hInstance
)) {
2510 if (!LocalInit16(hInstance
, 0,
2511 GlobalSize16(hInstance
))) {
2512 ERR("could not initialize local heap\n");
2515 TRACE("local heap initialized\n");
2518 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2519 alloc_size
= ROUND_TO_GROW(countA
);
2521 TRACE("Allocating 16-bit ANSI alias buffer\n");
2522 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2523 ERR("could not allocate new 16 bit buffer\n");
2527 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2528 ERR("could not lock new 16 bit buffer\n");
2529 LOCAL_Free(hInstance
, es
->hloc16
);
2534 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2535 LOCAL_Unlock(hInstance
, es
->hloc16
);
2537 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2542 /*********************************************************************
2547 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2550 INT line_len
, dst_len
;
2553 if (es
->style
& ES_MULTILINE
) {
2554 if (line
>= es
->line_count
)
2558 i
= EDIT_EM_LineIndex(es
, line
);
2560 line_len
= EDIT_EM_LineLength(es
, i
);
2561 dst_len
= *(WORD
*)lParam
;
2564 LPWSTR dst
= (LPWSTR
)lParam
;
2565 if(dst_len
<= line_len
)
2567 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2570 else /* Append 0 if enough space */
2572 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2579 LPSTR dst
= (LPSTR
)lParam
;
2581 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2582 if(!ret
) /* Insufficient buffer size */
2584 if(ret
< dst_len
) /* Append 0 if enough space */
2591 /*********************************************************************
2596 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2598 UINT s
= es
->selection_start
;
2599 UINT e
= es
->selection_end
;
2606 return MAKELONG(s
, e
);
2610 /*********************************************************************
2614 * FIXME: is this right ? (or should it be only VSCROLL)
2615 * (and maybe only for edit controls that really have their
2616 * own scrollbars) (and maybe only for multiline controls ?)
2617 * All in all: very poorly documented
2620 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2622 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2623 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2627 /*********************************************************************
2632 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2637 if (!(es
->style
& ES_MULTILINE
))
2639 if (index
> (INT
)strlenW(es
->text
))
2640 return es
->line_count
- 1;
2642 index
= min(es
->selection_start
, es
->selection_end
);
2645 line_def
= es
->first_line_def
;
2646 index
-= line_def
->length
;
2647 while ((index
>= 0) && line_def
->next
) {
2649 line_def
= line_def
->next
;
2650 index
-= line_def
->length
;
2656 /*********************************************************************
2661 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2666 if (!(es
->style
& ES_MULTILINE
))
2668 if (line
>= es
->line_count
)
2672 line_def
= es
->first_line_def
;
2674 INT index
= es
->selection_end
- line_def
->length
;
2675 while ((index
>= 0) && line_def
->next
) {
2676 line_index
+= line_def
->length
;
2677 line_def
= line_def
->next
;
2678 index
-= line_def
->length
;
2682 line_index
+= line_def
->length
;
2683 line_def
= line_def
->next
;
2691 /*********************************************************************
2696 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2700 if (!(es
->style
& ES_MULTILINE
))
2701 return strlenW(es
->text
);
2704 /* get the number of remaining non-selected chars of selected lines */
2705 INT32 l
; /* line number */
2706 INT32 li
; /* index of first char in line */
2708 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2709 /* # chars before start of selection area */
2710 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2711 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2712 /* # chars after end of selection */
2713 li
= EDIT_EM_LineIndex(es
, l
);
2714 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2717 line_def
= es
->first_line_def
;
2718 index
-= line_def
->length
;
2719 while ((index
>= 0) && line_def
->next
) {
2720 line_def
= line_def
->next
;
2721 index
-= line_def
->length
;
2723 return line_def
->net_length
;
2727 /*********************************************************************
2731 * NOTE: dx is in average character widths, dy - in lines;
2734 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2736 if (!(es
->style
& ES_MULTILINE
))
2739 dx
*= es
->char_width
;
2740 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2743 /*********************************************************************
2745 * EDIT_EM_LineScroll_internal
2747 * Version of EDIT_EM_LineScroll for internal use.
2748 * It doesn't refuse if ES_MULTILINE is set and assumes that
2749 * dx is in pixels, dy - in lines.
2752 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2755 INT x_offset_in_pixels
;
2757 if (es
->style
& ES_MULTILINE
)
2759 x_offset_in_pixels
= es
->x_offset
;
2764 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2767 if (-dx
> x_offset_in_pixels
)
2768 dx
= -x_offset_in_pixels
;
2769 if (dx
> es
->text_width
- x_offset_in_pixels
)
2770 dx
= es
->text_width
- x_offset_in_pixels
;
2771 nyoff
= max(0, es
->y_offset
+ dy
);
2772 if (nyoff
>= es
->line_count
)
2773 nyoff
= es
->line_count
- 1;
2774 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2779 es
->y_offset
= nyoff
;
2780 if(es
->style
& ES_MULTILINE
)
2783 es
->x_offset
+= dx
/ es
->char_width
;
2785 GetClientRect(es
->hwndSelf
, &rc1
);
2786 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2787 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2788 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2789 /* force scroll info update */
2790 EDIT_UpdateScrollInfo(es
);
2792 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2793 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2794 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2795 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2800 /*********************************************************************
2805 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2807 INT len
= strlenW(es
->text
);
2816 index
= min(index
, len
);
2817 dc
= GetDC(es
->hwndSelf
);
2819 old_font
= SelectObject(dc
, es
->font
);
2820 if (es
->style
& ES_MULTILINE
) {
2821 l
= EDIT_EM_LineFromChar(es
, index
);
2822 y
= (l
- es
->y_offset
) * es
->line_height
;
2823 li
= EDIT_EM_LineIndex(es
, l
);
2824 if (after_wrap
&& (li
== index
) && l
) {
2826 LINEDEF
*line_def
= es
->first_line_def
;
2828 line_def
= line_def
->next
;
2831 if (line_def
->ending
== END_WRAP
) {
2833 y
-= es
->line_height
;
2834 li
= EDIT_EM_LineIndex(es
, l
);
2837 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2838 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2840 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2841 if (index
< es
->x_offset
) {
2842 GetTextExtentPoint32W(dc
, text
+ index
,
2843 es
->x_offset
- index
, &size
);
2846 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2847 index
- es
->x_offset
, &size
);
2851 if (es
->style
& ES_PASSWORD
)
2852 HeapFree(GetProcessHeap(), 0, text
);
2854 x
+= es
->format_rect
.left
;
2855 y
+= es
->format_rect
.top
;
2857 SelectObject(dc
, old_font
);
2858 ReleaseDC(es
->hwndSelf
, dc
);
2859 return MAKELONG((INT16
)x
, (INT16
)y
);
2863 /*********************************************************************
2867 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2870 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2872 UINT strl
= strlenW(lpsz_replace
);
2873 UINT tl
= strlenW(es
->text
);
2881 TRACE("%s, can_undo %d, send_update %d\n",
2882 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2884 s
= es
->selection_start
;
2885 e
= es
->selection_end
;
2887 if ((s
== e
) && !strl
)
2892 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
, honor_limit
))
2896 /* there is something to be deleted */
2897 TRACE("deleting stuff.\n");
2899 utl
= strlenW(es
->undo_text
);
2900 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2901 /* undo-buffer is extended to the right */
2902 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2903 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2904 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2905 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2906 /* undo-buffer is extended to the left */
2907 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2908 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2910 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2911 p
[i
] = (es
->text
+ s
)[i
];
2912 es
->undo_position
= s
;
2914 /* new undo-buffer */
2915 EDIT_MakeUndoFit(es
, e
- s
);
2916 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2917 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2918 es
->undo_position
= s
;
2920 /* any deletion makes the old insertion-undo invalid */
2921 es
->undo_insert_count
= 0;
2923 EDIT_EM_EmptyUndoBuffer(es
);
2926 strcpyW(es
->text
+ s
, es
->text
+ e
);
2929 /* there is an insertion */
2931 if ((s
== es
->undo_position
) ||
2932 ((es
->undo_insert_count
) &&
2933 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2935 * insertion is new and at delete position or
2936 * an extension to either left or right
2938 es
->undo_insert_count
+= strl
;
2940 /* new insertion undo */
2941 es
->undo_position
= s
;
2942 es
->undo_insert_count
= strl
;
2943 /* new insertion makes old delete-buffer invalid */
2944 *es
->undo_text
= '\0';
2947 EDIT_EM_EmptyUndoBuffer(es
);
2950 tl
= strlenW(es
->text
);
2951 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
));
2952 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2954 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2955 p
[i
] = lpsz_replace
[i
];
2956 if(es
->style
& ES_UPPERCASE
)
2957 CharUpperBuffW(p
, strl
);
2958 else if(es
->style
& ES_LOWERCASE
)
2959 CharLowerBuffW(p
, strl
);
2962 if (es
->style
& ES_MULTILINE
)
2964 INT s
= min(es
->selection_start
, es
->selection_end
);
2966 hrgn
= CreateRectRgn(0, 0, 0, 0);
2967 EDIT_BuildLineDefs_ML(es
, s
, s
+ strl
,
2968 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2971 EDIT_CalcLineWidth_SL(es
);
2973 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2974 es
->flags
|= EF_MODIFIED
;
2975 if (send_update
) es
->flags
|= EF_UPDATE
;
2976 EDIT_EM_ScrollCaret(es
);
2978 /* force scroll info update */
2979 EDIT_UpdateScrollInfo(es
);
2983 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2987 EDIT_UpdateText(es
, NULL
, TRUE
);
2989 if(es
->flags
& EF_UPDATE
)
2991 es
->flags
&= ~EF_UPDATE
;
2992 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
2997 /*********************************************************************
3002 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3006 if (!(es
->style
& ES_MULTILINE
))
3007 return (LRESULT
)FALSE
;
3017 if (es
->y_offset
< es
->line_count
- 1)
3022 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3025 if (es
->y_offset
< es
->line_count
- 1)
3026 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3029 return (LRESULT
)FALSE
;
3032 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3033 /* check if we are going to move too far */
3034 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3035 dy
= es
->line_count
- vlc
- es
->y_offset
;
3037 /* Notification is done in EDIT_EM_LineScroll */
3039 EDIT_EM_LineScroll(es
, 0, dy
);
3041 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3045 /*********************************************************************
3050 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3052 if (es
->style
& ES_MULTILINE
) {
3057 INT cw
= es
->char_width
;
3062 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3063 li
= EDIT_EM_LineIndex(es
, l
);
3064 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3065 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3066 if (l
>= es
->y_offset
+ vlc
)
3067 dy
= l
- vlc
+ 1 - es
->y_offset
;
3068 if (l
< es
->y_offset
)
3069 dy
= l
- es
->y_offset
;
3070 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3071 if (x
< es
->format_rect
.left
)
3072 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3073 if (x
> es
->format_rect
.right
)
3074 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3077 /* check if we are going to move too far */
3078 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3079 dx
= es
->text_width
- ww
- es
->x_offset
;
3081 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3088 if (!(es
->style
& ES_AUTOHSCROLL
))
3091 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3092 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3093 if (x
< es
->format_rect
.left
) {
3094 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3097 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3098 } while ((x
< goal
) && es
->x_offset
);
3099 /* FIXME: use ScrollWindow() somehow to improve performance */
3100 EDIT_UpdateText(es
, NULL
, TRUE
);
3101 } else if (x
> es
->format_rect
.right
) {
3103 INT len
= strlenW(es
->text
);
3104 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3107 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3108 x_last
= SLOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3109 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3110 /* FIXME: use ScrollWindow() somehow to improve performance */
3111 EDIT_UpdateText(es
, NULL
, TRUE
);
3115 if(es
->flags
& EF_FOCUSED
)
3116 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3120 /*********************************************************************
3124 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3127 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3129 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3131 if (!(es
->style
& ES_MULTILINE
))
3135 WARN("called with NULL handle\n");
3139 EDIT_UnlockBuffer(es
, TRUE
);
3143 LOCAL_Free(hInstance
, es
->hloc16
);
3144 es
->hloc16
= (HLOCAL16
)NULL
;
3151 LocalFree(es
->hloc32A
);
3163 countA
= LocalSize(hloc
);
3164 textA
= LocalLock(hloc
);
3165 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3166 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3168 ERR("Could not allocate new unicode buffer\n");
3171 textW
= LocalLock(hloc32W_new
);
3172 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3173 LocalUnlock(hloc32W_new
);
3177 LocalFree(es
->hloc32W
);
3179 es
->hloc32W
= hloc32W_new
;
3183 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3185 EDIT_LockBuffer(es
);
3187 es
->x_offset
= es
->y_offset
= 0;
3188 es
->selection_start
= es
->selection_end
= 0;
3189 EDIT_EM_EmptyUndoBuffer(es
);
3190 es
->flags
&= ~EF_MODIFIED
;
3191 es
->flags
&= ~EF_UPDATE
;
3192 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3193 EDIT_UpdateText(es
, NULL
, TRUE
);
3194 EDIT_EM_ScrollCaret(es
);
3195 /* force scroll info update */
3196 EDIT_UpdateScrollInfo(es
);
3200 /*********************************************************************
3204 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3207 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3209 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3215 if (!(es
->style
& ES_MULTILINE
))
3219 WARN("called with NULL handle\n");
3223 EDIT_UnlockBuffer(es
, TRUE
);
3227 LocalFree(es
->hloc32A
);
3231 countA
= LOCAL_Size(hInstance
, hloc
);
3232 textA
= LOCAL_Lock(hInstance
, hloc
);
3233 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3234 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3236 ERR("Could not allocate new unicode buffer\n");
3239 textW
= LocalLock(hloc32W_new
);
3240 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3241 LocalUnlock(hloc32W_new
);
3242 LOCAL_Unlock(hInstance
, hloc
);
3245 LocalFree(es
->hloc32W
);
3247 es
->hloc32W
= hloc32W_new
;
3250 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3252 EDIT_LockBuffer(es
);
3254 es
->x_offset
= es
->y_offset
= 0;
3255 es
->selection_start
= es
->selection_end
= 0;
3256 EDIT_EM_EmptyUndoBuffer(es
);
3257 es
->flags
&= ~EF_MODIFIED
;
3258 es
->flags
&= ~EF_UPDATE
;
3259 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3260 EDIT_UpdateText(es
, NULL
, TRUE
);
3261 EDIT_EM_ScrollCaret(es
);
3262 /* force scroll info update */
3263 EDIT_UpdateScrollInfo(es
);
3267 /*********************************************************************
3271 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3272 * However, the windows version is not complied to yet in all of edit.c
3274 * Additionally as the wrapper for RichEdit controls we need larger buffers
3275 * at present -1 will represent nolimit
3277 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3279 if (limit
== 0xFFFFFFFF)
3280 es
->buffer_limit
= -1;
3281 else if (es
->style
& ES_MULTILINE
) {
3283 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3285 es
->buffer_limit
= BUFLIMIT_MULTI
;
3288 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3290 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3295 /*********************************************************************
3299 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3300 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3301 * margin according to the textmetrics of the current font.
3303 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3304 * of the char's width as the margin, but this is not how Windows handles this.
3305 * For all other fonts Windows sets the margins to zero.
3308 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3309 INT left
, INT right
)
3312 INT default_left_margin
= 0; /* in pixels */
3313 INT default_right_margin
= 0; /* in pixels */
3315 /* Set the default margins depending on the font */
3316 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3317 HDC dc
= GetDC(es
->hwndSelf
);
3318 HFONT old_font
= SelectObject(dc
, es
->font
);
3319 GetTextMetricsW(dc
, &tm
);
3320 /* The default margins are only non zero for TrueType or Vector fonts */
3321 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3322 /* This must be calculated more exactly! But how? */
3323 default_left_margin
= tm
.tmAveCharWidth
/ 3;
3324 default_right_margin
= tm
.tmAveCharWidth
/ 3;
3326 SelectObject(dc
, old_font
);
3327 ReleaseDC(es
->hwndSelf
, dc
);
3330 if (action
& EC_LEFTMARGIN
) {
3331 if (left
!= EC_USEFONTINFO
)
3332 es
->left_margin
= left
;
3334 es
->left_margin
= default_left_margin
;
3337 if (action
& EC_RIGHTMARGIN
) {
3338 if (right
!= EC_USEFONTINFO
)
3339 es
->right_margin
= right
;
3341 es
->right_margin
= default_right_margin
;
3343 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3347 /*********************************************************************
3349 * EM_SETPASSWORDCHAR
3352 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3356 if (es
->style
& ES_MULTILINE
)
3359 if (es
->password_char
== c
)
3362 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3363 es
->password_char
= c
;
3365 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3366 es
->style
|= ES_PASSWORD
;
3368 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3369 es
->style
&= ~ES_PASSWORD
;
3371 EDIT_UpdateText(es
, NULL
, TRUE
);
3375 /*********************************************************************
3379 * note: unlike the specs say: the order of start and end
3380 * _is_ preserved in Windows. (i.e. start can be > end)
3381 * In other words: this handler is OK
3384 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3386 UINT old_start
= es
->selection_start
;
3387 UINT old_end
= es
->selection_end
;
3388 UINT len
= strlenW(es
->text
);
3390 if (start
== (UINT
)-1) {
3391 start
= es
->selection_end
;
3392 end
= es
->selection_end
;
3394 start
= min(start
, len
);
3395 end
= min(end
, len
);
3397 es
->selection_start
= start
;
3398 es
->selection_end
= end
;
3400 es
->flags
|= EF_AFTER_WRAP
;
3402 es
->flags
&= ~EF_AFTER_WRAP
;
3403 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3404 ORDER_UINT(start
, end
);
3405 ORDER_UINT(end
, old_end
);
3406 ORDER_UINT(start
, old_start
);
3407 ORDER_UINT(old_start
, old_end
);
3408 if (end
!= old_start
)
3412 * ORDER_UINT32(end, old_start);
3413 * EDIT_InvalidateText(es, start, end);
3414 * EDIT_InvalidateText(es, old_start, old_end);
3415 * in place of the following if statement.
3417 if (old_start
> end
)
3419 EDIT_InvalidateText(es
, start
, end
);
3420 EDIT_InvalidateText(es
, old_start
, old_end
);
3424 EDIT_InvalidateText(es
, start
, old_start
);
3425 EDIT_InvalidateText(es
, end
, old_end
);
3428 else EDIT_InvalidateText(es
, start
, old_end
);
3432 /*********************************************************************
3437 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3439 if (!(es
->style
& ES_MULTILINE
))
3442 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3443 es
->tabs_count
= count
;
3447 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3448 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3454 /*********************************************************************
3459 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3461 if (!(es
->style
& ES_MULTILINE
))
3464 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3465 es
->tabs_count
= count
;
3470 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3471 for (i
= 0 ; i
< count
; i
++)
3472 es
->tabs
[i
] = *tabs
++;
3478 /*********************************************************************
3480 * EM_SETWORDBREAKPROC
3483 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
)
3485 if (es
->word_break_proc
== (void *)lParam
)
3488 es
->word_break_proc
= (void *)lParam
;
3489 es
->word_break_proc16
= NULL
;
3491 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3492 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3493 EDIT_UpdateText(es
, NULL
, TRUE
);
3498 /*********************************************************************
3500 * EM_SETWORDBREAKPROC16
3503 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3505 if (es
->word_break_proc16
== wbp
)
3508 es
->word_break_proc
= NULL
;
3509 es
->word_break_proc16
= wbp
;
3510 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3511 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3512 EDIT_UpdateText(es
, NULL
, TRUE
);
3517 /*********************************************************************
3522 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3527 /* Protect read-only edit control from modification */
3528 if(es
->style
& ES_READONLY
)
3531 ulength
= strlenW(es
->undo_text
);
3532 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3534 strcpyW(utext
, es
->undo_text
);
3536 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3537 es
->undo_insert_count
, debugstr_w(utext
));
3539 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3540 EDIT_EM_EmptyUndoBuffer(es
);
3541 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, FALSE
, TRUE
);
3542 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3543 /* send the notification after the selection start and end are set */
3544 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3545 EDIT_EM_ScrollCaret(es
);
3546 HeapFree(GetProcessHeap(), 0, utext
);
3548 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3549 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3554 /*********************************************************************
3559 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3563 /* Protect read-only edit control from modification */
3564 if(es
->style
& ES_READONLY
)
3567 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3571 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3572 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3575 if (es
->style
& ES_MULTILINE
) {
3576 if (es
->style
& ES_READONLY
) {
3577 EDIT_MoveHome(es
, FALSE
);
3578 EDIT_MoveDown_ML(es
, FALSE
);
3580 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3581 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3586 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3588 static const WCHAR tabW
[] = {'\t',0};
3589 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3593 if (!(es
->style
& ES_READONLY
) && !control
) {
3594 if (es
->selection_start
!= es
->selection_end
)
3597 /* delete character left of caret */
3598 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3599 EDIT_MoveBackward(es
, TRUE
);
3605 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3608 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3611 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3615 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3619 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3626 /*********************************************************************
3631 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3633 if (code
|| control
)
3653 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3654 EDIT_EM_ScrollCaret(es
);
3657 ERR("unknown menu item, please report\n");
3663 /*********************************************************************
3667 * Note: the resource files resource/sysres_??.rc cannot define a
3668 * single popup menu. Hence we use a (dummy) menubar
3669 * containing the single popup menu as its first item.
3671 * FIXME: the message identifiers have been chosen arbitrarily,
3672 * hence we use MF_BYPOSITION.
3673 * We might as well use the "real" values (anybody knows ?)
3674 * The menu definition is in resources/sysres_??.rc.
3675 * Once these are OK, we better use MF_BYCOMMAND here
3676 * (as we do in EDIT_WM_Command()).
3679 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3681 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3682 HMENU popup
= GetSubMenu(menu
, 0);
3683 UINT start
= es
->selection_start
;
3684 UINT end
= es
->selection_end
;
3686 ORDER_UINT(start
, end
);
3689 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3691 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3693 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3695 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3697 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3699 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3701 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3706 /*********************************************************************
3711 static void EDIT_WM_Copy(EDITSTATE
*es
)
3713 INT s
= min(es
->selection_start
, es
->selection_end
);
3714 INT e
= max(es
->selection_start
, es
->selection_end
);
3720 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3721 dst
= GlobalLock(hdst
);
3722 strncpyW(dst
, es
->text
+ s
, e
- s
);
3723 dst
[e
- s
] = 0; /* ensure 0 termination */
3724 TRACE("%s\n", debugstr_w(dst
));
3726 OpenClipboard(es
->hwndSelf
);
3728 SetClipboardData(CF_UNICODETEXT
, hdst
);
3733 /*********************************************************************
3738 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3740 TRACE("%s\n", debugstr_w(name
));
3742 * To initialize some final structure members, we call some helper
3743 * functions. However, since the EDITSTATE is not consistent (i.e.
3744 * not fully initialized), we should be very careful which
3745 * functions can be called, and in what order.
3747 EDIT_WM_SetFont(es
, 0, FALSE
);
3748 EDIT_EM_EmptyUndoBuffer(es
);
3750 if (name
&& *name
) {
3751 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3752 /* if we insert text to the editline, the text scrolls out
3753 * of the window, as the caret is placed after the insert
3754 * pos normally; thus we reset es->selection... to 0 and
3757 es
->selection_start
= es
->selection_end
= 0;
3758 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3759 * Messages are only to be sent when the USER does something to
3760 * change the contents. So I am removing this EN_CHANGE
3762 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3764 EDIT_EM_ScrollCaret(es
);
3766 /* force scroll info update */
3767 EDIT_UpdateScrollInfo(es
);
3772 /*********************************************************************
3777 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
3782 while (LocalUnlock(es
->hloc32W
)) ;
3783 LocalFree(es
->hloc32W
);
3786 while (LocalUnlock(es
->hloc32A
)) ;
3787 LocalFree(es
->hloc32A
);
3790 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
3791 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3792 LOCAL_Free(hInstance
, es
->hloc16
);
3795 pc
= es
->first_line_def
;
3799 HeapFree(GetProcessHeap(), 0, pc
);
3803 SetWindowLongW( es
->hwndSelf
, 0, 0 );
3804 HeapFree(GetProcessHeap(), 0, es
);
3810 /*********************************************************************
3815 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
3820 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
3821 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3823 GetClientRect(es
->hwndSelf
, &rc
);
3824 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3825 GetClipBox(dc
, &rc
);
3827 * FIXME: specs say that we should UnrealizeObject() the brush,
3828 * but the specs of UnrealizeObject() say that we shouldn't
3829 * unrealize a stock object. The default brush that
3830 * DefWndProc() returns is ... a stock object.
3832 FillRect(dc
, &rc
, brush
);
3837 /*********************************************************************
3842 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3844 if(!count
) return 0;
3848 LPWSTR textW
= (LPWSTR
)lParam
;
3849 lstrcpynW(textW
, es
->text
, count
);
3850 return strlenW(textW
);
3854 LPSTR textA
= (LPSTR
)lParam
;
3855 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3856 textA
[count
- 1] = 0; /* ensure 0 termination */
3857 return strlen(textA
);
3861 /*********************************************************************
3866 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3871 if (!(es
->style
& ES_MULTILINE
))
3874 if (!(es
->style
& ES_AUTOHSCROLL
))
3878 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3881 TRACE("SB_LINELEFT\n");
3883 dx
= -es
->char_width
;
3886 TRACE("SB_LINERIGHT\n");
3887 if (es
->x_offset
< es
->text_width
)
3888 dx
= es
->char_width
;
3891 TRACE("SB_PAGELEFT\n");
3893 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3896 TRACE("SB_PAGERIGHT\n");
3897 if (es
->x_offset
< es
->text_width
)
3898 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3906 TRACE("SB_RIGHT\n");
3907 if (es
->x_offset
< es
->text_width
)
3908 dx
= es
->text_width
- es
->x_offset
;
3911 TRACE("SB_THUMBTRACK %d\n", pos
);
3912 es
->flags
|= EF_HSCROLL_TRACK
;
3913 if(es
->style
& WS_HSCROLL
)
3914 dx
= pos
- es
->x_offset
;
3919 if(pos
< 0 || pos
> 100) return 0;
3920 /* Assume default scroll range 0-100 */
3921 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3922 new_x
= pos
* (es
->text_width
- fw
) / 100;
3923 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3926 case SB_THUMBPOSITION
:
3927 TRACE("SB_THUMBPOSITION %d\n", pos
);
3928 es
->flags
&= ~EF_HSCROLL_TRACK
;
3929 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3930 dx
= pos
- es
->x_offset
;
3935 if(pos
< 0 || pos
> 100) return 0;
3936 /* Assume default scroll range 0-100 */
3937 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3938 new_x
= pos
* (es
->text_width
- fw
) / 100;
3939 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3942 /* force scroll info update */
3943 EDIT_UpdateScrollInfo(es
);
3944 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
3948 TRACE("SB_ENDSCROLL\n");
3951 * FIXME : the next two are undocumented !
3952 * Are we doing the right thing ?
3953 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3954 * although it's also a regular control message.
3956 case EM_GETTHUMB
: /* this one is used by NT notepad */
3960 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3961 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3964 /* Assume default scroll range 0-100 */
3965 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3966 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3968 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3971 case EM_LINESCROLL16
:
3972 TRACE("EM_LINESCROLL16\n");
3977 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3983 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3984 /* check if we are going to move too far */
3985 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3986 dx
= es
->text_width
- fw
- es
->x_offset
;
3988 EDIT_EM_LineScroll_internal(es
, dx
, 0);
3994 /*********************************************************************
3999 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4001 HWND hLBox
= es
->hwndListBox
;
4009 hCombo
= GetParent(es
->hwndSelf
);
4013 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4015 if (key
== VK_UP
|| key
== VK_DOWN
)
4017 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4020 if (msg
== WM_KEYDOWN
|| nEUI
)
4021 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4027 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4029 /* make sure ComboLBox pops up */
4030 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4035 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4038 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4040 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4042 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4047 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4053 /*********************************************************************
4057 * Handling of special keys that don't produce a WM_CHAR
4058 * (i.e. non-printable keys) & Backspace & Delete
4061 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4066 if (GetKeyState(VK_MENU
) & 0x8000)
4069 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4070 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4075 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4080 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4081 EDIT_MoveUp_ML(es
, shift
);
4084 EDIT_MoveWordBackward(es
, shift
);
4086 EDIT_MoveBackward(es
, shift
);
4089 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4093 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4094 EDIT_MoveDown_ML(es
, shift
);
4096 EDIT_MoveWordForward(es
, shift
);
4098 EDIT_MoveForward(es
, shift
);
4101 EDIT_MoveHome(es
, shift
);
4104 EDIT_MoveEnd(es
, shift
);
4107 if (es
->style
& ES_MULTILINE
)
4108 EDIT_MovePageUp_ML(es
, shift
);
4110 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4113 if (es
->style
& ES_MULTILINE
)
4114 EDIT_MovePageDown_ML(es
, shift
);
4116 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4119 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4120 if (es
->selection_start
!= es
->selection_end
) {
4127 /* delete character left of caret */
4128 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4129 EDIT_MoveBackward(es
, TRUE
);
4131 } else if (control
) {
4132 /* delete to end of line */
4133 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4134 EDIT_MoveEnd(es
, TRUE
);
4137 /* delete character right of caret */
4138 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4139 EDIT_MoveForward(es
, TRUE
);
4147 if (!(es
->style
& ES_READONLY
))
4153 /* If the edit doesn't want the return send a message to the default object */
4154 if(!(es
->style
& ES_WANTRETURN
))
4156 HWND hwndParent
= GetParent(es
->hwndSelf
);
4157 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4158 if (HIWORD(dw
) == DC_HASDEFID
)
4160 SendMessageW( hwndParent
, WM_COMMAND
,
4161 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4162 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4171 /*********************************************************************
4176 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4178 es
->flags
&= ~EF_FOCUSED
;
4180 if(!(es
->style
& ES_NOHIDESEL
))
4181 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4182 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4187 /*********************************************************************
4191 * The caret position has been set on the WM_LBUTTONDOWN message
4194 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4197 INT e
= es
->selection_end
;
4202 if (!(es
->flags
& EF_FOCUSED
))
4205 l
= EDIT_EM_LineFromChar(es
, e
);
4206 li
= EDIT_EM_LineIndex(es
, l
);
4207 ll
= EDIT_EM_LineLength(es
, e
);
4208 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4209 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4210 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4211 EDIT_EM_ScrollCaret(es
);
4216 /*********************************************************************
4221 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4226 if (!(es
->flags
& EF_FOCUSED
))
4229 es
->bCaptureState
= TRUE
;
4230 SetCapture(es
->hwndSelf
);
4231 EDIT_ConfinePoint(es
, &x
, &y
);
4232 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4233 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4234 EDIT_EM_ScrollCaret(es
);
4235 es
->region_posx
= es
->region_posy
= 0;
4236 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4241 /*********************************************************************
4246 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4248 if (es
->bCaptureState
) {
4249 KillTimer(es
->hwndSelf
, 0);
4250 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4252 es
->bCaptureState
= FALSE
;
4257 /*********************************************************************
4262 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4264 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4269 /*********************************************************************
4274 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4280 if (GetCapture() != es
->hwndSelf
)
4284 * FIXME: gotta do some scrolling if outside client
4285 * area. Maybe reset the timer ?
4288 EDIT_ConfinePoint(es
, &x
, &y
);
4289 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4290 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4291 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4292 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4293 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4298 /*********************************************************************
4302 * See also EDIT_WM_StyleChanged
4304 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4309 TRACE("Creating %s edit control, style = %08lx\n",
4310 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4312 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4314 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4317 * Note: since the EDITSTATE has not been fully initialized yet,
4318 * we can't use any API calls that may send
4319 * WM_XXX messages before WM_NCCREATE is completed.
4322 es
->is_unicode
= unicode
;
4323 es
->style
= lpcs
->style
;
4325 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4327 es
->hwndSelf
= hwnd
;
4328 /* Save parent, which will be notified by EN_* messages */
4329 es
->hwndParent
= lpcs
->hwndParent
;
4331 if (es
->style
& ES_COMBO
)
4332 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4334 /* Number overrides lowercase overrides uppercase (at least it
4335 * does in Win95). However I'll bet that ES_NUMBER would be
4336 * invalid under Win 3.1.
4338 if (es
->style
& ES_NUMBER
) {
4339 ; /* do not override the ES_NUMBER */
4340 } else if (es
->style
& ES_LOWERCASE
) {
4341 es
->style
&= ~ES_UPPERCASE
;
4343 if (es
->style
& ES_MULTILINE
) {
4344 es
->buffer_limit
= BUFLIMIT_MULTI
;
4345 if (es
->style
& WS_VSCROLL
)
4346 es
->style
|= ES_AUTOVSCROLL
;
4347 if (es
->style
& WS_HSCROLL
)
4348 es
->style
|= ES_AUTOHSCROLL
;
4349 es
->style
&= ~ES_PASSWORD
;
4350 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4351 /* Confirmed - RIGHT overrides CENTER */
4352 if (es
->style
& ES_RIGHT
)
4353 es
->style
&= ~ES_CENTER
;
4354 es
->style
&= ~WS_HSCROLL
;
4355 es
->style
&= ~ES_AUTOHSCROLL
;
4358 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4359 es
->style
|= ES_AUTOVSCROLL
;
4361 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4362 if (WIN31_LOOK
== TWEAK_WineLook
||
4363 WIN95_LOOK
== TWEAK_WineLook
) {
4364 es
->style
&= ~ES_CENTER
;
4365 es
->style
&= ~ES_RIGHT
;
4367 if (es
->style
& ES_RIGHT
)
4368 es
->style
&= ~ES_CENTER
;
4370 es
->style
&= ~WS_HSCROLL
;
4371 es
->style
&= ~WS_VSCROLL
;
4372 es
->style
&= ~ES_AUTOVSCROLL
;
4373 es
->style
&= ~ES_WANTRETURN
;
4374 if (es
->style
& ES_PASSWORD
)
4375 es
->password_char
= '*';
4377 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4378 es
->style
|= ES_AUTOHSCROLL
;
4381 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4382 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4384 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4386 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4388 es
->undo_buffer_size
= es
->buffer_size
;
4390 if (es
->style
& ES_MULTILINE
)
4391 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4396 * In Win95 look and feel, the WS_BORDER style is replaced by the
4397 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4398 * control a non client area. Not always. This coordinates in some
4399 * way with the window creation code in dialog.c When making
4400 * modifications please ensure that the code still works for edit
4401 * controls created directly with style 0x50800000, exStyle 0 (
4402 * which should have a single pixel border)
4404 if (TWEAK_WineLook
!= WIN31_LOOK
)
4406 es
->style
&= ~WS_BORDER
;
4410 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4411 SetWindowLongW( hwnd
, GWL_STYLE
,
4412 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4418 /*********************************************************************
4423 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
)
4432 BOOL rev
= es
->bEnableState
&&
4433 ((es
->flags
& EF_FOCUSED
) ||
4434 (es
->style
& ES_NOHIDESEL
));
4436 dc
= BeginPaint(es
->hwndSelf
, &ps
);
4439 if(es
->style
& WS_BORDER
) {
4440 GetClientRect(es
->hwndSelf
, &rc
);
4441 if(es
->style
& ES_MULTILINE
) {
4442 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4443 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4445 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4447 IntersectClipRect(dc
, es
->format_rect
.left
,
4448 es
->format_rect
.top
,
4449 es
->format_rect
.right
,
4450 es
->format_rect
.bottom
);
4451 if (es
->style
& ES_MULTILINE
) {
4452 GetClientRect(es
->hwndSelf
, &rc
);
4453 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4456 old_font
= SelectObject(dc
, es
->font
);
4457 EDIT_NotifyCtlColor(es
, dc
);
4459 if (!es
->bEnableState
)
4460 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4461 GetClipBox(dc
, &rcRgn
);
4462 if (es
->style
& ES_MULTILINE
) {
4463 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4464 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4465 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4466 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4467 EDIT_PaintLine(es
, dc
, i
, rev
);
4470 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4471 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4472 EDIT_PaintLine(es
, dc
, 0, rev
);
4475 SelectObject(dc
, old_font
);
4478 EndPaint(es
->hwndSelf
, &ps
);
4482 /*********************************************************************
4487 static void EDIT_WM_Paste(EDITSTATE
*es
)
4492 /* Protect read-only edit control from modification */
4493 if(es
->style
& ES_READONLY
)
4496 OpenClipboard(es
->hwndSelf
);
4497 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4498 src
= (LPWSTR
)GlobalLock(hsrc
);
4499 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4506 /*********************************************************************
4511 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4513 es
->flags
|= EF_FOCUSED
;
4514 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4515 EDIT_SetCaretPos(es
, es
->selection_end
,
4516 es
->flags
& EF_AFTER_WRAP
);
4517 if(!(es
->style
& ES_NOHIDESEL
))
4518 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4519 ShowCaret(es
->hwndSelf
);
4520 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4524 /*********************************************************************
4528 * With Win95 look the margins are set to default font value unless
4529 * the system font (font == 0) is being set, in which case they are left
4533 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4541 dc
= GetDC(es
->hwndSelf
);
4543 old_font
= SelectObject(dc
, font
);
4544 GetTextMetricsW(dc
, &tm
);
4545 es
->line_height
= tm
.tmHeight
;
4546 es
->char_width
= tm
.tmAveCharWidth
;
4548 SelectObject(dc
, old_font
);
4549 ReleaseDC(es
->hwndSelf
, dc
);
4550 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4551 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4552 EC_USEFONTINFO
, EC_USEFONTINFO
);
4554 /* Force the recalculation of the format rect for each font change */
4555 GetClientRect(es
->hwndSelf
, &r
);
4556 EDIT_SetRectNP(es
, &r
);
4558 if (es
->style
& ES_MULTILINE
)
4559 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4561 EDIT_CalcLineWidth_SL(es
);
4564 EDIT_UpdateText(es
, NULL
, TRUE
);
4565 if (es
->flags
& EF_FOCUSED
) {
4567 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4568 EDIT_SetCaretPos(es
, es
->selection_end
,
4569 es
->flags
& EF_AFTER_WRAP
);
4570 ShowCaret(es
->hwndSelf
);
4575 /*********************************************************************
4580 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4581 * The modified flag is reset. No notifications are sent.
4583 * For single-line controls, reception of WM_SETTEXT triggers:
4584 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4587 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4592 text
= (LPWSTR
)lParam
;
4595 LPCSTR textA
= (LPCSTR
)lParam
;
4596 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4597 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4598 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4601 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4603 TRACE("%s\n", debugstr_w(text
));
4604 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4606 HeapFree(GetProcessHeap(), 0, text
);
4608 static const WCHAR empty_stringW
[] = {0};
4610 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4613 es
->flags
&= ~EF_MODIFIED
;
4614 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4615 /* Send the notification after the selection start and end have been set
4616 * edit control doesn't send notification on WM_SETTEXT
4617 * if it is multiline, or it is part of combobox
4619 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4621 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4622 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4624 EDIT_EM_ScrollCaret(es
);
4628 /*********************************************************************
4633 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4635 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4637 TRACE("width = %d, height = %d\n", width
, height
);
4638 SetRect(&rc
, 0, 0, width
, height
);
4639 EDIT_SetRectNP(es
, &rc
);
4640 EDIT_UpdateText(es
, NULL
, TRUE
);
4645 /*********************************************************************
4649 * This message is sent by SetWindowLong on having changed either the Style
4650 * or the extended style.
4652 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4654 * See also EDIT_WM_NCCreate
4656 * It appears that the Windows version of the edit control allows the style
4657 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4658 * style variable which will generally be different. In this function we
4659 * update the internal style based on what changed in the externally visible
4662 * Much of this content as based upon the MSDN, especially:
4663 * Platform SDK Documentation -> User Interface Services ->
4664 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4665 * Edit Control Styles
4667 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4669 if (GWL_STYLE
== which
) {
4670 DWORD style_change_mask
;
4672 /* Only a subset of changes can be applied after the control
4675 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4677 if (es
->style
& ES_MULTILINE
)
4678 style_change_mask
|= ES_WANTRETURN
;
4680 new_style
= style
->styleNew
& style_change_mask
;
4682 /* Number overrides lowercase overrides uppercase (at least it
4683 * does in Win95). However I'll bet that ES_NUMBER would be
4684 * invalid under Win 3.1.
4686 if (new_style
& ES_NUMBER
) {
4687 ; /* do not override the ES_NUMBER */
4688 } else if (new_style
& ES_LOWERCASE
) {
4689 new_style
&= ~ES_UPPERCASE
;
4692 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4693 } else if (GWL_EXSTYLE
== which
) {
4694 ; /* FIXME - what is needed here */
4696 WARN ("Invalid style change %d\n",which
);
4702 /*********************************************************************
4707 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4709 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4710 if (EDIT_EM_CanUndo(es
))
4713 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4714 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4717 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4721 /*********************************************************************
4726 static void EDIT_WM_Timer(EDITSTATE
*es
)
4728 if (es
->region_posx
< 0) {
4729 EDIT_MoveBackward(es
, TRUE
);
4730 } else if (es
->region_posx
> 0) {
4731 EDIT_MoveForward(es
, TRUE
);
4734 * FIXME: gotta do some vertical scrolling here, like
4735 * EDIT_EM_LineScroll(hwnd, 0, 1);
4739 /*********************************************************************
4744 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4748 if (!(es
->style
& ES_MULTILINE
))
4751 if (!(es
->style
& ES_AUTOVSCROLL
))
4760 TRACE("action %d\n", action
);
4761 EDIT_EM_Scroll(es
, action
);
4768 TRACE("SB_BOTTOM\n");
4769 dy
= es
->line_count
- 1 - es
->y_offset
;
4772 TRACE("SB_THUMBTRACK %d\n", pos
);
4773 es
->flags
|= EF_VSCROLL_TRACK
;
4774 if(es
->style
& WS_VSCROLL
)
4775 dy
= pos
- es
->y_offset
;
4778 /* Assume default scroll range 0-100 */
4781 if(pos
< 0 || pos
> 100) return 0;
4782 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4783 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4784 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4785 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4786 es
->line_count
, es
->y_offset
, pos
, dy
);
4789 case SB_THUMBPOSITION
:
4790 TRACE("SB_THUMBPOSITION %d\n", pos
);
4791 es
->flags
&= ~EF_VSCROLL_TRACK
;
4792 if(es
->style
& WS_VSCROLL
)
4793 dy
= pos
- es
->y_offset
;
4796 /* Assume default scroll range 0-100 */
4799 if(pos
< 0 || pos
> 100) return 0;
4800 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4801 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4802 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4803 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4804 es
->line_count
, es
->y_offset
, pos
, dy
);
4808 /* force scroll info update */
4809 EDIT_UpdateScrollInfo(es
);
4810 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4814 TRACE("SB_ENDSCROLL\n");
4817 * FIXME : the next two are undocumented !
4818 * Are we doing the right thing ?
4819 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4820 * although it's also a regular control message.
4822 case EM_GETTHUMB
: /* this one is used by NT notepad */
4826 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4827 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4830 /* Assume default scroll range 0-100 */
4831 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4832 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4834 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4837 case EM_LINESCROLL16
:
4838 TRACE("EM_LINESCROLL16 %d\n", pos
);
4843 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4848 EDIT_EM_LineScroll(es
, 0, dy
);
4852 /*********************************************************************
4857 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4859 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4860 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
4864 /*********************************************************************
4869 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4871 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4872 InvalidateRect(es
->hwndSelf
, rc
, bErase
);