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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
57 #include "wine/winbase16.h"
58 #include "wine/winuser16.h"
59 #include "wine/unicode.h"
61 #include "user_private.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
66 WINE_DECLARE_DEBUG_CHANNEL(combo
);
67 WINE_DECLARE_DEBUG_CHANNEL(relay
);
69 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
70 FIXME: BTW, new specs say 65535 (do you dare ???) */
71 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
72 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
73 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
74 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
77 * extra flags for EDITSTATE.flags field
79 #define EF_MODIFIED 0x0001 /* text has been modified */
80 #define EF_FOCUSED 0x0002 /* we have input focus */
81 #define EF_UPDATE 0x0004 /* notify parent of changed state */
82 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
83 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
84 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
85 wrapped line, instead of in front of the next character */
86 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
90 END_0
= 0, /* line ends with terminating '\0' character */
91 END_WRAP
, /* line is wrapped */
92 END_HARD
, /* line ends with a hard return '\r\n' */
93 END_SOFT
, /* line ends with a soft return '\r\r\n' */
94 END_RICH
/* line ends with a single '\n' */
97 typedef struct tagLINEDEF
{
98 INT length
; /* bruto length of a line in bytes */
99 INT net_length
; /* netto length of a line in visible characters */
101 INT width
; /* width of the line in pixels */
102 INT index
; /* line index into the buffer */
103 struct tagLINEDEF
*next
;
108 BOOL is_unicode
; /* how the control was created */
109 LPWSTR text
; /* the actual contents of the control */
110 UINT buffer_size
; /* the size of the buffer in characters */
111 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
112 HFONT font
; /* NULL means standard system font */
113 INT x_offset
; /* scroll offset for multi lines this is in pixels
114 for single lines it's in characters */
115 INT line_height
; /* height of a screen line in pixels */
116 INT char_width
; /* average character width in pixels */
117 DWORD style
; /* sane version of wnd->dwStyle */
118 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
119 INT undo_insert_count
; /* number of characters inserted in sequence */
120 UINT undo_position
; /* character index of the insertion and deletion */
121 LPWSTR undo_text
; /* deleted text */
122 UINT undo_buffer_size
; /* size of the deleted text buffer */
123 INT selection_start
; /* == selection_end if no selection */
124 INT selection_end
; /* == current caret position */
125 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
126 INT left_margin
; /* in pixels */
127 INT right_margin
; /* in pixels */
129 INT text_width
; /* width of the widest line in pixels for multi line controls
130 and just line width for single line controls */
131 INT region_posx
; /* Position of cursor relative to region: */
132 INT region_posy
; /* -1: to left, 0: within, 1: to right */
133 EDITWORDBREAKPROC16 word_break_proc16
;
134 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
135 INT line_count
; /* number of lines */
136 INT y_offset
; /* scroll offset in number of lines */
137 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
138 BOOL bEnableState
; /* flag keeping the enable state */
139 HWND hwndSelf
; /* the our window handle */
140 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
141 Even if parent will change, EN_* messages
142 should be sent to the first parent. */
143 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
145 * only for multi line controls
147 INT lock_count
; /* amount of re-entries in the EditWndProc */
150 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
151 HLOCAL hloc32W
; /* our unicode local memory block */
152 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
154 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
159 UINT composition_len
; /* length of composition, 0 == no composition */
160 int composition_start
; /* the character position for the composition */
164 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
165 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
167 /* used for disabled or read-only edit control */
168 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
170 { /* Notify parent which has created this edit control */ \
171 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
172 SendMessageW(es->hwndParent, WM_COMMAND, \
173 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
174 (LPARAM)(es->hwndSelf)); \
177 /*********************************************************************
184 * These functions have trivial implementations
185 * We still like to call them internally
186 * "static inline" makes them more like macro's
188 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
189 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
190 static inline void EDIT_WM_Clear(EDITSTATE
*es
);
191 static inline void EDIT_WM_Cut(EDITSTATE
*es
);
194 * Helper functions only valid for one type of control
196 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
197 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
);
198 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
199 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
);
200 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
);
201 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
);
202 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
);
204 * Helper functions valid for both single line _and_ multi line controls
206 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
207 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
208 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
209 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
210 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
);
211 static void EDIT_LockBuffer(EDITSTATE
*es
);
212 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
);
213 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
214 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
);
215 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
);
216 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
);
217 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
);
218 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
);
219 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
);
220 static void EDIT_PaintLine(EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
221 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
222 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
223 static void EDIT_AdjustFormatRect(EDITSTATE
*es
);
224 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT lprc
);
225 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
);
226 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
);
227 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
229 * EM_XXX message handlers
231 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
);
232 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
233 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
234 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
);
235 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
);
236 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
);
237 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
);
238 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
239 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
240 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
241 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
);
242 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
);
243 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
244 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
);
245 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
);
246 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
);
247 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
);
248 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
);
249 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
250 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, WORD left
, WORD right
, BOOL repaint
);
251 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
);
252 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
253 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
254 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
255 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
);
256 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
257 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
);
259 * WM_XXX message handlers
261 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
);
262 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
263 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
);
264 static void EDIT_WM_Copy(EDITSTATE
*es
);
265 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
);
266 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
);
267 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
);
268 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
);
269 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
);
270 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
);
271 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
);
272 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
);
273 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
274 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
);
275 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
);
276 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
);
277 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
);
278 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
);
279 static void EDIT_WM_Paste(EDITSTATE
*es
);
280 static void EDIT_WM_SetFocus(EDITSTATE
*es
);
281 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
);
282 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
);
283 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
);
284 static LRESULT
EDIT_WM_StyleChanged(EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
285 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
);
286 static void EDIT_WM_Timer(EDITSTATE
*es
);
287 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
);
288 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
289 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
290 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
);
292 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
293 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
295 /***********************************************************************
296 * USER32_DisplayUnixPaths
298 * Check if unix paths should be displayed.
300 static int bDisplayUnixPath
= -1;
302 int USER32_DisplayUnixPaths(EDITSTATE
*es
)
304 if (bDisplayUnixPath
< 0)
308 bDisplayUnixPath
= 0;
310 /* @@ Wine registry key: HKCU\Software\Wine */
311 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine", &hkey
))
314 DWORD type
, count
= sizeof(buffer
);
316 if(!RegQueryValueExA(hkey
, "DisplayUnixPaths", 0, &type
, (LPBYTE
)buffer
, &count
))
317 bDisplayUnixPath
= atoi(buffer
);
323 return bDisplayUnixPath
&& !(es
->style
& ES_MULTILINE
) && strchrW(es
->text
, '/');
327 /*********************************************************************
328 * edit class descriptor
330 const struct builtin_class_descr EDIT_builtin_class
=
333 CS_DBLCLKS
| CS_PARENTDC
, /* style */
334 EditWndProcA
, /* procA */
335 EditWndProcW
, /* procW */
336 sizeof(EDITSTATE
*), /* extra */
337 IDC_IBEAM
, /* cursor */
342 /*********************************************************************
347 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
349 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
353 /*********************************************************************
358 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
360 es
->undo_insert_count
= 0;
361 *es
->undo_text
= '\0';
365 /*********************************************************************
370 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
372 static const WCHAR empty_stringW
[] = {0};
374 /* Protect read-only edit control from modification */
375 if(es
->style
& ES_READONLY
)
378 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
382 /*********************************************************************
387 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
394 /**********************************************************************
397 * Returns the window version in case Wine emulates a later version
398 * of windows than the application expects.
400 * In a number of cases when windows runs an application that was
401 * designed for an earlier windows version, windows reverts
402 * to "old" behaviour of that earlier version.
404 * An example is a disabled edit control that needs to be painted.
405 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
406 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
407 * applications with an expected version 0f 4.0 or higher.
410 static DWORD
get_app_version(void)
412 static DWORD version
;
415 DWORD dwEmulatedVersion
;
417 DWORD dwProcVersion
= GetProcessVersion(0);
419 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
420 GetVersionExW( &info
);
421 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
422 /* FIXME: this may not be 100% correct; see discussion on the
423 * wine developer list in Nov 1999 */
424 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
430 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
435 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
436 msg
= WM_CTLCOLORSTATIC
;
438 msg
= WM_CTLCOLOREDIT
;
440 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
441 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
443 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
447 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
450 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
452 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
455 /*********************************************************************
459 * The messages are in the order of the actual integer values
460 * (which can be found in include/windows.h)
461 * Wherever possible the 16 bit versions are converted to
462 * the 32 bit ones, so that we can 'fall through' to the
463 * helper functions. These are mostly 32 bit (with a few
464 * exceptions, clearly indicated by a '16' extension to their
468 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
469 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
471 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
474 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
476 if (!es
&& msg
!= WM_NCCREATE
)
477 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
479 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
487 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
491 if ((short)LOWORD(lParam
) == -1)
492 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
494 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
496 EDIT_EM_ScrollCaret(es
);
500 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
501 EDIT_EM_ScrollCaret(es
);
508 RECT16
*r16
= MapSL(lParam
);
509 r16
->left
= es
->format_rect
.left
;
510 r16
->top
= es
->format_rect
.top
;
511 r16
->right
= es
->format_rect
.right
;
512 r16
->bottom
= es
->format_rect
.bottom
;
517 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
521 if ((es
->style
& ES_MULTILINE
) && lParam
) {
523 RECT16
*r16
= MapSL(lParam
);
526 rc
.right
= r16
->right
;
527 rc
.bottom
= r16
->bottom
;
528 EDIT_SetRectNP(es
, &rc
);
529 EDIT_UpdateText(es
, NULL
, TRUE
);
533 if ((es
->style
& ES_MULTILINE
) && lParam
) {
534 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
535 EDIT_UpdateText(es
, NULL
, TRUE
);
540 if ((es
->style
& ES_MULTILINE
) && lParam
) {
542 RECT16
*r16
= MapSL(lParam
);
545 rc
.right
= r16
->right
;
546 rc
.bottom
= r16
->bottom
;
547 EDIT_SetRectNP(es
, &rc
);
551 if ((es
->style
& ES_MULTILINE
) && lParam
)
552 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
557 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
560 case EM_LINESCROLL16
:
561 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
562 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
565 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
568 case EM_SCROLLCARET16
:
570 EDIT_EM_ScrollCaret(es
);
576 result
= ((es
->flags
& EF_MODIFIED
) != 0);
582 es
->flags
|= EF_MODIFIED
;
584 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
587 case EM_GETLINECOUNT16
:
588 case EM_GETLINECOUNT
:
589 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
593 if ((INT16
)wParam
== -1)
597 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
601 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
604 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
608 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
611 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
616 result
= EDIT_EM_GetThumb(es
);
619 /* these messages missing from specs */
628 FIXME("undocumented message 0x%x, please report\n", msg
);
629 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
632 case EM_LINELENGTH16
:
634 if (USER32_DisplayUnixPaths(es
))
636 WCHAR textW
[MAX_PATH
];
637 return EDIT_WM_GetText(es
, MAX_PATH
, textW
, TRUE
);
639 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
642 case EM_REPLACESEL16
:
643 lParam
= (LPARAM
)MapSL(lParam
);
644 unicode
= FALSE
; /* 16-bit message is always ascii */
651 textW
= (LPWSTR
)lParam
;
654 LPSTR textA
= (LPSTR
)lParam
;
655 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
656 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
657 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
660 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
664 HeapFree(GetProcessHeap(), 0, textW
);
669 lParam
= (LPARAM
)MapSL(lParam
);
670 unicode
= FALSE
; /* 16-bit message is always ascii */
673 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
677 case EM_SETLIMITTEXT
:
678 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
683 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
689 result
= (LRESULT
)EDIT_EM_Undo(es
);
694 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
697 case EM_LINEFROMCHAR16
:
698 case EM_LINEFROMCHAR
:
699 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
702 case EM_SETTABSTOPS16
:
703 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
706 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
709 case EM_SETPASSWORDCHAR16
:
710 unicode
= FALSE
; /* 16-bit message is always ascii */
712 case EM_SETPASSWORDCHAR
:
717 charW
= (WCHAR
)wParam
;
721 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
724 EDIT_EM_SetPasswordChar(es
, charW
);
728 case EM_EMPTYUNDOBUFFER16
:
729 case EM_EMPTYUNDOBUFFER
:
730 EDIT_EM_EmptyUndoBuffer(es
);
733 case EM_GETFIRSTVISIBLELINE16
:
734 result
= es
->y_offset
;
736 case EM_GETFIRSTVISIBLELINE
:
737 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
740 case EM_SETREADONLY16
:
743 SetWindowLongW( hwnd
, GWL_STYLE
,
744 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
745 es
->style
|= ES_READONLY
;
747 SetWindowLongW( hwnd
, GWL_STYLE
,
748 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
749 es
->style
&= ~ES_READONLY
;
754 case EM_SETWORDBREAKPROC16
:
755 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
757 case EM_SETWORDBREAKPROC
:
758 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
761 case EM_GETWORDBREAKPROC16
:
762 result
= (LRESULT
)es
->word_break_proc16
;
764 case EM_GETWORDBREAKPROC
:
765 result
= (LRESULT
)es
->word_break_proc
;
768 case EM_GETPASSWORDCHAR16
:
769 unicode
= FALSE
; /* 16-bit message is always ascii */
771 case EM_GETPASSWORDCHAR
:
774 result
= es
->password_char
;
777 WCHAR charW
= es
->password_char
;
779 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
785 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
788 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
792 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
795 case EM_GETLIMITTEXT
:
796 result
= es
->buffer_limit
;
800 result
= strlenW(es
->text
);
801 if ((INT
)wParam
>= result
) result
= -1;
802 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
806 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
809 /* End of the EM_ messages which were in numerical order; what order
810 * are these in? vaguely alphabetical?
814 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
818 result
= EDIT_WM_Destroy(es
);
823 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
825 if (es
->style
& ES_MULTILINE
)
827 result
|= DLGC_WANTALLKEYS
;
831 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
833 int vk
= (int)((LPMSG
)lParam
)->wParam
;
835 if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
837 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
838 result
|= DLGC_WANTMESSAGE
;
849 strng
[0] = wParam
>> 8;
850 strng
[1] = wParam
& 0xff;
851 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
852 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
853 EDIT_WM_Char(es
, charW
);
866 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
869 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
871 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
872 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
875 EDIT_WM_Char(es
, charW
);
884 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
888 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
897 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
900 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
904 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
905 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
906 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
908 result
= EDIT_WM_Create(es
, nameW
);
909 HeapFree(GetProcessHeap(), 0, nameW
);
918 es
->bEnableState
= (BOOL
) wParam
;
919 EDIT_UpdateText(es
, NULL
, TRUE
);
923 result
= EDIT_WM_EraseBkGnd(es
, (HDC
)wParam
);
927 result
= (LRESULT
)es
->font
;
931 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
934 case WM_GETTEXTLENGTH
:
935 if (USER32_DisplayUnixPaths(es
))
937 WCHAR textW
[MAX_PATH
];
938 return EDIT_WM_GetText(es
, MAX_PATH
, textW
, TRUE
);
940 if (unicode
) result
= strlenW(es
->text
);
941 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, strlenW(es
->text
),
942 NULL
, 0, NULL
, NULL
);
946 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
950 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
954 result
= EDIT_WM_KillFocus(es
);
957 case WM_LBUTTONDBLCLK
:
958 result
= EDIT_WM_LButtonDblClk(es
);
962 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
966 result
= EDIT_WM_LButtonUp(es
);
970 result
= EDIT_WM_MButtonDown(es
);
974 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
979 EDIT_WM_Paint(es
, (HDC
)wParam
);
987 EDIT_WM_SetFocus(es
);
991 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
995 /* FIXME: actually set an internal flag and behave accordingly */
999 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
1004 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1007 case WM_STYLECHANGED
:
1008 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
1011 case WM_STYLECHANGING
:
1012 result
= 0; /* See EDIT_WM_StyleChanged */
1016 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
1024 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
1029 int gcWheelDelta
= 0;
1030 UINT pulScrollLines
= 3;
1031 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1033 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1034 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1037 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
1038 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1040 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1041 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1042 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
1048 /* IME messages to make the edit control IME aware */
1049 case WM_IME_SETCONTEXT
:
1052 case WM_IME_STARTCOMPOSITION
:
1054 * FIXME in IME: This message is not always sent like it should be
1056 if (es
->selection_start
!= es
->selection_end
)
1058 static const WCHAR empty_stringW
[] = {0};
1059 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1061 es
->composition_start
= es
->selection_end
;
1062 es
->composition_len
= 0;
1065 case WM_IME_COMPOSITION
:
1066 if (es
->composition_len
== 0)
1068 if (es
->selection_start
!= es
->selection_end
)
1070 static const WCHAR empty_stringW
[] = {0};
1071 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
1074 es
->composition_start
= es
->selection_end
;
1076 EDIT_ImeComposition(hwnd
,lParam
,es
);
1079 case WM_IME_ENDCOMPOSITION
:
1080 es
->composition_len
= 0;
1083 case WM_IME_COMPOSITIONFULL
:
1089 case WM_IME_CONTROL
:
1093 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
1097 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
1099 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
1104 /*********************************************************************
1106 * EditWndProcW (USER32.@)
1108 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1110 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1113 /*********************************************************************
1115 * EditWndProc (USER32.@)
1117 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1119 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1122 /*********************************************************************
1124 * EDIT_BuildLineDefs_ML
1126 * Build linked list of text lines.
1127 * Lines can end with '\0' (last line), a character (if it is wrapped),
1128 * a soft return '\r\r\n' or a hard return '\r\n'
1131 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1135 LPWSTR current_position
, cp
;
1137 LINEDEF
*current_line
;
1138 LINEDEF
*previous_line
;
1139 LINEDEF
*start_line
;
1140 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1141 INT line_count
= es
->line_count
;
1142 INT orig_net_length
;
1145 if (istart
== iend
&& delta
== 0)
1148 dc
= GetDC(es
->hwndSelf
);
1150 old_font
= SelectObject(dc
, es
->font
);
1152 previous_line
= NULL
;
1153 current_line
= es
->first_line_def
;
1155 /* Find starting line. istart must lie inside an existing line or
1156 * at the end of buffer */
1158 if (istart
< current_line
->index
+ current_line
->length
||
1159 current_line
->ending
== END_0
)
1162 previous_line
= current_line
;
1163 current_line
= current_line
->next
;
1165 } while (current_line
);
1167 if (!current_line
) /* Error occurred start is not inside previous buffer */
1169 FIXME(" modification occurred outside buffer\n");
1170 ReleaseDC(es
->hwndSelf
, dc
);
1174 /* Remember start of modifications in order to calculate update region */
1175 nstart_line
= line_index
;
1176 nstart_index
= current_line
->index
;
1178 /* We must start to reformat from the previous line since the modifications
1179 * may have caused the line to wrap upwards. */
1180 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1183 current_line
= previous_line
;
1185 start_line
= current_line
;
1187 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1188 current_position
= es
->text
+ current_line
->index
;
1190 if (current_line
!= start_line
)
1192 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1194 /* The buffer has been expanded, create a new line and
1195 insert it into the link list */
1196 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1197 new_line
->next
= previous_line
->next
;
1198 previous_line
->next
= new_line
;
1199 current_line
= new_line
;
1202 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1204 /* The previous line merged with this line so we delete this extra entry */
1205 previous_line
->next
= current_line
->next
;
1206 HeapFree(GetProcessHeap(), 0, current_line
);
1207 current_line
= previous_line
->next
;
1211 else /* current_line->index + delta == current_position */
1213 if (current_position
- es
->text
> iend
)
1214 break; /* We reached end of line modifications */
1215 /* else recalulate this line */
1219 current_line
->index
= current_position
- es
->text
;
1220 orig_net_length
= current_line
->net_length
;
1222 /* Find end of line */
1223 cp
= current_position
;
1225 if (*cp
== '\n') break;
1226 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1231 /* Mark type of line termination */
1233 current_line
->ending
= END_0
;
1234 current_line
->net_length
= strlenW(current_position
);
1235 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1236 current_line
->ending
= END_SOFT
;
1237 current_line
->net_length
= cp
- current_position
- 1;
1238 } else if (*cp
== '\n') {
1239 current_line
->ending
= END_RICH
;
1240 current_line
->net_length
= cp
- current_position
;
1242 current_line
->ending
= END_HARD
;
1243 current_line
->net_length
= cp
- current_position
;
1246 /* Calculate line width */
1247 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1248 current_position
, current_line
->net_length
,
1249 es
->tabs_count
, es
->tabs
));
1251 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1252 if (!(es
->style
& ES_AUTOHSCROLL
)) {
1253 if (current_line
->width
> fw
) {
1258 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1259 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1260 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1261 current_position
, next
, es
->tabs_count
, es
->tabs
));
1262 } while (current_line
->width
<= fw
);
1263 if (!prev
) { /* Didn't find a line break so force a break */
1268 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1269 current_position
, next
, es
->tabs_count
, es
->tabs
));
1270 } while (current_line
->width
<= fw
);
1275 /* If the first line we are calculating, wrapped before istart, we must
1276 * adjust istart in order for this to be reflected in the update region. */
1277 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1278 istart
= current_line
->index
+ prev
;
1279 /* else if we are updating the previous line before the first line we
1280 * are re-calculating and it expanded */
1281 else if (current_line
== start_line
&&
1282 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1284 /* Line expanded due to an upwards line wrap so we must partially include
1285 * previous line in update region */
1286 nstart_line
= line_index
;
1287 nstart_index
= current_line
->index
;
1288 istart
= current_line
->index
+ orig_net_length
;
1291 current_line
->net_length
= prev
;
1292 current_line
->ending
= END_WRAP
;
1293 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1294 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1296 else if (orig_net_length
< current_line
->net_length
&&
1297 current_line
== start_line
&&
1298 current_line
->index
!= nstart_index
) {
1299 /* The previous line expanded but it's still not as wide as the client rect */
1300 /* The expansion is due to an upwards line wrap so we must partially include
1301 it in the update region */
1302 nstart_line
= line_index
;
1303 nstart_index
= current_line
->index
;
1304 istart
= current_line
->index
+ orig_net_length
;
1309 /* Adjust length to include line termination */
1310 switch (current_line
->ending
) {
1312 current_line
->length
= current_line
->net_length
+ 3;
1315 current_line
->length
= current_line
->net_length
+ 1;
1318 current_line
->length
= current_line
->net_length
+ 2;
1322 current_line
->length
= current_line
->net_length
;
1325 es
->text_width
= max(es
->text_width
, current_line
->width
);
1326 current_position
+= current_line
->length
;
1327 previous_line
= current_line
;
1328 current_line
= current_line
->next
;
1330 } while (previous_line
->ending
!= END_0
);
1332 /* Finish adjusting line indexes by delta or remove hanging lines */
1333 if (previous_line
->ending
== END_0
)
1335 LINEDEF
*pnext
= NULL
;
1337 previous_line
->next
= NULL
;
1338 while (current_line
)
1340 pnext
= current_line
->next
;
1341 HeapFree(GetProcessHeap(), 0, current_line
);
1342 current_line
= pnext
;
1346 else if (delta
!= 0)
1348 while (current_line
)
1350 current_line
->index
+= delta
;
1351 current_line
= current_line
->next
;
1355 /* Calculate rest of modification rectangle */
1360 * We calculate two rectangles. One for the first line which may have
1361 * an indent with respect to the format rect. The other is a format-width
1362 * rectangle that spans the rest of the lines that changed or moved.
1364 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1365 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1366 rc
.bottom
= rc
.top
+ es
->line_height
;
1367 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
1368 rc
.left
= es
->format_rect
.left
;
1370 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1371 es
->text
+ nstart_index
, istart
- nstart_index
,
1372 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1373 rc
.right
= es
->format_rect
.right
;
1374 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1377 rc
.left
= es
->format_rect
.left
;
1378 rc
.right
= es
->format_rect
.right
;
1380 * If lines were added or removed we must re-paint the remainder of the
1381 * lines since the remaining lines were either shifted up or down.
1383 if (line_count
< es
->line_count
) /* We added lines */
1384 rc
.bottom
= es
->line_count
* es
->line_height
;
1385 else if (line_count
> es
->line_count
) /* We removed lines */
1386 rc
.bottom
= line_count
* es
->line_height
;
1388 rc
.bottom
= line_index
* es
->line_height
;
1389 rc
.bottom
+= es
->format_rect
.top
;
1390 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1391 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1392 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1393 DeleteObject(tmphrgn
);
1397 SelectObject(dc
, old_font
);
1399 ReleaseDC(es
->hwndSelf
, dc
);
1402 /*********************************************************************
1404 * EDIT_CalcLineWidth_SL
1407 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
1414 text
= EDIT_GetPasswordPointer_SL(es
);
1416 dc
= GetDC(es
->hwndSelf
);
1418 old_font
= SelectObject(dc
, es
->font
);
1420 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
1423 SelectObject(dc
, old_font
);
1424 ReleaseDC(es
->hwndSelf
, dc
);
1426 if (es
->style
& ES_PASSWORD
)
1427 HeapFree(GetProcessHeap(), 0, text
);
1429 es
->text_width
= size
.cx
;
1432 /*********************************************************************
1434 * EDIT_CallWordBreakProc
1436 * Call appropriate WordBreakProc (internal or external).
1438 * Note: The "start" argument should always be an index referring
1439 * to es->text. The actual wordbreak proc might be
1440 * 16 bit, so we can't always pass any 32 bit LPSTR.
1441 * Hence we assume that es->text is the buffer that holds
1442 * the string under examination (we can decide this for ourselves).
1445 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1449 if (es
->word_break_proc16
) {
1456 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1457 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1458 segptr
= WOWGlobalLock16(hglob16
);
1459 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1460 args
[4] = SELECTOROF(segptr
);
1461 args
[3] = OFFSETOF(segptr
);
1465 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
1466 ret
= LOWORD(result
);
1467 GlobalUnlock16(hglob16
);
1468 GlobalFree16(hglob16
);
1470 else if (es
->word_break_proc
)
1474 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1476 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1477 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1478 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1482 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1486 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1487 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1488 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1489 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1490 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1491 ret
= wbpA(textA
, index
, countA
, action
);
1492 HeapFree(GetProcessHeap(), 0, textA
);
1496 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1502 /*********************************************************************
1506 * Beware: This is not the function called on EM_CHARFROMPOS
1507 * The position _can_ be outside the formatting / client
1509 * The return value is only the character index
1512 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1517 INT x_high
= 0, x_low
= 0;
1519 if (es
->style
& ES_MULTILINE
) {
1520 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1522 LINEDEF
*line_def
= es
->first_line_def
;
1524 while ((line
> 0) && line_def
->next
) {
1525 line_index
+= line_def
->length
;
1526 line_def
= line_def
->next
;
1529 x
+= es
->x_offset
- es
->format_rect
.left
;
1530 if (es
->style
& ES_RIGHT
)
1531 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
1532 else if (es
->style
& ES_CENTER
)
1533 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
1534 if (x
>= line_def
->width
) {
1536 *after_wrap
= (line_def
->ending
== END_WRAP
);
1537 return line_index
+ line_def
->net_length
;
1541 *after_wrap
= FALSE
;
1544 dc
= GetDC(es
->hwndSelf
);
1546 old_font
= SelectObject(dc
, es
->font
);
1548 high
= line_index
+ line_def
->net_length
+ 1;
1549 while (low
< high
- 1)
1551 INT mid
= (low
+ high
) / 2;
1552 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
1561 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
1567 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1568 (line_def
->ending
== END_WRAP
));
1573 *after_wrap
= FALSE
;
1574 x
-= es
->format_rect
.left
;
1576 return es
->x_offset
;
1580 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
1581 if (es
->style
& ES_RIGHT
)
1583 else if (es
->style
& ES_CENTER
)
1587 text
= EDIT_GetPasswordPointer_SL(es
);
1588 dc
= GetDC(es
->hwndSelf
);
1590 old_font
= SelectObject(dc
, es
->font
);
1594 INT high
= es
->x_offset
;
1595 while (low
< high
- 1)
1597 INT mid
= (low
+ high
) / 2;
1598 GetTextExtentPoint32W( dc
, text
+ mid
,
1599 es
->x_offset
- mid
, &size
);
1608 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
1615 INT low
= es
->x_offset
;
1616 INT high
= strlenW(es
->text
) + 1;
1617 while (low
< high
- 1)
1619 INT mid
= (low
+ high
) / 2;
1620 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1621 mid
- es
->x_offset
, &size
);
1630 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
1635 if (es
->style
& ES_PASSWORD
)
1636 HeapFree(GetProcessHeap(), 0, text
);
1639 SelectObject(dc
, old_font
);
1640 ReleaseDC(es
->hwndSelf
, dc
);
1645 /*********************************************************************
1649 * adjusts the point to be within the formatting rectangle
1650 * (so CharFromPos returns the nearest _visible_ character)
1653 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1655 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1656 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1660 /*********************************************************************
1664 * Calculates the bounding rectangle for a line from a starting
1665 * column to an ending column.
1668 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1670 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1672 if (es
->style
& ES_MULTILINE
)
1673 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1675 rc
->top
= es
->format_rect
.top
;
1676 rc
->bottom
= rc
->top
+ es
->line_height
;
1677 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1678 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1682 /*********************************************************************
1684 * EDIT_GetPasswordPointer_SL
1686 * note: caller should free the (optionally) allocated buffer
1689 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1691 if (es
->style
& ES_PASSWORD
) {
1692 INT len
= strlenW(es
->text
);
1693 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1695 while(len
) text
[--len
] = es
->password_char
;
1702 /*********************************************************************
1706 * This acts as a LocalLock16(), but it locks only once. This way
1707 * you can call it whenever you like, without unlocking.
1709 * Initially the edit control allocates a HLOCAL32 buffer
1710 * (32 bit linear memory handler). However, 16 bit application
1711 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1712 * handler). From that moment on we have to keep using this 16 bit memory
1713 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1714 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1718 static void EDIT_LockBuffer(EDITSTATE
*es
)
1720 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
1721 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1726 BOOL _16bit
= FALSE
;
1732 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1733 textA
= LocalLock(es
->hloc32A
);
1734 countA
= strlen(textA
) + 1;
1738 HANDLE16 oldDS
= stack16
->ds
;
1739 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1740 stack16
->ds
= hInstance
;
1741 textA
= MapSL(LocalLock16(es
->hloc16
));
1742 stack16
->ds
= oldDS
;
1743 countA
= strlen(textA
) + 1;
1748 ERR("no buffer ... please report\n");
1755 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1756 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1757 if(countW_new
> es
->buffer_size
+ 1)
1759 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1760 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1761 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1764 es
->hloc32W
= hloc32W_new
;
1765 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1766 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1769 WARN("FAILED! Will synchronize partially\n");
1773 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1774 es
->text
= LocalLock(es
->hloc32W
);
1778 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1781 HANDLE16 oldDS
= stack16
->ds
;
1782 stack16
->ds
= hInstance
;
1783 LocalUnlock16(es
->hloc16
);
1784 stack16
->ds
= oldDS
;
1787 LocalUnlock(es
->hloc32A
);
1794 /*********************************************************************
1796 * EDIT_SL_InvalidateText
1798 * Called from EDIT_InvalidateText().
1799 * Does the job for single-line controls only.
1802 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1807 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1808 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1809 EDIT_UpdateText(es
, &rc
, TRUE
);
1813 /*********************************************************************
1815 * EDIT_ML_InvalidateText
1817 * Called from EDIT_InvalidateText().
1818 * Does the job for multi-line controls only.
1821 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1823 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1824 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1825 INT el
= EDIT_EM_LineFromChar(es
, end
);
1834 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1837 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1838 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1839 if (sl
< es
->y_offset
) {
1843 if (el
> es
->y_offset
+ vlc
) {
1844 el
= es
->y_offset
+ vlc
;
1845 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1847 GetClientRect(es
->hwndSelf
, &rc1
);
1848 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1850 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1851 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1852 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1854 EDIT_GetLineRect(es
, sl
, sc
,
1855 EDIT_EM_LineLength(es
,
1856 EDIT_EM_LineIndex(es
, sl
)),
1858 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1859 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1860 for (l
= sl
+ 1 ; l
< el
; l
++) {
1861 EDIT_GetLineRect(es
, l
, 0,
1862 EDIT_EM_LineLength(es
,
1863 EDIT_EM_LineIndex(es
, l
)),
1865 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1866 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1868 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1869 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1870 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1875 /*********************************************************************
1877 * EDIT_InvalidateText
1879 * Invalidate the text from offset start up to, but not including,
1880 * offset end. Useful for (re)painting the selection.
1881 * Regions outside the linewidth are not invalidated.
1882 * end == -1 means end == TextLength.
1883 * start and end need not be ordered.
1886 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1892 end
= strlenW(es
->text
);
1900 if (es
->style
& ES_MULTILINE
)
1901 EDIT_ML_InvalidateText(es
, start
, end
);
1903 EDIT_SL_InvalidateText(es
, start
, end
);
1907 /*********************************************************************
1911 * Try to fit size + 1 characters in the buffer.
1913 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1917 if (size
<= es
->buffer_size
)
1920 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1922 /* Force edit to unlock it's buffer. es->text now NULL */
1923 EDIT_UnlockBuffer(es
, TRUE
);
1926 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1927 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1928 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1929 es
->hloc32W
= hNew32W
;
1930 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1934 EDIT_LockBuffer(es
);
1936 if (es
->buffer_size
< size
) {
1937 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1938 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1941 TRACE("We now have %d+1\n", es
->buffer_size
);
1947 /*********************************************************************
1951 * Try to fit size + 1 bytes in the undo buffer.
1954 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1958 if (size
<= es
->undo_buffer_size
)
1961 TRACE("trying to ReAlloc to %d+1\n", size
);
1963 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1964 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1965 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1970 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1976 /*********************************************************************
1981 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1983 INT e
= es
->selection_end
;
1987 if ((es
->style
& ES_MULTILINE
) && e
&&
1988 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1990 if (e
&& (es
->text
[e
- 1] == '\r'))
1994 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1995 EDIT_EM_ScrollCaret(es
);
1999 /*********************************************************************
2003 * Only for multi line controls
2004 * Move the caret one line down, on a column with the nearest
2005 * x coordinate on the screen (might be a different column).
2008 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
2010 INT s
= es
->selection_start
;
2011 INT e
= es
->selection_end
;
2012 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2013 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2014 INT x
= (short)LOWORD(pos
);
2015 INT y
= (short)HIWORD(pos
);
2017 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
2020 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2021 EDIT_EM_ScrollCaret(es
);
2025 /*********************************************************************
2030 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
)
2032 BOOL after_wrap
= FALSE
;
2035 /* Pass a high value in x to make sure of receiving the end of the line */
2036 if (es
->style
& ES_MULTILINE
)
2037 e
= EDIT_CharFromPos(es
, 0x3fffffff,
2038 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
2040 e
= strlenW(es
->text
);
2041 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
2042 EDIT_EM_ScrollCaret(es
);
2046 /*********************************************************************
2051 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
2053 INT e
= es
->selection_end
;
2057 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
2058 if (es
->text
[e
] == '\n')
2060 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
2064 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2065 EDIT_EM_ScrollCaret(es
);
2069 /*********************************************************************
2073 * Home key: move to beginning of line.
2076 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
)
2080 /* Pass the x_offset in x to make sure of receiving the first position of the line */
2081 if (es
->style
& ES_MULTILINE
)
2082 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
2083 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
2086 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
2087 EDIT_EM_ScrollCaret(es
);
2091 /*********************************************************************
2093 * EDIT_MovePageDown_ML
2095 * Only for multi line controls
2096 * Move the caret one page down, on a column with the nearest
2097 * x coordinate on the screen (might be a different column).
2100 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2102 INT s
= es
->selection_start
;
2103 INT e
= es
->selection_end
;
2104 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2105 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2106 INT x
= (short)LOWORD(pos
);
2107 INT y
= (short)HIWORD(pos
);
2109 e
= EDIT_CharFromPos(es
, x
,
2110 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2114 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2115 EDIT_EM_ScrollCaret(es
);
2119 /*********************************************************************
2121 * EDIT_MovePageUp_ML
2123 * Only for multi line controls
2124 * Move the caret one page up, on a column with the nearest
2125 * x coordinate on the screen (might be a different column).
2128 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2130 INT s
= es
->selection_start
;
2131 INT e
= es
->selection_end
;
2132 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2133 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2134 INT x
= (short)LOWORD(pos
);
2135 INT y
= (short)HIWORD(pos
);
2137 e
= EDIT_CharFromPos(es
, x
,
2138 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2142 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2143 EDIT_EM_ScrollCaret(es
);
2147 /*********************************************************************
2151 * Only for multi line controls
2152 * Move the caret one line up, on a column with the nearest
2153 * x coordinate on the screen (might be a different column).
2156 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2158 INT s
= es
->selection_start
;
2159 INT e
= es
->selection_end
;
2160 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2161 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2162 INT x
= (short)LOWORD(pos
);
2163 INT y
= (short)HIWORD(pos
);
2165 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2168 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2169 EDIT_EM_ScrollCaret(es
);
2173 /*********************************************************************
2175 * EDIT_MoveWordBackward
2178 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2180 INT s
= es
->selection_start
;
2181 INT e
= es
->selection_end
;
2186 l
= EDIT_EM_LineFromChar(es
, e
);
2187 ll
= EDIT_EM_LineLength(es
, e
);
2188 li
= EDIT_EM_LineIndex(es
, l
);
2191 li
= EDIT_EM_LineIndex(es
, l
- 1);
2192 e
= li
+ EDIT_EM_LineLength(es
, li
);
2195 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2196 li
, e
- li
, ll
, WB_LEFT
);
2200 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2201 EDIT_EM_ScrollCaret(es
);
2205 /*********************************************************************
2207 * EDIT_MoveWordForward
2210 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2212 INT s
= es
->selection_start
;
2213 INT e
= es
->selection_end
;
2218 l
= EDIT_EM_LineFromChar(es
, e
);
2219 ll
= EDIT_EM_LineLength(es
, e
);
2220 li
= EDIT_EM_LineIndex(es
, l
);
2222 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2223 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2225 e
= li
+ EDIT_CallWordBreakProc(es
,
2226 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2230 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2231 EDIT_EM_ScrollCaret(es
);
2235 /*********************************************************************
2240 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2242 INT s
= es
->selection_start
;
2243 INT e
= es
->selection_end
;
2250 if (es
->style
& ES_MULTILINE
) {
2251 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2252 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2257 TRACE("line=%d\n", line
);
2259 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2260 x
= (short)LOWORD(pos
);
2261 y
= (short)HIWORD(pos
);
2262 li
= EDIT_EM_LineIndex(es
, line
);
2263 ll
= EDIT_EM_LineLength(es
, li
);
2264 s
= min(es
->selection_start
, es
->selection_end
);
2265 e
= max(es
->selection_start
, es
->selection_end
);
2266 s
= min(li
+ ll
, max(li
, s
));
2267 e
= min(li
+ ll
, max(li
, e
));
2268 if (rev
&& (s
!= e
) &&
2269 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2270 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2271 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2272 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2274 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2278 /*********************************************************************
2283 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2287 LOGFONTW underline_font
;
2288 HFONT hUnderline
= 0;
2297 BkMode
= GetBkMode(dc
);
2298 BkColor
= GetBkColor(dc
);
2299 TextColor
= GetTextColor(dc
);
2301 if (es
->composition_len
== 0)
2303 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2304 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2305 SetBkMode( dc
, OPAQUE
);
2309 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2310 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2311 underline_font
.lfUnderline
= TRUE
;
2312 hUnderline
= CreateFontIndirectW(&underline_font
);
2313 old_font
= SelectObject(dc
,hUnderline
);
2316 li
= EDIT_EM_LineIndex(es
, line
);
2317 if (es
->style
& ES_MULTILINE
) {
2318 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2319 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2321 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2322 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2323 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2325 if (es
->style
& ES_PASSWORD
)
2326 HeapFree(GetProcessHeap(), 0, text
);
2329 if (es
->composition_len
== 0)
2331 SetBkColor(dc
, BkColor
);
2332 SetTextColor(dc
, TextColor
);
2333 SetBkMode( dc
, BkMode
);
2338 SelectObject(dc
,old_font
);
2340 DeleteObject(hUnderline
);
2347 /*********************************************************************
2352 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
2355 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
2356 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
2357 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
2361 /*********************************************************************
2363 * EDIT_AdjustFormatRect
2365 * Adjusts the format rectangle for the current font and the
2366 * current client rectangle.
2369 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2373 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2374 if (es
->style
& ES_MULTILINE
)
2376 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2378 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2379 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2381 /* correct es->x_offset */
2382 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2383 max_x_offset
= es
->text_width
- fw
;
2384 if(max_x_offset
< 0) max_x_offset
= 0;
2385 if(es
->x_offset
> max_x_offset
)
2386 es
->x_offset
= max_x_offset
;
2388 /* correct es->y_offset */
2389 max_y_offset
= es
->line_count
- vlc
;
2390 if(max_y_offset
< 0) max_y_offset
= 0;
2391 if(es
->y_offset
> max_y_offset
)
2392 es
->y_offset
= max_y_offset
;
2394 /* force scroll info update */
2395 EDIT_UpdateScrollInfo(es
);
2398 /* Windows doesn't care to fix text placement for SL controls */
2399 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2401 /* Always stay within the client area */
2402 GetClientRect(es
->hwndSelf
, &ClientRect
);
2403 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2405 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2406 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
2408 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2412 /*********************************************************************
2416 * note: this is not (exactly) the handler called on EM_SETRECTNP
2417 * it is also used to set the rect of a single line control
2420 static void EDIT_SetRectNP(EDITSTATE
*es
, LPRECT rc
)
2424 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2426 CopyRect(&es
->format_rect
, rc
);
2428 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2429 es
->format_rect
.left
++;
2430 es
->format_rect
.right
--;
2432 if (es
->format_rect
.bottom
- es
->format_rect
.top
2433 >= es
->line_height
+ 2)
2435 es
->format_rect
.top
++;
2436 es
->format_rect
.bottom
--;
2439 else if (es
->style
& WS_BORDER
) {
2440 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2441 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2442 es
->format_rect
.left
+= bw
;
2443 es
->format_rect
.right
-= bw
;
2444 if (es
->format_rect
.bottom
- es
->format_rect
.top
2445 >= es
->line_height
+ 2 * bh
)
2447 es
->format_rect
.top
+= bh
;
2448 es
->format_rect
.bottom
-= bh
;
2452 es
->format_rect
.left
+= es
->left_margin
;
2453 es
->format_rect
.right
-= es
->right_margin
;
2454 EDIT_AdjustFormatRect(es
);
2458 /*********************************************************************
2463 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
2466 /* Edit window might be already destroyed */
2467 if(!IsWindow(es
->hwndSelf
))
2469 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
2473 if (!es
->lock_count
) {
2474 ERR("lock_count == 0 ... please report\n");
2478 ERR("es->text == 0 ... please report\n");
2482 if (force
|| (es
->lock_count
== 1)) {
2486 UINT countW
= strlenW(es
->text
) + 1;
2487 STACK16FRAME
* stack16
= NULL
;
2492 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2493 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2494 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2495 countA
= LocalSize(es
->hloc32A
);
2496 if(countA_new
> countA
)
2499 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2500 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2501 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2504 es
->hloc32A
= hloc32A_new
;
2505 countA
= LocalSize(hloc32A_new
);
2506 TRACE("Real new size %d bytes\n", countA
);
2509 WARN("FAILED! Will synchronize partially\n");
2511 textA
= LocalLock(es
->hloc32A
);
2515 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2517 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2518 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2520 stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
2521 oldDS
= stack16
->ds
;
2522 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2524 countA
= LocalSize16(es
->hloc16
);
2525 if(countA_new
> countA
)
2527 HLOCAL16 hloc16_new
;
2528 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2529 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2530 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2533 es
->hloc16
= hloc16_new
;
2534 countA
= LocalSize16(hloc16_new
);
2535 TRACE("Real new size %d bytes\n", countA
);
2538 WARN("FAILED! Will synchronize partially\n");
2540 textA
= MapSL(LocalLock16(es
->hloc16
));
2545 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2547 LocalUnlock16(es
->hloc16
);
2549 LocalUnlock(es
->hloc32A
);
2552 if (stack16
) stack16
->ds
= oldDS
;
2553 LocalUnlock(es
->hloc32W
);
2557 ERR("no buffer ... please report\n");
2565 /*********************************************************************
2567 * EDIT_UpdateScrollInfo
2570 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
2572 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2575 si
.cbSize
= sizeof(SCROLLINFO
);
2576 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2578 si
.nMax
= es
->line_count
- 1;
2579 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2580 si
.nPos
= es
->y_offset
;
2581 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2582 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2583 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
2586 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2589 si
.cbSize
= sizeof(SCROLLINFO
);
2590 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2592 si
.nMax
= es
->text_width
- 1;
2593 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2594 si
.nPos
= es
->x_offset
;
2595 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2596 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2597 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
2601 /*********************************************************************
2603 * EDIT_WordBreakProc
2605 * Find the beginning of words.
2606 * Note: unlike the specs for a WordBreakProc, this function only
2607 * allows to be called without linebreaks between s[0] up to
2608 * s[count - 1]. Remember it is only called
2609 * internally, so we can decide this for ourselves.
2612 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2616 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2626 if (s
[index
] == ' ') {
2627 while (index
&& (s
[index
] == ' '))
2630 while (index
&& (s
[index
] != ' '))
2632 if (s
[index
] == ' ')
2636 while (index
&& (s
[index
] != ' '))
2638 if (s
[index
] == ' ')
2648 if (s
[index
] == ' ')
2649 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2651 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2653 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2657 case WB_ISDELIMITER
:
2658 ret
= (s
[index
] == ' ');
2661 ERR("unknown action code, please report !\n");
2668 /*********************************************************************
2672 * returns line number (not index) in high-order word of result.
2673 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2674 * to Richedit, not to the edit control. Original documentation is valid.
2675 * FIXME: do the specs mean to return -1 if outside client area or
2676 * if outside formatting rectangle ???
2679 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2687 GetClientRect(es
->hwndSelf
, &rc
);
2688 if (!PtInRect(&rc
, pt
))
2691 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2692 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2696 /*********************************************************************
2700 * Enable or disable soft breaks.
2702 * This means: insert or remove the soft linebreak character (\r\r\n).
2703 * Take care to check if the text still fits the buffer after insertion.
2704 * If not, notify with EN_ERRSPACE.
2707 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2709 es
->flags
&= ~EF_USE_SOFTBRK
;
2711 es
->flags
|= EF_USE_SOFTBRK
;
2712 FIXME("soft break enabled, not implemented\n");
2718 /*********************************************************************
2722 * Hopefully this won't fire back at us.
2723 * We always start with a fixed buffer in the local heap.
2724 * Despite of the documentation says that the local heap is used
2725 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2726 * buffer on the local heap.
2729 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2733 if (!(es
->style
& ES_MULTILINE
))
2737 hLocal
= es
->hloc32W
;
2743 UINT countA
, alloc_size
;
2744 TRACE("Allocating 32-bit ANSI alias buffer\n");
2745 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2746 alloc_size
= ROUND_TO_GROW(countA
);
2747 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2749 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2752 textA
= LocalLock(es
->hloc32A
);
2753 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2754 LocalUnlock(es
->hloc32A
);
2756 hLocal
= es
->hloc32A
;
2759 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2764 /*********************************************************************
2768 * Hopefully this won't fire back at us.
2769 * We always start with a buffer in 32 bit linear memory.
2770 * However, with this message a 16 bit application requests
2771 * a handle of 16 bit local heap memory, where it expects to find
2773 * It's a pitty that from this moment on we have to use this
2774 * local heap, because applications may rely on the handle
2777 * In this function we'll try to switch to local heap.
2779 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2782 UINT countA
, alloc_size
;
2783 STACK16FRAME
* stack16
;
2786 if (!(es
->style
& ES_MULTILINE
))
2792 stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
2793 oldDS
= stack16
->ds
;
2794 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2796 if (!LocalHeapSize16()) {
2798 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2799 ERR("could not initialize local heap\n");
2802 TRACE("local heap initialized\n");
2805 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2806 alloc_size
= ROUND_TO_GROW(countA
);
2808 TRACE("Allocating 16-bit ANSI alias buffer\n");
2809 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2810 ERR("could not allocate new 16 bit buffer\n");
2814 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2815 ERR("could not lock new 16 bit buffer\n");
2816 LocalFree16(es
->hloc16
);
2821 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2822 LocalUnlock16(es
->hloc16
);
2824 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2827 stack16
->ds
= oldDS
;
2832 /*********************************************************************
2837 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2840 INT line_len
, dst_len
;
2843 if (es
->style
& ES_MULTILINE
) {
2844 if (line
>= es
->line_count
)
2848 i
= EDIT_EM_LineIndex(es
, line
);
2850 line_len
= EDIT_EM_LineLength(es
, i
);
2851 dst_len
= *(WORD
*)dst
;
2854 if(dst_len
<= line_len
)
2856 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2859 else /* Append 0 if enough space */
2861 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2868 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2869 if(!ret
&& line_len
) /* Insufficient buffer size */
2871 if(ret
< dst_len
) /* Append 0 if enough space */
2872 ((LPSTR
)dst
)[ret
] = 0;
2878 /*********************************************************************
2883 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, PUINT start
, PUINT end
)
2885 UINT s
= es
->selection_start
;
2886 UINT e
= es
->selection_end
;
2893 return MAKELONG(s
, e
);
2897 /*********************************************************************
2901 * FIXME: is this right ? (or should it be only VSCROLL)
2902 * (and maybe only for edit controls that really have their
2903 * own scrollbars) (and maybe only for multiline controls ?)
2904 * All in all: very poorly documented
2907 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
2909 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
2910 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
2914 /*********************************************************************
2919 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2924 if (!(es
->style
& ES_MULTILINE
))
2926 if (index
> (INT
)strlenW(es
->text
))
2927 return es
->line_count
- 1;
2929 index
= min(es
->selection_start
, es
->selection_end
);
2932 line_def
= es
->first_line_def
;
2933 index
-= line_def
->length
;
2934 while ((index
>= 0) && line_def
->next
) {
2936 line_def
= line_def
->next
;
2937 index
-= line_def
->length
;
2943 /*********************************************************************
2948 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2953 if (!(es
->style
& ES_MULTILINE
))
2955 if (line
>= es
->line_count
)
2959 line_def
= es
->first_line_def
;
2961 INT index
= es
->selection_end
- line_def
->length
;
2962 while ((index
>= 0) && line_def
->next
) {
2963 line_index
+= line_def
->length
;
2964 line_def
= line_def
->next
;
2965 index
-= line_def
->length
;
2969 line_index
+= line_def
->length
;
2970 line_def
= line_def
->next
;
2978 /*********************************************************************
2983 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2987 if (!(es
->style
& ES_MULTILINE
))
2988 return strlenW(es
->text
);
2991 /* get the number of remaining non-selected chars of selected lines */
2992 INT32 l
; /* line number */
2993 INT32 li
; /* index of first char in line */
2995 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2996 /* # chars before start of selection area */
2997 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
2998 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2999 /* # chars after end of selection */
3000 li
= EDIT_EM_LineIndex(es
, l
);
3001 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
3004 line_def
= es
->first_line_def
;
3005 index
-= line_def
->length
;
3006 while ((index
>= 0) && line_def
->next
) {
3007 line_def
= line_def
->next
;
3008 index
-= line_def
->length
;
3010 return line_def
->net_length
;
3014 /*********************************************************************
3018 * NOTE: dx is in average character widths, dy - in lines;
3021 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
3023 if (!(es
->style
& ES_MULTILINE
))
3026 dx
*= es
->char_width
;
3027 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3030 /*********************************************************************
3032 * EDIT_EM_LineScroll_internal
3034 * Version of EDIT_EM_LineScroll for internal use.
3035 * It doesn't refuse if ES_MULTILINE is set and assumes that
3036 * dx is in pixels, dy - in lines.
3039 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
3042 INT x_offset_in_pixels
;
3043 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
3046 if (es
->style
& ES_MULTILINE
)
3048 x_offset_in_pixels
= es
->x_offset
;
3053 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
3056 if (-dx
> x_offset_in_pixels
)
3057 dx
= -x_offset_in_pixels
;
3058 if (dx
> es
->text_width
- x_offset_in_pixels
)
3059 dx
= es
->text_width
- x_offset_in_pixels
;
3060 nyoff
= max(0, es
->y_offset
+ dy
);
3061 if (nyoff
>= es
->line_count
- lines_per_page
)
3062 nyoff
= max(0, es
->line_count
- lines_per_page
);
3063 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
3068 es
->y_offset
= nyoff
;
3069 if(es
->style
& ES_MULTILINE
)
3072 es
->x_offset
+= dx
/ es
->char_width
;
3074 GetClientRect(es
->hwndSelf
, &rc1
);
3075 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
3076 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
3077 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
3078 /* force scroll info update */
3079 EDIT_UpdateScrollInfo(es
);
3081 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
3082 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3083 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
3084 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
3089 /*********************************************************************
3094 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
3096 INT len
= strlenW(es
->text
);
3109 index
= min(index
, len
);
3110 dc
= GetDC(es
->hwndSelf
);
3112 old_font
= SelectObject(dc
, es
->font
);
3113 if (es
->style
& ES_MULTILINE
) {
3114 l
= EDIT_EM_LineFromChar(es
, index
);
3115 y
= (l
- es
->y_offset
) * es
->line_height
;
3116 li
= EDIT_EM_LineIndex(es
, l
);
3117 if (after_wrap
&& (li
== index
) && l
) {
3119 line_def
= es
->first_line_def
;
3121 line_def
= line_def
->next
;
3124 if (line_def
->ending
== END_WRAP
) {
3126 y
-= es
->line_height
;
3127 li
= EDIT_EM_LineIndex(es
, l
);
3131 line_def
= es
->first_line_def
;
3132 while (line_def
->index
!= li
)
3133 line_def
= line_def
->next
;
3135 ll
= line_def
->net_length
;
3136 lw
= line_def
->width
;
3138 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3139 if (es
->style
& ES_RIGHT
)
3141 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
3142 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3145 else if (es
->style
& ES_CENTER
)
3147 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3148 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3153 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
3154 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
3157 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
3158 if (index
< es
->x_offset
) {
3159 GetTextExtentPoint32W(dc
, text
+ index
,
3160 es
->x_offset
- index
, &size
);
3163 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
3164 index
- es
->x_offset
, &size
);
3167 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
3169 w
= es
->format_rect
.right
- es
->format_rect
.left
;
3170 if (w
> es
->text_width
)
3172 if (es
->style
& ES_RIGHT
)
3173 x
+= w
- es
->text_width
;
3174 else if (es
->style
& ES_CENTER
)
3175 x
+= (w
- es
->text_width
) / 2;
3180 if (es
->style
& ES_PASSWORD
)
3181 HeapFree(GetProcessHeap(), 0, text
);
3183 x
+= es
->format_rect
.left
;
3184 y
+= es
->format_rect
.top
;
3186 SelectObject(dc
, old_font
);
3187 ReleaseDC(es
->hwndSelf
, dc
);
3188 return MAKELONG((INT16
)x
, (INT16
)y
);
3192 /*********************************************************************
3196 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
3199 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
3201 UINT strl
= strlenW(lpsz_replace
);
3202 UINT tl
= strlenW(es
->text
);
3213 TRACE("%s, can_undo %d, send_update %d\n",
3214 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3216 s
= es
->selection_start
;
3217 e
= es
->selection_end
;
3219 if ((s
== e
) && !strl
)
3224 size
= tl
- (e
- s
) + strl
;
3228 /* Issue the EN_MAXTEXT notification and continue with replacing text
3229 * such that buffer limit is honored. */
3230 if ((honor_limit
) && (es
->buffer_limit
> 0) && (size
> es
->buffer_limit
)) {
3231 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3232 strl
= es
->buffer_limit
- (tl
- (e
-s
));
3235 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
3239 /* there is something to be deleted */
3240 TRACE("deleting stuff.\n");
3242 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
3244 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
3245 buf
[bufl
] = 0; /* ensure 0 termination */
3247 strcpyW(es
->text
+ s
, es
->text
+ e
);
3250 /* there is an insertion */
3251 tl
= strlenW(es
->text
);
3252 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
));
3253 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3255 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3256 p
[i
] = lpsz_replace
[i
];
3257 if(es
->style
& ES_UPPERCASE
)
3258 CharUpperBuffW(p
, strl
);
3259 else if(es
->style
& ES_LOWERCASE
)
3260 CharLowerBuffW(p
, strl
);
3262 if (es
->style
& ES_MULTILINE
)
3264 INT st
= min(es
->selection_start
, es
->selection_end
);
3265 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3267 hrgn
= CreateRectRgn(0, 0, 0, 0);
3268 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
3269 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3270 /* if text is too long undo all changes */
3271 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
3273 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
3275 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
3277 EDIT_BuildLineDefs_ML(es
, s
, e
,
3278 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
3281 hrgn
= CreateRectRgn(0, 0, 0, 0);
3282 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3286 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3287 EDIT_CalcLineWidth_SL(es
);
3288 /* remove chars that don't fit */
3289 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
3290 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
3291 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
3293 EDIT_CalcLineWidth_SL(es
);
3295 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
3301 utl
= strlenW(es
->undo_text
);
3302 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3303 /* undo-buffer is extended to the right */
3304 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3305 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
3306 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3307 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3308 /* undo-buffer is extended to the left */
3309 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3310 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3312 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3314 es
->undo_position
= s
;
3316 /* new undo-buffer */
3317 EDIT_MakeUndoFit(es
, e
- s
);
3318 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
3319 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3320 es
->undo_position
= s
;
3322 /* any deletion makes the old insertion-undo invalid */
3323 es
->undo_insert_count
= 0;
3325 EDIT_EM_EmptyUndoBuffer(es
);
3329 if ((s
== es
->undo_position
) ||
3330 ((es
->undo_insert_count
) &&
3331 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3333 * insertion is new and at delete position or
3334 * an extension to either left or right
3336 es
->undo_insert_count
+= strl
;
3338 /* new insertion undo */
3339 es
->undo_position
= s
;
3340 es
->undo_insert_count
= strl
;
3341 /* new insertion makes old delete-buffer invalid */
3342 *es
->undo_text
= '\0';
3345 EDIT_EM_EmptyUndoBuffer(es
);
3349 HeapFree(GetProcessHeap(), 0, buf
);
3353 /* If text has been deleted and we're right or center aligned then scroll rightward */
3354 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
3356 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
3358 if (delta
< 0 && es
->x_offset
)
3360 if (abs(delta
) > es
->x_offset
)
3363 es
->x_offset
+= delta
;
3367 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
3368 es
->flags
|= EF_MODIFIED
;
3369 if (send_update
) es
->flags
|= EF_UPDATE
;
3372 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
3376 EDIT_UpdateText(es
, NULL
, TRUE
);
3378 EDIT_EM_ScrollCaret(es
);
3380 /* force scroll info update */
3381 EDIT_UpdateScrollInfo(es
);
3384 if(send_update
|| (es
->flags
& EF_UPDATE
))
3386 es
->flags
&= ~EF_UPDATE
;
3387 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3392 /*********************************************************************
3397 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
3401 if (!(es
->style
& ES_MULTILINE
))
3402 return (LRESULT
)FALSE
;
3412 if (es
->y_offset
< es
->line_count
- 1)
3417 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3420 if (es
->y_offset
< es
->line_count
- 1)
3421 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3424 return (LRESULT
)FALSE
;
3427 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3428 /* check if we are going to move too far */
3429 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3430 dy
= es
->line_count
- vlc
- es
->y_offset
;
3432 /* Notification is done in EDIT_EM_LineScroll */
3434 EDIT_EM_LineScroll(es
, 0, dy
);
3436 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3440 /*********************************************************************
3445 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
3447 if (es
->style
& ES_MULTILINE
) {
3452 INT cw
= es
->char_width
;
3457 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3458 li
= EDIT_EM_LineIndex(es
, l
);
3459 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3460 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3461 if (l
>= es
->y_offset
+ vlc
)
3462 dy
= l
- vlc
+ 1 - es
->y_offset
;
3463 if (l
< es
->y_offset
)
3464 dy
= l
- es
->y_offset
;
3465 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3466 if (x
< es
->format_rect
.left
)
3467 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3468 if (x
> es
->format_rect
.right
)
3469 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3470 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3472 /* check if we are going to move too far */
3473 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3474 dx
= es
->text_width
- ww
- es
->x_offset
;
3475 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
3476 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
3483 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3484 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3485 if (x
< es
->format_rect
.left
) {
3486 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3489 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3490 } while ((x
< goal
) && es
->x_offset
);
3491 /* FIXME: use ScrollWindow() somehow to improve performance */
3492 EDIT_UpdateText(es
, NULL
, TRUE
);
3493 } else if (x
> es
->format_rect
.right
) {
3495 INT len
= strlenW(es
->text
);
3496 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3499 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
3500 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
3501 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3502 /* FIXME: use ScrollWindow() somehow to improve performance */
3503 EDIT_UpdateText(es
, NULL
, TRUE
);
3507 if(es
->flags
& EF_FOCUSED
)
3508 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3512 /*********************************************************************
3516 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3519 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
3521 if (!(es
->style
& ES_MULTILINE
))
3525 WARN("called with NULL handle\n");
3529 EDIT_UnlockBuffer(es
, TRUE
);
3533 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
3534 HANDLE16 oldDS
= stack16
->ds
;
3536 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3537 LocalFree16(es
->hloc16
);
3538 stack16
->ds
= oldDS
;
3546 LocalFree(es
->hloc32A
);
3558 countA
= LocalSize(hloc
);
3559 textA
= LocalLock(hloc
);
3560 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3561 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3563 ERR("Could not allocate new unicode buffer\n");
3566 textW
= LocalLock(hloc32W_new
);
3567 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3568 LocalUnlock(hloc32W_new
);
3572 LocalFree(es
->hloc32W
);
3574 es
->hloc32W
= hloc32W_new
;
3578 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3580 EDIT_LockBuffer(es
);
3582 es
->x_offset
= es
->y_offset
= 0;
3583 es
->selection_start
= es
->selection_end
= 0;
3584 EDIT_EM_EmptyUndoBuffer(es
);
3585 es
->flags
&= ~EF_MODIFIED
;
3586 es
->flags
&= ~EF_UPDATE
;
3587 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3588 EDIT_UpdateText(es
, NULL
, TRUE
);
3589 EDIT_EM_ScrollCaret(es
);
3590 /* force scroll info update */
3591 EDIT_UpdateScrollInfo(es
);
3595 /*********************************************************************
3599 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3602 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
3604 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
3605 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
3606 HANDLE16 oldDS
= stack16
->ds
;
3612 if (!(es
->style
& ES_MULTILINE
))
3616 WARN("called with NULL handle\n");
3620 EDIT_UnlockBuffer(es
, TRUE
);
3624 LocalFree(es
->hloc32A
);
3628 stack16
->ds
= hInstance
;
3629 countA
= LocalSize16(hloc
);
3630 textA
= MapSL(LocalLock16(hloc
));
3631 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3632 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3634 ERR("Could not allocate new unicode buffer\n");
3637 textW
= LocalLock(hloc32W_new
);
3638 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3639 LocalUnlock(hloc32W_new
);
3640 LocalUnlock16(hloc
);
3641 stack16
->ds
= oldDS
;
3644 LocalFree(es
->hloc32W
);
3646 es
->hloc32W
= hloc32W_new
;
3649 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3651 EDIT_LockBuffer(es
);
3653 es
->x_offset
= es
->y_offset
= 0;
3654 es
->selection_start
= es
->selection_end
= 0;
3655 EDIT_EM_EmptyUndoBuffer(es
);
3656 es
->flags
&= ~EF_MODIFIED
;
3657 es
->flags
&= ~EF_UPDATE
;
3658 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3659 EDIT_UpdateText(es
, NULL
, TRUE
);
3660 EDIT_EM_ScrollCaret(es
);
3661 /* force scroll info update */
3662 EDIT_UpdateScrollInfo(es
);
3666 /*********************************************************************
3670 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3671 * However, the windows version is not complied to yet in all of edit.c
3673 * Additionally as the wrapper for RichEdit controls we need larger buffers
3674 * at present -1 will represent nolimit
3676 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3678 if (limit
== 0xFFFFFFFF)
3679 es
->buffer_limit
= -1;
3680 else if (es
->style
& ES_MULTILINE
) {
3682 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3684 es
->buffer_limit
= BUFLIMIT_MULTI
;
3687 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3689 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3694 /*********************************************************************
3698 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3699 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3700 * margin according to the textmetrics of the current font.
3702 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3703 * of the char's width as the margin, but this is not how Windows handles this.
3704 * For all other fonts Windows sets the margins to zero.
3706 * FIXME - When EC_USEFONTINFO is used the margins only change if the
3707 * edit control is equal to or larger than a certain size.
3708 * Interestingly if one subtracts both the left and right margins from
3709 * this size one always seems to get an even number. The extents of
3710 * the (four character) string "'**'" match this quite closely, so
3711 * we'll use this until we come up with a better idea.
3713 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
3715 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
3718 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
3719 return sz
.cx
+ left
+ right
;
3722 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3723 WORD left
, WORD right
, BOOL repaint
)
3726 INT default_left_margin
= 0; /* in pixels */
3727 INT default_right_margin
= 0; /* in pixels */
3729 /* Set the default margins depending on the font */
3730 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
3731 HDC dc
= GetDC(es
->hwndSelf
);
3732 HFONT old_font
= SelectObject(dc
, es
->font
);
3733 GetTextMetricsW(dc
, &tm
);
3734 /* The default margins are only non zero for TrueType or Vector fonts */
3735 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
3738 /* This must be calculated more exactly! But how? */
3739 default_left_margin
= tm
.tmAveCharWidth
/ 2;
3740 default_right_margin
= tm
.tmAveCharWidth
/ 2;
3741 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
3742 GetClientRect(es
->hwndSelf
, &rc
);
3743 if(rc
.right
- rc
.left
< min_size
) {
3744 default_left_margin
= es
->left_margin
;
3745 default_right_margin
= es
->right_margin
;
3748 SelectObject(dc
, old_font
);
3749 ReleaseDC(es
->hwndSelf
, dc
);
3752 if (action
& EC_LEFTMARGIN
) {
3753 es
->format_rect
.left
-= es
->left_margin
;
3754 if (left
!= EC_USEFONTINFO
)
3755 es
->left_margin
= left
;
3757 es
->left_margin
= default_left_margin
;
3758 es
->format_rect
.left
+= es
->left_margin
;
3761 if (action
& EC_RIGHTMARGIN
) {
3762 es
->format_rect
.right
+= es
->right_margin
;
3763 if (right
!= EC_USEFONTINFO
)
3764 es
->right_margin
= right
;
3766 es
->right_margin
= default_right_margin
;
3767 es
->format_rect
.right
-= es
->right_margin
;
3770 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3771 EDIT_AdjustFormatRect(es
);
3772 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3775 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3779 /*********************************************************************
3781 * EM_SETPASSWORDCHAR
3784 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3788 if (es
->style
& ES_MULTILINE
)
3791 if (es
->password_char
== c
)
3794 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3795 es
->password_char
= c
;
3797 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3798 es
->style
|= ES_PASSWORD
;
3800 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3801 es
->style
&= ~ES_PASSWORD
;
3803 EDIT_UpdateText(es
, NULL
, TRUE
);
3807 /*********************************************************************
3811 * note: unlike the specs say: the order of start and end
3812 * _is_ preserved in Windows. (i.e. start can be > end)
3813 * In other words: this handler is OK
3816 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3818 UINT old_start
= es
->selection_start
;
3819 UINT old_end
= es
->selection_end
;
3820 UINT len
= strlenW(es
->text
);
3822 if (start
== (UINT
)-1) {
3823 start
= es
->selection_end
;
3824 end
= es
->selection_end
;
3826 start
= min(start
, len
);
3827 end
= min(end
, len
);
3829 es
->selection_start
= start
;
3830 es
->selection_end
= end
;
3832 es
->flags
|= EF_AFTER_WRAP
;
3834 es
->flags
&= ~EF_AFTER_WRAP
;
3835 /* Compute the necessary invalidation region. */
3836 /* Note that we don't need to invalidate regions which have
3837 * "never" been selected, or those which are "still" selected.
3838 * In fact, every time we hit a selection boundary, we can
3839 * *toggle* whether we need to invalidate. Thus we can optimize by
3840 * *sorting* the interval endpoints. Let's assume that we sort them
3842 * start <= end <= old_start <= old_end
3843 * Knuth 5.3.1 (p 183) asssures us that this can be done optimally
3844 * in 5 comparisons; ie it's impossible to do better than the
3846 ORDER_UINT(end
, old_end
);
3847 ORDER_UINT(start
, old_start
);
3848 ORDER_UINT(old_start
, old_end
);
3849 ORDER_UINT(start
, end
);
3850 /* Note that at this point 'end' and 'old_start' are not in order, but
3851 * start is definitely the min. and old_end is definitely the max. */
3852 if (end
!= old_start
)
3856 * ORDER_UINT32(end, old_start);
3857 * EDIT_InvalidateText(es, start, end);
3858 * EDIT_InvalidateText(es, old_start, old_end);
3859 * in place of the following if statement.
3860 * (That would complete the optimal five-comparison four-element sort.)
3862 if (old_start
> end
)
3864 EDIT_InvalidateText(es
, start
, end
);
3865 EDIT_InvalidateText(es
, old_start
, old_end
);
3869 EDIT_InvalidateText(es
, start
, old_start
);
3870 EDIT_InvalidateText(es
, end
, old_end
);
3873 else EDIT_InvalidateText(es
, start
, old_end
);
3877 /*********************************************************************
3882 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3884 if (!(es
->style
& ES_MULTILINE
))
3886 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3887 es
->tabs_count
= count
;
3891 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3892 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3898 /*********************************************************************
3903 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3905 if (!(es
->style
& ES_MULTILINE
))
3907 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3908 es
->tabs_count
= count
;
3913 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3914 for (i
= 0 ; i
< count
; i
++)
3915 es
->tabs
[i
] = *tabs
++;
3921 /*********************************************************************
3923 * EM_SETWORDBREAKPROC
3926 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3928 if (es
->word_break_proc
== wbp
)
3931 es
->word_break_proc
= wbp
;
3932 es
->word_break_proc16
= NULL
;
3934 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3935 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3936 EDIT_UpdateText(es
, NULL
, TRUE
);
3941 /*********************************************************************
3943 * EM_SETWORDBREAKPROC16
3946 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3948 if (es
->word_break_proc16
== wbp
)
3951 es
->word_break_proc
= NULL
;
3952 es
->word_break_proc16
= wbp
;
3953 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3954 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
3955 EDIT_UpdateText(es
, NULL
, TRUE
);
3960 /*********************************************************************
3965 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3970 /* As per MSDN spec, for a single-line edit control,
3971 the return value is always TRUE */
3972 if( es
->style
& ES_READONLY
)
3973 return !(es
->style
& ES_MULTILINE
);
3975 ulength
= strlenW(es
->undo_text
);
3977 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3979 strcpyW(utext
, es
->undo_text
);
3981 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3982 es
->undo_insert_count
, debugstr_w(utext
));
3984 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3985 EDIT_EM_EmptyUndoBuffer(es
);
3986 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3987 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3988 /* send the notification after the selection start and end are set */
3989 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3990 EDIT_EM_ScrollCaret(es
);
3991 HeapFree(GetProcessHeap(), 0, utext
);
3993 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3994 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3999 /*********************************************************************
4004 static void EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
4008 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4012 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
4013 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
4016 if (es
->style
& ES_MULTILINE
) {
4017 if (es
->style
& ES_READONLY
) {
4018 EDIT_MoveHome(es
, FALSE
);
4019 EDIT_MoveDown_ML(es
, FALSE
);
4021 static const WCHAR cr_lfW
[] = {'\r','\n',0};
4022 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
4027 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
4029 static const WCHAR tabW
[] = {'\t',0};
4030 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
4034 if (!(es
->style
& ES_READONLY
) && !control
) {
4035 if (es
->selection_start
!= es
->selection_end
)
4038 /* delete character left of caret */
4039 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4040 EDIT_MoveBackward(es
, TRUE
);
4046 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
4049 if (!(es
->style
& ES_READONLY
))
4050 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4053 if (!(es
->style
& ES_READONLY
))
4054 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
4058 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
4059 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
4062 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
4066 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
4073 /*********************************************************************
4078 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
4080 if (code
|| control
)
4100 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4101 EDIT_EM_ScrollCaret(es
);
4104 ERR("unknown menu item, please report\n");
4110 /*********************************************************************
4114 * Note: the resource files resource/sysres_??.rc cannot define a
4115 * single popup menu. Hence we use a (dummy) menubar
4116 * containing the single popup menu as its first item.
4118 * FIXME: the message identifiers have been chosen arbitrarily,
4119 * hence we use MF_BYPOSITION.
4120 * We might as well use the "real" values (anybody knows ?)
4121 * The menu definition is in resources/sysres_??.rc.
4122 * Once these are OK, we better use MF_BYCOMMAND here
4123 * (as we do in EDIT_WM_Command()).
4126 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
4128 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
4129 HMENU popup
= GetSubMenu(menu
, 0);
4130 UINT start
= es
->selection_start
;
4131 UINT end
= es
->selection_end
;
4133 ORDER_UINT(start
, end
);
4136 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4138 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4140 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
4142 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4144 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
4146 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
4148 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
4151 /* Windows places the menu at the edit's center in this case */
4152 GetClientRect(es
->hwndSelf
, &rc
);
4153 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
4154 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
4155 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
4158 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
4163 /*********************************************************************
4168 static void EDIT_WM_Copy(EDITSTATE
*es
)
4170 INT s
= min(es
->selection_start
, es
->selection_end
);
4171 INT e
= max(es
->selection_start
, es
->selection_end
);
4179 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
4180 dst
= GlobalLock(hdst
);
4181 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
4182 dst
[len
] = 0; /* ensure 0 termination */
4183 TRACE("%s\n", debugstr_w(dst
));
4185 OpenClipboard(es
->hwndSelf
);
4187 SetClipboardData(CF_UNICODETEXT
, hdst
);
4192 /*********************************************************************
4197 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4201 TRACE("%s\n", debugstr_w(name
));
4203 * To initialize some final structure members, we call some helper
4204 * functions. However, since the EDITSTATE is not consistent (i.e.
4205 * not fully initialized), we should be very careful which
4206 * functions can be called, and in what order.
4208 EDIT_WM_SetFont(es
, 0, FALSE
);
4209 EDIT_EM_EmptyUndoBuffer(es
);
4211 /* We need to calculate the format rect
4212 (applications may send EM_SETMARGINS before the control gets visible) */
4213 GetClientRect(es
->hwndSelf
, &clientRect
);
4214 EDIT_SetRectNP(es
, &clientRect
);
4216 if (name
&& *name
) {
4217 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4218 /* if we insert text to the editline, the text scrolls out
4219 * of the window, as the caret is placed after the insert
4220 * pos normally; thus we reset es->selection... to 0 and
4223 es
->selection_start
= es
->selection_end
= 0;
4224 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4225 * Messages are only to be sent when the USER does something to
4226 * change the contents. So I am removing this EN_CHANGE
4228 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4230 EDIT_EM_ScrollCaret(es
);
4232 /* force scroll info update */
4233 EDIT_UpdateScrollInfo(es
);
4234 /* The rule seems to return 1 here for success */
4235 /* Power Builder masked edit controls will crash */
4237 /* FIXME: is that in all cases so ? */
4242 /*********************************************************************
4247 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4252 while (LocalUnlock(es
->hloc32W
)) ;
4253 LocalFree(es
->hloc32W
);
4256 while (LocalUnlock(es
->hloc32A
)) ;
4257 LocalFree(es
->hloc32A
);
4260 STACK16FRAME
* stack16
= MapSL((SEGPTR
)NtCurrentTeb()->WOW32Reserved
);
4261 HANDLE16 oldDS
= stack16
->ds
;
4263 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4264 while (LocalUnlock16(es
->hloc16
)) ;
4265 LocalFree16(es
->hloc16
);
4266 stack16
->ds
= oldDS
;
4269 pc
= es
->first_line_def
;
4273 HeapFree(GetProcessHeap(), 0, pc
);
4277 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4278 HeapFree(GetProcessHeap(), 0, es
);
4284 /*********************************************************************
4289 static LRESULT
EDIT_WM_EraseBkGnd(EDITSTATE
*es
, HDC dc
)
4291 /* we do the proper erase in EDIT_WM_Paint */
4296 /*********************************************************************
4301 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
4303 WCHAR text
[MAX_PATH
];
4304 LPWSTR lptext
= es
->text
;
4306 if(!count
) return 0;
4308 if (USER32_DisplayUnixPaths(es
))
4310 INT len
= GetShortPathNameW(es
->text
, text
, MAX_PATH
);
4311 if (len
&& len
< MAX_PATH
)
4317 lstrcpynW(dst
, es
->text
, count
);
4318 return strlenW(dst
);
4322 LPSTR textA
= (LPSTR
)dst
;
4323 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
4324 textA
[count
- 1] = 0; /* ensure 0 termination */
4325 return strlen(textA
);
4329 /*********************************************************************
4334 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4339 if (!(es
->style
& ES_MULTILINE
))
4342 if (!(es
->style
& ES_AUTOHSCROLL
))
4346 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4349 TRACE("SB_LINELEFT\n");
4351 dx
= -es
->char_width
;
4354 TRACE("SB_LINERIGHT\n");
4355 if (es
->x_offset
< es
->text_width
)
4356 dx
= es
->char_width
;
4359 TRACE("SB_PAGELEFT\n");
4361 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4364 TRACE("SB_PAGERIGHT\n");
4365 if (es
->x_offset
< es
->text_width
)
4366 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4374 TRACE("SB_RIGHT\n");
4375 if (es
->x_offset
< es
->text_width
)
4376 dx
= es
->text_width
- es
->x_offset
;
4379 TRACE("SB_THUMBTRACK %d\n", pos
);
4380 es
->flags
|= EF_HSCROLL_TRACK
;
4381 if(es
->style
& WS_HSCROLL
)
4382 dx
= pos
- es
->x_offset
;
4387 if(pos
< 0 || pos
> 100) return 0;
4388 /* Assume default scroll range 0-100 */
4389 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4390 new_x
= pos
* (es
->text_width
- fw
) / 100;
4391 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4394 case SB_THUMBPOSITION
:
4395 TRACE("SB_THUMBPOSITION %d\n", pos
);
4396 es
->flags
&= ~EF_HSCROLL_TRACK
;
4397 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4398 dx
= pos
- es
->x_offset
;
4403 if(pos
< 0 || pos
> 100) return 0;
4404 /* Assume default scroll range 0-100 */
4405 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4406 new_x
= pos
* (es
->text_width
- fw
) / 100;
4407 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4410 /* force scroll info update */
4411 EDIT_UpdateScrollInfo(es
);
4412 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4416 TRACE("SB_ENDSCROLL\n");
4419 * FIXME : the next two are undocumented !
4420 * Are we doing the right thing ?
4421 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4422 * although it's also a regular control message.
4424 case EM_GETTHUMB
: /* this one is used by NT notepad */
4428 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4429 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4432 /* Assume default scroll range 0-100 */
4433 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4434 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4436 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4439 case EM_LINESCROLL16
:
4440 TRACE("EM_LINESCROLL16\n");
4445 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4451 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4452 /* check if we are going to move too far */
4453 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4454 dx
= es
->text_width
- fw
- es
->x_offset
;
4456 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4462 /*********************************************************************
4467 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
4469 HWND hLBox
= es
->hwndListBox
;
4477 hCombo
= GetParent(es
->hwndSelf
);
4481 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
4483 if (key
== VK_UP
|| key
== VK_DOWN
)
4485 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4488 if (msg
== WM_KEYDOWN
|| nEUI
)
4489 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4495 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4497 /* make sure ComboLBox pops up */
4498 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4503 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4506 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4508 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4510 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4515 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4521 /*********************************************************************
4525 * Handling of special keys that don't produce a WM_CHAR
4526 * (i.e. non-printable keys) & Backspace & Delete
4529 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
4534 if (GetKeyState(VK_MENU
) & 0x8000)
4537 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4538 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4543 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4548 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4549 EDIT_MoveUp_ML(es
, shift
);
4552 EDIT_MoveWordBackward(es
, shift
);
4554 EDIT_MoveBackward(es
, shift
);
4557 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
4561 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4562 EDIT_MoveDown_ML(es
, shift
);
4564 EDIT_MoveWordForward(es
, shift
);
4566 EDIT_MoveForward(es
, shift
);
4569 EDIT_MoveHome(es
, shift
);
4572 EDIT_MoveEnd(es
, shift
);
4575 if (es
->style
& ES_MULTILINE
)
4576 EDIT_MovePageUp_ML(es
, shift
);
4578 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4581 if (es
->style
& ES_MULTILINE
)
4582 EDIT_MovePageDown_ML(es
, shift
);
4584 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
4587 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4588 if (es
->selection_start
!= es
->selection_end
) {
4595 /* delete character left of caret */
4596 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4597 EDIT_MoveBackward(es
, TRUE
);
4599 } else if (control
) {
4600 /* delete to end of line */
4601 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4602 EDIT_MoveEnd(es
, TRUE
);
4605 /* delete character right of caret */
4606 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4607 EDIT_MoveForward(es
, TRUE
);
4615 if (!(es
->style
& ES_READONLY
))
4621 /* If the edit doesn't want the return send a message to the default object */
4622 if(!(es
->style
& ES_WANTRETURN
))
4624 HWND hwndParent
= GetParent(es
->hwndSelf
);
4625 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4626 if (HIWORD(dw
) == DC_HASDEFID
)
4628 SendMessageW( hwndParent
, WM_COMMAND
,
4629 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4630 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4639 /*********************************************************************
4644 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
4646 es
->flags
&= ~EF_FOCUSED
;
4648 if(!(es
->style
& ES_NOHIDESEL
))
4649 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
4650 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
4655 /*********************************************************************
4659 * The caret position has been set on the WM_LBUTTONDOWN message
4662 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
4665 INT e
= es
->selection_end
;
4670 es
->bCaptureState
= TRUE
;
4671 SetCapture(es
->hwndSelf
);
4673 l
= EDIT_EM_LineFromChar(es
, e
);
4674 li
= EDIT_EM_LineIndex(es
, l
);
4675 ll
= EDIT_EM_LineLength(es
, e
);
4676 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4677 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4678 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
4679 EDIT_EM_ScrollCaret(es
);
4680 es
->region_posx
= es
->region_posy
= 0;
4681 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4686 /*********************************************************************
4691 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4696 es
->bCaptureState
= TRUE
;
4697 SetCapture(es
->hwndSelf
);
4698 EDIT_ConfinePoint(es
, &x
, &y
);
4699 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4700 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4701 EDIT_EM_ScrollCaret(es
);
4702 es
->region_posx
= es
->region_posy
= 0;
4703 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
4705 if (!(es
->flags
& EF_FOCUSED
))
4706 SetFocus(es
->hwndSelf
);
4712 /*********************************************************************
4717 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
4719 if (es
->bCaptureState
) {
4720 KillTimer(es
->hwndSelf
, 0);
4721 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
4723 es
->bCaptureState
= FALSE
;
4728 /*********************************************************************
4733 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
4735 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
4740 /*********************************************************************
4745 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
4751 /* If the mouse has been captured by process other than the edit control itself,
4752 * the windows edit controls will not select the strings with mouse move.
4754 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
4758 * FIXME: gotta do some scrolling if outside client
4759 * area. Maybe reset the timer ?
4762 EDIT_ConfinePoint(es
, &x
, &y
);
4763 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4764 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4765 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
4766 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
4767 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
4772 /*********************************************************************
4776 * See also EDIT_WM_StyleChanged
4778 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4783 TRACE("Creating %s edit control, style = %08x\n",
4784 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4786 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4788 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4791 * Note: since the EDITSTATE has not been fully initialized yet,
4792 * we can't use any API calls that may send
4793 * WM_XXX messages before WM_NCCREATE is completed.
4796 es
->is_unicode
= unicode
;
4797 es
->style
= lpcs
->style
;
4799 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4801 es
->hwndSelf
= hwnd
;
4802 /* Save parent, which will be notified by EN_* messages */
4803 es
->hwndParent
= lpcs
->hwndParent
;
4805 if (es
->style
& ES_COMBO
)
4806 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4808 /* Number overrides lowercase overrides uppercase (at least it
4809 * does in Win95). However I'll bet that ES_NUMBER would be
4810 * invalid under Win 3.1.
4812 if (es
->style
& ES_NUMBER
) {
4813 ; /* do not override the ES_NUMBER */
4814 } else if (es
->style
& ES_LOWERCASE
) {
4815 es
->style
&= ~ES_UPPERCASE
;
4817 if (es
->style
& ES_MULTILINE
) {
4818 es
->buffer_limit
= BUFLIMIT_MULTI
;
4819 if (es
->style
& WS_VSCROLL
)
4820 es
->style
|= ES_AUTOVSCROLL
;
4821 if (es
->style
& WS_HSCROLL
)
4822 es
->style
|= ES_AUTOHSCROLL
;
4823 es
->style
&= ~ES_PASSWORD
;
4824 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4825 /* Confirmed - RIGHT overrides CENTER */
4826 if (es
->style
& ES_RIGHT
)
4827 es
->style
&= ~ES_CENTER
;
4828 es
->style
&= ~WS_HSCROLL
;
4829 es
->style
&= ~ES_AUTOHSCROLL
;
4832 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4833 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4834 es
->style
&= ~ES_CENTER
;
4835 es
->style
&= ~WS_HSCROLL
;
4836 es
->style
&= ~WS_VSCROLL
;
4837 if (es
->style
& ES_PASSWORD
)
4838 es
->password_char
= '*';
4841 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4842 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4844 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4846 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4848 es
->undo_buffer_size
= es
->buffer_size
;
4850 if (es
->style
& ES_MULTILINE
)
4851 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4856 * In Win95 look and feel, the WS_BORDER style is replaced by the
4857 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4858 * control a nonclient area so we don't need to draw the border.
4859 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4860 * a nonclient area and we should handle painting the border ourselves.
4862 * When making modifications please ensure that the code still works
4863 * for edit controls created directly with style 0x50800000, exStyle 0
4864 * (which should have a single pixel border)
4866 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4867 es
->style
&= ~WS_BORDER
;
4868 else if (es
->style
& WS_BORDER
)
4869 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4874 /*********************************************************************
4879 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
4892 BOOL rev
= es
->bEnableState
&&
4893 ((es
->flags
& EF_FOCUSED
) ||
4894 (es
->style
& ES_NOHIDESEL
));
4895 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
4897 GetClientRect(es
->hwndSelf
, &rcClient
);
4899 /* get the background brush */
4900 brush
= EDIT_NotifyCtlColor(es
, dc
);
4902 /* paint the border and the background */
4903 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
4905 if(es
->style
& WS_BORDER
) {
4906 bw
= GetSystemMetrics(SM_CXBORDER
);
4907 bh
= GetSystemMetrics(SM_CYBORDER
);
4909 if(es
->style
& ES_MULTILINE
) {
4910 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
4911 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
4914 /* Draw the frame. Same code as in nonclient.c */
4915 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
4916 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
4917 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4918 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
4919 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
4920 SelectObject(dc
, old_brush
);
4922 /* Keep the border clean */
4923 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
4924 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
4927 GetClipBox(dc
, &rc
);
4928 FillRect(dc
, &rc
, brush
);
4930 IntersectClipRect(dc
, es
->format_rect
.left
,
4931 es
->format_rect
.top
,
4932 es
->format_rect
.right
,
4933 es
->format_rect
.bottom
);
4934 if (es
->style
& ES_MULTILINE
) {
4936 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4939 old_font
= SelectObject(dc
, es
->font
);
4941 if (!es
->bEnableState
)
4942 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4943 GetClipBox(dc
, &rcRgn
);
4944 if (es
->style
& ES_MULTILINE
) {
4945 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4946 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4947 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
4948 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4949 EDIT_PaintLine(es
, dc
, i
, rev
);
4952 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
4953 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4954 EDIT_PaintLine(es
, dc
, 0, rev
);
4957 SelectObject(dc
, old_font
);
4960 EndPaint(es
->hwndSelf
, &ps
);
4964 /*********************************************************************
4969 static void EDIT_WM_Paste(EDITSTATE
*es
)
4974 /* Protect read-only edit control from modification */
4975 if(es
->style
& ES_READONLY
)
4978 OpenClipboard(es
->hwndSelf
);
4979 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4980 src
= (LPWSTR
)GlobalLock(hsrc
);
4981 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
4988 /*********************************************************************
4993 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
4995 es
->flags
|= EF_FOCUSED
;
4997 if (!(es
->style
& ES_NOHIDESEL
))
4998 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
5000 /* single line edit updates itself */
5001 if (!(es
->style
& ES_MULTILINE
))
5003 HDC hdc
= GetDC(es
->hwndSelf
);
5004 EDIT_WM_Paint(es
, hdc
);
5005 ReleaseDC(es
->hwndSelf
, hdc
);
5008 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5009 EDIT_SetCaretPos(es
, es
->selection_end
,
5010 es
->flags
& EF_AFTER_WRAP
);
5011 ShowCaret(es
->hwndSelf
);
5012 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
5016 /*********************************************************************
5020 * With Win95 look the margins are set to default font value unless
5021 * the system font (font == 0) is being set, in which case they are left
5025 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
5033 dc
= GetDC(es
->hwndSelf
);
5035 old_font
= SelectObject(dc
, font
);
5036 GetTextMetricsW(dc
, &tm
);
5037 es
->line_height
= tm
.tmHeight
;
5038 es
->char_width
= tm
.tmAveCharWidth
;
5040 SelectObject(dc
, old_font
);
5041 ReleaseDC(es
->hwndSelf
, dc
);
5043 /* Reset the format rect and the margins */
5044 GetClientRect(es
->hwndSelf
, &clientRect
);
5045 EDIT_SetRectNP(es
, &clientRect
);
5046 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
5047 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
5049 if (es
->style
& ES_MULTILINE
)
5050 EDIT_BuildLineDefs_ML(es
, 0, strlenW(es
->text
), 0, NULL
);
5052 EDIT_CalcLineWidth_SL(es
);
5055 EDIT_UpdateText(es
, NULL
, TRUE
);
5056 if (es
->flags
& EF_FOCUSED
) {
5058 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
5059 EDIT_SetCaretPos(es
, es
->selection_end
,
5060 es
->flags
& EF_AFTER_WRAP
);
5061 ShowCaret(es
->hwndSelf
);
5066 /*********************************************************************
5071 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
5072 * The modified flag is reset. No notifications are sent.
5074 * For single-line controls, reception of WM_SETTEXT triggers:
5075 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
5078 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
5081 LPWSTR textW
= NULL
;
5083 if (!unicode
&& text
)
5085 LPCSTR textA
= (LPCSTR
)text
;
5086 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5087 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
5089 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5093 if (es
->flags
& EF_UPDATE
)
5094 /* fixed this bug once; complain if we see it about to happen again. */
5095 ERR("SetSel may generate UPDATE message whose handler may reset "
5098 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
5101 if (USER32_DisplayUnixPaths(es
))
5103 char *textA
= wine_get_unix_file_name( text
);
5106 HeapFree(GetProcessHeap(), 0, textW
);
5108 countW
= MultiByteToWideChar(CP_UNIXCP
, 0, textA
, -1, NULL
, 0);
5109 if ((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5111 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5112 unicode
= FALSE
; /* Force text to be freed */
5115 HeapFree( GetProcessHeap(), 0, textA
);
5118 TRACE("%s\n", debugstr_w(text
));
5119 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
5121 HeapFree(GetProcessHeap(), 0, textW
);
5125 static const WCHAR empty_stringW
[] = {0};
5127 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
5130 es
->flags
&= ~EF_MODIFIED
;
5131 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
5133 /* Send the notification after the selection start and end have been set
5134 * edit control doesn't send notification on WM_SETTEXT
5135 * if it is multiline, or it is part of combobox
5137 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
5139 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5140 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
5142 EDIT_EM_ScrollCaret(es
);
5143 EDIT_UpdateScrollInfo(es
);
5147 /*********************************************************************
5152 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
5154 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
5156 TRACE("width = %d, height = %d\n", width
, height
);
5157 SetRect(&rc
, 0, 0, width
, height
);
5158 EDIT_SetRectNP(es
, &rc
);
5159 EDIT_UpdateText(es
, NULL
, TRUE
);
5164 /*********************************************************************
5168 * This message is sent by SetWindowLong on having changed either the Style
5169 * or the extended style.
5171 * We ensure that the window's version of the styles and the EDITSTATE's agree.
5173 * See also EDIT_WM_NCCreate
5175 * It appears that the Windows version of the edit control allows the style
5176 * (as retrieved by GetWindowLong) to be any value and maintains an internal
5177 * style variable which will generally be different. In this function we
5178 * update the internal style based on what changed in the externally visible
5181 * Much of this content as based upon the MSDN, especially:
5182 * Platform SDK Documentation -> User Interface Services ->
5183 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
5184 * Edit Control Styles
5186 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
5188 if (GWL_STYLE
== which
) {
5189 DWORD style_change_mask
;
5191 /* Only a subset of changes can be applied after the control
5194 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
5196 if (es
->style
& ES_MULTILINE
)
5197 style_change_mask
|= ES_WANTRETURN
;
5199 new_style
= style
->styleNew
& style_change_mask
;
5201 /* Number overrides lowercase overrides uppercase (at least it
5202 * does in Win95). However I'll bet that ES_NUMBER would be
5203 * invalid under Win 3.1.
5205 if (new_style
& ES_NUMBER
) {
5206 ; /* do not override the ES_NUMBER */
5207 } else if (new_style
& ES_LOWERCASE
) {
5208 new_style
&= ~ES_UPPERCASE
;
5211 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
5212 } else if (GWL_EXSTYLE
== which
) {
5213 ; /* FIXME - what is needed here */
5215 WARN ("Invalid style change %d\n",which
);
5221 /*********************************************************************
5226 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
5228 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
5229 if (EDIT_EM_CanUndo(es
))
5232 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
5233 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
5236 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
5240 /*********************************************************************
5245 static void EDIT_WM_Timer(EDITSTATE
*es
)
5247 if (es
->region_posx
< 0) {
5248 EDIT_MoveBackward(es
, TRUE
);
5249 } else if (es
->region_posx
> 0) {
5250 EDIT_MoveForward(es
, TRUE
);
5253 * FIXME: gotta do some vertical scrolling here, like
5254 * EDIT_EM_LineScroll(hwnd, 0, 1);
5258 /*********************************************************************
5263 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
5267 if (!(es
->style
& ES_MULTILINE
))
5270 if (!(es
->style
& ES_AUTOVSCROLL
))
5279 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
5280 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
5281 (action
== SB_PAGEUP
? "SB_PAGEUP" :
5283 EDIT_EM_Scroll(es
, action
);
5290 TRACE("SB_BOTTOM\n");
5291 dy
= es
->line_count
- 1 - es
->y_offset
;
5294 TRACE("SB_THUMBTRACK %d\n", pos
);
5295 es
->flags
|= EF_VSCROLL_TRACK
;
5296 if(es
->style
& WS_VSCROLL
)
5297 dy
= pos
- es
->y_offset
;
5300 /* Assume default scroll range 0-100 */
5303 if(pos
< 0 || pos
> 100) return 0;
5304 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5305 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5306 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5307 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5308 es
->line_count
, es
->y_offset
, pos
, dy
);
5311 case SB_THUMBPOSITION
:
5312 TRACE("SB_THUMBPOSITION %d\n", pos
);
5313 es
->flags
&= ~EF_VSCROLL_TRACK
;
5314 if(es
->style
& WS_VSCROLL
)
5315 dy
= pos
- es
->y_offset
;
5318 /* Assume default scroll range 0-100 */
5321 if(pos
< 0 || pos
> 100) return 0;
5322 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5323 new_y
= pos
* (es
->line_count
- vlc
) / 100;
5324 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
5325 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
5326 es
->line_count
, es
->y_offset
, pos
, dy
);
5330 /* force scroll info update */
5331 EDIT_UpdateScrollInfo(es
);
5332 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
5336 TRACE("SB_ENDSCROLL\n");
5339 * FIXME : the next two are undocumented !
5340 * Are we doing the right thing ?
5341 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
5342 * although it's also a regular control message.
5344 case EM_GETTHUMB
: /* this one is used by NT notepad */
5348 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
5349 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
5352 /* Assume default scroll range 0-100 */
5353 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
5354 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
5356 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
5359 case EM_LINESCROLL16
:
5360 TRACE("EM_LINESCROLL16 %d\n", pos
);
5365 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
5370 EDIT_EM_LineScroll(es
, 0, dy
);
5374 /*********************************************************************
5379 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
5381 if (es
->flags
& EF_UPDATE
) {
5382 es
->flags
&= ~EF_UPDATE
;
5383 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5385 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
5389 /*********************************************************************
5394 static void EDIT_UpdateText(EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
5396 if (es
->flags
& EF_UPDATE
) {
5397 es
->flags
&= ~EF_UPDATE
;
5398 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
5400 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
5403 /********************************************************************
5405 * The Following code is to handle inline editing from IMEs
5408 static void EDIT_GetCompositionStr(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5411 LPWSTR lpCompStr
= NULL
;
5413 LPSTR lpCompStrAttr
= NULL
;
5416 if (!(hIMC
= ImmGetContext(hwnd
)))
5419 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
5423 ImmReleaseContext(hwnd
, hIMC
);
5427 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
5430 ERR("Unable to allocate IME CompositionString\n");
5431 ImmReleaseContext(hwnd
,hIMC
);
5436 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
5437 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5439 if (CompFlag
& GCS_COMPATTR
)
5442 * We do not use the attributes yet. it would tell us what characters
5443 * are in transition and which are converted or decided upon
5445 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
5449 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
5452 ERR("Unable to allocate IME Attribute String\n");
5453 HeapFree(GetProcessHeap(),0,lpCompStr
);
5454 ImmReleaseContext(hwnd
,hIMC
);
5457 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
5459 lpCompStrAttr
[dwBufLenAttr
] = 0;
5462 lpCompStrAttr
= NULL
;
5465 /* check for change in composition start */
5466 if (es
->selection_end
< es
->composition_start
)
5467 es
->composition_start
= es
->selection_end
;
5469 /* replace existing selection string */
5470 es
->selection_start
= es
->composition_start
;
5472 if (es
->composition_len
> 0)
5473 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5475 es
->selection_end
= es
->selection_start
;
5477 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
5478 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
5480 es
->selection_start
= es
->composition_start
;
5481 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
5483 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
5484 HeapFree(GetProcessHeap(),0,lpCompStr
);
5485 ImmReleaseContext(hwnd
,hIMC
);
5488 static void EDIT_GetResultStr(HWND hwnd
, EDITSTATE
*es
)
5494 if ( !(hIMC
= ImmGetContext(hwnd
)))
5497 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
5500 ImmReleaseContext(hwnd
, hIMC
);
5504 lpResultStr
= HeapAlloc(GetProcessHeap(),0, dwBufLen
+sizeof(WCHAR
));
5507 ERR("Unable to alloc buffer for IME string\n");
5508 ImmReleaseContext(hwnd
, hIMC
);
5512 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, dwBufLen
);
5513 lpResultStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
5515 /* check for change in composition start */
5516 if (es
->selection_end
< es
->composition_start
)
5517 es
->composition_start
= es
->selection_end
;
5519 es
->selection_start
= es
->composition_start
;
5520 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
5521 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
5522 es
->composition_start
= es
->selection_end
;
5523 es
->composition_len
= 0;
5525 HeapFree(GetProcessHeap(),0,lpResultStr
);
5526 ImmReleaseContext(hwnd
, hIMC
);
5529 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
5531 if (CompFlag
& GCS_RESULTSTR
)
5532 EDIT_GetResultStr(hwnd
,es
);
5533 if (CompFlag
& GCS_COMPSTR
)
5534 EDIT_GetCompositionStr(hwnd
, CompFlag
, es
);