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
= (es
->style
& ES_MULTILINE
) ?
724 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
725 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
729 DPRINTF_EDIT_MSG32("WM_CHAR");
730 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
734 DPRINTF_EDIT_MSG32("WM_CLEAR");
735 EDIT_WM_Clear(wnd
, es
);
739 DPRINTF_EDIT_MSG32("WM_COMMAND");
740 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
744 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
745 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
749 DPRINTF_EDIT_MSG32("WM_COPY");
750 EDIT_WM_Copy(wnd
, es
);
754 DPRINTF_EDIT_MSG32("WM_CREATE");
755 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
759 DPRINTF_EDIT_MSG32("WM_CUT");
760 EDIT_WM_Cut(wnd
, es
);
764 DPRINTF_EDIT_MSG32("WM_ENABLE");
765 es
->bEnableState
= (BOOL
) wParam
;
766 EDIT_UpdateText(wnd
, NULL
, TRUE
);
770 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
771 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
775 DPRINTF_EDIT_MSG32("WM_GETFONT");
776 result
= (LRESULT
)es
->font
;
780 DPRINTF_EDIT_MSG32("WM_GETTEXT");
781 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
784 case WM_GETTEXTLENGTH
:
785 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
786 result
= lstrlenA(es
->text
);
790 DPRINTF_EDIT_MSG32("WM_HSCROLL");
791 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
795 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
796 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
800 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
801 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
804 case WM_LBUTTONDBLCLK
:
805 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
806 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
810 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
811 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
815 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
816 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
820 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
821 result
= EDIT_WM_MButtonDown(wnd
);
824 case WM_MOUSEACTIVATE
:
826 * FIXME: maybe DefWindowProc() screws up, but it seems that
827 * modeless dialog boxes need this. If we don't do this, the focus
828 * will _not_ be set by DefWindowProc() for edit controls in a
829 * modeless dialog box ???
831 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
832 SetFocus(wnd
->hwndSelf
);
833 result
= MA_ACTIVATE
;
838 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
840 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
844 DPRINTF_EDIT_MSG32("WM_PAINT");
845 EDIT_WM_Paint(wnd
, es
, wParam
);
849 DPRINTF_EDIT_MSG32("WM_PASTE");
850 EDIT_WM_Paste(wnd
, es
);
854 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
855 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
859 DPRINTF_EDIT_MSG32("WM_SETFONT");
860 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
864 DPRINTF_EDIT_MSG32("WM_SETTEXT");
865 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
870 DPRINTF_EDIT_MSG32("WM_SIZE");
871 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
875 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
876 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
880 DPRINTF_EDIT_MSG32("WM_TIMER");
881 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
885 DPRINTF_EDIT_MSG32("WM_VSCROLL");
886 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
891 short gcWheelDelta
= 0;
892 UINT pulScrollLines
= 3;
893 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
895 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
896 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
899 gcWheelDelta
-= (short) HIWORD(wParam
);
900 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
902 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
903 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
904 result
= EDIT_EM_LineScroll(wnd
, es
, 0, cLineScroll
);
909 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
912 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
914 WIN_ReleaseWndPtr(wnd
);
920 /*********************************************************************
922 * EDIT_BuildLineDefs_ML
924 * Build linked list of text lines.
925 * Lines can end with '\0' (last line), a character (if it is wrapped),
926 * a soft return '\r\r\n' or a hard return '\r\n'
929 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
935 LINEDEF
*current_def
;
936 LINEDEF
**previous_next
;
938 current_def
= es
->first_line_def
;
940 LINEDEF
*next_def
= current_def
->next
;
941 HeapFree(es
->heap
, 0, current_def
);
942 current_def
= next_def
;
943 } while (current_def
);
947 dc
= GetDC(wnd
->hwndSelf
);
949 old_font
= SelectObject(dc
, es
->font
);
951 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
953 previous_next
= &es
->first_line_def
;
955 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
956 current_def
->next
= NULL
;
959 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
964 current_def
->ending
= END_0
;
965 current_def
->net_length
= lstrlenA(start
);
966 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
967 current_def
->ending
= END_SOFT
;
968 current_def
->net_length
= cp
- start
- 1;
970 current_def
->ending
= END_HARD
;
971 current_def
->net_length
= cp
- start
;
973 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
974 start
, current_def
->net_length
,
975 es
->tabs_count
, es
->tabs
));
976 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
977 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
982 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
983 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
984 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
985 start
, next
, es
->tabs_count
, es
->tabs
));
986 } while (current_def
->width
<= fw
);
992 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
993 start
, next
, es
->tabs_count
, es
->tabs
));
994 } while (current_def
->width
<= fw
);
998 current_def
->net_length
= prev
;
999 current_def
->ending
= END_WRAP
;
1000 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
1001 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
1003 switch (current_def
->ending
) {
1005 current_def
->length
= current_def
->net_length
+ 3;
1008 current_def
->length
= current_def
->net_length
+ 2;
1012 current_def
->length
= current_def
->net_length
;
1015 es
->text_width
= max(es
->text_width
, current_def
->width
);
1016 start
+= current_def
->length
;
1017 *previous_next
= current_def
;
1018 previous_next
= ¤t_def
->next
;
1020 } while (current_def
->ending
!= END_0
);
1022 SelectObject(dc
, old_font
);
1023 ReleaseDC(wnd
->hwndSelf
, dc
);
1027 /*********************************************************************
1029 * EDIT_CallWordBreakProc
1031 * Call appropriate WordBreakProc (internal or external).
1033 * Note: The "start" argument should always be an index refering
1034 * to es->text. The actual wordbreak proc might be
1035 * 16 bit, so we can't always pass any 32 bit LPSTR.
1036 * Hence we assume that es->text is the buffer that holds
1037 * the string under examination (we can decide this for ourselves).
1040 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1042 if (es
->word_break_proc16
) {
1043 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1044 SEGPTR segptr
= LocalLock16(hloc16
);
1045 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1046 segptr
+ start
, index
, count
, action
);
1047 LocalUnlock16(hloc16
);
1050 else if (es
->word_break_proc32A
)
1052 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1053 es
->word_break_proc32A
, es
->text
+ start
, index
,
1055 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1059 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1063 /*********************************************************************
1067 * Beware: This is not the function called on EM_CHARFROMPOS
1068 * The position _can_ be outside the formatting / client
1070 * The return value is only the character index
1073 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1079 if (es
->style
& ES_MULTILINE
) {
1080 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1082 LINEDEF
*line_def
= es
->first_line_def
;
1084 while ((line
> 0) && line_def
->next
) {
1085 line_index
+= line_def
->length
;
1086 line_def
= line_def
->next
;
1089 x
+= es
->x_offset
- es
->format_rect
.left
;
1090 if (x
>= line_def
->width
) {
1092 *after_wrap
= (line_def
->ending
== END_WRAP
);
1093 return line_index
+ line_def
->net_length
;
1097 *after_wrap
= FALSE
;
1100 dc
= GetDC(wnd
->hwndSelf
);
1102 old_font
= SelectObject(dc
, es
->font
);
1103 low
= line_index
+ 1;
1104 high
= line_index
+ line_def
->net_length
+ 1;
1105 while (low
< high
- 1)
1107 INT mid
= (low
+ high
) / 2;
1108 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1114 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1115 (line_def
->ending
== END_WRAP
));
1120 *after_wrap
= FALSE
;
1121 x
-= es
->format_rect
.left
;
1123 return es
->x_offset
;
1124 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1125 dc
= GetDC(wnd
->hwndSelf
);
1127 old_font
= SelectObject(dc
, es
->font
);
1131 INT high
= es
->x_offset
;
1132 while (low
< high
- 1)
1134 INT mid
= (low
+ high
) / 2;
1135 GetTextExtentPoint32A( dc
, text
+ mid
,
1136 es
->x_offset
- mid
, &size
);
1137 if (size
.cx
> -x
) low
= mid
;
1144 INT low
= es
->x_offset
;
1145 INT high
= lstrlenA(es
->text
) + 1;
1146 while (low
< high
- 1)
1148 INT mid
= (low
+ high
) / 2;
1149 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1150 mid
- es
->x_offset
, &size
);
1151 if (size
.cx
> x
) high
= mid
;
1156 if (es
->style
& ES_PASSWORD
)
1157 HeapFree(es
->heap
, 0 ,text
);
1160 SelectObject(dc
, old_font
);
1161 ReleaseDC(wnd
->hwndSelf
, dc
);
1166 /*********************************************************************
1170 * adjusts the point to be within the formatting rectangle
1171 * (so CharFromPos returns the nearest _visible_ character)
1174 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1176 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1177 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1181 /*********************************************************************
1185 * Calculates the bounding rectangle for a line from a starting
1186 * column to an ending column.
1189 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1191 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1193 if (es
->style
& ES_MULTILINE
)
1194 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1196 rc
->top
= es
->format_rect
.top
;
1197 rc
->bottom
= rc
->top
+ es
->line_height
;
1198 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1199 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1203 /*********************************************************************
1205 * EDIT_GetPasswordPointer_SL
1207 * note: caller should free the (optionally) allocated buffer
1210 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1212 if (es
->style
& ES_PASSWORD
) {
1213 INT len
= lstrlenA(es
->text
);
1214 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1215 RtlFillMemory(text
, len
, es
->password_char
);
1223 /*********************************************************************
1227 * This acts as a LOCAL_Lock(), but it locks only once. This way
1228 * you can call it whenever you like, without unlocking.
1231 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1234 ERR("no EDITSTATE ... please report\n");
1237 if (!(es
->style
& ES_MULTILINE
))
1241 es
->text
= LocalLock(es
->hloc32
);
1242 else if (es
->hloc16
)
1243 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1245 ERR("no buffer ... please report\n");
1253 /*********************************************************************
1255 * EDIT_SL_InvalidateText
1257 * Called from EDIT_InvalidateText().
1258 * Does the job for single-line controls only.
1261 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1266 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1267 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1268 EDIT_UpdateText(wnd
, &rc
, FALSE
);
1272 /*********************************************************************
1274 * EDIT_ML_InvalidateText
1276 * Called from EDIT_InvalidateText().
1277 * Does the job for multi-line controls only.
1280 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1282 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1283 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1284 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1293 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1296 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1297 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1298 if (sl
< es
->y_offset
) {
1302 if (el
> es
->y_offset
+ vlc
) {
1303 el
= es
->y_offset
+ vlc
;
1304 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1306 GetClientRect(wnd
->hwndSelf
, &rc1
);
1307 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1309 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1310 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1311 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1313 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1314 EDIT_EM_LineLength(wnd
, es
,
1315 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1317 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1318 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1319 for (l
= sl
+ 1 ; l
< el
; l
++) {
1320 EDIT_GetLineRect(wnd
, es
, l
, 0,
1321 EDIT_EM_LineLength(wnd
, es
,
1322 EDIT_EM_LineIndex(wnd
, es
, l
)),
1324 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1325 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1327 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1328 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1329 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1334 /*********************************************************************
1336 * EDIT_InvalidateText
1338 * Invalidate the text from offset start upto, but not including,
1339 * offset end. Useful for (re)painting the selection.
1340 * Regions outside the linewidth are not invalidated.
1341 * end == -1 means end == TextLength.
1342 * start and end need not be ordered.
1345 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1351 end
= lstrlenA(es
->text
);
1353 ORDER_INT(start
, end
);
1355 if (es
->style
& ES_MULTILINE
)
1356 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1358 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1362 /*********************************************************************
1366 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1369 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1374 if (size
<= es
->buffer_size
)
1376 if (size
> es
->buffer_limit
) {
1377 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1380 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1381 if (size
> es
->buffer_limit
)
1382 size
= es
->buffer_limit
;
1384 TRACE("trying to ReAlloc to %d+1\n", size
);
1386 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1388 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1389 es
->buffer_size
= min(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1391 es
->buffer_size
= 0;
1392 } else if (es
->hloc32
) {
1393 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1394 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1395 es
->hloc32
= hNew32
;
1396 es
->buffer_size
= min(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1398 } else if (es
->hloc16
) {
1399 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1400 TRACE("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1401 es
->hloc16
= hNew16
;
1402 es
->buffer_size
= min(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1405 if (es
->buffer_size
< size
) {
1406 EDIT_LockBuffer(wnd
, es
);
1407 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1408 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1411 EDIT_LockBuffer(wnd
, es
);
1412 TRACE("We now have %d+1\n", es
->buffer_size
);
1418 /*********************************************************************
1422 * Try to fit size + 1 bytes in the undo buffer.
1425 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1427 if (size
<= es
->undo_buffer_size
)
1429 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1431 TRACE("trying to ReAlloc to %d+1\n", size
);
1433 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1434 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1435 if (es
->undo_buffer_size
< size
) {
1436 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1445 /*********************************************************************
1450 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1452 INT e
= es
->selection_end
;
1456 if ((es
->style
& ES_MULTILINE
) && e
&&
1457 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1459 if (e
&& (es
->text
[e
- 1] == '\r'))
1463 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1464 EDIT_EM_ScrollCaret(wnd
, es
);
1468 /*********************************************************************
1472 * Only for multi line controls
1473 * Move the caret one line down, on a column with the nearest
1474 * x coordinate on the screen (might be a different column).
1477 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1479 INT s
= es
->selection_start
;
1480 INT e
= es
->selection_end
;
1481 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1482 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1483 INT x
= SLOWORD(pos
);
1484 INT y
= SHIWORD(pos
);
1486 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1489 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1490 EDIT_EM_ScrollCaret(wnd
, es
);
1494 /*********************************************************************
1499 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1501 BOOL after_wrap
= FALSE
;
1504 /* Pass a high value in x to make sure of receiving the en of the line */
1505 if (es
->style
& ES_MULTILINE
)
1506 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1507 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1509 e
= lstrlenA(es
->text
);
1510 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1511 EDIT_EM_ScrollCaret(wnd
, es
);
1515 /*********************************************************************
1520 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1522 INT e
= es
->selection_end
;
1526 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1527 if (es
->text
[e
] == '\n')
1529 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1533 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1534 EDIT_EM_ScrollCaret(wnd
, es
);
1538 /*********************************************************************
1542 * Home key: move to beginning of line.
1545 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1549 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1550 if (es
->style
& ES_MULTILINE
)
1551 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1552 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1555 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1556 EDIT_EM_ScrollCaret(wnd
, es
);
1560 /*********************************************************************
1562 * EDIT_MovePageDown_ML
1564 * Only for multi line controls
1565 * Move the caret one page down, on a column with the nearest
1566 * x coordinate on the screen (might be a different column).
1569 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1571 INT s
= es
->selection_start
;
1572 INT e
= es
->selection_end
;
1573 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1574 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1575 INT x
= SLOWORD(pos
);
1576 INT y
= SHIWORD(pos
);
1578 e
= EDIT_CharFromPos(wnd
, es
, x
,
1579 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1583 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1584 EDIT_EM_ScrollCaret(wnd
, es
);
1588 /*********************************************************************
1590 * EDIT_MovePageUp_ML
1592 * Only for multi line controls
1593 * Move the caret one page up, on a column with the nearest
1594 * x coordinate on the screen (might be a different column).
1597 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1599 INT s
= es
->selection_start
;
1600 INT e
= es
->selection_end
;
1601 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1602 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1603 INT x
= SLOWORD(pos
);
1604 INT y
= SHIWORD(pos
);
1606 e
= EDIT_CharFromPos(wnd
, es
, x
,
1607 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1611 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1612 EDIT_EM_ScrollCaret(wnd
, es
);
1616 /*********************************************************************
1620 * Only for multi line controls
1621 * Move the caret one line up, on a column with the nearest
1622 * x coordinate on the screen (might be a different column).
1625 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1627 INT s
= es
->selection_start
;
1628 INT e
= es
->selection_end
;
1629 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1630 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1631 INT x
= SLOWORD(pos
);
1632 INT y
= SHIWORD(pos
);
1634 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1637 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1638 EDIT_EM_ScrollCaret(wnd
, es
);
1642 /*********************************************************************
1644 * EDIT_MoveWordBackward
1647 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1649 INT s
= es
->selection_start
;
1650 INT e
= es
->selection_end
;
1655 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1656 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1657 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1660 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1661 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1664 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1665 li
, e
- li
, ll
, WB_LEFT
);
1669 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1670 EDIT_EM_ScrollCaret(wnd
, es
);
1674 /*********************************************************************
1676 * EDIT_MoveWordForward
1679 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1681 INT s
= es
->selection_start
;
1682 INT e
= es
->selection_end
;
1687 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1688 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1689 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1691 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1692 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1694 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1695 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1699 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1700 EDIT_EM_ScrollCaret(wnd
, es
);
1704 /*********************************************************************
1709 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1711 INT s
= es
->selection_start
;
1712 INT e
= es
->selection_end
;
1719 if (es
->style
& ES_MULTILINE
) {
1720 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1721 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1726 TRACE("line=%d\n", line
);
1728 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1731 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1732 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1733 s
= es
->selection_start
;
1734 e
= es
->selection_end
;
1736 s
= min(li
+ ll
, max(li
, s
));
1737 e
= min(li
+ ll
, max(li
, e
));
1738 if (rev
&& (s
!= e
) &&
1739 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1740 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1741 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1742 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1744 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1748 /*********************************************************************
1753 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1763 BkColor
= GetBkColor(dc
);
1764 TextColor
= GetTextColor(dc
);
1766 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1767 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1769 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1770 if (es
->style
& ES_MULTILINE
) {
1771 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1772 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1774 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1775 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1776 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1778 if (es
->style
& ES_PASSWORD
)
1779 HeapFree(es
->heap
, 0, text
);
1782 SetBkColor(dc
, BkColor
);
1783 SetTextColor(dc
, TextColor
);
1789 /*********************************************************************
1794 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1797 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1798 INT x
= SLOWORD(res
);
1799 INT y
= SHIWORD(res
);
1801 if(x
< es
->format_rect
.left
)
1802 x
= es
->format_rect
.left
;
1803 if(x
> es
->format_rect
.right
- 2)
1804 x
= es
->format_rect
.right
- 2;
1805 if(y
> es
->format_rect
.bottom
)
1806 y
= es
->format_rect
.bottom
;
1807 if(y
< es
->format_rect
.top
)
1808 y
= es
->format_rect
.top
;
1814 /*********************************************************************
1818 * note: this is not (exactly) the handler called on EM_SETRECTNP
1819 * it is also used to set the rect of a single line control
1822 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1824 CopyRect(&es
->format_rect
, rc
);
1825 if (es
->style
& WS_BORDER
) {
1826 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1827 if(TWEAK_WineLook
== WIN31_LOOK
)
1829 es
->format_rect
.left
+= bw
;
1830 es
->format_rect
.top
+= bw
;
1831 es
->format_rect
.right
-= bw
;
1832 es
->format_rect
.bottom
-= bw
;
1834 es
->format_rect
.left
+= es
->left_margin
;
1835 es
->format_rect
.right
-= es
->right_margin
;
1836 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1837 if (es
->style
& ES_MULTILINE
)
1838 es
->format_rect
.bottom
= es
->format_rect
.top
+
1839 max(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1841 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1842 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1843 EDIT_BuildLineDefs_ML(wnd
, es
);
1847 /*********************************************************************
1852 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1855 ERR("no EDITSTATE ... please report\n");
1858 if (!(es
->style
& ES_MULTILINE
))
1860 if (!es
->lock_count
) {
1861 ERR("lock_count == 0 ... please report\n");
1865 ERR("es->text == 0 ... please report\n");
1868 if (force
|| (es
->lock_count
== 1)) {
1870 LocalUnlock(es
->hloc32
);
1872 } else if (es
->hloc16
) {
1873 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1881 /*********************************************************************
1883 * EDIT_WordBreakProc
1885 * Find the beginning of words.
1886 * Note: unlike the specs for a WordBreakProc, this function only
1887 * allows to be called without linebreaks between s[0] upto
1888 * s[count - 1]. Remember it is only called
1889 * internally, so we can decide this for ourselves.
1892 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1896 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1897 s
, index
, count
, action
);
1905 if (s
[index
] == ' ') {
1906 while (index
&& (s
[index
] == ' '))
1909 while (index
&& (s
[index
] != ' '))
1911 if (s
[index
] == ' ')
1915 while (index
&& (s
[index
] != ' '))
1917 if (s
[index
] == ' ')
1927 if (s
[index
] == ' ')
1928 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1930 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1932 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1936 case WB_ISDELIMITER
:
1937 ret
= (s
[index
] == ' ');
1940 ERR("unknown action code, please report !\n");
1947 /*********************************************************************
1951 * returns line number (not index) in high-order word of result.
1952 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1953 * to Richedit, not to the edit control. Original documentation is valid.
1954 * FIXME: do the specs mean to return -1 if outside client area or
1955 * if outside formatting rectangle ???
1958 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1966 GetClientRect(wnd
->hwndSelf
, &rc
);
1967 if (!PtInRect(&rc
, pt
))
1970 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1971 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1975 /*********************************************************************
1979 * Enable or disable soft breaks.
1981 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1983 es
->flags
&= ~EF_USE_SOFTBRK
;
1985 es
->flags
|= EF_USE_SOFTBRK
;
1986 FIXME("soft break enabled, not implemented\n");
1992 /*********************************************************************
1996 * Hopefully this won't fire back at us.
1997 * We always start with a fixed buffer in our own heap.
1998 * However, with this message a 32 bit application requests
1999 * a handle to 32 bit moveable local heap memory, where it expects
2001 * It's a pity that from this moment on we have to use this
2002 * local heap, because applications may rely on the handle
2005 * In this function we'll try to switch to local heap.
2008 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
2014 if (!(es
->style
& ES_MULTILINE
))
2019 else if (es
->hloc16
)
2020 return (HLOCAL
)es
->hloc16
;
2022 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2023 ERR("could not allocate new 32 bit buffer\n");
2026 newSize
= min(LocalSize(newBuf
) - 1, es
->buffer_limit
);
2027 if (!(newText
= LocalLock(newBuf
))) {
2028 ERR("could not lock new 32 bit buffer\n");
2032 lstrcpyA(newText
, es
->text
);
2033 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2035 HeapFree(es
->heap
, 0, es
->text
);
2036 es
->hloc32
= newBuf
;
2037 es
->hloc16
= (HLOCAL16
)NULL
;
2038 es
->buffer_size
= newSize
;
2040 EDIT_LockBuffer(wnd
, es
);
2041 TRACE("switched to 32 bit local heap\n");
2047 /*********************************************************************
2051 * Hopefully this won't fire back at us.
2052 * We always start with a buffer in 32 bit linear memory.
2053 * However, with this message a 16 bit application requests
2054 * a handle of 16 bit local heap memory, where it expects to find
2056 * It's a pitty that from this moment on we have to use this
2057 * local heap, because applications may rely on the handle
2060 * In this function we'll try to switch to local heap.
2062 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2068 if (!(es
->style
& ES_MULTILINE
))
2074 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2075 if (!LocalInit16(wnd
->hInstance
, 0,
2076 GlobalSize16(wnd
->hInstance
))) {
2077 ERR("could not initialize local heap\n");
2080 TRACE("local heap initialized\n");
2082 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2083 ERR("could not allocate new 16 bit buffer\n");
2086 newSize
= min(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2087 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2088 ERR("could not lock new 16 bit buffer\n");
2089 LOCAL_Free(wnd
->hInstance
, newBuf
);
2092 lstrcpyA(newText
, es
->text
);
2093 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2095 HeapFree(es
->heap
, 0, es
->text
);
2096 else if (es
->hloc32
) {
2097 while (LocalFree(es
->hloc32
)) ;
2098 LocalFree(es
->hloc32
);
2100 es
->hloc32
= (HLOCAL
)NULL
;
2101 es
->hloc16
= newBuf
;
2102 es
->buffer_size
= newSize
;
2104 EDIT_LockBuffer(wnd
, es
);
2105 TRACE("switched to 16 bit buffer\n");
2111 /*********************************************************************
2116 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2122 if (es
->style
& ES_MULTILINE
) {
2123 if (line
>= es
->line_count
)
2127 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2129 len
= min(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2130 for (i
= 0 ; i
< len
; i
++) {
2135 return (LRESULT
)len
;
2139 /*********************************************************************
2144 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2146 UINT s
= es
->selection_start
;
2147 UINT e
= es
->selection_end
;
2154 return MAKELONG(s
, e
);
2158 /*********************************************************************
2162 * FIXME: is this right ? (or should it be only VSCROLL)
2163 * (and maybe only for edit controls that really have their
2164 * own scrollbars) (and maybe only for multiline controls ?)
2165 * All in all: very poorly documented
2167 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2168 * WM_VSCROLL handlers
2171 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2173 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2174 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2178 /*********************************************************************
2183 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2188 if (!(es
->style
& ES_MULTILINE
))
2190 if (index
> lstrlenA(es
->text
))
2191 return es
->line_count
- 1;
2193 index
= min(es
->selection_start
, es
->selection_end
);
2196 line_def
= es
->first_line_def
;
2197 index
-= line_def
->length
;
2198 while ((index
>= 0) && line_def
->next
) {
2200 line_def
= line_def
->next
;
2201 index
-= line_def
->length
;
2207 /*********************************************************************
2212 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2217 if (!(es
->style
& ES_MULTILINE
))
2219 if (line
>= es
->line_count
)
2223 line_def
= es
->first_line_def
;
2225 INT index
= es
->selection_end
- line_def
->length
;
2226 while ((index
>= 0) && line_def
->next
) {
2227 line_index
+= line_def
->length
;
2228 line_def
= line_def
->next
;
2229 index
-= line_def
->length
;
2233 line_index
+= line_def
->length
;
2234 line_def
= line_def
->next
;
2242 /*********************************************************************
2247 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2251 if (!(es
->style
& ES_MULTILINE
))
2252 return lstrlenA(es
->text
);
2255 /* get the number of remaining non-selected chars of selected lines */
2258 li
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_start
);
2259 /* # chars before start of selection area */
2260 count
= es
->selection_start
- EDIT_EM_LineIndex(wnd
, es
, li
);
2261 li
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2262 /* # chars after end of selection */
2263 count
+= EDIT_EM_LineIndex(wnd
, es
, li
) +
2264 EDIT_EM_LineLength(wnd
, es
, li
) - es
->selection_end
;
2267 line_def
= es
->first_line_def
;
2268 index
-= line_def
->length
;
2269 while ((index
>= 0) && line_def
->next
) {
2270 line_def
= line_def
->next
;
2271 index
-= line_def
->length
;
2273 return line_def
->net_length
;
2277 /*********************************************************************
2281 * FIXME: dx is in average character widths
2282 * However, we assume it is in pixels when we use this
2283 * function internally
2286 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2290 if (!(es
->style
& ES_MULTILINE
))
2293 if (-dx
> es
->x_offset
)
2295 if (dx
> es
->text_width
- es
->x_offset
)
2296 dx
= es
->text_width
- es
->x_offset
;
2297 nyoff
= max(0, es
->y_offset
+ dy
);
2298 if (nyoff
>= es
->line_count
)
2299 nyoff
= es
->line_count
- 1;
2300 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2304 GetClientRect(wnd
->hwndSelf
, &rc1
);
2305 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2306 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2307 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2308 es
->y_offset
= nyoff
;
2311 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2312 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2313 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2314 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2319 /*********************************************************************
2324 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2326 INT len
= lstrlenA(es
->text
);
2335 index
= min(index
, len
);
2336 dc
= GetDC(wnd
->hwndSelf
);
2338 old_font
= SelectObject(dc
, es
->font
);
2339 if (es
->style
& ES_MULTILINE
) {
2340 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2341 y
= (l
- es
->y_offset
) * es
->line_height
;
2342 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2343 if (after_wrap
&& (li
== index
) && l
) {
2345 LINEDEF
*line_def
= es
->first_line_def
;
2347 line_def
= line_def
->next
;
2350 if (line_def
->ending
== END_WRAP
) {
2352 y
-= es
->line_height
;
2353 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2356 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2357 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2359 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2360 if (index
< es
->x_offset
) {
2361 GetTextExtentPoint32A(dc
, text
+ index
,
2362 es
->x_offset
- index
, &size
);
2365 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2366 index
- es
->x_offset
, &size
);
2370 if (es
->style
& ES_PASSWORD
)
2371 HeapFree(es
->heap
, 0 ,text
);
2373 x
+= es
->format_rect
.left
;
2374 y
+= es
->format_rect
.top
;
2376 SelectObject(dc
, old_font
);
2377 ReleaseDC(wnd
->hwndSelf
, dc
);
2378 return MAKELONG((INT16
)x
, (INT16
)y
);
2382 /*********************************************************************
2386 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2389 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2391 INT strl
= lstrlenA(lpsz_replace
);
2392 INT tl
= lstrlenA(es
->text
);
2399 s
= es
->selection_start
;
2400 e
= es
->selection_end
;
2402 if ((s
== e
) && !strl
)
2407 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2411 /* there is something to be deleted */
2413 utl
= lstrlenA(es
->undo_text
);
2414 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2415 /* undo-buffer is extended to the right */
2416 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2417 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2418 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2419 /* undo-buffer is extended to the left */
2420 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2421 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2423 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2424 p
[i
] = (es
->text
+ s
)[i
];
2425 es
->undo_position
= s
;
2427 /* new undo-buffer */
2428 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2429 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2430 es
->undo_position
= s
;
2432 /* any deletion makes the old insertion-undo invalid */
2433 es
->undo_insert_count
= 0;
2435 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2438 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2441 /* there is an insertion */
2443 if ((s
== es
->undo_position
) ||
2444 ((es
->undo_insert_count
) &&
2445 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2447 * insertion is new and at delete position or
2448 * an extension to either left or right
2450 es
->undo_insert_count
+= strl
;
2452 /* new insertion undo */
2453 es
->undo_position
= s
;
2454 es
->undo_insert_count
= strl
;
2455 /* new insertion makes old delete-buffer invalid */
2456 *es
->undo_text
= '\0';
2459 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2462 tl
= lstrlenA(es
->text
);
2463 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2465 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2466 p
[i
] = lpsz_replace
[i
];
2467 if(es
->style
& ES_UPPERCASE
)
2468 CharUpperBuffA(p
, strl
);
2469 else if(es
->style
& ES_LOWERCASE
)
2470 CharLowerBuffA(p
, strl
);
2473 /* FIXME: really inefficient */
2474 if (es
->style
& ES_MULTILINE
)
2475 EDIT_BuildLineDefs_ML(wnd
, es
);
2477 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2478 es
->flags
|= EF_MODIFIED
;
2479 es
->flags
|= EF_UPDATE
;
2480 EDIT_EM_ScrollCaret(wnd
, es
);
2482 /* FIXME: really inefficient */
2483 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2487 /*********************************************************************
2492 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2496 if (!(es
->style
& ES_MULTILINE
))
2497 return (LRESULT
)FALSE
;
2507 if (es
->y_offset
< es
->line_count
- 1)
2512 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2515 if (es
->y_offset
< es
->line_count
- 1)
2516 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2519 return (LRESULT
)FALSE
;
2522 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2523 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2525 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2529 /*********************************************************************
2534 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2536 if (es
->style
& ES_MULTILINE
) {
2541 INT cw
= es
->char_width
;
2546 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2547 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2548 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2549 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2550 if (l
>= es
->y_offset
+ vlc
)
2551 dy
= l
- vlc
+ 1 - es
->y_offset
;
2552 if (l
< es
->y_offset
)
2553 dy
= l
- es
->y_offset
;
2554 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2555 if (x
< es
->format_rect
.left
)
2556 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2557 if (x
> es
->format_rect
.right
)
2558 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2560 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2566 if (!(es
->style
& ES_AUTOHSCROLL
))
2569 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2570 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2571 if (x
< es
->format_rect
.left
) {
2572 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2575 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2576 } while ((x
< goal
) && es
->x_offset
);
2577 /* FIXME: use ScrollWindow() somehow to improve performance */
2578 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2579 } else if (x
> es
->format_rect
.right
) {
2581 INT len
= lstrlenA(es
->text
);
2582 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2585 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2586 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2587 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2588 /* FIXME: use ScrollWindow() somehow to improve performance */
2589 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2595 /*********************************************************************
2599 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2602 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2604 if (!(es
->style
& ES_MULTILINE
))
2608 WARN("called with NULL handle\n");
2612 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2614 * old buffer is freed by caller, unless
2615 * it is still in our own heap. (in that case
2616 * we free it, correcting the buggy caller.)
2619 HeapFree(es
->heap
, 0, es
->text
);
2621 es
->hloc16
= (HLOCAL16
)NULL
;
2624 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2625 EDIT_LockBuffer(wnd
, es
);
2627 es
->x_offset
= es
->y_offset
= 0;
2628 es
->selection_start
= es
->selection_end
= 0;
2629 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2630 es
->flags
&= ~EF_MODIFIED
;
2631 es
->flags
&= ~EF_UPDATE
;
2632 EDIT_BuildLineDefs_ML(wnd
, es
);
2633 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2634 EDIT_EM_ScrollCaret(wnd
, es
);
2638 /*********************************************************************
2642 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2645 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2647 if (!(es
->style
& ES_MULTILINE
))
2651 WARN("called with NULL handle\n");
2655 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2657 * old buffer is freed by caller, unless
2658 * it is still in our own heap. (in that case
2659 * we free it, correcting the buggy caller.)
2662 HeapFree(es
->heap
, 0, es
->text
);
2665 es
->hloc32
= (HLOCAL
)NULL
;
2667 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2668 EDIT_LockBuffer(wnd
, es
);
2670 es
->x_offset
= es
->y_offset
= 0;
2671 es
->selection_start
= es
->selection_end
= 0;
2672 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2673 es
->flags
&= ~EF_MODIFIED
;
2674 es
->flags
&= ~EF_UPDATE
;
2675 EDIT_BuildLineDefs_ML(wnd
, es
);
2676 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2677 EDIT_EM_ScrollCaret(wnd
, es
);
2681 /*********************************************************************
2685 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2686 * However, the windows version is not complied to yet in all of edit.c
2689 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2691 if (es
->style
& ES_MULTILINE
) {
2693 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
2695 es
->buffer_limit
= BUFLIMIT_MULTI
;
2698 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
2700 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2705 /*********************************************************************
2709 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2710 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2711 * of the char's width, according to the new docs.
2714 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2715 INT left
, INT right
)
2717 if (action
& EC_LEFTMARGIN
) {
2718 if (left
!= EC_USEFONTINFO
)
2719 es
->left_margin
= left
;
2721 es
->left_margin
= es
->char_width
/ 3;
2724 if (action
& EC_RIGHTMARGIN
) {
2725 if (right
!= EC_USEFONTINFO
)
2726 es
->right_margin
= right
;
2728 es
->right_margin
= es
->char_width
/ 3;
2730 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2734 /*********************************************************************
2736 * EM_SETPASSWORDCHAR
2739 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2741 if (es
->style
& ES_MULTILINE
)
2744 if (es
->password_char
== c
)
2747 es
->password_char
= c
;
2749 wnd
->dwStyle
|= ES_PASSWORD
;
2750 es
->style
|= ES_PASSWORD
;
2752 wnd
->dwStyle
&= ~ES_PASSWORD
;
2753 es
->style
&= ~ES_PASSWORD
;
2755 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2759 /*********************************************************************
2763 * note: unlike the specs say: the order of start and end
2764 * _is_ preserved in Windows. (i.e. start can be > end)
2765 * In other words: this handler is OK
2768 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2770 UINT old_start
= es
->selection_start
;
2771 UINT old_end
= es
->selection_end
;
2772 UINT len
= lstrlenA(es
->text
);
2775 start
= es
->selection_end
;
2776 end
= es
->selection_end
;
2778 start
= min(start
, len
);
2779 end
= min(end
, len
);
2781 es
->selection_start
= start
;
2782 es
->selection_end
= end
;
2784 es
->flags
|= EF_AFTER_WRAP
;
2786 es
->flags
&= ~EF_AFTER_WRAP
;
2787 if (es
->flags
& EF_FOCUSED
)
2788 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2789 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
2790 ORDER_UINT(start
, end
);
2791 ORDER_UINT(end
, old_end
);
2792 ORDER_UINT(start
, old_start
);
2793 ORDER_UINT(old_start
, old_end
);
2794 if (end
!= old_start
)
2798 * ORDER_UINT32(end, old_start);
2799 * EDIT_InvalidateText(wnd, es, start, end);
2800 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2801 * in place of the following if statement.
2803 if (old_start
> end
)
2805 EDIT_InvalidateText(wnd
, es
, start
, end
);
2806 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2810 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2811 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2814 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2818 /*********************************************************************
2823 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2825 if (!(es
->style
& ES_MULTILINE
))
2828 HeapFree(es
->heap
, 0, es
->tabs
);
2829 es
->tabs_count
= count
;
2833 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2834 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2840 /*********************************************************************
2845 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2847 if (!(es
->style
& ES_MULTILINE
))
2850 HeapFree(es
->heap
, 0, es
->tabs
);
2851 es
->tabs_count
= count
;
2856 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2857 for (i
= 0 ; i
< count
; i
++)
2858 es
->tabs
[i
] = *tabs
++;
2864 /*********************************************************************
2866 * EM_SETWORDBREAKPROC
2869 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2871 if (es
->word_break_proc32A
== wbp
)
2874 es
->word_break_proc32A
= wbp
;
2875 es
->word_break_proc16
= NULL
;
2876 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2877 EDIT_BuildLineDefs_ML(wnd
, es
);
2878 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2883 /*********************************************************************
2885 * EM_SETWORDBREAKPROC16
2888 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2890 if (es
->word_break_proc16
== wbp
)
2893 es
->word_break_proc32A
= NULL
;
2894 es
->word_break_proc16
= wbp
;
2895 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2896 EDIT_BuildLineDefs_ML(wnd
, es
);
2897 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2902 /*********************************************************************
2907 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2909 INT ulength
= lstrlenA(es
->undo_text
);
2910 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2912 lstrcpyA(utext
, es
->undo_text
);
2914 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2915 es
->undo_insert_count
, utext
);
2917 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2918 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2919 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2920 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2921 HeapFree(es
->heap
, 0, utext
);
2923 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2924 es
->undo_insert_count
, es
->undo_text
);
2926 if (es
->flags
& EF_UPDATE
) {
2927 es
->flags
&= ~EF_UPDATE
;
2928 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2935 /*********************************************************************
2940 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2942 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
2945 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2946 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2949 if (es
->style
& ES_MULTILINE
) {
2950 if (es
->style
& ES_READONLY
) {
2951 EDIT_MoveHome(wnd
, es
, FALSE
);
2952 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2954 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2955 if (es
->flags
& EF_UPDATE
) {
2956 es
->flags
&= ~EF_UPDATE
;
2957 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2963 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2965 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2966 if (es
->flags
& EF_UPDATE
) {
2967 es
->flags
&= ~EF_UPDATE
;
2968 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2973 if (!(es
->style
& ES_READONLY
) && !control
) {
2974 if (es
->selection_start
!= es
->selection_end
)
2975 EDIT_WM_Clear(wnd
, es
);
2977 /* delete character left of caret */
2978 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
2979 EDIT_MoveBackward(wnd
, es
, TRUE
);
2980 EDIT_WM_Clear(wnd
, es
);
2985 SendMessageA(wnd
->hwndSelf
, WM_COPY
, 0, 0);
2988 SendMessageA(wnd
->hwndSelf
, WM_PASTE
, 0, 0);
2991 SendMessageA(wnd
->hwndSelf
, WM_CUT
, 0, 0);
2995 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2999 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
3000 if (es
->flags
& EF_UPDATE
) {
3001 es
->flags
&= ~EF_UPDATE
;
3002 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3010 /*********************************************************************
3015 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3017 if (code
|| control
)
3022 EDIT_EM_Undo(wnd
, es
);
3025 EDIT_WM_Cut(wnd
, es
);
3028 EDIT_WM_Copy(wnd
, es
);
3031 EDIT_WM_Paste(wnd
, es
);
3034 EDIT_WM_Clear(wnd
, es
);
3037 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3038 EDIT_EM_ScrollCaret(wnd
, es
);
3041 ERR("unknown menu item, please report\n");
3047 /*********************************************************************
3051 * Note: the resource files resource/sysres_??.rc cannot define a
3052 * single popup menu. Hence we use a (dummy) menubar
3053 * containing the single popup menu as its first item.
3055 * FIXME: the message identifiers have been chosen arbitrarily,
3056 * hence we use MF_BYPOSITION.
3057 * We might as well use the "real" values (anybody knows ?)
3058 * The menu definition is in resources/sysres_??.rc.
3059 * Once these are OK, we better use MF_BYCOMMAND here
3060 * (as we do in EDIT_WM_Command()).
3063 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
3065 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3066 HMENU popup
= GetSubMenu(menu
, 0);
3067 UINT start
= es
->selection_start
;
3068 UINT end
= es
->selection_end
;
3070 ORDER_UINT(start
, end
);
3073 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
3075 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3077 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3079 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
3081 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3083 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3085 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3090 /*********************************************************************
3095 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3097 INT s
= es
->selection_start
;
3098 INT e
= es
->selection_end
;
3105 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3106 dst
= GlobalLock(hdst
);
3107 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3109 OpenClipboard(wnd
->hwndSelf
);
3111 SetClipboardData(CF_TEXT
, hdst
);
3116 /*********************************************************************
3121 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3124 * To initialize some final structure members, we call some helper
3125 * functions. However, since the EDITSTATE is not consistent (i.e.
3126 * not fully initialized), we should be very careful which
3127 * functions can be called, and in what order.
3129 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3130 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3132 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3133 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3134 /* if we insert text to the editline, the text scrolls out
3135 * of the window, as the caret is placed after the insert
3136 * pos normally; thus we reset es->selection... to 0 and
3139 es
->selection_start
= es
->selection_end
= 0;
3140 EDIT_EM_ScrollCaret(wnd
, es
);
3141 if (es
->flags
& EF_UPDATE
) {
3142 es
->flags
&= ~EF_UPDATE
;
3143 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3150 /*********************************************************************
3155 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3158 while (LocalUnlock(es
->hloc32
)) ;
3159 LocalFree(es
->hloc32
);
3162 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3163 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3165 HeapDestroy(es
->heap
);
3166 HeapFree(GetProcessHeap(), 0, es
);
3167 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3171 /*********************************************************************
3176 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3181 if ( VERSION_AppWinVer() >= 0x40000 &&(
3182 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3183 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3185 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3188 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3190 GetClientRect(wnd
->hwndSelf
, &rc
);
3191 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3192 GetClipBox(dc
, &rc
);
3194 * FIXME: specs say that we should UnrealizeObject() the brush,
3195 * but the specs of UnrealizeObject() say that we shouldn't
3196 * unrealize a stock object. The default brush that
3197 * DefWndProc() returns is ... a stock object.
3199 FillRect(dc
, &rc
, brush
);
3204 /*********************************************************************
3209 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3211 lstrcpynA(text
, es
->text
, count
);
3212 return strlen(text
);
3216 /*********************************************************************
3220 * 16 bit notepad needs this. Actually it is not _our_ hack,
3221 * it is notepad's. Notepad is sending us scrollbar messages with
3222 * undocumented parameters without us even having a scrollbar ... !?!?
3225 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3228 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3231 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3232 ERR("hacked WM_HSCROLL handler invoked\n");
3233 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3234 ERR(" (this message is only displayed once per edit control)\n");
3235 es
->flags
|= EF_HSCROLL_HACK
;
3241 dx
= -es
->char_width
;
3244 if (es
->x_offset
< es
->text_width
)
3245 dx
= es
->char_width
;
3249 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3252 if (es
->x_offset
< es
->text_width
)
3253 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3260 if (es
->x_offset
< es
->text_width
)
3261 dx
= es
->text_width
- es
->x_offset
;
3264 es
->flags
|= EF_HSCROLL_TRACK
;
3265 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3267 case SB_THUMBPOSITION
:
3268 es
->flags
&= ~EF_HSCROLL_TRACK
;
3269 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3270 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3276 * FIXME : the next two are undocumented !
3277 * Are we doing the right thing ?
3278 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3279 * although it's also a regular control message.
3282 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3284 case EM_LINESCROLL16
:
3289 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3293 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3298 /*********************************************************************
3303 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3308 if (!(es
->style
& ES_MULTILINE
))
3311 if (!(es
->style
& ES_AUTOHSCROLL
))
3314 if (!(es
->style
& WS_HSCROLL
))
3315 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3318 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3322 dx
= -es
->char_width
;
3325 if (es
->x_offset
< es
->text_width
)
3326 dx
= es
->char_width
;
3330 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3333 if (es
->x_offset
< es
->text_width
)
3334 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3341 if (es
->x_offset
< es
->text_width
)
3342 dx
= es
->text_width
- es
->x_offset
;
3345 es
->flags
|= EF_HSCROLL_TRACK
;
3346 dx
= pos
- es
->x_offset
;
3348 case SB_THUMBPOSITION
:
3349 es
->flags
&= ~EF_HSCROLL_TRACK
;
3350 if (!(dx
= pos
- es
->x_offset
)) {
3351 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3352 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3359 ERR("undocumented WM_HSCROLL parameter, please report\n");
3363 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3368 /*********************************************************************
3373 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3377 /********************************************************************
3378 * This if statement used to check to see if the parent of the
3379 * edit control was a 'combobox' by comparing the ATOM of the parent
3380 * to a table of internal window control ATOMs. However, this check
3381 * would fail if the parent was a superclassed combobox (Although
3382 * having the same basic functionality of a combobox, it has a
3383 * different name and ATOM, thus defeating this check.)
3385 * The safe way to determine if the parent is a combobox is to send it
3386 * a message only a combo box would understand. I send it a message
3387 * CB_GETCOUNT, if I get 0 then the parent is not a combobox -
3388 * return FALSE. If I get > 0, then the parent IS a combobox
3389 * (or sub/super classed derrivative thereof)
3390 ********************************************************************/
3392 ((SendMessageA(wnd
->parent
->hwndSelf
, CB_GETCOUNT
, 0, 0)) > 0) &&
3393 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))
3396 HWND hCombo
= wnd
->parent
->hwndSelf
;
3397 BOOL bUIFlip
= TRUE
;
3399 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3400 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3403 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3405 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3406 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3410 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3412 /* make sure ComboLBox pops up */
3413 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3414 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3415 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3418 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3419 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3421 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3422 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3424 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3433 /*********************************************************************
3437 * Handling of special keys that don't produce a WM_CHAR
3438 * (i.e. non-printable keys) & Backspace & Delete
3441 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3446 if (GetKeyState(VK_MENU
) & 0x8000)
3449 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3450 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3455 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3461 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3462 EDIT_MoveUp_ML(wnd
, es
, shift
);
3465 EDIT_MoveWordBackward(wnd
, es
, shift
);
3467 EDIT_MoveBackward(wnd
, es
, shift
);
3470 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3474 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3475 EDIT_MoveDown_ML(wnd
, es
, shift
);
3477 EDIT_MoveWordForward(wnd
, es
, shift
);
3479 EDIT_MoveForward(wnd
, es
, shift
);
3482 EDIT_MoveHome(wnd
, es
, shift
);
3485 EDIT_MoveEnd(wnd
, es
, shift
);
3488 if (es
->style
& ES_MULTILINE
)
3489 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3492 if (es
->style
& ES_MULTILINE
)
3493 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3496 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3497 if (es
->selection_start
!= es
->selection_end
) {
3499 EDIT_WM_Cut(wnd
, es
);
3501 EDIT_WM_Clear(wnd
, es
);
3504 /* delete character left of caret */
3505 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3506 EDIT_MoveBackward(wnd
, es
, TRUE
);
3507 EDIT_WM_Clear(wnd
, es
);
3508 } else if (control
) {
3509 /* delete to end of line */
3510 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3511 EDIT_MoveEnd(wnd
, es
, TRUE
);
3512 EDIT_WM_Clear(wnd
, es
);
3514 /* delete character right of caret */
3515 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3516 EDIT_MoveForward(wnd
, es
, TRUE
);
3517 EDIT_WM_Clear(wnd
, es
);
3524 if (!(es
->style
& ES_READONLY
))
3525 EDIT_WM_Paste(wnd
, es
);
3527 EDIT_WM_Copy(wnd
, es
);
3530 /* If the edit doesn't want the return send a message to the default object */
3531 if(!(es
->style
& ES_WANTRETURN
))
3533 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
3534 DWORD dw
= SendMessage16( hwndParent
, DM_GETDEFID
, 0, 0 );
3535 if (HIWORD(dw
) == DC_HASDEFID
)
3537 SendMessageA( hwndParent
, WM_COMMAND
,
3538 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3539 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3548 /*********************************************************************
3553 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3555 es
->flags
&= ~EF_FOCUSED
;
3557 if(!(es
->style
& ES_NOHIDESEL
))
3558 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3559 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3564 /*********************************************************************
3568 * The caret position has been set on the WM_LBUTTONDOWN message
3571 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3574 INT e
= es
->selection_end
;
3579 if (!(es
->flags
& EF_FOCUSED
))
3582 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3583 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3584 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3585 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3586 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3587 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3588 EDIT_EM_ScrollCaret(wnd
, es
);
3593 /*********************************************************************
3598 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3603 if (!(es
->flags
& EF_FOCUSED
))
3606 es
->bCaptureState
= TRUE
;
3607 SetCapture(wnd
->hwndSelf
);
3608 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3609 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3610 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3611 EDIT_EM_ScrollCaret(wnd
, es
);
3612 es
->region_posx
= es
->region_posy
= 0;
3613 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3618 /*********************************************************************
3623 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3625 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3626 KillTimer(wnd
->hwndSelf
, 0);
3629 es
->bCaptureState
= FALSE
;
3634 /*********************************************************************
3639 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
)
3641 SendMessageA(wnd
->hwndSelf
,WM_PASTE
,0,0);
3646 /*********************************************************************
3651 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3657 if (GetCapture() != wnd
->hwndSelf
)
3661 * FIXME: gotta do some scrolling if outside client
3662 * area. Maybe reset the timer ?
3665 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3666 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3667 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3668 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3669 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3674 /*********************************************************************
3679 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3683 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3685 *(EDITSTATE
**)wnd
->wExtra
= es
;
3688 * Note: since the EDITSTATE has not been fully initialized yet,
3689 * we can't use any API calls that may send
3690 * WM_XXX messages before WM_NCCREATE is completed.
3693 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3695 es
->style
= cs
->style
;
3697 es
->bEnableState
= !(cs
->style
& WS_DISABLED
);
3700 * In Win95 look and feel, the WS_BORDER style is replaced by the
3701 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3702 * control a non client area.
3704 if (TWEAK_WineLook
!= WIN31_LOOK
)
3706 if (es
->style
& WS_BORDER
)
3708 es
->style
&= ~WS_BORDER
;
3709 wnd
->dwStyle
&= ~WS_BORDER
;
3710 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3715 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3716 wnd
->dwStyle
&= ~WS_BORDER
;
3719 if (es
->style
& ES_MULTILINE
) {
3720 es
->buffer_size
= BUFSTART_MULTI
;
3721 es
->buffer_limit
= BUFLIMIT_MULTI
;
3722 if (es
->style
& WS_VSCROLL
)
3723 es
->style
|= ES_AUTOVSCROLL
;
3724 if (es
->style
& WS_HSCROLL
)
3725 es
->style
|= ES_AUTOHSCROLL
;
3726 es
->style
&= ~ES_PASSWORD
;
3727 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3728 if (es
->style
& ES_RIGHT
)
3729 es
->style
&= ~ES_CENTER
;
3730 es
->style
&= ~WS_HSCROLL
;
3731 es
->style
&= ~ES_AUTOHSCROLL
;
3734 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3735 es
->style
|= ES_AUTOVSCROLL
;
3737 es
->buffer_size
= BUFSTART_SINGLE
;
3738 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3739 es
->style
&= ~ES_CENTER
;
3740 es
->style
&= ~ES_RIGHT
;
3741 es
->style
&= ~WS_HSCROLL
;
3742 es
->style
&= ~WS_VSCROLL
;
3743 es
->style
&= ~ES_AUTOVSCROLL
;
3744 es
->style
&= ~ES_WANTRETURN
;
3745 if (es
->style
& ES_UPPERCASE
) {
3746 es
->style
&= ~ES_LOWERCASE
;
3747 es
->style
&= ~ES_NUMBER
;
3748 } else if (es
->style
& ES_LOWERCASE
)
3749 es
->style
&= ~ES_NUMBER
;
3750 if (es
->style
& ES_PASSWORD
)
3751 es
->password_char
= '*';
3753 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3754 es
->style
|= ES_AUTOHSCROLL
;
3756 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3758 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3759 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3761 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3763 if (es
->style
& ES_MULTILINE
)
3764 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3771 /*********************************************************************
3776 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3785 BOOL rev
= es
->bEnableState
&&
3786 ((es
->flags
& EF_FOCUSED
) ||
3787 (es
->style
& ES_NOHIDESEL
));
3789 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3792 if(es
->style
& WS_BORDER
) {
3793 GetClientRect(wnd
->hwndSelf
, &rc
);
3794 if(es
->style
& ES_MULTILINE
) {
3795 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3796 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3798 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3800 IntersectClipRect(dc
, es
->format_rect
.left
,
3801 es
->format_rect
.top
,
3802 es
->format_rect
.right
,
3803 es
->format_rect
.bottom
);
3804 if (es
->style
& ES_MULTILINE
) {
3805 GetClientRect(wnd
->hwndSelf
, &rc
);
3806 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3809 old_font
= SelectObject(dc
, es
->font
);
3810 if ( VERSION_AppWinVer() >= 0x40000 &&(
3811 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3812 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3814 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3816 if (!es
->bEnableState
)
3817 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3818 GetClipBox(dc
, &rcRgn
);
3819 if (es
->style
& ES_MULTILINE
) {
3820 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3821 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3822 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3823 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3824 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3827 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3828 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3829 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3832 SelectObject(dc
, old_font
);
3833 if (es
->flags
& EF_FOCUSED
)
3834 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3835 es
->flags
& EF_AFTER_WRAP
);
3837 EndPaint(wnd
->hwndSelf
, &ps
);
3838 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3839 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3841 si
.cbSize
= sizeof(SCROLLINFO
);
3842 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3844 si
.nMax
= es
->line_count
+ vlc
- 2;
3846 si
.nPos
= es
->y_offset
;
3847 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3849 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3851 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3852 si
.cbSize
= sizeof(SCROLLINFO
);
3853 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3855 si
.nMax
= es
->text_width
+ fw
- 1;
3857 si
.nPos
= es
->x_offset
;
3858 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3863 /*********************************************************************
3868 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3873 OpenClipboard(wnd
->hwndSelf
);
3874 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3875 src
= (LPSTR
)GlobalLock(hsrc
);
3876 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3879 if (es
->flags
& EF_UPDATE
) {
3880 es
->flags
&= ~EF_UPDATE
;
3881 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3888 /*********************************************************************
3893 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3895 es
->flags
|= EF_FOCUSED
;
3896 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3897 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3898 es
->flags
& EF_AFTER_WRAP
);
3899 if(!(es
->style
& ES_NOHIDESEL
))
3900 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3901 ShowCaret(wnd
->hwndSelf
);
3902 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3906 /*********************************************************************
3910 * With Win95 look the margins are set to default font value unless
3911 * the system font (font == 0) is being set, in which case they are left
3915 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3923 dc
= GetDC(wnd
->hwndSelf
);
3925 old_font
= SelectObject(dc
, font
);
3926 GetTextMetricsA(dc
, &tm
);
3927 es
->line_height
= tm
.tmHeight
;
3928 es
->char_width
= tm
.tmAveCharWidth
;
3930 SelectObject(dc
, old_font
);
3931 ReleaseDC(wnd
->hwndSelf
, dc
);
3932 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3933 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3934 EC_USEFONTINFO
, EC_USEFONTINFO
);
3936 /* Force the recalculation of the format rect for each font change */
3937 GetClientRect(wnd
->hwndSelf
, &r
);
3938 EDIT_SetRectNP(wnd
, es
, &r
);
3940 if (es
->style
& ES_MULTILINE
)
3941 EDIT_BuildLineDefs_ML(wnd
, es
);
3944 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3945 if (es
->flags
& EF_FOCUSED
) {
3947 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3948 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3949 es
->flags
& EF_AFTER_WRAP
);
3950 ShowCaret(wnd
->hwndSelf
);
3955 /*********************************************************************
3960 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3961 * The modified flag is reset. No notifications are sent.
3963 * For single-line controls, reception of WM_SETTEXT triggers:
3964 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3967 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3969 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3971 TRACE("\t'%s'\n", text
);
3972 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3974 TRACE("\t<NULL>\n");
3975 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3978 if (es
->style
& ES_MULTILINE
) {
3979 es
->flags
&= ~EF_UPDATE
;
3981 es
->flags
|= EF_UPDATE
;
3983 es
->flags
&= ~EF_MODIFIED
;
3984 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3985 EDIT_EM_ScrollCaret(wnd
, es
);
3987 if (es
->flags
& EF_UPDATE
) {
3988 es
->flags
&= ~EF_UPDATE
;
3989 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3994 /*********************************************************************
3999 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4001 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4003 SetRect(&rc
, 0, 0, width
, height
);
4004 EDIT_SetRectNP(wnd
, es
, &rc
);
4005 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4010 /*********************************************************************
4015 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4017 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4018 if (EDIT_EM_CanUndo(wnd
, es
))
4019 EDIT_EM_Undo(wnd
, es
);
4021 } else if (key
== VK_UP
|| key
== VK_DOWN
)
4022 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
4024 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4028 /*********************************************************************
4033 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
4035 if (es
->region_posx
< 0) {
4036 EDIT_MoveBackward(wnd
, es
, TRUE
);
4037 } else if (es
->region_posx
> 0) {
4038 EDIT_MoveForward(wnd
, es
, TRUE
);
4041 * FIXME: gotta do some vertical scrolling here, like
4042 * EDIT_EM_LineScroll(wnd, 0, 1);
4047 /*********************************************************************
4051 * 16 bit notepad needs this. Actually it is not _our_ hack,
4052 * it is notepad's. Notepad is sending us scrollbar messages with
4053 * undocumented parameters without us even having a scrollbar ... !?!?
4056 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4061 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
4062 ERR("hacked WM_VSCROLL handler invoked\n");
4063 ERR(" if you are _not_ running 16 bit notepad, please report\n");
4064 ERR(" (this message is only displayed once per edit control)\n");
4065 es
->flags
|= EF_VSCROLL_HACK
;
4073 EDIT_EM_Scroll(wnd
, es
, action
);
4079 dy
= es
->line_count
- 1 - es
->y_offset
;
4082 es
->flags
|= EF_VSCROLL_TRACK
;
4083 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
4085 case SB_THUMBPOSITION
:
4086 es
->flags
&= ~EF_VSCROLL_TRACK
;
4087 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
4088 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4094 * FIXME : the next two are undocumented !
4095 * Are we doing the right thing ?
4096 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4097 * although it's also a regular control message.
4100 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
4102 case EM_LINESCROLL16
:
4107 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4111 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4116 /*********************************************************************
4121 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4125 if (!(es
->style
& ES_MULTILINE
))
4128 if (!(es
->style
& ES_AUTOVSCROLL
))
4131 if (!(es
->style
& WS_VSCROLL
))
4132 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4140 EDIT_EM_Scroll(wnd
, es
, action
);
4147 dy
= es
->line_count
- 1 - es
->y_offset
;
4150 es
->flags
|= EF_VSCROLL_TRACK
;
4151 dy
= pos
- es
->y_offset
;
4153 case SB_THUMBPOSITION
:
4154 es
->flags
&= ~EF_VSCROLL_TRACK
;
4155 if (!(dy
= pos
- es
->y_offset
)) {
4156 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4157 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4164 ERR("undocumented WM_VSCROLL action %d, please report\n",
4169 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4174 /*********************************************************************
4179 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
)
4181 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
4183 /* EF_UPDATE will be turned off in paint */
4184 if (es
->flags
& EF_UPDATE
)
4185 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
4187 InvalidateRect(wnd
->hwndSelf
, rc
, bErase
);