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)
21 #include "wine/winbase16.h"
24 #include "selectors.h"
25 #include "debugtools.h"
28 #include "winversion.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 BUFSTART_MULTI 1024 /* starting size */
38 #define BUFSTART_SINGLE 256 /* starting size */
39 #define GROWLENGTH 64 /* buffers grow by this much */
40 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
43 * extra flags for EDITSTATE.flags field
45 #define EF_MODIFIED 0x0001 /* text has been modified */
46 #define EF_FOCUSED 0x0002 /* we have input focus */
47 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
48 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
49 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
50 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
51 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
52 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
53 wrapped line, instead of in front of the next character */
54 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
58 END_0
= 0, /* line ends with terminating '\0' character */
59 END_WRAP
, /* line is wrapped */
60 END_HARD
, /* line ends with a hard return '\r\n' */
61 END_SOFT
/* line ends with a soft return '\r\r\n' */
64 typedef struct tagLINEDEF
{
65 INT length
; /* bruto length of a line in bytes */
66 INT net_length
; /* netto length of a line in visible characters */
68 INT width
; /* width of the line in pixels */
69 struct tagLINEDEF
*next
;
74 HANDLE heap
; /* our own heap */
75 LPSTR text
; /* the actual contents of the control */
76 INT buffer_size
; /* the size of the buffer */
77 INT buffer_limit
; /* the maximum size to which the buffer may grow */
78 HFONT font
; /* NULL means standard system font */
79 INT x_offset
; /* scroll offset for multi lines this is in pixels
80 for single lines it's in characters */
81 INT line_height
; /* height of a screen line in pixels */
82 INT char_width
; /* average character width in pixels */
83 DWORD style
; /* sane version of wnd->dwStyle */
84 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
85 INT undo_insert_count
; /* number of characters inserted in sequence */
86 INT undo_position
; /* character index of the insertion and deletion */
87 LPSTR undo_text
; /* deleted text */
88 INT undo_buffer_size
; /* size of the deleted text buffer */
89 INT selection_start
; /* == selection_end if no selection */
90 INT selection_end
; /* == current caret position */
91 CHAR password_char
; /* == 0 if no password char, and for multi line controls */
92 INT left_margin
; /* in pixels */
93 INT right_margin
; /* in pixels */
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 EDITWORDBREAKPROCA word_break_proc32A
;
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 */
104 * only for multi line controls
106 INT lock_count
; /* amount of re-entries in the EditWndProc */
109 INT text_width
; /* width of the widest line in pixels */
110 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
111 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
112 HLOCAL hloc32
; /* for controls receiving EM_GETHANDLE */
116 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
117 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
119 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
120 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
122 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
123 do {TRACE("notification " str " sent to hwnd=%08x\n", \
124 (UINT)(hwnd));} while(0)
126 /* used for disabled or read-only edit control */
127 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
128 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
129 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
130 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
131 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
132 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
133 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
134 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
135 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
136 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
137 (LPARAM)(wnd)->hwndSelf);} while(0)
138 #define DPRINTF_EDIT_MSG16(str) \
140 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
141 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
142 #define DPRINTF_EDIT_MSG32(str) \
144 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
145 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
147 /*********************************************************************
154 * These functions have trivial implementations
155 * We still like to call them internally
156 * "static inline" makes them more like macro's
158 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
159 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
160 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
161 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
164 * Helper functions only valid for one type of control
166 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
167 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
168 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
169 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
170 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
171 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
173 * Helper functions valid for both single line _and_ multi line controls
175 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
176 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
177 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
178 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
179 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
180 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
181 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
182 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
183 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
184 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
185 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
186 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
187 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
190 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
191 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
192 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
193 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
194 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
196 * EM_XXX message handlers
198 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
199 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
200 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
201 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
202 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
203 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
204 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
205 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
206 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
207 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
208 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
209 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
210 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
211 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
212 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
213 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
214 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
215 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
216 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
217 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
218 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
219 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
220 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
221 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
222 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
223 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
225 * WM_XXX message handlers
227 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
228 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
229 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
230 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
231 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
232 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
233 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
234 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
235 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
236 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
237 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
238 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
239 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
240 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
241 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
);
242 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
243 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
244 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
245 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
246 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
247 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
248 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
249 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
250 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
251 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
252 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
253 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
);
256 /*********************************************************************
261 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
263 return (es
->undo_insert_count
|| lstrlenA(es
->undo_text
));
267 /*********************************************************************
272 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
274 es
->undo_insert_count
= 0;
275 *es
->undo_text
= '\0';
279 /*********************************************************************
284 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
286 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
288 if (es
->flags
& EF_UPDATE
) {
289 es
->flags
&= ~EF_UPDATE
;
290 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
295 /*********************************************************************
300 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
302 EDIT_WM_Copy(wnd
, es
);
303 EDIT_WM_Clear(wnd
, es
);
307 /*********************************************************************
311 * The messages are in the order of the actual integer values
312 * (which can be found in include/windows.h)
313 * Whereever possible the 16 bit versions are converted to
314 * the 32 bit ones, so that we can 'fall through' to the
315 * helper functions. These are mostly 32 bit (with a few
316 * exceptions, clearly indicated by a '16' extension to their
320 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
321 WPARAM wParam
, LPARAM lParam
)
323 WND
*wnd
= WIN_FindWndPtr(hwnd
);
324 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
329 DPRINTF_EDIT_MSG32("WM_DESTROY");
330 EDIT_WM_Destroy(wnd
, es
);
335 DPRINTF_EDIT_MSG32("WM_NCCREATE");
336 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
342 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
347 EDIT_LockBuffer(wnd
, es
);
350 DPRINTF_EDIT_MSG16("EM_GETSEL");
355 DPRINTF_EDIT_MSG32("EM_GETSEL");
356 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
360 DPRINTF_EDIT_MSG16("EM_SETSEL");
361 if (SLOWORD(lParam
) == -1)
362 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
364 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
366 EDIT_EM_ScrollCaret(wnd
, es
);
370 DPRINTF_EDIT_MSG32("EM_SETSEL");
371 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
372 EDIT_EM_ScrollCaret(wnd
, es
);
377 DPRINTF_EDIT_MSG16("EM_GETRECT");
379 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
382 DPRINTF_EDIT_MSG32("EM_GETRECT");
384 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
388 DPRINTF_EDIT_MSG16("EM_SETRECT");
389 if ((es
->style
& ES_MULTILINE
) && lParam
) {
391 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
392 EDIT_SetRectNP(wnd
, es
, &rc
);
393 EDIT_UpdateText(wnd
, NULL
, TRUE
);
397 DPRINTF_EDIT_MSG32("EM_SETRECT");
398 if ((es
->style
& ES_MULTILINE
) && lParam
) {
399 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
400 EDIT_UpdateText(wnd
, NULL
, TRUE
);
405 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
406 if ((es
->style
& ES_MULTILINE
) && lParam
) {
408 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
409 EDIT_SetRectNP(wnd
, es
, &rc
);
413 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
414 if ((es
->style
& ES_MULTILINE
) && lParam
)
415 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
419 DPRINTF_EDIT_MSG16("EM_SCROLL");
422 DPRINTF_EDIT_MSG32("EM_SCROLL");
423 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
426 case EM_LINESCROLL16
:
427 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
428 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
429 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
432 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
433 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
436 case EM_SCROLLCARET16
:
437 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
440 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
441 EDIT_EM_ScrollCaret(wnd
, es
);
446 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
449 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
450 result
= ((es
->flags
& EF_MODIFIED
) != 0);
454 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
457 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
459 es
->flags
|= EF_MODIFIED
;
461 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
464 case EM_GETLINECOUNT16
:
465 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
467 case EM_GETLINECOUNT
:
468 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
469 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
473 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
474 if ((INT16
)wParam
== -1)
478 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
479 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
483 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
484 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
487 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
488 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
492 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
493 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
496 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
497 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
501 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
504 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
505 result
= EDIT_EM_GetThumb(wnd
, es
);
508 /* messages 0x00bf and 0x00c0 missing from specs */
511 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
514 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
515 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
519 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
522 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
523 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
526 case EM_LINELENGTH16
:
527 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
530 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
531 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
534 case EM_REPLACESEL16
:
535 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
536 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
539 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
540 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
541 if (es
->flags
& EF_UPDATE
) {
542 es
->flags
&= ~EF_UPDATE
;
543 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
548 /* message 0x00c3 missing from specs */
551 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
554 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
555 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
559 DPRINTF_EDIT_MSG16("EM_GETLINE");
560 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
563 DPRINTF_EDIT_MSG32("EM_GETLINE");
564 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
568 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
570 case EM_SETLIMITTEXT
:
571 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
572 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
576 DPRINTF_EDIT_MSG16("EM_CANUNDO");
579 DPRINTF_EDIT_MSG32("EM_CANUNDO");
580 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
584 DPRINTF_EDIT_MSG16("EM_UNDO");
589 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
590 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
594 DPRINTF_EDIT_MSG16("EM_FMTLINES");
597 DPRINTF_EDIT_MSG32("EM_FMTLINES");
598 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
601 case EM_LINEFROMCHAR16
:
602 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
604 case EM_LINEFROMCHAR
:
605 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
606 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
609 /* message 0x00ca missing from specs */
612 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
615 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
616 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
619 case EM_SETTABSTOPS16
:
620 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
621 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
624 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
625 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
628 case EM_SETPASSWORDCHAR16
:
629 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
631 case EM_SETPASSWORDCHAR
:
632 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
633 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
636 case EM_EMPTYUNDOBUFFER16
:
637 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
639 case EM_EMPTYUNDOBUFFER
:
640 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
641 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
644 case EM_GETFIRSTVISIBLELINE16
:
645 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
646 result
= es
->y_offset
;
648 case EM_GETFIRSTVISIBLELINE
:
649 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
650 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
653 case EM_SETREADONLY16
:
654 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
657 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
659 wnd
->dwStyle
|= ES_READONLY
;
660 es
->style
|= ES_READONLY
;
662 wnd
->dwStyle
&= ~ES_READONLY
;
663 es
->style
&= ~ES_READONLY
;
668 case EM_SETWORDBREAKPROC16
:
669 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
670 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
672 case EM_SETWORDBREAKPROC
:
673 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
674 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
677 case EM_GETWORDBREAKPROC16
:
678 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
679 result
= (LRESULT
)es
->word_break_proc16
;
681 case EM_GETWORDBREAKPROC
:
682 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
683 result
= (LRESULT
)es
->word_break_proc32A
;
686 case EM_GETPASSWORDCHAR16
:
687 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
689 case EM_GETPASSWORDCHAR
:
690 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
691 result
= es
->password_char
;
694 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
697 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
698 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
702 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
703 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
706 case EM_GETLIMITTEXT
:
707 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
708 result
= es
->buffer_limit
;
712 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
713 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
717 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
718 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
722 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
723 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
724 if (wnd
->dwStyle
& ES_WANTRETURN
)
726 LPMSG msg
= (LPMSG
)lParam
;
727 if (msg
&& (msg
->message
== WM_KEYDOWN
) && (msg
->wParam
== VK_RETURN
))
728 result
|= DLGC_WANTMESSAGE
;
733 DPRINTF_EDIT_MSG32("WM_CHAR");
734 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
738 DPRINTF_EDIT_MSG32("WM_CLEAR");
739 EDIT_WM_Clear(wnd
, es
);
743 DPRINTF_EDIT_MSG32("WM_COMMAND");
744 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
748 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
749 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
753 DPRINTF_EDIT_MSG32("WM_COPY");
754 EDIT_WM_Copy(wnd
, es
);
758 DPRINTF_EDIT_MSG32("WM_CREATE");
759 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
763 DPRINTF_EDIT_MSG32("WM_CUT");
764 EDIT_WM_Cut(wnd
, es
);
768 DPRINTF_EDIT_MSG32("WM_ENABLE");
769 es
->bEnableState
= (BOOL
) wParam
;
770 EDIT_UpdateText(wnd
, NULL
, TRUE
);
774 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
775 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
779 DPRINTF_EDIT_MSG32("WM_GETFONT");
780 result
= (LRESULT
)es
->font
;
784 DPRINTF_EDIT_MSG32("WM_GETTEXT");
785 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
788 case WM_GETTEXTLENGTH
:
789 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
790 result
= lstrlenA(es
->text
);
794 DPRINTF_EDIT_MSG32("WM_HSCROLL");
795 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
799 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
800 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
804 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
805 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
808 case WM_LBUTTONDBLCLK
:
809 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
810 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
814 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
815 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
819 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
820 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
824 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
825 result
= EDIT_WM_MButtonDown(wnd
);
828 case WM_MOUSEACTIVATE
:
830 * FIXME: maybe DefWindowProc() screws up, but it seems that
831 * modeless dialog boxes need this. If we don't do this, the focus
832 * will _not_ be set by DefWindowProc() for edit controls in a
833 * modeless dialog box ???
835 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
836 SetFocus(wnd
->hwndSelf
);
837 result
= MA_ACTIVATE
;
842 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
844 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
848 DPRINTF_EDIT_MSG32("WM_PAINT");
849 EDIT_WM_Paint(wnd
, es
, wParam
);
853 DPRINTF_EDIT_MSG32("WM_PASTE");
854 EDIT_WM_Paste(wnd
, es
);
858 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
859 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
863 DPRINTF_EDIT_MSG32("WM_SETFONT");
864 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
868 DPRINTF_EDIT_MSG32("WM_SETTEXT");
869 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
874 DPRINTF_EDIT_MSG32("WM_SIZE");
875 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
879 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
880 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
884 DPRINTF_EDIT_MSG32("WM_TIMER");
885 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
889 DPRINTF_EDIT_MSG32("WM_VSCROLL");
890 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
895 short gcWheelDelta
= 0;
896 UINT pulScrollLines
= 3;
897 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
899 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
900 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
903 gcWheelDelta
-= (short) HIWORD(wParam
);
904 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
906 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
907 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
908 result
= EDIT_EM_LineScroll(wnd
, es
, 0, cLineScroll
);
913 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
916 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
918 WIN_ReleaseWndPtr(wnd
);
924 /*********************************************************************
926 * EDIT_BuildLineDefs_ML
928 * Build linked list of text lines.
929 * Lines can end with '\0' (last line), a character (if it is wrapped),
930 * a soft return '\r\r\n' or a hard return '\r\n'
933 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
939 LINEDEF
*current_def
;
940 LINEDEF
**previous_next
;
942 current_def
= es
->first_line_def
;
944 LINEDEF
*next_def
= current_def
->next
;
945 HeapFree(es
->heap
, 0, current_def
);
946 current_def
= next_def
;
947 } while (current_def
);
951 dc
= GetDC(wnd
->hwndSelf
);
953 old_font
= SelectObject(dc
, es
->font
);
955 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
957 previous_next
= &es
->first_line_def
;
959 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
960 current_def
->next
= NULL
;
963 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
968 current_def
->ending
= END_0
;
969 current_def
->net_length
= lstrlenA(start
);
970 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
971 current_def
->ending
= END_SOFT
;
972 current_def
->net_length
= cp
- start
- 1;
974 current_def
->ending
= END_HARD
;
975 current_def
->net_length
= cp
- start
;
977 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
978 start
, current_def
->net_length
,
979 es
->tabs_count
, es
->tabs
));
980 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
981 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
986 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
987 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
988 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
989 start
, next
, es
->tabs_count
, es
->tabs
));
990 } while (current_def
->width
<= fw
);
996 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
997 start
, next
, es
->tabs_count
, es
->tabs
));
998 } while (current_def
->width
<= fw
);
1002 current_def
->net_length
= prev
;
1003 current_def
->ending
= END_WRAP
;
1004 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
1005 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
1007 switch (current_def
->ending
) {
1009 current_def
->length
= current_def
->net_length
+ 3;
1012 current_def
->length
= current_def
->net_length
+ 2;
1016 current_def
->length
= current_def
->net_length
;
1019 es
->text_width
= max(es
->text_width
, current_def
->width
);
1020 start
+= current_def
->length
;
1021 *previous_next
= current_def
;
1022 previous_next
= ¤t_def
->next
;
1024 } while (current_def
->ending
!= END_0
);
1026 SelectObject(dc
, old_font
);
1027 ReleaseDC(wnd
->hwndSelf
, dc
);
1031 /*********************************************************************
1033 * EDIT_CallWordBreakProc
1035 * Call appropriate WordBreakProc (internal or external).
1037 * Note: The "start" argument should always be an index refering
1038 * to es->text. The actual wordbreak proc might be
1039 * 16 bit, so we can't always pass any 32 bit LPSTR.
1040 * Hence we assume that es->text is the buffer that holds
1041 * the string under examination (we can decide this for ourselves).
1044 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1046 if (es
->word_break_proc16
) {
1047 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1048 SEGPTR segptr
= LocalLock16(hloc16
);
1049 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1050 segptr
+ start
, index
, count
, action
);
1051 LocalUnlock16(hloc16
);
1054 else if (es
->word_break_proc32A
)
1056 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1057 es
->word_break_proc32A
, es
->text
+ start
, index
,
1059 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1063 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1067 /*********************************************************************
1071 * Beware: This is not the function called on EM_CHARFROMPOS
1072 * The position _can_ be outside the formatting / client
1074 * The return value is only the character index
1077 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1083 if (es
->style
& ES_MULTILINE
) {
1084 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1086 LINEDEF
*line_def
= es
->first_line_def
;
1088 while ((line
> 0) && line_def
->next
) {
1089 line_index
+= line_def
->length
;
1090 line_def
= line_def
->next
;
1093 x
+= es
->x_offset
- es
->format_rect
.left
;
1094 if (x
>= line_def
->width
) {
1096 *after_wrap
= (line_def
->ending
== END_WRAP
);
1097 return line_index
+ line_def
->net_length
;
1101 *after_wrap
= FALSE
;
1104 dc
= GetDC(wnd
->hwndSelf
);
1106 old_font
= SelectObject(dc
, es
->font
);
1107 low
= line_index
+ 1;
1108 high
= line_index
+ line_def
->net_length
+ 1;
1109 while (low
< high
- 1)
1111 INT mid
= (low
+ high
) / 2;
1112 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1118 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1119 (line_def
->ending
== END_WRAP
));
1124 *after_wrap
= FALSE
;
1125 x
-= es
->format_rect
.left
;
1127 return es
->x_offset
;
1128 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1129 dc
= GetDC(wnd
->hwndSelf
);
1131 old_font
= SelectObject(dc
, es
->font
);
1135 INT high
= es
->x_offset
;
1136 while (low
< high
- 1)
1138 INT mid
= (low
+ high
) / 2;
1139 GetTextExtentPoint32A( dc
, text
+ mid
,
1140 es
->x_offset
- mid
, &size
);
1141 if (size
.cx
> -x
) low
= mid
;
1148 INT low
= es
->x_offset
;
1149 INT high
= lstrlenA(es
->text
) + 1;
1150 while (low
< high
- 1)
1152 INT mid
= (low
+ high
) / 2;
1153 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1154 mid
- es
->x_offset
, &size
);
1155 if (size
.cx
> x
) high
= mid
;
1160 if (es
->style
& ES_PASSWORD
)
1161 HeapFree(es
->heap
, 0 ,text
);
1164 SelectObject(dc
, old_font
);
1165 ReleaseDC(wnd
->hwndSelf
, dc
);
1170 /*********************************************************************
1174 * adjusts the point to be within the formatting rectangle
1175 * (so CharFromPos returns the nearest _visible_ character)
1178 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1180 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1181 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1185 /*********************************************************************
1189 * Calculates the bounding rectangle for a line from a starting
1190 * column to an ending column.
1193 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1195 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1197 if (es
->style
& ES_MULTILINE
)
1198 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1200 rc
->top
= es
->format_rect
.top
;
1201 rc
->bottom
= rc
->top
+ es
->line_height
;
1202 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1203 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1207 /*********************************************************************
1209 * EDIT_GetPasswordPointer_SL
1211 * note: caller should free the (optionally) allocated buffer
1214 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1216 if (es
->style
& ES_PASSWORD
) {
1217 INT len
= lstrlenA(es
->text
);
1218 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1219 RtlFillMemory(text
, len
, es
->password_char
);
1227 /*********************************************************************
1231 * This acts as a LOCAL_Lock(), but it locks only once. This way
1232 * you can call it whenever you like, without unlocking.
1235 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1238 ERR("no EDITSTATE ... please report\n");
1241 if (!(es
->style
& ES_MULTILINE
))
1245 es
->text
= LocalLock(es
->hloc32
);
1246 else if (es
->hloc16
)
1247 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1249 ERR("no buffer ... please report\n");
1257 /*********************************************************************
1259 * EDIT_SL_InvalidateText
1261 * Called from EDIT_InvalidateText().
1262 * Does the job for single-line controls only.
1265 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1270 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1271 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1272 EDIT_UpdateText(wnd
, &rc
, FALSE
);
1276 /*********************************************************************
1278 * EDIT_ML_InvalidateText
1280 * Called from EDIT_InvalidateText().
1281 * Does the job for multi-line controls only.
1284 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1286 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1287 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1288 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1297 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1300 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1301 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1302 if (sl
< es
->y_offset
) {
1306 if (el
> es
->y_offset
+ vlc
) {
1307 el
= es
->y_offset
+ vlc
;
1308 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1310 GetClientRect(wnd
->hwndSelf
, &rc1
);
1311 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1313 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1314 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1315 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1317 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1318 EDIT_EM_LineLength(wnd
, es
,
1319 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1321 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1322 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1323 for (l
= sl
+ 1 ; l
< el
; l
++) {
1324 EDIT_GetLineRect(wnd
, es
, l
, 0,
1325 EDIT_EM_LineLength(wnd
, es
,
1326 EDIT_EM_LineIndex(wnd
, es
, l
)),
1328 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1329 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1331 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1332 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1333 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1338 /*********************************************************************
1340 * EDIT_InvalidateText
1342 * Invalidate the text from offset start upto, but not including,
1343 * offset end. Useful for (re)painting the selection.
1344 * Regions outside the linewidth are not invalidated.
1345 * end == -1 means end == TextLength.
1346 * start and end need not be ordered.
1349 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1355 end
= lstrlenA(es
->text
);
1357 ORDER_INT(start
, end
);
1359 if (es
->style
& ES_MULTILINE
)
1360 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1362 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1366 /*********************************************************************
1370 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1373 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1378 if (size
<= es
->buffer_size
)
1380 if (size
> es
->buffer_limit
) {
1381 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1384 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1385 if (size
> es
->buffer_limit
)
1386 size
= es
->buffer_limit
;
1388 TRACE("trying to ReAlloc to %d+1\n", size
);
1390 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1392 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1393 es
->buffer_size
= min(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1395 es
->buffer_size
= 0;
1396 } else if (es
->hloc32
) {
1397 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1398 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1399 es
->hloc32
= hNew32
;
1400 es
->buffer_size
= min(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1402 } else if (es
->hloc16
) {
1403 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1404 TRACE("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1405 es
->hloc16
= hNew16
;
1406 es
->buffer_size
= min(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1409 if (es
->buffer_size
< size
) {
1410 EDIT_LockBuffer(wnd
, es
);
1411 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1412 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1415 EDIT_LockBuffer(wnd
, es
);
1416 TRACE("We now have %d+1\n", es
->buffer_size
);
1422 /*********************************************************************
1426 * Try to fit size + 1 bytes in the undo buffer.
1429 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1431 if (size
<= es
->undo_buffer_size
)
1433 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1435 TRACE("trying to ReAlloc to %d+1\n", size
);
1437 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1438 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1439 if (es
->undo_buffer_size
< size
) {
1440 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1449 /*********************************************************************
1454 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1456 INT e
= es
->selection_end
;
1460 if ((es
->style
& ES_MULTILINE
) && e
&&
1461 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1463 if (e
&& (es
->text
[e
- 1] == '\r'))
1467 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1468 EDIT_EM_ScrollCaret(wnd
, es
);
1472 /*********************************************************************
1476 * Only for multi line controls
1477 * Move the caret one line down, on a column with the nearest
1478 * x coordinate on the screen (might be a different column).
1481 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1483 INT s
= es
->selection_start
;
1484 INT e
= es
->selection_end
;
1485 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1486 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1487 INT x
= SLOWORD(pos
);
1488 INT y
= SHIWORD(pos
);
1490 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1493 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1494 EDIT_EM_ScrollCaret(wnd
, es
);
1498 /*********************************************************************
1503 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1505 BOOL after_wrap
= FALSE
;
1508 /* Pass a high value in x to make sure of receiving the en of the line */
1509 if (es
->style
& ES_MULTILINE
)
1510 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1511 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1513 e
= lstrlenA(es
->text
);
1514 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1515 EDIT_EM_ScrollCaret(wnd
, es
);
1519 /*********************************************************************
1524 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1526 INT e
= es
->selection_end
;
1530 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1531 if (es
->text
[e
] == '\n')
1533 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1537 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1538 EDIT_EM_ScrollCaret(wnd
, es
);
1542 /*********************************************************************
1546 * Home key: move to beginning of line.
1549 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1553 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1554 if (es
->style
& ES_MULTILINE
)
1555 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1556 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1559 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1560 EDIT_EM_ScrollCaret(wnd
, es
);
1564 /*********************************************************************
1566 * EDIT_MovePageDown_ML
1568 * Only for multi line controls
1569 * Move the caret one page down, on a column with the nearest
1570 * x coordinate on the screen (might be a different column).
1573 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1575 INT s
= es
->selection_start
;
1576 INT e
= es
->selection_end
;
1577 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1578 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1579 INT x
= SLOWORD(pos
);
1580 INT y
= SHIWORD(pos
);
1582 e
= EDIT_CharFromPos(wnd
, es
, x
,
1583 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1587 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1588 EDIT_EM_ScrollCaret(wnd
, es
);
1592 /*********************************************************************
1594 * EDIT_MovePageUp_ML
1596 * Only for multi line controls
1597 * Move the caret one page up, on a column with the nearest
1598 * x coordinate on the screen (might be a different column).
1601 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1603 INT s
= es
->selection_start
;
1604 INT e
= es
->selection_end
;
1605 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1606 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1607 INT x
= SLOWORD(pos
);
1608 INT y
= SHIWORD(pos
);
1610 e
= EDIT_CharFromPos(wnd
, es
, x
,
1611 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1615 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1616 EDIT_EM_ScrollCaret(wnd
, es
);
1620 /*********************************************************************
1624 * Only for multi line controls
1625 * Move the caret one line up, on a column with the nearest
1626 * x coordinate on the screen (might be a different column).
1629 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1631 INT s
= es
->selection_start
;
1632 INT e
= es
->selection_end
;
1633 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1634 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1635 INT x
= SLOWORD(pos
);
1636 INT y
= SHIWORD(pos
);
1638 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1641 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1642 EDIT_EM_ScrollCaret(wnd
, es
);
1646 /*********************************************************************
1648 * EDIT_MoveWordBackward
1651 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1653 INT s
= es
->selection_start
;
1654 INT e
= es
->selection_end
;
1659 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1660 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1661 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1664 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1665 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1668 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1669 li
, e
- li
, ll
, WB_LEFT
);
1673 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1674 EDIT_EM_ScrollCaret(wnd
, es
);
1678 /*********************************************************************
1680 * EDIT_MoveWordForward
1683 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1685 INT s
= es
->selection_start
;
1686 INT e
= es
->selection_end
;
1691 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1692 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1693 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1695 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1696 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1698 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1699 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1703 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1704 EDIT_EM_ScrollCaret(wnd
, es
);
1708 /*********************************************************************
1713 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1715 INT s
= es
->selection_start
;
1716 INT e
= es
->selection_end
;
1723 if (es
->style
& ES_MULTILINE
) {
1724 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1725 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1730 TRACE("line=%d\n", line
);
1732 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1735 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1736 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1737 s
= es
->selection_start
;
1738 e
= es
->selection_end
;
1740 s
= min(li
+ ll
, max(li
, s
));
1741 e
= min(li
+ ll
, max(li
, e
));
1742 if (rev
&& (s
!= e
) &&
1743 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1744 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1745 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1746 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1748 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1752 /*********************************************************************
1757 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1767 BkColor
= GetBkColor(dc
);
1768 TextColor
= GetTextColor(dc
);
1770 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1771 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1773 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1774 if (es
->style
& ES_MULTILINE
) {
1775 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1776 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1778 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1779 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1780 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1782 if (es
->style
& ES_PASSWORD
)
1783 HeapFree(es
->heap
, 0, text
);
1786 SetBkColor(dc
, BkColor
);
1787 SetTextColor(dc
, TextColor
);
1793 /*********************************************************************
1798 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1801 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1802 INT x
= SLOWORD(res
);
1803 INT y
= SHIWORD(res
);
1805 if(x
< es
->format_rect
.left
)
1806 x
= es
->format_rect
.left
;
1807 if(x
> es
->format_rect
.right
- 2)
1808 x
= es
->format_rect
.right
- 2;
1809 if(y
> es
->format_rect
.bottom
)
1810 y
= es
->format_rect
.bottom
;
1811 if(y
< es
->format_rect
.top
)
1812 y
= es
->format_rect
.top
;
1818 /*********************************************************************
1822 * note: this is not (exactly) the handler called on EM_SETRECTNP
1823 * it is also used to set the rect of a single line control
1826 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1828 CopyRect(&es
->format_rect
, rc
);
1829 if (es
->style
& WS_BORDER
) {
1830 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1831 if(TWEAK_WineLook
== WIN31_LOOK
)
1833 es
->format_rect
.left
+= bw
;
1834 es
->format_rect
.top
+= bw
;
1835 es
->format_rect
.right
-= bw
;
1836 es
->format_rect
.bottom
-= bw
;
1838 es
->format_rect
.left
+= es
->left_margin
;
1839 es
->format_rect
.right
-= es
->right_margin
;
1840 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1841 if (es
->style
& ES_MULTILINE
)
1842 es
->format_rect
.bottom
= es
->format_rect
.top
+
1843 max(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1845 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1846 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1847 EDIT_BuildLineDefs_ML(wnd
, es
);
1851 /*********************************************************************
1856 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1859 ERR("no EDITSTATE ... please report\n");
1862 if (!(es
->style
& ES_MULTILINE
))
1864 if (!es
->lock_count
) {
1865 ERR("lock_count == 0 ... please report\n");
1869 ERR("es->text == 0 ... please report\n");
1872 if (force
|| (es
->lock_count
== 1)) {
1874 LocalUnlock(es
->hloc32
);
1876 } else if (es
->hloc16
) {
1877 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1885 /*********************************************************************
1887 * EDIT_WordBreakProc
1889 * Find the beginning of words.
1890 * Note: unlike the specs for a WordBreakProc, this function only
1891 * allows to be called without linebreaks between s[0] upto
1892 * s[count - 1]. Remember it is only called
1893 * internally, so we can decide this for ourselves.
1896 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1900 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1901 s
, index
, count
, action
);
1909 if (s
[index
] == ' ') {
1910 while (index
&& (s
[index
] == ' '))
1913 while (index
&& (s
[index
] != ' '))
1915 if (s
[index
] == ' ')
1919 while (index
&& (s
[index
] != ' '))
1921 if (s
[index
] == ' ')
1931 if (s
[index
] == ' ')
1932 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1934 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1936 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1940 case WB_ISDELIMITER
:
1941 ret
= (s
[index
] == ' ');
1944 ERR("unknown action code, please report !\n");
1951 /*********************************************************************
1955 * returns line number (not index) in high-order word of result.
1956 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1957 * to Richedit, not to the edit control. Original documentation is valid.
1958 * FIXME: do the specs mean to return -1 if outside client area or
1959 * if outside formatting rectangle ???
1962 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1970 GetClientRect(wnd
->hwndSelf
, &rc
);
1971 if (!PtInRect(&rc
, pt
))
1974 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1975 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1979 /*********************************************************************
1983 * Enable or disable soft breaks.
1985 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1987 es
->flags
&= ~EF_USE_SOFTBRK
;
1989 es
->flags
|= EF_USE_SOFTBRK
;
1990 FIXME("soft break enabled, not implemented\n");
1996 /*********************************************************************
2000 * Hopefully this won't fire back at us.
2001 * We always start with a fixed buffer in our own heap.
2002 * However, with this message a 32 bit application requests
2003 * a handle to 32 bit moveable local heap memory, where it expects
2005 * It's a pity that from this moment on we have to use this
2006 * local heap, because applications may rely on the handle
2009 * In this function we'll try to switch to local heap.
2012 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
2018 if (!(es
->style
& ES_MULTILINE
))
2023 else if (es
->hloc16
)
2024 return (HLOCAL
)es
->hloc16
;
2026 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2027 ERR("could not allocate new 32 bit buffer\n");
2030 newSize
= min(LocalSize(newBuf
) - 1, es
->buffer_limit
);
2031 if (!(newText
= LocalLock(newBuf
))) {
2032 ERR("could not lock new 32 bit buffer\n");
2036 lstrcpyA(newText
, es
->text
);
2037 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2039 HeapFree(es
->heap
, 0, es
->text
);
2040 es
->hloc32
= newBuf
;
2041 es
->hloc16
= (HLOCAL16
)NULL
;
2042 es
->buffer_size
= newSize
;
2044 EDIT_LockBuffer(wnd
, es
);
2045 TRACE("switched to 32 bit local heap\n");
2051 /*********************************************************************
2055 * Hopefully this won't fire back at us.
2056 * We always start with a buffer in 32 bit linear memory.
2057 * However, with this message a 16 bit application requests
2058 * a handle of 16 bit local heap memory, where it expects to find
2060 * It's a pitty that from this moment on we have to use this
2061 * local heap, because applications may rely on the handle
2064 * In this function we'll try to switch to local heap.
2066 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2072 if (!(es
->style
& ES_MULTILINE
))
2078 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2079 if (!LocalInit16(wnd
->hInstance
, 0,
2080 GlobalSize16(wnd
->hInstance
))) {
2081 ERR("could not initialize local heap\n");
2084 TRACE("local heap initialized\n");
2086 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2087 ERR("could not allocate new 16 bit buffer\n");
2090 newSize
= min(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2091 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2092 ERR("could not lock new 16 bit buffer\n");
2093 LOCAL_Free(wnd
->hInstance
, newBuf
);
2096 lstrcpyA(newText
, es
->text
);
2097 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2099 HeapFree(es
->heap
, 0, es
->text
);
2100 else if (es
->hloc32
) {
2101 while (LocalFree(es
->hloc32
)) ;
2102 LocalFree(es
->hloc32
);
2104 es
->hloc32
= (HLOCAL
)NULL
;
2105 es
->hloc16
= newBuf
;
2106 es
->buffer_size
= newSize
;
2108 EDIT_LockBuffer(wnd
, es
);
2109 TRACE("switched to 16 bit buffer\n");
2115 /*********************************************************************
2120 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2126 if (es
->style
& ES_MULTILINE
) {
2127 if (line
>= es
->line_count
)
2131 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2133 len
= min(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2134 for (i
= 0 ; i
< len
; i
++) {
2139 return (LRESULT
)len
;
2143 /*********************************************************************
2148 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2150 UINT s
= es
->selection_start
;
2151 UINT e
= es
->selection_end
;
2158 return MAKELONG(s
, e
);
2162 /*********************************************************************
2166 * FIXME: is this right ? (or should it be only VSCROLL)
2167 * (and maybe only for edit controls that really have their
2168 * own scrollbars) (and maybe only for multiline controls ?)
2169 * All in all: very poorly documented
2171 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2172 * WM_VSCROLL handlers
2175 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2177 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2178 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2182 /*********************************************************************
2187 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2192 if (!(es
->style
& ES_MULTILINE
))
2194 if (index
> lstrlenA(es
->text
))
2195 return es
->line_count
- 1;
2197 index
= min(es
->selection_start
, es
->selection_end
);
2200 line_def
= es
->first_line_def
;
2201 index
-= line_def
->length
;
2202 while ((index
>= 0) && line_def
->next
) {
2204 line_def
= line_def
->next
;
2205 index
-= line_def
->length
;
2211 /*********************************************************************
2216 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2221 if (!(es
->style
& ES_MULTILINE
))
2223 if (line
>= es
->line_count
)
2227 line_def
= es
->first_line_def
;
2229 INT index
= es
->selection_end
- line_def
->length
;
2230 while ((index
>= 0) && line_def
->next
) {
2231 line_index
+= line_def
->length
;
2232 line_def
= line_def
->next
;
2233 index
-= line_def
->length
;
2237 line_index
+= line_def
->length
;
2238 line_def
= line_def
->next
;
2246 /*********************************************************************
2251 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2255 if (!(es
->style
& ES_MULTILINE
))
2256 return lstrlenA(es
->text
);
2259 /* get the number of remaining non-selected chars of selected lines */
2262 li
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_start
);
2263 /* # chars before start of selection area */
2264 count
= es
->selection_start
- EDIT_EM_LineIndex(wnd
, es
, li
);
2265 li
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2266 /* # chars after end of selection */
2267 count
+= EDIT_EM_LineIndex(wnd
, es
, li
) +
2268 EDIT_EM_LineLength(wnd
, es
, li
) - es
->selection_end
;
2271 line_def
= es
->first_line_def
;
2272 index
-= line_def
->length
;
2273 while ((index
>= 0) && line_def
->next
) {
2274 line_def
= line_def
->next
;
2275 index
-= line_def
->length
;
2277 return line_def
->net_length
;
2281 /*********************************************************************
2285 * FIXME: dx is in average character widths
2286 * However, we assume it is in pixels when we use this
2287 * function internally
2290 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2294 if (!(es
->style
& ES_MULTILINE
))
2297 if (-dx
> es
->x_offset
)
2299 if (dx
> es
->text_width
- es
->x_offset
)
2300 dx
= es
->text_width
- es
->x_offset
;
2301 nyoff
= max(0, es
->y_offset
+ dy
);
2302 if (nyoff
>= es
->line_count
)
2303 nyoff
= es
->line_count
- 1;
2304 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2308 GetClientRect(wnd
->hwndSelf
, &rc1
);
2309 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2310 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2311 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2312 es
->y_offset
= nyoff
;
2315 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2316 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2317 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2318 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2323 /*********************************************************************
2328 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2330 INT len
= lstrlenA(es
->text
);
2339 index
= min(index
, len
);
2340 dc
= GetDC(wnd
->hwndSelf
);
2342 old_font
= SelectObject(dc
, es
->font
);
2343 if (es
->style
& ES_MULTILINE
) {
2344 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2345 y
= (l
- es
->y_offset
) * es
->line_height
;
2346 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2347 if (after_wrap
&& (li
== index
) && l
) {
2349 LINEDEF
*line_def
= es
->first_line_def
;
2351 line_def
= line_def
->next
;
2354 if (line_def
->ending
== END_WRAP
) {
2356 y
-= es
->line_height
;
2357 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2360 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2361 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2363 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2364 if (index
< es
->x_offset
) {
2365 GetTextExtentPoint32A(dc
, text
+ index
,
2366 es
->x_offset
- index
, &size
);
2369 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2370 index
- es
->x_offset
, &size
);
2374 if (es
->style
& ES_PASSWORD
)
2375 HeapFree(es
->heap
, 0 ,text
);
2377 x
+= es
->format_rect
.left
;
2378 y
+= es
->format_rect
.top
;
2380 SelectObject(dc
, old_font
);
2381 ReleaseDC(wnd
->hwndSelf
, dc
);
2382 return MAKELONG((INT16
)x
, (INT16
)y
);
2386 /*********************************************************************
2390 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2393 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2395 INT strl
= lstrlenA(lpsz_replace
);
2396 INT tl
= lstrlenA(es
->text
);
2403 s
= es
->selection_start
;
2404 e
= es
->selection_end
;
2406 if ((s
== e
) && !strl
)
2411 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2415 /* there is something to be deleted */
2417 utl
= lstrlenA(es
->undo_text
);
2418 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2419 /* undo-buffer is extended to the right */
2420 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2421 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2422 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2423 /* undo-buffer is extended to the left */
2424 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2425 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2427 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2428 p
[i
] = (es
->text
+ s
)[i
];
2429 es
->undo_position
= s
;
2431 /* new undo-buffer */
2432 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2433 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2434 es
->undo_position
= s
;
2436 /* any deletion makes the old insertion-undo invalid */
2437 es
->undo_insert_count
= 0;
2439 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2442 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2445 /* there is an insertion */
2447 if ((s
== es
->undo_position
) ||
2448 ((es
->undo_insert_count
) &&
2449 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2451 * insertion is new and at delete position or
2452 * an extension to either left or right
2454 es
->undo_insert_count
+= strl
;
2456 /* new insertion undo */
2457 es
->undo_position
= s
;
2458 es
->undo_insert_count
= strl
;
2459 /* new insertion makes old delete-buffer invalid */
2460 *es
->undo_text
= '\0';
2463 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2466 tl
= lstrlenA(es
->text
);
2467 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2469 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2470 p
[i
] = lpsz_replace
[i
];
2471 if(es
->style
& ES_UPPERCASE
)
2472 CharUpperBuffA(p
, strl
);
2473 else if(es
->style
& ES_LOWERCASE
)
2474 CharLowerBuffA(p
, strl
);
2477 /* FIXME: really inefficient */
2478 if (es
->style
& ES_MULTILINE
)
2479 EDIT_BuildLineDefs_ML(wnd
, es
);
2481 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2482 es
->flags
|= EF_MODIFIED
;
2483 es
->flags
|= EF_UPDATE
;
2484 EDIT_EM_ScrollCaret(wnd
, es
);
2486 /* FIXME: really inefficient */
2487 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2491 /*********************************************************************
2496 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2500 if (!(es
->style
& ES_MULTILINE
))
2501 return (LRESULT
)FALSE
;
2511 if (es
->y_offset
< es
->line_count
- 1)
2516 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2519 if (es
->y_offset
< es
->line_count
- 1)
2520 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2523 return (LRESULT
)FALSE
;
2526 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2527 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2529 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2533 /*********************************************************************
2538 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2540 if (es
->style
& ES_MULTILINE
) {
2545 INT cw
= es
->char_width
;
2550 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2551 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2552 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2553 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2554 if (l
>= es
->y_offset
+ vlc
)
2555 dy
= l
- vlc
+ 1 - es
->y_offset
;
2556 if (l
< es
->y_offset
)
2557 dy
= l
- es
->y_offset
;
2558 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2559 if (x
< es
->format_rect
.left
)
2560 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2561 if (x
> es
->format_rect
.right
)
2562 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2564 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2570 if (!(es
->style
& ES_AUTOHSCROLL
))
2573 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2574 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2575 if (x
< es
->format_rect
.left
) {
2576 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2579 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2580 } while ((x
< goal
) && es
->x_offset
);
2581 /* FIXME: use ScrollWindow() somehow to improve performance */
2582 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2583 } else if (x
> es
->format_rect
.right
) {
2585 INT len
= lstrlenA(es
->text
);
2586 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2589 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2590 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2591 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2592 /* FIXME: use ScrollWindow() somehow to improve performance */
2593 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2599 /*********************************************************************
2603 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2606 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2608 if (!(es
->style
& ES_MULTILINE
))
2612 WARN("called with NULL handle\n");
2616 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2618 * old buffer is freed by caller, unless
2619 * it is still in our own heap. (in that case
2620 * we free it, correcting the buggy caller.)
2623 HeapFree(es
->heap
, 0, es
->text
);
2625 es
->hloc16
= (HLOCAL16
)NULL
;
2628 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2629 EDIT_LockBuffer(wnd
, es
);
2631 es
->x_offset
= es
->y_offset
= 0;
2632 es
->selection_start
= es
->selection_end
= 0;
2633 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2634 es
->flags
&= ~EF_MODIFIED
;
2635 es
->flags
&= ~EF_UPDATE
;
2636 EDIT_BuildLineDefs_ML(wnd
, es
);
2637 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2638 EDIT_EM_ScrollCaret(wnd
, es
);
2642 /*********************************************************************
2646 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2649 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2651 if (!(es
->style
& ES_MULTILINE
))
2655 WARN("called with NULL handle\n");
2659 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2661 * old buffer is freed by caller, unless
2662 * it is still in our own heap. (in that case
2663 * we free it, correcting the buggy caller.)
2666 HeapFree(es
->heap
, 0, es
->text
);
2669 es
->hloc32
= (HLOCAL
)NULL
;
2671 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2672 EDIT_LockBuffer(wnd
, es
);
2674 es
->x_offset
= es
->y_offset
= 0;
2675 es
->selection_start
= es
->selection_end
= 0;
2676 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2677 es
->flags
&= ~EF_MODIFIED
;
2678 es
->flags
&= ~EF_UPDATE
;
2679 EDIT_BuildLineDefs_ML(wnd
, es
);
2680 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2681 EDIT_EM_ScrollCaret(wnd
, es
);
2685 /*********************************************************************
2689 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2690 * However, the windows version is not complied to yet in all of edit.c
2693 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2695 if (es
->style
& ES_MULTILINE
) {
2697 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
2699 es
->buffer_limit
= BUFLIMIT_MULTI
;
2702 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
2704 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2709 /*********************************************************************
2713 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2714 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2715 * of the char's width, according to the new docs.
2718 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2719 INT left
, INT right
)
2721 if (action
& EC_LEFTMARGIN
) {
2722 if (left
!= EC_USEFONTINFO
)
2723 es
->left_margin
= left
;
2725 es
->left_margin
= es
->char_width
/ 3;
2728 if (action
& EC_RIGHTMARGIN
) {
2729 if (right
!= EC_USEFONTINFO
)
2730 es
->right_margin
= right
;
2732 es
->right_margin
= es
->char_width
/ 3;
2734 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2738 /*********************************************************************
2740 * EM_SETPASSWORDCHAR
2743 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2745 if (es
->style
& ES_MULTILINE
)
2748 if (es
->password_char
== c
)
2751 es
->password_char
= c
;
2753 wnd
->dwStyle
|= ES_PASSWORD
;
2754 es
->style
|= ES_PASSWORD
;
2756 wnd
->dwStyle
&= ~ES_PASSWORD
;
2757 es
->style
&= ~ES_PASSWORD
;
2759 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2763 /*********************************************************************
2767 * note: unlike the specs say: the order of start and end
2768 * _is_ preserved in Windows. (i.e. start can be > end)
2769 * In other words: this handler is OK
2772 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2774 UINT old_start
= es
->selection_start
;
2775 UINT old_end
= es
->selection_end
;
2776 UINT len
= lstrlenA(es
->text
);
2779 start
= es
->selection_end
;
2780 end
= es
->selection_end
;
2782 start
= min(start
, len
);
2783 end
= min(end
, len
);
2785 es
->selection_start
= start
;
2786 es
->selection_end
= end
;
2788 es
->flags
|= EF_AFTER_WRAP
;
2790 es
->flags
&= ~EF_AFTER_WRAP
;
2791 if (es
->flags
& EF_FOCUSED
)
2792 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2793 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
2794 ORDER_UINT(start
, end
);
2795 ORDER_UINT(end
, old_end
);
2796 ORDER_UINT(start
, old_start
);
2797 ORDER_UINT(old_start
, old_end
);
2798 if (end
!= old_start
)
2802 * ORDER_UINT32(end, old_start);
2803 * EDIT_InvalidateText(wnd, es, start, end);
2804 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2805 * in place of the following if statement.
2807 if (old_start
> end
)
2809 EDIT_InvalidateText(wnd
, es
, start
, end
);
2810 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2814 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2815 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2818 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2822 /*********************************************************************
2827 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2829 if (!(es
->style
& ES_MULTILINE
))
2832 HeapFree(es
->heap
, 0, es
->tabs
);
2833 es
->tabs_count
= count
;
2837 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2838 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2844 /*********************************************************************
2849 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2851 if (!(es
->style
& ES_MULTILINE
))
2854 HeapFree(es
->heap
, 0, es
->tabs
);
2855 es
->tabs_count
= count
;
2860 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2861 for (i
= 0 ; i
< count
; i
++)
2862 es
->tabs
[i
] = *tabs
++;
2868 /*********************************************************************
2870 * EM_SETWORDBREAKPROC
2873 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2875 if (es
->word_break_proc32A
== wbp
)
2878 es
->word_break_proc32A
= wbp
;
2879 es
->word_break_proc16
= NULL
;
2880 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2881 EDIT_BuildLineDefs_ML(wnd
, es
);
2882 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2887 /*********************************************************************
2889 * EM_SETWORDBREAKPROC16
2892 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2894 if (es
->word_break_proc16
== wbp
)
2897 es
->word_break_proc32A
= NULL
;
2898 es
->word_break_proc16
= wbp
;
2899 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2900 EDIT_BuildLineDefs_ML(wnd
, es
);
2901 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2906 /*********************************************************************
2911 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2913 INT ulength
= lstrlenA(es
->undo_text
);
2914 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2916 lstrcpyA(utext
, es
->undo_text
);
2918 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2919 es
->undo_insert_count
, utext
);
2921 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2922 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2923 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2924 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2925 HeapFree(es
->heap
, 0, utext
);
2927 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2928 es
->undo_insert_count
, es
->undo_text
);
2930 if (es
->flags
& EF_UPDATE
) {
2931 es
->flags
&= ~EF_UPDATE
;
2932 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2939 /*********************************************************************
2944 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2946 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
2949 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2950 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2953 if (es
->style
& ES_MULTILINE
) {
2954 if (es
->style
& ES_READONLY
) {
2955 EDIT_MoveHome(wnd
, es
, FALSE
);
2956 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2958 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2959 if (es
->flags
& EF_UPDATE
) {
2960 es
->flags
&= ~EF_UPDATE
;
2961 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2967 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2969 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2970 if (es
->flags
& EF_UPDATE
) {
2971 es
->flags
&= ~EF_UPDATE
;
2972 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2977 if (!(es
->style
& ES_READONLY
) && !control
) {
2978 if (es
->selection_start
!= es
->selection_end
)
2979 EDIT_WM_Clear(wnd
, es
);
2981 /* delete character left of caret */
2982 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
2983 EDIT_MoveBackward(wnd
, es
, TRUE
);
2984 EDIT_WM_Clear(wnd
, es
);
2989 SendMessageA(wnd
->hwndSelf
, WM_COPY
, 0, 0);
2992 SendMessageA(wnd
->hwndSelf
, WM_PASTE
, 0, 0);
2995 SendMessageA(wnd
->hwndSelf
, WM_CUT
, 0, 0);
2999 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
3003 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
3004 if (es
->flags
& EF_UPDATE
) {
3005 es
->flags
&= ~EF_UPDATE
;
3006 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3014 /*********************************************************************
3019 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3021 if (code
|| control
)
3026 EDIT_EM_Undo(wnd
, es
);
3029 EDIT_WM_Cut(wnd
, es
);
3032 EDIT_WM_Copy(wnd
, es
);
3035 EDIT_WM_Paste(wnd
, es
);
3038 EDIT_WM_Clear(wnd
, es
);
3041 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3042 EDIT_EM_ScrollCaret(wnd
, es
);
3045 ERR("unknown menu item, please report\n");
3051 /*********************************************************************
3055 * Note: the resource files resource/sysres_??.rc cannot define a
3056 * single popup menu. Hence we use a (dummy) menubar
3057 * containing the single popup menu as its first item.
3059 * FIXME: the message identifiers have been chosen arbitrarily,
3060 * hence we use MF_BYPOSITION.
3061 * We might as well use the "real" values (anybody knows ?)
3062 * The menu definition is in resources/sysres_??.rc.
3063 * Once these are OK, we better use MF_BYCOMMAND here
3064 * (as we do in EDIT_WM_Command()).
3067 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
3069 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3070 HMENU popup
= GetSubMenu(menu
, 0);
3071 UINT start
= es
->selection_start
;
3072 UINT end
= es
->selection_end
;
3074 ORDER_UINT(start
, end
);
3077 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
3079 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3081 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3083 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
3085 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3087 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3089 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3094 /*********************************************************************
3099 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3101 INT s
= es
->selection_start
;
3102 INT e
= es
->selection_end
;
3109 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3110 dst
= GlobalLock(hdst
);
3111 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3113 OpenClipboard(wnd
->hwndSelf
);
3115 SetClipboardData(CF_TEXT
, hdst
);
3120 /*********************************************************************
3125 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3128 * To initialize some final structure members, we call some helper
3129 * functions. However, since the EDITSTATE is not consistent (i.e.
3130 * not fully initialized), we should be very careful which
3131 * functions can be called, and in what order.
3133 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3134 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3136 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3137 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3138 /* if we insert text to the editline, the text scrolls out
3139 * of the window, as the caret is placed after the insert
3140 * pos normally; thus we reset es->selection... to 0 and
3143 es
->selection_start
= es
->selection_end
= 0;
3144 EDIT_EM_ScrollCaret(wnd
, es
);
3145 if (es
->flags
& EF_UPDATE
) {
3146 es
->flags
&= ~EF_UPDATE
;
3147 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3154 /*********************************************************************
3159 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3162 while (LocalUnlock(es
->hloc32
)) ;
3163 LocalFree(es
->hloc32
);
3166 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3167 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3169 HeapDestroy(es
->heap
);
3170 HeapFree(GetProcessHeap(), 0, es
);
3171 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3175 /*********************************************************************
3180 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3185 if ( VERSION_AppWinVer() >= 0x40000 &&(
3186 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3187 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3189 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3192 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3194 GetClientRect(wnd
->hwndSelf
, &rc
);
3195 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3196 GetClipBox(dc
, &rc
);
3198 * FIXME: specs say that we should UnrealizeObject() the brush,
3199 * but the specs of UnrealizeObject() say that we shouldn't
3200 * unrealize a stock object. The default brush that
3201 * DefWndProc() returns is ... a stock object.
3203 FillRect(dc
, &rc
, brush
);
3208 /*********************************************************************
3213 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3215 lstrcpynA(text
, es
->text
, count
);
3216 return strlen(text
);
3220 /*********************************************************************
3224 * 16 bit notepad needs this. Actually it is not _our_ hack,
3225 * it is notepad's. Notepad is sending us scrollbar messages with
3226 * undocumented parameters without us even having a scrollbar ... !?!?
3229 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3232 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3235 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3236 ERR("hacked WM_HSCROLL handler invoked\n");
3237 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3238 ERR(" (this message is only displayed once per edit control)\n");
3239 es
->flags
|= EF_HSCROLL_HACK
;
3245 dx
= -es
->char_width
;
3248 if (es
->x_offset
< es
->text_width
)
3249 dx
= es
->char_width
;
3253 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3256 if (es
->x_offset
< es
->text_width
)
3257 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3264 if (es
->x_offset
< es
->text_width
)
3265 dx
= es
->text_width
- es
->x_offset
;
3268 es
->flags
|= EF_HSCROLL_TRACK
;
3269 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3271 case SB_THUMBPOSITION
:
3272 es
->flags
&= ~EF_HSCROLL_TRACK
;
3273 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3274 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3280 * FIXME : the next two are undocumented !
3281 * Are we doing the right thing ?
3282 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3283 * although it's also a regular control message.
3286 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3288 case EM_LINESCROLL16
:
3293 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3297 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3302 /*********************************************************************
3307 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3312 if (!(es
->style
& ES_MULTILINE
))
3315 if (!(es
->style
& ES_AUTOHSCROLL
))
3318 if (!(es
->style
& WS_HSCROLL
))
3319 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3322 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3326 dx
= -es
->char_width
;
3329 if (es
->x_offset
< es
->text_width
)
3330 dx
= es
->char_width
;
3334 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3337 if (es
->x_offset
< es
->text_width
)
3338 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3345 if (es
->x_offset
< es
->text_width
)
3346 dx
= es
->text_width
- es
->x_offset
;
3349 es
->flags
|= EF_HSCROLL_TRACK
;
3350 dx
= pos
- es
->x_offset
;
3352 case SB_THUMBPOSITION
:
3353 es
->flags
&= ~EF_HSCROLL_TRACK
;
3354 if (!(dx
= pos
- es
->x_offset
)) {
3355 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3356 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3363 ERR("undocumented WM_HSCROLL parameter, please report\n");
3367 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3372 /*********************************************************************
3377 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3381 /********************************************************************
3382 * This if statement used to check to see if the parent of the
3383 * edit control was a 'combobox' by comparing the ATOM of the parent
3384 * to a table of internal window control ATOMs. However, this check
3385 * would fail if the parent was a superclassed combobox (Although
3386 * having the same basic functionality of a combobox, it has a
3387 * different name and ATOM, thus defeating this check.)
3389 * The safe way to determine if the parent is a combobox is to send it
3390 * a message only a combo box would understand. I send it a message
3391 * CB_GETCOUNT, if I get 0 then the parent is not a combobox -
3392 * return FALSE. If I get > 0, then the parent IS a combobox
3393 * (or sub/super classed derrivative thereof)
3394 ********************************************************************/
3396 ((SendMessageA(wnd
->parent
->hwndSelf
, CB_GETCOUNT
, 0, 0)) > 0) &&
3397 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))
3400 HWND hCombo
= wnd
->parent
->hwndSelf
;
3401 BOOL bUIFlip
= TRUE
;
3403 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3404 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3407 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3409 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3410 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3414 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3416 /* make sure ComboLBox pops up */
3417 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3418 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3419 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3422 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3423 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3425 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3426 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3428 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3437 /*********************************************************************
3441 * Handling of special keys that don't produce a WM_CHAR
3442 * (i.e. non-printable keys) & Backspace & Delete
3445 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3450 if (GetKeyState(VK_MENU
) & 0x8000)
3453 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3454 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3459 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3465 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3466 EDIT_MoveUp_ML(wnd
, es
, shift
);
3469 EDIT_MoveWordBackward(wnd
, es
, shift
);
3471 EDIT_MoveBackward(wnd
, es
, shift
);
3474 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3478 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3479 EDIT_MoveDown_ML(wnd
, es
, shift
);
3481 EDIT_MoveWordForward(wnd
, es
, shift
);
3483 EDIT_MoveForward(wnd
, es
, shift
);
3486 EDIT_MoveHome(wnd
, es
, shift
);
3489 EDIT_MoveEnd(wnd
, es
, shift
);
3492 if (es
->style
& ES_MULTILINE
)
3493 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3496 if (es
->style
& ES_MULTILINE
)
3497 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3500 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3501 if (es
->selection_start
!= es
->selection_end
) {
3503 EDIT_WM_Cut(wnd
, es
);
3505 EDIT_WM_Clear(wnd
, es
);
3508 /* delete character left of caret */
3509 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3510 EDIT_MoveBackward(wnd
, es
, TRUE
);
3511 EDIT_WM_Clear(wnd
, es
);
3512 } else if (control
) {
3513 /* delete to end of line */
3514 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3515 EDIT_MoveEnd(wnd
, es
, TRUE
);
3516 EDIT_WM_Clear(wnd
, es
);
3518 /* delete character right of caret */
3519 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3520 EDIT_MoveForward(wnd
, es
, TRUE
);
3521 EDIT_WM_Clear(wnd
, es
);
3528 if (!(es
->style
& ES_READONLY
))
3529 EDIT_WM_Paste(wnd
, es
);
3531 EDIT_WM_Copy(wnd
, es
);
3534 /* If the edit doesn't want the return send a message to the default object */
3535 if(!(es
->style
& ES_WANTRETURN
))
3537 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
3538 DWORD dw
= SendMessage16( hwndParent
, DM_GETDEFID
, 0, 0 );
3539 if (HIWORD(dw
) == DC_HASDEFID
)
3541 SendMessageA( hwndParent
, WM_COMMAND
,
3542 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3543 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3552 /*********************************************************************
3557 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3559 es
->flags
&= ~EF_FOCUSED
;
3561 if(!(es
->style
& ES_NOHIDESEL
))
3562 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3563 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3568 /*********************************************************************
3572 * The caret position has been set on the WM_LBUTTONDOWN message
3575 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3578 INT e
= es
->selection_end
;
3583 if (!(es
->flags
& EF_FOCUSED
))
3586 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3587 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3588 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3589 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3590 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3591 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3592 EDIT_EM_ScrollCaret(wnd
, es
);
3597 /*********************************************************************
3602 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3607 if (!(es
->flags
& EF_FOCUSED
))
3610 es
->bCaptureState
= TRUE
;
3611 SetCapture(wnd
->hwndSelf
);
3612 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3613 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3614 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3615 EDIT_EM_ScrollCaret(wnd
, es
);
3616 es
->region_posx
= es
->region_posy
= 0;
3617 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3622 /*********************************************************************
3627 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3629 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3630 KillTimer(wnd
->hwndSelf
, 0);
3633 es
->bCaptureState
= FALSE
;
3638 /*********************************************************************
3643 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
)
3645 SendMessageA(wnd
->hwndSelf
,WM_PASTE
,0,0);
3650 /*********************************************************************
3655 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3661 if (GetCapture() != wnd
->hwndSelf
)
3665 * FIXME: gotta do some scrolling if outside client
3666 * area. Maybe reset the timer ?
3669 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3670 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3671 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3672 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3673 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3678 /*********************************************************************
3683 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3687 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3689 *(EDITSTATE
**)wnd
->wExtra
= es
;
3692 * Note: since the EDITSTATE has not been fully initialized yet,
3693 * we can't use any API calls that may send
3694 * WM_XXX messages before WM_NCCREATE is completed.
3697 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3699 es
->style
= cs
->style
;
3701 es
->bEnableState
= !(cs
->style
& WS_DISABLED
);
3704 * In Win95 look and feel, the WS_BORDER style is replaced by the
3705 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3706 * control a non client area.
3708 if (TWEAK_WineLook
!= WIN31_LOOK
)
3710 if (es
->style
& WS_BORDER
)
3712 es
->style
&= ~WS_BORDER
;
3713 wnd
->dwStyle
&= ~WS_BORDER
;
3714 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3719 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3720 wnd
->dwStyle
&= ~WS_BORDER
;
3723 if (es
->style
& ES_MULTILINE
) {
3724 es
->buffer_size
= BUFSTART_MULTI
;
3725 es
->buffer_limit
= BUFLIMIT_MULTI
;
3726 if (es
->style
& WS_VSCROLL
)
3727 es
->style
|= ES_AUTOVSCROLL
;
3728 if (es
->style
& WS_HSCROLL
)
3729 es
->style
|= ES_AUTOHSCROLL
;
3730 es
->style
&= ~ES_PASSWORD
;
3731 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3732 if (es
->style
& ES_RIGHT
)
3733 es
->style
&= ~ES_CENTER
;
3734 es
->style
&= ~WS_HSCROLL
;
3735 es
->style
&= ~ES_AUTOHSCROLL
;
3738 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3739 es
->style
|= ES_AUTOVSCROLL
;
3741 es
->buffer_size
= BUFSTART_SINGLE
;
3742 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3743 es
->style
&= ~ES_CENTER
;
3744 es
->style
&= ~ES_RIGHT
;
3745 es
->style
&= ~WS_HSCROLL
;
3746 es
->style
&= ~WS_VSCROLL
;
3747 es
->style
&= ~ES_AUTOVSCROLL
;
3748 es
->style
&= ~ES_WANTRETURN
;
3749 if (es
->style
& ES_UPPERCASE
) {
3750 es
->style
&= ~ES_LOWERCASE
;
3751 es
->style
&= ~ES_NUMBER
;
3752 } else if (es
->style
& ES_LOWERCASE
)
3753 es
->style
&= ~ES_NUMBER
;
3754 if (es
->style
& ES_PASSWORD
)
3755 es
->password_char
= '*';
3757 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3758 es
->style
|= ES_AUTOHSCROLL
;
3760 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3762 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3763 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3765 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3767 if (es
->style
& ES_MULTILINE
)
3768 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3775 /*********************************************************************
3780 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3789 BOOL rev
= es
->bEnableState
&&
3790 ((es
->flags
& EF_FOCUSED
) ||
3791 (es
->style
& ES_NOHIDESEL
));
3793 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3796 if(es
->style
& WS_BORDER
) {
3797 GetClientRect(wnd
->hwndSelf
, &rc
);
3798 if(es
->style
& ES_MULTILINE
) {
3799 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3800 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3802 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3804 IntersectClipRect(dc
, es
->format_rect
.left
,
3805 es
->format_rect
.top
,
3806 es
->format_rect
.right
,
3807 es
->format_rect
.bottom
);
3808 if (es
->style
& ES_MULTILINE
) {
3809 GetClientRect(wnd
->hwndSelf
, &rc
);
3810 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3813 old_font
= SelectObject(dc
, es
->font
);
3814 if ( VERSION_AppWinVer() >= 0x40000 &&(
3815 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3816 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3818 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3820 if (!es
->bEnableState
)
3821 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3822 GetClipBox(dc
, &rcRgn
);
3823 if (es
->style
& ES_MULTILINE
) {
3824 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3825 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3826 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3827 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3828 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3831 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3832 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3833 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3836 SelectObject(dc
, old_font
);
3837 if (es
->flags
& EF_FOCUSED
)
3838 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3839 es
->flags
& EF_AFTER_WRAP
);
3841 EndPaint(wnd
->hwndSelf
, &ps
);
3842 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3843 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3845 si
.cbSize
= sizeof(SCROLLINFO
);
3846 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3848 si
.nMax
= es
->line_count
+ vlc
- 2;
3850 si
.nPos
= es
->y_offset
;
3851 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3853 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3855 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3856 si
.cbSize
= sizeof(SCROLLINFO
);
3857 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3859 si
.nMax
= es
->text_width
+ fw
- 1;
3861 si
.nPos
= es
->x_offset
;
3862 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3867 /*********************************************************************
3872 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3877 OpenClipboard(wnd
->hwndSelf
);
3878 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3879 src
= (LPSTR
)GlobalLock(hsrc
);
3880 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3883 if (es
->flags
& EF_UPDATE
) {
3884 es
->flags
&= ~EF_UPDATE
;
3885 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3892 /*********************************************************************
3897 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3899 es
->flags
|= EF_FOCUSED
;
3900 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3901 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3902 es
->flags
& EF_AFTER_WRAP
);
3903 if(!(es
->style
& ES_NOHIDESEL
))
3904 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3905 ShowCaret(wnd
->hwndSelf
);
3906 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3910 /*********************************************************************
3914 * With Win95 look the margins are set to default font value unless
3915 * the system font (font == 0) is being set, in which case they are left
3919 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3927 dc
= GetDC(wnd
->hwndSelf
);
3929 old_font
= SelectObject(dc
, font
);
3930 GetTextMetricsA(dc
, &tm
);
3931 es
->line_height
= tm
.tmHeight
;
3932 es
->char_width
= tm
.tmAveCharWidth
;
3934 SelectObject(dc
, old_font
);
3935 ReleaseDC(wnd
->hwndSelf
, dc
);
3936 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3937 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3938 EC_USEFONTINFO
, EC_USEFONTINFO
);
3940 /* Force the recalculation of the format rect for each font change */
3941 GetClientRect(wnd
->hwndSelf
, &r
);
3942 EDIT_SetRectNP(wnd
, es
, &r
);
3944 if (es
->style
& ES_MULTILINE
)
3945 EDIT_BuildLineDefs_ML(wnd
, es
);
3948 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3949 if (es
->flags
& EF_FOCUSED
) {
3951 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3952 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3953 es
->flags
& EF_AFTER_WRAP
);
3954 ShowCaret(wnd
->hwndSelf
);
3959 /*********************************************************************
3964 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3965 * The modified flag is reset. No notifications are sent.
3967 * For single-line controls, reception of WM_SETTEXT triggers:
3968 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3971 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3973 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3975 TRACE("\t'%s'\n", text
);
3976 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3978 TRACE("\t<NULL>\n");
3979 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3982 if (es
->style
& ES_MULTILINE
) {
3983 es
->flags
&= ~EF_UPDATE
;
3985 es
->flags
|= EF_UPDATE
;
3987 es
->flags
&= ~EF_MODIFIED
;
3988 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3989 EDIT_EM_ScrollCaret(wnd
, es
);
3991 if (es
->flags
& EF_UPDATE
) {
3992 es
->flags
&= ~EF_UPDATE
;
3993 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3998 /*********************************************************************
4003 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4005 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4007 SetRect(&rc
, 0, 0, width
, height
);
4008 EDIT_SetRectNP(wnd
, es
, &rc
);
4009 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4014 /*********************************************************************
4019 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4021 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4022 if (EDIT_EM_CanUndo(wnd
, es
))
4023 EDIT_EM_Undo(wnd
, es
);
4025 } else if (key
== VK_UP
|| key
== VK_DOWN
)
4026 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
4028 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4032 /*********************************************************************
4037 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
4039 if (es
->region_posx
< 0) {
4040 EDIT_MoveBackward(wnd
, es
, TRUE
);
4041 } else if (es
->region_posx
> 0) {
4042 EDIT_MoveForward(wnd
, es
, TRUE
);
4045 * FIXME: gotta do some vertical scrolling here, like
4046 * EDIT_EM_LineScroll(wnd, 0, 1);
4051 /*********************************************************************
4055 * 16 bit notepad needs this. Actually it is not _our_ hack,
4056 * it is notepad's. Notepad is sending us scrollbar messages with
4057 * undocumented parameters without us even having a scrollbar ... !?!?
4060 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4065 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
4066 ERR("hacked WM_VSCROLL handler invoked\n");
4067 ERR(" if you are _not_ running 16 bit notepad, please report\n");
4068 ERR(" (this message is only displayed once per edit control)\n");
4069 es
->flags
|= EF_VSCROLL_HACK
;
4077 EDIT_EM_Scroll(wnd
, es
, action
);
4083 dy
= es
->line_count
- 1 - es
->y_offset
;
4086 es
->flags
|= EF_VSCROLL_TRACK
;
4087 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
4089 case SB_THUMBPOSITION
:
4090 es
->flags
&= ~EF_VSCROLL_TRACK
;
4091 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
4092 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4098 * FIXME : the next two are undocumented !
4099 * Are we doing the right thing ?
4100 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4101 * although it's also a regular control message.
4104 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
4106 case EM_LINESCROLL16
:
4111 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4115 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4120 /*********************************************************************
4125 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4129 if (!(es
->style
& ES_MULTILINE
))
4132 if (!(es
->style
& ES_AUTOVSCROLL
))
4135 if (!(es
->style
& WS_VSCROLL
))
4136 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4144 EDIT_EM_Scroll(wnd
, es
, action
);
4151 dy
= es
->line_count
- 1 - es
->y_offset
;
4154 es
->flags
|= EF_VSCROLL_TRACK
;
4155 dy
= pos
- es
->y_offset
;
4157 case SB_THUMBPOSITION
:
4158 es
->flags
&= ~EF_VSCROLL_TRACK
;
4159 if (!(dy
= pos
- es
->y_offset
)) {
4160 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4161 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4168 ERR("undocumented WM_VSCROLL action %d, please report\n",
4173 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4178 /*********************************************************************
4183 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
)
4185 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
4187 /* EF_UPDATE will be turned off in paint */
4188 if (es
->flags
& EF_UPDATE
)
4189 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
4191 InvalidateRect(wnd
->hwndSelf
, rc
, bErase
);