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.
48 #include "wine/winbase16.h"
49 #include "wine/winuser16.h"
50 #include "wine/unicode.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
57 WINE_DECLARE_DEBUG_CHANNEL(combo
);
58 WINE_DECLARE_DEBUG_CHANNEL(relay
);
60 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
61 FIXME: BTW, new specs say 65535 (do you dare ???) */
62 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
63 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
64 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
65 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
68 * extra flags for EDITSTATE.flags field
70 #define EF_MODIFIED 0x0001 /* text has been modified */
71 #define EF_FOCUSED 0x0002 /* we have input focus */
72 #define EF_UPDATE 0x0004 /* notify parent of changed state */
73 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
74 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
75 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
76 wrapped line, instead of in front of the next character */
77 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
81 END_0
= 0, /* line ends with terminating '\0' character */
82 END_WRAP
, /* line is wrapped */
83 END_HARD
, /* line ends with a hard return '\r\n' */
84 END_SOFT
, /* line ends with a soft return '\r\r\n' */
85 END_RICH
/* line ends with a single '\n' */
88 typedef struct tagLINEDEF
{
89 INT length
; /* bruto length of a line in bytes */
90 INT net_length
; /* netto length of a line in visible characters */
92 INT width
; /* width of the line in pixels */
93 INT index
; /* line index into the buffer */
94 struct tagLINEDEF
*next
;
99 BOOL is_unicode
; /* how the control was created */
100 LPWSTR text
; /* the actual contents of the control */
101 UINT buffer_size
; /* the size of the buffer in characters */
102 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
103 HFONT font
; /* NULL means standard system font */
104 INT x_offset
; /* scroll offset for multi lines this is in pixels
105 for single lines it's in characters */
106 INT line_height
; /* height of a screen line in pixels */
107 INT char_width
; /* average character width in pixels */
108 DWORD style
; /* sane version of wnd->dwStyle */
109 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
110 INT undo_insert_count
; /* number of characters inserted in sequence */
111 UINT undo_position
; /* character index of the insertion and deletion */
112 LPWSTR undo_text
; /* deleted text */
113 UINT undo_buffer_size
; /* size of the deleted text buffer */
114 INT selection_start
; /* == selection_end if no selection */
115 INT selection_end
; /* == current caret position */
116 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
117 INT left_margin
; /* in pixels */
118 INT right_margin
; /* in pixels */
120 INT text_width
; /* width of the widest line in pixels for multi line controls
121 and just line width for single line controls */
122 INT region_posx
; /* Position of cursor relative to region: */
123 INT region_posy
; /* -1: to left, 0: within, 1: to right */
124 EDITWORDBREAKPROC16 word_break_proc16
;
125 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
126 INT line_count
; /* number of lines */
127 INT y_offset
; /* scroll offset in number of lines */
128 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
129 BOOL bEnableState
; /* flag keeping the enable state */
130 HWND hwndSelf
; /* the our window handle */
131 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
132 Even if parent will change, EN_* messages
133 should be sent to the first parent. */
134 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
136 * only for multi line controls
138 INT lock_count
; /* amount of re-entries in the EditWndProc */
141 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
142 HLOCAL hloc32W
; /* our unicode local memory block */
143 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
145 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
150 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
151 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
153 /* used for disabled or read-only edit control */
154 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
156 { /* Notify parent which has created this edit control */ \
157 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
158 SendMessageW(es->hwndParent, WM_COMMAND, \
159 MAKEWPARAM(GetWindowLongW((es->hwndSelf),GWL_ID), wNotifyCode), \
160 (LPARAM)(es->hwndSelf)); \
163 /*********************************************************************
170 * These functions have trivial implementations
171 * We still like to call them internally
172 * "static inline" makes them more like macro's
174 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
175 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
176 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
177 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
180 * Helper functions only valid for one type of control
182 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
183 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
184 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
185 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
186 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
187 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
190 * Helper functions valid for both single line _and_ multi line controls
192 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
193 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
194 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
195 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
196 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
197 static void EDIT_LockBuffer(EDITSTATE
*es
);
198 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
);
199 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
200 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
201 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
202 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
203 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
204 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
205 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
206 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
207 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
208 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
209 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
210 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
211 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
212 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
214 * EM_XXX message handlers
216 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
217 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
218 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
219 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
220 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
);
221 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
222 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
223 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
224 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
225 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
226 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
227 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
228 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
229 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
230 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
231 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
232 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
233 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
234 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
235 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
236 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
237 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
238 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
239 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
240 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
);
241 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
242 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
244 * WM_XXX message handlers
246 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
247 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
248 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
249 static void EDIT_WM_Copy(EDITSTATE
*es
);
250 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
251 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
252 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
253 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
254 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
255 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
256 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
257 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
258 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
259 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
260 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
261 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
262 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
263 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
);
264 static void EDIT_WM_Paste(EDITSTATE
*es
);
265 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
266 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
267 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
268 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
269 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
270 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
271 static void EDIT_WM_Timer(EDITSTATE
*es
);
272 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
273 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
274 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
276 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
277 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
279 /*********************************************************************
280 * edit class descriptor
282 const struct builtin_class_descr EDIT_builtin_class
=
285 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_PARENTDC
, /* style */
286 EditWndProcA
, /* procA */
287 EditWndProcW
, /* procW */
288 sizeof(EDITSTATE
*), /* extra */
289 IDC_IBEAMA
, /* cursor */
294 /*********************************************************************
299 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
301 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
305 /*********************************************************************
310 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
312 es
->undo_insert_count
= 0;
313 *es
->undo_text
= '\0';
317 /*********************************************************************
322 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
324 static const WCHAR empty_stringW
[] = {0};
326 /* Protect read-only edit control from modification */
327 if(es
->style
& ES_READONLY
)
330 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
334 /*********************************************************************
339 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
346 /**********************************************************************
349 * Returns the window version in case Wine emulates a later version
350 * of windows then the application expects.
352 * In a number of cases when windows runs an application that was
353 * designed for an earlier windows version, windows reverts
354 * to "old" behaviour of that earlier version.
356 * An example is a disabled edit control that needs to be painted.
357 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
358 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
359 * applications with an expected version 0f 4.0 or higher.
362 static DWORD
get_app_version(void)
364 static DWORD version
;
367 DWORD dwEmulatedVersion
;
369 DWORD dwProcVersion
= GetProcessVersion(0);
371 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
372 GetVersionExW( &info
);
373 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
374 /* FIXME: this may not be 100% correct; see discussion on the
375 * wine developer list in Nov 1999 */
376 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
382 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
386 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
387 msg
= WM_CTLCOLORSTATIC
;
389 msg
= WM_CTLCOLOREDIT
;
391 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
392 return (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
395 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
398 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
400 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
403 /*********************************************************************
407 * The messages are in the order of the actual integer values
408 * (which can be found in include/windows.h)
409 * Wherever possible the 16 bit versions are converted to
410 * the 32 bit ones, so that we can 'fall through' to the
411 * helper functions. These are mostly 32 bit (with a few
412 * exceptions, clearly indicated by a '16' extension to their
416 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
417 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
419 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongW( hwnd
, 0 );
422 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
424 if (!es
&& msg
!= WM_NCCREATE
)
425 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
426 else if (msg
== WM_NCCREATE
)
427 return EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
428 else if (msg
== WM_DESTROY
)
429 return EDIT_WM_Destroy(es
);
432 if (es
) EDIT_LockBuffer(es
);
440 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
444 if (SLOWORD(lParam
) == -1)
445 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
447 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
449 EDIT_EM_ScrollCaret(es
);
453 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
454 EDIT_EM_ScrollCaret(es
);
460 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
464 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
468 if ((es
->style
& ES_MULTILINE
) && lParam
) {
470 CONV_RECT16TO32(MapSL(lParam
), &rc
);
471 EDIT_SetRectNP(es
, &rc
);
472 EDIT_UpdateText(es
, NULL
, TRUE
);
476 if ((es
->style
& ES_MULTILINE
) && lParam
) {
477 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
478 EDIT_UpdateText(es
, NULL
, TRUE
);
483 if ((es
->style
& ES_MULTILINE
) && lParam
) {
485 CONV_RECT16TO32(MapSL(lParam
), &rc
);
486 EDIT_SetRectNP(es
, &rc
);
490 if ((es
->style
& ES_MULTILINE
) && lParam
)
491 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
496 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
499 case EM_LINESCROLL16
:
500 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
501 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
504 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
507 case EM_SCROLLCARET16
:
509 EDIT_EM_ScrollCaret(es
);
515 result
= ((es
->flags
& EF_MODIFIED
) != 0);
521 es
->flags
|= EF_MODIFIED
;
523 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
526 case EM_GETLINECOUNT16
:
527 case EM_GETLINECOUNT
:
528 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
532 if ((INT16
)wParam
== -1)
536 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
540 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
543 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
547 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
550 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
555 result
= EDIT_EM_GetThumb(es
);
558 /* these messages missing from specs */
567 FIXME("undocumented message 0x%x, please report\n", msg
);
568 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
571 case EM_LINELENGTH16
:
573 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
576 case EM_REPLACESEL16
:
577 lParam
= (LPARAM
)MapSL(lParam
);
578 unicode
= FALSE
; /* 16-bit message is always ascii */
585 textW
= (LPWSTR
)lParam
;
588 LPSTR textA
= (LPSTR
)lParam
;
589 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
590 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
591 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
594 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
598 HeapFree(GetProcessHeap(), 0, textW
);
603 lParam
= (LPARAM
)MapSL(lParam
);
604 unicode
= FALSE
; /* 16-bit message is always ascii */
607 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, lParam
, unicode
);
611 case EM_SETLIMITTEXT
:
612 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
617 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
623 result
= (LRESULT
)EDIT_EM_Undo(es
);
628 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
631 case EM_LINEFROMCHAR16
:
632 case EM_LINEFROMCHAR
:
633 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
636 case EM_SETTABSTOPS16
:
637 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
640 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
643 case EM_SETPASSWORDCHAR16
:
644 unicode
= FALSE
; /* 16-bit message is always ascii */
646 case EM_SETPASSWORDCHAR
:
651 charW
= (WCHAR
)wParam
;
655 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
658 EDIT_EM_SetPasswordChar(es
, charW
);
662 case EM_EMPTYUNDOBUFFER16
:
663 case EM_EMPTYUNDOBUFFER
:
664 EDIT_EM_EmptyUndoBuffer(es
);
667 case EM_GETFIRSTVISIBLELINE16
:
668 result
= es
->y_offset
;
670 case EM_GETFIRSTVISIBLELINE
:
671 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
674 case EM_SETREADONLY16
:
677 SetWindowLongW( hwnd
, GWL_STYLE
,
678 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
679 es
->style
|= ES_READONLY
;
681 SetWindowLongW( hwnd
, GWL_STYLE
,
682 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
683 es
->style
&= ~ES_READONLY
;
688 case EM_SETWORDBREAKPROC16
:
689 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
691 case EM_SETWORDBREAKPROC
:
692 EDIT_EM_SetWordBreakProc(es
, lParam
);
695 case EM_GETWORDBREAKPROC16
:
696 result
= (LRESULT
)es
->word_break_proc16
;
698 case EM_GETWORDBREAKPROC
:
699 result
= (LRESULT
)es
->word_break_proc
;
702 case EM_GETPASSWORDCHAR16
:
703 unicode
= FALSE
; /* 16-bit message is always ascii */
705 case EM_GETPASSWORDCHAR
:
708 result
= es
->password_char
;
711 WCHAR charW
= es
->password_char
;
713 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
719 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
722 EDIT_EM_SetMargins(es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
726 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
729 case EM_GETLIMITTEXT
:
730 result
= es
->buffer_limit
;
734 result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
738 result
= EDIT_EM_CharFromPos(es
, SLOWORD(lParam
), SHIWORD(lParam
));
741 /* End of the EM_ messages which were in numerical order; what order
742 * are these in? vaguely alphabetical?
746 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
748 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
750 int vk
= (int)((LPMSG
)lParam
)->wParam
;
752 if (vk
== VK_RETURN
&& (GetWindowLongW( hwnd
, GWL_STYLE
) & ES_WANTRETURN
))
754 result
|= DLGC_WANTMESSAGE
;
756 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
758 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
759 result
|= DLGC_WANTMESSAGE
;
773 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
776 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
778 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
779 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
782 EDIT_WM_Char(es
, charW
);
791 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
795 EDIT_WM_ContextMenu(es
, SLOWORD(lParam
), SHIWORD(lParam
));
804 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
807 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
811 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
812 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
813 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
815 result
= EDIT_WM_Create(es
, nameW
);
817 HeapFree(GetProcessHeap(), 0, nameW
);
826 es
->bEnableState
= (BOOL
) wParam
;
827 EDIT_UpdateText(es
, NULL
, TRUE
);
831 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
835 result
= (LRESULT
)es
->font
;
839 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
842 case WM_GETTEXTLENGTH
:
843 if (unicode
) result
= strlenW(es
->text
);
844 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
845 NULL
, 0, NULL
, NULL
);
849 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), SHIWORD(wParam
));
853 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
857 result
= EDIT_WM_KillFocus(es
);
860 case WM_LBUTTONDBLCLK
:
861 result
= EDIT_WM_LButtonDblClk(es
);
865 result
= EDIT_WM_LButtonDown(es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
869 result
= EDIT_WM_LButtonUp(es
);
873 result
= EDIT_WM_MButtonDown(es
);
876 case WM_MOUSEACTIVATE
:
878 * FIXME: maybe DefWindowProc() screws up, but it seems that
879 * modeless dialog boxes need this. If we don't do this, the focus
880 * will _not_ be set by DefWindowProc() for edit controls in a
881 * modeless dialog box ???
884 result
= MA_ACTIVATE
;
888 result
= EDIT_WM_MouseMove(es
, SLOWORD(lParam
), SHIWORD(lParam
));
892 EDIT_WM_Paint(es
, wParam
);
900 EDIT_WM_SetFocus(es
);
904 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
908 /* FIXME: actually set an internal flag and behave accordingly */
912 EDIT_WM_SetText(es
, lParam
, unicode
);
917 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
920 case WM_STYLECHANGED
:
921 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
924 case WM_STYLECHANGING
:
925 result
= 0; /* See EDIT_WM_StyleChanged */
929 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
937 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), SHIWORD(wParam
));
942 int gcWheelDelta
= 0;
943 UINT pulScrollLines
= 3;
944 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
946 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
947 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
950 gcWheelDelta
-= SHIWORD(wParam
);
951 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
953 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
954 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
955 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
960 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
964 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
969 /*********************************************************************
971 * EditWndProcW (USER32.@)
973 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
975 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
978 /*********************************************************************
980 * EditWndProc (USER32.@)
982 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
984 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
987 /*********************************************************************
989 * EDIT_BuildLineDefs_ML
991 * Build linked list of text lines.
992 * Lines can end with '\0' (last line), a character (if it is wrapped),
993 * a soft return '\r\r\n' or a hard return '\r\n'
996 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1000 LPWSTR current_position
, cp
;
1002 LINEDEF
*current_line
;
1003 LINEDEF
*previous_line
;
1004 LINEDEF
*start_line
;
1005 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1006 INT line_count
= es
->line_count
;
1007 INT orig_net_length
;
1010 if (istart
== iend
&& delta
== 0)
1013 dc
= GetDC(es
->hwndSelf
);
1015 old_font
= SelectObject(dc
, es
->font
);
1017 previous_line
= NULL
;
1018 current_line
= es
->first_line_def
;
1020 /* Find starting line. istart must lie inside an existing line or
1021 * at the end of buffer */
1023 if (istart
< current_line
->index
+ current_line
->length
||
1024 current_line
->ending
== END_0
)
1027 previous_line
= current_line
;
1028 current_line
= current_line
->next
;
1030 } while (current_line
);
1032 if (!current_line
) /* Error occurred start is not inside previous buffer */
1034 FIXME(" modification occurred outside buffer\n");
1038 /* Remember start of modifications in order to calculate update region */
1039 nstart_line
= line_index
;
1040 nstart_index
= current_line
->index
;
1042 /* We must start to reformat from the previous line since the modifications
1043 * may have caused the line to wrap upwards. */
1044 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1047 current_line
= previous_line
;
1049 start_line
= current_line
;
1051 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1052 current_position
= es
->text
+ current_line
->index
;
1054 if (current_line
!= start_line
)
1056 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1058 /* The buffer has been expanded, create a new line and
1059 insert it into the link list */
1060 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1061 new_line
->next
= previous_line
->next
;
1062 previous_line
->next
= new_line
;
1063 current_line
= new_line
;
1066 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1068 /* The previous line merged with this line so we delete this extra entry */
1069 previous_line
->next
= current_line
->next
;
1070 HeapFree(GetProcessHeap(), 0, current_line
);
1071 current_line
= previous_line
->next
;
1075 else /* current_line->index + delta == current_position */
1077 if (current_position
- es
->text
> iend
)
1078 break; /* We reached end of line modifications */
1079 /* else recalulate this line */
1083 current_line
->index
= current_position
- es
->text
;
1084 orig_net_length
= current_line
->net_length
;
1086 /* Find end of line */
1087 cp
= current_position
;
1089 if (*cp
== '\n') break;
1090 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1095 /* Mark type of line termination */
1097 current_line
->ending
= END_0
;
1098 current_line
->net_length
= strlenW(current_position
);
1099 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1100 current_line
->ending
= END_SOFT
;
1101 current_line
->net_length
= cp
- current_position
- 1;
1102 } else if (*cp
== '\n') {
1103 current_line
->ending
= END_RICH
;
1104 current_line
->net_length
= cp
- current_position
;
1106 current_line
->ending
= END_HARD
;
1107 current_line
->net_length
= cp
- current_position
;
1110 /* Calculate line width */
1111 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1112 current_position
, current_line
->net_length
,
1113 es
->tabs_count
, es
->tabs
));
1115 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1116 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1121 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1122 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1123 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1124 current_position
, next
, es
->tabs_count
, es
->tabs
));
1125 } while (current_line
->width
<= fw
);
1126 if (!prev
) { /* Didn't find a line break so force a break */
1131 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1132 current_position
, next
, es
->tabs_count
, es
->tabs
));
1133 } while (current_line
->width
<= fw
);
1138 /* If the first line we are calculating, wrapped before istart, we must
1139 * adjust istart in order for this to be reflected in the update region. */
1140 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1141 istart
= current_line
->index
+ prev
;
1142 /* else if we are updating the previous line before the first line we
1143 * are re-calculating and it expanded */
1144 else if (current_line
== start_line
&&
1145 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1147 /* Line expanded due to an upwards line wrap so we must partially include
1148 * previous line in update region */
1149 nstart_line
= line_index
;
1150 nstart_index
= current_line
->index
;
1151 istart
= current_line
->index
+ orig_net_length
;
1154 current_line
->net_length
= prev
;
1155 current_line
->ending
= END_WRAP
;
1156 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1157 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1161 /* Adjust length to include line termination */
1162 switch (current_line
->ending
) {
1164 current_line
->length
= current_line
->net_length
+ 3;
1167 current_line
->length
= current_line
->net_length
+ 1;
1170 current_line
->length
= current_line
->net_length
+ 2;
1174 current_line
->length
= current_line
->net_length
;
1177 es
->text_width
= max(es
->text_width
, current_line
->width
);
1178 current_position
+= current_line
->length
;
1179 previous_line
= current_line
;
1180 current_line
= current_line
->next
;
1182 } while (previous_line
->ending
!= END_0
);
1184 /* Finish adjusting line indexes by delta or remove hanging lines */
1185 if (previous_line
->ending
== END_0
)
1187 LINEDEF
*pnext
= NULL
;
1189 previous_line
->next
= NULL
;
1190 while (current_line
)
1192 pnext
= current_line
->next
;
1193 HeapFree(GetProcessHeap(), 0, current_line
);
1194 current_line
= pnext
;
1200 while (current_line
)
1202 current_line
->index
+= delta
;
1203 current_line
= current_line
->next
;
1207 /* Calculate rest of modification rectangle */
1212 * We calculate two rectangles. One for the first line which may have
1213 * an indent with respect to the format rect. The other is a format-width
1214 * rectangle that spans the rest of the lines that changed or moved.
1216 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1217 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1218 rc
.bottom
= rc
.top
+ es
->line_height
;
1219 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1220 es
->text
+ nstart_index
, istart
- nstart_index
,
1221 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1222 rc
.right
= es
->format_rect
.right
;
1223 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1226 rc
.left
= es
->format_rect
.left
;
1227 rc
.right
= es
->format_rect
.right
;
1229 * If lines were added or removed we must re-paint the remainder of the
1230 * lines since the remaining lines were either shifted up or down.
1232 if (line_count
< es
->line_count
) /* We added lines */
1233 rc
.bottom
= es
->line_count
* es
->line_height
;
1234 else if (line_count
> es
->line_count
) /* We removed lines */
1235 rc
.bottom
= line_count
* es
->line_height
;
1237 rc
.bottom
= line_index
* es
->line_height
;
1238 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1239 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1240 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1241 DeleteObject(tmphrgn
);
1245 SelectObject(dc
, old_font
);
1247 ReleaseDC(es
->hwndSelf
, dc
);
1250 /*********************************************************************
1252 * EDIT_CalcLineWidth_SL
1255 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1257 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(es
, strlenW(es
->text
), FALSE
));
1260 /*********************************************************************
1262 * EDIT_CallWordBreakProc
1264 * Call appropriate WordBreakProc (internal or external).
1266 * Note: The "start" argument should always be an index referring
1267 * to es->text. The actual wordbreak proc might be
1268 * 16 bit, so we can't always pass any 32 bit LPSTR.
1269 * Hence we assume that es->text is the buffer that holds
1270 * the string under examination (we can decide this for ourselves).
1273 /* ### start build ### */
1274 extern WORD CALLBACK
EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16
,SEGPTR
,WORD
,WORD
,WORD
);
1275 /* ### stop build ### */
1276 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1278 INT ret
, iWndsLocks
;
1280 /* To avoid any deadlocks, all the locks on the window structures
1281 must be suspended before the control is passed to the application */
1282 iWndsLocks
= WIN_SuspendWndsLock();
1284 if (es
->word_break_proc16
) {
1289 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1290 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1291 segptr
= K32WOWGlobalLock16(hglob16
);
1292 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1293 ret
= (INT
)EDIT_CallTo16_word_lwww(es
->word_break_proc16
,
1294 segptr
, index
, countA
, action
);
1295 GlobalUnlock16(hglob16
);
1296 GlobalFree16(hglob16
);
1298 else if (es
->word_break_proc
)
1302 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1304 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1305 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1306 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1310 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1314 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1315 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1316 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1317 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1318 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1319 ret
= wbpA(textA
, index
, countA
, action
);
1320 HeapFree(GetProcessHeap(), 0, textA
);
1324 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1326 WIN_RestoreWndsLock(iWndsLocks
);
1331 /*********************************************************************
1335 * Beware: This is not the function called on EM_CHARFROMPOS
1336 * The position _can_ be outside the formatting / client
1338 * The return value is only the character index
1341 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1347 if (es
->style
& ES_MULTILINE
) {
1348 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1350 LINEDEF
*line_def
= es
->first_line_def
;
1352 while ((line
> 0) && line_def
->next
) {
1353 line_index
+= line_def
->length
;
1354 line_def
= line_def
->next
;
1357 x
+= es
->x_offset
- es
->format_rect
.left
;
1358 if (x
>= line_def
->width
) {
1360 *after_wrap
= (line_def
->ending
== END_WRAP
);
1361 return line_index
+ line_def
->net_length
;
1365 *after_wrap
= FALSE
;
1368 dc
= GetDC(es
->hwndSelf
);
1370 old_font
= SelectObject(dc
, es
->font
);
1371 low
= line_index
+ 1;
1372 high
= line_index
+ line_def
->net_length
+ 1;
1373 while (low
< high
- 1)
1375 INT mid
= (low
+ high
) / 2;
1376 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1382 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1383 (line_def
->ending
== END_WRAP
));
1388 *after_wrap
= FALSE
;
1389 x
-= es
->format_rect
.left
;
1391 return es
->x_offset
;
1392 text
= EDIT_GetPasswordPointer_SL(es
);
1393 dc
= GetDC(es
->hwndSelf
);
1395 old_font
= SelectObject(dc
, es
->font
);
1399 INT high
= es
->x_offset
;
1400 while (low
< high
- 1)
1402 INT mid
= (low
+ high
) / 2;
1403 GetTextExtentPoint32W( dc
, text
+ mid
,
1404 es
->x_offset
- mid
, &size
);
1405 if (size
.cx
> -x
) low
= mid
;
1412 INT low
= es
->x_offset
;
1413 INT high
= strlenW(es
->text
) + 1;
1414 while (low
< high
- 1)
1416 INT mid
= (low
+ high
) / 2;
1417 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1418 mid
- es
->x_offset
, &size
);
1419 if (size
.cx
> x
) high
= mid
;
1424 if (es
->style
& ES_PASSWORD
)
1425 HeapFree(GetProcessHeap(), 0, text
);
1428 SelectObject(dc
, old_font
);
1429 ReleaseDC(es
->hwndSelf
, dc
);
1434 /*********************************************************************
1438 * adjusts the point to be within the formatting rectangle
1439 * (so CharFromPos returns the nearest _visible_ character)
1442 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1444 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1445 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1449 /*********************************************************************
1453 * Calculates the bounding rectangle for a line from a starting
1454 * column to an ending column.
1457 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1459 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1461 if (es
->style
& ES_MULTILINE
)
1462 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1464 rc
->top
= es
->format_rect
.top
;
1465 rc
->bottom
= rc
->top
+ es
->line_height
;
1466 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1467 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1471 /*********************************************************************
1473 * EDIT_GetPasswordPointer_SL
1475 * note: caller should free the (optionally) allocated buffer
1478 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1480 if (es
->style
& ES_PASSWORD
) {
1481 INT len
= strlenW(es
->text
);
1482 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1484 while(len
) text
[--len
] = es
->password_char
;
1491 /*********************************************************************
1495 * This acts as a LOCAL_Lock(), but it locks only once. This way
1496 * you can call it whenever you like, without unlocking.
1498 * Initially the edit control allocates a HLOCAL32 buffer
1499 * (32 bit linear memory handler). However, 16 bit application
1500 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1501 * handler). From that moment on we have to keep using this 16 bit memory
1502 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1503 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1507 static void EDIT_LockBuffer(EDITSTATE
*es
)
1509 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1513 BOOL _16bit
= FALSE
;
1519 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1520 textA
= LocalLock(es
->hloc32A
);
1521 countA
= strlen(textA
) + 1;
1525 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1526 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1527 countA
= strlen(textA
) + 1;
1532 ERR("no buffer ... please report\n");
1539 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1540 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1541 if(countW_new
> es
->buffer_size
+ 1)
1543 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1544 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1545 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1548 es
->hloc32W
= hloc32W_new
;
1549 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1550 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1553 WARN("FAILED! Will synchronize partially\n");
1557 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1558 es
->text
= LocalLock(es
->hloc32W
);
1562 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1564 LOCAL_Unlock(hInstance
, es
->hloc16
);
1566 LocalUnlock(es
->hloc32A
);
1573 /*********************************************************************
1575 * EDIT_SL_InvalidateText
1577 * Called from EDIT_InvalidateText().
1578 * Does the job for single-line controls only.
1581 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1586 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1587 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1588 EDIT_UpdateText(es
, &rc
, TRUE
);
1592 /*********************************************************************
1594 * EDIT_ML_InvalidateText
1596 * Called from EDIT_InvalidateText().
1597 * Does the job for multi-line controls only.
1600 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1602 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1603 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1604 INT el
= EDIT_EM_LineFromChar(es
, end
);
1613 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1616 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1617 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1618 if (sl
< es
->y_offset
) {
1622 if (el
> es
->y_offset
+ vlc
) {
1623 el
= es
->y_offset
+ vlc
;
1624 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1626 GetClientRect(es
->hwndSelf
, &rc1
);
1627 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1629 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1630 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1631 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1633 EDIT_GetLineRect(es
, sl
, sc
,
1634 EDIT_EM_LineLength(es
,
1635 EDIT_EM_LineIndex(es
, sl
)),
1637 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1638 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1639 for (l
= sl
+ 1 ; l
< el
; l
++) {
1640 EDIT_GetLineRect(es
, l
, 0,
1641 EDIT_EM_LineLength(es
,
1642 EDIT_EM_LineIndex(es
, l
)),
1644 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1645 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1647 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1648 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1649 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1654 /*********************************************************************
1656 * EDIT_InvalidateText
1658 * Invalidate the text from offset start upto, but not including,
1659 * offset end. Useful for (re)painting the selection.
1660 * Regions outside the linewidth are not invalidated.
1661 * end == -1 means end == TextLength.
1662 * start and end need not be ordered.
1665 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1671 end
= strlenW(es
->text
);
1679 if (es
->style
& ES_MULTILINE
)
1680 EDIT_ML_InvalidateText(es
, start
, end
);
1682 EDIT_SL_InvalidateText(es
, start
, end
);
1686 /*********************************************************************
1690 * Try to fit size + 1 characters in the buffer.
1691 * Constrain to limits if honor_limit is TRUE.
1693 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
)
1697 if (size
<= es
->buffer_size
)
1700 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
1701 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
1705 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1707 /* Force edit to unlock it's buffer. es->text now NULL */
1708 EDIT_UnlockBuffer(es
, TRUE
);
1711 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1712 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1713 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1714 es
->hloc32W
= hNew32W
;
1715 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1719 EDIT_LockBuffer(es
);
1721 if (es
->buffer_size
< size
) {
1722 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1723 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1726 TRACE("We now have %d+1\n", es
->buffer_size
);
1732 /*********************************************************************
1736 * Try to fit size + 1 bytes in the undo buffer.
1739 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1743 if (size
<= es
->undo_buffer_size
)
1746 TRACE("trying to ReAlloc to %d+1\n", size
);
1748 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1749 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1750 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
);
1755 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1761 /*********************************************************************
1766 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1768 INT e
= es
->selection_end
;
1772 if ((es
->style
& ES_MULTILINE
) && e
&&
1773 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1775 if (e
&& (es
->text
[e
- 1] == '\r'))
1779 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1780 EDIT_EM_ScrollCaret(es
);
1784 /*********************************************************************
1788 * Only for multi line controls
1789 * Move the caret one line down, on a column with the nearest
1790 * x coordinate on the screen (might be a different column).
1793 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1795 INT s
= es
->selection_start
;
1796 INT e
= es
->selection_end
;
1797 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1798 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1799 INT x
= SLOWORD(pos
);
1800 INT y
= SHIWORD(pos
);
1802 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1805 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1806 EDIT_EM_ScrollCaret(es
);
1810 /*********************************************************************
1815 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1817 BOOL after_wrap
= FALSE
;
1820 /* Pass a high value in x to make sure of receiving the end of the line */
1821 if (es
->style
& ES_MULTILINE
)
1822 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1823 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1825 e
= strlenW(es
->text
);
1826 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1827 EDIT_EM_ScrollCaret(es
);
1831 /*********************************************************************
1836 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1838 INT e
= es
->selection_end
;
1842 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1843 if (es
->text
[e
] == '\n')
1845 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1849 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1850 EDIT_EM_ScrollCaret(es
);
1854 /*********************************************************************
1858 * Home key: move to beginning of line.
1861 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1865 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1866 if (es
->style
& ES_MULTILINE
)
1867 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1868 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1871 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1872 EDIT_EM_ScrollCaret(es
);
1876 /*********************************************************************
1878 * EDIT_MovePageDown_ML
1880 * Only for multi line controls
1881 * Move the caret one page down, on a column with the nearest
1882 * x coordinate on the screen (might be a different column).
1885 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1887 INT s
= es
->selection_start
;
1888 INT e
= es
->selection_end
;
1889 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1890 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1891 INT x
= SLOWORD(pos
);
1892 INT y
= SHIWORD(pos
);
1894 e
= EDIT_CharFromPos(es
, x
,
1895 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1899 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1900 EDIT_EM_ScrollCaret(es
);
1904 /*********************************************************************
1906 * EDIT_MovePageUp_ML
1908 * Only for multi line controls
1909 * Move the caret one page up, on a column with the nearest
1910 * x coordinate on the screen (might be a different column).
1913 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1915 INT s
= es
->selection_start
;
1916 INT e
= es
->selection_end
;
1917 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1918 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1919 INT x
= SLOWORD(pos
);
1920 INT y
= SHIWORD(pos
);
1922 e
= EDIT_CharFromPos(es
, x
,
1923 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1927 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1928 EDIT_EM_ScrollCaret(es
);
1932 /*********************************************************************
1936 * Only for multi line controls
1937 * Move the caret one line up, on a column with the nearest
1938 * x coordinate on the screen (might be a different column).
1941 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1943 INT s
= es
->selection_start
;
1944 INT e
= es
->selection_end
;
1945 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1946 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1947 INT x
= SLOWORD(pos
);
1948 INT y
= SHIWORD(pos
);
1950 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1953 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1954 EDIT_EM_ScrollCaret(es
);
1958 /*********************************************************************
1960 * EDIT_MoveWordBackward
1963 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1965 INT s
= es
->selection_start
;
1966 INT e
= es
->selection_end
;
1971 l
= EDIT_EM_LineFromChar(es
, e
);
1972 ll
= EDIT_EM_LineLength(es
, e
);
1973 li
= EDIT_EM_LineIndex(es
, l
);
1976 li
= EDIT_EM_LineIndex(es
, l
- 1);
1977 e
= li
+ EDIT_EM_LineLength(es
, li
);
1980 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
1981 li
, e
- li
, ll
, WB_LEFT
);
1985 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
1986 EDIT_EM_ScrollCaret(es
);
1990 /*********************************************************************
1992 * EDIT_MoveWordForward
1995 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
1997 INT s
= es
->selection_start
;
1998 INT e
= es
->selection_end
;
2003 l
= EDIT_EM_LineFromChar(es
, e
);
2004 ll
= EDIT_EM_LineLength(es
, e
);
2005 li
= EDIT_EM_LineIndex(es
, l
);
2007 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2008 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2010 e
= li
+ EDIT_CallWordBreakProc(es
,
2011 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2015 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2016 EDIT_EM_ScrollCaret(es
);
2020 /*********************************************************************
2025 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2027 INT s
= es
->selection_start
;
2028 INT e
= es
->selection_end
;
2035 if (es
->style
& ES_MULTILINE
) {
2036 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2037 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2042 TRACE("line=%d\n", line
);
2044 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2047 li
= EDIT_EM_LineIndex(es
, line
);
2048 ll
= EDIT_EM_LineLength(es
, li
);
2049 s
= min(es
->selection_start
, es
->selection_end
);
2050 e
= max(es
->selection_start
, es
->selection_end
);
2051 s
= min(li
+ ll
, max(li
, s
));
2052 e
= min(li
+ ll
, max(li
, e
));
2053 if (rev
&& (s
!= e
) &&
2054 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2055 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2056 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2057 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2059 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2063 /*********************************************************************
2068 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2079 BkMode
= GetBkMode(dc
);
2080 BkColor
= GetBkColor(dc
);
2081 TextColor
= GetTextColor(dc
);
2083 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2084 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2085 SetBkMode( dc
, OPAQUE
);
2087 li
= EDIT_EM_LineIndex(es
, line
);
2088 if (es
->style
& ES_MULTILINE
) {
2089 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2090 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2092 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2093 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2094 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2096 if (es
->style
& ES_PASSWORD
)
2097 HeapFree(GetProcessHeap(), 0, text
);
2100 SetBkColor(dc
, BkColor
);
2101 SetTextColor(dc
, TextColor
);
2102 SetBkMode( dc
, BkMode
);
2108 /*********************************************************************
2113 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2116 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2117 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2121 /*********************************************************************
2125 * note: this is not (exactly) the handler called on EM_SETRECTNP
2126 * it is also used to set the rect of a single line control
2129 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2131 CopyRect(&es
->format_rect
, rc
);
2132 if (es
->style
& WS_BORDER
) {
2133 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2134 if(TWEAK_WineLook
== WIN31_LOOK
)
2136 es
->format_rect
.left
+= bw
;
2137 es
->format_rect
.top
+= bw
;
2138 es
->format_rect
.right
-= bw
;
2139 es
->format_rect
.bottom
-= bw
;
2141 es
->format_rect
.left
+= es
->left_margin
;
2142 es
->format_rect
.right
-= es
->right_margin
;
2143 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2144 if (es
->style
& ES_MULTILINE
)
2146 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2148 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2149 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2151 /* correct es->x_offset */
2152 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2153 max_x_offset
= es
->text_width
- fw
;
2154 if(max_x_offset
< 0) max_x_offset
= 0;
2155 if(es
->x_offset
> max_x_offset
)
2156 es
->x_offset
= max_x_offset
;
2158 /* correct es->y_offset */
2159 max_y_offset
= es
->line_count
- vlc
;
2160 if(max_y_offset
< 0) max_y_offset
= 0;
2161 if(es
->y_offset
> max_y_offset
)
2162 es
->y_offset
= max_y_offset
;
2164 /* force scroll info update */
2165 EDIT_UpdateScrollInfo(es
);
2168 /* Windows doesn't care to fix text placement for SL controls */
2169 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2171 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2172 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
2176 /*********************************************************************
2181 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2183 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2185 /* Edit window might be already destroyed */
2186 if(!IsWindow(es
->hwndSelf
))
2188 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2192 if (!es
->lock_count
) {
2193 ERR("lock_count == 0 ... please report\n");
2197 ERR("es->text == 0 ... please report\n");
2201 if (force
|| (es
->lock_count
== 1)) {
2204 BOOL _16bit
= FALSE
;
2206 UINT countW
= strlenW(es
->text
) + 1;
2210 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2211 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2212 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2213 countA
= LocalSize(es
->hloc32A
);
2214 if(countA_new
> countA
)
2217 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2218 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2219 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2222 es
->hloc32A
= hloc32A_new
;
2223 countA
= LocalSize(hloc32A_new
);
2224 TRACE("Real new size %d bytes\n", countA
);
2227 WARN("FAILED! Will synchronize partially\n");
2229 textA
= LocalLock(es
->hloc32A
);
2233 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2234 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2235 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2236 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2237 if(countA_new
> countA
)
2239 HLOCAL16 hloc16_new
;
2240 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2241 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2242 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2245 es
->hloc16
= hloc16_new
;
2246 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2247 TRACE("Real new size %d bytes\n", countA
);
2250 WARN("FAILED! Will synchronize partially\n");
2252 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2258 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2260 LOCAL_Unlock(hInstance
, es
->hloc16
);
2262 LocalUnlock(es
->hloc32A
);
2265 LocalUnlock(es
->hloc32W
);
2269 ERR("no buffer ... please report\n");
2277 /*********************************************************************
2279 * EDIT_UpdateScrollInfo
2282 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2284 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2287 si
.cbSize
= sizeof(SCROLLINFO
);
2288 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2290 si
.nMax
= es
->line_count
- 1;
2291 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2292 si
.nPos
= es
->y_offset
;
2293 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2294 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2295 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2298 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2301 si
.cbSize
= sizeof(SCROLLINFO
);
2302 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2304 si
.nMax
= es
->text_width
- 1;
2305 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2306 si
.nPos
= es
->x_offset
;
2307 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2308 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2309 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2313 /*********************************************************************
2315 * EDIT_WordBreakProc
2317 * Find the beginning of words.
2318 * Note: unlike the specs for a WordBreakProc, this function only
2319 * allows to be called without linebreaks between s[0] upto
2320 * s[count - 1]. Remember it is only called
2321 * internally, so we can decide this for ourselves.
2324 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2328 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2338 if (s
[index
] == ' ') {
2339 while (index
&& (s
[index
] == ' '))
2342 while (index
&& (s
[index
] != ' '))
2344 if (s
[index
] == ' ')
2348 while (index
&& (s
[index
] != ' '))
2350 if (s
[index
] == ' ')
2360 if (s
[index
] == ' ')
2361 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2363 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2365 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2369 case WB_ISDELIMITER
:
2370 ret
= (s
[index
] == ' ');
2373 ERR("unknown action code, please report !\n");
2380 /*********************************************************************
2384 * returns line number (not index) in high-order word of result.
2385 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2386 * to Richedit, not to the edit control. Original documentation is valid.
2387 * FIXME: do the specs mean to return -1 if outside client area or
2388 * if outside formatting rectangle ???
2391 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2399 GetClientRect(es
->hwndSelf
, &rc
);
2400 if (!PtInRect(&rc
, pt
))
2403 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2404 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2408 /*********************************************************************
2412 * Enable or disable soft breaks.
2414 * This means: insert or remove the soft linebreak character (\r\r\n).
2415 * Take care to check if the text still fits the buffer after insertion.
2416 * If not, notify with EN_ERRSPACE.
2419 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2421 es
->flags
&= ~EF_USE_SOFTBRK
;
2423 es
->flags
|= EF_USE_SOFTBRK
;
2424 FIXME("soft break enabled, not implemented\n");
2430 /*********************************************************************
2434 * Hopefully this won't fire back at us.
2435 * We always start with a fixed buffer in the local heap.
2436 * Despite of the documentation says that the local heap is used
2437 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2438 * buffer on the local heap.
2441 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2445 if (!(es
->style
& ES_MULTILINE
))
2449 hLocal
= es
->hloc32W
;
2455 UINT countA
, alloc_size
;
2456 TRACE("Allocating 32-bit ANSI alias buffer\n");
2457 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2458 alloc_size
= ROUND_TO_GROW(countA
);
2459 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2461 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2464 textA
= LocalLock(es
->hloc32A
);
2465 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2466 LocalUnlock(es
->hloc32A
);
2468 hLocal
= es
->hloc32A
;
2471 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2476 /*********************************************************************
2480 * Hopefully this won't fire back at us.
2481 * We always start with a buffer in 32 bit linear memory.
2482 * However, with this message a 16 bit application requests
2483 * a handle of 16 bit local heap memory, where it expects to find
2485 * It's a pitty that from this moment on we have to use this
2486 * local heap, because applications may rely on the handle
2489 * In this function we'll try to switch to local heap.
2491 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2493 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2495 UINT countA
, alloc_size
;
2497 if (!(es
->style
& ES_MULTILINE
))
2503 if (!LOCAL_HeapSize(hInstance
)) {
2504 if (!LocalInit16(hInstance
, 0,
2505 GlobalSize16(hInstance
))) {
2506 ERR("could not initialize local heap\n");
2509 TRACE("local heap initialized\n");
2512 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2513 alloc_size
= ROUND_TO_GROW(countA
);
2515 TRACE("Allocating 16-bit ANSI alias buffer\n");
2516 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2517 ERR("could not allocate new 16 bit buffer\n");
2521 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2522 ERR("could not lock new 16 bit buffer\n");
2523 LOCAL_Free(hInstance
, es
->hloc16
);
2528 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2529 LOCAL_Unlock(hInstance
, es
->hloc16
);
2531 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2536 /*********************************************************************
2541 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2544 INT line_len
, dst_len
;
2547 if (es
->style
& ES_MULTILINE
) {
2548 if (line
>= es
->line_count
)
2552 i
= EDIT_EM_LineIndex(es
, line
);
2554 line_len
= EDIT_EM_LineLength(es
, i
);
2555 dst_len
= *(WORD
*)lParam
;
2558 LPWSTR dst
= (LPWSTR
)lParam
;
2559 if(dst_len
<= line_len
)
2561 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2564 else /* Append 0 if enough space */
2566 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2573 LPSTR dst
= (LPSTR
)lParam
;
2575 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2576 if(!ret
) /* Insufficient buffer size */
2578 if(ret
< dst_len
) /* Append 0 if enough space */
2585 /*********************************************************************
2590 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2592 UINT s
= es
->selection_start
;
2593 UINT e
= es
->selection_end
;
2600 return MAKELONG(s
, e
);
2604 /*********************************************************************
2608 * FIXME: is this right ? (or should it be only VSCROLL)
2609 * (and maybe only for edit controls that really have their
2610 * own scrollbars) (and maybe only for multiline controls ?)
2611 * All in all: very poorly documented
2614 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2616 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2617 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2621 /*********************************************************************
2626 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2631 if (!(es
->style
& ES_MULTILINE
))
2633 if (index
> (INT
)strlenW(es
->text
))
2634 return es
->line_count
- 1;
2636 index
= min(es
->selection_start
, es
->selection_end
);
2639 line_def
= es
->first_line_def
;
2640 index
-= line_def
->length
;
2641 while ((index
>= 0) && line_def
->next
) {
2643 line_def
= line_def
->next
;
2644 index
-= line_def
->length
;
2650 /*********************************************************************
2655 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2660 if (!(es
->style
& ES_MULTILINE
))
2662 if (line
>= es
->line_count
)
2666 line_def
= es
->first_line_def
;
2668 INT index
= es
->selection_end
- line_def
->length
;
2669 while ((index
>= 0) && line_def
->next
) {
2670 line_index
+= line_def
->length
;
2671 line_def
= line_def
->next
;
2672 index
-= line_def
->length
;
2676 line_index
+= line_def
->length
;
2677 line_def
= line_def
->next
;
2685 /*********************************************************************
2690 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2694 if (!(es
->style
& ES_MULTILINE
))
2695 return strlenW(es
->text
);
2698 /* get the number of remaining non-selected chars of selected lines */
2699 INT32 l
; /* line number */
2700 INT32 li
; /* index of first char in line */
2702 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2703 /* # chars before start of selection area */
2704 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2705 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2706 /* # chars after end of selection */
2707 li
= EDIT_EM_LineIndex(es
, l
);
2708 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2711 line_def
= es
->first_line_def
;
2712 index
-= line_def
->length
;
2713 while ((index
>= 0) && line_def
->next
) {
2714 line_def
= line_def
->next
;
2715 index
-= line_def
->length
;
2717 return line_def
->net_length
;
2721 /*********************************************************************
2725 * NOTE: dx is in average character widths, dy - in lines;
2728 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2730 if (!(es
->style
& ES_MULTILINE
))
2733 dx
*= es
->char_width
;
2734 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2737 /*********************************************************************
2739 * EDIT_EM_LineScroll_internal
2741 * Version of EDIT_EM_LineScroll for internal use.
2742 * It doesn't refuse if ES_MULTILINE is set and assumes that
2743 * dx is in pixels, dy - in lines.
2746 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2749 INT x_offset_in_pixels
;
2751 if (es
->style
& ES_MULTILINE
)
2753 x_offset_in_pixels
= es
->x_offset
;
2758 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2761 if (-dx
> x_offset_in_pixels
)
2762 dx
= -x_offset_in_pixels
;
2763 if (dx
> es
->text_width
- x_offset_in_pixels
)
2764 dx
= es
->text_width
- x_offset_in_pixels
;
2765 nyoff
= max(0, es
->y_offset
+ dy
);
2766 if (nyoff
>= es
->line_count
)
2767 nyoff
= es
->line_count
- 1;
2768 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2773 es
->y_offset
= nyoff
;
2774 if(es
->style
& ES_MULTILINE
)
2777 es
->x_offset
+= dx
/ es
->char_width
;
2779 GetClientRect(es
->hwndSelf
, &rc1
);
2780 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2781 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2782 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2783 /* force scroll info update */
2784 EDIT_UpdateScrollInfo(es
);
2786 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2787 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2788 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2789 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2794 /*********************************************************************
2799 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2801 INT len
= strlenW(es
->text
);
2810 index
= min(index
, len
);
2811 dc
= GetDC(es
->hwndSelf
);
2813 old_font
= SelectObject(dc
, es
->font
);
2814 if (es
->style
& ES_MULTILINE
) {
2815 l
= EDIT_EM_LineFromChar(es
, index
);
2816 y
= (l
- es
->y_offset
) * es
->line_height
;
2817 li
= EDIT_EM_LineIndex(es
, l
);
2818 if (after_wrap
&& (li
== index
) && l
) {
2820 LINEDEF
*line_def
= es
->first_line_def
;
2822 line_def
= line_def
->next
;
2825 if (line_def
->ending
== END_WRAP
) {
2827 y
-= es
->line_height
;
2828 li
= EDIT_EM_LineIndex(es
, l
);
2831 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2832 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2834 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2835 if (index
< es
->x_offset
) {
2836 GetTextExtentPoint32W(dc
, text
+ index
,
2837 es
->x_offset
- index
, &size
);
2840 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2841 index
- es
->x_offset
, &size
);
2845 if (es
->style
& ES_PASSWORD
)
2846 HeapFree(GetProcessHeap(), 0, text
);
2848 x
+= es
->format_rect
.left
;
2849 y
+= es
->format_rect
.top
;
2851 SelectObject(dc
, old_font
);
2852 ReleaseDC(es
->hwndSelf
, dc
);
2853 return MAKELONG((INT16
)x
, (INT16
)y
);
2857 /*********************************************************************
2861 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2864 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2866 UINT strl
= strlenW(lpsz_replace
);
2867 UINT tl
= strlenW(es
->text
);
2875 TRACE("%s, can_undo %d, send_update %d\n",
2876 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2878 s
= es
->selection_start
;
2879 e
= es
->selection_end
;
2881 if ((s
== e
) && !strl
)
2886 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
, honor_limit
))
2890 /* there is something to be deleted */
2891 TRACE("deleting stuff.\n");
2893 utl
= strlenW(es
->undo_text
);
2894 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2895 /* undo-buffer is extended to the right */
2896 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2897 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2898 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2899 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2900 /* undo-buffer is extended to the left */
2901 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2902 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2904 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2905 p
[i
] = (es
->text
+ s
)[i
];
2906 es
->undo_position
= s
;
2908 /* new undo-buffer */
2909 EDIT_MakeUndoFit(es
, e
- s
);
2910 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2911 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2912 es
->undo_position
= s
;
2914 /* any deletion makes the old insertion-undo invalid */
2915 es
->undo_insert_count
= 0;
2917 EDIT_EM_EmptyUndoBuffer(es
);
2920 strcpyW(es
->text
+ s
, es
->text
+ e
);
2923 /* there is an insertion */
2925 if ((s
== es
->undo_position
) ||
2926 ((es
->undo_insert_count
) &&
2927 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2929 * insertion is new and at delete position or
2930 * an extension to either left or right
2932 es
->undo_insert_count
+= strl
;
2934 /* new insertion undo */
2935 es
->undo_position
= s
;
2936 es
->undo_insert_count
= strl
;
2937 /* new insertion makes old delete-buffer invalid */
2938 *es
->undo_text
= '\0';
2941 EDIT_EM_EmptyUndoBuffer(es
);
2944 tl
= strlenW(es
->text
);
2945 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
));
2946 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2948 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2949 p
[i
] = lpsz_replace
[i
];
2950 if(es
->style
& ES_UPPERCASE
)
2951 CharUpperBuffW(p
, strl
);
2952 else if(es
->style
& ES_LOWERCASE
)
2953 CharLowerBuffW(p
, strl
);
2956 if (es
->style
& ES_MULTILINE
)
2958 INT s
= min(es
->selection_start
, es
->selection_end
);
2960 hrgn
= CreateRectRgn(0, 0, 0, 0);
2961 EDIT_BuildLineDefs_ML(es
, s
, s
+ strl
,
2962 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2965 EDIT_CalcLineWidth_SL(es
);
2967 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2968 es
->flags
|= EF_MODIFIED
;
2969 if (send_update
) es
->flags
|= EF_UPDATE
;
2970 EDIT_EM_ScrollCaret(es
);
2972 /* force scroll info update */
2973 EDIT_UpdateScrollInfo(es
);
2977 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2981 EDIT_UpdateText(es
, NULL
, TRUE
);
2983 if(es
->flags
& EF_UPDATE
)
2985 es
->flags
&= ~EF_UPDATE
;
2986 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
2991 /*********************************************************************
2996 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3000 if (!(es
->style
& ES_MULTILINE
))
3001 return (LRESULT
)FALSE
;
3011 if (es
->y_offset
< es
->line_count
- 1)
3016 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3019 if (es
->y_offset
< es
->line_count
- 1)
3020 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3023 return (LRESULT
)FALSE
;
3026 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3027 /* check if we are going to move too far */
3028 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3029 dy
= es
->line_count
- vlc
- es
->y_offset
;
3031 /* Notification is done in EDIT_EM_LineScroll */
3033 EDIT_EM_LineScroll(es
, 0, dy
);
3035 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3039 /*********************************************************************
3044 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3046 if (es
->style
& ES_MULTILINE
) {
3051 INT cw
= es
->char_width
;
3056 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3057 li
= EDIT_EM_LineIndex(es
, l
);
3058 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3059 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3060 if (l
>= es
->y_offset
+ vlc
)
3061 dy
= l
- vlc
+ 1 - es
->y_offset
;
3062 if (l
< es
->y_offset
)
3063 dy
= l
- es
->y_offset
;
3064 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3065 if (x
< es
->format_rect
.left
)
3066 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3067 if (x
> es
->format_rect
.right
)
3068 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3071 /* check if we are going to move too far */
3072 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3073 dx
= es
->text_width
- ww
- es
->x_offset
;
3075 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3082 if (!(es
->style
& ES_AUTOHSCROLL
))
3085 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3086 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3087 if (x
< es
->format_rect
.left
) {
3088 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3091 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3092 } while ((x
< goal
) && es
->x_offset
);
3093 /* FIXME: use ScrollWindow() somehow to improve performance */
3094 EDIT_UpdateText(es
, NULL
, TRUE
);
3095 } else if (x
> es
->format_rect
.right
) {
3097 INT len
= strlenW(es
->text
);
3098 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3101 x
= SLOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3102 x_last
= SLOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3103 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3104 /* FIXME: use ScrollWindow() somehow to improve performance */
3105 EDIT_UpdateText(es
, NULL
, TRUE
);
3109 if(es
->flags
& EF_FOCUSED
)
3110 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3114 /*********************************************************************
3118 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3121 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3123 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3125 if (!(es
->style
& ES_MULTILINE
))
3129 WARN("called with NULL handle\n");
3133 EDIT_UnlockBuffer(es
, TRUE
);
3137 LOCAL_Free(hInstance
, es
->hloc16
);
3138 es
->hloc16
= (HLOCAL16
)NULL
;
3145 LocalFree(es
->hloc32A
);
3146 es
->hloc32A
= (HLOCAL
)NULL
;
3157 countA
= LocalSize(hloc
);
3158 textA
= LocalLock(hloc
);
3159 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3160 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3162 ERR("Could not allocate new unicode buffer\n");
3165 textW
= LocalLock(hloc32W_new
);
3166 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3167 LocalUnlock(hloc32W_new
);
3171 LocalFree(es
->hloc32W
);
3173 es
->hloc32W
= hloc32W_new
;
3177 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3179 EDIT_LockBuffer(es
);
3181 es
->x_offset
= es
->y_offset
= 0;
3182 es
->selection_start
= es
->selection_end
= 0;
3183 EDIT_EM_EmptyUndoBuffer(es
);
3184 es
->flags
&= ~EF_MODIFIED
;
3185 es
->flags
&= ~EF_UPDATE
;
3186 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3187 EDIT_UpdateText(es
, NULL
, TRUE
);
3188 EDIT_EM_ScrollCaret(es
);
3189 /* force scroll info update */
3190 EDIT_UpdateScrollInfo(es
);
3194 /*********************************************************************
3198 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3201 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3203 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3209 if (!(es
->style
& ES_MULTILINE
))
3213 WARN("called with NULL handle\n");
3217 EDIT_UnlockBuffer(es
, TRUE
);
3221 LocalFree(es
->hloc32A
);
3222 es
->hloc32A
= (HLOCAL
)NULL
;
3225 countA
= LOCAL_Size(hInstance
, hloc
);
3226 textA
= LOCAL_Lock(hInstance
, hloc
);
3227 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3228 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3230 ERR("Could not allocate new unicode buffer\n");
3233 textW
= LocalLock(hloc32W_new
);
3234 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3235 LocalUnlock(hloc32W_new
);
3236 LOCAL_Unlock(hInstance
, hloc
);
3239 LocalFree(es
->hloc32W
);
3241 es
->hloc32W
= hloc32W_new
;
3244 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3246 EDIT_LockBuffer(es
);
3248 es
->x_offset
= es
->y_offset
= 0;
3249 es
->selection_start
= es
->selection_end
= 0;
3250 EDIT_EM_EmptyUndoBuffer(es
);
3251 es
->flags
&= ~EF_MODIFIED
;
3252 es
->flags
&= ~EF_UPDATE
;
3253 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3254 EDIT_UpdateText(es
, NULL
, TRUE
);
3255 EDIT_EM_ScrollCaret(es
);
3256 /* force scroll info update */
3257 EDIT_UpdateScrollInfo(es
);
3261 /*********************************************************************
3265 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3266 * However, the windows version is not complied to yet in all of edit.c
3268 * Additionally as the wrapper for RichEdit controls we need larger buffers
3269 * at present -1 will represent nolimit
3271 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3273 if (limit
== 0xFFFFFFFF)
3274 es
->buffer_limit
= -1;
3275 else if (es
->style
& ES_MULTILINE
) {
3277 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3279 es
->buffer_limit
= BUFLIMIT_MULTI
;
3282 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3284 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3289 /*********************************************************************
3293 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3294 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3295 * of the char's width, according to the new docs.
3298 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3299 INT left
, INT right
)
3301 if (action
& EC_LEFTMARGIN
) {
3302 if (left
!= EC_USEFONTINFO
)
3303 es
->left_margin
= left
;
3305 es
->left_margin
= es
->char_width
/ 3;
3308 if (action
& EC_RIGHTMARGIN
) {
3309 if (right
!= EC_USEFONTINFO
)
3310 es
->right_margin
= right
;
3312 es
->right_margin
= es
->char_width
/ 3;
3314 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3318 /*********************************************************************
3320 * EM_SETPASSWORDCHAR
3323 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3327 if (es
->style
& ES_MULTILINE
)
3330 if (es
->password_char
== c
)
3333 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3334 es
->password_char
= c
;
3336 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3337 es
->style
|= ES_PASSWORD
;
3339 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3340 es
->style
&= ~ES_PASSWORD
;
3342 EDIT_UpdateText(es
, NULL
, TRUE
);
3346 /*********************************************************************
3350 * note: unlike the specs say: the order of start and end
3351 * _is_ preserved in Windows. (i.e. start can be > end)
3352 * In other words: this handler is OK
3355 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3357 UINT old_start
= es
->selection_start
;
3358 UINT old_end
= es
->selection_end
;
3359 UINT len
= strlenW(es
->text
);
3361 if (start
== (UINT
)-1) {
3362 start
= es
->selection_end
;
3363 end
= es
->selection_end
;
3365 start
= min(start
, len
);
3366 end
= min(end
, len
);
3368 es
->selection_start
= start
;
3369 es
->selection_end
= end
;
3371 es
->flags
|= EF_AFTER_WRAP
;
3373 es
->flags
&= ~EF_AFTER_WRAP
;
3374 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3375 ORDER_UINT(start
, end
);
3376 ORDER_UINT(end
, old_end
);
3377 ORDER_UINT(start
, old_start
);
3378 ORDER_UINT(old_start
, old_end
);
3379 if (end
!= old_start
)
3383 * ORDER_UINT32(end, old_start);
3384 * EDIT_InvalidateText(es, start, end);
3385 * EDIT_InvalidateText(es, old_start, old_end);
3386 * in place of the following if statement.
3388 if (old_start
> end
)
3390 EDIT_InvalidateText(es
, start
, end
);
3391 EDIT_InvalidateText(es
, old_start
, old_end
);
3395 EDIT_InvalidateText(es
, start
, old_start
);
3396 EDIT_InvalidateText(es
, end
, old_end
);
3399 else EDIT_InvalidateText(es
, start
, old_end
);
3403 /*********************************************************************
3408 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3410 if (!(es
->style
& ES_MULTILINE
))
3413 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3414 es
->tabs_count
= count
;
3418 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3419 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3425 /*********************************************************************
3430 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3432 if (!(es
->style
& ES_MULTILINE
))
3435 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3436 es
->tabs_count
= count
;
3441 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3442 for (i
= 0 ; i
< count
; i
++)
3443 es
->tabs
[i
] = *tabs
++;
3449 /*********************************************************************
3451 * EM_SETWORDBREAKPROC
3454 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
)
3456 if (es
->word_break_proc
== (void *)lParam
)
3459 es
->word_break_proc
= (void *)lParam
;
3460 es
->word_break_proc16
= NULL
;
3462 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3463 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3464 EDIT_UpdateText(es
, NULL
, TRUE
);
3469 /*********************************************************************
3471 * EM_SETWORDBREAKPROC16
3474 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3476 if (es
->word_break_proc16
== wbp
)
3479 es
->word_break_proc
= NULL
;
3480 es
->word_break_proc16
= wbp
;
3481 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3482 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3483 EDIT_UpdateText(es
, NULL
, TRUE
);
3488 /*********************************************************************
3493 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3498 /* Protect read-only edit control from modification */
3499 if(es
->style
& ES_READONLY
)
3502 ulength
= strlenW(es
->undo_text
);
3503 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3505 strcpyW(utext
, es
->undo_text
);
3507 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3508 es
->undo_insert_count
, debugstr_w(utext
));
3510 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3511 EDIT_EM_EmptyUndoBuffer(es
);
3512 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, FALSE
, TRUE
);
3513 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3514 /* send the notification after the selection start and end are set */
3515 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3516 EDIT_EM_ScrollCaret(es
);
3517 HeapFree(GetProcessHeap(), 0, utext
);
3519 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3520 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3525 /*********************************************************************
3530 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3534 /* Protect read-only edit control from modification */
3535 if(es
->style
& ES_READONLY
)
3538 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3542 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3543 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3546 if (es
->style
& ES_MULTILINE
) {
3547 if (es
->style
& ES_READONLY
) {
3548 EDIT_MoveHome(es
, FALSE
);
3549 EDIT_MoveDown_ML(es
, FALSE
);
3551 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3552 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3557 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3559 static const WCHAR tabW
[] = {'\t',0};
3560 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3564 if (!(es
->style
& ES_READONLY
) && !control
) {
3565 if (es
->selection_start
!= es
->selection_end
)
3568 /* delete character left of caret */
3569 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3570 EDIT_MoveBackward(es
, TRUE
);
3576 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3579 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3582 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3586 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3590 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3597 /*********************************************************************
3602 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3604 if (code
|| control
)
3624 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3625 EDIT_EM_ScrollCaret(es
);
3628 ERR("unknown menu item, please report\n");
3634 /*********************************************************************
3638 * Note: the resource files resource/sysres_??.rc cannot define a
3639 * single popup menu. Hence we use a (dummy) menubar
3640 * containing the single popup menu as its first item.
3642 * FIXME: the message identifiers have been chosen arbitrarily,
3643 * hence we use MF_BYPOSITION.
3644 * We might as well use the "real" values (anybody knows ?)
3645 * The menu definition is in resources/sysres_??.rc.
3646 * Once these are OK, we better use MF_BYCOMMAND here
3647 * (as we do in EDIT_WM_Command()).
3650 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3652 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3653 HMENU popup
= GetSubMenu(menu
, 0);
3654 UINT start
= es
->selection_start
;
3655 UINT end
= es
->selection_end
;
3657 ORDER_UINT(start
, end
);
3660 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3662 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3664 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3666 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3668 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3670 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3672 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3677 /*********************************************************************
3682 static void EDIT_WM_Copy(EDITSTATE
*es
)
3684 INT s
= min(es
->selection_start
, es
->selection_end
);
3685 INT e
= max(es
->selection_start
, es
->selection_end
);
3691 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3692 dst
= GlobalLock(hdst
);
3693 strncpyW(dst
, es
->text
+ s
, e
- s
);
3694 dst
[e
- s
] = 0; /* ensure 0 termination */
3695 TRACE("%s\n", debugstr_w(dst
));
3697 OpenClipboard(es
->hwndSelf
);
3699 SetClipboardData(CF_UNICODETEXT
, hdst
);
3704 /*********************************************************************
3709 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3711 TRACE("%s\n", debugstr_w(name
));
3713 * To initialize some final structure members, we call some helper
3714 * functions. However, since the EDITSTATE is not consistent (i.e.
3715 * not fully initialized), we should be very careful which
3716 * functions can be called, and in what order.
3718 EDIT_WM_SetFont(es
, 0, FALSE
);
3719 EDIT_EM_EmptyUndoBuffer(es
);
3721 if (name
&& *name
) {
3722 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3723 /* if we insert text to the editline, the text scrolls out
3724 * of the window, as the caret is placed after the insert
3725 * pos normally; thus we reset es->selection... to 0 and
3728 es
->selection_start
= es
->selection_end
= 0;
3729 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3730 * Messages are only to be sent when the USER does something to
3731 * change the contents. So I am removing this EN_CHANGE
3733 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3735 EDIT_EM_ScrollCaret(es
);
3737 /* force scroll info update */
3738 EDIT_UpdateScrollInfo(es
);
3743 /*********************************************************************
3748 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
3753 while (LocalUnlock(es
->hloc32W
)) ;
3754 LocalFree(es
->hloc32W
);
3757 while (LocalUnlock(es
->hloc32A
)) ;
3758 LocalFree(es
->hloc32A
);
3761 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
3762 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3763 LOCAL_Free(hInstance
, es
->hloc16
);
3766 pc
= es
->first_line_def
;
3770 HeapFree(GetProcessHeap(), 0, pc
);
3774 SetWindowLongW( es
->hwndSelf
, 0, 0 );
3775 HeapFree(GetProcessHeap(), 0, es
);
3781 /*********************************************************************
3786 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
3791 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
3792 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3794 GetClientRect(es
->hwndSelf
, &rc
);
3795 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3796 GetClipBox(dc
, &rc
);
3798 * FIXME: specs say that we should UnrealizeObject() the brush,
3799 * but the specs of UnrealizeObject() say that we shouldn't
3800 * unrealize a stock object. The default brush that
3801 * DefWndProc() returns is ... a stock object.
3803 FillRect(dc
, &rc
, brush
);
3808 /*********************************************************************
3813 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3815 if(!count
) return 0;
3819 LPWSTR textW
= (LPWSTR
)lParam
;
3820 lstrcpynW(textW
, es
->text
, count
);
3821 return strlenW(textW
);
3825 LPSTR textA
= (LPSTR
)lParam
;
3826 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3827 textA
[count
- 1] = 0; /* ensure 0 termination */
3828 return strlen(textA
);
3832 /*********************************************************************
3837 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3842 if (!(es
->style
& ES_MULTILINE
))
3845 if (!(es
->style
& ES_AUTOHSCROLL
))
3849 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3852 TRACE("SB_LINELEFT\n");
3854 dx
= -es
->char_width
;
3857 TRACE("SB_LINERIGHT\n");
3858 if (es
->x_offset
< es
->text_width
)
3859 dx
= es
->char_width
;
3862 TRACE("SB_PAGELEFT\n");
3864 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3867 TRACE("SB_PAGERIGHT\n");
3868 if (es
->x_offset
< es
->text_width
)
3869 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3877 TRACE("SB_RIGHT\n");
3878 if (es
->x_offset
< es
->text_width
)
3879 dx
= es
->text_width
- es
->x_offset
;
3882 TRACE("SB_THUMBTRACK %d\n", pos
);
3883 es
->flags
|= EF_HSCROLL_TRACK
;
3884 if(es
->style
& WS_HSCROLL
)
3885 dx
= pos
- es
->x_offset
;
3890 if(pos
< 0 || pos
> 100) return 0;
3891 /* Assume default scroll range 0-100 */
3892 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3893 new_x
= pos
* (es
->text_width
- fw
) / 100;
3894 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3897 case SB_THUMBPOSITION
:
3898 TRACE("SB_THUMBPOSITION %d\n", pos
);
3899 es
->flags
&= ~EF_HSCROLL_TRACK
;
3900 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3901 dx
= pos
- es
->x_offset
;
3906 if(pos
< 0 || pos
> 100) return 0;
3907 /* Assume default scroll range 0-100 */
3908 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3909 new_x
= pos
* (es
->text_width
- fw
) / 100;
3910 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3913 /* force scroll info update */
3914 EDIT_UpdateScrollInfo(es
);
3915 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
3919 TRACE("SB_ENDSCROLL\n");
3922 * FIXME : the next two are undocumented !
3923 * Are we doing the right thing ?
3924 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3925 * although it's also a regular control message.
3927 case EM_GETTHUMB
: /* this one is used by NT notepad */
3931 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3932 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3935 /* Assume default scroll range 0-100 */
3936 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3937 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3939 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3942 case EM_LINESCROLL16
:
3943 TRACE("EM_LINESCROLL16\n");
3948 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3954 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3955 /* check if we are going to move too far */
3956 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3957 dx
= es
->text_width
- fw
- es
->x_offset
;
3959 EDIT_EM_LineScroll_internal(es
, dx
, 0);
3965 /*********************************************************************
3970 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3972 HWND hLBox
= es
->hwndListBox
;
3980 hCombo
= GetParent(es
->hwndSelf
);
3984 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3986 if (key
== VK_UP
|| key
== VK_DOWN
)
3988 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3991 if (msg
== WM_KEYDOWN
|| nEUI
)
3992 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3998 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4000 /* make sure ComboLBox pops up */
4001 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4006 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4009 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4011 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4013 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4018 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4024 /*********************************************************************
4028 * Handling of special keys that don't produce a WM_CHAR
4029 * (i.e. non-printable keys) & Backspace & Delete
4032 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4037 if (GetKeyState(VK_MENU
) & 0x8000)
4040 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4041 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4046 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4051 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4052 EDIT_MoveUp_ML(es
, shift
);
4055 EDIT_MoveWordBackward(es
, shift
);
4057 EDIT_MoveBackward(es
, shift
);
4060 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4064 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4065 EDIT_MoveDown_ML(es
, shift
);
4067 EDIT_MoveWordForward(es
, shift
);
4069 EDIT_MoveForward(es
, shift
);
4072 EDIT_MoveHome(es
, shift
);
4075 EDIT_MoveEnd(es
, shift
);
4078 if (es
->style
& ES_MULTILINE
)
4079 EDIT_MovePageUp_ML(es
, shift
);
4081 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4084 if (es
->style
& ES_MULTILINE
)
4085 EDIT_MovePageDown_ML(es
, shift
);
4087 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4090 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4091 if (es
->selection_start
!= es
->selection_end
) {
4098 /* delete character left of caret */
4099 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4100 EDIT_MoveBackward(es
, TRUE
);
4102 } else if (control
) {
4103 /* delete to end of line */
4104 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4105 EDIT_MoveEnd(es
, TRUE
);
4108 /* delete character right of caret */
4109 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4110 EDIT_MoveForward(es
, TRUE
);
4118 if (!(es
->style
& ES_READONLY
))
4124 /* If the edit doesn't want the return send a message to the default object */
4125 if(!(es
->style
& ES_WANTRETURN
))
4127 HWND hwndParent
= GetParent(es
->hwndSelf
);
4128 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4129 if (HIWORD(dw
) == DC_HASDEFID
)
4131 SendMessageW( hwndParent
, WM_COMMAND
,
4132 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4133 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4142 /*********************************************************************
4147 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4149 es
->flags
&= ~EF_FOCUSED
;
4151 if(!(es
->style
& ES_NOHIDESEL
))
4152 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4153 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4158 /*********************************************************************
4162 * The caret position has been set on the WM_LBUTTONDOWN message
4165 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4168 INT e
= es
->selection_end
;
4173 if (!(es
->flags
& EF_FOCUSED
))
4176 l
= EDIT_EM_LineFromChar(es
, e
);
4177 li
= EDIT_EM_LineIndex(es
, l
);
4178 ll
= EDIT_EM_LineLength(es
, e
);
4179 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4180 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4181 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4182 EDIT_EM_ScrollCaret(es
);
4187 /*********************************************************************
4192 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4197 if (!(es
->flags
& EF_FOCUSED
))
4200 es
->bCaptureState
= TRUE
;
4201 SetCapture(es
->hwndSelf
);
4202 EDIT_ConfinePoint(es
, &x
, &y
);
4203 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4204 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4205 EDIT_EM_ScrollCaret(es
);
4206 es
->region_posx
= es
->region_posy
= 0;
4207 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4212 /*********************************************************************
4217 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4219 if (es
->bCaptureState
&& GetCapture() == es
->hwndSelf
) {
4220 KillTimer(es
->hwndSelf
, 0);
4223 es
->bCaptureState
= FALSE
;
4228 /*********************************************************************
4233 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4235 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4240 /*********************************************************************
4245 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4251 if (GetCapture() != es
->hwndSelf
)
4255 * FIXME: gotta do some scrolling if outside client
4256 * area. Maybe reset the timer ?
4259 EDIT_ConfinePoint(es
, &x
, &y
);
4260 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4261 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4262 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4263 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4264 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4269 /*********************************************************************
4273 * See also EDIT_WM_StyleChanged
4275 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4280 TRACE("Creating %s edit control, style = %08lx\n",
4281 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4283 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4285 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4288 * Note: since the EDITSTATE has not been fully initialized yet,
4289 * we can't use any API calls that may send
4290 * WM_XXX messages before WM_NCCREATE is completed.
4293 es
->is_unicode
= unicode
;
4294 es
->style
= lpcs
->style
;
4296 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4298 es
->hwndSelf
= hwnd
;
4299 /* Save parent, which will be notified by EN_* messages */
4300 es
->hwndParent
= lpcs
->hwndParent
;
4302 if (es
->style
& ES_COMBO
)
4303 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4305 /* Number overrides lowercase overrides uppercase (at least it
4306 * does in Win95). However I'll bet that ES_NUMBER would be
4307 * invalid under Win 3.1.
4309 if (es
->style
& ES_NUMBER
) {
4310 ; /* do not override the ES_NUMBER */
4311 } else if (es
->style
& ES_LOWERCASE
) {
4312 es
->style
&= ~ES_UPPERCASE
;
4314 if (es
->style
& ES_MULTILINE
) {
4315 es
->buffer_limit
= BUFLIMIT_MULTI
;
4316 if (es
->style
& WS_VSCROLL
)
4317 es
->style
|= ES_AUTOVSCROLL
;
4318 if (es
->style
& WS_HSCROLL
)
4319 es
->style
|= ES_AUTOHSCROLL
;
4320 es
->style
&= ~ES_PASSWORD
;
4321 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4322 /* Confirmed - RIGHT overrides CENTER */
4323 if (es
->style
& ES_RIGHT
)
4324 es
->style
&= ~ES_CENTER
;
4325 es
->style
&= ~WS_HSCROLL
;
4326 es
->style
&= ~ES_AUTOHSCROLL
;
4329 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4330 es
->style
|= ES_AUTOVSCROLL
;
4332 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4333 if (WIN31_LOOK
== TWEAK_WineLook
||
4334 WIN95_LOOK
== TWEAK_WineLook
) {
4335 es
->style
&= ~ES_CENTER
;
4336 es
->style
&= ~ES_RIGHT
;
4338 if (es
->style
& ES_RIGHT
)
4339 es
->style
&= ~ES_CENTER
;
4341 es
->style
&= ~WS_HSCROLL
;
4342 es
->style
&= ~WS_VSCROLL
;
4343 es
->style
&= ~ES_AUTOVSCROLL
;
4344 es
->style
&= ~ES_WANTRETURN
;
4345 if (es
->style
& ES_PASSWORD
)
4346 es
->password_char
= '*';
4348 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4349 es
->style
|= ES_AUTOHSCROLL
;
4352 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4353 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4355 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4357 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4359 es
->undo_buffer_size
= es
->buffer_size
;
4361 if (es
->style
& ES_MULTILINE
)
4362 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4367 * In Win95 look and feel, the WS_BORDER style is replaced by the
4368 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4369 * control a non client area. Not always. This coordinates in some
4370 * way with the window creation code in dialog.c When making
4371 * modifications please ensure that the code still works for edit
4372 * controls created directly with style 0x50800000, exStyle 0 (
4373 * which should have a single pixel border)
4375 if (TWEAK_WineLook
!= WIN31_LOOK
)
4377 es
->style
&= ~WS_BORDER
;
4381 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4382 SetWindowLongW( hwnd
, GWL_STYLE
,
4383 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4389 /*********************************************************************
4394 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
)
4403 BOOL rev
= es
->bEnableState
&&
4404 ((es
->flags
& EF_FOCUSED
) ||
4405 (es
->style
& ES_NOHIDESEL
));
4407 dc
= BeginPaint(es
->hwndSelf
, &ps
);
4410 if(es
->style
& WS_BORDER
) {
4411 GetClientRect(es
->hwndSelf
, &rc
);
4412 if(es
->style
& ES_MULTILINE
) {
4413 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4414 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4416 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4418 IntersectClipRect(dc
, es
->format_rect
.left
,
4419 es
->format_rect
.top
,
4420 es
->format_rect
.right
,
4421 es
->format_rect
.bottom
);
4422 if (es
->style
& ES_MULTILINE
) {
4423 GetClientRect(es
->hwndSelf
, &rc
);
4424 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4427 old_font
= SelectObject(dc
, es
->font
);
4428 EDIT_NotifyCtlColor(es
, dc
);
4430 if (!es
->bEnableState
)
4431 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4432 GetClipBox(dc
, &rcRgn
);
4433 if (es
->style
& ES_MULTILINE
) {
4434 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4435 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4436 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4437 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4438 EDIT_PaintLine(es
, dc
, i
, rev
);
4441 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4442 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4443 EDIT_PaintLine(es
, dc
, 0, rev
);
4446 SelectObject(dc
, old_font
);
4449 EndPaint(es
->hwndSelf
, &ps
);
4453 /*********************************************************************
4458 static void EDIT_WM_Paste(EDITSTATE
*es
)
4463 /* Protect read-only edit control from modification */
4464 if(es
->style
& ES_READONLY
)
4467 OpenClipboard(es
->hwndSelf
);
4468 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4469 src
= (LPWSTR
)GlobalLock(hsrc
);
4470 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4477 /*********************************************************************
4482 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4484 es
->flags
|= EF_FOCUSED
;
4485 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4486 EDIT_SetCaretPos(es
, es
->selection_end
,
4487 es
->flags
& EF_AFTER_WRAP
);
4488 if(!(es
->style
& ES_NOHIDESEL
))
4489 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4490 ShowCaret(es
->hwndSelf
);
4491 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4495 /*********************************************************************
4499 * With Win95 look the margins are set to default font value unless
4500 * the system font (font == 0) is being set, in which case they are left
4504 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4512 dc
= GetDC(es
->hwndSelf
);
4514 old_font
= SelectObject(dc
, font
);
4515 GetTextMetricsW(dc
, &tm
);
4516 es
->line_height
= tm
.tmHeight
;
4517 es
->char_width
= tm
.tmAveCharWidth
;
4519 SelectObject(dc
, old_font
);
4520 ReleaseDC(es
->hwndSelf
, dc
);
4521 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4522 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4523 EC_USEFONTINFO
, EC_USEFONTINFO
);
4525 /* Force the recalculation of the format rect for each font change */
4526 GetClientRect(es
->hwndSelf
, &r
);
4527 EDIT_SetRectNP(es
, &r
);
4529 if (es
->style
& ES_MULTILINE
)
4530 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
4532 EDIT_CalcLineWidth_SL(es
);
4535 EDIT_UpdateText(es
, NULL
, TRUE
);
4536 if (es
->flags
& EF_FOCUSED
) {
4538 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4539 EDIT_SetCaretPos(es
, es
->selection_end
,
4540 es
->flags
& EF_AFTER_WRAP
);
4541 ShowCaret(es
->hwndSelf
);
4546 /*********************************************************************
4551 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4552 * The modified flag is reset. No notifications are sent.
4554 * For single-line controls, reception of WM_SETTEXT triggers:
4555 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4558 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4563 text
= (LPWSTR
)lParam
;
4566 LPCSTR textA
= (LPCSTR
)lParam
;
4567 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4568 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4569 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4572 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4574 TRACE("%s\n", debugstr_w(text
));
4575 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4577 HeapFree(GetProcessHeap(), 0, text
);
4579 static const WCHAR empty_stringW
[] = {0};
4581 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4584 es
->flags
&= ~EF_MODIFIED
;
4585 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4586 /* Send the notification after the selection start and end have been set
4587 * edit control doesn't send notification on WM_SETTEXT
4588 * if it is multiline, or it is part of combobox
4590 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4592 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4593 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4595 EDIT_EM_ScrollCaret(es
);
4599 /*********************************************************************
4604 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4606 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4608 TRACE("width = %d, height = %d\n", width
, height
);
4609 SetRect(&rc
, 0, 0, width
, height
);
4610 EDIT_SetRectNP(es
, &rc
);
4611 EDIT_UpdateText(es
, NULL
, TRUE
);
4616 /*********************************************************************
4620 * This message is sent by SetWindowLong on having changed either the Style
4621 * or the extended style.
4623 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4625 * See also EDIT_WM_NCCreate
4627 * It appears that the Windows version of the edit control allows the style
4628 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4629 * style variable which will generally be different. In this function we
4630 * update the internal style based on what changed in the externally visible
4633 * Much of this content as based upon the MSDN, especially:
4634 * Platform SDK Documentation -> User Interface Services ->
4635 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4636 * Edit Control Styles
4638 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4640 if (GWL_STYLE
== which
) {
4641 DWORD style_change_mask
;
4643 /* Only a subset of changes can be applied after the control
4646 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4648 if (es
->style
& ES_MULTILINE
)
4649 style_change_mask
|= ES_WANTRETURN
;
4651 new_style
= style
->styleNew
& style_change_mask
;
4653 /* Number overrides lowercase overrides uppercase (at least it
4654 * does in Win95). However I'll bet that ES_NUMBER would be
4655 * invalid under Win 3.1.
4657 if (new_style
& ES_NUMBER
) {
4658 ; /* do not override the ES_NUMBER */
4659 } else if (new_style
& ES_LOWERCASE
) {
4660 new_style
&= ~ES_UPPERCASE
;
4663 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4664 } else if (GWL_EXSTYLE
== which
) {
4665 ; /* FIXME - what is needed here */
4667 WARN ("Invalid style change %d\n",which
);
4673 /*********************************************************************
4678 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4680 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4681 if (EDIT_EM_CanUndo(es
))
4684 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4685 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4688 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4692 /*********************************************************************
4697 static void EDIT_WM_Timer(EDITSTATE
*es
)
4699 if (es
->region_posx
< 0) {
4700 EDIT_MoveBackward(es
, TRUE
);
4701 } else if (es
->region_posx
> 0) {
4702 EDIT_MoveForward(es
, TRUE
);
4705 * FIXME: gotta do some vertical scrolling here, like
4706 * EDIT_EM_LineScroll(hwnd, 0, 1);
4710 /*********************************************************************
4715 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4719 if (!(es
->style
& ES_MULTILINE
))
4722 if (!(es
->style
& ES_AUTOVSCROLL
))
4731 TRACE("action %d\n", action
);
4732 EDIT_EM_Scroll(es
, action
);
4739 TRACE("SB_BOTTOM\n");
4740 dy
= es
->line_count
- 1 - es
->y_offset
;
4743 TRACE("SB_THUMBTRACK %d\n", pos
);
4744 es
->flags
|= EF_VSCROLL_TRACK
;
4745 if(es
->style
& WS_VSCROLL
)
4746 dy
= pos
- es
->y_offset
;
4749 /* Assume default scroll range 0-100 */
4752 if(pos
< 0 || pos
> 100) return 0;
4753 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4754 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4755 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4756 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4757 es
->line_count
, es
->y_offset
, pos
, dy
);
4760 case SB_THUMBPOSITION
:
4761 TRACE("SB_THUMBPOSITION %d\n", pos
);
4762 es
->flags
&= ~EF_VSCROLL_TRACK
;
4763 if(es
->style
& WS_VSCROLL
)
4764 dy
= pos
- es
->y_offset
;
4767 /* Assume default scroll range 0-100 */
4770 if(pos
< 0 || pos
> 100) return 0;
4771 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4772 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4773 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4774 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4775 es
->line_count
, es
->y_offset
, pos
, dy
);
4779 /* force scroll info update */
4780 EDIT_UpdateScrollInfo(es
);
4781 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4785 TRACE("SB_ENDSCROLL\n");
4788 * FIXME : the next two are undocumented !
4789 * Are we doing the right thing ?
4790 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4791 * although it's also a regular control message.
4793 case EM_GETTHUMB
: /* this one is used by NT notepad */
4797 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4798 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4801 /* Assume default scroll range 0-100 */
4802 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4803 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4805 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4808 case EM_LINESCROLL16
:
4809 TRACE("EM_LINESCROLL16 %d\n", pos
);
4814 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4819 EDIT_EM_LineScroll(es
, 0, dy
);
4823 /*********************************************************************
4828 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4830 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4831 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
4835 /*********************************************************************
4840 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4842 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4843 InvalidateRect(es
->hwndSelf
, rc
, bErase
);