4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
11 * please read EDIT.TODO (and update it when you change things)
22 #include "wine/winbase16.h"
23 #include "wine/winuser16.h"
24 #include "wine/unicode.h"
28 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(edit
);
31 DECLARE_DEBUG_CHANNEL(combo
);
32 DECLARE_DEBUG_CHANNEL(relay
);
34 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
35 FIXME: BTW, new specs say 65535 (do you dare ???) */
36 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
37 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
38 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
39 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
42 * extra flags for EDITSTATE.flags field
44 #define EF_MODIFIED 0x0001 /* text has been modified */
45 #define EF_FOCUSED 0x0002 /* we have input focus */
46 #define EF_UPDATE 0x0004 /* notify parent of changed state */
47 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
48 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
49 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
50 wrapped line, instead of in front of the next character */
51 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
55 END_0
= 0, /* line ends with terminating '\0' character */
56 END_WRAP
, /* line is wrapped */
57 END_HARD
, /* line ends with a hard return '\r\n' */
58 END_SOFT
/* line ends with a soft return '\r\r\n' */
61 typedef struct tagLINEDEF
{
62 INT length
; /* bruto length of a line in bytes */
63 INT net_length
; /* netto length of a line in visible characters */
65 INT width
; /* width of the line in pixels */
66 INT index
; /* line index into the buffer */
67 struct tagLINEDEF
*next
;
72 BOOL is_unicode
; /* how the control was created */
73 LPWSTR text
; /* the actual contents of the control */
74 UINT buffer_size
; /* the size of the buffer in characters */
75 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
76 HFONT font
; /* NULL means standard system font */
77 INT x_offset
; /* scroll offset for multi lines this is in pixels
78 for single lines it's in characters */
79 INT line_height
; /* height of a screen line in pixels */
80 INT char_width
; /* average character width in pixels */
81 DWORD style
; /* sane version of wnd->dwStyle */
82 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
83 INT undo_insert_count
; /* number of characters inserted in sequence */
84 UINT undo_position
; /* character index of the insertion and deletion */
85 LPWSTR undo_text
; /* deleted text */
86 UINT undo_buffer_size
; /* size of the deleted text buffer */
87 INT selection_start
; /* == selection_end if no selection */
88 INT selection_end
; /* == current caret position */
89 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
90 INT left_margin
; /* in pixels */
91 INT right_margin
; /* in pixels */
93 INT text_width
; /* width of the widest line in pixels for multi line controls
94 and just line width for single line controls */
95 INT region_posx
; /* Position of cursor relative to region: */
96 INT region_posy
; /* -1: to left, 0: within, 1: to right */
97 EDITWORDBREAKPROC16 word_break_proc16
;
98 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
99 INT line_count
; /* number of lines */
100 INT y_offset
; /* scroll offset in number of lines */
101 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
102 BOOL bEnableState
; /* flag keeping the enable state */
103 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
104 Even if parent will change, EN_* messages
105 should be sent to the first parent. */
106 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
108 * only for multi line controls
110 INT lock_count
; /* amount of re-entries in the EditWndProc */
113 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
114 HLOCAL hloc32W
; /* our unicode local memory block */
115 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
117 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
122 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
123 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
125 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
126 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
128 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
129 do {TRACE("notification " str " sent to hwnd=%08x\n", \
130 (UINT)(hwnd));} while(0)
132 /* used for disabled or read-only edit control */
133 #define EDIT_SEND_CTLCOLORSTATIC(hwnd,hdc) \
134 (SendMessageW(GetParent(hwnd), WM_CTLCOLORSTATIC, \
135 (WPARAM)(hdc), (LPARAM)(hwnd)))
136 #define EDIT_SEND_CTLCOLOR(hwnd,hdc) \
137 (SendMessageW(GetParent(hwnd), WM_CTLCOLOREDIT, \
138 (WPARAM)(hdc), (LPARAM)(hwnd)))
139 #define EDIT_NOTIFY_PARENT(hwnd, es, wNotifyCode, str) \
141 { /* Notify parent which has created this edit control */ \
142 DPRINTF_EDIT_NOTIFY((es)->hwndParent, str); \
143 SendMessageW((es)->hwndParent, WM_COMMAND, \
144 MAKEWPARAM(GetWindowLongA((hwnd),GWL_ID), wNotifyCode), \
147 #define DPRINTF_EDIT_MSG16(str) \
149 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
150 hwnd, (UINT)wParam, (UINT)lParam)
151 #define DPRINTF_EDIT_MSG32(str) \
153 "32 bit %c : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
154 unicode ? 'W' : 'A', \
155 hwnd, (UINT)wParam, (UINT)lParam)
157 /*********************************************************************
164 * These functions have trivial implementations
165 * We still like to call them internally
166 * "static inline" makes them more like macro's
168 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
);
169 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
);
170 static inline void EDIT_WM_Clear(HWND hwnd
, EDITSTATE
*es
);
171 static inline void EDIT_WM_Cut(HWND hwnd
, EDITSTATE
*es
);
174 * Helper functions only valid for one type of control
176 static void EDIT_BuildLineDefs_ML(HWND hwnd
, EDITSTATE
*es
, INT iStart
, INT iEnd
, INT delta
, HRGN hrgn
);
177 static void EDIT_CalcLineWidth_SL(HWND hwnd
, EDITSTATE
*es
);
178 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
);
179 static void EDIT_MoveDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
180 static void EDIT_MovePageDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
181 static void EDIT_MovePageUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
182 static void EDIT_MoveUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
184 * Helper functions valid for both single line _and_ multi line controls
186 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
187 static INT
EDIT_CharFromPos(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
188 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
);
189 static void EDIT_GetLineRect(HWND hwnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
190 static void EDIT_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
);
191 static void EDIT_LockBuffer(HWND hwnd
, EDITSTATE
*es
);
192 static BOOL
EDIT_MakeFit(HWND hwnd
, EDITSTATE
*es
, UINT size
);
193 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
);
194 static void EDIT_MoveBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
195 static void EDIT_MoveEnd(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
196 static void EDIT_MoveForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
197 static void EDIT_MoveHome(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
198 static void EDIT_MoveWordBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
199 static void EDIT_MoveWordForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
);
200 static void EDIT_PaintLine(HWND hwnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
201 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
202 static void EDIT_SetCaretPos(HWND hwnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
203 static void EDIT_SetRectNP(HWND hwnd
, EDITSTATE
*es
, LPRECT lprc
);
204 static void EDIT_UnlockBuffer(HWND hwnd
, EDITSTATE
*es
, BOOL force
);
205 static void EDIT_UpdateScrollInfo(HWND hwnd
, EDITSTATE
*es
);
206 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
);
208 * EM_XXX message handlers
210 static LRESULT
EDIT_EM_CharFromPos(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
);
211 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
);
212 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
);
213 static HLOCAL16
EDIT_EM_GetHandle16(HWND hwnd
, EDITSTATE
*es
);
214 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
);
215 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
);
216 static LRESULT
EDIT_EM_GetThumb(HWND hwnd
, EDITSTATE
*es
);
217 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
);
218 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
);
219 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
);
220 static BOOL
EDIT_EM_LineScroll(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
);
221 static BOOL
EDIT_EM_LineScroll_internal(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
);
222 static LRESULT
EDIT_EM_PosFromChar(HWND hwnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
223 static void EDIT_EM_ReplaceSel(HWND hwnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
);
224 static LRESULT
EDIT_EM_Scroll(HWND hwnd
, EDITSTATE
*es
, INT action
);
225 static void EDIT_EM_ScrollCaret(HWND hwnd
, EDITSTATE
*es
);
226 static void EDIT_EM_SetHandle(HWND hwnd
, EDITSTATE
*es
, HLOCAL hloc
);
227 static void EDIT_EM_SetHandle16(HWND hwnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
228 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
);
229 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
, INT left
, INT right
);
230 static void EDIT_EM_SetPasswordChar(HWND hwnd
, EDITSTATE
*es
, WCHAR c
);
231 static void EDIT_EM_SetSel(HWND hwnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
232 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
);
233 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
);
234 static void EDIT_EM_SetWordBreakProc(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
);
235 static void EDIT_EM_SetWordBreakProc16(HWND hwnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
236 static BOOL
EDIT_EM_Undo(HWND hwnd
, EDITSTATE
*es
);
238 * WM_XXX message handlers
240 static void EDIT_WM_Char(HWND hwnd
, EDITSTATE
*es
, WCHAR c
);
241 static void EDIT_WM_Command(HWND hwnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
242 static void EDIT_WM_ContextMenu(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
);
243 static void EDIT_WM_Copy(HWND hwnd
, EDITSTATE
*es
);
244 static LRESULT
EDIT_WM_Create(HWND hwnd
, EDITSTATE
*es
, LPCWSTR name
);
245 static void EDIT_WM_Destroy(HWND hwnd
, EDITSTATE
*es
);
246 static LRESULT
EDIT_WM_EraseBkGnd(HWND hwnd
, EDITSTATE
*es
, HDC dc
);
247 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
);
248 static LRESULT
EDIT_WM_HScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
);
249 static LRESULT
EDIT_WM_KeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
);
250 static LRESULT
EDIT_WM_KillFocus(HWND hwnd
, EDITSTATE
*es
);
251 static LRESULT
EDIT_WM_LButtonDblClk(HWND hwnd
, EDITSTATE
*es
);
252 static LRESULT
EDIT_WM_LButtonDown(HWND hwnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
253 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
);
254 static LRESULT
EDIT_WM_MButtonDown(HWND hwnd
);
255 static LRESULT
EDIT_WM_MouseMove(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
);
256 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, DWORD style
, HWND hwndParent
, BOOL unicode
);
257 static void EDIT_WM_Paint(HWND hwnd
, EDITSTATE
*es
, WPARAM wParam
);
258 static void EDIT_WM_Paste(HWND hwnd
, EDITSTATE
*es
);
259 static void EDIT_WM_SetFocus(HWND hwnd
, EDITSTATE
*es
);
260 static void EDIT_WM_SetFont(HWND hwnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
261 static void EDIT_WM_SetText(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
);
262 static void EDIT_WM_Size(HWND hwnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
263 static LRESULT
EDIT_WM_StyleChanged (HWND hwnd
, EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
);
264 static LRESULT
EDIT_WM_SysKeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
265 static void EDIT_WM_Timer(HWND hwnd
, EDITSTATE
*es
);
266 static LRESULT
EDIT_WM_VScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
);
267 static void EDIT_UpdateText(HWND hwnd
, EDITSTATE
*es
, LPRECT rc
, BOOL bErase
);
268 static void EDIT_UpdateTextRegion(HWND hwnd
, EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
);
270 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
271 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
273 /*********************************************************************
274 * edit class descriptor
276 const struct builtin_class_descr EDIT_builtin_class
=
279 CS_GLOBALCLASS
| CS_DBLCLKS
/*| CS_PARENTDC*/, /* style */
280 EditWndProcA
, /* procA */
281 EditWndProcW
, /* procW */
282 sizeof(EDITSTATE
*), /* extra */
283 IDC_IBEAMA
, /* cursor */
288 /*********************************************************************
293 static inline BOOL
EDIT_EM_CanUndo(EDITSTATE
*es
)
295 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
299 /*********************************************************************
304 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
306 es
->undo_insert_count
= 0;
307 *es
->undo_text
= '\0';
311 /*********************************************************************
316 static inline void EDIT_WM_Clear(HWND hwnd
, EDITSTATE
*es
)
318 static const WCHAR empty_stringW
[] = {0};
320 /* Protect read-only edit control from modification */
321 if(es
->style
& ES_READONLY
)
324 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, empty_stringW
, TRUE
);
328 /*********************************************************************
333 static inline void EDIT_WM_Cut(HWND hwnd
, EDITSTATE
*es
)
335 EDIT_WM_Copy(hwnd
, es
);
336 EDIT_WM_Clear(hwnd
, es
);
340 /**********************************************************************
343 * Returns the window version in case Wine emulates a later version
344 * of windows then the application expects.
346 * In a number of cases when windows runs an application that was
347 * designed for an earlier windows version, windows reverts
348 * to "old" behaviour of that earlier version.
350 * An example is a disabled edit control that needs to be painted.
351 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
352 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
353 * applications with an expected version 0f 4.0 or higher.
356 static DWORD
get_app_version(void)
358 static DWORD version
;
361 DWORD dwEmulatedVersion
;
363 DWORD dwProcVersion
= GetProcessVersion(0);
365 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
366 GetVersionExW( &info
);
367 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
368 /* fixme: this may not be 100% correct; see discussion on the
369 * wine developer list in Nov 1999 */
370 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
376 /*********************************************************************
380 * The messages are in the order of the actual integer values
381 * (which can be found in include/windows.h)
382 * Wherever possible the 16 bit versions are converted to
383 * the 32 bit ones, so that we can 'fall through' to the
384 * helper functions. These are mostly 32 bit (with a few
385 * exceptions, clearly indicated by a '16' extension to their
389 static LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
390 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
392 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongA( hwnd
, 0 );
397 DPRINTF_EDIT_MSG32("WM_DESTROY");
398 if (es
) EDIT_WM_Destroy(hwnd
, es
);
403 DPRINTF_EDIT_MSG32("WM_NCCREATE");
406 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
407 result
= EDIT_WM_NCCreate(hwnd
, cs
->style
, cs
->hwndParent
, TRUE
);
411 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
412 result
= EDIT_WM_NCCreate(hwnd
, cs
->style
, cs
->hwndParent
, FALSE
);
420 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
422 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
427 EDIT_LockBuffer(hwnd
, es
);
430 DPRINTF_EDIT_MSG16("EM_GETSEL");
435 DPRINTF_EDIT_MSG32("EM_GETSEL");
436 result
= EDIT_EM_GetSel(es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
440 DPRINTF_EDIT_MSG16("EM_SETSEL");
441 if (SLOWORD(lParam
) == -1)
442 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
444 EDIT_EM_SetSel(hwnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
446 EDIT_EM_ScrollCaret(hwnd
, es
);
450 DPRINTF_EDIT_MSG32("EM_SETSEL");
451 EDIT_EM_SetSel(hwnd
, es
, wParam
, lParam
, FALSE
);
452 EDIT_EM_ScrollCaret(hwnd
, es
);
457 DPRINTF_EDIT_MSG16("EM_GETRECT");
459 CONV_RECT32TO16(&es
->format_rect
, MapSL(lParam
));
462 DPRINTF_EDIT_MSG32("EM_GETRECT");
464 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
468 DPRINTF_EDIT_MSG16("EM_SETRECT");
469 if ((es
->style
& ES_MULTILINE
) && lParam
) {
471 CONV_RECT16TO32(MapSL(lParam
), &rc
);
472 EDIT_SetRectNP(hwnd
, es
, &rc
);
473 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
477 DPRINTF_EDIT_MSG32("EM_SETRECT");
478 if ((es
->style
& ES_MULTILINE
) && lParam
) {
479 EDIT_SetRectNP(hwnd
, es
, (LPRECT
)lParam
);
480 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
485 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
486 if ((es
->style
& ES_MULTILINE
) && lParam
) {
488 CONV_RECT16TO32(MapSL(lParam
), &rc
);
489 EDIT_SetRectNP(hwnd
, es
, &rc
);
493 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
494 if ((es
->style
& ES_MULTILINE
) && lParam
)
495 EDIT_SetRectNP(hwnd
, es
, (LPRECT
)lParam
);
499 DPRINTF_EDIT_MSG16("EM_SCROLL");
502 DPRINTF_EDIT_MSG32("EM_SCROLL");
503 result
= EDIT_EM_Scroll(hwnd
, es
, (INT
)wParam
);
506 case EM_LINESCROLL16
:
507 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
508 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
509 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
512 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
513 result
= (LRESULT
)EDIT_EM_LineScroll(hwnd
, es
, (INT
)wParam
, (INT
)lParam
);
516 case EM_SCROLLCARET16
:
517 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
520 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
521 EDIT_EM_ScrollCaret(hwnd
, es
);
526 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
529 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
530 result
= ((es
->flags
& EF_MODIFIED
) != 0);
534 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
537 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
539 es
->flags
|= EF_MODIFIED
;
541 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
544 case EM_GETLINECOUNT16
:
545 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
547 case EM_GETLINECOUNT
:
548 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
549 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
553 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
554 if ((INT16
)wParam
== -1)
558 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
559 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
563 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
564 EDIT_EM_SetHandle16(hwnd
, es
, (HLOCAL16
)wParam
);
567 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
568 EDIT_EM_SetHandle(hwnd
, es
, (HLOCAL
)wParam
);
572 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
573 result
= (LRESULT
)EDIT_EM_GetHandle16(hwnd
, es
);
576 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
577 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
581 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
584 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
585 result
= EDIT_EM_GetThumb(hwnd
, es
);
588 /* messages 0x00bf and 0x00c0 missing from specs */
591 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
594 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
595 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
599 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
602 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
603 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
606 case EM_LINELENGTH16
:
607 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
610 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
611 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
614 case EM_REPLACESEL16
:
615 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
616 lParam
= (LPARAM
)MapSL(lParam
);
617 unicode
= FALSE
; /* 16-bit message is always ascii */
622 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
625 textW
= (LPWSTR
)lParam
;
628 LPSTR textA
= (LPSTR
)lParam
;
629 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
630 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
631 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
634 EDIT_EM_ReplaceSel(hwnd
, es
, (BOOL
)wParam
, textW
, TRUE
);
638 HeapFree(GetProcessHeap(), 0, textW
);
641 /* message 0x00c3 missing from specs */
644 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
647 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
648 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
652 DPRINTF_EDIT_MSG16("EM_GETLINE");
653 lParam
= (LPARAM
)MapSL(lParam
);
654 unicode
= FALSE
; /* 16-bit message is always ascii */
657 DPRINTF_EDIT_MSG32("EM_GETLINE");
658 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, lParam
, unicode
);
662 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
664 case EM_SETLIMITTEXT
:
665 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
666 EDIT_EM_SetLimitText(es
, (INT
)wParam
);
670 DPRINTF_EDIT_MSG16("EM_CANUNDO");
673 DPRINTF_EDIT_MSG32("EM_CANUNDO");
674 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
678 DPRINTF_EDIT_MSG16("EM_UNDO");
683 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
684 result
= (LRESULT
)EDIT_EM_Undo(hwnd
, es
);
688 DPRINTF_EDIT_MSG16("EM_FMTLINES");
691 DPRINTF_EDIT_MSG32("EM_FMTLINES");
692 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
695 case EM_LINEFROMCHAR16
:
696 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
698 case EM_LINEFROMCHAR
:
699 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
700 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
703 /* message 0x00ca missing from specs */
706 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
709 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
710 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
713 case EM_SETTABSTOPS16
:
714 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
715 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
718 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
719 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
722 case EM_SETPASSWORDCHAR16
:
723 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
724 unicode
= FALSE
; /* 16-bit message is always ascii */
726 case EM_SETPASSWORDCHAR
:
729 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
732 charW
= (WCHAR
)wParam
;
736 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
739 EDIT_EM_SetPasswordChar(hwnd
, es
, charW
);
743 case EM_EMPTYUNDOBUFFER16
:
744 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
746 case EM_EMPTYUNDOBUFFER
:
747 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
748 EDIT_EM_EmptyUndoBuffer(es
);
751 case EM_GETFIRSTVISIBLELINE16
:
752 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
753 result
= es
->y_offset
;
755 case EM_GETFIRSTVISIBLELINE
:
756 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
757 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
760 case EM_SETREADONLY16
:
761 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
764 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
766 SetWindowLongA( hwnd
, GWL_STYLE
,
767 GetWindowLongA( hwnd
, GWL_STYLE
) | ES_READONLY
);
768 es
->style
|= ES_READONLY
;
770 SetWindowLongA( hwnd
, GWL_STYLE
,
771 GetWindowLongA( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
772 es
->style
&= ~ES_READONLY
;
777 case EM_SETWORDBREAKPROC16
:
778 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
779 EDIT_EM_SetWordBreakProc16(hwnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
781 case EM_SETWORDBREAKPROC
:
782 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
783 EDIT_EM_SetWordBreakProc(hwnd
, es
, lParam
);
786 case EM_GETWORDBREAKPROC16
:
787 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
788 result
= (LRESULT
)es
->word_break_proc16
;
790 case EM_GETWORDBREAKPROC
:
791 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
792 result
= (LRESULT
)es
->word_break_proc
;
795 case EM_GETPASSWORDCHAR16
:
796 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
797 unicode
= FALSE
; /* 16-bit message is always ascii */
799 case EM_GETPASSWORDCHAR
:
801 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
804 result
= es
->password_char
;
807 WCHAR charW
= es
->password_char
;
809 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
815 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
818 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
819 EDIT_EM_SetMargins(es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
823 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
824 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
827 case EM_GETLIMITTEXT
:
828 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
829 result
= es
->buffer_limit
;
833 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
834 result
= EDIT_EM_PosFromChar(hwnd
, es
, (INT
)wParam
, FALSE
);
838 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
839 result
= EDIT_EM_CharFromPos(hwnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
842 /* End of the EM_ messages which were in numerical order; what order
843 * are these in? vaguely alphabetical?
847 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
848 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
850 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
852 int vk
= (int)((LPMSG
)lParam
)->wParam
;
854 if (vk
== VK_RETURN
&& (GetWindowLongA( hwnd
, GWL_STYLE
) & ES_WANTRETURN
))
856 result
|= DLGC_WANTMESSAGE
;
858 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
860 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
861 result
|= DLGC_WANTMESSAGE
;
869 DPRINTF_EDIT_MSG32("WM_CHAR");
876 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
879 if ((charW
== VK_RETURN
|| charW
== VK_ESCAPE
) && es
->hwndListBox
)
881 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
882 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
885 EDIT_WM_Char(hwnd
, es
, charW
);
890 DPRINTF_EDIT_MSG32("WM_CLEAR");
891 EDIT_WM_Clear(hwnd
, es
);
895 DPRINTF_EDIT_MSG32("WM_COMMAND");
896 EDIT_WM_Command(hwnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
900 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
901 EDIT_WM_ContextMenu(hwnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
905 DPRINTF_EDIT_MSG32("WM_COPY");
906 EDIT_WM_Copy(hwnd
, es
);
910 DPRINTF_EDIT_MSG32("WM_CREATE");
912 result
= EDIT_WM_Create(hwnd
, es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
915 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
919 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
920 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
921 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
923 result
= EDIT_WM_Create(hwnd
, es
, nameW
);
925 HeapFree(GetProcessHeap(), 0, nameW
);
930 DPRINTF_EDIT_MSG32("WM_CUT");
931 EDIT_WM_Cut(hwnd
, es
);
935 DPRINTF_EDIT_MSG32("WM_ENABLE");
936 es
->bEnableState
= (BOOL
) wParam
;
937 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
941 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
942 result
= EDIT_WM_EraseBkGnd(hwnd
, es
, (HDC
)wParam
);
946 DPRINTF_EDIT_MSG32("WM_GETFONT");
947 result
= (LRESULT
)es
->font
;
951 DPRINTF_EDIT_MSG32("WM_GETTEXT");
952 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, lParam
, unicode
);
955 case WM_GETTEXTLENGTH
:
956 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
957 result
= strlenW(es
->text
);
961 DPRINTF_EDIT_MSG32("WM_HSCROLL");
962 result
= EDIT_WM_HScroll(hwnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
966 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
967 result
= EDIT_WM_KeyDown(hwnd
, es
, (INT
)wParam
);
971 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
972 result
= EDIT_WM_KillFocus(hwnd
, es
);
975 case WM_LBUTTONDBLCLK
:
976 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
977 result
= EDIT_WM_LButtonDblClk(hwnd
, es
);
981 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
982 result
= EDIT_WM_LButtonDown(hwnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
986 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
987 result
= EDIT_WM_LButtonUp(hwnd
, es
);
991 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
992 result
= EDIT_WM_MButtonDown(hwnd
);
995 case WM_MOUSEACTIVATE
:
997 * FIXME: maybe DefWindowProc() screws up, but it seems that
998 * modeless dialog boxes need this. If we don't do this, the focus
999 * will _not_ be set by DefWindowProc() for edit controls in a
1000 * modeless dialog box ???
1002 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
1004 result
= MA_ACTIVATE
;
1009 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
1011 result
= EDIT_WM_MouseMove(hwnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
1015 DPRINTF_EDIT_MSG32("WM_PAINT");
1016 EDIT_WM_Paint(hwnd
, es
, wParam
);
1020 DPRINTF_EDIT_MSG32("WM_PASTE");
1021 EDIT_WM_Paste(hwnd
, es
);
1025 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
1026 EDIT_WM_SetFocus(hwnd
, es
);
1030 DPRINTF_EDIT_MSG32("WM_SETFONT");
1031 EDIT_WM_SetFont(hwnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
1035 /* FIXME: actually set an internal flag and behave accordingly */
1039 DPRINTF_EDIT_MSG32("WM_SETTEXT");
1040 EDIT_WM_SetText(hwnd
, es
, lParam
, unicode
);
1045 DPRINTF_EDIT_MSG32("WM_SIZE");
1046 EDIT_WM_Size(hwnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
1049 case WM_STYLECHANGED
:
1050 DPRINTF_EDIT_MSG32("WM_STYLECHANGED");
1051 result
= EDIT_WM_StyleChanged (hwnd
, es
, wParam
, (const STYLESTRUCT
*)lParam
);
1054 case WM_STYLECHANGING
:
1055 DPRINTF_EDIT_MSG32("WM_STYLECHANGING");
1056 result
= 0; /* See EDIT_WM_StyleChanged */
1060 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
1061 result
= EDIT_WM_SysKeyDown(hwnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
1065 DPRINTF_EDIT_MSG32("WM_TIMER");
1066 EDIT_WM_Timer(hwnd
, es
);
1070 DPRINTF_EDIT_MSG32("WM_VSCROLL");
1071 result
= EDIT_WM_VScroll(hwnd
, es
, LOWORD(wParam
), SHIWORD(wParam
));
1076 int gcWheelDelta
= 0;
1077 UINT pulScrollLines
= 3;
1078 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
1080 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
1081 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1084 gcWheelDelta
-= SHIWORD(wParam
);
1085 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
1087 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
1088 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
1089 result
= EDIT_EM_LineScroll(hwnd
, es
, 0, cLineScroll
);
1095 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1097 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
1100 EDIT_UnlockBuffer(hwnd
, es
, FALSE
);
1105 /*********************************************************************
1107 * EditWndProcW (USER32.@)
1109 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1111 if (!IsWindow( hWnd
)) return 0;
1112 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1115 /*********************************************************************
1117 * EditWndProc (USER32.@)
1119 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1121 if (!IsWindow( hWnd
)) return 0;
1122 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1125 /*********************************************************************
1127 * EDIT_BuildLineDefs_ML
1129 * Build linked list of text lines.
1130 * Lines can end with '\0' (last line), a character (if it is wrapped),
1131 * a soft return '\r\r\n' or a hard return '\r\n'
1134 static void EDIT_BuildLineDefs_ML(HWND hwnd
, EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
1138 LPWSTR current_position
, cp
;
1140 LINEDEF
*current_line
;
1141 LINEDEF
*previous_line
;
1142 LINEDEF
*start_line
;
1143 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
1144 INT line_count
= es
->line_count
;
1145 INT orig_net_length
;
1148 if (istart
== iend
&& delta
== 0)
1153 old_font
= SelectObject(dc
, es
->font
);
1155 previous_line
= NULL
;
1156 current_line
= es
->first_line_def
;
1158 /* Find starting line. istart must lie inside an existing line or
1159 * at the end of buffer */
1161 if (istart
< current_line
->index
+ current_line
->length
||
1162 current_line
->ending
== END_0
)
1165 previous_line
= current_line
;
1166 current_line
= current_line
->next
;
1168 } while (current_line
);
1170 if (!current_line
) /* Error occurred start is not inside previous buffer */
1172 FIXME(" modification occurred outside buffer\n");
1176 /* Remember start of modifications in order to calculate update region */
1177 nstart_line
= line_index
;
1178 nstart_index
= current_line
->index
;
1180 /* We must start to reformat from the previous line since the modifications
1181 * may have caused the line to wrap upwards. */
1182 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
1185 current_line
= previous_line
;
1187 start_line
= current_line
;
1189 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
1190 current_position
= es
->text
+ current_line
->index
;
1192 if (current_line
!= start_line
)
1194 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
1196 /* The buffer has been expanded, create a new line and
1197 insert it into the link list */
1198 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
1199 new_line
->next
= previous_line
->next
;
1200 previous_line
->next
= new_line
;
1201 current_line
= new_line
;
1204 else if (current_line
->index
+ delta
< current_position
- es
->text
)
1206 /* The previous line merged with this line so we delete this extra entry */
1207 previous_line
->next
= current_line
->next
;
1208 HeapFree(GetProcessHeap(), 0, current_line
);
1209 current_line
= previous_line
->next
;
1213 else /* current_line->index + delta == current_position */
1215 if (current_position
- es
->text
> iend
)
1216 break; /* We reached end of line modifications */
1217 /* else recalulate this line */
1221 current_line
->index
= current_position
- es
->text
;
1222 orig_net_length
= current_line
->net_length
;
1224 /* Find end of line */
1225 cp
= current_position
;
1227 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
1232 /* Mark type of line termination */
1234 current_line
->ending
= END_0
;
1235 current_line
->net_length
= strlenW(current_position
);
1236 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
1237 current_line
->ending
= END_SOFT
;
1238 current_line
->net_length
= cp
- current_position
- 1;
1240 current_line
->ending
= END_HARD
;
1241 current_line
->net_length
= cp
- current_position
;
1244 /* Calculate line width */
1245 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1246 current_position
, current_line
->net_length
,
1247 es
->tabs_count
, es
->tabs
));
1249 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
1250 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_line
->width
> fw
)) {
1255 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
1256 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
1257 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1258 current_position
, next
, es
->tabs_count
, es
->tabs
));
1259 } while (current_line
->width
<= fw
);
1260 if (!prev
) { /* Didn't find a line break so force a break */
1265 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1266 current_position
, next
, es
->tabs_count
, es
->tabs
));
1267 } while (current_line
->width
<= fw
);
1272 /* If the first line we are calculating, wrapped before istart, we must
1273 * adjust istart in order for this to be reflected in the update region. */
1274 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
1275 istart
= current_line
->index
+ prev
;
1276 /* else if we are updating the previous line before the first line we
1277 * are re-caulculating and it expanded */
1278 else if (current_line
== start_line
&&
1279 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
1281 /* Line expanded due to an upwards line wrap so we must partially include
1282 * previous line in update region */
1283 nstart_line
= line_index
;
1284 nstart_index
= current_line
->index
;
1285 istart
= current_line
->index
+ orig_net_length
;
1288 current_line
->net_length
= prev
;
1289 current_line
->ending
= END_WRAP
;
1290 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
1291 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
1295 /* Adjust length to include line termination */
1296 switch (current_line
->ending
) {
1298 current_line
->length
= current_line
->net_length
+ 3;
1301 current_line
->length
= current_line
->net_length
+ 2;
1305 current_line
->length
= current_line
->net_length
;
1308 es
->text_width
= max(es
->text_width
, current_line
->width
);
1309 current_position
+= current_line
->length
;
1310 previous_line
= current_line
;
1311 current_line
= current_line
->next
;
1313 } while (previous_line
->ending
!= END_0
);
1315 /* Finish adjusting line index's by delta or remove hanging lines */
1316 if (previous_line
->ending
== END_0
)
1318 LINEDEF
*pnext
= NULL
;
1320 previous_line
->next
= NULL
;
1321 while (current_line
)
1323 pnext
= current_line
->next
;
1324 HeapFree(GetProcessHeap(), 0, current_line
);
1325 current_line
= pnext
;
1331 while (current_line
)
1333 current_line
->index
+= delta
;
1334 current_line
= current_line
->next
;
1338 /* Calculate rest of modification rectangle */
1343 * We calculate two rectangles. One for the first line which may have
1344 * an indent with respect to the format rect. The other is a format-width
1345 * rectangle that spans the rest of the lines that changed or moved.
1347 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
1348 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1349 rc
.bottom
= rc
.top
+ es
->line_height
;
1350 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
1351 es
->text
+ nstart_index
, istart
- nstart_index
,
1352 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
1353 rc
.right
= es
->format_rect
.right
;
1354 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1357 rc
.left
= es
->format_rect
.left
;
1358 rc
.right
= es
->format_rect
.right
;
1360 * If lines were added or removed we must re-paint the remainder of the
1361 * lines since the remaining lines were either shifted up or down.
1363 if (line_count
< es
->line_count
) /* We added lines */
1364 rc
.bottom
= es
->line_count
* es
->line_height
;
1365 else if (line_count
> es
->line_count
) /* We removed lines */
1366 rc
.bottom
= line_count
* es
->line_height
;
1368 rc
.bottom
= line_index
* es
->line_height
;
1369 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
1370 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1371 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
1372 DeleteObject(tmphrgn
);
1376 SelectObject(dc
, old_font
);
1378 ReleaseDC(hwnd
, dc
);
1381 /*********************************************************************
1383 * EDIT_CalcLineWidth_SL
1386 static void EDIT_CalcLineWidth_SL(HWND hwnd
, EDITSTATE
*es
)
1388 es
->text_width
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, strlenW(es
->text
), FALSE
));
1391 /*********************************************************************
1393 * EDIT_CallWordBreakProc
1395 * Call appropriate WordBreakProc (internal or external).
1397 * Note: The "start" argument should always be an index refering
1398 * to es->text. The actual wordbreak proc might be
1399 * 16 bit, so we can't always pass any 32 bit LPSTR.
1400 * Hence we assume that es->text is the buffer that holds
1401 * the string under examination (we can decide this for ourselves).
1404 /* ### start build ### */
1405 extern WORD CALLBACK
EDIT_CallTo16_word_lwww(EDITWORDBREAKPROC16
,SEGPTR
,WORD
,WORD
,WORD
);
1406 /* ### stop build ### */
1407 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1409 INT ret
, iWndsLocks
;
1411 /* To avoid any deadlocks, all the locks on the windows structures
1412 must be suspended before the control is passed to the application */
1413 iWndsLocks
= WIN_SuspendWndsLock();
1415 if (es
->word_break_proc16
) {
1420 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1421 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
1422 segptr
= K32WOWGlobalLock16(hglob16
);
1423 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
1424 ret
= (INT
)EDIT_CallTo16_word_lwww(es
->word_break_proc16
,
1425 segptr
, index
, countA
, action
);
1426 GlobalUnlock16(hglob16
);
1427 GlobalFree16(hglob16
);
1429 else if (es
->word_break_proc
)
1433 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
1435 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1436 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
1437 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
1441 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
1445 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
1446 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
1447 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
1448 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1449 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
1450 ret
= wbpA(textA
, index
, countA
, action
);
1451 HeapFree(GetProcessHeap(), 0, textA
);
1455 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1457 WIN_RestoreWndsLock(iWndsLocks
);
1462 /*********************************************************************
1466 * Beware: This is not the function called on EM_CHARFROMPOS
1467 * The position _can_ be outside the formatting / client
1469 * The return value is only the character index
1472 static INT
EDIT_CharFromPos(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1478 if (es
->style
& ES_MULTILINE
) {
1479 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1481 LINEDEF
*line_def
= es
->first_line_def
;
1483 while ((line
> 0) && line_def
->next
) {
1484 line_index
+= line_def
->length
;
1485 line_def
= line_def
->next
;
1488 x
+= es
->x_offset
- es
->format_rect
.left
;
1489 if (x
>= line_def
->width
) {
1491 *after_wrap
= (line_def
->ending
== END_WRAP
);
1492 return line_index
+ line_def
->net_length
;
1496 *after_wrap
= FALSE
;
1501 old_font
= SelectObject(dc
, es
->font
);
1502 low
= line_index
+ 1;
1503 high
= line_index
+ line_def
->net_length
+ 1;
1504 while (low
< high
- 1)
1506 INT mid
= (low
+ high
) / 2;
1507 if (LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1513 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1514 (line_def
->ending
== END_WRAP
));
1519 *after_wrap
= FALSE
;
1520 x
-= es
->format_rect
.left
;
1522 return es
->x_offset
;
1523 text
= EDIT_GetPasswordPointer_SL(es
);
1526 old_font
= SelectObject(dc
, es
->font
);
1530 INT high
= es
->x_offset
;
1531 while (low
< high
- 1)
1533 INT mid
= (low
+ high
) / 2;
1534 GetTextExtentPoint32W( dc
, text
+ mid
,
1535 es
->x_offset
- mid
, &size
);
1536 if (size
.cx
> -x
) low
= mid
;
1543 INT low
= es
->x_offset
;
1544 INT high
= strlenW(es
->text
) + 1;
1545 while (low
< high
- 1)
1547 INT mid
= (low
+ high
) / 2;
1548 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
1549 mid
- es
->x_offset
, &size
);
1550 if (size
.cx
> x
) high
= mid
;
1555 if (es
->style
& ES_PASSWORD
)
1556 HeapFree(GetProcessHeap(), 0, text
);
1559 SelectObject(dc
, old_font
);
1560 ReleaseDC(hwnd
, dc
);
1565 /*********************************************************************
1569 * adjusts the point to be within the formatting rectangle
1570 * (so CharFromPos returns the nearest _visible_ character)
1573 static void EDIT_ConfinePoint(EDITSTATE
*es
, LPINT x
, LPINT y
)
1575 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1576 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1580 /*********************************************************************
1584 * Calculates the bounding rectangle for a line from a starting
1585 * column to an ending column.
1588 static void EDIT_GetLineRect(HWND hwnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1590 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1592 if (es
->style
& ES_MULTILINE
)
1593 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1595 rc
->top
= es
->format_rect
.top
;
1596 rc
->bottom
= rc
->top
+ es
->line_height
;
1597 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, line_index
+ scol
, TRUE
));
1598 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, line_index
+ ecol
, TRUE
));
1602 /*********************************************************************
1604 * EDIT_GetPasswordPointer_SL
1606 * note: caller should free the (optionally) allocated buffer
1609 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
1611 if (es
->style
& ES_PASSWORD
) {
1612 INT len
= strlenW(es
->text
);
1613 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1615 while(len
) text
[--len
] = es
->password_char
;
1622 /*********************************************************************
1626 * This acts as a LOCAL_Lock(), but it locks only once. This way
1627 * you can call it whenever you like, without unlocking.
1630 static void EDIT_LockBuffer(HWND hwnd
, EDITSTATE
*es
)
1632 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
1634 ERR("no EDITSTATE ... please report\n");
1640 BOOL _16bit
= FALSE
;
1646 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1647 textA
= LocalLock(es
->hloc32A
);
1648 countA
= strlen(textA
) + 1;
1652 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1653 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
1654 countA
= strlen(textA
) + 1;
1659 ERR("no buffer ... please report\n");
1666 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1667 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1668 if(countW_new
> es
->buffer_size
+ 1)
1670 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1671 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1672 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1675 es
->hloc32W
= hloc32W_new
;
1676 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1677 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1680 WARN("FAILED! Will synchronize partially\n");
1684 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1685 es
->text
= LocalLock(es
->hloc32W
);
1689 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1691 LOCAL_Unlock(hInstance
, es
->hloc16
);
1693 LocalUnlock(es
->hloc32A
);
1700 /*********************************************************************
1702 * EDIT_SL_InvalidateText
1704 * Called from EDIT_InvalidateText().
1705 * Does the job for single-line controls only.
1708 static void EDIT_SL_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
)
1713 EDIT_GetLineRect(hwnd
, es
, 0, start
, end
, &line_rect
);
1714 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1715 EDIT_UpdateText(hwnd
, es
, &rc
, FALSE
);
1719 /*********************************************************************
1721 * EDIT_ML_InvalidateText
1723 * Called from EDIT_InvalidateText().
1724 * Does the job for multi-line controls only.
1727 static void EDIT_ML_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
)
1729 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1730 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1731 INT el
= EDIT_EM_LineFromChar(es
, end
);
1740 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1743 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1744 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1745 if (sl
< es
->y_offset
) {
1749 if (el
> es
->y_offset
+ vlc
) {
1750 el
= es
->y_offset
+ vlc
;
1751 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1753 GetClientRect(hwnd
, &rc1
);
1754 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1756 EDIT_GetLineRect(hwnd
, es
, sl
, sc
, ec
, &rcLine
);
1757 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1758 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1760 EDIT_GetLineRect(hwnd
, es
, sl
, sc
,
1761 EDIT_EM_LineLength(es
,
1762 EDIT_EM_LineIndex(es
, sl
)),
1764 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1765 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1766 for (l
= sl
+ 1 ; l
< el
; l
++) {
1767 EDIT_GetLineRect(hwnd
, es
, l
, 0,
1768 EDIT_EM_LineLength(es
,
1769 EDIT_EM_LineIndex(es
, l
)),
1771 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1772 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1774 EDIT_GetLineRect(hwnd
, es
, el
, 0, ec
, &rcLine
);
1775 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1776 EDIT_UpdateText(hwnd
, es
, &rcUpdate
, FALSE
);
1781 /*********************************************************************
1783 * EDIT_InvalidateText
1785 * Invalidate the text from offset start upto, but not including,
1786 * offset end. Useful for (re)painting the selection.
1787 * Regions outside the linewidth are not invalidated.
1788 * end == -1 means end == TextLength.
1789 * start and end need not be ordered.
1792 static void EDIT_InvalidateText(HWND hwnd
, EDITSTATE
*es
, INT start
, INT end
)
1798 end
= strlenW(es
->text
);
1800 ORDER_INT(start
, end
);
1802 if (es
->style
& ES_MULTILINE
)
1803 EDIT_ML_InvalidateText(hwnd
, es
, start
, end
);
1805 EDIT_SL_InvalidateText(hwnd
, es
, start
, end
);
1809 /*********************************************************************
1813 * Try to fit size + 1 characters in the buffer. Constrain to limits.
1816 static BOOL
EDIT_MakeFit(HWND hwnd
, EDITSTATE
*es
, UINT size
)
1820 if (size
<= es
->buffer_size
)
1822 if (size
> es
->buffer_limit
) {
1823 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_MAXTEXT
, "EN_MAXTEXT");
1826 if (size
> es
->buffer_limit
)
1827 size
= es
->buffer_limit
;
1829 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1831 /* Force edit to unlock it's buffer. es->text now NULL */
1832 EDIT_UnlockBuffer(hwnd
, es
, TRUE
);
1835 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1836 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1837 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32W
, hNew32W
);
1838 es
->hloc32W
= hNew32W
;
1839 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1843 EDIT_LockBuffer(hwnd
, es
);
1845 if (es
->buffer_size
< size
) {
1846 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1847 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_ERRSPACE
, "EN_ERRSPACE");
1850 TRACE("We now have %d+1\n", es
->buffer_size
);
1856 /*********************************************************************
1860 * Try to fit size + 1 bytes in the undo buffer.
1863 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1867 if (size
<= es
->undo_buffer_size
)
1870 TRACE("trying to ReAlloc to %d+1\n", size
);
1872 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1873 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1874 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
);
1879 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1885 /*********************************************************************
1890 static void EDIT_MoveBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1892 INT e
= es
->selection_end
;
1896 if ((es
->style
& ES_MULTILINE
) && e
&&
1897 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1899 if (e
&& (es
->text
[e
- 1] == '\r'))
1903 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1904 EDIT_EM_ScrollCaret(hwnd
, es
);
1908 /*********************************************************************
1912 * Only for multi line controls
1913 * Move the caret one line down, on a column with the nearest
1914 * x coordinate on the screen (might be a different column).
1917 static void EDIT_MoveDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1919 INT s
= es
->selection_start
;
1920 INT e
= es
->selection_end
;
1921 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1922 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
1923 INT x
= SLOWORD(pos
);
1924 INT y
= SHIWORD(pos
);
1926 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1929 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
1930 EDIT_EM_ScrollCaret(hwnd
, es
);
1934 /*********************************************************************
1939 static void EDIT_MoveEnd(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1941 BOOL after_wrap
= FALSE
;
1944 /* Pass a high value in x to make sure of receiving the end of the line */
1945 if (es
->style
& ES_MULTILINE
)
1946 e
= EDIT_CharFromPos(hwnd
, es
, 0x3fffffff,
1947 HIWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1949 e
= strlenW(es
->text
);
1950 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1951 EDIT_EM_ScrollCaret(hwnd
, es
);
1955 /*********************************************************************
1960 static void EDIT_MoveForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1962 INT e
= es
->selection_end
;
1966 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1967 if (es
->text
[e
] == '\n')
1969 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1973 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1974 EDIT_EM_ScrollCaret(hwnd
, es
);
1978 /*********************************************************************
1982 * Home key: move to beginning of line.
1985 static void EDIT_MoveHome(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
1989 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1990 if (es
->style
& ES_MULTILINE
)
1991 e
= EDIT_CharFromPos(hwnd
, es
, -es
->x_offset
,
1992 HIWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1995 EDIT_EM_SetSel(hwnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1996 EDIT_EM_ScrollCaret(hwnd
, es
);
2000 /*********************************************************************
2002 * EDIT_MovePageDown_ML
2004 * Only for multi line controls
2005 * Move the caret one page down, on a column with the nearest
2006 * x coordinate on the screen (might be a different column).
2009 static void EDIT_MovePageDown_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2011 INT s
= es
->selection_start
;
2012 INT e
= es
->selection_end
;
2013 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2014 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
2015 INT x
= SLOWORD(pos
);
2016 INT y
= SHIWORD(pos
);
2018 e
= EDIT_CharFromPos(hwnd
, es
, x
,
2019 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2023 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
2024 EDIT_EM_ScrollCaret(hwnd
, es
);
2028 /*********************************************************************
2030 * EDIT_MovePageUp_ML
2032 * Only for multi line controls
2033 * Move the caret one page up, on a column with the nearest
2034 * x coordinate on the screen (might be a different column).
2037 static void EDIT_MovePageUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2039 INT s
= es
->selection_start
;
2040 INT e
= es
->selection_end
;
2041 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2042 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
2043 INT x
= SLOWORD(pos
);
2044 INT y
= SHIWORD(pos
);
2046 e
= EDIT_CharFromPos(hwnd
, es
, x
,
2047 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2051 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
2052 EDIT_EM_ScrollCaret(hwnd
, es
);
2056 /*********************************************************************
2060 * Only for multi line controls
2061 * Move the caret one line up, on a column with the nearest
2062 * x coordinate on the screen (might be a different column).
2065 static void EDIT_MoveUp_ML(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2067 INT s
= es
->selection_start
;
2068 INT e
= es
->selection_end
;
2069 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2070 LRESULT pos
= EDIT_EM_PosFromChar(hwnd
, es
, e
, after_wrap
);
2071 INT x
= SLOWORD(pos
);
2072 INT y
= SHIWORD(pos
);
2074 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
2077 EDIT_EM_SetSel(hwnd
, es
, s
, e
, after_wrap
);
2078 EDIT_EM_ScrollCaret(hwnd
, es
);
2082 /*********************************************************************
2084 * EDIT_MoveWordBackward
2087 static void EDIT_MoveWordBackward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2089 INT s
= es
->selection_start
;
2090 INT e
= es
->selection_end
;
2095 l
= EDIT_EM_LineFromChar(es
, e
);
2096 ll
= EDIT_EM_LineLength(es
, e
);
2097 li
= EDIT_EM_LineIndex(es
, l
);
2100 li
= EDIT_EM_LineIndex(es
, l
- 1);
2101 e
= li
+ EDIT_EM_LineLength(es
, li
);
2104 e
= li
+ (INT
)EDIT_CallWordBreakProc(es
,
2105 li
, e
- li
, ll
, WB_LEFT
);
2109 EDIT_EM_SetSel(hwnd
, es
, s
, e
, FALSE
);
2110 EDIT_EM_ScrollCaret(hwnd
, es
);
2114 /*********************************************************************
2116 * EDIT_MoveWordForward
2119 static void EDIT_MoveWordForward(HWND hwnd
, EDITSTATE
*es
, BOOL extend
)
2121 INT s
= es
->selection_start
;
2122 INT e
= es
->selection_end
;
2127 l
= EDIT_EM_LineFromChar(es
, e
);
2128 ll
= EDIT_EM_LineLength(es
, e
);
2129 li
= EDIT_EM_LineIndex(es
, l
);
2131 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2132 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2134 e
= li
+ EDIT_CallWordBreakProc(es
,
2135 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2139 EDIT_EM_SetSel(hwnd
, es
, s
, e
, FALSE
);
2140 EDIT_EM_ScrollCaret(hwnd
, es
);
2144 /*********************************************************************
2149 static void EDIT_PaintLine(HWND hwnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2151 INT s
= es
->selection_start
;
2152 INT e
= es
->selection_end
;
2159 if (es
->style
& ES_MULTILINE
) {
2160 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2161 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2166 TRACE("line=%d\n", line
);
2168 pos
= EDIT_EM_PosFromChar(hwnd
, es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2171 li
= EDIT_EM_LineIndex(es
, line
);
2172 ll
= EDIT_EM_LineLength(es
, li
);
2173 s
= es
->selection_start
;
2174 e
= es
->selection_end
;
2176 s
= min(li
+ ll
, max(li
, s
));
2177 e
= min(li
+ ll
, max(li
, e
));
2178 if (rev
&& (s
!= e
) &&
2179 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2180 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2181 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2182 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2184 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2188 /*********************************************************************
2193 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2204 BkMode
= GetBkMode(dc
);
2205 BkColor
= GetBkColor(dc
);
2206 TextColor
= GetTextColor(dc
);
2208 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2209 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2210 SetBkMode( dc
, OPAQUE
);
2212 li
= EDIT_EM_LineIndex(es
, line
);
2213 if (es
->style
& ES_MULTILINE
) {
2214 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2215 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2217 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2218 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2219 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2221 if (es
->style
& ES_PASSWORD
)
2222 HeapFree(GetProcessHeap(), 0, text
);
2225 SetBkColor(dc
, BkColor
);
2226 SetTextColor(dc
, TextColor
);
2227 SetBkMode( dc
, BkMode
);
2233 /*********************************************************************
2238 static void EDIT_SetCaretPos(HWND hwnd
, EDITSTATE
*es
, INT pos
,
2241 LRESULT res
= EDIT_EM_PosFromChar(hwnd
, es
, pos
, after_wrap
);
2242 SetCaretPos(SLOWORD(res
), SHIWORD(res
));
2246 /*********************************************************************
2250 * note: this is not (exactly) the handler called on EM_SETRECTNP
2251 * it is also used to set the rect of a single line control
2254 static void EDIT_SetRectNP(HWND hwnd
, EDITSTATE
*es
, LPRECT rc
)
2256 CopyRect(&es
->format_rect
, rc
);
2257 if (es
->style
& WS_BORDER
) {
2258 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2259 if(TWEAK_WineLook
== WIN31_LOOK
)
2261 es
->format_rect
.left
+= bw
;
2262 es
->format_rect
.top
+= bw
;
2263 es
->format_rect
.right
-= bw
;
2264 es
->format_rect
.bottom
-= bw
;
2266 es
->format_rect
.left
+= es
->left_margin
;
2267 es
->format_rect
.right
-= es
->right_margin
;
2268 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2269 if (es
->style
& ES_MULTILINE
)
2271 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2273 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2274 es
->format_rect
.bottom
= es
->format_rect
.top
+ max(1, vlc
) * es
->line_height
;
2276 /* correct es->x_offset */
2277 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2278 max_x_offset
= es
->text_width
- fw
;
2279 if(max_x_offset
< 0) max_x_offset
= 0;
2280 if(es
->x_offset
> max_x_offset
)
2281 es
->x_offset
= max_x_offset
;
2283 /* correct es->y_offset */
2284 max_y_offset
= es
->line_count
- vlc
;
2285 if(max_y_offset
< 0) max_y_offset
= 0;
2286 if(es
->y_offset
> max_y_offset
)
2287 es
->y_offset
= max_y_offset
;
2289 /* force scroll info update */
2290 EDIT_UpdateScrollInfo(hwnd
, es
);
2293 /* Windows doesn't care to fix text placement for SL controls */
2294 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2296 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2297 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
2301 /*********************************************************************
2306 static void EDIT_UnlockBuffer(HWND hwnd
, EDITSTATE
*es
, BOOL force
)
2308 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
2310 /* Edit window might be already destroyed */
2313 WARN("edit hwnd %04x already destroyed\n", hwnd
);
2318 ERR("no EDITSTATE ... please report\n");
2321 if (!es
->lock_count
) {
2322 ERR("lock_count == 0 ... please report\n");
2326 ERR("es->text == 0 ... please report\n");
2330 if (force
|| (es
->lock_count
== 1)) {
2333 BOOL _16bit
= FALSE
;
2335 UINT countW
= strlenW(es
->text
) + 1;
2339 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2340 TRACE("Synchronizing with 32-bit ANSI buffer\n");
2341 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2342 countA
= LocalSize(es
->hloc32A
);
2343 if(countA_new
> countA
)
2346 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2347 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2348 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2351 es
->hloc32A
= hloc32A_new
;
2352 countA
= LocalSize(hloc32A_new
);
2353 TRACE("Real new size %d bytes\n", countA
);
2356 WARN("FAILED! Will synchronize partially\n");
2358 textA
= LocalLock(es
->hloc32A
);
2362 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
2363 TRACE("Synchronizing with 16-bit ANSI buffer\n");
2364 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
2365 countA
= LOCAL_Size(hInstance
, es
->hloc16
);
2366 if(countA_new
> countA
)
2368 HLOCAL16 hloc16_new
;
2369 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
2370 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
2371 hloc16_new
= LOCAL_ReAlloc(hInstance
, es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
2374 es
->hloc16
= hloc16_new
;
2375 countA
= LOCAL_Size(hInstance
, hloc16_new
);
2376 TRACE("Real new size %d bytes\n", countA
);
2379 WARN("FAILED! Will synchronize partially\n");
2381 textA
= LOCAL_Lock(hInstance
, es
->hloc16
);
2387 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
2389 LOCAL_Unlock(hInstance
, es
->hloc16
);
2391 LocalUnlock(es
->hloc32A
);
2394 LocalUnlock(es
->hloc32W
);
2398 ERR("no buffer ... please report\n");
2406 /*********************************************************************
2408 * EDIT_UpdateScrollInfo
2411 static void EDIT_UpdateScrollInfo(HWND hwnd
, EDITSTATE
*es
)
2413 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
2416 si
.cbSize
= sizeof(SCROLLINFO
);
2417 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2419 si
.nMax
= es
->line_count
- 1;
2420 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2421 si
.nPos
= es
->y_offset
;
2422 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2423 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2424 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2427 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
2430 si
.cbSize
= sizeof(SCROLLINFO
);
2431 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
2433 si
.nMax
= es
->text_width
- 1;
2434 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
2435 si
.nPos
= es
->x_offset
;
2436 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2437 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
2438 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2442 /*********************************************************************
2444 * EDIT_WordBreakProc
2446 * Find the beginning of words.
2447 * Note: unlike the specs for a WordBreakProc, this function only
2448 * allows to be called without linebreaks between s[0] upto
2449 * s[count - 1]. Remember it is only called
2450 * internally, so we can decide this for ourselves.
2453 static INT CALLBACK
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
2457 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
2467 if (s
[index
] == ' ') {
2468 while (index
&& (s
[index
] == ' '))
2471 while (index
&& (s
[index
] != ' '))
2473 if (s
[index
] == ' ')
2477 while (index
&& (s
[index
] != ' '))
2479 if (s
[index
] == ' ')
2489 if (s
[index
] == ' ')
2490 while ((index
< count
) && (s
[index
] == ' ')) index
++;
2492 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
2494 while ((s
[index
] == ' ') && (index
< count
)) index
++;
2498 case WB_ISDELIMITER
:
2499 ret
= (s
[index
] == ' ');
2502 ERR("unknown action code, please report !\n");
2509 /*********************************************************************
2513 * returns line number (not index) in high-order word of result.
2514 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2515 * to Richedit, not to the edit control. Original documentation is valid.
2516 * FIXME: do the specs mean to return -1 if outside client area or
2517 * if outside formatting rectangle ???
2520 static LRESULT
EDIT_EM_CharFromPos(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
)
2528 GetClientRect(hwnd
, &rc
);
2529 if (!PtInRect(&rc
, pt
))
2532 index
= EDIT_CharFromPos(hwnd
, es
, x
, y
, NULL
);
2533 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2537 /*********************************************************************
2541 * Enable or disable soft breaks.
2543 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2545 es
->flags
&= ~EF_USE_SOFTBRK
;
2547 es
->flags
|= EF_USE_SOFTBRK
;
2548 FIXME("soft break enabled, not implemented\n");
2554 /*********************************************************************
2558 * Hopefully this won't fire back at us.
2559 * We always start with a fixed buffer in the local heap.
2560 * Despite of the documentation says that the local heap is used
2561 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2562 * buffer on the local heap.
2565 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2569 if (!(es
->style
& ES_MULTILINE
))
2573 hLocal
= es
->hloc32W
;
2579 UINT countA
, alloc_size
;
2580 TRACE("Allocating 32-bit ANSI alias buffer\n");
2581 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2582 alloc_size
= ROUND_TO_GROW(countA
);
2583 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2585 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2588 textA
= LocalLock(es
->hloc32A
);
2589 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2590 LocalUnlock(es
->hloc32A
);
2592 hLocal
= es
->hloc32A
;
2595 TRACE("Returning %04X, LocalSize() = %d\n", hLocal
, LocalSize(hLocal
));
2600 /*********************************************************************
2604 * Hopefully this won't fire back at us.
2605 * We always start with a buffer in 32 bit linear memory.
2606 * However, with this message a 16 bit application requests
2607 * a handle of 16 bit local heap memory, where it expects to find
2609 * It's a pitty that from this moment on we have to use this
2610 * local heap, because applications may rely on the handle
2613 * In this function we'll try to switch to local heap.
2615 static HLOCAL16
EDIT_EM_GetHandle16(HWND hwnd
, EDITSTATE
*es
)
2617 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
2619 UINT countA
, alloc_size
;
2621 if (!(es
->style
& ES_MULTILINE
))
2627 if (!LOCAL_HeapSize(hInstance
)) {
2628 if (!LocalInit16(hInstance
, 0,
2629 GlobalSize16(hInstance
))) {
2630 ERR("could not initialize local heap\n");
2633 TRACE("local heap initialized\n");
2636 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2637 alloc_size
= ROUND_TO_GROW(countA
);
2639 TRACE("Allocating 16-bit ANSI alias buffer\n");
2640 if (!(es
->hloc16
= LOCAL_Alloc(hInstance
, LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2641 ERR("could not allocate new 16 bit buffer\n");
2645 if (!(textA
= (LPSTR
)LOCAL_Lock(hInstance
, es
->hloc16
))) {
2646 ERR("could not lock new 16 bit buffer\n");
2647 LOCAL_Free(hInstance
, es
->hloc16
);
2652 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2653 LOCAL_Unlock(hInstance
, es
->hloc16
);
2655 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LOCAL_Size(hInstance
, es
->hloc16
));
2660 /*********************************************************************
2665 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPARAM lParam
, BOOL unicode
)
2668 INT line_len
, dst_len
;
2671 if (es
->style
& ES_MULTILINE
) {
2672 if (line
>= es
->line_count
)
2676 i
= EDIT_EM_LineIndex(es
, line
);
2678 line_len
= EDIT_EM_LineLength(es
, i
);
2679 dst_len
= *(WORD
*)lParam
;
2682 LPWSTR dst
= (LPWSTR
)lParam
;
2683 if(dst_len
<= line_len
)
2685 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2688 else /* Append 0 if enough space */
2690 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2697 LPSTR dst
= (LPSTR
)lParam
;
2699 ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, dst
, dst_len
, NULL
, NULL
);
2700 if(!ret
) /* Insufficient buffer size */
2702 if(ret
< dst_len
) /* Append 0 if enough space */
2709 /*********************************************************************
2714 static LRESULT
EDIT_EM_GetSel(EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2716 UINT s
= es
->selection_start
;
2717 UINT e
= es
->selection_end
;
2724 return MAKELONG(s
, e
);
2728 /*********************************************************************
2732 * FIXME: is this right ? (or should it be only VSCROLL)
2733 * (and maybe only for edit controls that really have their
2734 * own scrollbars) (and maybe only for multiline controls ?)
2735 * All in all: very poorly documented
2738 static LRESULT
EDIT_EM_GetThumb(HWND hwnd
, EDITSTATE
*es
)
2740 return MAKELONG(EDIT_WM_VScroll(hwnd
, es
, EM_GETTHUMB16
, 0),
2741 EDIT_WM_HScroll(hwnd
, es
, EM_GETTHUMB16
, 0));
2745 /*********************************************************************
2750 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
2755 if (!(es
->style
& ES_MULTILINE
))
2757 if (index
> (INT
)strlenW(es
->text
))
2758 return es
->line_count
- 1;
2760 index
= min(es
->selection_start
, es
->selection_end
);
2763 line_def
= es
->first_line_def
;
2764 index
-= line_def
->length
;
2765 while ((index
>= 0) && line_def
->next
) {
2767 line_def
= line_def
->next
;
2768 index
-= line_def
->length
;
2774 /*********************************************************************
2779 static INT
EDIT_EM_LineIndex(EDITSTATE
*es
, INT line
)
2784 if (!(es
->style
& ES_MULTILINE
))
2786 if (line
>= es
->line_count
)
2790 line_def
= es
->first_line_def
;
2792 INT index
= es
->selection_end
- line_def
->length
;
2793 while ((index
>= 0) && line_def
->next
) {
2794 line_index
+= line_def
->length
;
2795 line_def
= line_def
->next
;
2796 index
-= line_def
->length
;
2800 line_index
+= line_def
->length
;
2801 line_def
= line_def
->next
;
2809 /*********************************************************************
2814 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
2818 if (!(es
->style
& ES_MULTILINE
))
2819 return strlenW(es
->text
);
2822 /* get the number of remaining non-selected chars of selected lines */
2825 li
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
2826 /* # chars before start of selection area */
2827 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, li
);
2828 li
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
2829 /* # chars after end of selection */
2830 count
+= EDIT_EM_LineIndex(es
, li
) +
2831 EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
2834 line_def
= es
->first_line_def
;
2835 index
-= line_def
->length
;
2836 while ((index
>= 0) && line_def
->next
) {
2837 line_def
= line_def
->next
;
2838 index
-= line_def
->length
;
2840 return line_def
->net_length
;
2844 /*********************************************************************
2848 * NOTE: dx is in average character widths, dy - in lines;
2851 static BOOL
EDIT_EM_LineScroll(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2853 if (!(es
->style
& ES_MULTILINE
))
2856 dx
*= es
->char_width
;
2857 return EDIT_EM_LineScroll_internal(hwnd
, es
, dx
, dy
);
2860 /*********************************************************************
2862 * EDIT_EM_LineScroll_internal
2864 * Version of EDIT_EM_LineScroll for internal use.
2865 * It doesn't refuse if ES_MULTILINE is set and assumes that
2866 * dx is in pixels, dy - in lines.
2869 static BOOL
EDIT_EM_LineScroll_internal(HWND hwnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2872 INT x_offset_in_pixels
;
2874 if (es
->style
& ES_MULTILINE
)
2876 x_offset_in_pixels
= es
->x_offset
;
2881 x_offset_in_pixels
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->x_offset
, FALSE
));
2884 if (-dx
> x_offset_in_pixels
)
2885 dx
= -x_offset_in_pixels
;
2886 if (dx
> es
->text_width
- x_offset_in_pixels
)
2887 dx
= es
->text_width
- x_offset_in_pixels
;
2888 nyoff
= max(0, es
->y_offset
+ dy
);
2889 if (nyoff
>= es
->line_count
)
2890 nyoff
= es
->line_count
- 1;
2891 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2896 es
->y_offset
= nyoff
;
2897 if(es
->style
& ES_MULTILINE
)
2900 es
->x_offset
+= dx
/ es
->char_width
;
2902 GetClientRect(hwnd
, &rc1
);
2903 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2904 ScrollWindowEx(hwnd
, -dx
, dy
,
2905 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2906 /* force scroll info update */
2907 EDIT_UpdateScrollInfo(hwnd
, es
);
2909 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2910 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_HSCROLL
, "EN_HSCROLL");
2911 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2912 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_VSCROLL
, "EN_VSCROLL");
2917 /*********************************************************************
2922 static LRESULT
EDIT_EM_PosFromChar(HWND hwnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2924 INT len
= strlenW(es
->text
);
2933 index
= min(index
, len
);
2936 old_font
= SelectObject(dc
, es
->font
);
2937 if (es
->style
& ES_MULTILINE
) {
2938 l
= EDIT_EM_LineFromChar(es
, index
);
2939 y
= (l
- es
->y_offset
) * es
->line_height
;
2940 li
= EDIT_EM_LineIndex(es
, l
);
2941 if (after_wrap
&& (li
== index
) && l
) {
2943 LINEDEF
*line_def
= es
->first_line_def
;
2945 line_def
= line_def
->next
;
2948 if (line_def
->ending
== END_WRAP
) {
2950 y
-= es
->line_height
;
2951 li
= EDIT_EM_LineIndex(es
, l
);
2954 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
2955 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2957 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2958 if (index
< es
->x_offset
) {
2959 GetTextExtentPoint32W(dc
, text
+ index
,
2960 es
->x_offset
- index
, &size
);
2963 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
2964 index
- es
->x_offset
, &size
);
2968 if (es
->style
& ES_PASSWORD
)
2969 HeapFree(GetProcessHeap(), 0, text
);
2971 x
+= es
->format_rect
.left
;
2972 y
+= es
->format_rect
.top
;
2974 SelectObject(dc
, old_font
);
2975 ReleaseDC(hwnd
, dc
);
2976 return MAKELONG((INT16
)x
, (INT16
)y
);
2980 /*********************************************************************
2984 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2987 static void EDIT_EM_ReplaceSel(HWND hwnd
, EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
)
2989 UINT strl
= strlenW(lpsz_replace
);
2990 UINT tl
= strlenW(es
->text
);
2998 TRACE("%s, can_undo %d, send_update %d\n",
2999 debugstr_w(lpsz_replace
), can_undo
, send_update
);
3001 s
= es
->selection_start
;
3002 e
= es
->selection_end
;
3004 if ((s
== e
) && !strl
)
3009 if (!EDIT_MakeFit(hwnd
, es
, tl
- (e
- s
) + strl
))
3013 /* there is something to be deleted */
3015 utl
= strlenW(es
->undo_text
);
3016 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
3017 /* undo-buffer is extended to the right */
3018 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3019 strncpyW(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
3020 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
3021 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
3022 /* undo-buffer is extended to the left */
3023 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
3024 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
3026 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
3027 p
[i
] = (es
->text
+ s
)[i
];
3028 es
->undo_position
= s
;
3030 /* new undo-buffer */
3031 EDIT_MakeUndoFit(es
, e
- s
);
3032 strncpyW(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
3033 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
3034 es
->undo_position
= s
;
3036 /* any deletion makes the old insertion-undo invalid */
3037 es
->undo_insert_count
= 0;
3039 EDIT_EM_EmptyUndoBuffer(es
);
3042 strcpyW(es
->text
+ s
, es
->text
+ e
);
3045 /* there is an insertion */
3047 if ((s
== es
->undo_position
) ||
3048 ((es
->undo_insert_count
) &&
3049 (s
== es
->undo_position
+ es
->undo_insert_count
)))
3051 * insertion is new and at delete position or
3052 * an extension to either left or right
3054 es
->undo_insert_count
+= strl
;
3056 /* new insertion undo */
3057 es
->undo_position
= s
;
3058 es
->undo_insert_count
= strl
;
3059 /* new insertion makes old delete-buffer invalid */
3060 *es
->undo_text
= '\0';
3063 EDIT_EM_EmptyUndoBuffer(es
);
3066 tl
= strlenW(es
->text
);
3067 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
3069 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
3070 p
[i
] = lpsz_replace
[i
];
3071 if(es
->style
& ES_UPPERCASE
)
3072 CharUpperBuffW(p
, strl
);
3073 else if(es
->style
& ES_LOWERCASE
)
3074 CharLowerBuffW(p
, strl
);
3077 if (es
->style
& ES_MULTILINE
)
3079 INT s
= min(es
->selection_start
, es
->selection_end
);
3081 hrgn
= CreateRectRgn(0, 0, 0, 0);
3082 EDIT_BuildLineDefs_ML(hwnd
, es
, s
, s
+ strl
,
3083 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
3086 EDIT_CalcLineWidth_SL(hwnd
, es
);
3088 EDIT_EM_SetSel(hwnd
, es
, s
, s
, FALSE
);
3089 es
->flags
|= EF_MODIFIED
;
3090 if (send_update
) es
->flags
|= EF_UPDATE
;
3091 EDIT_EM_ScrollCaret(hwnd
, es
);
3093 /* force scroll info update */
3094 EDIT_UpdateScrollInfo(hwnd
, es
);
3098 EDIT_UpdateTextRegion(hwnd
, es
, hrgn
, TRUE
);
3102 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3104 if(es
->flags
& EF_UPDATE
)
3106 es
->flags
&= ~EF_UPDATE
;
3107 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
3112 /*********************************************************************
3117 static LRESULT
EDIT_EM_Scroll(HWND hwnd
, EDITSTATE
*es
, INT action
)
3121 if (!(es
->style
& ES_MULTILINE
))
3122 return (LRESULT
)FALSE
;
3132 if (es
->y_offset
< es
->line_count
- 1)
3137 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3140 if (es
->y_offset
< es
->line_count
- 1)
3141 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3144 return (LRESULT
)FALSE
;
3147 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3148 /* check if we are going to move too far */
3149 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
3150 dy
= es
->line_count
- vlc
- es
->y_offset
;
3152 /* Notification is done in EDIT_EM_LineScroll */
3154 EDIT_EM_LineScroll(hwnd
, es
, 0, dy
);
3156 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
3160 /*********************************************************************
3165 static void EDIT_EM_ScrollCaret(HWND hwnd
, EDITSTATE
*es
)
3167 if (es
->style
& ES_MULTILINE
) {
3172 INT cw
= es
->char_width
;
3177 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
3178 li
= EDIT_EM_LineIndex(es
, l
);
3179 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
3180 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3181 if (l
>= es
->y_offset
+ vlc
)
3182 dy
= l
- vlc
+ 1 - es
->y_offset
;
3183 if (l
< es
->y_offset
)
3184 dy
= l
- es
->y_offset
;
3185 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
3186 if (x
< es
->format_rect
.left
)
3187 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3188 if (x
> es
->format_rect
.right
)
3189 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
3192 /* check if we are going to move too far */
3193 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
3194 dx
= es
->text_width
- ww
- es
->x_offset
;
3196 EDIT_EM_LineScroll_internal(hwnd
, es
, dx
, dy
);
3203 if (!(es
->style
& ES_AUTOHSCROLL
))
3206 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, FALSE
));
3207 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
3208 if (x
< es
->format_rect
.left
) {
3209 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
3212 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, FALSE
));
3213 } while ((x
< goal
) && es
->x_offset
);
3214 /* FIXME: use ScrollWindow() somehow to improve performance */
3215 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3216 } else if (x
> es
->format_rect
.right
) {
3218 INT len
= strlenW(es
->text
);
3219 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
3222 x
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, es
->selection_end
, FALSE
));
3223 x_last
= SLOWORD(EDIT_EM_PosFromChar(hwnd
, es
, len
, FALSE
));
3224 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
3225 /* FIXME: use ScrollWindow() somehow to improve performance */
3226 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3230 if(es
->flags
& EF_FOCUSED
)
3231 EDIT_SetCaretPos(hwnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3235 /*********************************************************************
3239 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3242 static void EDIT_EM_SetHandle(HWND hwnd
, EDITSTATE
*es
, HLOCAL hloc
)
3244 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
3246 if (!(es
->style
& ES_MULTILINE
))
3250 WARN("called with NULL handle\n");
3254 EDIT_UnlockBuffer(hwnd
, es
, TRUE
);
3258 LOCAL_Free(hInstance
, es
->hloc16
);
3259 es
->hloc16
= (HLOCAL16
)NULL
;
3266 LocalFree(es
->hloc32A
);
3267 es
->hloc32A
= (HLOCAL
)NULL
;
3278 countA
= LocalSize(hloc
);
3279 textA
= LocalLock(hloc
);
3280 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3281 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3283 ERR("Could not allocate new unicode buffer\n");
3286 textW
= LocalLock(hloc32W_new
);
3287 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3288 LocalUnlock(hloc32W_new
);
3292 LocalFree(es
->hloc32W
);
3294 es
->hloc32W
= hloc32W_new
;
3298 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3300 EDIT_LockBuffer(hwnd
, es
);
3302 es
->x_offset
= es
->y_offset
= 0;
3303 es
->selection_start
= es
->selection_end
= 0;
3304 EDIT_EM_EmptyUndoBuffer(es
);
3305 es
->flags
&= ~EF_MODIFIED
;
3306 es
->flags
&= ~EF_UPDATE
;
3307 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3308 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3309 EDIT_EM_ScrollCaret(hwnd
, es
);
3310 /* force scroll info update */
3311 EDIT_UpdateScrollInfo(hwnd
, es
);
3315 /*********************************************************************
3319 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3322 static void EDIT_EM_SetHandle16(HWND hwnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
3324 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
3330 if (!(es
->style
& ES_MULTILINE
))
3334 WARN("called with NULL handle\n");
3338 EDIT_UnlockBuffer(hwnd
, es
, TRUE
);
3342 LocalFree(es
->hloc32A
);
3343 es
->hloc32A
= (HLOCAL
)NULL
;
3346 countA
= LOCAL_Size(hInstance
, hloc
);
3347 textA
= LOCAL_Lock(hInstance
, hloc
);
3348 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
3349 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
3351 ERR("Could not allocate new unicode buffer\n");
3354 textW
= LocalLock(hloc32W_new
);
3355 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
3356 LocalUnlock(hloc32W_new
);
3357 LOCAL_Unlock(hInstance
, hloc
);
3360 LocalFree(es
->hloc32W
);
3362 es
->hloc32W
= hloc32W_new
;
3365 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
3367 EDIT_LockBuffer(hwnd
, es
);
3369 es
->x_offset
= es
->y_offset
= 0;
3370 es
->selection_start
= es
->selection_end
= 0;
3371 EDIT_EM_EmptyUndoBuffer(es
);
3372 es
->flags
&= ~EF_MODIFIED
;
3373 es
->flags
&= ~EF_UPDATE
;
3374 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3375 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3376 EDIT_EM_ScrollCaret(hwnd
, es
);
3377 /* force scroll info update */
3378 EDIT_UpdateScrollInfo(hwnd
, es
);
3382 /*********************************************************************
3386 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3387 * However, the windows version is not complied to yet in all of edit.c
3390 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, INT limit
)
3392 if (es
->style
& ES_MULTILINE
) {
3394 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
3396 es
->buffer_limit
= BUFLIMIT_MULTI
;
3399 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
3401 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3406 /*********************************************************************
3410 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
3411 * action wParam despite what the docs say. EC_USEFONTINFO means one third
3412 * of the char's width, according to the new docs.
3415 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
3416 INT left
, INT right
)
3418 if (action
& EC_LEFTMARGIN
) {
3419 if (left
!= EC_USEFONTINFO
)
3420 es
->left_margin
= left
;
3422 es
->left_margin
= es
->char_width
/ 3;
3425 if (action
& EC_RIGHTMARGIN
) {
3426 if (right
!= EC_USEFONTINFO
)
3427 es
->right_margin
= right
;
3429 es
->right_margin
= es
->char_width
/ 3;
3431 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3435 /*********************************************************************
3437 * EM_SETPASSWORDCHAR
3440 static void EDIT_EM_SetPasswordChar(HWND hwnd
, EDITSTATE
*es
, WCHAR c
)
3444 if (es
->style
& ES_MULTILINE
)
3447 if (es
->password_char
== c
)
3450 style
= GetWindowLongA( hwnd
, GWL_STYLE
);
3451 es
->password_char
= c
;
3453 SetWindowLongA( hwnd
, GWL_STYLE
, style
| ES_PASSWORD
);
3454 es
->style
|= ES_PASSWORD
;
3456 SetWindowLongA( hwnd
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3457 es
->style
&= ~ES_PASSWORD
;
3459 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3463 /*********************************************************************
3467 * note: unlike the specs say: the order of start and end
3468 * _is_ preserved in Windows. (i.e. start can be > end)
3469 * In other words: this handler is OK
3472 static void EDIT_EM_SetSel(HWND hwnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
3474 UINT old_start
= es
->selection_start
;
3475 UINT old_end
= es
->selection_end
;
3476 UINT len
= strlenW(es
->text
);
3478 if (start
== (UINT
)-1) {
3479 start
= es
->selection_end
;
3480 end
= es
->selection_end
;
3482 start
= min(start
, len
);
3483 end
= min(end
, len
);
3485 es
->selection_start
= start
;
3486 es
->selection_end
= end
;
3488 es
->flags
|= EF_AFTER_WRAP
;
3490 es
->flags
&= ~EF_AFTER_WRAP
;
3491 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
3492 ORDER_UINT(start
, end
);
3493 ORDER_UINT(end
, old_end
);
3494 ORDER_UINT(start
, old_start
);
3495 ORDER_UINT(old_start
, old_end
);
3496 if (end
!= old_start
)
3500 * ORDER_UINT32(end, old_start);
3501 * EDIT_InvalidateText(hwnd, es, start, end);
3502 * EDIT_InvalidateText(hwnd, es, old_start, old_end);
3503 * in place of the following if statement.
3505 if (old_start
> end
)
3507 EDIT_InvalidateText(hwnd
, es
, start
, end
);
3508 EDIT_InvalidateText(hwnd
, es
, old_start
, old_end
);
3512 EDIT_InvalidateText(hwnd
, es
, start
, old_start
);
3513 EDIT_InvalidateText(hwnd
, es
, end
, old_end
);
3516 else EDIT_InvalidateText(hwnd
, es
, start
, old_end
);
3520 /*********************************************************************
3525 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, LPINT tabs
)
3527 if (!(es
->style
& ES_MULTILINE
))
3530 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3531 es
->tabs_count
= count
;
3535 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3536 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3542 /*********************************************************************
3547 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, LPINT16 tabs
)
3549 if (!(es
->style
& ES_MULTILINE
))
3552 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3553 es
->tabs_count
= count
;
3558 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3559 for (i
= 0 ; i
< count
; i
++)
3560 es
->tabs
[i
] = *tabs
++;
3566 /*********************************************************************
3568 * EM_SETWORDBREAKPROC
3571 static void EDIT_EM_SetWordBreakProc(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
)
3573 if (es
->word_break_proc
== (void *)lParam
)
3576 es
->word_break_proc
= (void *)lParam
;
3577 es
->word_break_proc16
= NULL
;
3579 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3580 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3581 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3586 /*********************************************************************
3588 * EM_SETWORDBREAKPROC16
3591 static void EDIT_EM_SetWordBreakProc16(HWND hwnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3593 if (es
->word_break_proc16
== wbp
)
3596 es
->word_break_proc
= NULL
;
3597 es
->word_break_proc16
= wbp
;
3598 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3599 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
3600 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
3605 /*********************************************************************
3610 static BOOL
EDIT_EM_Undo(HWND hwnd
, EDITSTATE
*es
)
3615 /* Protect read-only edit control from modification */
3616 if(es
->style
& ES_READONLY
)
3619 ulength
= strlenW(es
->undo_text
);
3620 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3622 strcpyW(utext
, es
->undo_text
);
3624 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3625 es
->undo_insert_count
, debugstr_w(utext
));
3627 EDIT_EM_SetSel(hwnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3628 EDIT_EM_EmptyUndoBuffer(es
);
3629 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, utext
, FALSE
);
3630 EDIT_EM_SetSel(hwnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3631 /* send the notification after the selection start and end are set */
3632 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
3633 EDIT_EM_ScrollCaret(hwnd
, es
);
3634 HeapFree(GetProcessHeap(), 0, utext
);
3636 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3637 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3642 /*********************************************************************
3647 static void EDIT_WM_Char(HWND hwnd
, EDITSTATE
*es
, WCHAR c
)
3651 /* Protect read-only edit control from modification */
3652 if(es
->style
& ES_READONLY
)
3655 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3659 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3660 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3663 if (es
->style
& ES_MULTILINE
) {
3664 if (es
->style
& ES_READONLY
) {
3665 EDIT_MoveHome(hwnd
, es
, FALSE
);
3666 EDIT_MoveDown_ML(hwnd
, es
, FALSE
);
3668 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3669 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, cr_lfW
, TRUE
);
3674 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3676 static const WCHAR tabW
[] = {'\t',0};
3677 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, tabW
, TRUE
);
3681 if (!(es
->style
& ES_READONLY
) && !control
) {
3682 if (es
->selection_start
!= es
->selection_end
)
3683 EDIT_WM_Clear(hwnd
, es
);
3685 /* delete character left of caret */
3686 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
3687 EDIT_MoveBackward(hwnd
, es
, TRUE
);
3688 EDIT_WM_Clear(hwnd
, es
);
3693 SendMessageW(hwnd
, WM_COPY
, 0, 0);
3696 SendMessageW(hwnd
, WM_PASTE
, 0, 0);
3699 SendMessageW(hwnd
, WM_CUT
, 0, 0);
3703 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3707 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, str
, TRUE
);
3714 /*********************************************************************
3719 static void EDIT_WM_Command(HWND hwnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3721 if (code
|| control
)
3726 EDIT_EM_Undo(hwnd
, es
);
3729 EDIT_WM_Cut(hwnd
, es
);
3732 EDIT_WM_Copy(hwnd
, es
);
3735 EDIT_WM_Paste(hwnd
, es
);
3738 EDIT_WM_Clear(hwnd
, es
);
3741 EDIT_EM_SetSel(hwnd
, es
, 0, (UINT
)-1, FALSE
);
3742 EDIT_EM_ScrollCaret(hwnd
, es
);
3745 ERR("unknown menu item, please report\n");
3751 /*********************************************************************
3755 * Note: the resource files resource/sysres_??.rc cannot define a
3756 * single popup menu. Hence we use a (dummy) menubar
3757 * containing the single popup menu as its first item.
3759 * FIXME: the message identifiers have been chosen arbitrarily,
3760 * hence we use MF_BYPOSITION.
3761 * We might as well use the "real" values (anybody knows ?)
3762 * The menu definition is in resources/sysres_??.rc.
3763 * Once these are OK, we better use MF_BYCOMMAND here
3764 * (as we do in EDIT_WM_Command()).
3767 static void EDIT_WM_ContextMenu(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
)
3769 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3770 HMENU popup
= GetSubMenu(menu
, 0);
3771 UINT start
= es
->selection_start
;
3772 UINT end
= es
->selection_end
;
3774 ORDER_UINT(start
, end
);
3777 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3779 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3781 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3783 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3785 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3787 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlenW(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3789 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, hwnd
, NULL
);
3794 /*********************************************************************
3799 static void EDIT_WM_Copy(HWND hwnd
, EDITSTATE
*es
)
3801 INT s
= es
->selection_start
;
3802 INT e
= es
->selection_end
;
3809 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (DWORD
)(e
- s
+ 1) * sizeof(WCHAR
));
3810 dst
= GlobalLock(hdst
);
3811 strncpyW(dst
, es
->text
+ s
, e
- s
);
3812 dst
[e
- s
] = 0; /* ensure 0 termination */
3813 TRACE("%s\n", debugstr_w(dst
));
3815 OpenClipboard(hwnd
);
3817 SetClipboardData(CF_UNICODETEXT
, hdst
);
3822 /*********************************************************************
3827 static LRESULT
EDIT_WM_Create(HWND hwnd
, EDITSTATE
*es
, LPCWSTR name
)
3829 TRACE("%s\n", debugstr_w(name
));
3831 * To initialize some final structure members, we call some helper
3832 * functions. However, since the EDITSTATE is not consistent (i.e.
3833 * not fully initialized), we should be very careful which
3834 * functions can be called, and in what order.
3836 EDIT_WM_SetFont(hwnd
, es
, 0, FALSE
);
3837 EDIT_EM_EmptyUndoBuffer(es
);
3839 if (name
&& *name
) {
3840 EDIT_EM_ReplaceSel(hwnd
, es
, FALSE
, name
, FALSE
);
3841 /* if we insert text to the editline, the text scrolls out
3842 * of the window, as the caret is placed after the insert
3843 * pos normally; thus we reset es->selection... to 0 and
3846 es
->selection_start
= es
->selection_end
= 0;
3847 /* send the notification after the selection start and end are set */
3848 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
3849 EDIT_EM_ScrollCaret(hwnd
, es
);
3851 /* force scroll info update */
3852 EDIT_UpdateScrollInfo(hwnd
, es
);
3857 /*********************************************************************
3862 static void EDIT_WM_Destroy(HWND hwnd
, EDITSTATE
*es
)
3864 HINSTANCE hInstance
= GetWindowLongA( hwnd
, GWL_HINSTANCE
);
3868 while (LocalUnlock(es
->hloc32W
)) ;
3869 LocalFree(es
->hloc32W
);
3872 while (LocalUnlock(es
->hloc32A
)) ;
3873 LocalFree(es
->hloc32A
);
3876 while (LOCAL_Unlock(hInstance
, es
->hloc16
)) ;
3877 LOCAL_Free(hInstance
, es
->hloc16
);
3880 pc
= es
->first_line_def
;
3884 HeapFree(GetProcessHeap(), 0, pc
);
3888 SetWindowLongA( hwnd
, 0, 0 );
3889 HeapFree(GetProcessHeap(), 0, es
);
3893 /*********************************************************************
3898 static LRESULT
EDIT_WM_EraseBkGnd(HWND hwnd
, EDITSTATE
*es
, HDC dc
)
3903 if ( get_app_version() >= 0x40000 &&(
3904 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3905 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(hwnd
, dc
);
3907 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(hwnd
, dc
);
3910 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3912 GetClientRect(hwnd
, &rc
);
3913 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3914 GetClipBox(dc
, &rc
);
3916 * FIXME: specs say that we should UnrealizeObject() the brush,
3917 * but the specs of UnrealizeObject() say that we shouldn't
3918 * unrealize a stock object. The default brush that
3919 * DefWndProc() returns is ... a stock object.
3921 FillRect(dc
, &rc
, brush
);
3926 /*********************************************************************
3931 static INT
EDIT_WM_GetText(EDITSTATE
*es
, INT count
, LPARAM lParam
, BOOL unicode
)
3933 if(!count
) return 0;
3937 LPWSTR textW
= (LPWSTR
)lParam
;
3938 strncpyW(textW
, es
->text
, count
);
3939 textW
[count
- 1] = 0; /* ensure 0 termination */
3940 return strlenW(textW
);
3944 LPSTR textA
= (LPSTR
)lParam
;
3945 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
);
3946 textA
[count
- 1] = 0; /* ensure 0 termination */
3947 return strlen(textA
);
3951 /*********************************************************************
3956 static LRESULT
EDIT_WM_HScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
)
3961 if (!(es
->style
& ES_MULTILINE
))
3964 if (!(es
->style
& ES_AUTOHSCROLL
))
3968 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3971 TRACE("SB_LINELEFT\n");
3973 dx
= -es
->char_width
;
3976 TRACE("SB_LINERIGHT\n");
3977 if (es
->x_offset
< es
->text_width
)
3978 dx
= es
->char_width
;
3981 TRACE("SB_PAGELEFT\n");
3983 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3986 TRACE("SB_PAGERIGHT\n");
3987 if (es
->x_offset
< es
->text_width
)
3988 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3996 TRACE("SB_RIGHT\n");
3997 if (es
->x_offset
< es
->text_width
)
3998 dx
= es
->text_width
- es
->x_offset
;
4001 TRACE("SB_THUMBTRACK %d\n", pos
);
4002 es
->flags
|= EF_HSCROLL_TRACK
;
4003 if(es
->style
& WS_HSCROLL
)
4004 dx
= pos
- es
->x_offset
;
4009 if(pos
< 0 || pos
> 100) return 0;
4010 /* Assume default scroll range 0-100 */
4011 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4012 new_x
= pos
* (es
->text_width
- fw
) / 100;
4013 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4016 case SB_THUMBPOSITION
:
4017 TRACE("SB_THUMBPOSITION %d\n", pos
);
4018 es
->flags
&= ~EF_HSCROLL_TRACK
;
4019 if(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_HSCROLL
)
4020 dx
= pos
- es
->x_offset
;
4025 if(pos
< 0 || pos
> 100) return 0;
4026 /* Assume default scroll range 0-100 */
4027 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4028 new_x
= pos
* (es
->text_width
- fw
) / 100;
4029 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4032 /* force scroll info update */
4033 EDIT_UpdateScrollInfo(hwnd
, es
);
4034 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_HSCROLL
, "EN_HSCROLL");
4038 TRACE("SB_ENDSCROLL\n");
4041 * FIXME : the next two are undocumented !
4042 * Are we doing the right thing ?
4043 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4044 * although it's also a regular control message.
4046 case EM_GETTHUMB
: /* this one is used by NT notepad */
4050 if(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_HSCROLL
)
4051 ret
= GetScrollPos(hwnd
, SB_HORZ
);
4054 /* Assume default scroll range 0-100 */
4055 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4056 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4058 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4061 case EM_LINESCROLL16
:
4062 TRACE("EM_LINESCROLL16\n");
4067 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4073 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4074 /* check if we are going to move too far */
4075 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4076 dx
= es
->text_width
- fw
- es
->x_offset
;
4078 EDIT_EM_LineScroll_internal(hwnd
, es
, dx
, 0);
4084 /*********************************************************************
4089 static BOOL
EDIT_CheckCombo(HWND hwnd
, EDITSTATE
*es
, UINT msg
, INT key
)
4091 HWND hLBox
= es
->hwndListBox
;
4099 hCombo
= GetParent(hwnd
);
4103 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
4104 hwnd
, (UINT16
)msg
, (UINT16
)key
);
4106 if (key
== VK_UP
|| key
== VK_DOWN
)
4108 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
4111 if (msg
== WM_KEYDOWN
|| nEUI
)
4112 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
4118 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
4120 /* make sure ComboLBox pops up */
4121 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
4126 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
4129 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
4131 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
4133 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
4138 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
4144 /*********************************************************************
4148 * Handling of special keys that don't produce a WM_CHAR
4149 * (i.e. non-printable keys) & Backspace & Delete
4152 static LRESULT
EDIT_WM_KeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
)
4157 if (GetKeyState(VK_MENU
) & 0x8000)
4160 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
4161 control
= GetKeyState(VK_CONTROL
) & 0x8000;
4166 if (EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
4171 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
4172 EDIT_MoveUp_ML(hwnd
, es
, shift
);
4175 EDIT_MoveWordBackward(hwnd
, es
, shift
);
4177 EDIT_MoveBackward(hwnd
, es
, shift
);
4180 if (EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
))
4184 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
4185 EDIT_MoveDown_ML(hwnd
, es
, shift
);
4187 EDIT_MoveWordForward(hwnd
, es
, shift
);
4189 EDIT_MoveForward(hwnd
, es
, shift
);
4192 EDIT_MoveHome(hwnd
, es
, shift
);
4195 EDIT_MoveEnd(hwnd
, es
, shift
);
4198 if (es
->style
& ES_MULTILINE
)
4199 EDIT_MovePageUp_ML(hwnd
, es
, shift
);
4201 EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
);
4204 if (es
->style
& ES_MULTILINE
)
4205 EDIT_MovePageDown_ML(hwnd
, es
, shift
);
4207 EDIT_CheckCombo(hwnd
, es
, WM_KEYDOWN
, key
);
4210 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
4211 if (es
->selection_start
!= es
->selection_end
) {
4213 EDIT_WM_Cut(hwnd
, es
);
4215 EDIT_WM_Clear(hwnd
, es
);
4218 /* delete character left of caret */
4219 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
4220 EDIT_MoveBackward(hwnd
, es
, TRUE
);
4221 EDIT_WM_Clear(hwnd
, es
);
4222 } else if (control
) {
4223 /* delete to end of line */
4224 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
4225 EDIT_MoveEnd(hwnd
, es
, TRUE
);
4226 EDIT_WM_Clear(hwnd
, es
);
4228 /* delete character right of caret */
4229 EDIT_EM_SetSel(hwnd
, es
, (UINT
)-1, 0, FALSE
);
4230 EDIT_MoveForward(hwnd
, es
, TRUE
);
4231 EDIT_WM_Clear(hwnd
, es
);
4238 if (!(es
->style
& ES_READONLY
))
4239 EDIT_WM_Paste(hwnd
, es
);
4241 EDIT_WM_Copy(hwnd
, es
);
4244 /* If the edit doesn't want the return send a message to the default object */
4245 if(!(es
->style
& ES_WANTRETURN
))
4247 HWND hwndParent
= GetParent(hwnd
);
4248 DWORD dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
4249 if (HIWORD(dw
) == DC_HASDEFID
)
4251 SendMessageW( hwndParent
, WM_COMMAND
,
4252 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
4253 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
4262 /*********************************************************************
4267 static LRESULT
EDIT_WM_KillFocus(HWND hwnd
, EDITSTATE
*es
)
4269 es
->flags
&= ~EF_FOCUSED
;
4271 if(!(es
->style
& ES_NOHIDESEL
))
4272 EDIT_InvalidateText(hwnd
, es
, es
->selection_start
, es
->selection_end
);
4273 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_KILLFOCUS
, "EN_KILLFOCUS");
4278 /*********************************************************************
4282 * The caret position has been set on the WM_LBUTTONDOWN message
4285 static LRESULT
EDIT_WM_LButtonDblClk(HWND hwnd
, EDITSTATE
*es
)
4288 INT e
= es
->selection_end
;
4293 if (!(es
->flags
& EF_FOCUSED
))
4296 l
= EDIT_EM_LineFromChar(es
, e
);
4297 li
= EDIT_EM_LineIndex(es
, l
);
4298 ll
= EDIT_EM_LineLength(es
, e
);
4299 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
4300 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
4301 EDIT_EM_SetSel(hwnd
, es
, s
, e
, FALSE
);
4302 EDIT_EM_ScrollCaret(hwnd
, es
);
4307 /*********************************************************************
4312 static LRESULT
EDIT_WM_LButtonDown(HWND hwnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
4317 if (!(es
->flags
& EF_FOCUSED
))
4320 es
->bCaptureState
= TRUE
;
4322 EDIT_ConfinePoint(es
, &x
, &y
);
4323 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
, &after_wrap
);
4324 EDIT_EM_SetSel(hwnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
4325 EDIT_EM_ScrollCaret(hwnd
, es
);
4326 es
->region_posx
= es
->region_posy
= 0;
4327 SetTimer(hwnd
, 0, 100, NULL
);
4332 /*********************************************************************
4337 static LRESULT
EDIT_WM_LButtonUp(HWND hwndSelf
, EDITSTATE
*es
)
4339 if (es
->bCaptureState
&& GetCapture() == hwndSelf
) {
4340 KillTimer(hwndSelf
, 0);
4343 es
->bCaptureState
= FALSE
;
4348 /*********************************************************************
4353 static LRESULT
EDIT_WM_MButtonDown(HWND hwnd
)
4355 SendMessageW(hwnd
,WM_PASTE
,0,0);
4360 /*********************************************************************
4365 static LRESULT
EDIT_WM_MouseMove(HWND hwnd
, EDITSTATE
*es
, INT x
, INT y
)
4371 if (GetCapture() != hwnd
)
4375 * FIXME: gotta do some scrolling if outside client
4376 * area. Maybe reset the timer ?
4379 EDIT_ConfinePoint(es
, &x
, &y
);
4380 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
4381 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
4382 e
= EDIT_CharFromPos(hwnd
, es
, x
, y
, &after_wrap
);
4383 EDIT_EM_SetSel(hwnd
, es
, es
->selection_start
, e
, after_wrap
);
4388 /*********************************************************************
4392 * See also EDIT_WM_StyleChanged
4394 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, DWORD style
, HWND hwndParent
, BOOL unicode
)
4399 TRACE("Creating %s edit control, style = %08lx\n",
4400 unicode
? "Unicode" : "ANSI", style
);
4402 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4404 SetWindowLongA( hwnd
, 0, (LONG
)es
);
4407 * Note: since the EDITSTATE has not been fully initialized yet,
4408 * we can't use any API calls that may send
4409 * WM_XXX messages before WM_NCCREATE is completed.
4412 es
->is_unicode
= unicode
;
4415 es
->bEnableState
= !(style
& WS_DISABLED
);
4418 * In Win95 look and feel, the WS_BORDER style is replaced by the
4419 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4420 * control a non client area. Not always. This coordinates in some
4421 * way with the window creation code in dialog.c When making
4422 * modifications please ensure that the code still works for edit
4423 * controls created directly with style 0x50800000, exStyle 0 (
4424 * which should have a single pixel border)
4426 if (TWEAK_WineLook
!= WIN31_LOOK
)
4428 es
->style
&= ~WS_BORDER
;
4432 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
4433 SetWindowLongA( hwnd
, GWL_STYLE
,
4434 GetWindowLongA( hwnd
, GWL_STYLE
) & ~WS_BORDER
);
4437 /* Save parent, which will be notified by EN_* messages */
4438 es
->hwndParent
= hwndParent
;
4440 if (es
->style
& ES_COMBO
)
4441 es
->hwndListBox
= GetDlgItem(hwndParent
, ID_CB_LISTBOX
);
4443 /* Number overrides lowercase overrides uppercase (at least it
4444 * does in Win95). However I'll bet that ES_NUMBER would be
4445 * invalid under Win 3.1.
4447 if (es
->style
& ES_NUMBER
) {
4448 ; /* do not override the ES_NUMBER */
4449 } else if (es
->style
& ES_LOWERCASE
) {
4450 es
->style
&= ~ES_UPPERCASE
;
4452 if (es
->style
& ES_MULTILINE
) {
4453 es
->buffer_limit
= BUFLIMIT_MULTI
;
4454 if (es
->style
& WS_VSCROLL
)
4455 es
->style
|= ES_AUTOVSCROLL
;
4456 if (es
->style
& WS_HSCROLL
)
4457 es
->style
|= ES_AUTOHSCROLL
;
4458 es
->style
&= ~ES_PASSWORD
;
4459 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4460 /* Confirmed - RIGHT overrides CENTER */
4461 if (es
->style
& ES_RIGHT
)
4462 es
->style
&= ~ES_CENTER
;
4463 es
->style
&= ~WS_HSCROLL
;
4464 es
->style
&= ~ES_AUTOHSCROLL
;
4467 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4468 es
->style
|= ES_AUTOVSCROLL
;
4470 es
->buffer_limit
= BUFLIMIT_SINGLE
;
4471 if (WIN31_LOOK
== TWEAK_WineLook
||
4472 WIN95_LOOK
== TWEAK_WineLook
) {
4473 es
->style
&= ~ES_CENTER
;
4474 es
->style
&= ~ES_RIGHT
;
4476 if (es
->style
& ES_RIGHT
)
4477 es
->style
&= ~ES_CENTER
;
4479 es
->style
&= ~WS_HSCROLL
;
4480 es
->style
&= ~WS_VSCROLL
;
4481 es
->style
&= ~ES_AUTOVSCROLL
;
4482 es
->style
&= ~ES_WANTRETURN
;
4483 if (es
->style
& ES_PASSWORD
)
4484 es
->password_char
= '*';
4486 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4487 es
->style
|= ES_AUTOHSCROLL
;
4490 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4491 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4493 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4495 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4497 es
->undo_buffer_size
= es
->buffer_size
;
4499 if (es
->style
& ES_MULTILINE
)
4500 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4507 /*********************************************************************
4512 static void EDIT_WM_Paint(HWND hwnd
, EDITSTATE
*es
, WPARAM wParam
)
4521 BOOL rev
= es
->bEnableState
&&
4522 ((es
->flags
& EF_FOCUSED
) ||
4523 (es
->style
& ES_NOHIDESEL
));
4525 dc
= BeginPaint(hwnd
, &ps
);
4528 if(es
->style
& WS_BORDER
) {
4529 GetClientRect(hwnd
, &rc
);
4530 if(es
->style
& ES_MULTILINE
) {
4531 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
4532 if(es
->style
& WS_VSCROLL
) rc
.right
++;
4534 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4536 IntersectClipRect(dc
, es
->format_rect
.left
,
4537 es
->format_rect
.top
,
4538 es
->format_rect
.right
,
4539 es
->format_rect
.bottom
);
4540 if (es
->style
& ES_MULTILINE
) {
4541 GetClientRect(hwnd
, &rc
);
4542 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4545 old_font
= SelectObject(dc
, es
->font
);
4546 if ( get_app_version() >= 0x40000 &&(
4547 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
4548 EDIT_SEND_CTLCOLORSTATIC(hwnd
, dc
);
4550 EDIT_SEND_CTLCOLOR(hwnd
, dc
);
4552 if (!es
->bEnableState
)
4553 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
4554 GetClipBox(dc
, &rcRgn
);
4555 if (es
->style
& ES_MULTILINE
) {
4556 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4557 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
4558 EDIT_GetLineRect(hwnd
, es
, i
, 0, -1, &rcLine
);
4559 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4560 EDIT_PaintLine(hwnd
, es
, dc
, i
, rev
);
4563 EDIT_GetLineRect(hwnd
, es
, 0, 0, -1, &rcLine
);
4564 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
4565 EDIT_PaintLine(hwnd
, es
, dc
, 0, rev
);
4568 SelectObject(dc
, old_font
);
4571 EndPaint(hwnd
, &ps
);
4575 /*********************************************************************
4580 static void EDIT_WM_Paste(HWND hwnd
, EDITSTATE
*es
)
4585 /* Protect read-only edit control from modification */
4586 if(es
->style
& ES_READONLY
)
4589 OpenClipboard(hwnd
);
4590 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
4591 src
= (LPWSTR
)GlobalLock(hsrc
);
4592 EDIT_EM_ReplaceSel(hwnd
, es
, TRUE
, src
, TRUE
);
4599 /*********************************************************************
4604 static void EDIT_WM_SetFocus(HWND hwnd
, EDITSTATE
*es
)
4606 es
->flags
|= EF_FOCUSED
;
4607 CreateCaret(hwnd
, 0, 2, es
->line_height
);
4608 EDIT_SetCaretPos(hwnd
, es
, es
->selection_end
,
4609 es
->flags
& EF_AFTER_WRAP
);
4610 if(!(es
->style
& ES_NOHIDESEL
))
4611 EDIT_InvalidateText(hwnd
, es
, es
->selection_start
, es
->selection_end
);
4613 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_SETFOCUS
, "EN_SETFOCUS");
4617 /*********************************************************************
4621 * With Win95 look the margins are set to default font value unless
4622 * the system font (font == 0) is being set, in which case they are left
4626 static void EDIT_WM_SetFont(HWND hwnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
4636 old_font
= SelectObject(dc
, font
);
4637 GetTextMetricsW(dc
, &tm
);
4638 es
->line_height
= tm
.tmHeight
;
4639 es
->char_width
= tm
.tmAveCharWidth
;
4641 SelectObject(dc
, old_font
);
4642 ReleaseDC(hwnd
, dc
);
4643 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
4644 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
4645 EC_USEFONTINFO
, EC_USEFONTINFO
);
4647 /* Force the recalculation of the format rect for each font change */
4648 GetClientRect(hwnd
, &r
);
4649 EDIT_SetRectNP(hwnd
, es
, &r
);
4651 if (es
->style
& ES_MULTILINE
)
4652 EDIT_BuildLineDefs_ML(hwnd
, es
, 0, strlenW(es
->text
), 0, (HRGN
)0);
4654 EDIT_CalcLineWidth_SL(hwnd
, es
);
4657 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
4658 if (es
->flags
& EF_FOCUSED
) {
4660 CreateCaret(hwnd
, 0, 2, es
->line_height
);
4661 EDIT_SetCaretPos(hwnd
, es
, es
->selection_end
,
4662 es
->flags
& EF_AFTER_WRAP
);
4668 /*********************************************************************
4673 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4674 * The modified flag is reset. No notifications are sent.
4676 * For single-line controls, reception of WM_SETTEXT triggers:
4677 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4680 static void EDIT_WM_SetText(HWND hwnd
, EDITSTATE
*es
, LPARAM lParam
, BOOL unicode
)
4685 text
= (LPWSTR
)lParam
;
4688 LPCSTR textA
= (LPCSTR
)lParam
;
4689 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4690 if((text
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4691 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, text
, countW
);
4694 EDIT_EM_SetSel(hwnd
, es
, 0, (UINT
)-1, FALSE
);
4696 TRACE("%s\n", debugstr_w(text
));
4697 EDIT_EM_ReplaceSel(hwnd
, es
, FALSE
, text
, FALSE
);
4699 HeapFree(GetProcessHeap(), 0, text
);
4701 static const WCHAR empty_stringW
[] = {0};
4703 EDIT_EM_ReplaceSel(hwnd
, es
, FALSE
, empty_stringW
, FALSE
);
4706 es
->flags
&= ~EF_MODIFIED
;
4707 EDIT_EM_SetSel(hwnd
, es
, 0, 0, FALSE
);
4708 /* Send the notification after the selection start and end have been set
4709 * edit control doesn't send notification on WM_SETTEXT
4710 * if it is multiline, or it is part of combobox
4712 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4713 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_CHANGE
, "EN_CHANGE");
4714 EDIT_EM_ScrollCaret(hwnd
, es
);
4718 /*********************************************************************
4723 static void EDIT_WM_Size(HWND hwnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4725 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4727 TRACE("width = %d, height = %d\n", width
, height
);
4728 SetRect(&rc
, 0, 0, width
, height
);
4729 EDIT_SetRectNP(hwnd
, es
, &rc
);
4730 EDIT_UpdateText(hwnd
, es
, NULL
, TRUE
);
4735 /*********************************************************************
4739 * This message is sent by SetWindowLong on having changed either the Style
4740 * or the extended style.
4742 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4744 * See also EDIT_WM_NCCreate
4746 * It appears that the Windows version of the edit control allows the style
4747 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4748 * style variable which will generally be different. In this function we
4749 * update the internal style based on what changed in the externally visible
4752 * Much of this content as based upon the MSDN, especially:
4753 * Platform SDK Documentation -> User Interface Services ->
4754 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4755 * Edit Control Styles
4757 static LRESULT
EDIT_WM_StyleChanged (HWND hwnd
,
4760 const STYLESTRUCT
*style
)
4762 if (GWL_STYLE
== which
) {
4763 DWORD style_change_mask
;
4765 /* Only a subset of changes can be applied after the control
4768 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4770 if (es
->style
& ES_MULTILINE
)
4771 style_change_mask
|= ES_WANTRETURN
;
4773 new_style
= style
->styleNew
& style_change_mask
;
4775 /* Number overrides lowercase overrides uppercase (at least it
4776 * does in Win95). However I'll bet that ES_NUMBER would be
4777 * invalid under Win 3.1.
4779 if (new_style
& ES_NUMBER
) {
4780 ; /* do not override the ES_NUMBER */
4781 } else if (new_style
& ES_LOWERCASE
) {
4782 new_style
&= ~ES_UPPERCASE
;
4785 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4786 } else if (GWL_EXSTYLE
== which
) {
4787 ; /* FIXME - what is needed here */
4789 WARN ("Invalid style change %d\n",which
);
4795 /*********************************************************************
4800 static LRESULT
EDIT_WM_SysKeyDown(HWND hwnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4802 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4803 if (EDIT_EM_CanUndo(es
))
4804 EDIT_EM_Undo(hwnd
, es
);
4806 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4807 if (EDIT_CheckCombo(hwnd
, es
, WM_SYSKEYDOWN
, key
))
4810 return DefWindowProcW(hwnd
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4814 /*********************************************************************
4819 static void EDIT_WM_Timer(HWND hwnd
, EDITSTATE
*es
)
4821 if (es
->region_posx
< 0) {
4822 EDIT_MoveBackward(hwnd
, es
, TRUE
);
4823 } else if (es
->region_posx
> 0) {
4824 EDIT_MoveForward(hwnd
, es
, TRUE
);
4827 * FIXME: gotta do some vertical scrolling here, like
4828 * EDIT_EM_LineScroll(hwnd, 0, 1);
4832 /*********************************************************************
4837 static LRESULT
EDIT_WM_VScroll(HWND hwnd
, EDITSTATE
*es
, INT action
, INT pos
)
4841 if (!(es
->style
& ES_MULTILINE
))
4844 if (!(es
->style
& ES_AUTOVSCROLL
))
4853 TRACE("action %d\n", action
);
4854 EDIT_EM_Scroll(hwnd
, es
, action
);
4861 TRACE("SB_BOTTOM\n");
4862 dy
= es
->line_count
- 1 - es
->y_offset
;
4865 TRACE("SB_THUMBTRACK %d\n", pos
);
4866 es
->flags
|= EF_VSCROLL_TRACK
;
4867 if(es
->style
& WS_VSCROLL
)
4868 dy
= pos
- es
->y_offset
;
4871 /* Assume default scroll range 0-100 */
4874 if(pos
< 0 || pos
> 100) return 0;
4875 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4876 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4877 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4878 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4879 es
->line_count
, es
->y_offset
, pos
, dy
);
4882 case SB_THUMBPOSITION
:
4883 TRACE("SB_THUMBPOSITION %d\n", pos
);
4884 es
->flags
&= ~EF_VSCROLL_TRACK
;
4885 if(es
->style
& WS_VSCROLL
)
4886 dy
= pos
- es
->y_offset
;
4889 /* Assume default scroll range 0-100 */
4892 if(pos
< 0 || pos
> 100) return 0;
4893 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4894 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4895 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4896 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4897 es
->line_count
, es
->y_offset
, pos
, dy
);
4901 /* force scroll info update */
4902 EDIT_UpdateScrollInfo(hwnd
, es
);
4903 EDIT_NOTIFY_PARENT(hwnd
, es
, EN_VSCROLL
, "EN_VSCROLL");
4907 TRACE("SB_ENDSCROLL\n");
4910 * FIXME : the next two are undocumented !
4911 * Are we doing the right thing ?
4912 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4913 * although it's also a regular control message.
4915 case EM_GETTHUMB
: /* this one is used by NT notepad */
4919 if(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_VSCROLL
)
4920 ret
= GetScrollPos(hwnd
, SB_VERT
);
4923 /* Assume default scroll range 0-100 */
4924 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
4925 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4927 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4930 case EM_LINESCROLL16
:
4931 TRACE("EM_LINESCROLL16 %d\n", pos
);
4936 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4941 EDIT_EM_LineScroll(hwnd
, es
, 0, dy
);
4945 /*********************************************************************
4950 static void EDIT_UpdateTextRegion(HWND hwnd
, EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
4952 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(hwnd
, es
, EN_UPDATE
, "EN_UPDATE");
4953 InvalidateRgn(hwnd
, hrgn
, bErase
);
4957 /*********************************************************************
4962 static void EDIT_UpdateText(HWND hwnd
, EDITSTATE
*es
, LPRECT rc
, BOOL bErase
)
4964 if (es
->flags
& EF_UPDATE
) EDIT_NOTIFY_PARENT(hwnd
, es
, EN_UPDATE
, "EN_UPDATE");
4965 InvalidateRect(hwnd
, rc
, bErase
);