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 */
103 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
105 * only for multi line controls
107 INT lock_count
; /* amount of re-entries in the EditWndProc */
110 INT text_width
; /* width of the widest line in pixels */
111 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
112 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
113 HLOCAL hloc32
; /* for controls receiving EM_GETHANDLE */
117 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
118 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
120 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
121 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
123 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
124 do {TRACE("notification " str " sent to hwnd=%08x\n", \
125 (UINT)(hwnd));} while(0)
127 /* used for disabled or read-only edit control */
128 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
129 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
130 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
131 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
132 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
133 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
134 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
135 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
136 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
137 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
138 (LPARAM)(wnd)->hwndSelf);} while(0)
139 #define DPRINTF_EDIT_MSG16(str) \
141 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
142 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
143 #define DPRINTF_EDIT_MSG32(str) \
145 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
146 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
148 /*********************************************************************
155 * These functions have trivial implementations
156 * We still like to call them internally
157 * "static inline" makes them more like macro's
159 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
160 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
161 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
162 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
165 * Helper functions only valid for one type of control
167 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
168 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
169 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
170 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
171 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
172 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
174 * Helper functions valid for both single line _and_ multi line controls
176 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
177 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
178 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
179 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
180 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
181 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
182 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
183 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
184 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
185 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
186 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
187 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
190 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
191 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
192 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
193 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
194 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
195 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
197 * EM_XXX message handlers
199 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
200 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
201 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
202 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
203 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
204 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
205 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
206 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
207 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
208 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
209 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
210 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
211 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
212 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
213 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
214 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
215 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
216 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
217 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
218 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
219 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
220 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
221 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
222 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
223 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
224 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
226 * WM_XXX message handlers
228 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
229 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
230 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
231 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
232 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
233 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
234 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
235 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
236 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
237 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
238 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
239 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
240 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
241 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
242 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
);
243 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
244 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
245 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
246 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
247 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
248 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
249 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
250 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
251 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
252 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
253 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
254 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
);
257 /*********************************************************************
262 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
264 return (es
->undo_insert_count
|| strlen(es
->undo_text
));
268 /*********************************************************************
273 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
275 es
->undo_insert_count
= 0;
276 *es
->undo_text
= '\0';
280 /*********************************************************************
285 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
287 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
289 if (es
->flags
& EF_UPDATE
) {
290 es
->flags
&= ~EF_UPDATE
;
291 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
296 /*********************************************************************
301 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
303 EDIT_WM_Copy(wnd
, es
);
304 EDIT_WM_Clear(wnd
, es
);
308 /*********************************************************************
312 * The messages are in the order of the actual integer values
313 * (which can be found in include/windows.h)
314 * Whereever possible the 16 bit versions are converted to
315 * the 32 bit ones, so that we can 'fall through' to the
316 * helper functions. These are mostly 32 bit (with a few
317 * exceptions, clearly indicated by a '16' extension to their
321 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
322 WPARAM wParam
, LPARAM lParam
)
324 WND
*wnd
= WIN_FindWndPtr(hwnd
);
325 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
330 DPRINTF_EDIT_MSG32("WM_DESTROY");
331 EDIT_WM_Destroy(wnd
, es
);
336 DPRINTF_EDIT_MSG32("WM_NCCREATE");
337 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
343 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
348 EDIT_LockBuffer(wnd
, es
);
351 DPRINTF_EDIT_MSG16("EM_GETSEL");
356 DPRINTF_EDIT_MSG32("EM_GETSEL");
357 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
361 DPRINTF_EDIT_MSG16("EM_SETSEL");
362 if (SLOWORD(lParam
) == -1)
363 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
365 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
367 EDIT_EM_ScrollCaret(wnd
, es
);
371 DPRINTF_EDIT_MSG32("EM_SETSEL");
372 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
373 EDIT_EM_ScrollCaret(wnd
, es
);
378 DPRINTF_EDIT_MSG16("EM_GETRECT");
380 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
383 DPRINTF_EDIT_MSG32("EM_GETRECT");
385 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
389 DPRINTF_EDIT_MSG16("EM_SETRECT");
390 if ((es
->style
& ES_MULTILINE
) && lParam
) {
392 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
393 EDIT_SetRectNP(wnd
, es
, &rc
);
394 EDIT_UpdateText(wnd
, NULL
, TRUE
);
398 DPRINTF_EDIT_MSG32("EM_SETRECT");
399 if ((es
->style
& ES_MULTILINE
) && lParam
) {
400 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
401 EDIT_UpdateText(wnd
, NULL
, TRUE
);
406 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
407 if ((es
->style
& ES_MULTILINE
) && lParam
) {
409 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
410 EDIT_SetRectNP(wnd
, es
, &rc
);
414 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
415 if ((es
->style
& ES_MULTILINE
) && lParam
)
416 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
420 DPRINTF_EDIT_MSG16("EM_SCROLL");
423 DPRINTF_EDIT_MSG32("EM_SCROLL");
424 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
427 case EM_LINESCROLL16
:
428 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
429 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
430 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
433 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
434 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
437 case EM_SCROLLCARET16
:
438 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
441 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
442 EDIT_EM_ScrollCaret(wnd
, es
);
447 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
450 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
451 result
= ((es
->flags
& EF_MODIFIED
) != 0);
455 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
458 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
460 es
->flags
|= EF_MODIFIED
;
462 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
465 case EM_GETLINECOUNT16
:
466 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
468 case EM_GETLINECOUNT
:
469 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
470 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
474 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
475 if ((INT16
)wParam
== -1)
479 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
480 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
484 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
485 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
488 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
489 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
493 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
494 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
497 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
498 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
502 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
505 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
506 result
= EDIT_EM_GetThumb(wnd
, es
);
509 /* messages 0x00bf and 0x00c0 missing from specs */
512 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
515 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
516 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
520 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
523 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
524 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
527 case EM_LINELENGTH16
:
528 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
531 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
532 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
535 case EM_REPLACESEL16
:
536 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
537 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
540 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
541 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
542 if (es
->flags
& EF_UPDATE
) {
543 es
->flags
&= ~EF_UPDATE
;
544 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
549 /* message 0x00c3 missing from specs */
552 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
555 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
556 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
560 DPRINTF_EDIT_MSG16("EM_GETLINE");
561 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
564 DPRINTF_EDIT_MSG32("EM_GETLINE");
565 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
569 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
571 case EM_SETLIMITTEXT
:
572 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
573 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
577 DPRINTF_EDIT_MSG16("EM_CANUNDO");
580 DPRINTF_EDIT_MSG32("EM_CANUNDO");
581 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
585 DPRINTF_EDIT_MSG16("EM_UNDO");
590 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
591 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
595 DPRINTF_EDIT_MSG16("EM_FMTLINES");
598 DPRINTF_EDIT_MSG32("EM_FMTLINES");
599 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
602 case EM_LINEFROMCHAR16
:
603 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
605 case EM_LINEFROMCHAR
:
606 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
607 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
610 /* message 0x00ca missing from specs */
613 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
616 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
617 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
620 case EM_SETTABSTOPS16
:
621 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
622 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
625 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
626 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
629 case EM_SETPASSWORDCHAR16
:
630 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
632 case EM_SETPASSWORDCHAR
:
633 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
634 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
637 case EM_EMPTYUNDOBUFFER16
:
638 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
640 case EM_EMPTYUNDOBUFFER
:
641 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
642 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
645 case EM_GETFIRSTVISIBLELINE16
:
646 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
647 result
= es
->y_offset
;
649 case EM_GETFIRSTVISIBLELINE
:
650 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
651 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
654 case EM_SETREADONLY16
:
655 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
658 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
660 wnd
->dwStyle
|= ES_READONLY
;
661 es
->style
|= ES_READONLY
;
663 wnd
->dwStyle
&= ~ES_READONLY
;
664 es
->style
&= ~ES_READONLY
;
669 case EM_SETWORDBREAKPROC16
:
670 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
671 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
673 case EM_SETWORDBREAKPROC
:
674 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
675 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
678 case EM_GETWORDBREAKPROC16
:
679 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
680 result
= (LRESULT
)es
->word_break_proc16
;
682 case EM_GETWORDBREAKPROC
:
683 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
684 result
= (LRESULT
)es
->word_break_proc32A
;
687 case EM_GETPASSWORDCHAR16
:
688 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
690 case EM_GETPASSWORDCHAR
:
691 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
692 result
= es
->password_char
;
695 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
698 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
699 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
703 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
704 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
707 case EM_GETLIMITTEXT
:
708 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
709 result
= es
->buffer_limit
;
713 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
714 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
718 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
719 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
723 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
724 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
726 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
728 int vk
= (int)((LPMSG
)lParam
)->wParam
;
730 if ((wnd
->dwStyle
& ES_WANTRETURN
) && vk
== VK_RETURN
)
732 result
|= DLGC_WANTMESSAGE
;
734 else if (es
->hwndListBox
&& (vk
== VK_RETURN
|| vk
== VK_ESCAPE
))
736 if (SendMessageA(wnd
->parent
->hwndSelf
, CB_GETDROPPEDSTATE
, 0, 0))
737 result
|= DLGC_WANTMESSAGE
;
743 DPRINTF_EDIT_MSG32("WM_CHAR");
744 if (((CHAR
)wParam
== VK_RETURN
|| (CHAR
)wParam
== VK_ESCAPE
) && es
->hwndListBox
)
746 if (SendMessageA(wnd
->parent
->hwndSelf
, CB_GETDROPPEDSTATE
, 0, 0))
747 SendMessageA(wnd
->parent
->hwndSelf
, WM_KEYDOWN
, wParam
, 0);
750 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
754 DPRINTF_EDIT_MSG32("WM_CLEAR");
755 EDIT_WM_Clear(wnd
, es
);
759 DPRINTF_EDIT_MSG32("WM_COMMAND");
760 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
764 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
765 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
769 DPRINTF_EDIT_MSG32("WM_COPY");
770 EDIT_WM_Copy(wnd
, es
);
774 DPRINTF_EDIT_MSG32("WM_CREATE");
775 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
779 DPRINTF_EDIT_MSG32("WM_CUT");
780 EDIT_WM_Cut(wnd
, es
);
784 DPRINTF_EDIT_MSG32("WM_ENABLE");
785 es
->bEnableState
= (BOOL
) wParam
;
786 EDIT_UpdateText(wnd
, NULL
, TRUE
);
790 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
791 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
795 DPRINTF_EDIT_MSG32("WM_GETFONT");
796 result
= (LRESULT
)es
->font
;
800 DPRINTF_EDIT_MSG32("WM_GETTEXT");
801 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
804 case WM_GETTEXTLENGTH
:
805 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
806 result
= strlen(es
->text
);
810 DPRINTF_EDIT_MSG32("WM_HSCROLL");
811 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
815 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
816 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
820 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
821 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
824 case WM_LBUTTONDBLCLK
:
825 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
826 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
830 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
831 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
835 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
836 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
840 DPRINTF_EDIT_MSG32("WM_MBUTTONDOWN");
841 result
= EDIT_WM_MButtonDown(wnd
);
844 case WM_MOUSEACTIVATE
:
846 * FIXME: maybe DefWindowProc() screws up, but it seems that
847 * modeless dialog boxes need this. If we don't do this, the focus
848 * will _not_ be set by DefWindowProc() for edit controls in a
849 * modeless dialog box ???
851 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
852 SetFocus(wnd
->hwndSelf
);
853 result
= MA_ACTIVATE
;
858 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
860 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
864 DPRINTF_EDIT_MSG32("WM_PAINT");
865 EDIT_WM_Paint(wnd
, es
, wParam
);
869 DPRINTF_EDIT_MSG32("WM_PASTE");
870 EDIT_WM_Paste(wnd
, es
);
874 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
875 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
879 DPRINTF_EDIT_MSG32("WM_SETFONT");
880 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
884 DPRINTF_EDIT_MSG32("WM_SETTEXT");
885 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
890 DPRINTF_EDIT_MSG32("WM_SIZE");
891 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
895 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
896 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
900 DPRINTF_EDIT_MSG32("WM_TIMER");
901 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
905 DPRINTF_EDIT_MSG32("WM_VSCROLL");
906 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
911 short gcWheelDelta
= 0;
912 UINT pulScrollLines
= 3;
913 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
915 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
916 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
919 gcWheelDelta
-= (short) HIWORD(wParam
);
920 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
922 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
923 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
924 result
= EDIT_EM_LineScroll(wnd
, es
, 0, cLineScroll
);
929 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
932 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
934 WIN_ReleaseWndPtr(wnd
);
940 /*********************************************************************
942 * EDIT_BuildLineDefs_ML
944 * Build linked list of text lines.
945 * Lines can end with '\0' (last line), a character (if it is wrapped),
946 * a soft return '\r\r\n' or a hard return '\r\n'
949 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
955 LINEDEF
*current_def
;
956 LINEDEF
**previous_next
;
958 current_def
= es
->first_line_def
;
960 LINEDEF
*next_def
= current_def
->next
;
961 HeapFree(es
->heap
, 0, current_def
);
962 current_def
= next_def
;
963 } while (current_def
);
967 dc
= GetDC(wnd
->hwndSelf
);
969 old_font
= SelectObject(dc
, es
->font
);
971 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
973 previous_next
= &es
->first_line_def
;
975 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
976 current_def
->next
= NULL
;
979 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
984 current_def
->ending
= END_0
;
985 current_def
->net_length
= strlen(start
);
986 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
987 current_def
->ending
= END_SOFT
;
988 current_def
->net_length
= cp
- start
- 1;
990 current_def
->ending
= END_HARD
;
991 current_def
->net_length
= cp
- start
;
993 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
994 start
, current_def
->net_length
,
995 es
->tabs_count
, es
->tabs
));
996 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
997 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
1002 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
1003 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
1004 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
1005 start
, next
, es
->tabs_count
, es
->tabs
));
1006 } while (current_def
->width
<= fw
);
1012 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
1013 start
, next
, es
->tabs_count
, es
->tabs
));
1014 } while (current_def
->width
<= fw
);
1018 current_def
->net_length
= prev
;
1019 current_def
->ending
= END_WRAP
;
1020 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
1021 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
1023 switch (current_def
->ending
) {
1025 current_def
->length
= current_def
->net_length
+ 3;
1028 current_def
->length
= current_def
->net_length
+ 2;
1032 current_def
->length
= current_def
->net_length
;
1035 es
->text_width
= max(es
->text_width
, current_def
->width
);
1036 start
+= current_def
->length
;
1037 *previous_next
= current_def
;
1038 previous_next
= ¤t_def
->next
;
1040 } while (current_def
->ending
!= END_0
);
1042 SelectObject(dc
, old_font
);
1043 ReleaseDC(wnd
->hwndSelf
, dc
);
1047 /*********************************************************************
1049 * EDIT_CallWordBreakProc
1051 * Call appropriate WordBreakProc (internal or external).
1053 * Note: The "start" argument should always be an index refering
1054 * to es->text. The actual wordbreak proc might be
1055 * 16 bit, so we can't always pass any 32 bit LPSTR.
1056 * Hence we assume that es->text is the buffer that holds
1057 * the string under examination (we can decide this for ourselves).
1060 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1062 if (es
->word_break_proc16
) {
1063 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1064 SEGPTR segptr
= LocalLock16(hloc16
);
1065 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1066 segptr
+ start
, index
, count
, action
);
1067 LocalUnlock16(hloc16
);
1070 else if (es
->word_break_proc32A
)
1072 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1073 es
->word_break_proc32A
, es
->text
+ start
, index
,
1075 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1079 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1083 /*********************************************************************
1087 * Beware: This is not the function called on EM_CHARFROMPOS
1088 * The position _can_ be outside the formatting / client
1090 * The return value is only the character index
1093 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1099 if (es
->style
& ES_MULTILINE
) {
1100 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1102 LINEDEF
*line_def
= es
->first_line_def
;
1104 while ((line
> 0) && line_def
->next
) {
1105 line_index
+= line_def
->length
;
1106 line_def
= line_def
->next
;
1109 x
+= es
->x_offset
- es
->format_rect
.left
;
1110 if (x
>= line_def
->width
) {
1112 *after_wrap
= (line_def
->ending
== END_WRAP
);
1113 return line_index
+ line_def
->net_length
;
1117 *after_wrap
= FALSE
;
1120 dc
= GetDC(wnd
->hwndSelf
);
1122 old_font
= SelectObject(dc
, es
->font
);
1123 low
= line_index
+ 1;
1124 high
= line_index
+ line_def
->net_length
+ 1;
1125 while (low
< high
- 1)
1127 INT mid
= (low
+ high
) / 2;
1128 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1134 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1135 (line_def
->ending
== END_WRAP
));
1140 *after_wrap
= FALSE
;
1141 x
-= es
->format_rect
.left
;
1143 return es
->x_offset
;
1144 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1145 dc
= GetDC(wnd
->hwndSelf
);
1147 old_font
= SelectObject(dc
, es
->font
);
1151 INT high
= es
->x_offset
;
1152 while (low
< high
- 1)
1154 INT mid
= (low
+ high
) / 2;
1155 GetTextExtentPoint32A( dc
, text
+ mid
,
1156 es
->x_offset
- mid
, &size
);
1157 if (size
.cx
> -x
) low
= mid
;
1164 INT low
= es
->x_offset
;
1165 INT high
= strlen(es
->text
) + 1;
1166 while (low
< high
- 1)
1168 INT mid
= (low
+ high
) / 2;
1169 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1170 mid
- es
->x_offset
, &size
);
1171 if (size
.cx
> x
) high
= mid
;
1176 if (es
->style
& ES_PASSWORD
)
1177 HeapFree(es
->heap
, 0 ,text
);
1180 SelectObject(dc
, old_font
);
1181 ReleaseDC(wnd
->hwndSelf
, dc
);
1186 /*********************************************************************
1190 * adjusts the point to be within the formatting rectangle
1191 * (so CharFromPos returns the nearest _visible_ character)
1194 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1196 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1197 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1201 /*********************************************************************
1205 * Calculates the bounding rectangle for a line from a starting
1206 * column to an ending column.
1209 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1211 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1213 if (es
->style
& ES_MULTILINE
)
1214 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1216 rc
->top
= es
->format_rect
.top
;
1217 rc
->bottom
= rc
->top
+ es
->line_height
;
1218 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1219 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1223 /*********************************************************************
1225 * EDIT_GetPasswordPointer_SL
1227 * note: caller should free the (optionally) allocated buffer
1230 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1232 if (es
->style
& ES_PASSWORD
) {
1233 INT len
= strlen(es
->text
);
1234 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1235 RtlFillMemory(text
, len
, es
->password_char
);
1243 /*********************************************************************
1247 * This acts as a LOCAL_Lock(), but it locks only once. This way
1248 * you can call it whenever you like, without unlocking.
1251 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1254 ERR("no EDITSTATE ... please report\n");
1257 if (!(es
->style
& ES_MULTILINE
))
1261 es
->text
= LocalLock(es
->hloc32
);
1262 else if (es
->hloc16
)
1263 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1265 ERR("no buffer ... please report\n");
1273 /*********************************************************************
1275 * EDIT_SL_InvalidateText
1277 * Called from EDIT_InvalidateText().
1278 * Does the job for single-line controls only.
1281 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1286 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1287 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1288 EDIT_UpdateText(wnd
, &rc
, FALSE
);
1292 /*********************************************************************
1294 * EDIT_ML_InvalidateText
1296 * Called from EDIT_InvalidateText().
1297 * Does the job for multi-line controls only.
1300 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1302 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1303 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1304 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1313 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1316 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1317 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1318 if (sl
< es
->y_offset
) {
1322 if (el
> es
->y_offset
+ vlc
) {
1323 el
= es
->y_offset
+ vlc
;
1324 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1326 GetClientRect(wnd
->hwndSelf
, &rc1
);
1327 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1329 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1330 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1331 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1333 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1334 EDIT_EM_LineLength(wnd
, es
,
1335 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1337 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1338 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1339 for (l
= sl
+ 1 ; l
< el
; l
++) {
1340 EDIT_GetLineRect(wnd
, es
, l
, 0,
1341 EDIT_EM_LineLength(wnd
, es
,
1342 EDIT_EM_LineIndex(wnd
, es
, l
)),
1344 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1345 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1347 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1348 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1349 EDIT_UpdateText(wnd
, &rcUpdate
, FALSE
);
1354 /*********************************************************************
1356 * EDIT_InvalidateText
1358 * Invalidate the text from offset start upto, but not including,
1359 * offset end. Useful for (re)painting the selection.
1360 * Regions outside the linewidth are not invalidated.
1361 * end == -1 means end == TextLength.
1362 * start and end need not be ordered.
1365 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1371 end
= strlen(es
->text
);
1373 ORDER_INT(start
, end
);
1375 if (es
->style
& ES_MULTILINE
)
1376 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1378 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1382 /*********************************************************************
1386 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1389 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1394 if (size
<= es
->buffer_size
)
1396 if (size
> es
->buffer_limit
) {
1397 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1400 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1401 if (size
> es
->buffer_limit
)
1402 size
= es
->buffer_limit
;
1404 TRACE("trying to ReAlloc to %d+1\n", size
);
1406 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1408 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1409 es
->buffer_size
= min(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1411 es
->buffer_size
= 0;
1412 } else if (es
->hloc32
) {
1413 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1414 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1415 es
->hloc32
= hNew32
;
1416 es
->buffer_size
= min(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1418 } else if (es
->hloc16
) {
1419 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1420 TRACE("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1421 es
->hloc16
= hNew16
;
1422 es
->buffer_size
= min(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1425 if (es
->buffer_size
< size
) {
1426 EDIT_LockBuffer(wnd
, es
);
1427 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1428 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1431 EDIT_LockBuffer(wnd
, es
);
1432 TRACE("We now have %d+1\n", es
->buffer_size
);
1438 /*********************************************************************
1442 * Try to fit size + 1 bytes in the undo buffer.
1445 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1447 if (size
<= es
->undo_buffer_size
)
1449 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1451 TRACE("trying to ReAlloc to %d+1\n", size
);
1453 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1454 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1455 if (es
->undo_buffer_size
< size
) {
1456 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1465 /*********************************************************************
1470 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1472 INT e
= es
->selection_end
;
1476 if ((es
->style
& ES_MULTILINE
) && e
&&
1477 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1479 if (e
&& (es
->text
[e
- 1] == '\r'))
1483 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1484 EDIT_EM_ScrollCaret(wnd
, es
);
1488 /*********************************************************************
1492 * Only for multi line controls
1493 * Move the caret one line down, on a column with the nearest
1494 * x coordinate on the screen (might be a different column).
1497 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1499 INT s
= es
->selection_start
;
1500 INT e
= es
->selection_end
;
1501 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1502 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1503 INT x
= SLOWORD(pos
);
1504 INT y
= SHIWORD(pos
);
1506 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1509 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1510 EDIT_EM_ScrollCaret(wnd
, es
);
1514 /*********************************************************************
1519 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1521 BOOL after_wrap
= FALSE
;
1524 /* Pass a high value in x to make sure of receiving the en of the line */
1525 if (es
->style
& ES_MULTILINE
)
1526 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1527 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1529 e
= strlen(es
->text
);
1530 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1531 EDIT_EM_ScrollCaret(wnd
, es
);
1535 /*********************************************************************
1540 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1542 INT e
= es
->selection_end
;
1546 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1547 if (es
->text
[e
] == '\n')
1549 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1553 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1554 EDIT_EM_ScrollCaret(wnd
, es
);
1558 /*********************************************************************
1562 * Home key: move to beginning of line.
1565 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1569 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1570 if (es
->style
& ES_MULTILINE
)
1571 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1572 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1575 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1576 EDIT_EM_ScrollCaret(wnd
, es
);
1580 /*********************************************************************
1582 * EDIT_MovePageDown_ML
1584 * Only for multi line controls
1585 * Move the caret one page down, on a column with the nearest
1586 * x coordinate on the screen (might be a different column).
1589 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1591 INT s
= es
->selection_start
;
1592 INT e
= es
->selection_end
;
1593 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1594 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1595 INT x
= SLOWORD(pos
);
1596 INT y
= SHIWORD(pos
);
1598 e
= EDIT_CharFromPos(wnd
, es
, x
,
1599 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1603 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1604 EDIT_EM_ScrollCaret(wnd
, es
);
1608 /*********************************************************************
1610 * EDIT_MovePageUp_ML
1612 * Only for multi line controls
1613 * Move the caret one page up, on a column with the nearest
1614 * x coordinate on the screen (might be a different column).
1617 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1619 INT s
= es
->selection_start
;
1620 INT e
= es
->selection_end
;
1621 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1622 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1623 INT x
= SLOWORD(pos
);
1624 INT y
= SHIWORD(pos
);
1626 e
= EDIT_CharFromPos(wnd
, es
, x
,
1627 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1631 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1632 EDIT_EM_ScrollCaret(wnd
, es
);
1636 /*********************************************************************
1640 * Only for multi line controls
1641 * Move the caret one line up, on a column with the nearest
1642 * x coordinate on the screen (might be a different column).
1645 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1647 INT s
= es
->selection_start
;
1648 INT e
= es
->selection_end
;
1649 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1650 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1651 INT x
= SLOWORD(pos
);
1652 INT y
= SHIWORD(pos
);
1654 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1657 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1658 EDIT_EM_ScrollCaret(wnd
, es
);
1662 /*********************************************************************
1664 * EDIT_MoveWordBackward
1667 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1669 INT s
= es
->selection_start
;
1670 INT e
= es
->selection_end
;
1675 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1676 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1677 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1680 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1681 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1684 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1685 li
, e
- li
, ll
, WB_LEFT
);
1689 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1690 EDIT_EM_ScrollCaret(wnd
, es
);
1694 /*********************************************************************
1696 * EDIT_MoveWordForward
1699 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1701 INT s
= es
->selection_start
;
1702 INT e
= es
->selection_end
;
1707 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1708 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1709 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1711 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1712 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1714 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1715 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1719 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1720 EDIT_EM_ScrollCaret(wnd
, es
);
1724 /*********************************************************************
1729 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1731 INT s
= es
->selection_start
;
1732 INT e
= es
->selection_end
;
1739 if (es
->style
& ES_MULTILINE
) {
1740 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1741 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1746 TRACE("line=%d\n", line
);
1748 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1751 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1752 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1753 s
= es
->selection_start
;
1754 e
= es
->selection_end
;
1756 s
= min(li
+ ll
, max(li
, s
));
1757 e
= min(li
+ ll
, max(li
, e
));
1758 if (rev
&& (s
!= e
) &&
1759 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1760 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1761 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1762 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1764 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1768 /*********************************************************************
1773 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1783 BkColor
= GetBkColor(dc
);
1784 TextColor
= GetTextColor(dc
);
1786 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1787 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1789 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1790 if (es
->style
& ES_MULTILINE
) {
1791 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1792 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1794 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1795 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1796 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1798 if (es
->style
& ES_PASSWORD
)
1799 HeapFree(es
->heap
, 0, text
);
1802 SetBkColor(dc
, BkColor
);
1803 SetTextColor(dc
, TextColor
);
1809 /*********************************************************************
1814 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1817 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1818 INT x
= SLOWORD(res
);
1819 INT y
= SHIWORD(res
);
1821 if(x
< es
->format_rect
.left
)
1822 x
= es
->format_rect
.left
;
1823 if(x
> es
->format_rect
.right
- 2)
1824 x
= es
->format_rect
.right
- 2;
1825 if(y
> es
->format_rect
.bottom
)
1826 y
= es
->format_rect
.bottom
;
1827 if(y
< es
->format_rect
.top
)
1828 y
= es
->format_rect
.top
;
1834 /*********************************************************************
1838 * note: this is not (exactly) the handler called on EM_SETRECTNP
1839 * it is also used to set the rect of a single line control
1842 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1844 CopyRect(&es
->format_rect
, rc
);
1845 if (es
->style
& WS_BORDER
) {
1846 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1847 if(TWEAK_WineLook
== WIN31_LOOK
)
1849 es
->format_rect
.left
+= bw
;
1850 es
->format_rect
.top
+= bw
;
1851 es
->format_rect
.right
-= bw
;
1852 es
->format_rect
.bottom
-= bw
;
1854 es
->format_rect
.left
+= es
->left_margin
;
1855 es
->format_rect
.right
-= es
->right_margin
;
1856 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1857 if (es
->style
& ES_MULTILINE
)
1858 es
->format_rect
.bottom
= es
->format_rect
.top
+
1859 max(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1861 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1862 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1863 EDIT_BuildLineDefs_ML(wnd
, es
);
1867 /*********************************************************************
1872 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1875 ERR("no EDITSTATE ... please report\n");
1878 if (!(es
->style
& ES_MULTILINE
))
1880 if (!es
->lock_count
) {
1881 ERR("lock_count == 0 ... please report\n");
1885 ERR("es->text == 0 ... please report\n");
1888 if (force
|| (es
->lock_count
== 1)) {
1890 LocalUnlock(es
->hloc32
);
1892 } else if (es
->hloc16
) {
1893 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1901 /*********************************************************************
1903 * EDIT_WordBreakProc
1905 * Find the beginning of words.
1906 * Note: unlike the specs for a WordBreakProc, this function only
1907 * allows to be called without linebreaks between s[0] upto
1908 * s[count - 1]. Remember it is only called
1909 * internally, so we can decide this for ourselves.
1912 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1916 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1917 s
, index
, count
, action
);
1925 if (s
[index
] == ' ') {
1926 while (index
&& (s
[index
] == ' '))
1929 while (index
&& (s
[index
] != ' '))
1931 if (s
[index
] == ' ')
1935 while (index
&& (s
[index
] != ' '))
1937 if (s
[index
] == ' ')
1947 if (s
[index
] == ' ')
1948 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1950 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1952 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1956 case WB_ISDELIMITER
:
1957 ret
= (s
[index
] == ' ');
1960 ERR("unknown action code, please report !\n");
1967 /*********************************************************************
1971 * returns line number (not index) in high-order word of result.
1972 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1973 * to Richedit, not to the edit control. Original documentation is valid.
1974 * FIXME: do the specs mean to return -1 if outside client area or
1975 * if outside formatting rectangle ???
1978 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1986 GetClientRect(wnd
->hwndSelf
, &rc
);
1987 if (!PtInRect(&rc
, pt
))
1990 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1991 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1995 /*********************************************************************
1999 * Enable or disable soft breaks.
2001 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
2003 es
->flags
&= ~EF_USE_SOFTBRK
;
2005 es
->flags
|= EF_USE_SOFTBRK
;
2006 FIXME("soft break enabled, not implemented\n");
2012 /*********************************************************************
2016 * Hopefully this won't fire back at us.
2017 * We always start with a fixed buffer in our own heap.
2018 * However, with this message a 32 bit application requests
2019 * a handle to 32 bit moveable local heap memory, where it expects
2021 * It's a pity that from this moment on we have to use this
2022 * local heap, because applications may rely on the handle
2025 * In this function we'll try to switch to local heap.
2028 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
2034 if (!(es
->style
& ES_MULTILINE
))
2039 else if (es
->hloc16
)
2040 return (HLOCAL
)es
->hloc16
;
2042 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, strlen(es
->text
) + 1))) {
2043 ERR("could not allocate new 32 bit buffer\n");
2046 newSize
= min(LocalSize(newBuf
) - 1, es
->buffer_limit
);
2047 if (!(newText
= LocalLock(newBuf
))) {
2048 ERR("could not lock new 32 bit buffer\n");
2052 lstrcpyA(newText
, es
->text
);
2053 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2055 HeapFree(es
->heap
, 0, es
->text
);
2056 es
->hloc32
= newBuf
;
2057 es
->hloc16
= (HLOCAL16
)NULL
;
2058 es
->buffer_size
= newSize
;
2060 EDIT_LockBuffer(wnd
, es
);
2061 TRACE("switched to 32 bit local heap\n");
2067 /*********************************************************************
2071 * Hopefully this won't fire back at us.
2072 * We always start with a buffer in 32 bit linear memory.
2073 * However, with this message a 16 bit application requests
2074 * a handle of 16 bit local heap memory, where it expects to find
2076 * It's a pitty that from this moment on we have to use this
2077 * local heap, because applications may rely on the handle
2080 * In this function we'll try to switch to local heap.
2082 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2088 if (!(es
->style
& ES_MULTILINE
))
2094 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2095 if (!LocalInit16(wnd
->hInstance
, 0,
2096 GlobalSize16(wnd
->hInstance
))) {
2097 ERR("could not initialize local heap\n");
2100 TRACE("local heap initialized\n");
2102 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, strlen(es
->text
) + 1))) {
2103 ERR("could not allocate new 16 bit buffer\n");
2106 newSize
= min(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2107 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2108 ERR("could not lock new 16 bit buffer\n");
2109 LOCAL_Free(wnd
->hInstance
, newBuf
);
2112 lstrcpyA(newText
, es
->text
);
2113 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2115 HeapFree(es
->heap
, 0, es
->text
);
2116 else if (es
->hloc32
) {
2117 while (LocalFree(es
->hloc32
)) ;
2118 LocalFree(es
->hloc32
);
2120 es
->hloc32
= (HLOCAL
)NULL
;
2121 es
->hloc16
= newBuf
;
2122 es
->buffer_size
= newSize
;
2124 EDIT_LockBuffer(wnd
, es
);
2125 TRACE("switched to 16 bit buffer\n");
2131 /*********************************************************************
2136 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2142 if (es
->style
& ES_MULTILINE
) {
2143 if (line
>= es
->line_count
)
2147 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2149 len
= min(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2150 for (i
= 0 ; i
< len
; i
++) {
2155 return (LRESULT
)len
;
2159 /*********************************************************************
2164 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2166 UINT s
= es
->selection_start
;
2167 UINT e
= es
->selection_end
;
2174 return MAKELONG(s
, e
);
2178 /*********************************************************************
2182 * FIXME: is this right ? (or should it be only VSCROLL)
2183 * (and maybe only for edit controls that really have their
2184 * own scrollbars) (and maybe only for multiline controls ?)
2185 * All in all: very poorly documented
2187 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2188 * WM_VSCROLL handlers
2191 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2193 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2194 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2198 /*********************************************************************
2203 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2208 if (!(es
->style
& ES_MULTILINE
))
2210 if (index
> strlen(es
->text
))
2211 return es
->line_count
- 1;
2213 index
= min(es
->selection_start
, es
->selection_end
);
2216 line_def
= es
->first_line_def
;
2217 index
-= line_def
->length
;
2218 while ((index
>= 0) && line_def
->next
) {
2220 line_def
= line_def
->next
;
2221 index
-= line_def
->length
;
2227 /*********************************************************************
2232 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2237 if (!(es
->style
& ES_MULTILINE
))
2239 if (line
>= es
->line_count
)
2243 line_def
= es
->first_line_def
;
2245 INT index
= es
->selection_end
- line_def
->length
;
2246 while ((index
>= 0) && line_def
->next
) {
2247 line_index
+= line_def
->length
;
2248 line_def
= line_def
->next
;
2249 index
-= line_def
->length
;
2253 line_index
+= line_def
->length
;
2254 line_def
= line_def
->next
;
2262 /*********************************************************************
2267 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2271 if (!(es
->style
& ES_MULTILINE
))
2272 return strlen(es
->text
);
2275 /* get the number of remaining non-selected chars of selected lines */
2278 li
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_start
);
2279 /* # chars before start of selection area */
2280 count
= es
->selection_start
- EDIT_EM_LineIndex(wnd
, es
, li
);
2281 li
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2282 /* # chars after end of selection */
2283 count
+= EDIT_EM_LineIndex(wnd
, es
, li
) +
2284 EDIT_EM_LineLength(wnd
, es
, li
) - es
->selection_end
;
2287 line_def
= es
->first_line_def
;
2288 index
-= line_def
->length
;
2289 while ((index
>= 0) && line_def
->next
) {
2290 line_def
= line_def
->next
;
2291 index
-= line_def
->length
;
2293 return line_def
->net_length
;
2297 /*********************************************************************
2301 * FIXME: dx is in average character widths
2302 * However, we assume it is in pixels when we use this
2303 * function internally
2306 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2310 if (!(es
->style
& ES_MULTILINE
))
2313 if (-dx
> es
->x_offset
)
2315 if (dx
> es
->text_width
- es
->x_offset
)
2316 dx
= es
->text_width
- es
->x_offset
;
2317 nyoff
= max(0, es
->y_offset
+ dy
);
2318 if (nyoff
>= es
->line_count
)
2319 nyoff
= es
->line_count
- 1;
2320 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2324 GetClientRect(wnd
->hwndSelf
, &rc1
);
2325 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2326 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2327 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2328 es
->y_offset
= nyoff
;
2331 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2332 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2333 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2334 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2339 /*********************************************************************
2344 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2346 INT len
= strlen(es
->text
);
2355 index
= min(index
, len
);
2356 dc
= GetDC(wnd
->hwndSelf
);
2358 old_font
= SelectObject(dc
, es
->font
);
2359 if (es
->style
& ES_MULTILINE
) {
2360 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2361 y
= (l
- es
->y_offset
) * es
->line_height
;
2362 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2363 if (after_wrap
&& (li
== index
) && l
) {
2365 LINEDEF
*line_def
= es
->first_line_def
;
2367 line_def
= line_def
->next
;
2370 if (line_def
->ending
== END_WRAP
) {
2372 y
-= es
->line_height
;
2373 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2376 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2377 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2379 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2380 if (index
< es
->x_offset
) {
2381 GetTextExtentPoint32A(dc
, text
+ index
,
2382 es
->x_offset
- index
, &size
);
2385 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2386 index
- es
->x_offset
, &size
);
2390 if (es
->style
& ES_PASSWORD
)
2391 HeapFree(es
->heap
, 0 ,text
);
2393 x
+= es
->format_rect
.left
;
2394 y
+= es
->format_rect
.top
;
2396 SelectObject(dc
, old_font
);
2397 ReleaseDC(wnd
->hwndSelf
, dc
);
2398 return MAKELONG((INT16
)x
, (INT16
)y
);
2402 /*********************************************************************
2406 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2409 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2411 INT strl
= strlen(lpsz_replace
);
2412 INT tl
= strlen(es
->text
);
2419 s
= es
->selection_start
;
2420 e
= es
->selection_end
;
2422 if ((s
== e
) && !strl
)
2427 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2431 /* there is something to be deleted */
2433 utl
= strlen(es
->undo_text
);
2434 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2435 /* undo-buffer is extended to the right */
2436 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2437 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2438 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2439 /* undo-buffer is extended to the left */
2440 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2441 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2443 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2444 p
[i
] = (es
->text
+ s
)[i
];
2445 es
->undo_position
= s
;
2447 /* new undo-buffer */
2448 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2449 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2450 es
->undo_position
= s
;
2452 /* any deletion makes the old insertion-undo invalid */
2453 es
->undo_insert_count
= 0;
2455 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2458 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2461 /* there is an insertion */
2463 if ((s
== es
->undo_position
) ||
2464 ((es
->undo_insert_count
) &&
2465 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2467 * insertion is new and at delete position or
2468 * an extension to either left or right
2470 es
->undo_insert_count
+= strl
;
2472 /* new insertion undo */
2473 es
->undo_position
= s
;
2474 es
->undo_insert_count
= strl
;
2475 /* new insertion makes old delete-buffer invalid */
2476 *es
->undo_text
= '\0';
2479 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2482 tl
= strlen(es
->text
);
2483 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2485 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2486 p
[i
] = lpsz_replace
[i
];
2487 if(es
->style
& ES_UPPERCASE
)
2488 CharUpperBuffA(p
, strl
);
2489 else if(es
->style
& ES_LOWERCASE
)
2490 CharLowerBuffA(p
, strl
);
2493 /* FIXME: really inefficient */
2494 if (es
->style
& ES_MULTILINE
)
2495 EDIT_BuildLineDefs_ML(wnd
, es
);
2497 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2498 es
->flags
|= EF_MODIFIED
;
2499 es
->flags
|= EF_UPDATE
;
2500 EDIT_EM_ScrollCaret(wnd
, es
);
2502 /* FIXME: really inefficient */
2503 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2507 /*********************************************************************
2512 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2516 if (!(es
->style
& ES_MULTILINE
))
2517 return (LRESULT
)FALSE
;
2527 if (es
->y_offset
< es
->line_count
- 1)
2532 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2535 if (es
->y_offset
< es
->line_count
- 1)
2536 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2539 return (LRESULT
)FALSE
;
2542 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2543 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2545 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2549 /*********************************************************************
2554 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2556 if (es
->style
& ES_MULTILINE
) {
2561 INT cw
= es
->char_width
;
2566 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2567 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2568 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2569 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2570 if (l
>= es
->y_offset
+ vlc
)
2571 dy
= l
- vlc
+ 1 - es
->y_offset
;
2572 if (l
< es
->y_offset
)
2573 dy
= l
- es
->y_offset
;
2574 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2575 if (x
< es
->format_rect
.left
)
2576 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2577 if (x
> es
->format_rect
.right
)
2578 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2580 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2586 if (!(es
->style
& ES_AUTOHSCROLL
))
2589 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2590 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2591 if (x
< es
->format_rect
.left
) {
2592 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2595 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2596 } while ((x
< goal
) && es
->x_offset
);
2597 /* FIXME: use ScrollWindow() somehow to improve performance */
2598 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2599 } else if (x
> es
->format_rect
.right
) {
2601 INT len
= strlen(es
->text
);
2602 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2605 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2606 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2607 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2608 /* FIXME: use ScrollWindow() somehow to improve performance */
2609 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2615 /*********************************************************************
2619 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2622 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2624 if (!(es
->style
& ES_MULTILINE
))
2628 WARN("called with NULL handle\n");
2632 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2634 * old buffer is freed by caller, unless
2635 * it is still in our own heap. (in that case
2636 * we free it, correcting the buggy caller.)
2639 HeapFree(es
->heap
, 0, es
->text
);
2641 es
->hloc16
= (HLOCAL16
)NULL
;
2644 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2645 EDIT_LockBuffer(wnd
, es
);
2647 es
->x_offset
= es
->y_offset
= 0;
2648 es
->selection_start
= es
->selection_end
= 0;
2649 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2650 es
->flags
&= ~EF_MODIFIED
;
2651 es
->flags
&= ~EF_UPDATE
;
2652 EDIT_BuildLineDefs_ML(wnd
, es
);
2653 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2654 EDIT_EM_ScrollCaret(wnd
, es
);
2658 /*********************************************************************
2662 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2665 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2667 if (!(es
->style
& ES_MULTILINE
))
2671 WARN("called with NULL handle\n");
2675 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2677 * old buffer is freed by caller, unless
2678 * it is still in our own heap. (in that case
2679 * we free it, correcting the buggy caller.)
2682 HeapFree(es
->heap
, 0, es
->text
);
2685 es
->hloc32
= (HLOCAL
)NULL
;
2687 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2688 EDIT_LockBuffer(wnd
, es
);
2690 es
->x_offset
= es
->y_offset
= 0;
2691 es
->selection_start
= es
->selection_end
= 0;
2692 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2693 es
->flags
&= ~EF_MODIFIED
;
2694 es
->flags
&= ~EF_UPDATE
;
2695 EDIT_BuildLineDefs_ML(wnd
, es
);
2696 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2697 EDIT_EM_ScrollCaret(wnd
, es
);
2701 /*********************************************************************
2705 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2706 * However, the windows version is not complied to yet in all of edit.c
2709 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2711 if (es
->style
& ES_MULTILINE
) {
2713 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
2715 es
->buffer_limit
= BUFLIMIT_MULTI
;
2718 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
2720 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2725 /*********************************************************************
2729 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2730 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2731 * of the char's width, according to the new docs.
2734 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2735 INT left
, INT right
)
2737 if (action
& EC_LEFTMARGIN
) {
2738 if (left
!= EC_USEFONTINFO
)
2739 es
->left_margin
= left
;
2741 es
->left_margin
= es
->char_width
/ 3;
2744 if (action
& EC_RIGHTMARGIN
) {
2745 if (right
!= EC_USEFONTINFO
)
2746 es
->right_margin
= right
;
2748 es
->right_margin
= es
->char_width
/ 3;
2750 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2754 /*********************************************************************
2756 * EM_SETPASSWORDCHAR
2759 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2761 if (es
->style
& ES_MULTILINE
)
2764 if (es
->password_char
== c
)
2767 es
->password_char
= c
;
2769 wnd
->dwStyle
|= ES_PASSWORD
;
2770 es
->style
|= ES_PASSWORD
;
2772 wnd
->dwStyle
&= ~ES_PASSWORD
;
2773 es
->style
&= ~ES_PASSWORD
;
2775 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2779 /*********************************************************************
2783 * note: unlike the specs say: the order of start and end
2784 * _is_ preserved in Windows. (i.e. start can be > end)
2785 * In other words: this handler is OK
2788 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2790 UINT old_start
= es
->selection_start
;
2791 UINT old_end
= es
->selection_end
;
2792 UINT len
= strlen(es
->text
);
2795 start
= es
->selection_end
;
2796 end
= es
->selection_end
;
2798 start
= min(start
, len
);
2799 end
= min(end
, len
);
2801 es
->selection_start
= start
;
2802 es
->selection_end
= end
;
2804 es
->flags
|= EF_AFTER_WRAP
;
2806 es
->flags
&= ~EF_AFTER_WRAP
;
2807 if (es
->flags
& EF_FOCUSED
)
2808 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2809 /* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
2810 ORDER_UINT(start
, end
);
2811 ORDER_UINT(end
, old_end
);
2812 ORDER_UINT(start
, old_start
);
2813 ORDER_UINT(old_start
, old_end
);
2814 if (end
!= old_start
)
2818 * ORDER_UINT32(end, old_start);
2819 * EDIT_InvalidateText(wnd, es, start, end);
2820 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2821 * in place of the following if statement.
2823 if (old_start
> end
)
2825 EDIT_InvalidateText(wnd
, es
, start
, end
);
2826 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2830 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2831 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2834 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2838 /*********************************************************************
2843 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2845 if (!(es
->style
& ES_MULTILINE
))
2848 HeapFree(es
->heap
, 0, es
->tabs
);
2849 es
->tabs_count
= count
;
2853 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2854 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2860 /*********************************************************************
2865 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2867 if (!(es
->style
& ES_MULTILINE
))
2870 HeapFree(es
->heap
, 0, es
->tabs
);
2871 es
->tabs_count
= count
;
2876 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2877 for (i
= 0 ; i
< count
; i
++)
2878 es
->tabs
[i
] = *tabs
++;
2884 /*********************************************************************
2886 * EM_SETWORDBREAKPROC
2889 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2891 if (es
->word_break_proc32A
== wbp
)
2894 es
->word_break_proc32A
= wbp
;
2895 es
->word_break_proc16
= NULL
;
2896 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2897 EDIT_BuildLineDefs_ML(wnd
, es
);
2898 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2903 /*********************************************************************
2905 * EM_SETWORDBREAKPROC16
2908 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2910 if (es
->word_break_proc16
== wbp
)
2913 es
->word_break_proc32A
= NULL
;
2914 es
->word_break_proc16
= wbp
;
2915 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2916 EDIT_BuildLineDefs_ML(wnd
, es
);
2917 EDIT_UpdateText(wnd
, NULL
, TRUE
);
2922 /*********************************************************************
2927 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2929 INT ulength
= strlen(es
->undo_text
);
2930 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2932 lstrcpyA(utext
, es
->undo_text
);
2934 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2935 es
->undo_insert_count
, utext
);
2937 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2938 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2939 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2940 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2941 HeapFree(es
->heap
, 0, utext
);
2943 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2944 es
->undo_insert_count
, es
->undo_text
);
2946 if (es
->flags
& EF_UPDATE
) {
2947 es
->flags
&= ~EF_UPDATE
;
2948 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2955 /*********************************************************************
2960 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2962 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
2965 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2966 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2969 if (es
->style
& ES_MULTILINE
) {
2970 if (es
->style
& ES_READONLY
) {
2971 EDIT_MoveHome(wnd
, es
, FALSE
);
2972 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2974 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2975 if (es
->flags
& EF_UPDATE
) {
2976 es
->flags
&= ~EF_UPDATE
;
2977 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2983 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2985 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2986 if (es
->flags
& EF_UPDATE
) {
2987 es
->flags
&= ~EF_UPDATE
;
2988 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
2993 if (!(es
->style
& ES_READONLY
) && !control
) {
2994 if (es
->selection_start
!= es
->selection_end
)
2995 EDIT_WM_Clear(wnd
, es
);
2997 /* delete character left of caret */
2998 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
2999 EDIT_MoveBackward(wnd
, es
, TRUE
);
3000 EDIT_WM_Clear(wnd
, es
);
3005 SendMessageA(wnd
->hwndSelf
, WM_COPY
, 0, 0);
3008 SendMessageA(wnd
->hwndSelf
, WM_PASTE
, 0, 0);
3011 SendMessageA(wnd
->hwndSelf
, WM_CUT
, 0, 0);
3015 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
3019 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
3020 if (es
->flags
& EF_UPDATE
) {
3021 es
->flags
&= ~EF_UPDATE
;
3022 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3030 /*********************************************************************
3035 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3037 if (code
|| control
)
3042 EDIT_EM_Undo(wnd
, es
);
3045 EDIT_WM_Cut(wnd
, es
);
3048 EDIT_WM_Copy(wnd
, es
);
3051 EDIT_WM_Paste(wnd
, es
);
3054 EDIT_WM_Clear(wnd
, es
);
3057 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3058 EDIT_EM_ScrollCaret(wnd
, es
);
3061 ERR("unknown menu item, please report\n");
3067 /*********************************************************************
3071 * Note: the resource files resource/sysres_??.rc cannot define a
3072 * single popup menu. Hence we use a (dummy) menubar
3073 * containing the single popup menu as its first item.
3075 * FIXME: the message identifiers have been chosen arbitrarily,
3076 * hence we use MF_BYPOSITION.
3077 * We might as well use the "real" values (anybody knows ?)
3078 * The menu definition is in resources/sysres_??.rc.
3079 * Once these are OK, we better use MF_BYCOMMAND here
3080 * (as we do in EDIT_WM_Command()).
3083 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
3085 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3086 HMENU popup
= GetSubMenu(menu
, 0);
3087 UINT start
= es
->selection_start
;
3088 UINT end
= es
->selection_end
;
3090 ORDER_UINT(start
, end
);
3093 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
3095 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3097 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3099 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
3101 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3103 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= strlen(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3105 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3110 /*********************************************************************
3115 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3117 INT s
= es
->selection_start
;
3118 INT e
= es
->selection_end
;
3125 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3126 dst
= GlobalLock(hdst
);
3127 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3129 OpenClipboard(wnd
->hwndSelf
);
3131 SetClipboardData(CF_TEXT
, hdst
);
3136 /*********************************************************************
3141 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3144 * To initialize some final structure members, we call some helper
3145 * functions. However, since the EDITSTATE is not consistent (i.e.
3146 * not fully initialized), we should be very careful which
3147 * functions can be called, and in what order.
3149 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3150 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3152 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3153 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3154 /* if we insert text to the editline, the text scrolls out
3155 * of the window, as the caret is placed after the insert
3156 * pos normally; thus we reset es->selection... to 0 and
3159 es
->selection_start
= es
->selection_end
= 0;
3160 EDIT_EM_ScrollCaret(wnd
, es
);
3161 if (es
->flags
& EF_UPDATE
) {
3162 es
->flags
&= ~EF_UPDATE
;
3163 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3170 /*********************************************************************
3175 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3178 while (LocalUnlock(es
->hloc32
)) ;
3179 LocalFree(es
->hloc32
);
3182 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3183 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3185 HeapDestroy(es
->heap
);
3186 HeapFree(GetProcessHeap(), 0, es
);
3187 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3191 /*********************************************************************
3196 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3201 if ( VERSION_AppWinVer() >= 0x40000 &&(
3202 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3203 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3205 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3208 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3210 GetClientRect(wnd
->hwndSelf
, &rc
);
3211 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3212 GetClipBox(dc
, &rc
);
3214 * FIXME: specs say that we should UnrealizeObject() the brush,
3215 * but the specs of UnrealizeObject() say that we shouldn't
3216 * unrealize a stock object. The default brush that
3217 * DefWndProc() returns is ... a stock object.
3219 FillRect(dc
, &rc
, brush
);
3224 /*********************************************************************
3229 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3231 lstrcpynA(text
, es
->text
, count
);
3232 return strlen(text
);
3236 /*********************************************************************
3240 * 16 bit notepad needs this. Actually it is not _our_ hack,
3241 * it is notepad's. Notepad is sending us scrollbar messages with
3242 * undocumented parameters without us even having a scrollbar ... !?!?
3245 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3248 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3251 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3252 ERR("hacked WM_HSCROLL handler invoked\n");
3253 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3254 ERR(" (this message is only displayed once per edit control)\n");
3255 es
->flags
|= EF_HSCROLL_HACK
;
3261 dx
= -es
->char_width
;
3264 if (es
->x_offset
< es
->text_width
)
3265 dx
= es
->char_width
;
3269 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3272 if (es
->x_offset
< es
->text_width
)
3273 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3280 if (es
->x_offset
< es
->text_width
)
3281 dx
= es
->text_width
- es
->x_offset
;
3284 es
->flags
|= EF_HSCROLL_TRACK
;
3285 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3287 case SB_THUMBPOSITION
:
3288 es
->flags
&= ~EF_HSCROLL_TRACK
;
3289 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3290 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3296 * FIXME : the next two are undocumented !
3297 * Are we doing the right thing ?
3298 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3299 * although it's also a regular control message.
3302 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3304 case EM_LINESCROLL16
:
3309 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3313 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3318 /*********************************************************************
3323 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3328 if (!(es
->style
& ES_MULTILINE
))
3331 if (!(es
->style
& ES_AUTOHSCROLL
))
3334 if (!(es
->style
& WS_HSCROLL
))
3335 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3338 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3342 dx
= -es
->char_width
;
3345 if (es
->x_offset
< es
->text_width
)
3346 dx
= es
->char_width
;
3350 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3353 if (es
->x_offset
< es
->text_width
)
3354 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3361 if (es
->x_offset
< es
->text_width
)
3362 dx
= es
->text_width
- es
->x_offset
;
3365 es
->flags
|= EF_HSCROLL_TRACK
;
3366 dx
= pos
- es
->x_offset
;
3368 case SB_THUMBPOSITION
:
3369 es
->flags
&= ~EF_HSCROLL_TRACK
;
3370 if (!(dx
= pos
- es
->x_offset
)) {
3371 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3372 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3379 ERR("undocumented WM_HSCROLL parameter, please report\n");
3383 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3388 /*********************************************************************
3393 static BOOL
EDIT_CheckCombo(WND
*wnd
, EDITSTATE
*es
, UINT msg
, INT key
, DWORD key_data
)
3395 HWND hLBox
= es
->hwndListBox
;
3403 hCombo
= wnd
->parent
->hwndSelf
;
3407 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3408 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3410 if (key
== VK_UP
|| key
== VK_DOWN
)
3412 if (SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3415 if (msg
== WM_KEYDOWN
|| nEUI
)
3416 bDropped
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3422 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3424 /* make sure ComboLBox pops up */
3425 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3430 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3433 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3435 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3437 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
3442 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3448 /*********************************************************************
3452 * Handling of special keys that don't produce a WM_CHAR
3453 * (i.e. non-printable keys) & Backspace & Delete
3456 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3461 if (GetKeyState(VK_MENU
) & 0x8000)
3464 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3465 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3470 if (EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
, key_data
) || key
== VK_F4
)
3475 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3476 EDIT_MoveUp_ML(wnd
, es
, shift
);
3479 EDIT_MoveWordBackward(wnd
, es
, shift
);
3481 EDIT_MoveBackward(wnd
, es
, shift
);
3484 if (EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
, key_data
))
3488 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3489 EDIT_MoveDown_ML(wnd
, es
, shift
);
3491 EDIT_MoveWordForward(wnd
, es
, shift
);
3493 EDIT_MoveForward(wnd
, es
, shift
);
3496 EDIT_MoveHome(wnd
, es
, shift
);
3499 EDIT_MoveEnd(wnd
, es
, shift
);
3502 if (es
->style
& ES_MULTILINE
)
3503 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3505 EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
, key_data
);
3508 if (es
->style
& ES_MULTILINE
)
3509 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3511 EDIT_CheckCombo(wnd
, es
, WM_KEYDOWN
, key
, key_data
);
3514 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3515 if (es
->selection_start
!= es
->selection_end
) {
3517 EDIT_WM_Cut(wnd
, es
);
3519 EDIT_WM_Clear(wnd
, es
);
3522 /* delete character left of caret */
3523 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3524 EDIT_MoveBackward(wnd
, es
, TRUE
);
3525 EDIT_WM_Clear(wnd
, es
);
3526 } else if (control
) {
3527 /* delete to end of line */
3528 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3529 EDIT_MoveEnd(wnd
, es
, TRUE
);
3530 EDIT_WM_Clear(wnd
, es
);
3532 /* delete character right of caret */
3533 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3534 EDIT_MoveForward(wnd
, es
, TRUE
);
3535 EDIT_WM_Clear(wnd
, es
);
3542 if (!(es
->style
& ES_READONLY
))
3543 EDIT_WM_Paste(wnd
, es
);
3545 EDIT_WM_Copy(wnd
, es
);
3548 /* If the edit doesn't want the return send a message to the default object */
3549 if(!(es
->style
& ES_WANTRETURN
))
3551 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
3552 DWORD dw
= SendMessage16( hwndParent
, DM_GETDEFID
, 0, 0 );
3553 if (HIWORD(dw
) == DC_HASDEFID
)
3555 SendMessageA( hwndParent
, WM_COMMAND
,
3556 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3557 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3566 /*********************************************************************
3571 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3573 es
->flags
&= ~EF_FOCUSED
;
3575 if(!(es
->style
& ES_NOHIDESEL
))
3576 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3577 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3582 /*********************************************************************
3586 * The caret position has been set on the WM_LBUTTONDOWN message
3589 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3592 INT e
= es
->selection_end
;
3597 if (!(es
->flags
& EF_FOCUSED
))
3600 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3601 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3602 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3603 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3604 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3605 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3606 EDIT_EM_ScrollCaret(wnd
, es
);
3611 /*********************************************************************
3616 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3621 if (!(es
->flags
& EF_FOCUSED
))
3624 es
->bCaptureState
= TRUE
;
3625 SetCapture(wnd
->hwndSelf
);
3626 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3627 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3628 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3629 EDIT_EM_ScrollCaret(wnd
, es
);
3630 es
->region_posx
= es
->region_posy
= 0;
3631 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3636 /*********************************************************************
3641 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3643 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3644 KillTimer(wnd
->hwndSelf
, 0);
3647 es
->bCaptureState
= FALSE
;
3652 /*********************************************************************
3657 static LRESULT
EDIT_WM_MButtonDown(WND
*wnd
)
3659 SendMessageA(wnd
->hwndSelf
,WM_PASTE
,0,0);
3664 /*********************************************************************
3669 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3675 if (GetCapture() != wnd
->hwndSelf
)
3679 * FIXME: gotta do some scrolling if outside client
3680 * area. Maybe reset the timer ?
3683 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3684 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3685 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3686 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3687 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3692 /*********************************************************************
3697 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3701 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3703 *(EDITSTATE
**)wnd
->wExtra
= es
;
3706 * Note: since the EDITSTATE has not been fully initialized yet,
3707 * we can't use any API calls that may send
3708 * WM_XXX messages before WM_NCCREATE is completed.
3711 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3713 es
->style
= cs
->style
;
3715 es
->bEnableState
= !(cs
->style
& WS_DISABLED
);
3718 * In Win95 look and feel, the WS_BORDER style is replaced by the
3719 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3720 * control a non client area.
3722 if (TWEAK_WineLook
!= WIN31_LOOK
)
3724 if (es
->style
& WS_BORDER
)
3726 es
->style
&= ~WS_BORDER
;
3727 wnd
->dwStyle
&= ~WS_BORDER
;
3728 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3733 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3734 wnd
->dwStyle
&= ~WS_BORDER
;
3737 if (es
->style
& ES_COMBO
)
3738 es
->hwndListBox
= GetDlgItem(cs
->hwndParent
, ID_CB_LISTBOX
);
3740 if (es
->style
& ES_MULTILINE
) {
3741 es
->buffer_size
= BUFSTART_MULTI
;
3742 es
->buffer_limit
= BUFLIMIT_MULTI
;
3743 if (es
->style
& WS_VSCROLL
)
3744 es
->style
|= ES_AUTOVSCROLL
;
3745 if (es
->style
& WS_HSCROLL
)
3746 es
->style
|= ES_AUTOHSCROLL
;
3747 es
->style
&= ~ES_PASSWORD
;
3748 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3749 if (es
->style
& ES_RIGHT
)
3750 es
->style
&= ~ES_CENTER
;
3751 es
->style
&= ~WS_HSCROLL
;
3752 es
->style
&= ~ES_AUTOHSCROLL
;
3755 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3756 es
->style
|= ES_AUTOVSCROLL
;
3758 es
->buffer_size
= BUFSTART_SINGLE
;
3759 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3760 es
->style
&= ~ES_CENTER
;
3761 es
->style
&= ~ES_RIGHT
;
3762 es
->style
&= ~WS_HSCROLL
;
3763 es
->style
&= ~WS_VSCROLL
;
3764 es
->style
&= ~ES_AUTOVSCROLL
;
3765 es
->style
&= ~ES_WANTRETURN
;
3766 if (es
->style
& ES_UPPERCASE
) {
3767 es
->style
&= ~ES_LOWERCASE
;
3768 es
->style
&= ~ES_NUMBER
;
3769 } else if (es
->style
& ES_LOWERCASE
)
3770 es
->style
&= ~ES_NUMBER
;
3771 if (es
->style
& ES_PASSWORD
)
3772 es
->password_char
= '*';
3774 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3775 es
->style
|= ES_AUTOHSCROLL
;
3777 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3779 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3780 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3782 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3784 if (es
->style
& ES_MULTILINE
)
3785 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3792 /*********************************************************************
3797 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3806 BOOL rev
= es
->bEnableState
&&
3807 ((es
->flags
& EF_FOCUSED
) ||
3808 (es
->style
& ES_NOHIDESEL
));
3810 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3813 if(es
->style
& WS_BORDER
) {
3814 GetClientRect(wnd
->hwndSelf
, &rc
);
3815 if(es
->style
& ES_MULTILINE
) {
3816 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3817 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3819 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3821 IntersectClipRect(dc
, es
->format_rect
.left
,
3822 es
->format_rect
.top
,
3823 es
->format_rect
.right
,
3824 es
->format_rect
.bottom
);
3825 if (es
->style
& ES_MULTILINE
) {
3826 GetClientRect(wnd
->hwndSelf
, &rc
);
3827 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3830 old_font
= SelectObject(dc
, es
->font
);
3831 if ( VERSION_AppWinVer() >= 0x40000 &&(
3832 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3833 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3835 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3837 if (!es
->bEnableState
)
3838 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3839 GetClipBox(dc
, &rcRgn
);
3840 if (es
->style
& ES_MULTILINE
) {
3841 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3842 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3843 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3844 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3845 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3848 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3849 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3850 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3853 SelectObject(dc
, old_font
);
3854 if (es
->flags
& EF_FOCUSED
)
3855 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3856 es
->flags
& EF_AFTER_WRAP
);
3858 EndPaint(wnd
->hwndSelf
, &ps
);
3859 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3860 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3862 si
.cbSize
= sizeof(SCROLLINFO
);
3863 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3865 si
.nMax
= es
->line_count
+ vlc
- 2;
3867 si
.nPos
= es
->y_offset
;
3868 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3870 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3872 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3873 si
.cbSize
= sizeof(SCROLLINFO
);
3874 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3876 si
.nMax
= es
->text_width
+ fw
- 1;
3878 si
.nPos
= es
->x_offset
;
3879 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3884 /*********************************************************************
3889 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3894 OpenClipboard(wnd
->hwndSelf
);
3895 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3896 src
= (LPSTR
)GlobalLock(hsrc
);
3897 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3900 if (es
->flags
& EF_UPDATE
) {
3901 es
->flags
&= ~EF_UPDATE
;
3902 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3909 /*********************************************************************
3914 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3916 es
->flags
|= EF_FOCUSED
;
3917 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3918 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3919 es
->flags
& EF_AFTER_WRAP
);
3920 if(!(es
->style
& ES_NOHIDESEL
))
3921 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3922 ShowCaret(wnd
->hwndSelf
);
3923 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3927 /*********************************************************************
3931 * With Win95 look the margins are set to default font value unless
3932 * the system font (font == 0) is being set, in which case they are left
3936 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3944 dc
= GetDC(wnd
->hwndSelf
);
3946 old_font
= SelectObject(dc
, font
);
3947 GetTextMetricsA(dc
, &tm
);
3948 es
->line_height
= tm
.tmHeight
;
3949 es
->char_width
= tm
.tmAveCharWidth
;
3951 SelectObject(dc
, old_font
);
3952 ReleaseDC(wnd
->hwndSelf
, dc
);
3953 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3954 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3955 EC_USEFONTINFO
, EC_USEFONTINFO
);
3957 /* Force the recalculation of the format rect for each font change */
3958 GetClientRect(wnd
->hwndSelf
, &r
);
3959 EDIT_SetRectNP(wnd
, es
, &r
);
3961 if (es
->style
& ES_MULTILINE
)
3962 EDIT_BuildLineDefs_ML(wnd
, es
);
3965 EDIT_UpdateText(wnd
, NULL
, TRUE
);
3966 if (es
->flags
& EF_FOCUSED
) {
3968 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3969 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3970 es
->flags
& EF_AFTER_WRAP
);
3971 ShowCaret(wnd
->hwndSelf
);
3976 /*********************************************************************
3981 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3982 * The modified flag is reset. No notifications are sent.
3984 * For single-line controls, reception of WM_SETTEXT triggers:
3985 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3988 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3990 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3992 TRACE("\t'%p'\n", text
);
3993 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3995 TRACE("\t<NULL>\n");
3996 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3999 if (es
->style
& ES_MULTILINE
) {
4000 es
->flags
&= ~EF_UPDATE
;
4002 es
->flags
|= EF_UPDATE
;
4004 es
->flags
&= ~EF_MODIFIED
;
4005 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
4006 EDIT_EM_ScrollCaret(wnd
, es
);
4008 if (es
->flags
& EF_UPDATE
) {
4009 es
->flags
&= ~EF_UPDATE
;
4010 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
4015 /*********************************************************************
4020 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4022 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4024 SetRect(&rc
, 0, 0, width
, height
);
4025 EDIT_SetRectNP(wnd
, es
, &rc
);
4026 EDIT_UpdateText(wnd
, NULL
, TRUE
);
4031 /*********************************************************************
4036 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
4038 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4039 if (EDIT_EM_CanUndo(wnd
, es
))
4040 EDIT_EM_Undo(wnd
, es
);
4042 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4043 if (EDIT_CheckCombo(wnd
, es
, WM_SYSKEYDOWN
, key
, key_data
))
4046 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4050 /*********************************************************************
4055 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
4057 if (es
->region_posx
< 0) {
4058 EDIT_MoveBackward(wnd
, es
, TRUE
);
4059 } else if (es
->region_posx
> 0) {
4060 EDIT_MoveForward(wnd
, es
, TRUE
);
4063 * FIXME: gotta do some vertical scrolling here, like
4064 * EDIT_EM_LineScroll(wnd, 0, 1);
4069 /*********************************************************************
4073 * 16 bit notepad needs this. Actually it is not _our_ hack,
4074 * it is notepad's. Notepad is sending us scrollbar messages with
4075 * undocumented parameters without us even having a scrollbar ... !?!?
4078 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4083 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
4084 ERR("hacked WM_VSCROLL handler invoked\n");
4085 ERR(" if you are _not_ running 16 bit notepad, please report\n");
4086 ERR(" (this message is only displayed once per edit control)\n");
4087 es
->flags
|= EF_VSCROLL_HACK
;
4095 EDIT_EM_Scroll(wnd
, es
, action
);
4101 dy
= es
->line_count
- 1 - es
->y_offset
;
4104 es
->flags
|= EF_VSCROLL_TRACK
;
4105 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
4107 case SB_THUMBPOSITION
:
4108 es
->flags
&= ~EF_VSCROLL_TRACK
;
4109 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
4110 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4116 * FIXME : the next two are undocumented !
4117 * Are we doing the right thing ?
4118 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4119 * although it's also a regular control message.
4122 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
4124 case EM_LINESCROLL16
:
4129 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4133 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4138 /*********************************************************************
4143 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4147 if (!(es
->style
& ES_MULTILINE
))
4150 if (!(es
->style
& ES_AUTOVSCROLL
))
4153 if (!(es
->style
& WS_VSCROLL
))
4154 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4162 EDIT_EM_Scroll(wnd
, es
, action
);
4169 dy
= es
->line_count
- 1 - es
->y_offset
;
4172 es
->flags
|= EF_VSCROLL_TRACK
;
4173 dy
= pos
- es
->y_offset
;
4175 case SB_THUMBPOSITION
:
4176 es
->flags
&= ~EF_VSCROLL_TRACK
;
4177 if (!(dy
= pos
- es
->y_offset
)) {
4178 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4179 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4186 ERR("undocumented WM_VSCROLL action %d, please report\n",
4191 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4196 /*********************************************************************
4201 static void EDIT_UpdateText(WND
*wnd
, LPRECT rc
, BOOL bErase
)
4203 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
4205 /* EF_UPDATE will be turned off in paint */
4206 if (es
->flags
& EF_UPDATE
)
4207 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
4209 InvalidateRect(wnd
->hwndSelf
, rc
, bErase
);