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 than 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
;
771 strng
[0] = wParam
>> 8;
772 strng
[1] = wParam
& 0xff;
773 MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
774 EDIT_WM_Char(es
, charW
);
787 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
790 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
792 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
793 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
796 EDIT_WM_Char(es
, charW
);
805 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
809 EDIT_WM_ContextMenu(es
, SLOWORD(lParam
), SHIWORD(lParam
));
818 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
821 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
825 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
826 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
827 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
829 result
= EDIT_WM_Create(es
, nameW
);
831 HeapFree(GetProcessHeap(), 0, nameW
);
840 es
->bEnableState
= (BOOL
) wParam
;
841 EDIT_UpdateText(es
, NULL
, TRUE
);
845 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
849 result
= (LRESULT
)es
->font
;
853 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
856 case WM_GETTEXTLENGTH
:
857 if (unicode
) result
= strlenW(es
->text
);
858 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
859 NULL
, 0, NULL
, NULL
);
863 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), SHIWORD(wParam
));
867 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
871 result
= EDIT_WM_KillFocus(es
);
874 case WM_LBUTTONDBLCLK
:
875 result
= EDIT_WM_LButtonDblClk(es
);
879 result
= EDIT_WM_LButtonDown(es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
883 result
= EDIT_WM_LButtonUp(es
);
887 result
= EDIT_WM_MButtonDown(es
);
890 case WM_MOUSEACTIVATE
:
892 * FIXME: maybe DefWindowProc() screws up, but it seems that
893 * modeless dialog boxes need this. If we don't do this, the focus
894 * will _not_ be set by DefWindowProc() for edit controls in a
895 * modeless dialog box ???
898 result
= MA_ACTIVATE
;
902 result
= EDIT_WM_MouseMove(es
, SLOWORD(lParam
), SHIWORD(lParam
));
906 EDIT_WM_Paint(es
, wParam
);
914 EDIT_WM_SetFocus(es
);
918 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
922 /* FIXME: actually set an internal flag and behave accordingly */
926 EDIT_WM_SetText(es
, lParam
, unicode
);
931 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
934 case WM_STYLECHANGED
:
935 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
938 case WM_STYLECHANGING
:
939 result
= 0; /* See EDIT_WM_StyleChanged */
943 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
951 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), SHIWORD(wParam
));
956 int gcWheelDelta
= 0;
957 UINT pulScrollLines
= 3;
958 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
960 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
961 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
964 gcWheelDelta
-= SHIWORD(wParam
);
965 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
967 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
968 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
969 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
974 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
978 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
983 /*********************************************************************
985 * EditWndProcW (USER32.@)
987 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
989 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
992 /*********************************************************************
994 * EditWndProc (USER32.@)
996 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
998 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1001 /*********************************************************************
1003 * EDIT_BuildLineDefs_ML
1005 * Build linked list of text lines.
1006 * Lines can end with '\0' (last line), a character (if it is wrapped),
1007 * a soft return '\r\r\n' or a hard return '\r\n'
1010 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1014 LPWSTR current_position
, cp
;
1016 LINEDEF
*current_line
;
1017 LINEDEF
*previous_line
;
1018 LINEDEF
*start_line
;
1019 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1020 INT line_count
= es
->line_count
;
1021 INT orig_net_length
;
1024 if (istart
== iend
&& delta
== 0)
1027 dc
= GetDC(es
->hwndSelf
);
1029 old_font
= SelectObject(dc
, es
->font
);
1031 previous_line
= NULL
;
1032 current_line
= es
->first_line_def
;
1034 /* Find starting line. istart must lie inside an existing line or
1035 * at the end of buffer */
1037 if (istart
< current_line
->index
+ current_line
->length
||
1038 current_line
->ending
== END_0
)
1041 previous_line
= current_line
;
1042 current_line
= current_line
->next
;
1044 } while (current_line
);
1046 if (!current_line
) /* Error occurred start is not inside previous buffer */
1048 FIXME(" modification occurred outside buffer\n");
1049 ReleaseDC(es
->hwndSelf
, dc
);
1053 /* Remember start of modifications in order to calculate update region */
1054 nstart_line
= line_index
;
1055 nstart_index
= current_line
->index
;
1057 /* We must start to reformat from the previous line since the modifications
1058 * may have caused the line to wrap upwards. */
1059 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1062 current_line
= previous_line
;
1064 start_line
= current_line
;
1066 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1067 current_position
= es
->text
+ current_line
->index
;
1069 if (current_line
!= start_line
)
1071 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1073 /* The buffer has been expanded, create a new line and
1074 insert it into the link list */
1075 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1076 new_line
->next
= previous_line
->next
;
1077 previous_line
->next
= new_line
;
1078 current_line
= new_line
;
1081 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1083 /* The previous line merged with this line so we delete this extra entry */
1084 previous_line
->next
= current_line
->next
;
1085 HeapFree(GetProcessHeap(), 0, current_line
);
1086 current_line
= previous_line
->next
;
1090 else /* current_line->index + delta == current_position */
1092 if (current_position
- es
->text
> iend
)
1093 break; /* We reached end of line modifications */
1094 /* else recalulate this line */
1098 current_line
->index
= current_position
- es
->text
;
1099 orig_net_length
= current_line
->net_length
;
1101 /* Find end of line */
1102 cp
= current_position
;
1104 if (*cp
== '\n') break;
1105 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1110 /* Mark type of line termination */
1112 current_line
->ending
= END_0
;
1113 current_line
->net_length
= strlenW(current_position
);
1114 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1115 current_line
->ending
= END_SOFT
;
1116 current_line
->net_length
= cp
- current_position
- 1;
1117 } else if (*cp
== '\n') {
1118 current_line
->ending
= END_RICH
;
1119 current_line
->net_length
= cp
- current_position
;
1121 current_line
->ending
= END_HARD
;
1122 current_line
->net_length
= cp
- current_position
;
1125 /* Calculate line width */
1126 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1127 current_position
, current_line
->net_length
,
1128 es
->tabs_count
, es
->tabs
));
1130 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1131 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1136 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1137 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1138 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1139 current_position
, next
, es
->tabs_count
, es
->tabs
));
1140 } while (current_line
->width
<= fw
);
1141 if (!prev
) { /* Didn't find a line break so force a break */
1146 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1147 current_position
, next
, es
->tabs_count
, es
->tabs
));
1148 } while (current_line
->width
<= fw
);
1153 /* If the first line we are calculating, wrapped before istart, we must
1154 * adjust istart in order for this to be reflected in the update region. */
1155 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1156 istart
= current_line
->index
+ prev
;
1157 /* else if we are updating the previous line before the first line we
1158 * are re-calculating and it expanded */
1159 else if (current_line
== start_line
&&
1160 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1162 /* Line expanded due to an upwards line wrap so we must partially include
1163 * previous line in update region */
1164 nstart_line
= line_index
;
1165 nstart_index
= current_line
->index
;
1166 istart
= current_line
->index
+ orig_net_length
;
1169 current_line
->net_length
= prev
;
1170 current_line
->ending
= END_WRAP
;
1171 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1172 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1176 /* Adjust length to include line termination */
1177 switch (current_line
->ending
) {
1179 current_line
->length
= current_line
->net_length
+ 3;
1182 current_line
->length
= current_line
->net_length
+ 1;
1185 current_line
->length
= current_line
->net_length
+ 2;
1189 current_line
->length
= current_line
->net_length
;
1192 es
->text_width
= max(es
->text_width
, current_line
->width
);
1193 current_position
+= current_line
->length
;
1194 previous_line
= current_line
;
1195 current_line
= current_line
->next
;
1197 } while (previous_line
->ending
!= END_0
);
1199 /* Finish adjusting line indexes by delta or remove hanging lines */
1200 if (previous_line
->ending
== END_0
)
1202 LINEDEF
*pnext
= NULL
;
1204 previous_line
->next
= NULL
;
1205 while (current_line
)
1207 pnext
= current_line
->next
;
1208 HeapFree(GetProcessHeap(), 0, current_line
);
1209 current_line
= pnext
;
1215 while (current_line
)
1217 current_line
->index
+= delta
;
1218 current_line
= current_line
->next
;
1222 /* Calculate rest of modification rectangle */
1227 * We calculate two rectangles. One for the first line which may have
1228 * an indent with respect to the format rect. The other is a format-width
1229 * rectangle that spans the rest of the lines that changed or moved.
1231 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1232 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1233 rc
.bottom
= rc
.top
+ es
->line_height
;
1234 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1235 es
->text
+ nstart_index
, istart
- nstart_index
,
1236 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1237 rc
.right
= es
->format_rect
.right
;
1238 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1241 rc
.left
= es
->format_rect
.left
;
1242 rc
.right
= es
->format_rect
.right
;
1244 * If lines were added or removed we must re-paint the remainder of the
1245 * lines since the remaining lines were either shifted up or down.
1247 if (line_count
< es
->line_count
) /* We added lines */
1248 rc
.bottom
= es
->line_count
* es
->line_height
;
1249 else if (line_count
> es
->line_count
) /* We removed lines */
1250 rc
.bottom
= line_count
* es
->line_height
;
1252 rc
.bottom
= line_index
* es
->line_height
;
1253 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1254 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1255 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1256 DeleteObject(tmphrgn
);
1260 SelectObject(dc
, old_font
);
1262 ReleaseDC(es
->hwndSelf
, dc
);
1265 /*********************************************************************
1267 * EDIT_CalcLineWidth_SL
1270 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1272 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(es
, strlenW(es
->text
), FALSE
));
1275 /*********************************************************************
1277 * EDIT_CallWordBreakProc
1279 * Call appropriate WordBreakProc (internal or external).
1281 * Note: The "start" argument should always be an index referring
1282 * to es->text. The actual wordbreak proc might be
1283 * 16 bit, so we can't always pass any 32 bit LPSTR.
1284 * Hence we assume that es->text is the buffer that holds
1285 * the string under examination (we can decide this for ourselves).
1288 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1290 INT ret
, iWndsLocks
;
1292 /* To avoid any deadlocks, all the locks on the window structures
1293 must be suspended before the control is passed to the application */
1294 iWndsLocks
= WIN_SuspendWndsLock();
1296 if (es
->word_break_proc16
) {
1303 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1304 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1305 segptr
= K32WOWGlobalLock16(hglob16
);
1306 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1307 args
[4] = SELECTOROF(segptr
);
1308 args
[3] = OFFSETOF(segptr
);
1312 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1313 ret
= LOWORD(result
);
1314 GlobalUnlock16(hglob16
);
1315 GlobalFree16(hglob16
);
1317 else if (es
->word_break_proc
)
1321 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1323 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1324 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1325 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1329 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1333 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1334 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1335 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1336 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1337 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1338 ret
= wbpA(textA
, index
, countA
, action
);
1339 HeapFree(GetProcessHeap(), 0, textA
);
1343 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1345 WIN_RestoreWndsLock(iWndsLocks
);
1350 /*********************************************************************
1354 * Beware: This is not the function called on EM_CHARFROMPOS
1355 * The position _can_ be outside the formatting / client
1357 * The return value is only the character index
1360 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1366 if (es
->style
& ES_MULTILINE
) {
1367 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1369 LINEDEF
*line_def
= es
->first_line_def
;
1371 while ((line
> 0) && line_def
->next
) {
1372 line_index
+= line_def
->length
;
1373 line_def
= line_def
->next
;
1376 x
+= es
->x_offset
- es
->format_rect
.left
;
1377 if (x
>= line_def
->width
) {
1379 *after_wrap
= (line_def
->ending
== END_WRAP
);
1380 return line_index
+ line_def
->net_length
;
1384 *after_wrap
= FALSE
;
1387 dc
= GetDC(es
->hwndSelf
);
1389 old_font
= SelectObject(dc
, es
->font
);
1390 low
= line_index
+ 1;
1391 high
= line_index
+ line_def
->net_length
+ 1;
1392 while (low
< high
- 1)
1394 INT mid
= (low
+ high
) / 2;
1395 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1401 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1402 (line_def
->ending
== END_WRAP
));
1407 *after_wrap
= FALSE
;
1408 x
-= es
->format_rect
.left
;
1410 return es
->x_offset
;
1411 text
= EDIT_GetPasswordPointer_SL(es
);
1412 dc
= GetDC(es
->hwndSelf
);
1414 old_font
= SelectObject(dc
, es
->font
);
1418 INT high
= es
->x_offset
;
1419 while (low
< high
- 1)
1421 INT mid
= (low
+ high
) / 2;
1422 GetTextExtentPoint32W( dc
, text
+ mid
,
1423 es
->x_offset
- mid
, &size
);
1424 if (size
.cx
> -x
) low
= mid
;
1431 INT low
= es
->x_offset
;
1432 INT high
= strlenW(es
->text
) + 1;
1433 while (low
< high
- 1)
1435 INT mid
= (low
+ high
) / 2;
1436 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1437 mid
- es
->x_offset
, &size
);
1438 if (size
.cx
> x
) high
= mid
;
1443 if (es
->style
& ES_PASSWORD
)
1444 HeapFree(GetProcessHeap(), 0, text
);
1447 SelectObject(dc
, old_font
);
1448 ReleaseDC(es
->hwndSelf
, dc
);
1453 /*********************************************************************
1457 * adjusts the point to be within the formatting rectangle
1458 * (so CharFromPos returns the nearest _visible_ character)
1461 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1463 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1464 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1468 /*********************************************************************
1472 * Calculates the bounding rectangle for a line from a starting
1473 * column to an ending column.
1476 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1478 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1480 if (es
->style
& ES_MULTILINE
)
1481 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1483 rc
->top
= es
->format_rect
.top
;
1484 rc
->bottom
= rc
->top
+ es
->line_height
;
1485 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1486 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1490 /*********************************************************************
1492 * EDIT_GetPasswordPointer_SL
1494 * note: caller should free the (optionally) allocated buffer
1497 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1499 if (es
->style
& ES_PASSWORD
) {
1500 INT len
= strlenW(es
->text
);
1501 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1503 while(len
) text
[--len
] = es
->password_char
;
1510 /*********************************************************************
1514 * This acts as a LOCAL_Lock(), but it locks only once. This way
1515 * you can call it whenever you like, without unlocking.
1517 * Initially the edit control allocates a HLOCAL32 buffer
1518 * (32 bit linear memory handler). However, 16 bit application
1519 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1520 * handler). From that moment on we have to keep using this 16 bit memory
1521 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1522 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1526 static void EDIT_LockBuffer(EDITSTATE
*es
)
1528 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1532 BOOL _16bit
= FALSE
;
1538 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1539 textA
= LocalLock(es
->hloc32A
);
1540 countA
= strlen(textA
) + 1;
1544 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1545 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1546 countA
= strlen(textA
) + 1;
1551 ERR("no buffer ... please report\n");
1558 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1559 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1560 if(countW_new
> es
->buffer_size
+ 1)
1562 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1563 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1564 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1567 es
->hloc32W
= hloc32W_new
;
1568 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1569 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1572 WARN("FAILED! Will synchronize partially\n");
1576 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1577 es
->text
= LocalLock(es
->hloc32W
);
1581 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1583 LOCAL_Unlock(hInstance
, es
->hloc16
);
1585 LocalUnlock(es
->hloc32A
);
1592 /*********************************************************************
1594 * EDIT_SL_InvalidateText
1596 * Called from EDIT_InvalidateText().
1597 * Does the job for single-line controls only.
1600 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1605 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1606 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1607 EDIT_UpdateText(es
, &rc
, TRUE
);
1611 /*********************************************************************
1613 * EDIT_ML_InvalidateText
1615 * Called from EDIT_InvalidateText().
1616 * Does the job for multi-line controls only.
1619 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1621 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1622 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1623 INT el
= EDIT_EM_LineFromChar(es
, end
);
1632 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1635 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1636 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1637 if (sl
< es
->y_offset
) {
1641 if (el
> es
->y_offset
+ vlc
) {
1642 el
= es
->y_offset
+ vlc
;
1643 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1645 GetClientRect(es
->hwndSelf
, &rc1
);
1646 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1648 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1649 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1650 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1652 EDIT_GetLineRect(es
, sl
, sc
,
1653 EDIT_EM_LineLength(es
,
1654 EDIT_EM_LineIndex(es
, sl
)),
1656 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1657 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1658 for (l
= sl
+ 1 ; l
< el
; l
++) {
1659 EDIT_GetLineRect(es
, l
, 0,
1660 EDIT_EM_LineLength(es
,
1661 EDIT_EM_LineIndex(es
, l
)),
1663 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1664 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1666 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1667 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1668 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1673 /*********************************************************************
1675 * EDIT_InvalidateText
1677 * Invalidate the text from offset start upto, but not including,
1678 * offset end. Useful for (re)painting the selection.
1679 * Regions outside the linewidth are not invalidated.
1680 * end == -1 means end == TextLength.
1681 * start and end need not be ordered.
1684 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1690 end
= strlenW(es
->text
);
1698 if (es
->style
& ES_MULTILINE
)
1699 EDIT_ML_InvalidateText(es
, start
, end
);
1701 EDIT_SL_InvalidateText(es
, start
, end
);
1705 /*********************************************************************
1709 * Try to fit size + 1 characters in the buffer.
1710 * Constrain to limits if honor_limit is TRUE.
1712 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
)
1716 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
1717 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
1721 if (size
<= es
->buffer_size
)
1724 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1726 /* Force edit to unlock it's buffer. es->text now NULL */
1727 EDIT_UnlockBuffer(es
, TRUE
);
1730 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1731 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1732 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1733 es
->hloc32W
= hNew32W
;
1734 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1738 EDIT_LockBuffer(es
);
1740 if (es
->buffer_size
< size
) {
1741 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1742 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1745 TRACE("We now have %d+1\n", es
->buffer_size
);
1751 /*********************************************************************
1755 * Try to fit size + 1 bytes in the undo buffer.
1758 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1762 if (size
<= es
->undo_buffer_size
)
1765 TRACE("trying to ReAlloc to %d+1\n", size
);
1767 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1768 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1769 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1774 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1780 /*********************************************************************
1785 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1787 INT e
= es
->selection_end
;
1791 if ((es
->style
& ES_MULTILINE
) && e
&&
1792 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1794 if (e
&& (es
->text
[e
- 1] == '\r'))
1798 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1799 EDIT_EM_ScrollCaret(es
);
1803 /*********************************************************************
1807 * Only for multi line controls
1808 * Move the caret one line down, on a column with the nearest
1809 * x coordinate on the screen (might be a different column).
1812 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1814 INT s
= es
->selection_start
;
1815 INT e
= es
->selection_end
;
1816 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1817 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1818 INT x
= SLOWORD(pos
);
1819 INT y
= SHIWORD(pos
);
1821 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1824 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1825 EDIT_EM_ScrollCaret(es
);
1829 /*********************************************************************
1834 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1836 BOOL after_wrap
= FALSE
;
1839 /* Pass a high value in x to make sure of receiving the end of the line */
1840 if (es
->style
& ES_MULTILINE
)
1841 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1842 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1844 e
= strlenW(es
->text
);
1845 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1846 EDIT_EM_ScrollCaret(es
);
1850 /*********************************************************************
1855 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1857 INT e
= es
->selection_end
;
1861 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1862 if (es
->text
[e
] == '\n')
1864 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1868 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1869 EDIT_EM_ScrollCaret(es
);
1873 /*********************************************************************
1877 * Home key: move to beginning of line.
1880 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1884 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1885 if (es
->style
& ES_MULTILINE
)
1886 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1887 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1890 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1891 EDIT_EM_ScrollCaret(es
);
1895 /*********************************************************************
1897 * EDIT_MovePageDown_ML
1899 * Only for multi line controls
1900 * Move the caret one page down, on a column with the nearest
1901 * x coordinate on the screen (might be a different column).
1904 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1906 INT s
= es
->selection_start
;
1907 INT e
= es
->selection_end
;
1908 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1909 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1910 INT x
= SLOWORD(pos
);
1911 INT y
= SHIWORD(pos
);
1913 e
= EDIT_CharFromPos(es
, x
,
1914 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1918 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1919 EDIT_EM_ScrollCaret(es
);
1923 /*********************************************************************
1925 * EDIT_MovePageUp_ML
1927 * Only for multi line controls
1928 * Move the caret one page up, on a column with the nearest
1929 * x coordinate on the screen (might be a different column).
1932 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1934 INT s
= es
->selection_start
;
1935 INT e
= es
->selection_end
;
1936 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1937 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1938 INT x
= SLOWORD(pos
);
1939 INT y
= SHIWORD(pos
);
1941 e
= EDIT_CharFromPos(es
, x
,
1942 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1946 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1947 EDIT_EM_ScrollCaret(es
);
1951 /*********************************************************************
1955 * Only for multi line controls
1956 * Move the caret one line up, on a column with the nearest
1957 * x coordinate on the screen (might be a different column).
1960 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1962 INT s
= es
->selection_start
;
1963 INT e
= es
->selection_end
;
1964 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1965 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1966 INT x
= SLOWORD(pos
);
1967 INT y
= SHIWORD(pos
);
1969 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1972 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1973 EDIT_EM_ScrollCaret(es
);
1977 /*********************************************************************
1979 * EDIT_MoveWordBackward
1982 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1984 INT s
= es
->selection_start
;
1985 INT e
= es
->selection_end
;
1990 l
= EDIT_EM_LineFromChar(es
, e
);
1991 ll
= EDIT_EM_LineLength(es
, e
);
1992 li
= EDIT_EM_LineIndex(es
, l
);
1995 li
= EDIT_EM_LineIndex(es
, l
- 1);
1996 e
= li
+ EDIT_EM_LineLength(es
, li
);
1999 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2000 li
, e
- li
, ll
, WB_LEFT
);
2004 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2005 EDIT_EM_ScrollCaret(es
);
2009 /*********************************************************************
2011 * EDIT_MoveWordForward
2014 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2016 INT s
= es
->selection_start
;
2017 INT e
= es
->selection_end
;
2022 l
= EDIT_EM_LineFromChar(es
, e
);
2023 ll
= EDIT_EM_LineLength(es
, e
);
2024 li
= EDIT_EM_LineIndex(es
, l
);
2026 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2027 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2029 e
= li
+ EDIT_CallWordBreakProc(es
,
2030 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2034 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2035 EDIT_EM_ScrollCaret(es
);
2039 /*********************************************************************
2044 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2046 INT s
= es
->selection_start
;
2047 INT e
= es
->selection_end
;
2054 if (es
->style
& ES_MULTILINE
) {
2055 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2056 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2061 TRACE("line=%d\n", line
);
2063 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2066 li
= EDIT_EM_LineIndex(es
, line
);
2067 ll
= EDIT_EM_LineLength(es
, li
);
2068 s
= min(es
->selection_start
, es
->selection_end
);
2069 e
= max(es
->selection_start
, es
->selection_end
);
2070 s
= min(li
+ ll
, max(li
, s
));
2071 e
= min(li
+ ll
, max(li
, e
));
2072 if (rev
&& (s
!= e
) &&
2073 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2074 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2075 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2076 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2078 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2082 /*********************************************************************
2087 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2098 BkMode
= GetBkMode(dc
);
2099 BkColor
= GetBkColor(dc
);
2100 TextColor
= GetTextColor(dc
);
2102 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2103 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2104 SetBkMode( dc
, OPAQUE
);
2106 li
= EDIT_EM_LineIndex(es
, line
);
2107 if (es
->style
& ES_MULTILINE
) {
2108 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2109 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2111 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2112 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2113 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2115 if (es
->style
& ES_PASSWORD
)
2116 HeapFree(GetProcessHeap(), 0, text
);
2119 SetBkColor(dc
, BkColor
);
2120 SetTextColor(dc
, TextColor
);
2121 SetBkMode( dc
, BkMode
);
2127 /*********************************************************************
2132 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2135 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2136 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2140 /*********************************************************************
2144 * note: this is not (exactly) the handler called on EM_SETRECTNP
2145 * it is also used to set the rect of a single line control
2148 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2150 CopyRect(&es
->format_rect
, rc
);
2151 if (es
->style
& WS_BORDER
) {
2152 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2153 if(TWEAK_WineLook
== WIN31_LOOK
)
2155 es
->format_rect
.left
+= bw
;
2156 es
->format_rect
.top
+= bw
;
2157 es
->format_rect
.right
-= bw
;
2158 es
->format_rect
.bottom
-= bw
;
2160 es
->format_rect
.left
+= es
->left_margin
;
2161 es
->format_rect
.right
-= es
->right_margin
;
2162 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2163 if (es
->style
& ES_MULTILINE
)
2165 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2167 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2168 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2170 /* correct es->x_offset */
2171 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2172 max_x_offset
= es
->text_width
- fw
;
2173 if(max_x_offset
< 0) max_x_offset
= 0;
2174 if(es
->x_offset
> max_x_offset
)
2175 es
->x_offset
= max_x_offset
;
2177 /* correct es->y_offset */
2178 max_y_offset
= es
->line_count
- vlc
;
2179 if(max_y_offset
< 0) max_y_offset
= 0;
2180 if(es
->y_offset
> max_y_offset
)
2181 es
->y_offset
= max_y_offset
;
2183 /* force scroll info update */
2184 EDIT_UpdateScrollInfo(es
);
2187 /* Windows doesn't care to fix text placement for SL controls */
2188 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2190 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2191 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2195 /*********************************************************************
2200 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2202 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2204 /* Edit window might be already destroyed */
2205 if(!IsWindow(es
->hwndSelf
))
2207 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2211 if (!es
->lock_count
) {
2212 ERR("lock_count == 0 ... please report\n");
2216 ERR("es->text == 0 ... please report\n");
2220 if (force
|| (es
->lock_count
== 1)) {
2223 BOOL _16bit
= FALSE
;
2225 UINT countW
= strlenW(es
->text
) + 1;
2229 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2230 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2231 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2232 countA
= LocalSize(es
->hloc32A
);
2233 if(countA_new
> countA
)
2236 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2237 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2238 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2241 es
->hloc32A
= hloc32A_new
;
2242 countA
= LocalSize(hloc32A_new
);
2243 TRACE("Real new size %d bytes\n", countA
);
2246 WARN("FAILED! Will synchronize partially\n");
2248 textA
= LocalLock(es
->hloc32A
);
2252 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2253 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2254 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2255 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2256 if(countA_new
> countA
)
2258 HLOCAL16 hloc16_new
;
2259 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2260 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2261 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2264 es
->hloc16
= hloc16_new
;
2265 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2266 TRACE("Real new size %d bytes\n", countA
);
2269 WARN("FAILED! Will synchronize partially\n");
2271 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2277 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2279 LOCAL_Unlock(hInstance
, es
->hloc16
);
2281 LocalUnlock(es
->hloc32A
);
2284 LocalUnlock(es
->hloc32W
);
2288 ERR("no buffer ... please report\n");
2296 /*********************************************************************
2298 * EDIT_UpdateScrollInfo
2301 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2303 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2306 si
.cbSize
= sizeof(SCROLLINFO
);
2307 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2309 si
.nMax
= es
->line_count
- 1;
2310 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2311 si
.nPos
= es
->y_offset
;
2312 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2313 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2314 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2317 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2320 si
.cbSize
= sizeof(SCROLLINFO
);
2321 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2323 si
.nMax
= es
->text_width
- 1;
2324 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2325 si
.nPos
= es
->x_offset
;
2326 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2327 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2328 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2332 /*********************************************************************
2334 * EDIT_WordBreakProc
2336 * Find the beginning of words.
2337 * Note: unlike the specs for a WordBreakProc, this function only
2338 * allows to be called without linebreaks between s[0] upto
2339 * s[count - 1]. Remember it is only called
2340 * internally, so we can decide this for ourselves.
2343 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2347 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2357 if (s
[index
] == ' ') {
2358 while (index
&& (s
[index
] == ' '))
2361 while (index
&& (s
[index
] != ' '))
2363 if (s
[index
] == ' ')
2367 while (index
&& (s
[index
] != ' '))
2369 if (s
[index
] == ' ')
2379 if (s
[index
] == ' ')
2380 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2382 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2384 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2388 case WB_ISDELIMITER
:
2389 ret
= (s
[index
] == ' ');
2392 ERR("unknown action code, please report !\n");
2399 /*********************************************************************
2403 * returns line number (not index) in high-order word of result.
2404 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2405 * to Richedit, not to the edit control. Original documentation is valid.
2406 * FIXME: do the specs mean to return -1 if outside client area or
2407 * if outside formatting rectangle ???
2410 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2418 GetClientRect(es
->hwndSelf
, &rc
);
2419 if (!PtInRect(&rc
, pt
))
2422 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2423 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2427 /*********************************************************************
2431 * Enable or disable soft breaks.
2433 * This means: insert or remove the soft linebreak character (\r\r\n).
2434 * Take care to check if the text still fits the buffer after insertion.
2435 * If not, notify with EN_ERRSPACE.
2438 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2440 es
->flags
&= ~EF_USE_SOFTBRK
;
2442 es
->flags
|= EF_USE_SOFTBRK
;
2443 FIXME("soft break enabled, not implemented\n");
2449 /*********************************************************************
2453 * Hopefully this won't fire back at us.
2454 * We always start with a fixed buffer in the local heap.
2455 * Despite of the documentation says that the local heap is used
2456 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2457 * buffer on the local heap.
2460 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2464 if (!(es
->style
& ES_MULTILINE
))
2468 hLocal
= es
->hloc32W
;
2474 UINT countA
, alloc_size
;
2475 TRACE("Allocating 32-bit ANSI alias buffer\n");
2476 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2477 alloc_size
= ROUND_TO_GROW(countA
);
2478 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2480 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2483 textA
= LocalLock(es
->hloc32A
);
2484 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2485 LocalUnlock(es
->hloc32A
);
2487 hLocal
= es
->hloc32A
;
2490 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2495 /*********************************************************************
2499 * Hopefully this won't fire back at us.
2500 * We always start with a buffer in 32 bit linear memory.
2501 * However, with this message a 16 bit application requests
2502 * a handle of 16 bit local heap memory, where it expects to find
2504 * It's a pitty that from this moment on we have to use this
2505 * local heap, because applications may rely on the handle
2508 * In this function we'll try to switch to local heap.
2510 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2512 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2514 UINT countA
, alloc_size
;
2516 if (!(es
->style
& ES_MULTILINE
))
2522 if (!LOCAL_HeapSize(hInstance
)) {
2523 if (!LocalInit16(hInstance
, 0,
2524 GlobalSize16(hInstance
))) {
2525 ERR("could not initialize local heap\n");
2528 TRACE("local heap initialized\n");
2531 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2532 alloc_size
= ROUND_TO_GROW(countA
);
2534 TRACE("Allocating 16-bit ANSI alias buffer\n");
2535 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2536 ERR("could not allocate new 16 bit buffer\n");
2540 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2541 ERR("could not lock new 16 bit buffer\n");
2542 LOCAL_Free(hInstance
, es
->hloc16
);
2547 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2548 LOCAL_Unlock(hInstance
, es
->hloc16
);
2550 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2555 /*********************************************************************
2560 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2563 INT line_len
, dst_len
;
2566 if (es
->style
& ES_MULTILINE
) {
2567 if (line
>= es
->line_count
)
2571 i
= EDIT_EM_LineIndex(es
, line
);
2573 line_len
= EDIT_EM_LineLength(es
, i
);
2574 dst_len
= *(WORD
*)lParam
;
2577 LPWSTR dst
= (LPWSTR
)lParam
;
2578 if(dst_len
<= line_len
)
2580 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2583 else /* Append 0 if enough space */
2585 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2592 LPSTR dst
= (LPSTR
)lParam
;
2594 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2595 if(!ret
) /* Insufficient buffer size */
2597 if(ret
< dst_len
) /* Append 0 if enough space */
2604 /*********************************************************************
2609 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2611 UINT s
= es
->selection_start
;
2612 UINT e
= es
->selection_end
;
2619 return MAKELONG(s
, e
);
2623 /*********************************************************************
2627 * FIXME: is this right ? (or should it be only VSCROLL)
2628 * (and maybe only for edit controls that really have their
2629 * own scrollbars) (and maybe only for multiline controls ?)
2630 * All in all: very poorly documented
2633 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2635 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2636 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2640 /*********************************************************************
2645 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2650 if (!(es
->style
& ES_MULTILINE
))
2652 if (index
> (INT
)strlenW(es
->text
))
2653 return es
->line_count
- 1;
2655 index
= min(es
->selection_start
, es
->selection_end
);
2658 line_def
= es
->first_line_def
;
2659 index
-= line_def
->length
;
2660 while ((index
>= 0) && line_def
->next
) {
2662 line_def
= line_def
->next
;
2663 index
-= line_def
->length
;
2669 /*********************************************************************
2674 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2679 if (!(es
->style
& ES_MULTILINE
))
2681 if (line
>= es
->line_count
)
2685 line_def
= es
->first_line_def
;
2687 INT index
= es
->selection_end
- line_def
->length
;
2688 while ((index
>= 0) && line_def
->next
) {
2689 line_index
+= line_def
->length
;
2690 line_def
= line_def
->next
;
2691 index
-= line_def
->length
;
2695 line_index
+= line_def
->length
;
2696 line_def
= line_def
->next
;
2704 /*********************************************************************
2709 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2713 if (!(es
->style
& ES_MULTILINE
))
2714 return strlenW(es
->text
);
2717 /* get the number of remaining non-selected chars of selected lines */
2718 INT32 l
; /* line number */
2719 INT32 li
; /* index of first char in line */
2721 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2722 /* # chars before start of selection area */
2723 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2724 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2725 /* # chars after end of selection */
2726 li
= EDIT_EM_LineIndex(es
, l
);
2727 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2730 line_def
= es
->first_line_def
;
2731 index
-= line_def
->length
;
2732 while ((index
>= 0) && line_def
->next
) {
2733 line_def
= line_def
->next
;
2734 index
-= line_def
->length
;
2736 return line_def
->net_length
;
2740 /*********************************************************************
2744 * NOTE: dx is in average character widths, dy - in lines;
2747 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2749 if (!(es
->style
& ES_MULTILINE
))
2752 dx
*= es
->char_width
;
2753 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2756 /*********************************************************************
2758 * EDIT_EM_LineScroll_internal
2760 * Version of EDIT_EM_LineScroll for internal use.
2761 * It doesn't refuse if ES_MULTILINE is set and assumes that
2762 * dx is in pixels, dy - in lines.
2765 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2768 INT x_offset_in_pixels
;
2770 if (es
->style
& ES_MULTILINE
)
2772 x_offset_in_pixels
= es
->x_offset
;
2777 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2780 if (-dx
> x_offset_in_pixels
)
2781 dx
= -x_offset_in_pixels
;
2782 if (dx
> es
->text_width
- x_offset_in_pixels
)
2783 dx
= es
->text_width
- x_offset_in_pixels
;
2784 nyoff
= max(0, es
->y_offset
+ dy
);
2785 if (nyoff
>= es
->line_count
)
2786 nyoff
= es
->line_count
- 1;
2787 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2792 es
->y_offset
= nyoff
;
2793 if(es
->style
& ES_MULTILINE
)
2796 es
->x_offset
+= dx
/ es
->char_width
;
2798 GetClientRect(es
->hwndSelf
, &rc1
);
2799 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2800 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2801 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2802 /* force scroll info update */
2803 EDIT_UpdateScrollInfo(es
);
2805 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2806 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2807 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2808 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2813 /*********************************************************************
2818 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2820 INT len
= strlenW(es
->text
);
2829 index
= min(index
, len
);
2830 dc
= GetDC(es
->hwndSelf
);
2832 old_font
= SelectObject(dc
, es
->font
);
2833 if (es
->style
& ES_MULTILINE
) {
2834 l
= EDIT_EM_LineFromChar(es
, index
);
2835 y
= (l
- es
->y_offset
) * es
->line_height
;
2836 li
= EDIT_EM_LineIndex(es
, l
);
2837 if (after_wrap
&& (li
== index
) && l
) {
2839 LINEDEF
*line_def
= es
->first_line_def
;
2841 line_def
= line_def
->next
;
2844 if (line_def
->ending
== END_WRAP
) {
2846 y
-= es
->line_height
;
2847 li
= EDIT_EM_LineIndex(es
, l
);
2850 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2851 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2853 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2854 if (index
< es
->x_offset
) {
2855 GetTextExtentPoint32W(dc
, text
+ index
,
2856 es
->x_offset
- index
, &size
);
2859 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2860 index
- es
->x_offset
, &size
);
2864 if (es
->style
& ES_PASSWORD
)
2865 HeapFree(GetProcessHeap(), 0, text
);
2867 x
+= es
->format_rect
.left
;
2868 y
+= es
->format_rect
.top
;
2870 SelectObject(dc
, old_font
);
2871 ReleaseDC(es
->hwndSelf
, dc
);
2872 return MAKELONG((INT16
)x
, (INT16
)y
);
2876 /*********************************************************************
2880 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2883 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2885 UINT strl
= strlenW(lpsz_replace
);
2886 UINT tl
= strlenW(es
->text
);
2894 TRACE("%s, can_undo %d, send_update %d\n",
2895 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2897 s
= es
->selection_start
;
2898 e
= es
->selection_end
;
2900 if ((s
== e
) && !strl
)
2905 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
, honor_limit
))
2909 /* there is something to be deleted */
2910 TRACE("deleting stuff.\n");
2912 utl
= strlenW(es
->undo_text
);
2913 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2914 /* undo-buffer is extended to the right */
2915 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2916 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2917 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2918 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2919 /* undo-buffer is extended to the left */
2920 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2921 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2923 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2924 p
[i
] = (es
->text
+ s
)[i
];
2925 es
->undo_position
= s
;
2927 /* new undo-buffer */
2928 EDIT_MakeUndoFit(es
, e
- s
);
2929 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2930 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2931 es
->undo_position
= s
;
2933 /* any deletion makes the old insertion-undo invalid */
2934 es
->undo_insert_count
= 0;
2936 EDIT_EM_EmptyUndoBuffer(es
);
2939 strcpyW(es
->text
+ s
, es
->text
+ e
);
2942 /* there is an insertion */
2944 if ((s
== es
->undo_position
) ||
2945 ((es
->undo_insert_count
) &&
2946 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2948 * insertion is new and at delete position or
2949 * an extension to either left or right
2951 es
->undo_insert_count
+= strl
;
2953 /* new insertion undo */
2954 es
->undo_position
= s
;
2955 es
->undo_insert_count
= strl
;
2956 /* new insertion makes old delete-buffer invalid */
2957 *es
->undo_text
= '\0';
2960 EDIT_EM_EmptyUndoBuffer(es
);
2963 tl
= strlenW(es
->text
);
2964 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
));
2965 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2967 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2968 p
[i
] = lpsz_replace
[i
];
2969 if(es
->style
& ES_UPPERCASE
)
2970 CharUpperBuffW(p
, strl
);
2971 else if(es
->style
& ES_LOWERCASE
)
2972 CharLowerBuffW(p
, strl
);
2975 if (es
->style
& ES_MULTILINE
)
2977 INT s
= min(es
->selection_start
, es
->selection_end
);
2979 hrgn
= CreateRectRgn(0, 0, 0, 0);
2980 EDIT_BuildLineDefs_ML(es
, s
, s
+ strl
,
2981 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2984 EDIT_CalcLineWidth_SL(es
);
2986 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2987 es
->flags
|= EF_MODIFIED
;
2988 if (send_update
) es
->flags
|= EF_UPDATE
;
2989 EDIT_EM_ScrollCaret(es
);
2991 /* force scroll info update */
2992 EDIT_UpdateScrollInfo(es
);
2996 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3000 EDIT_UpdateText(es
, NULL
, TRUE
);
3002 if(es
->flags
& EF_UPDATE
)
3004 es
->flags
&= ~EF_UPDATE
;
3005 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3010 /*********************************************************************
3015 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3019 if (!(es
->style
& ES_MULTILINE
))
3020 return (LRESULT
)FALSE
;
3030 if (es
->y_offset
< es
->line_count
- 1)
3035 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3038 if (es
->y_offset
< es
->line_count
- 1)
3039 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3042 return (LRESULT
)FALSE
;
3045 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3046 /* check if we are going to move too far */
3047 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3048 dy
= es
->line_count
- vlc
- es
->y_offset
;
3050 /* Notification is done in EDIT_EM_LineScroll */
3052 EDIT_EM_LineScroll(es
, 0, dy
);
3054 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3058 /*********************************************************************
3063 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3065 if (es
->style
& ES_MULTILINE
) {
3070 INT cw
= es
->char_width
;
3075 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3076 li
= EDIT_EM_LineIndex(es
, l
);
3077 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3078 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3079 if (l
>= es
->y_offset
+ vlc
)
3080 dy
= l
- vlc
+ 1 - es
->y_offset
;
3081 if (l
< es
->y_offset
)
3082 dy
= l
- es
->y_offset
;
3083 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3084 if (x
< es
->format_rect
.left
)
3085 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3086 if (x
> es
->format_rect
.right
)
3087 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3090 /* check if we are going to move too far */
3091 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3092 dx
= es
->text_width
- ww
- es
->x_offset
;
3094 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3101 if (!(es
->style
& ES_AUTOHSCROLL
))
3104 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3105 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3106 if (x
< es
->format_rect
.left
) {
3107 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3110 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3111 } while ((x
< goal
) && es
->x_offset
);
3112 /* FIXME: use ScrollWindow() somehow to improve performance */
3113 EDIT_UpdateText(es
, NULL
, TRUE
);
3114 } else if (x
> es
->format_rect
.right
) {
3116 INT len
= strlenW(es
->text
);
3117 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3120 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3121 x_last
= SLOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3122 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3123 /* FIXME: use ScrollWindow() somehow to improve performance */
3124 EDIT_UpdateText(es
, NULL
, TRUE
);
3128 if(es
->flags
& EF_FOCUSED
)
3129 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3133 /*********************************************************************
3137 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3140 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3142 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3144 if (!(es
->style
& ES_MULTILINE
))
3148 WARN("called with NULL handle\n");
3152 EDIT_UnlockBuffer(es
, TRUE
);
3156 LOCAL_Free(hInstance
, es
->hloc16
);
3157 es
->hloc16
= (HLOCAL16
)NULL
;
3164 LocalFree(es
->hloc32A
);
3176 countA
= LocalSize(hloc
);
3177 textA
= LocalLock(hloc
);
3178 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3179 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3181 ERR("Could not allocate new unicode buffer\n");
3184 textW
= LocalLock(hloc32W_new
);
3185 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3186 LocalUnlock(hloc32W_new
);
3190 LocalFree(es
->hloc32W
);
3192 es
->hloc32W
= hloc32W_new
;
3196 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3198 EDIT_LockBuffer(es
);
3200 es
->x_offset
= es
->y_offset
= 0;
3201 es
->selection_start
= es
->selection_end
= 0;
3202 EDIT_EM_EmptyUndoBuffer(es
);
3203 es
->flags
&= ~EF_MODIFIED
;
3204 es
->flags
&= ~EF_UPDATE
;
3205 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3206 EDIT_UpdateText(es
, NULL
, TRUE
);
3207 EDIT_EM_ScrollCaret(es
);
3208 /* force scroll info update */
3209 EDIT_UpdateScrollInfo(es
);
3213 /*********************************************************************
3217 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3220 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3222 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3228 if (!(es
->style
& ES_MULTILINE
))
3232 WARN("called with NULL handle\n");
3236 EDIT_UnlockBuffer(es
, TRUE
);
3240 LocalFree(es
->hloc32A
);
3244 countA
= LOCAL_Size(hInstance
, hloc
);
3245 textA
= LOCAL_Lock(hInstance
, hloc
);
3246 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3247 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3249 ERR("Could not allocate new unicode buffer\n");
3252 textW
= LocalLock(hloc32W_new
);
3253 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3254 LocalUnlock(hloc32W_new
);
3255 LOCAL_Unlock(hInstance
, hloc
);
3258 LocalFree(es
->hloc32W
);
3260 es
->hloc32W
= hloc32W_new
;
3263 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3265 EDIT_LockBuffer(es
);
3267 es
->x_offset
= es
->y_offset
= 0;
3268 es
->selection_start
= es
->selection_end
= 0;
3269 EDIT_EM_EmptyUndoBuffer(es
);
3270 es
->flags
&= ~EF_MODIFIED
;
3271 es
->flags
&= ~EF_UPDATE
;
3272 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3273 EDIT_UpdateText(es
, NULL
, TRUE
);
3274 EDIT_EM_ScrollCaret(es
);
3275 /* force scroll info update */
3276 EDIT_UpdateScrollInfo(es
);
3280 /*********************************************************************
3284 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3285 * However, the windows version is not complied to yet in all of edit.c
3287 * Additionally as the wrapper for RichEdit controls we need larger buffers
3288 * at present -1 will represent nolimit
3290 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3292 if (limit
== 0xFFFFFFFF)
3293 es
->buffer_limit
= -1;
3294 else if (es
->style
& ES_MULTILINE
) {
3296 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3298 es
->buffer_limit
= BUFLIMIT_MULTI
;
3301 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3303 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3308 /*********************************************************************
3312 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3313 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3314 * margin according to the textmetrics of the current font.
3316 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3317 * of the char's width as the margin, but this is not how Windows handles this.
3318 * For all other fonts Windows sets the margins to zero.
3321 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3322 INT left
, INT right
)
3325 INT default_left_margin
= 0; /* in pixels */
3326 INT default_right_margin
= 0; /* in pixels */
3328 /* Set the default margins depending on the font */
3329 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3330 HDC dc
= GetDC(es
->hwndSelf
);
3331 HFONT old_font
= SelectObject(dc
, es
->font
);
3332 GetTextMetricsW(dc
, &tm
);
3333 /* The default margins are only non zero for TrueType or Vector fonts */
3334 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3335 /* This must be calculated more exactly! But how? */
3336 default_left_margin
= tm
.tmAveCharWidth
/ 3;
3337 default_right_margin
= tm
.tmAveCharWidth
/ 3;
3339 SelectObject(dc
, old_font
);
3340 ReleaseDC(es
->hwndSelf
, dc
);
3343 if (action
& EC_LEFTMARGIN
) {
3344 if (left
!= EC_USEFONTINFO
)
3345 es
->left_margin
= left
;
3347 es
->left_margin
= default_left_margin
;
3350 if (action
& EC_RIGHTMARGIN
) {
3351 if (right
!= EC_USEFONTINFO
)
3352 es
->right_margin
= right
;
3354 es
->right_margin
= default_right_margin
;
3356 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3360 /*********************************************************************
3362 * EM_SETPASSWORDCHAR
3365 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3369 if (es
->style
& ES_MULTILINE
)
3372 if (es
->password_char
== c
)
3375 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3376 es
->password_char
= c
;
3378 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3379 es
->style
|= ES_PASSWORD
;
3381 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3382 es
->style
&= ~ES_PASSWORD
;
3384 EDIT_UpdateText(es
, NULL
, TRUE
);
3388 /*********************************************************************
3392 * note: unlike the specs say: the order of start and end
3393 * _is_ preserved in Windows. (i.e. start can be > end)
3394 * In other words: this handler is OK
3397 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3399 UINT old_start
= es
->selection_start
;
3400 UINT old_end
= es
->selection_end
;
3401 UINT len
= strlenW(es
->text
);
3403 if (start
== (UINT
)-1) {
3404 start
= es
->selection_end
;
3405 end
= es
->selection_end
;
3407 start
= min(start
, len
);
3408 end
= min(end
, len
);
3410 es
->selection_start
= start
;
3411 es
->selection_end
= end
;
3413 es
->flags
|= EF_AFTER_WRAP
;
3415 es
->flags
&= ~EF_AFTER_WRAP
;
3416 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3417 ORDER_UINT(start
, end
);
3418 ORDER_UINT(end
, old_end
);
3419 ORDER_UINT(start
, old_start
);
3420 ORDER_UINT(old_start
, old_end
);
3421 if (end
!= old_start
)
3425 * ORDER_UINT32(end, old_start);
3426 * EDIT_InvalidateText(es, start, end);
3427 * EDIT_InvalidateText(es, old_start, old_end);
3428 * in place of the following if statement.
3430 if (old_start
> end
)
3432 EDIT_InvalidateText(es
, start
, end
);
3433 EDIT_InvalidateText(es
, old_start
, old_end
);
3437 EDIT_InvalidateText(es
, start
, old_start
);
3438 EDIT_InvalidateText(es
, end
, old_end
);
3441 else EDIT_InvalidateText(es
, start
, old_end
);
3445 /*********************************************************************
3450 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3452 if (!(es
->style
& ES_MULTILINE
))
3455 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3456 es
->tabs_count
= count
;
3460 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3461 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3467 /*********************************************************************
3472 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3474 if (!(es
->style
& ES_MULTILINE
))
3477 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3478 es
->tabs_count
= count
;
3483 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3484 for (i
= 0 ; i
< count
; i
++)
3485 es
->tabs
[i
] = *tabs
++;
3491 /*********************************************************************
3493 * EM_SETWORDBREAKPROC
3496 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
)
3498 if (es
->word_break_proc
== (void *)lParam
)
3501 es
->word_break_proc
= (void *)lParam
;
3502 es
->word_break_proc16
= NULL
;
3504 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3505 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3506 EDIT_UpdateText(es
, NULL
, TRUE
);
3511 /*********************************************************************
3513 * EM_SETWORDBREAKPROC16
3516 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3518 if (es
->word_break_proc16
== wbp
)
3521 es
->word_break_proc
= NULL
;
3522 es
->word_break_proc16
= wbp
;
3523 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3524 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3525 EDIT_UpdateText(es
, NULL
, TRUE
);
3530 /*********************************************************************
3535 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3540 /* Protect read-only edit control from modification */
3541 if(es
->style
& ES_READONLY
)
3544 ulength
= strlenW(es
->undo_text
);
3545 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3547 strcpyW(utext
, es
->undo_text
);
3549 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3550 es
->undo_insert_count
, debugstr_w(utext
));
3552 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3553 EDIT_EM_EmptyUndoBuffer(es
);
3554 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, FALSE
, TRUE
);
3555 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3556 /* send the notification after the selection start and end are set */
3557 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3558 EDIT_EM_ScrollCaret(es
);
3559 HeapFree(GetProcessHeap(), 0, utext
);
3561 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3562 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3567 /*********************************************************************
3572 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3576 /* Protect read-only edit control from modification */
3577 if(es
->style
& ES_READONLY
)
3580 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3584 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3585 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3588 if (es
->style
& ES_MULTILINE
) {
3589 if (es
->style
& ES_READONLY
) {
3590 EDIT_MoveHome(es
, FALSE
);
3591 EDIT_MoveDown_ML(es
, FALSE
);
3593 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3594 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3599 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3601 static const WCHAR tabW
[] = {'\t',0};
3602 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3606 if (!(es
->style
& ES_READONLY
) && !control
) {
3607 if (es
->selection_start
!= es
->selection_end
)
3610 /* delete character left of caret */
3611 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3612 EDIT_MoveBackward(es
, TRUE
);
3618 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3621 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3624 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3628 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3632 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3639 /*********************************************************************
3644 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3646 if (code
|| control
)
3666 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3667 EDIT_EM_ScrollCaret(es
);
3670 ERR("unknown menu item, please report\n");
3676 /*********************************************************************
3680 * Note: the resource files resource/sysres_??.rc cannot define a
3681 * single popup menu. Hence we use a (dummy) menubar
3682 * containing the single popup menu as its first item.
3684 * FIXME: the message identifiers have been chosen arbitrarily,
3685 * hence we use MF_BYPOSITION.
3686 * We might as well use the "real" values (anybody knows ?)
3687 * The menu definition is in resources/sysres_??.rc.
3688 * Once these are OK, we better use MF_BYCOMMAND here
3689 * (as we do in EDIT_WM_Command()).
3692 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3694 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3695 HMENU popup
= GetSubMenu(menu
, 0);
3696 UINT start
= es
->selection_start
;
3697 UINT end
= es
->selection_end
;
3699 ORDER_UINT(start
, end
);
3702 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3704 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3706 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3708 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3710 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3712 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3714 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3719 /*********************************************************************
3724 static void EDIT_WM_Copy(EDITSTATE
*es
)
3726 INT s
= min(es
->selection_start
, es
->selection_end
);
3727 INT e
= max(es
->selection_start
, es
->selection_end
);
3733 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3734 dst
= GlobalLock(hdst
);
3735 strncpyW(dst
, es
->text
+ s
, e
- s
);
3736 dst
[e
- s
] = 0; /* ensure 0 termination */
3737 TRACE("%s\n", debugstr_w(dst
));
3739 OpenClipboard(es
->hwndSelf
);
3741 SetClipboardData(CF_UNICODETEXT
, hdst
);
3746 /*********************************************************************
3751 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3753 TRACE("%s\n", debugstr_w(name
));
3755 * To initialize some final structure members, we call some helper
3756 * functions. However, since the EDITSTATE is not consistent (i.e.
3757 * not fully initialized), we should be very careful which
3758 * functions can be called, and in what order.
3760 EDIT_WM_SetFont(es
, 0, FALSE
);
3761 EDIT_EM_EmptyUndoBuffer(es
);
3763 if (name
&& *name
) {
3764 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3765 /* if we insert text to the editline, the text scrolls out
3766 * of the window, as the caret is placed after the insert
3767 * pos normally; thus we reset es->selection... to 0 and
3770 es
->selection_start
= es
->selection_end
= 0;
3771 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3772 * Messages are only to be sent when the USER does something to
3773 * change the contents. So I am removing this EN_CHANGE
3775 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3777 EDIT_EM_ScrollCaret(es
);
3779 /* force scroll info update */
3780 EDIT_UpdateScrollInfo(es
);
3785 /*********************************************************************
3790 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
3795 while (LocalUnlock(es
->hloc32W
)) ;
3796 LocalFree(es
->hloc32W
);
3799 while (LocalUnlock(es
->hloc32A
)) ;
3800 LocalFree(es
->hloc32A
);
3803 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
3804 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3805 LOCAL_Free(hInstance
, es
->hloc16
);
3808 pc
= es
->first_line_def
;
3812 HeapFree(GetProcessHeap(), 0, pc
);
3816 SetWindowLongW( es
->hwndSelf
, 0, 0 );
3817 HeapFree(GetProcessHeap(), 0, es
);
3823 /*********************************************************************
3828 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
3833 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
3834 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3836 GetClientRect(es
->hwndSelf
, &rc
);
3837 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3838 GetClipBox(dc
, &rc
);
3840 * FIXME: specs say that we should UnrealizeObject() the brush,
3841 * but the specs of UnrealizeObject() say that we shouldn't
3842 * unrealize a stock object. The default brush that
3843 * DefWndProc() returns is ... a stock object.
3845 FillRect(dc
, &rc
, brush
);
3850 /*********************************************************************
3855 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3857 if(!count
) return 0;
3861 LPWSTR textW
= (LPWSTR
)lParam
;
3862 lstrcpynW(textW
, es
->text
, count
);
3863 return strlenW(textW
);
3867 LPSTR textA
= (LPSTR
)lParam
;
3868 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3869 textA
[count
- 1] = 0; /* ensure 0 termination */
3870 return strlen(textA
);
3874 /*********************************************************************
3879 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3884 if (!(es
->style
& ES_MULTILINE
))
3887 if (!(es
->style
& ES_AUTOHSCROLL
))
3891 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3894 TRACE("SB_LINELEFT\n");
3896 dx
= -es
->char_width
;
3899 TRACE("SB_LINERIGHT\n");
3900 if (es
->x_offset
< es
->text_width
)
3901 dx
= es
->char_width
;
3904 TRACE("SB_PAGELEFT\n");
3906 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3909 TRACE("SB_PAGERIGHT\n");
3910 if (es
->x_offset
< es
->text_width
)
3911 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3919 TRACE("SB_RIGHT\n");
3920 if (es
->x_offset
< es
->text_width
)
3921 dx
= es
->text_width
- es
->x_offset
;
3924 TRACE("SB_THUMBTRACK %d\n", pos
);
3925 es
->flags
|= EF_HSCROLL_TRACK
;
3926 if(es
->style
& WS_HSCROLL
)
3927 dx
= pos
- es
->x_offset
;
3932 if(pos
< 0 || pos
> 100) return 0;
3933 /* Assume default scroll range 0-100 */
3934 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3935 new_x
= pos
* (es
->text_width
- fw
) / 100;
3936 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3939 case SB_THUMBPOSITION
:
3940 TRACE("SB_THUMBPOSITION %d\n", pos
);
3941 es
->flags
&= ~EF_HSCROLL_TRACK
;
3942 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3943 dx
= pos
- es
->x_offset
;
3948 if(pos
< 0 || pos
> 100) return 0;
3949 /* Assume default scroll range 0-100 */
3950 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3951 new_x
= pos
* (es
->text_width
- fw
) / 100;
3952 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3955 /* force scroll info update */
3956 EDIT_UpdateScrollInfo(es
);
3957 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
3961 TRACE("SB_ENDSCROLL\n");
3964 * FIXME : the next two are undocumented !
3965 * Are we doing the right thing ?
3966 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3967 * although it's also a regular control message.
3969 case EM_GETTHUMB
: /* this one is used by NT notepad */
3973 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3974 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3977 /* Assume default scroll range 0-100 */
3978 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3979 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3981 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3984 case EM_LINESCROLL16
:
3985 TRACE("EM_LINESCROLL16\n");
3990 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3996 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3997 /* check if we are going to move too far */
3998 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3999 dx
= es
->text_width
- fw
- es
->x_offset
;
4001 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4007 /*********************************************************************
4012 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4014 HWND hLBox
= es
->hwndListBox
;
4022 hCombo
= GetParent(es
->hwndSelf
);
4026 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4028 if (key
== VK_UP
|| key
== VK_DOWN
)
4030 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4033 if (msg
== WM_KEYDOWN
|| nEUI
)
4034 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4040 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4042 /* make sure ComboLBox pops up */
4043 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4048 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4051 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4053 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4055 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4060 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4066 /*********************************************************************
4070 * Handling of special keys that don't produce a WM_CHAR
4071 * (i.e. non-printable keys) & Backspace & Delete
4074 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4079 if (GetKeyState(VK_MENU
) & 0x8000)
4082 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4083 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4088 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4093 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4094 EDIT_MoveUp_ML(es
, shift
);
4097 EDIT_MoveWordBackward(es
, shift
);
4099 EDIT_MoveBackward(es
, shift
);
4102 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4106 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4107 EDIT_MoveDown_ML(es
, shift
);
4109 EDIT_MoveWordForward(es
, shift
);
4111 EDIT_MoveForward(es
, shift
);
4114 EDIT_MoveHome(es
, shift
);
4117 EDIT_MoveEnd(es
, shift
);
4120 if (es
->style
& ES_MULTILINE
)
4121 EDIT_MovePageUp_ML(es
, shift
);
4123 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4126 if (es
->style
& ES_MULTILINE
)
4127 EDIT_MovePageDown_ML(es
, shift
);
4129 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4132 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4133 if (es
->selection_start
!= es
->selection_end
) {
4140 /* delete character left of caret */
4141 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4142 EDIT_MoveBackward(es
, TRUE
);
4144 } else if (control
) {
4145 /* delete to end of line */
4146 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4147 EDIT_MoveEnd(es
, TRUE
);
4150 /* delete character right of caret */
4151 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4152 EDIT_MoveForward(es
, TRUE
);
4160 if (!(es
->style
& ES_READONLY
))
4166 /* If the edit doesn't want the return send a message to the default object */
4167 if(!(es
->style
& ES_WANTRETURN
))
4169 HWND hwndParent
= GetParent(es
->hwndSelf
);
4170 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4171 if (HIWORD(dw
) == DC_HASDEFID
)
4173 SendMessageW( hwndParent
, WM_COMMAND
,
4174 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4175 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4184 /*********************************************************************
4189 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4191 es
->flags
&= ~EF_FOCUSED
;
4193 if(!(es
->style
& ES_NOHIDESEL
))
4194 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4195 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4200 /*********************************************************************
4204 * The caret position has been set on the WM_LBUTTONDOWN message
4207 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4210 INT e
= es
->selection_end
;
4215 if (!(es
->flags
& EF_FOCUSED
))
4218 l
= EDIT_EM_LineFromChar(es
, e
);
4219 li
= EDIT_EM_LineIndex(es
, l
);
4220 ll
= EDIT_EM_LineLength(es
, e
);
4221 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4222 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4223 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4224 EDIT_EM_ScrollCaret(es
);
4229 /*********************************************************************
4234 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4239 if (!(es
->flags
& EF_FOCUSED
))
4242 es
->bCaptureState
= TRUE
;
4243 SetCapture(es
->hwndSelf
);
4244 EDIT_ConfinePoint(es
, &x
, &y
);
4245 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4246 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4247 EDIT_EM_ScrollCaret(es
);
4248 es
->region_posx
= es
->region_posy
= 0;
4249 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4254 /*********************************************************************
4259 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4261 if (es
->bCaptureState
) {
4262 KillTimer(es
->hwndSelf
, 0);
4263 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4265 es
->bCaptureState
= FALSE
;
4270 /*********************************************************************
4275 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4277 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4282 /*********************************************************************
4287 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4293 if (GetCapture() != es
->hwndSelf
)
4297 * FIXME: gotta do some scrolling if outside client
4298 * area. Maybe reset the timer ?
4301 EDIT_ConfinePoint(es
, &x
, &y
);
4302 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4303 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4304 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4305 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4306 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4311 /*********************************************************************
4315 * See also EDIT_WM_StyleChanged
4317 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4322 TRACE("Creating %s edit control, style = %08lx\n",
4323 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4325 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4327 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4330 * Note: since the EDITSTATE has not been fully initialized yet,
4331 * we can't use any API calls that may send
4332 * WM_XXX messages before WM_NCCREATE is completed.
4335 es
->is_unicode
= unicode
;
4336 es
->style
= lpcs
->style
;
4338 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4340 es
->hwndSelf
= hwnd
;
4341 /* Save parent, which will be notified by EN_* messages */
4342 es
->hwndParent
= lpcs
->hwndParent
;
4344 if (es
->style
& ES_COMBO
)
4345 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4347 /* Number overrides lowercase overrides uppercase (at least it
4348 * does in Win95). However I'll bet that ES_NUMBER would be
4349 * invalid under Win 3.1.
4351 if (es
->style
& ES_NUMBER
) {
4352 ; /* do not override the ES_NUMBER */
4353 } else if (es
->style
& ES_LOWERCASE
) {
4354 es
->style
&= ~ES_UPPERCASE
;
4356 if (es
->style
& ES_MULTILINE
) {
4357 es
->buffer_limit
= BUFLIMIT_MULTI
;
4358 if (es
->style
& WS_VSCROLL
)
4359 es
->style
|= ES_AUTOVSCROLL
;
4360 if (es
->style
& WS_HSCROLL
)
4361 es
->style
|= ES_AUTOHSCROLL
;
4362 es
->style
&= ~ES_PASSWORD
;
4363 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4364 /* Confirmed - RIGHT overrides CENTER */
4365 if (es
->style
& ES_RIGHT
)
4366 es
->style
&= ~ES_CENTER
;
4367 es
->style
&= ~WS_HSCROLL
;
4368 es
->style
&= ~ES_AUTOHSCROLL
;
4371 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4372 es
->style
|= ES_AUTOVSCROLL
;
4374 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4375 if (WIN31_LOOK
== TWEAK_WineLook
||
4376 WIN95_LOOK
== TWEAK_WineLook
) {
4377 es
->style
&= ~ES_CENTER
;
4378 es
->style
&= ~ES_RIGHT
;
4380 if (es
->style
& ES_RIGHT
)
4381 es
->style
&= ~ES_CENTER
;
4383 es
->style
&= ~WS_HSCROLL
;
4384 es
->style
&= ~WS_VSCROLL
;
4385 es
->style
&= ~ES_AUTOVSCROLL
;
4386 es
->style
&= ~ES_WANTRETURN
;
4387 if (es
->style
& ES_PASSWORD
)
4388 es
->password_char
= '*';
4390 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4391 es
->style
|= ES_AUTOHSCROLL
;
4394 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4395 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4397 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4399 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4401 es
->undo_buffer_size
= es
->buffer_size
;
4403 if (es
->style
& ES_MULTILINE
)
4404 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4409 * In Win95 look and feel, the WS_BORDER style is replaced by the
4410 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4411 * control a non client area. Not always. This coordinates in some
4412 * way with the window creation code in dialog.c When making
4413 * modifications please ensure that the code still works for edit
4414 * controls created directly with style 0x50800000, exStyle 0 (
4415 * which should have a single pixel border)
4417 if (TWEAK_WineLook
!= WIN31_LOOK
)
4419 es
->style
&= ~WS_BORDER
;
4423 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4424 SetWindowLongW( hwnd
, GWL_STYLE
,
4425 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4431 /*********************************************************************
4436 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
)
4445 BOOL rev
= es
->bEnableState
&&
4446 ((es
->flags
& EF_FOCUSED
) ||
4447 (es
->style
& ES_NOHIDESEL
));
4449 dc
= BeginPaint(es
->hwndSelf
, &ps
);
4452 if(es
->style
& WS_BORDER
) {
4453 GetClientRect(es
->hwndSelf
, &rc
);
4454 if(es
->style
& ES_MULTILINE
) {
4455 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4456 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4458 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4460 IntersectClipRect(dc
, es
->format_rect
.left
,
4461 es
->format_rect
.top
,
4462 es
->format_rect
.right
,
4463 es
->format_rect
.bottom
);
4464 if (es
->style
& ES_MULTILINE
) {
4465 GetClientRect(es
->hwndSelf
, &rc
);
4466 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4469 old_font
= SelectObject(dc
, es
->font
);
4470 EDIT_NotifyCtlColor(es
, dc
);
4472 if (!es
->bEnableState
)
4473 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4474 GetClipBox(dc
, &rcRgn
);
4475 if (es
->style
& ES_MULTILINE
) {
4476 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4477 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4478 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4479 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4480 EDIT_PaintLine(es
, dc
, i
, rev
);
4483 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4484 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4485 EDIT_PaintLine(es
, dc
, 0, rev
);
4488 SelectObject(dc
, old_font
);
4491 EndPaint(es
->hwndSelf
, &ps
);
4495 /*********************************************************************
4500 static void EDIT_WM_Paste(EDITSTATE
*es
)
4505 /* Protect read-only edit control from modification */
4506 if(es
->style
& ES_READONLY
)
4509 OpenClipboard(es
->hwndSelf
);
4510 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4511 src
= (LPWSTR
)GlobalLock(hsrc
);
4512 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4519 /*********************************************************************
4524 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4526 es
->flags
|= EF_FOCUSED
;
4527 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4528 EDIT_SetCaretPos(es
, es
->selection_end
,
4529 es
->flags
& EF_AFTER_WRAP
);
4530 if(!(es
->style
& ES_NOHIDESEL
))
4531 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4532 ShowCaret(es
->hwndSelf
);
4533 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4537 /*********************************************************************
4541 * With Win95 look the margins are set to default font value unless
4542 * the system font (font == 0) is being set, in which case they are left
4546 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4554 dc
= GetDC(es
->hwndSelf
);
4556 old_font
= SelectObject(dc
, font
);
4557 GetTextMetricsW(dc
, &tm
);
4558 es
->line_height
= tm
.tmHeight
;
4559 es
->char_width
= tm
.tmAveCharWidth
;
4561 SelectObject(dc
, old_font
);
4562 ReleaseDC(es
->hwndSelf
, dc
);
4563 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4564 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4565 EC_USEFONTINFO
, EC_USEFONTINFO
);
4567 /* Force the recalculation of the format rect for each font change */
4568 GetClientRect(es
->hwndSelf
, &r
);
4569 EDIT_SetRectNP(es
, &r
);
4571 if (es
->style
& ES_MULTILINE
)
4572 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4574 EDIT_CalcLineWidth_SL(es
);
4577 EDIT_UpdateText(es
, NULL
, TRUE
);
4578 if (es
->flags
& EF_FOCUSED
) {
4580 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4581 EDIT_SetCaretPos(es
, es
->selection_end
,
4582 es
->flags
& EF_AFTER_WRAP
);
4583 ShowCaret(es
->hwndSelf
);
4588 /*********************************************************************
4593 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4594 * The modified flag is reset. No notifications are sent.
4596 * For single-line controls, reception of WM_SETTEXT triggers:
4597 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4600 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4605 text
= (LPWSTR
)lParam
;
4608 LPCSTR textA
= (LPCSTR
)lParam
;
4609 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4610 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4611 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4614 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4616 TRACE("%s\n", debugstr_w(text
));
4617 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4619 HeapFree(GetProcessHeap(), 0, text
);
4621 static const WCHAR empty_stringW
[] = {0};
4623 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4626 es
->flags
&= ~EF_MODIFIED
;
4627 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4628 /* Send the notification after the selection start and end have been set
4629 * edit control doesn't send notification on WM_SETTEXT
4630 * if it is multiline, or it is part of combobox
4632 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4634 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4635 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4637 EDIT_EM_ScrollCaret(es
);
4641 /*********************************************************************
4646 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4648 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4650 TRACE("width = %d, height = %d\n", width
, height
);
4651 SetRect(&rc
, 0, 0, width
, height
);
4652 EDIT_SetRectNP(es
, &rc
);
4653 EDIT_UpdateText(es
, NULL
, TRUE
);
4658 /*********************************************************************
4662 * This message is sent by SetWindowLong on having changed either the Style
4663 * or the extended style.
4665 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4667 * See also EDIT_WM_NCCreate
4669 * It appears that the Windows version of the edit control allows the style
4670 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4671 * style variable which will generally be different. In this function we
4672 * update the internal style based on what changed in the externally visible
4675 * Much of this content as based upon the MSDN, especially:
4676 * Platform SDK Documentation -> User Interface Services ->
4677 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4678 * Edit Control Styles
4680 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4682 if (GWL_STYLE
== which
) {
4683 DWORD style_change_mask
;
4685 /* Only a subset of changes can be applied after the control
4688 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4690 if (es
->style
& ES_MULTILINE
)
4691 style_change_mask
|= ES_WANTRETURN
;
4693 new_style
= style
->styleNew
& style_change_mask
;
4695 /* Number overrides lowercase overrides uppercase (at least it
4696 * does in Win95). However I'll bet that ES_NUMBER would be
4697 * invalid under Win 3.1.
4699 if (new_style
& ES_NUMBER
) {
4700 ; /* do not override the ES_NUMBER */
4701 } else if (new_style
& ES_LOWERCASE
) {
4702 new_style
&= ~ES_UPPERCASE
;
4705 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4706 } else if (GWL_EXSTYLE
== which
) {
4707 ; /* FIXME - what is needed here */
4709 WARN ("Invalid style change %d\n",which
);
4715 /*********************************************************************
4720 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4722 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4723 if (EDIT_EM_CanUndo(es
))
4726 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4727 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4730 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4734 /*********************************************************************
4739 static void EDIT_WM_Timer(EDITSTATE
*es
)
4741 if (es
->region_posx
< 0) {
4742 EDIT_MoveBackward(es
, TRUE
);
4743 } else if (es
->region_posx
> 0) {
4744 EDIT_MoveForward(es
, TRUE
);
4747 * FIXME: gotta do some vertical scrolling here, like
4748 * EDIT_EM_LineScroll(hwnd, 0, 1);
4752 /*********************************************************************
4757 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4761 if (!(es
->style
& ES_MULTILINE
))
4764 if (!(es
->style
& ES_AUTOVSCROLL
))
4773 TRACE("action %d\n", action
);
4774 EDIT_EM_Scroll(es
, action
);
4781 TRACE("SB_BOTTOM\n");
4782 dy
= es
->line_count
- 1 - es
->y_offset
;
4785 TRACE("SB_THUMBTRACK %d\n", pos
);
4786 es
->flags
|= EF_VSCROLL_TRACK
;
4787 if(es
->style
& WS_VSCROLL
)
4788 dy
= pos
- es
->y_offset
;
4791 /* Assume default scroll range 0-100 */
4794 if(pos
< 0 || pos
> 100) return 0;
4795 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4796 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4797 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4798 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4799 es
->line_count
, es
->y_offset
, pos
, dy
);
4802 case SB_THUMBPOSITION
:
4803 TRACE("SB_THUMBPOSITION %d\n", pos
);
4804 es
->flags
&= ~EF_VSCROLL_TRACK
;
4805 if(es
->style
& WS_VSCROLL
)
4806 dy
= pos
- es
->y_offset
;
4809 /* Assume default scroll range 0-100 */
4812 if(pos
< 0 || pos
> 100) return 0;
4813 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4814 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4815 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4816 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4817 es
->line_count
, es
->y_offset
, pos
, dy
);
4821 /* force scroll info update */
4822 EDIT_UpdateScrollInfo(es
);
4823 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4827 TRACE("SB_ENDSCROLL\n");
4830 * FIXME : the next two are undocumented !
4831 * Are we doing the right thing ?
4832 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4833 * although it's also a regular control message.
4835 case EM_GETTHUMB
: /* this one is used by NT notepad */
4839 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4840 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4843 /* Assume default scroll range 0-100 */
4844 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4845 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4847 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4850 case EM_LINESCROLL16
:
4851 TRACE("EM_LINESCROLL16 %d\n", pos
);
4856 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4861 EDIT_EM_LineScroll(es
, 0, dy
);
4865 /*********************************************************************
4870 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4872 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4873 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
4877 /*********************************************************************
4882 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4884 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4885 InvalidateRect(es
->hwndSelf
, rc
, bErase
);