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.
51 #include "wine/winbase16.h"
52 #include "wine/winuser16.h"
53 #include "wine/unicode.h"
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
60 WINE_DECLARE_DEBUG_CHANNEL(combo
);
61 WINE_DECLARE_DEBUG_CHANNEL(relay
);
63 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
64 FIXME: BTW, new specs say 65535 (do you dare ???) */
65 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
66 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
67 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
68 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
71 * extra flags for EDITSTATE.flags field
73 #define EF_MODIFIED 0x0001 /* text has been modified */
74 #define EF_FOCUSED 0x0002 /* we have input focus */
75 #define EF_UPDATE 0x0004 /* notify parent of changed state */
76 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
77 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
78 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
79 wrapped line, instead of in front of the next character */
80 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
84 END_0
= 0, /* line ends with terminating '\0' character */
85 END_WRAP
, /* line is wrapped */
86 END_HARD
, /* line ends with a hard return '\r\n' */
87 END_SOFT
, /* line ends with a soft return '\r\r\n' */
88 END_RICH
/* line ends with a single '\n' */
91 typedef struct tagLINEDEF
{
92 INT length
; /* bruto length of a line in bytes */
93 INT net_length
; /* netto length of a line in visible characters */
95 INT width
; /* width of the line in pixels */
96 INT index
; /* line index into the buffer */
97 struct tagLINEDEF
*next
;
102 BOOL is_unicode
; /* how the control was created */
103 LPWSTR text
; /* the actual contents of the control */
104 UINT buffer_size
; /* the size of the buffer in characters */
105 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
106 HFONT font
; /* NULL means standard system font */
107 INT x_offset
; /* scroll offset for multi lines this is in pixels
108 for single lines it's in characters */
109 INT line_height
; /* height of a screen line in pixels */
110 INT char_width
; /* average character width in pixels */
111 DWORD style
; /* sane version of wnd->dwStyle */
112 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
113 INT undo_insert_count
; /* number of characters inserted in sequence */
114 UINT undo_position
; /* character index of the insertion and deletion */
115 LPWSTR undo_text
; /* deleted text */
116 UINT undo_buffer_size
; /* size of the deleted text buffer */
117 INT selection_start
; /* == selection_end if no selection */
118 INT selection_end
; /* == current caret position */
119 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
120 INT left_margin
; /* in pixels */
121 INT right_margin
; /* in pixels */
123 INT text_width
; /* width of the widest line in pixels for multi line controls
124 and just line width for single line controls */
125 INT region_posx
; /* Position of cursor relative to region: */
126 INT region_posy
; /* -1: to left, 0: within, 1: to right */
127 EDITWORDBREAKPROC16 word_break_proc16
;
128 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
129 INT line_count
; /* number of lines */
130 INT y_offset
; /* scroll offset in number of lines */
131 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
132 BOOL bEnableState
; /* flag keeping the enable state */
133 HWND hwndSelf
; /* the our window handle */
134 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
135 Even if parent will change, EN_* messages
136 should be sent to the first parent. */
137 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
139 * only for multi line controls
141 INT lock_count
; /* amount of re-entries in the EditWndProc */
144 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
145 HLOCAL hloc32W
; /* our unicode local memory block */
146 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
148 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
153 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
154 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
156 /* used for disabled or read-only edit control */
157 #define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
159 { /* Notify parent which has created this edit control */ \
160 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
161 SendMessageW(es->hwndParent, WM_COMMAND, \
162 MAKEWPARAM(GetWindowLongW((es->hwndSelf),GWL_ID), wNotifyCode), \
163 (LPARAM)(es->hwndSelf)); \
166 /*********************************************************************
173 * These functions have trivial implementations
174 * We still like to call them internally
175 * "static inline" makes them more like macro's
177 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
178 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
179 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
180 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
183 * Helper functions only valid for one type of control
185 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
186 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
187 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
188 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
190 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
191 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
193 * Helper functions valid for both single line _and_ multi line controls
195 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
196 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
197 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
198 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
199 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
200 static void EDIT_LockBuffer(EDITSTATE
*es
);
201 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
);
202 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
203 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
204 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
205 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
206 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
207 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
208 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
209 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
210 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
211 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
212 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
213 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
214 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
215 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
217 * EM_XXX message handlers
219 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
220 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
221 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
222 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
223 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
);
224 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
225 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
226 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
227 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
228 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
229 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
230 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
231 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
232 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
233 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
234 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
235 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
236 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
237 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
238 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
239 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
240 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
241 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
242 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
243 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
);
244 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
245 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
247 * WM_XXX message handlers
249 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
250 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
251 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
252 static void EDIT_WM_Copy(EDITSTATE
*es
);
253 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
254 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
255 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
256 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
257 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
258 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
259 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
260 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
261 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
262 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
263 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
264 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
265 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
266 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
);
267 static void EDIT_WM_Paste(EDITSTATE
*es
);
268 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
269 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
270 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
271 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
272 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
273 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
274 static void EDIT_WM_Timer(EDITSTATE
*es
);
275 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
276 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
277 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
279 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
280 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
282 /*********************************************************************
283 * edit class descriptor
285 const struct builtin_class_descr EDIT_builtin_class
=
288 CS_DBLCLKS
| CS_PARENTDC
, /* style */
289 EditWndProcA
, /* procA */
290 EditWndProcW
, /* procW */
291 sizeof(EDITSTATE
*), /* extra */
292 IDC_IBEAM
, /* cursor */
297 /*********************************************************************
302 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
304 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
308 /*********************************************************************
313 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
315 es
->undo_insert_count
= 0;
316 *es
->undo_text
= '\0';
320 /*********************************************************************
325 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
327 static const WCHAR empty_stringW
[] = {0};
329 /* Protect read-only edit control from modification */
330 if(es
->style
& ES_READONLY
)
333 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
337 /*********************************************************************
342 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
349 /**********************************************************************
352 * Returns the window version in case Wine emulates a later version
353 * of windows than the application expects.
355 * In a number of cases when windows runs an application that was
356 * designed for an earlier windows version, windows reverts
357 * to "old" behaviour of that earlier version.
359 * An example is a disabled edit control that needs to be painted.
360 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
361 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
362 * applications with an expected version 0f 4.0 or higher.
365 static DWORD
get_app_version(void)
367 static DWORD version
;
370 DWORD dwEmulatedVersion
;
372 DWORD dwProcVersion
= GetProcessVersion(0);
374 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
375 GetVersionExW( &info
);
376 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
377 /* FIXME: this may not be 100% correct; see discussion on the
378 * wine developer list in Nov 1999 */
379 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
385 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
389 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
390 msg
= WM_CTLCOLORSTATIC
;
392 msg
= WM_CTLCOLOREDIT
;
394 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
395 return (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
398 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
401 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
403 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
406 /*********************************************************************
410 * The messages are in the order of the actual integer values
411 * (which can be found in include/windows.h)
412 * Wherever possible the 16 bit versions are converted to
413 * the 32 bit ones, so that we can 'fall through' to the
414 * helper functions. These are mostly 32 bit (with a few
415 * exceptions, clearly indicated by a '16' extension to their
419 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
420 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
422 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongW( hwnd
, 0 );
425 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
427 if (!es
&& msg
!= WM_NCCREATE
)
428 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
429 else if (msg
== WM_NCCREATE
)
430 return EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
431 else if (msg
== WM_DESTROY
)
432 return EDIT_WM_Destroy(es
);
435 if (es
) EDIT_LockBuffer(es
);
443 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
447 if ((short)LOWORD(lParam
) == -1)
448 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
450 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
452 EDIT_EM_ScrollCaret(es
);
456 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
457 EDIT_EM_ScrollCaret(es
);
463 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
467 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
471 if ((es
->style
& ES_MULTILINE
) && lParam
) {
473 CONV_RECT16TO32(MapSL(lParam
), &rc
);
474 EDIT_SetRectNP(es
, &rc
);
475 EDIT_UpdateText(es
, NULL
, TRUE
);
479 if ((es
->style
& ES_MULTILINE
) && lParam
) {
480 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
481 EDIT_UpdateText(es
, NULL
, TRUE
);
486 if ((es
->style
& ES_MULTILINE
) && lParam
) {
488 CONV_RECT16TO32(MapSL(lParam
), &rc
);
489 EDIT_SetRectNP(es
, &rc
);
493 if ((es
->style
& ES_MULTILINE
) && lParam
)
494 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
499 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
502 case EM_LINESCROLL16
:
503 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
504 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
507 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
510 case EM_SCROLLCARET16
:
512 EDIT_EM_ScrollCaret(es
);
518 result
= ((es
->flags
& EF_MODIFIED
) != 0);
524 es
->flags
|= EF_MODIFIED
;
526 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
529 case EM_GETLINECOUNT16
:
530 case EM_GETLINECOUNT
:
531 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
535 if ((INT16
)wParam
== -1)
539 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
543 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
546 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
550 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
553 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
558 result
= EDIT_EM_GetThumb(es
);
561 /* these messages missing from specs */
570 FIXME("undocumented message 0x%x, please report\n", msg
);
571 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
574 case EM_LINELENGTH16
:
576 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
579 case EM_REPLACESEL16
:
580 lParam
= (LPARAM
)MapSL(lParam
);
581 unicode
= FALSE
; /* 16-bit message is always ascii */
588 textW
= (LPWSTR
)lParam
;
591 LPSTR textA
= (LPSTR
)lParam
;
592 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
593 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
594 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
597 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
601 HeapFree(GetProcessHeap(), 0, textW
);
606 lParam
= (LPARAM
)MapSL(lParam
);
607 unicode
= FALSE
; /* 16-bit message is always ascii */
610 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, lParam
, unicode
);
614 case EM_SETLIMITTEXT
:
615 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
620 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
626 result
= (LRESULT
)EDIT_EM_Undo(es
);
631 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
634 case EM_LINEFROMCHAR16
:
635 case EM_LINEFROMCHAR
:
636 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
639 case EM_SETTABSTOPS16
:
640 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
643 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
646 case EM_SETPASSWORDCHAR16
:
647 unicode
= FALSE
; /* 16-bit message is always ascii */
649 case EM_SETPASSWORDCHAR
:
654 charW
= (WCHAR
)wParam
;
658 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
661 EDIT_EM_SetPasswordChar(es
, charW
);
665 case EM_EMPTYUNDOBUFFER16
:
666 case EM_EMPTYUNDOBUFFER
:
667 EDIT_EM_EmptyUndoBuffer(es
);
670 case EM_GETFIRSTVISIBLELINE16
:
671 result
= es
->y_offset
;
673 case EM_GETFIRSTVISIBLELINE
:
674 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
677 case EM_SETREADONLY16
:
680 SetWindowLongW( hwnd
, GWL_STYLE
,
681 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
682 es
->style
|= ES_READONLY
;
684 SetWindowLongW( hwnd
, GWL_STYLE
,
685 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
686 es
->style
&= ~ES_READONLY
;
691 case EM_SETWORDBREAKPROC16
:
692 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
694 case EM_SETWORDBREAKPROC
:
695 EDIT_EM_SetWordBreakProc(es
, lParam
);
698 case EM_GETWORDBREAKPROC16
:
699 result
= (LRESULT
)es
->word_break_proc16
;
701 case EM_GETWORDBREAKPROC
:
702 result
= (LRESULT
)es
->word_break_proc
;
705 case EM_GETPASSWORDCHAR16
:
706 unicode
= FALSE
; /* 16-bit message is always ascii */
708 case EM_GETPASSWORDCHAR
:
711 result
= es
->password_char
;
714 WCHAR charW
= es
->password_char
;
716 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
722 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
725 EDIT_EM_SetMargins(es
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
729 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
732 case EM_GETLIMITTEXT
:
733 result
= es
->buffer_limit
;
737 result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
741 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
744 /* End of the EM_ messages which were in numerical order; what order
745 * are these in? vaguely alphabetical?
749 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
751 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
753 int vk
= (int)((LPMSG
)lParam
)->wParam
;
755 if (vk
== VK_RETURN
&& (GetWindowLongW( hwnd
, GWL_STYLE
) & ES_WANTRETURN
))
757 result
|= DLGC_WANTMESSAGE
;
759 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
761 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
762 result
|= DLGC_WANTMESSAGE
;
773 strng
[0] = wParam
>> 8;
774 strng
[1] = wParam
& 0xff;
775 MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
776 EDIT_WM_Char(es
, charW
);
789 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
792 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
794 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
795 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
798 EDIT_WM_Char(es
, charW
);
807 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
811 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
820 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
823 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
827 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
828 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
829 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
831 result
= EDIT_WM_Create(es
, nameW
);
833 HeapFree(GetProcessHeap(), 0, nameW
);
842 es
->bEnableState
= (BOOL
) wParam
;
843 EDIT_UpdateText(es
, NULL
, TRUE
);
847 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
851 result
= (LRESULT
)es
->font
;
855 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
858 case WM_GETTEXTLENGTH
:
859 if (unicode
) result
= strlenW(es
->text
);
860 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
861 NULL
, 0, NULL
, NULL
);
865 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
869 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
873 result
= EDIT_WM_KillFocus(es
);
876 case WM_LBUTTONDBLCLK
:
877 result
= EDIT_WM_LButtonDblClk(es
);
881 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
885 result
= EDIT_WM_LButtonUp(es
);
889 result
= EDIT_WM_MButtonDown(es
);
892 case WM_MOUSEACTIVATE
:
893 result
= MA_ACTIVATE
;
897 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
901 EDIT_WM_Paint(es
, wParam
);
909 EDIT_WM_SetFocus(es
);
913 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
917 /* FIXME: actually set an internal flag and behave accordingly */
921 EDIT_WM_SetText(es
, lParam
, unicode
);
926 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
929 case WM_STYLECHANGED
:
930 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
933 case WM_STYLECHANGING
:
934 result
= 0; /* See EDIT_WM_StyleChanged */
938 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
946 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
951 int gcWheelDelta
= 0;
952 UINT pulScrollLines
= 3;
953 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
955 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
956 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
959 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
960 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
962 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
963 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
964 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
969 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
973 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
978 /*********************************************************************
980 * EditWndProcW (USER32.@)
982 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
984 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
987 /*********************************************************************
989 * EditWndProc (USER32.@)
991 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
993 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
996 /*********************************************************************
998 * EDIT_BuildLineDefs_ML
1000 * Build linked list of text lines.
1001 * Lines can end with '\0' (last line), a character (if it is wrapped),
1002 * a soft return '\r\r\n' or a hard return '\r\n'
1005 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1009 LPWSTR current_position
, cp
;
1011 LINEDEF
*current_line
;
1012 LINEDEF
*previous_line
;
1013 LINEDEF
*start_line
;
1014 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1015 INT line_count
= es
->line_count
;
1016 INT orig_net_length
;
1019 if (istart
== iend
&& delta
== 0)
1022 dc
= GetDC(es
->hwndSelf
);
1024 old_font
= SelectObject(dc
, es
->font
);
1026 previous_line
= NULL
;
1027 current_line
= es
->first_line_def
;
1029 /* Find starting line. istart must lie inside an existing line or
1030 * at the end of buffer */
1032 if (istart
< current_line
->index
+ current_line
->length
||
1033 current_line
->ending
== END_0
)
1036 previous_line
= current_line
;
1037 current_line
= current_line
->next
;
1039 } while (current_line
);
1041 if (!current_line
) /* Error occurred start is not inside previous buffer */
1043 FIXME(" modification occurred outside buffer\n");
1044 ReleaseDC(es
->hwndSelf
, dc
);
1048 /* Remember start of modifications in order to calculate update region */
1049 nstart_line
= line_index
;
1050 nstart_index
= current_line
->index
;
1052 /* We must start to reformat from the previous line since the modifications
1053 * may have caused the line to wrap upwards. */
1054 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1057 current_line
= previous_line
;
1059 start_line
= current_line
;
1061 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1062 current_position
= es
->text
+ current_line
->index
;
1064 if (current_line
!= start_line
)
1066 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1068 /* The buffer has been expanded, create a new line and
1069 insert it into the link list */
1070 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1071 new_line
->next
= previous_line
->next
;
1072 previous_line
->next
= new_line
;
1073 current_line
= new_line
;
1076 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1078 /* The previous line merged with this line so we delete this extra entry */
1079 previous_line
->next
= current_line
->next
;
1080 HeapFree(GetProcessHeap(), 0, current_line
);
1081 current_line
= previous_line
->next
;
1085 else /* current_line->index + delta == current_position */
1087 if (current_position
- es
->text
> iend
)
1088 break; /* We reached end of line modifications */
1089 /* else recalulate this line */
1093 current_line
->index
= current_position
- es
->text
;
1094 orig_net_length
= current_line
->net_length
;
1096 /* Find end of line */
1097 cp
= current_position
;
1099 if (*cp
== '\n') break;
1100 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1105 /* Mark type of line termination */
1107 current_line
->ending
= END_0
;
1108 current_line
->net_length
= strlenW(current_position
);
1109 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1110 current_line
->ending
= END_SOFT
;
1111 current_line
->net_length
= cp
- current_position
- 1;
1112 } else if (*cp
== '\n') {
1113 current_line
->ending
= END_RICH
;
1114 current_line
->net_length
= cp
- current_position
;
1116 current_line
->ending
= END_HARD
;
1117 current_line
->net_length
= cp
- current_position
;
1120 /* Calculate line width */
1121 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1122 current_position
, current_line
->net_length
,
1123 es
->tabs_count
, es
->tabs
));
1125 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1126 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1131 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1132 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1133 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1134 current_position
, next
, es
->tabs_count
, es
->tabs
));
1135 } while (current_line
->width
<= fw
);
1136 if (!prev
) { /* Didn't find a line break so force a break */
1141 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1142 current_position
, next
, es
->tabs_count
, es
->tabs
));
1143 } while (current_line
->width
<= fw
);
1148 /* If the first line we are calculating, wrapped before istart, we must
1149 * adjust istart in order for this to be reflected in the update region. */
1150 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1151 istart
= current_line
->index
+ prev
;
1152 /* else if we are updating the previous line before the first line we
1153 * are re-calculating and it expanded */
1154 else if (current_line
== start_line
&&
1155 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1157 /* Line expanded due to an upwards line wrap so we must partially include
1158 * previous line in update region */
1159 nstart_line
= line_index
;
1160 nstart_index
= current_line
->index
;
1161 istart
= current_line
->index
+ orig_net_length
;
1164 current_line
->net_length
= prev
;
1165 current_line
->ending
= END_WRAP
;
1166 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1167 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1171 /* Adjust length to include line termination */
1172 switch (current_line
->ending
) {
1174 current_line
->length
= current_line
->net_length
+ 3;
1177 current_line
->length
= current_line
->net_length
+ 1;
1180 current_line
->length
= current_line
->net_length
+ 2;
1184 current_line
->length
= current_line
->net_length
;
1187 es
->text_width
= max(es
->text_width
, current_line
->width
);
1188 current_position
+= current_line
->length
;
1189 previous_line
= current_line
;
1190 current_line
= current_line
->next
;
1192 } while (previous_line
->ending
!= END_0
);
1194 /* Finish adjusting line indexes by delta or remove hanging lines */
1195 if (previous_line
->ending
== END_0
)
1197 LINEDEF
*pnext
= NULL
;
1199 previous_line
->next
= NULL
;
1200 while (current_line
)
1202 pnext
= current_line
->next
;
1203 HeapFree(GetProcessHeap(), 0, current_line
);
1204 current_line
= pnext
;
1210 while (current_line
)
1212 current_line
->index
+= delta
;
1213 current_line
= current_line
->next
;
1217 /* Calculate rest of modification rectangle */
1222 * We calculate two rectangles. One for the first line which may have
1223 * an indent with respect to the format rect. The other is a format-width
1224 * rectangle that spans the rest of the lines that changed or moved.
1226 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1227 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1228 rc
.bottom
= rc
.top
+ es
->line_height
;
1229 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1230 es
->text
+ nstart_index
, istart
- nstart_index
,
1231 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1232 rc
.right
= es
->format_rect
.right
;
1233 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1236 rc
.left
= es
->format_rect
.left
;
1237 rc
.right
= es
->format_rect
.right
;
1239 * If lines were added or removed we must re-paint the remainder of the
1240 * lines since the remaining lines were either shifted up or down.
1242 if (line_count
< es
->line_count
) /* We added lines */
1243 rc
.bottom
= es
->line_count
* es
->line_height
;
1244 else if (line_count
> es
->line_count
) /* We removed lines */
1245 rc
.bottom
= line_count
* es
->line_height
;
1247 rc
.bottom
= line_index
* es
->line_height
;
1248 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1249 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1250 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1251 DeleteObject(tmphrgn
);
1255 SelectObject(dc
, old_font
);
1257 ReleaseDC(es
->hwndSelf
, dc
);
1260 /*********************************************************************
1262 * EDIT_CalcLineWidth_SL
1265 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1267 es
->text_width
= (short)LOWORD(EDIT_EM_PosFromChar(es
, strlenW(es
->text
), FALSE
));
1270 /*********************************************************************
1272 * EDIT_CallWordBreakProc
1274 * Call appropriate WordBreakProc (internal or external).
1276 * Note: The "start" argument should always be an index referring
1277 * to es->text. The actual wordbreak proc might be
1278 * 16 bit, so we can't always pass any 32 bit LPSTR.
1279 * Hence we assume that es->text is the buffer that holds
1280 * the string under examination (we can decide this for ourselves).
1283 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1285 INT ret
, iWndsLocks
;
1287 /* To avoid any deadlocks, all the locks on the window structures
1288 must be suspended before the control is passed to the application */
1289 iWndsLocks
= WIN_SuspendWndsLock();
1291 if (es
->word_break_proc16
) {
1298 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1299 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1300 segptr
= K32WOWGlobalLock16(hglob16
);
1301 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1302 args
[4] = SELECTOROF(segptr
);
1303 args
[3] = OFFSETOF(segptr
);
1307 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1308 ret
= LOWORD(result
);
1309 GlobalUnlock16(hglob16
);
1310 GlobalFree16(hglob16
);
1312 else if (es
->word_break_proc
)
1316 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1318 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1319 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1320 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1324 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1328 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1329 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1330 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1331 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1332 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1333 ret
= wbpA(textA
, index
, countA
, action
);
1334 HeapFree(GetProcessHeap(), 0, textA
);
1338 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1340 WIN_RestoreWndsLock(iWndsLocks
);
1345 /*********************************************************************
1349 * Beware: This is not the function called on EM_CHARFROMPOS
1350 * The position _can_ be outside the formatting / client
1352 * The return value is only the character index
1355 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1361 if (es
->style
& ES_MULTILINE
) {
1362 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1364 LINEDEF
*line_def
= es
->first_line_def
;
1366 while ((line
> 0) && line_def
->next
) {
1367 line_index
+= line_def
->length
;
1368 line_def
= line_def
->next
;
1371 x
+= es
->x_offset
- es
->format_rect
.left
;
1372 if (x
>= line_def
->width
) {
1374 *after_wrap
= (line_def
->ending
== END_WRAP
);
1375 return line_index
+ line_def
->net_length
;
1379 *after_wrap
= FALSE
;
1382 dc
= GetDC(es
->hwndSelf
);
1384 old_font
= SelectObject(dc
, es
->font
);
1385 low
= line_index
+ 1;
1386 high
= line_index
+ line_def
->net_length
+ 1;
1387 while (low
< high
- 1)
1389 INT mid
= (low
+ high
) / 2;
1390 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1396 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1397 (line_def
->ending
== END_WRAP
));
1402 *after_wrap
= FALSE
;
1403 x
-= es
->format_rect
.left
;
1405 return es
->x_offset
;
1406 text
= EDIT_GetPasswordPointer_SL(es
);
1407 dc
= GetDC(es
->hwndSelf
);
1409 old_font
= SelectObject(dc
, es
->font
);
1413 INT high
= es
->x_offset
;
1414 while (low
< high
- 1)
1416 INT mid
= (low
+ high
) / 2;
1417 GetTextExtentPoint32W( dc
, text
+ mid
,
1418 es
->x_offset
- mid
, &size
);
1419 if (size
.cx
> -x
) low
= mid
;
1426 INT low
= es
->x_offset
;
1427 INT high
= strlenW(es
->text
) + 1;
1428 while (low
< high
- 1)
1430 INT mid
= (low
+ high
) / 2;
1431 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1432 mid
- es
->x_offset
, &size
);
1433 if (size
.cx
> x
) high
= mid
;
1438 if (es
->style
& ES_PASSWORD
)
1439 HeapFree(GetProcessHeap(), 0, text
);
1442 SelectObject(dc
, old_font
);
1443 ReleaseDC(es
->hwndSelf
, dc
);
1448 /*********************************************************************
1452 * adjusts the point to be within the formatting rectangle
1453 * (so CharFromPos returns the nearest _visible_ character)
1456 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1458 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1459 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1463 /*********************************************************************
1467 * Calculates the bounding rectangle for a line from a starting
1468 * column to an ending column.
1471 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1473 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1475 if (es
->style
& ES_MULTILINE
)
1476 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1478 rc
->top
= es
->format_rect
.top
;
1479 rc
->bottom
= rc
->top
+ es
->line_height
;
1480 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1481 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1485 /*********************************************************************
1487 * EDIT_GetPasswordPointer_SL
1489 * note: caller should free the (optionally) allocated buffer
1492 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1494 if (es
->style
& ES_PASSWORD
) {
1495 INT len
= strlenW(es
->text
);
1496 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1498 while(len
) text
[--len
] = es
->password_char
;
1505 /*********************************************************************
1509 * This acts as a LOCAL_Lock(), but it locks only once. This way
1510 * you can call it whenever you like, without unlocking.
1512 * Initially the edit control allocates a HLOCAL32 buffer
1513 * (32 bit linear memory handler). However, 16 bit application
1514 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1515 * handler). From that moment on we have to keep using this 16 bit memory
1516 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1517 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1521 static void EDIT_LockBuffer(EDITSTATE
*es
)
1523 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
1527 BOOL _16bit
= FALSE
;
1533 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1534 textA
= LocalLock(es
->hloc32A
);
1535 countA
= strlen(textA
) + 1;
1539 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1540 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1541 countA
= strlen(textA
) + 1;
1546 ERR("no buffer ... please report\n");
1553 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1554 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1555 if(countW_new
> es
->buffer_size
+ 1)
1557 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1558 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1559 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1562 es
->hloc32W
= hloc32W_new
;
1563 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1564 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1567 WARN("FAILED! Will synchronize partially\n");
1571 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1572 es
->text
= LocalLock(es
->hloc32W
);
1576 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1578 LOCAL_Unlock(hInstance
, es
->hloc16
);
1580 LocalUnlock(es
->hloc32A
);
1587 /*********************************************************************
1589 * EDIT_SL_InvalidateText
1591 * Called from EDIT_InvalidateText().
1592 * Does the job for single-line controls only.
1595 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1600 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1601 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1602 EDIT_UpdateText(es
, &rc
, TRUE
);
1606 /*********************************************************************
1608 * EDIT_ML_InvalidateText
1610 * Called from EDIT_InvalidateText().
1611 * Does the job for multi-line controls only.
1614 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1616 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1617 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1618 INT el
= EDIT_EM_LineFromChar(es
, end
);
1627 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1630 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1631 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1632 if (sl
< es
->y_offset
) {
1636 if (el
> es
->y_offset
+ vlc
) {
1637 el
= es
->y_offset
+ vlc
;
1638 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1640 GetClientRect(es
->hwndSelf
, &rc1
);
1641 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1643 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1644 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1645 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1647 EDIT_GetLineRect(es
, sl
, sc
,
1648 EDIT_EM_LineLength(es
,
1649 EDIT_EM_LineIndex(es
, sl
)),
1651 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1652 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1653 for (l
= sl
+ 1 ; l
< el
; l
++) {
1654 EDIT_GetLineRect(es
, l
, 0,
1655 EDIT_EM_LineLength(es
,
1656 EDIT_EM_LineIndex(es
, l
)),
1658 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1659 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1661 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1662 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1663 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1668 /*********************************************************************
1670 * EDIT_InvalidateText
1672 * Invalidate the text from offset start upto, but not including,
1673 * offset end. Useful for (re)painting the selection.
1674 * Regions outside the linewidth are not invalidated.
1675 * end == -1 means end == TextLength.
1676 * start and end need not be ordered.
1679 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1685 end
= strlenW(es
->text
);
1693 if (es
->style
& ES_MULTILINE
)
1694 EDIT_ML_InvalidateText(es
, start
, end
);
1696 EDIT_SL_InvalidateText(es
, start
, end
);
1700 /*********************************************************************
1704 * Try to fit size + 1 characters in the buffer.
1705 * Constrain to limits if honor_limit is TRUE.
1707 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
, BOOL honor_limit
)
1711 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
1712 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
, "EN_MAXTEXT");
1716 if (size
<= es
->buffer_size
)
1719 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1721 /* Force edit to unlock it's buffer. es->text now NULL */
1722 EDIT_UnlockBuffer(es
, TRUE
);
1725 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1726 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1727 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1728 es
->hloc32W
= hNew32W
;
1729 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1733 EDIT_LockBuffer(es
);
1735 if (es
->buffer_size
< size
) {
1736 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1737 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
, "EN_ERRSPACE");
1740 TRACE("We now have %d+1\n", es
->buffer_size
);
1746 /*********************************************************************
1750 * Try to fit size + 1 bytes in the undo buffer.
1753 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1757 if (size
<= es
->undo_buffer_size
)
1760 TRACE("trying to ReAlloc to %d+1\n", size
);
1762 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1763 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1764 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1769 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1775 /*********************************************************************
1780 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1782 INT e
= es
->selection_end
;
1786 if ((es
->style
& ES_MULTILINE
) && e
&&
1787 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1789 if (e
&& (es
->text
[e
- 1] == '\r'))
1793 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1794 EDIT_EM_ScrollCaret(es
);
1798 /*********************************************************************
1802 * Only for multi line controls
1803 * Move the caret one line down, on a column with the nearest
1804 * x coordinate on the screen (might be a different column).
1807 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1809 INT s
= es
->selection_start
;
1810 INT e
= es
->selection_end
;
1811 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1812 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1813 INT x
= (short)LOWORD(pos
);
1814 INT y
= (short)HIWORD(pos
);
1816 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1819 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1820 EDIT_EM_ScrollCaret(es
);
1824 /*********************************************************************
1829 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
1831 BOOL after_wrap
= FALSE
;
1834 /* Pass a high value in x to make sure of receiving the end of the line */
1835 if (es
->style
& ES_MULTILINE
)
1836 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1837 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1839 e
= strlenW(es
->text
);
1840 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1841 EDIT_EM_ScrollCaret(es
);
1845 /*********************************************************************
1850 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1852 INT e
= es
->selection_end
;
1856 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1857 if (es
->text
[e
] == '\n')
1859 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1863 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1864 EDIT_EM_ScrollCaret(es
);
1868 /*********************************************************************
1872 * Home key: move to beginning of line.
1875 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
1879 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1880 if (es
->style
& ES_MULTILINE
)
1881 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1882 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1885 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1886 EDIT_EM_ScrollCaret(es
);
1890 /*********************************************************************
1892 * EDIT_MovePageDown_ML
1894 * Only for multi line controls
1895 * Move the caret one page down, on a column with the nearest
1896 * x coordinate on the screen (might be a different column).
1899 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1901 INT s
= es
->selection_start
;
1902 INT e
= es
->selection_end
;
1903 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1904 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1905 INT x
= (short)LOWORD(pos
);
1906 INT y
= (short)HIWORD(pos
);
1908 e
= EDIT_CharFromPos(es
, x
,
1909 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1913 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1914 EDIT_EM_ScrollCaret(es
);
1918 /*********************************************************************
1920 * EDIT_MovePageUp_ML
1922 * Only for multi line controls
1923 * Move the caret one page up, on a column with the nearest
1924 * x coordinate on the screen (might be a different column).
1927 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1929 INT s
= es
->selection_start
;
1930 INT e
= es
->selection_end
;
1931 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1932 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1933 INT x
= (short)LOWORD(pos
);
1934 INT y
= (short)HIWORD(pos
);
1936 e
= EDIT_CharFromPos(es
, x
,
1937 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1941 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1942 EDIT_EM_ScrollCaret(es
);
1946 /*********************************************************************
1950 * Only for multi line controls
1951 * Move the caret one line up, on a column with the nearest
1952 * x coordinate on the screen (might be a different column).
1955 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1957 INT s
= es
->selection_start
;
1958 INT e
= es
->selection_end
;
1959 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1960 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1961 INT x
= (short)LOWORD(pos
);
1962 INT y
= (short)HIWORD(pos
);
1964 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1967 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1968 EDIT_EM_ScrollCaret(es
);
1972 /*********************************************************************
1974 * EDIT_MoveWordBackward
1977 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1979 INT s
= es
->selection_start
;
1980 INT e
= es
->selection_end
;
1985 l
= EDIT_EM_LineFromChar(es
, e
);
1986 ll
= EDIT_EM_LineLength(es
, e
);
1987 li
= EDIT_EM_LineIndex(es
, l
);
1990 li
= EDIT_EM_LineIndex(es
, l
- 1);
1991 e
= li
+ EDIT_EM_LineLength(es
, li
);
1994 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
1995 li
, e
- li
, ll
, WB_LEFT
);
1999 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2000 EDIT_EM_ScrollCaret(es
);
2004 /*********************************************************************
2006 * EDIT_MoveWordForward
2009 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2011 INT s
= es
->selection_start
;
2012 INT e
= es
->selection_end
;
2017 l
= EDIT_EM_LineFromChar(es
, e
);
2018 ll
= EDIT_EM_LineLength(es
, e
);
2019 li
= EDIT_EM_LineIndex(es
, l
);
2021 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2022 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2024 e
= li
+ EDIT_CallWordBreakProc(es
,
2025 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2029 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2030 EDIT_EM_ScrollCaret(es
);
2034 /*********************************************************************
2039 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2041 INT s
= es
->selection_start
;
2042 INT e
= es
->selection_end
;
2049 if (es
->style
& ES_MULTILINE
) {
2050 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2051 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2056 TRACE("line=%d\n", line
);
2058 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2059 x
= (short)LOWORD(pos
);
2060 y
= (short)HIWORD(pos
);
2061 li
= EDIT_EM_LineIndex(es
, line
);
2062 ll
= EDIT_EM_LineLength(es
, li
);
2063 s
= min(es
->selection_start
, es
->selection_end
);
2064 e
= max(es
->selection_start
, es
->selection_end
);
2065 s
= min(li
+ ll
, max(li
, s
));
2066 e
= min(li
+ ll
, max(li
, e
));
2067 if (rev
&& (s
!= e
) &&
2068 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2069 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2070 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2071 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2073 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2077 /*********************************************************************
2082 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2093 BkMode
= GetBkMode(dc
);
2094 BkColor
= GetBkColor(dc
);
2095 TextColor
= GetTextColor(dc
);
2097 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2098 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2099 SetBkMode( dc
, OPAQUE
);
2101 li
= EDIT_EM_LineIndex(es
, line
);
2102 if (es
->style
& ES_MULTILINE
) {
2103 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2104 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2106 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2107 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2108 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2110 if (es
->style
& ES_PASSWORD
)
2111 HeapFree(GetProcessHeap(), 0, text
);
2114 SetBkColor(dc
, BkColor
);
2115 SetTextColor(dc
, TextColor
);
2116 SetBkMode( dc
, BkMode
);
2122 /*********************************************************************
2127 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2130 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2131 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2135 /*********************************************************************
2139 * note: this is not (exactly) the handler called on EM_SETRECTNP
2140 * it is also used to set the rect of a single line control
2143 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2145 CopyRect(&es
->format_rect
, rc
);
2146 if (es
->style
& WS_BORDER
) {
2147 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2148 if(TWEAK_WineLook
== WIN31_LOOK
)
2150 es
->format_rect
.left
+= bw
;
2151 es
->format_rect
.top
+= bw
;
2152 es
->format_rect
.right
-= bw
;
2153 es
->format_rect
.bottom
-= bw
;
2155 es
->format_rect
.left
+= es
->left_margin
;
2156 es
->format_rect
.right
-= es
->right_margin
;
2157 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2158 if (es
->style
& ES_MULTILINE
)
2160 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2162 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2163 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2165 /* correct es->x_offset */
2166 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2167 max_x_offset
= es
->text_width
- fw
;
2168 if(max_x_offset
< 0) max_x_offset
= 0;
2169 if(es
->x_offset
> max_x_offset
)
2170 es
->x_offset
= max_x_offset
;
2172 /* correct es->y_offset */
2173 max_y_offset
= es
->line_count
- vlc
;
2174 if(max_y_offset
< 0) max_y_offset
= 0;
2175 if(es
->y_offset
> max_y_offset
)
2176 es
->y_offset
= max_y_offset
;
2178 /* force scroll info update */
2179 EDIT_UpdateScrollInfo(es
);
2182 /* Windows doesn't care to fix text placement for SL controls */
2183 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2185 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2186 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2190 /*********************************************************************
2195 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2197 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2199 /* Edit window might be already destroyed */
2200 if(!IsWindow(es
->hwndSelf
))
2202 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2206 if (!es
->lock_count
) {
2207 ERR("lock_count == 0 ... please report\n");
2211 ERR("es->text == 0 ... please report\n");
2215 if (force
|| (es
->lock_count
== 1)) {
2218 BOOL _16bit
= FALSE
;
2220 UINT countW
= strlenW(es
->text
) + 1;
2224 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2225 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2226 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2227 countA
= LocalSize(es
->hloc32A
);
2228 if(countA_new
> countA
)
2231 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2232 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2233 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2236 es
->hloc32A
= hloc32A_new
;
2237 countA
= LocalSize(hloc32A_new
);
2238 TRACE("Real new size %d bytes\n", countA
);
2241 WARN("FAILED! Will synchronize partially\n");
2243 textA
= LocalLock(es
->hloc32A
);
2247 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2248 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2249 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2250 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2251 if(countA_new
> countA
)
2253 HLOCAL16 hloc16_new
;
2254 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2255 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2256 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2259 es
->hloc16
= hloc16_new
;
2260 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2261 TRACE("Real new size %d bytes\n", countA
);
2264 WARN("FAILED! Will synchronize partially\n");
2266 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2272 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2274 LOCAL_Unlock(hInstance
, es
->hloc16
);
2276 LocalUnlock(es
->hloc32A
);
2279 LocalUnlock(es
->hloc32W
);
2283 ERR("no buffer ... please report\n");
2291 /*********************************************************************
2293 * EDIT_UpdateScrollInfo
2296 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2298 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2301 si
.cbSize
= sizeof(SCROLLINFO
);
2302 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2304 si
.nMax
= es
->line_count
- 1;
2305 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2306 si
.nPos
= es
->y_offset
;
2307 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2308 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2309 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2312 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2315 si
.cbSize
= sizeof(SCROLLINFO
);
2316 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2318 si
.nMax
= es
->text_width
- 1;
2319 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2320 si
.nPos
= es
->x_offset
;
2321 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2322 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2323 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2327 /*********************************************************************
2329 * EDIT_WordBreakProc
2331 * Find the beginning of words.
2332 * Note: unlike the specs for a WordBreakProc, this function only
2333 * allows to be called without linebreaks between s[0] upto
2334 * s[count - 1]. Remember it is only called
2335 * internally, so we can decide this for ourselves.
2338 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2342 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2352 if (s
[index
] == ' ') {
2353 while (index
&& (s
[index
] == ' '))
2356 while (index
&& (s
[index
] != ' '))
2358 if (s
[index
] == ' ')
2362 while (index
&& (s
[index
] != ' '))
2364 if (s
[index
] == ' ')
2374 if (s
[index
] == ' ')
2375 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2377 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2379 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2383 case WB_ISDELIMITER
:
2384 ret
= (s
[index
] == ' ');
2387 ERR("unknown action code, please report !\n");
2394 /*********************************************************************
2398 * returns line number (not index) in high-order word of result.
2399 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2400 * to Richedit, not to the edit control. Original documentation is valid.
2401 * FIXME: do the specs mean to return -1 if outside client area or
2402 * if outside formatting rectangle ???
2405 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2413 GetClientRect(es
->hwndSelf
, &rc
);
2414 if (!PtInRect(&rc
, pt
))
2417 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2418 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2422 /*********************************************************************
2426 * Enable or disable soft breaks.
2428 * This means: insert or remove the soft linebreak character (\r\r\n).
2429 * Take care to check if the text still fits the buffer after insertion.
2430 * If not, notify with EN_ERRSPACE.
2433 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2435 es
->flags
&= ~EF_USE_SOFTBRK
;
2437 es
->flags
|= EF_USE_SOFTBRK
;
2438 FIXME("soft break enabled, not implemented\n");
2444 /*********************************************************************
2448 * Hopefully this won't fire back at us.
2449 * We always start with a fixed buffer in the local heap.
2450 * Despite of the documentation says that the local heap is used
2451 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2452 * buffer on the local heap.
2455 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2459 if (!(es
->style
& ES_MULTILINE
))
2463 hLocal
= es
->hloc32W
;
2469 UINT countA
, alloc_size
;
2470 TRACE("Allocating 32-bit ANSI alias buffer\n");
2471 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2472 alloc_size
= ROUND_TO_GROW(countA
);
2473 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2475 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2478 textA
= LocalLock(es
->hloc32A
);
2479 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2480 LocalUnlock(es
->hloc32A
);
2482 hLocal
= es
->hloc32A
;
2485 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2490 /*********************************************************************
2494 * Hopefully this won't fire back at us.
2495 * We always start with a buffer in 32 bit linear memory.
2496 * However, with this message a 16 bit application requests
2497 * a handle of 16 bit local heap memory, where it expects to find
2499 * It's a pitty that from this moment on we have to use this
2500 * local heap, because applications may rely on the handle
2503 * In this function we'll try to switch to local heap.
2505 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2507 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
2509 UINT countA
, alloc_size
;
2511 if (!(es
->style
& ES_MULTILINE
))
2517 if (!LOCAL_HeapSize(hInstance
)) {
2518 if (!LocalInit16(hInstance
, 0,
2519 GlobalSize16(hInstance
))) {
2520 ERR("could not initialize local heap\n");
2523 TRACE("local heap initialized\n");
2526 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2527 alloc_size
= ROUND_TO_GROW(countA
);
2529 TRACE("Allocating 16-bit ANSI alias buffer\n");
2530 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2531 ERR("could not allocate new 16 bit buffer\n");
2535 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2536 ERR("could not lock new 16 bit buffer\n");
2537 LOCAL_Free(hInstance
, es
->hloc16
);
2542 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2543 LOCAL_Unlock(hInstance
, es
->hloc16
);
2545 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2550 /*********************************************************************
2555 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2558 INT line_len
, dst_len
;
2561 if (es
->style
& ES_MULTILINE
) {
2562 if (line
>= es
->line_count
)
2566 i
= EDIT_EM_LineIndex(es
, line
);
2568 line_len
= EDIT_EM_LineLength(es
, i
);
2569 dst_len
= *(WORD
*)lParam
;
2572 LPWSTR dst
= (LPWSTR
)lParam
;
2573 if(dst_len
<= line_len
)
2575 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2578 else /* Append 0 if enough space */
2580 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2587 LPSTR dst
= (LPSTR
)lParam
;
2589 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2590 if(!ret
) /* Insufficient buffer size */
2592 if(ret
< dst_len
) /* Append 0 if enough space */
2599 /*********************************************************************
2604 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2606 UINT s
= es
->selection_start
;
2607 UINT e
= es
->selection_end
;
2614 return MAKELONG(s
, e
);
2618 /*********************************************************************
2622 * FIXME: is this right ? (or should it be only VSCROLL)
2623 * (and maybe only for edit controls that really have their
2624 * own scrollbars) (and maybe only for multiline controls ?)
2625 * All in all: very poorly documented
2628 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2630 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2631 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2635 /*********************************************************************
2640 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2645 if (!(es
->style
& ES_MULTILINE
))
2647 if (index
> (INT
)strlenW(es
->text
))
2648 return es
->line_count
- 1;
2650 index
= min(es
->selection_start
, es
->selection_end
);
2653 line_def
= es
->first_line_def
;
2654 index
-= line_def
->length
;
2655 while ((index
>= 0) && line_def
->next
) {
2657 line_def
= line_def
->next
;
2658 index
-= line_def
->length
;
2664 /*********************************************************************
2669 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2674 if (!(es
->style
& ES_MULTILINE
))
2676 if (line
>= es
->line_count
)
2680 line_def
= es
->first_line_def
;
2682 INT index
= es
->selection_end
- line_def
->length
;
2683 while ((index
>= 0) && line_def
->next
) {
2684 line_index
+= line_def
->length
;
2685 line_def
= line_def
->next
;
2686 index
-= line_def
->length
;
2690 line_index
+= line_def
->length
;
2691 line_def
= line_def
->next
;
2699 /*********************************************************************
2704 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2708 if (!(es
->style
& ES_MULTILINE
))
2709 return strlenW(es
->text
);
2712 /* get the number of remaining non-selected chars of selected lines */
2713 INT32 l
; /* line number */
2714 INT32 li
; /* index of first char in line */
2716 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2717 /* # chars before start of selection area */
2718 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2719 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2720 /* # chars after end of selection */
2721 li
= EDIT_EM_LineIndex(es
, l
);
2722 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2725 line_def
= es
->first_line_def
;
2726 index
-= line_def
->length
;
2727 while ((index
>= 0) && line_def
->next
) {
2728 line_def
= line_def
->next
;
2729 index
-= line_def
->length
;
2731 return line_def
->net_length
;
2735 /*********************************************************************
2739 * NOTE: dx is in average character widths, dy - in lines;
2742 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
2744 if (!(es
->style
& ES_MULTILINE
))
2747 dx
*= es
->char_width
;
2748 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
2751 /*********************************************************************
2753 * EDIT_EM_LineScroll_internal
2755 * Version of EDIT_EM_LineScroll for internal use.
2756 * It doesn't refuse if ES_MULTILINE is set and assumes that
2757 * dx is in pixels, dy - in lines.
2760 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
2763 INT x_offset_in_pixels
;
2765 if (es
->style
& ES_MULTILINE
)
2767 x_offset_in_pixels
= es
->x_offset
;
2772 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
2775 if (-dx
> x_offset_in_pixels
)
2776 dx
= -x_offset_in_pixels
;
2777 if (dx
> es
->text_width
- x_offset_in_pixels
)
2778 dx
= es
->text_width
- x_offset_in_pixels
;
2779 nyoff
= max(0, es
->y_offset
+ dy
);
2780 if (nyoff
>= es
->line_count
)
2781 nyoff
= es
->line_count
- 1;
2782 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2787 es
->y_offset
= nyoff
;
2788 if(es
->style
& ES_MULTILINE
)
2791 es
->x_offset
+= dx
/ es
->char_width
;
2793 GetClientRect(es
->hwndSelf
, &rc1
);
2794 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2795 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
2796 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
2797 /* force scroll info update */
2798 EDIT_UpdateScrollInfo(es
);
2800 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2801 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
2802 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2803 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
2808 /*********************************************************************
2813 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2815 INT len
= strlenW(es
->text
);
2824 index
= min(index
, len
);
2825 dc
= GetDC(es
->hwndSelf
);
2827 old_font
= SelectObject(dc
, es
->font
);
2828 if (es
->style
& ES_MULTILINE
) {
2829 l
= EDIT_EM_LineFromChar(es
, index
);
2830 y
= (l
- es
->y_offset
) * es
->line_height
;
2831 li
= EDIT_EM_LineIndex(es
, l
);
2832 if (after_wrap
&& (li
== index
) && l
) {
2834 LINEDEF
*line_def
= es
->first_line_def
;
2836 line_def
= line_def
->next
;
2839 if (line_def
->ending
== END_WRAP
) {
2841 y
-= es
->line_height
;
2842 li
= EDIT_EM_LineIndex(es
, l
);
2845 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2846 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2848 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2849 if (index
< es
->x_offset
) {
2850 GetTextExtentPoint32W(dc
, text
+ index
,
2851 es
->x_offset
- index
, &size
);
2854 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2855 index
- es
->x_offset
, &size
);
2859 if (es
->style
& ES_PASSWORD
)
2860 HeapFree(GetProcessHeap(), 0, text
);
2862 x
+= es
->format_rect
.left
;
2863 y
+= es
->format_rect
.top
;
2865 SelectObject(dc
, old_font
);
2866 ReleaseDC(es
->hwndSelf
, dc
);
2867 return MAKELONG((INT16
)x
, (INT16
)y
);
2871 /*********************************************************************
2875 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2878 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2880 UINT strl
= strlenW(lpsz_replace
);
2881 UINT tl
= strlenW(es
->text
);
2889 TRACE("%s, can_undo %d, send_update %d\n",
2890 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2892 s
= es
->selection_start
;
2893 e
= es
->selection_end
;
2895 if ((s
== e
) && !strl
)
2900 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
, honor_limit
))
2904 /* there is something to be deleted */
2905 TRACE("deleting stuff.\n");
2907 utl
= strlenW(es
->undo_text
);
2908 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2909 /* undo-buffer is extended to the right */
2910 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2911 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2912 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2913 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2914 /* undo-buffer is extended to the left */
2915 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2916 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2918 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2919 p
[i
] = (es
->text
+ s
)[i
];
2920 es
->undo_position
= s
;
2922 /* new undo-buffer */
2923 EDIT_MakeUndoFit(es
, e
- s
);
2924 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2925 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2926 es
->undo_position
= s
;
2928 /* any deletion makes the old insertion-undo invalid */
2929 es
->undo_insert_count
= 0;
2931 EDIT_EM_EmptyUndoBuffer(es
);
2934 strcpyW(es
->text
+ s
, es
->text
+ e
);
2937 /* there is an insertion */
2939 if ((s
== es
->undo_position
) ||
2940 ((es
->undo_insert_count
) &&
2941 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2943 * insertion is new and at delete position or
2944 * an extension to either left or right
2946 es
->undo_insert_count
+= strl
;
2948 /* new insertion undo */
2949 es
->undo_position
= s
;
2950 es
->undo_insert_count
= strl
;
2951 /* new insertion makes old delete-buffer invalid */
2952 *es
->undo_text
= '\0';
2955 EDIT_EM_EmptyUndoBuffer(es
);
2958 tl
= strlenW(es
->text
);
2959 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
));
2960 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2962 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2963 p
[i
] = lpsz_replace
[i
];
2964 if(es
->style
& ES_UPPERCASE
)
2965 CharUpperBuffW(p
, strl
);
2966 else if(es
->style
& ES_LOWERCASE
)
2967 CharLowerBuffW(p
, strl
);
2970 if (es
->style
& ES_MULTILINE
)
2972 INT s
= min(es
->selection_start
, es
->selection_end
);
2974 hrgn
= CreateRectRgn(0, 0, 0, 0);
2975 EDIT_BuildLineDefs_ML(es
, s
, s
+ strl
,
2976 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2979 EDIT_CalcLineWidth_SL(es
);
2981 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2982 es
->flags
|= EF_MODIFIED
;
2983 if (send_update
) es
->flags
|= EF_UPDATE
;
2986 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2990 EDIT_UpdateText(es
, NULL
, TRUE
);
2992 EDIT_EM_ScrollCaret(es
);
2994 /* force scroll info update */
2995 EDIT_UpdateScrollInfo(es
);
2998 if(es
->flags
& EF_UPDATE
)
3000 es
->flags
&= ~EF_UPDATE
;
3001 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3006 /*********************************************************************
3011 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3015 if (!(es
->style
& ES_MULTILINE
))
3016 return (LRESULT
)FALSE
;
3026 if (es
->y_offset
< es
->line_count
- 1)
3031 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3034 if (es
->y_offset
< es
->line_count
- 1)
3035 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3038 return (LRESULT
)FALSE
;
3041 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3042 /* check if we are going to move too far */
3043 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3044 dy
= es
->line_count
- vlc
- es
->y_offset
;
3046 /* Notification is done in EDIT_EM_LineScroll */
3048 EDIT_EM_LineScroll(es
, 0, dy
);
3050 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3054 /*********************************************************************
3059 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3061 if (es
->style
& ES_MULTILINE
) {
3066 INT cw
= es
->char_width
;
3071 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3072 li
= EDIT_EM_LineIndex(es
, l
);
3073 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3074 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3075 if (l
>= es
->y_offset
+ vlc
)
3076 dy
= l
- vlc
+ 1 - es
->y_offset
;
3077 if (l
< es
->y_offset
)
3078 dy
= l
- es
->y_offset
;
3079 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3080 if (x
< es
->format_rect
.left
)
3081 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3082 if (x
> es
->format_rect
.right
)
3083 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3086 /* check if we are going to move too far */
3087 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3088 dx
= es
->text_width
- ww
- es
->x_offset
;
3090 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3097 if (!(es
->style
& ES_AUTOHSCROLL
))
3100 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3101 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3102 if (x
< es
->format_rect
.left
) {
3103 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3106 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3107 } while ((x
< goal
) && es
->x_offset
);
3108 /* FIXME: use ScrollWindow() somehow to improve performance */
3109 EDIT_UpdateText(es
, NULL
, TRUE
);
3110 } else if (x
> es
->format_rect
.right
) {
3112 INT len
= strlenW(es
->text
);
3113 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3116 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3117 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3118 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3119 /* FIXME: use ScrollWindow() somehow to improve performance */
3120 EDIT_UpdateText(es
, NULL
, TRUE
);
3124 if(es
->flags
& EF_FOCUSED
)
3125 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3129 /*********************************************************************
3133 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3136 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3138 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3140 if (!(es
->style
& ES_MULTILINE
))
3144 WARN("called with NULL handle\n");
3148 EDIT_UnlockBuffer(es
, TRUE
);
3152 LOCAL_Free(hInstance
, es
->hloc16
);
3153 es
->hloc16
= (HLOCAL16
)NULL
;
3160 LocalFree(es
->hloc32A
);
3172 countA
= LocalSize(hloc
);
3173 textA
= LocalLock(hloc
);
3174 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3175 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3177 ERR("Could not allocate new unicode buffer\n");
3180 textW
= LocalLock(hloc32W_new
);
3181 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3182 LocalUnlock(hloc32W_new
);
3186 LocalFree(es
->hloc32W
);
3188 es
->hloc32W
= hloc32W_new
;
3192 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3194 EDIT_LockBuffer(es
);
3196 es
->x_offset
= es
->y_offset
= 0;
3197 es
->selection_start
= es
->selection_end
= 0;
3198 EDIT_EM_EmptyUndoBuffer(es
);
3199 es
->flags
&= ~EF_MODIFIED
;
3200 es
->flags
&= ~EF_UPDATE
;
3201 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3202 EDIT_UpdateText(es
, NULL
, TRUE
);
3203 EDIT_EM_ScrollCaret(es
);
3204 /* force scroll info update */
3205 EDIT_UpdateScrollInfo(es
);
3209 /*********************************************************************
3213 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3216 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3218 HINSTANCE16 hInstance
= GetWindowLongW( es
->hwndSelf
, GWL_HINSTANCE
);
3224 if (!(es
->style
& ES_MULTILINE
))
3228 WARN("called with NULL handle\n");
3232 EDIT_UnlockBuffer(es
, TRUE
);
3236 LocalFree(es
->hloc32A
);
3240 countA
= LOCAL_Size(hInstance
, hloc
);
3241 textA
= LOCAL_Lock(hInstance
, hloc
);
3242 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3243 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3245 ERR("Could not allocate new unicode buffer\n");
3248 textW
= LocalLock(hloc32W_new
);
3249 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3250 LocalUnlock(hloc32W_new
);
3251 LOCAL_Unlock(hInstance
, hloc
);
3254 LocalFree(es
->hloc32W
);
3256 es
->hloc32W
= hloc32W_new
;
3259 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3261 EDIT_LockBuffer(es
);
3263 es
->x_offset
= es
->y_offset
= 0;
3264 es
->selection_start
= es
->selection_end
= 0;
3265 EDIT_EM_EmptyUndoBuffer(es
);
3266 es
->flags
&= ~EF_MODIFIED
;
3267 es
->flags
&= ~EF_UPDATE
;
3268 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3269 EDIT_UpdateText(es
, NULL
, TRUE
);
3270 EDIT_EM_ScrollCaret(es
);
3271 /* force scroll info update */
3272 EDIT_UpdateScrollInfo(es
);
3276 /*********************************************************************
3280 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3281 * However, the windows version is not complied to yet in all of edit.c
3283 * Additionally as the wrapper for RichEdit controls we need larger buffers
3284 * at present -1 will represent nolimit
3286 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3288 if (limit
== 0xFFFFFFFF)
3289 es
->buffer_limit
= -1;
3290 else if (es
->style
& ES_MULTILINE
) {
3292 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3294 es
->buffer_limit
= BUFLIMIT_MULTI
;
3297 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3299 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3304 /*********************************************************************
3308 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3309 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3310 * margin according to the textmetrics of the current font.
3312 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3313 * of the char's width as the margin, but this is not how Windows handles this.
3314 * For all other fonts Windows sets the margins to zero.
3317 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3318 INT left
, INT right
)
3321 INT default_left_margin
= 0; /* in pixels */
3322 INT default_right_margin
= 0; /* in pixels */
3324 /* Set the default margins depending on the font */
3325 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3326 HDC dc
= GetDC(es
->hwndSelf
);
3327 HFONT old_font
= SelectObject(dc
, es
->font
);
3328 GetTextMetricsW(dc
, &tm
);
3329 /* The default margins are only non zero for TrueType or Vector fonts */
3330 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3331 /* This must be calculated more exactly! But how? */
3332 default_left_margin
= tm
.tmAveCharWidth
/ 3;
3333 default_right_margin
= tm
.tmAveCharWidth
/ 3;
3335 SelectObject(dc
, old_font
);
3336 ReleaseDC(es
->hwndSelf
, dc
);
3339 if (action
& EC_LEFTMARGIN
) {
3340 if (left
!= EC_USEFONTINFO
)
3341 es
->left_margin
= left
;
3343 es
->left_margin
= default_left_margin
;
3346 if (action
& EC_RIGHTMARGIN
) {
3347 if (right
!= EC_USEFONTINFO
)
3348 es
->right_margin
= right
;
3350 es
->right_margin
= default_right_margin
;
3352 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3356 /*********************************************************************
3358 * EM_SETPASSWORDCHAR
3361 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3365 if (es
->style
& ES_MULTILINE
)
3368 if (es
->password_char
== c
)
3371 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3372 es
->password_char
= c
;
3374 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3375 es
->style
|= ES_PASSWORD
;
3377 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3378 es
->style
&= ~ES_PASSWORD
;
3380 EDIT_UpdateText(es
, NULL
, TRUE
);
3384 /*********************************************************************
3388 * note: unlike the specs say: the order of start and end
3389 * _is_ preserved in Windows. (i.e. start can be > end)
3390 * In other words: this handler is OK
3393 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3395 UINT old_start
= es
->selection_start
;
3396 UINT old_end
= es
->selection_end
;
3397 UINT len
= strlenW(es
->text
);
3399 if (start
== (UINT
)-1) {
3400 start
= es
->selection_end
;
3401 end
= es
->selection_end
;
3403 start
= min(start
, len
);
3404 end
= min(end
, len
);
3406 es
->selection_start
= start
;
3407 es
->selection_end
= end
;
3409 es
->flags
|= EF_AFTER_WRAP
;
3411 es
->flags
&= ~EF_AFTER_WRAP
;
3412 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3413 ORDER_UINT(start
, end
);
3414 ORDER_UINT(end
, old_end
);
3415 ORDER_UINT(start
, old_start
);
3416 ORDER_UINT(old_start
, old_end
);
3417 if (end
!= old_start
)
3421 * ORDER_UINT32(end, old_start);
3422 * EDIT_InvalidateText(es, start, end);
3423 * EDIT_InvalidateText(es, old_start, old_end);
3424 * in place of the following if statement.
3426 if (old_start
> end
)
3428 EDIT_InvalidateText(es
, start
, end
);
3429 EDIT_InvalidateText(es
, old_start
, old_end
);
3433 EDIT_InvalidateText(es
, start
, old_start
);
3434 EDIT_InvalidateText(es
, end
, old_end
);
3437 else EDIT_InvalidateText(es
, start
, old_end
);
3441 /*********************************************************************
3446 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3448 if (!(es
->style
& ES_MULTILINE
))
3451 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3452 es
->tabs_count
= count
;
3456 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3457 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3463 /*********************************************************************
3468 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3470 if (!(es
->style
& ES_MULTILINE
))
3473 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3474 es
->tabs_count
= count
;
3479 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3480 for (i
= 0 ; i
< count
; i
++)
3481 es
->tabs
[i
] = *tabs
++;
3487 /*********************************************************************
3489 * EM_SETWORDBREAKPROC
3492 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, LPARAM lParam
)
3494 if (es
->word_break_proc
== (void *)lParam
)
3497 es
->word_break_proc
= (void *)lParam
;
3498 es
->word_break_proc16
= NULL
;
3500 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3501 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3502 EDIT_UpdateText(es
, NULL
, TRUE
);
3507 /*********************************************************************
3509 * EM_SETWORDBREAKPROC16
3512 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3514 if (es
->word_break_proc16
== wbp
)
3517 es
->word_break_proc
= NULL
;
3518 es
->word_break_proc16
= wbp
;
3519 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3520 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3521 EDIT_UpdateText(es
, NULL
, TRUE
);
3526 /*********************************************************************
3531 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3536 /* Protect read-only edit control from modification */
3537 if(es
->style
& ES_READONLY
)
3540 ulength
= strlenW(es
->undo_text
);
3541 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3543 strcpyW(utext
, es
->undo_text
);
3545 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3546 es
->undo_insert_count
, debugstr_w(utext
));
3548 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3549 EDIT_EM_EmptyUndoBuffer(es
);
3550 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, FALSE
, TRUE
);
3551 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3552 /* send the notification after the selection start and end are set */
3553 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
3554 EDIT_EM_ScrollCaret(es
);
3555 HeapFree(GetProcessHeap(), 0, utext
);
3557 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3558 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3563 /*********************************************************************
3568 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3572 /* Protect read-only edit control from modification */
3573 if(es
->style
& ES_READONLY
)
3576 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3580 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3581 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3584 if (es
->style
& ES_MULTILINE
) {
3585 if (es
->style
& ES_READONLY
) {
3586 EDIT_MoveHome(es
, FALSE
);
3587 EDIT_MoveDown_ML(es
, FALSE
);
3589 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3590 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3595 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3597 static const WCHAR tabW
[] = {'\t',0};
3598 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3602 if (!(es
->style
& ES_READONLY
) && !control
) {
3603 if (es
->selection_start
!= es
->selection_end
)
3606 /* delete character left of caret */
3607 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3608 EDIT_MoveBackward(es
, TRUE
);
3614 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3617 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3620 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3624 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3628 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3635 /*********************************************************************
3640 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3642 if (code
|| control
)
3662 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3663 EDIT_EM_ScrollCaret(es
);
3666 ERR("unknown menu item, please report\n");
3672 /*********************************************************************
3676 * Note: the resource files resource/sysres_??.rc cannot define a
3677 * single popup menu. Hence we use a (dummy) menubar
3678 * containing the single popup menu as its first item.
3680 * FIXME: the message identifiers have been chosen arbitrarily,
3681 * hence we use MF_BYPOSITION.
3682 * We might as well use the "real" values (anybody knows ?)
3683 * The menu definition is in resources/sysres_??.rc.
3684 * Once these are OK, we better use MF_BYCOMMAND here
3685 * (as we do in EDIT_WM_Command()).
3688 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3690 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3691 HMENU popup
= GetSubMenu(menu
, 0);
3692 UINT start
= es
->selection_start
;
3693 UINT end
= es
->selection_end
;
3695 ORDER_UINT(start
, end
);
3698 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3700 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3702 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3704 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3706 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3708 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3710 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3715 /*********************************************************************
3720 static void EDIT_WM_Copy(EDITSTATE
*es
)
3722 INT s
= min(es
->selection_start
, es
->selection_end
);
3723 INT e
= max(es
->selection_start
, es
->selection_end
);
3729 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3730 dst
= GlobalLock(hdst
);
3731 strncpyW(dst
, es
->text
+ s
, e
- s
);
3732 dst
[e
- s
] = 0; /* ensure 0 termination */
3733 TRACE("%s\n", debugstr_w(dst
));
3735 OpenClipboard(es
->hwndSelf
);
3737 SetClipboardData(CF_UNICODETEXT
, hdst
);
3742 /*********************************************************************
3747 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
3749 TRACE("%s\n", debugstr_w(name
));
3751 * To initialize some final structure members, we call some helper
3752 * functions. However, since the EDITSTATE is not consistent (i.e.
3753 * not fully initialized), we should be very careful which
3754 * functions can be called, and in what order.
3756 EDIT_WM_SetFont(es
, 0, FALSE
);
3757 EDIT_EM_EmptyUndoBuffer(es
);
3759 if (name
&& *name
) {
3760 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, TRUE
);
3761 /* if we insert text to the editline, the text scrolls out
3762 * of the window, as the caret is placed after the insert
3763 * pos normally; thus we reset es->selection... to 0 and
3766 es
->selection_start
= es
->selection_end
= 0;
3767 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3768 * Messages are only to be sent when the USER does something to
3769 * change the contents. So I am removing this EN_CHANGE
3771 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3773 EDIT_EM_ScrollCaret(es
);
3775 /* force scroll info update */
3776 EDIT_UpdateScrollInfo(es
);
3777 /* The rule seems to return 1 here for success */
3778 /* Power Builder masked edit controls will crash */
3780 /* FIXME: is that in all cases so ? */
3785 /*********************************************************************
3790 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
3795 while (LocalUnlock(es
->hloc32W
)) ;
3796 LocalFree(es
->hloc32W
);
3799 while (LocalUnlock(es
->hloc32A
)) ;
3800 LocalFree(es
->hloc32A
);
3803 HINSTANCE16 hInstance
= GetWindowWord( es
->hwndSelf
, GWL_HINSTANCE
);
3804 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3805 LOCAL_Free(hInstance
, es
->hloc16
);
3808 pc
= es
->first_line_def
;
3812 HeapFree(GetProcessHeap(), 0, pc
);
3816 SetWindowLongW( es
->hwndSelf
, 0, 0 );
3817 HeapFree(GetProcessHeap(), 0, es
);
3823 /*********************************************************************
3828 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
3833 if (!(brush
= EDIT_NotifyCtlColor(es
, dc
)))
3834 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3836 GetClientRect(es
->hwndSelf
, &rc
);
3837 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3838 GetClipBox(dc
, &rc
);
3840 * FIXME: specs say that we should UnrealizeObject() the brush,
3841 * but the specs of UnrealizeObject() say that we shouldn't
3842 * unrealize a stock object. The default brush that
3843 * DefWndProc() returns is ... a stock object.
3845 FillRect(dc
, &rc
, brush
);
3850 /*********************************************************************
3855 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3857 if(!count
) return 0;
3861 LPWSTR textW
= (LPWSTR
)lParam
;
3862 lstrcpynW(textW
, es
->text
, count
);
3863 return strlenW(textW
);
3867 LPSTR textA
= (LPSTR
)lParam
;
3868 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3869 textA
[count
- 1] = 0; /* ensure 0 termination */
3870 return strlen(textA
);
3874 /*********************************************************************
3879 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3884 if (!(es
->style
& ES_MULTILINE
))
3887 if (!(es
->style
& ES_AUTOHSCROLL
))
3891 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3894 TRACE("SB_LINELEFT\n");
3896 dx
= -es
->char_width
;
3899 TRACE("SB_LINERIGHT\n");
3900 if (es
->x_offset
< es
->text_width
)
3901 dx
= es
->char_width
;
3904 TRACE("SB_PAGELEFT\n");
3906 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3909 TRACE("SB_PAGERIGHT\n");
3910 if (es
->x_offset
< es
->text_width
)
3911 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3919 TRACE("SB_RIGHT\n");
3920 if (es
->x_offset
< es
->text_width
)
3921 dx
= es
->text_width
- es
->x_offset
;
3924 TRACE("SB_THUMBTRACK %d\n", pos
);
3925 es
->flags
|= EF_HSCROLL_TRACK
;
3926 if(es
->style
& WS_HSCROLL
)
3927 dx
= pos
- es
->x_offset
;
3932 if(pos
< 0 || pos
> 100) return 0;
3933 /* Assume default scroll range 0-100 */
3934 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3935 new_x
= pos
* (es
->text_width
- fw
) / 100;
3936 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3939 case SB_THUMBPOSITION
:
3940 TRACE("SB_THUMBPOSITION %d\n", pos
);
3941 es
->flags
&= ~EF_HSCROLL_TRACK
;
3942 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3943 dx
= pos
- es
->x_offset
;
3948 if(pos
< 0 || pos
> 100) return 0;
3949 /* Assume default scroll range 0-100 */
3950 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3951 new_x
= pos
* (es
->text_width
- fw
) / 100;
3952 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3955 /* force scroll info update */
3956 EDIT_UpdateScrollInfo(es
);
3957 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
, "EN_HSCROLL");
3961 TRACE("SB_ENDSCROLL\n");
3964 * FIXME : the next two are undocumented !
3965 * Are we doing the right thing ?
3966 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3967 * although it's also a regular control message.
3969 case EM_GETTHUMB
: /* this one is used by NT notepad */
3973 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3974 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3977 /* Assume default scroll range 0-100 */
3978 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3979 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3981 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3984 case EM_LINESCROLL16
:
3985 TRACE("EM_LINESCROLL16\n");
3990 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3996 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3997 /* check if we are going to move too far */
3998 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3999 dx
= es
->text_width
- fw
- es
->x_offset
;
4001 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4007 /*********************************************************************
4012 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4014 HWND hLBox
= es
->hwndListBox
;
4022 hCombo
= GetParent(es
->hwndSelf
);
4026 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4028 if (key
== VK_UP
|| key
== VK_DOWN
)
4030 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4033 if (msg
== WM_KEYDOWN
|| nEUI
)
4034 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4040 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4042 /* make sure ComboLBox pops up */
4043 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4048 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4051 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4053 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4055 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4060 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4066 /*********************************************************************
4070 * Handling of special keys that don't produce a WM_CHAR
4071 * (i.e. non-printable keys) & Backspace & Delete
4074 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4079 if (GetKeyState(VK_MENU
) & 0x8000)
4082 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4083 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4088 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4093 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4094 EDIT_MoveUp_ML(es
, shift
);
4097 EDIT_MoveWordBackward(es
, shift
);
4099 EDIT_MoveBackward(es
, shift
);
4102 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4106 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4107 EDIT_MoveDown_ML(es
, shift
);
4109 EDIT_MoveWordForward(es
, shift
);
4111 EDIT_MoveForward(es
, shift
);
4114 EDIT_MoveHome(es
, shift
);
4117 EDIT_MoveEnd(es
, shift
);
4120 if (es
->style
& ES_MULTILINE
)
4121 EDIT_MovePageUp_ML(es
, shift
);
4123 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4126 if (es
->style
& ES_MULTILINE
)
4127 EDIT_MovePageDown_ML(es
, shift
);
4129 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4132 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4133 if (es
->selection_start
!= es
->selection_end
) {
4140 /* delete character left of caret */
4141 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4142 EDIT_MoveBackward(es
, TRUE
);
4144 } else if (control
) {
4145 /* delete to end of line */
4146 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4147 EDIT_MoveEnd(es
, TRUE
);
4150 /* delete character right of caret */
4151 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4152 EDIT_MoveForward(es
, TRUE
);
4160 if (!(es
->style
& ES_READONLY
))
4166 /* If the edit doesn't want the return send a message to the default object */
4167 if(!(es
->style
& ES_WANTRETURN
))
4169 HWND hwndParent
= GetParent(es
->hwndSelf
);
4170 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4171 if (HIWORD(dw
) == DC_HASDEFID
)
4173 SendMessageW( hwndParent
, WM_COMMAND
,
4174 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4175 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4184 /*********************************************************************
4189 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4191 es
->flags
&= ~EF_FOCUSED
;
4193 if(!(es
->style
& ES_NOHIDESEL
))
4194 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4195 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4200 /*********************************************************************
4204 * The caret position has been set on the WM_LBUTTONDOWN message
4207 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4210 INT e
= es
->selection_end
;
4215 if (!(es
->flags
& EF_FOCUSED
))
4218 l
= EDIT_EM_LineFromChar(es
, e
);
4219 li
= EDIT_EM_LineIndex(es
, l
);
4220 ll
= EDIT_EM_LineLength(es
, e
);
4221 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4222 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4223 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4224 EDIT_EM_ScrollCaret(es
);
4229 /*********************************************************************
4234 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4239 SetFocus(es
->hwndSelf
);
4240 if (!(es
->flags
& EF_FOCUSED
))
4243 es
->bCaptureState
= TRUE
;
4244 SetCapture(es
->hwndSelf
);
4245 EDIT_ConfinePoint(es
, &x
, &y
);
4246 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4247 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4248 EDIT_EM_ScrollCaret(es
);
4249 es
->region_posx
= es
->region_posy
= 0;
4250 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4255 /*********************************************************************
4260 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4262 if (es
->bCaptureState
) {
4263 KillTimer(es
->hwndSelf
, 0);
4264 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4266 es
->bCaptureState
= FALSE
;
4271 /*********************************************************************
4276 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4278 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4283 /*********************************************************************
4288 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4294 if (GetCapture() != es
->hwndSelf
)
4298 * FIXME: gotta do some scrolling if outside client
4299 * area. Maybe reset the timer ?
4302 EDIT_ConfinePoint(es
, &x
, &y
);
4303 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4304 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4305 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4306 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4307 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4312 /*********************************************************************
4316 * See also EDIT_WM_StyleChanged
4318 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4323 TRACE("Creating %s edit control, style = %08lx\n",
4324 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4326 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4328 SetWindowLongW( hwnd
, 0, (LONG
)es
);
4331 * Note: since the EDITSTATE has not been fully initialized yet,
4332 * we can't use any API calls that may send
4333 * WM_XXX messages before WM_NCCREATE is completed.
4336 es
->is_unicode
= unicode
;
4337 es
->style
= lpcs
->style
;
4339 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4341 es
->hwndSelf
= hwnd
;
4342 /* Save parent, which will be notified by EN_* messages */
4343 es
->hwndParent
= lpcs
->hwndParent
;
4345 if (es
->style
& ES_COMBO
)
4346 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4348 /* Number overrides lowercase overrides uppercase (at least it
4349 * does in Win95). However I'll bet that ES_NUMBER would be
4350 * invalid under Win 3.1.
4352 if (es
->style
& ES_NUMBER
) {
4353 ; /* do not override the ES_NUMBER */
4354 } else if (es
->style
& ES_LOWERCASE
) {
4355 es
->style
&= ~ES_UPPERCASE
;
4357 if (es
->style
& ES_MULTILINE
) {
4358 es
->buffer_limit
= BUFLIMIT_MULTI
;
4359 if (es
->style
& WS_VSCROLL
)
4360 es
->style
|= ES_AUTOVSCROLL
;
4361 if (es
->style
& WS_HSCROLL
)
4362 es
->style
|= ES_AUTOHSCROLL
;
4363 es
->style
&= ~ES_PASSWORD
;
4364 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4365 /* Confirmed - RIGHT overrides CENTER */
4366 if (es
->style
& ES_RIGHT
)
4367 es
->style
&= ~ES_CENTER
;
4368 es
->style
&= ~WS_HSCROLL
;
4369 es
->style
&= ~ES_AUTOHSCROLL
;
4372 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4373 es
->style
|= ES_AUTOVSCROLL
;
4375 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4376 if (WIN31_LOOK
== TWEAK_WineLook
||
4377 WIN95_LOOK
== TWEAK_WineLook
) {
4378 es
->style
&= ~ES_CENTER
;
4379 es
->style
&= ~ES_RIGHT
;
4381 if (es
->style
& ES_RIGHT
)
4382 es
->style
&= ~ES_CENTER
;
4384 es
->style
&= ~WS_HSCROLL
;
4385 es
->style
&= ~WS_VSCROLL
;
4386 es
->style
&= ~ES_AUTOVSCROLL
;
4387 es
->style
&= ~ES_WANTRETURN
;
4388 if (es
->style
& ES_PASSWORD
)
4389 es
->password_char
= '*';
4391 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4392 es
->style
|= ES_AUTOHSCROLL
;
4395 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4396 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4398 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4400 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4402 es
->undo_buffer_size
= es
->buffer_size
;
4404 if (es
->style
& ES_MULTILINE
)
4405 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4410 * In Win95 look and feel, the WS_BORDER style is replaced by the
4411 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4412 * control a non client area. Not always. This coordinates in some
4413 * way with the window creation code in dialog.c When making
4414 * modifications please ensure that the code still works for edit
4415 * controls created directly with style 0x50800000, exStyle 0 (
4416 * which should have a single pixel border)
4418 if (TWEAK_WineLook
!= WIN31_LOOK
)
4420 es
->style
&= ~WS_BORDER
;
4424 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4425 SetWindowLongW( hwnd
, GWL_STYLE
,
4426 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4432 /*********************************************************************
4437 static void EDIT_WM_Paint(EDITSTATE
*es
, WPARAM wParam
)
4446 BOOL rev
= es
->bEnableState
&&
4447 ((es
->flags
& EF_FOCUSED
) ||
4448 (es
->style
& ES_NOHIDESEL
));
4450 dc
= BeginPaint(es
->hwndSelf
, &ps
);
4453 if(es
->style
& WS_BORDER
) {
4454 GetClientRect(es
->hwndSelf
, &rc
);
4455 if(es
->style
& ES_MULTILINE
) {
4456 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4457 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4459 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4461 IntersectClipRect(dc
, es
->format_rect
.left
,
4462 es
->format_rect
.top
,
4463 es
->format_rect
.right
,
4464 es
->format_rect
.bottom
);
4465 if (es
->style
& ES_MULTILINE
) {
4466 GetClientRect(es
->hwndSelf
, &rc
);
4467 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4470 old_font
= SelectObject(dc
, es
->font
);
4471 EDIT_NotifyCtlColor(es
, dc
);
4473 if (!es
->bEnableState
)
4474 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4475 GetClipBox(dc
, &rcRgn
);
4476 if (es
->style
& ES_MULTILINE
) {
4477 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4478 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4479 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4480 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4481 EDIT_PaintLine(es
, dc
, i
, rev
);
4484 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4485 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4486 EDIT_PaintLine(es
, dc
, 0, rev
);
4489 SelectObject(dc
, old_font
);
4492 EndPaint(es
->hwndSelf
, &ps
);
4496 /*********************************************************************
4501 static void EDIT_WM_Paste(EDITSTATE
*es
)
4506 /* Protect read-only edit control from modification */
4507 if(es
->style
& ES_READONLY
)
4510 OpenClipboard(es
->hwndSelf
);
4511 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4512 src
= (LPWSTR
)GlobalLock(hsrc
);
4513 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4520 /*********************************************************************
4525 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4527 es
->flags
|= EF_FOCUSED
;
4528 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4529 EDIT_SetCaretPos(es
, es
->selection_end
,
4530 es
->flags
& EF_AFTER_WRAP
);
4531 if(!(es
->style
& ES_NOHIDESEL
))
4532 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4533 ShowCaret(es
->hwndSelf
);
4534 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
, "EN_SETFOCUS");
4538 /*********************************************************************
4542 * With Win95 look the margins are set to default font value unless
4543 * the system font (font == 0) is being set, in which case they are left
4547 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4555 dc
= GetDC(es
->hwndSelf
);
4557 old_font
= SelectObject(dc
, font
);
4558 GetTextMetricsW(dc
, &tm
);
4559 es
->line_height
= tm
.tmHeight
;
4560 es
->char_width
= tm
.tmAveCharWidth
;
4562 SelectObject(dc
, old_font
);
4563 ReleaseDC(es
->hwndSelf
, dc
);
4564 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4565 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4566 EC_USEFONTINFO
, EC_USEFONTINFO
);
4568 /* Force the recalculation of the format rect for each font change */
4569 GetClientRect(es
->hwndSelf
, &r
);
4570 EDIT_SetRectNP(es
, &r
);
4572 if (es
->style
& ES_MULTILINE
)
4573 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
4575 EDIT_CalcLineWidth_SL(es
);
4578 EDIT_UpdateText(es
, NULL
, TRUE
);
4579 if (es
->flags
& EF_FOCUSED
) {
4581 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4582 EDIT_SetCaretPos(es
, es
->selection_end
,
4583 es
->flags
& EF_AFTER_WRAP
);
4584 ShowCaret(es
->hwndSelf
);
4589 /*********************************************************************
4594 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4595 * The modified flag is reset. No notifications are sent.
4597 * For single-line controls, reception of WM_SETTEXT triggers:
4598 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4601 static void EDIT_WM_SetText(EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4606 text
= (LPWSTR
)lParam
;
4609 LPCSTR textA
= (LPCSTR
)lParam
;
4610 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4611 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4612 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4615 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4617 TRACE("%s\n", debugstr_w(text
));
4618 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4620 HeapFree(GetProcessHeap(), 0, text
);
4622 static const WCHAR empty_stringW
[] = {0};
4624 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4627 es
->flags
&= ~EF_MODIFIED
;
4628 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4629 /* Send the notification after the selection start and end have been set
4630 * edit control doesn't send notification on WM_SETTEXT
4631 * if it is multiline, or it is part of combobox
4633 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4635 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
, "EN_CHANGE");
4636 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4638 EDIT_EM_ScrollCaret(es
);
4642 /*********************************************************************
4647 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4649 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4651 TRACE("width = %d, height = %d\n", width
, height
);
4652 SetRect(&rc
, 0, 0, width
, height
);
4653 EDIT_SetRectNP(es
, &rc
);
4654 EDIT_UpdateText(es
, NULL
, TRUE
);
4659 /*********************************************************************
4663 * This message is sent by SetWindowLong on having changed either the Style
4664 * or the extended style.
4666 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4668 * See also EDIT_WM_NCCreate
4670 * It appears that the Windows version of the edit control allows the style
4671 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4672 * style variable which will generally be different. In this function we
4673 * update the internal style based on what changed in the externally visible
4676 * Much of this content as based upon the MSDN, especially:
4677 * Platform SDK Documentation -> User Interface Services ->
4678 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4679 * Edit Control Styles
4681 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4683 if (GWL_STYLE
== which
) {
4684 DWORD style_change_mask
;
4686 /* Only a subset of changes can be applied after the control
4689 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4691 if (es
->style
& ES_MULTILINE
)
4692 style_change_mask
|= ES_WANTRETURN
;
4694 new_style
= style
->styleNew
& style_change_mask
;
4696 /* Number overrides lowercase overrides uppercase (at least it
4697 * does in Win95). However I'll bet that ES_NUMBER would be
4698 * invalid under Win 3.1.
4700 if (new_style
& ES_NUMBER
) {
4701 ; /* do not override the ES_NUMBER */
4702 } else if (new_style
& ES_LOWERCASE
) {
4703 new_style
&= ~ES_UPPERCASE
;
4706 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4707 } else if (GWL_EXSTYLE
== which
) {
4708 ; /* FIXME - what is needed here */
4710 WARN ("Invalid style change %d\n",which
);
4716 /*********************************************************************
4721 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4723 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4724 if (EDIT_EM_CanUndo(es
))
4727 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4728 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4731 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4735 /*********************************************************************
4740 static void EDIT_WM_Timer(EDITSTATE
*es
)
4742 if (es
->region_posx
< 0) {
4743 EDIT_MoveBackward(es
, TRUE
);
4744 } else if (es
->region_posx
> 0) {
4745 EDIT_MoveForward(es
, TRUE
);
4748 * FIXME: gotta do some vertical scrolling here, like
4749 * EDIT_EM_LineScroll(hwnd, 0, 1);
4753 /*********************************************************************
4758 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4762 if (!(es
->style
& ES_MULTILINE
))
4765 if (!(es
->style
& ES_AUTOVSCROLL
))
4774 TRACE("action %d\n", action
);
4775 EDIT_EM_Scroll(es
, action
);
4782 TRACE("SB_BOTTOM\n");
4783 dy
= es
->line_count
- 1 - es
->y_offset
;
4786 TRACE("SB_THUMBTRACK %d\n", pos
);
4787 es
->flags
|= EF_VSCROLL_TRACK
;
4788 if(es
->style
& WS_VSCROLL
)
4789 dy
= pos
- es
->y_offset
;
4792 /* Assume default scroll range 0-100 */
4795 if(pos
< 0 || pos
> 100) return 0;
4796 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4797 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4798 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4799 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4800 es
->line_count
, es
->y_offset
, pos
, dy
);
4803 case SB_THUMBPOSITION
:
4804 TRACE("SB_THUMBPOSITION %d\n", pos
);
4805 es
->flags
&= ~EF_VSCROLL_TRACK
;
4806 if(es
->style
& WS_VSCROLL
)
4807 dy
= pos
- es
->y_offset
;
4810 /* Assume default scroll range 0-100 */
4813 if(pos
< 0 || pos
> 100) return 0;
4814 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4815 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4816 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4817 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4818 es
->line_count
, es
->y_offset
, pos
, dy
);
4822 /* force scroll info update */
4823 EDIT_UpdateScrollInfo(es
);
4824 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
, "EN_VSCROLL");
4828 TRACE("SB_ENDSCROLL\n");
4831 * FIXME : the next two are undocumented !
4832 * Are we doing the right thing ?
4833 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4834 * although it's also a regular control message.
4836 case EM_GETTHUMB
: /* this one is used by NT notepad */
4840 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4841 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4844 /* Assume default scroll range 0-100 */
4845 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4846 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4848 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4851 case EM_LINESCROLL16
:
4852 TRACE("EM_LINESCROLL16 %d\n", pos
);
4857 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4862 EDIT_EM_LineScroll(es
, 0, dy
);
4866 /*********************************************************************
4871 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4873 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4874 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
4878 /*********************************************************************
4883 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4885 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(es
, EN_UPDATE
, "EN_UPDATE");
4886 InvalidateRect(es
->hwndSelf
, rc
, bErase
);