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)
17 #include "wine/winbase16.h"
25 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
26 FIXME: BTW, new specs say 65535 (do you dare ???) */
27 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
28 #define BUFSTART_MULTI 1024 /* starting size */
29 #define BUFSTART_SINGLE 256 /* starting size */
30 #define GROWLENGTH 64 /* buffers grow by this much */
31 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
34 * extra flags for EDITSTATE.flags field
36 #define EF_MODIFIED 0x0001 /* text has been modified */
37 #define EF_FOCUSED 0x0002 /* we have input focus */
38 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
39 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
40 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
41 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
42 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
43 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
44 wrapped line, instead of in front of the next character */
45 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
49 END_0
= 0, /* line ends with terminating '\0' character */
50 END_WRAP
, /* line is wrapped */
51 END_HARD
, /* line ends with a hard return '\r\n' */
52 END_SOFT
/* line ends with a soft return '\r\r\n' */
55 typedef struct tagLINEDEF
{
56 INT length
; /* bruto length of a line in bytes */
57 INT net_length
; /* netto length of a line in visible characters */
59 INT width
; /* width of the line in pixels */
60 struct tagLINEDEF
*next
;
65 HANDLE heap
; /* our own heap */
66 LPSTR text
; /* the actual contents of the control */
67 INT buffer_size
; /* the size of the buffer */
68 INT buffer_limit
; /* the maximum size to which the buffer may grow */
69 HFONT font
; /* NULL means standard system font */
70 INT x_offset
; /* scroll offset for multi lines this is in pixels
71 for single lines it's in characters */
72 INT line_height
; /* height of a screen line in pixels */
73 INT char_width
; /* average character width in pixels */
74 DWORD style
; /* sane version of wnd->dwStyle */
75 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
76 INT undo_insert_count
; /* number of characters inserted in sequence */
77 INT undo_position
; /* character index of the insertion and deletion */
78 LPSTR undo_text
; /* deleted text */
79 INT undo_buffer_size
; /* size of the deleted text buffer */
80 INT selection_start
; /* == selection_end if no selection */
81 INT selection_end
; /* == current caret position */
82 CHAR password_char
; /* == 0 if no password char, and for multi line controls */
83 INT left_margin
; /* in pixels */
84 INT right_margin
; /* in pixels */
86 INT region_posx
; /* Position of cursor relative to region: */
87 INT region_posy
; /* -1: to left, 0: within, 1: to right */
88 EDITWORDBREAKPROC16 word_break_proc16
;
89 EDITWORDBREAKPROCA word_break_proc32A
;
90 INT line_count
; /* number of lines */
91 INT y_offset
; /* scroll offset in number of lines */
93 * only for multi line controls
95 INT lock_count
; /* amount of re-entries in the EditWndProc */
98 INT text_width
; /* width of the widest line in pixels */
99 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
100 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
101 HLOCAL hloc32
; /* for controls receiving EM_GETHANDLE */
105 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
106 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
108 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
109 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
111 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
112 ({TRACE(edit, "notification " str " sent to hwnd=%08x\n", \
115 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
116 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
117 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
118 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
119 (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \
120 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
121 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
122 (LPARAM)(wnd)->hwndSelf))
123 #define DPRINTF_EDIT_MSG16(str) \
125 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
126 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
127 #define DPRINTF_EDIT_MSG32(str) \
129 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
130 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
132 /*********************************************************************
139 * These functions have trivial implementations
140 * We still like to call them internally
141 * "static __inline__" makes them more like macro's
143 static __inline__ BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
144 static __inline__
void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
145 static __inline__
void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
146 static __inline__
void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
148 * This is the only exported function
150 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
151 WPARAM wParam
, LPARAM lParam
);
153 * Helper functions only valid for one type of control
155 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
156 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
157 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
158 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
159 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
160 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
162 * Helper functions valid for both single line _and_ multi line controls
164 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
165 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
166 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
167 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
168 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
169 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
170 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
171 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
172 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
173 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
174 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
175 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
176 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
177 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
178 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
179 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
180 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
181 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
182 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
183 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
185 * EM_XXX message handlers
187 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
188 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
189 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
190 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
191 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
192 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
193 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
194 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
195 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
196 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
197 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
198 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
199 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
200 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
201 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
202 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
203 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
204 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
205 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
206 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
207 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
208 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
209 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
210 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
211 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
212 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
214 * WM_XXX message handlers
216 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
217 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
218 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
219 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
220 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
221 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
222 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
223 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
224 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
225 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
226 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
227 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
228 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
229 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
230 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
231 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
232 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
);
233 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
234 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
235 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
236 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
237 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
238 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
239 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
240 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
243 /*********************************************************************
248 static __inline__ BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
250 return (es
->undo_insert_count
|| lstrlenA(es
->undo_text
));
254 /*********************************************************************
259 static __inline__
void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
261 es
->undo_insert_count
= 0;
262 *es
->undo_text
= '\0';
266 /*********************************************************************
271 static __inline__
void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
273 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
277 /*********************************************************************
282 static __inline__
void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
284 EDIT_WM_Copy(wnd
, es
);
285 EDIT_WM_Clear(wnd
, es
);
289 /*********************************************************************
293 * The messages are in the order of the actual integer values
294 * (which can be found in include/windows.h)
295 * Whereever possible the 16 bit versions are converted to
296 * the 32 bit ones, so that we can 'fall through' to the
297 * helper functions. These are mostly 32 bit (with a few
298 * exceptions, clearly indicated by a '16' extension to their
302 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
303 WPARAM wParam
, LPARAM lParam
)
305 WND
*wnd
= WIN_FindWndPtr(hwnd
);
306 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
311 DPRINTF_EDIT_MSG32("WM_DESTROY");
312 EDIT_WM_Destroy(wnd
, es
);
317 DPRINTF_EDIT_MSG32("WM_NCCREATE");
318 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
324 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
329 EDIT_LockBuffer(wnd
, es
);
332 DPRINTF_EDIT_MSG16("EM_GETSEL");
337 DPRINTF_EDIT_MSG32("EM_GETSEL");
338 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
342 DPRINTF_EDIT_MSG16("EM_SETSEL");
343 if (SLOWORD(lParam
) == -1)
344 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
346 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
348 EDIT_EM_ScrollCaret(wnd
, es
);
352 DPRINTF_EDIT_MSG32("EM_SETSEL");
353 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
358 DPRINTF_EDIT_MSG16("EM_GETRECT");
360 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
363 DPRINTF_EDIT_MSG32("EM_GETRECT");
365 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
369 DPRINTF_EDIT_MSG16("EM_SETRECT");
370 if ((es
->style
& ES_MULTILINE
) && lParam
) {
372 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
373 EDIT_SetRectNP(wnd
, es
, &rc
);
374 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
378 DPRINTF_EDIT_MSG32("EM_SETRECT");
379 if ((es
->style
& ES_MULTILINE
) && lParam
) {
380 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
381 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
386 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
387 if ((es
->style
& ES_MULTILINE
) && lParam
) {
389 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
390 EDIT_SetRectNP(wnd
, es
, &rc
);
394 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
395 if ((es
->style
& ES_MULTILINE
) && lParam
)
396 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
400 DPRINTF_EDIT_MSG16("EM_SCROLL");
403 DPRINTF_EDIT_MSG32("EM_SCROLL");
404 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
407 case EM_LINESCROLL16
:
408 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
409 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
410 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
413 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
414 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
417 case EM_SCROLLCARET16
:
418 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
421 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
422 EDIT_EM_ScrollCaret(wnd
, es
);
427 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
430 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
431 return ((es
->flags
& EF_MODIFIED
) != 0);
435 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
438 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
440 es
->flags
|= EF_MODIFIED
;
442 es
->flags
&= ~EF_MODIFIED
;
445 case EM_GETLINECOUNT16
:
446 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
448 case EM_GETLINECOUNT
:
449 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
450 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
454 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
455 if ((INT16
)wParam
== -1)
459 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
460 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
464 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
465 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
468 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
469 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
473 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
474 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
477 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
478 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
482 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
485 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
486 result
= EDIT_EM_GetThumb(wnd
, es
);
489 /* messages 0x00bf and 0x00c0 missing from specs */
492 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
495 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
496 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
500 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
503 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
504 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
507 case EM_LINELENGTH16
:
508 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
511 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
512 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
515 case EM_REPLACESEL16
:
516 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
517 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
520 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
521 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
525 /* message 0x00c3 missing from specs */
528 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
531 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
532 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
536 DPRINTF_EDIT_MSG16("EM_GETLINE");
537 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
540 DPRINTF_EDIT_MSG32("EM_GETLINE");
541 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
545 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
547 case EM_SETLIMITTEXT
:
548 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
549 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
553 DPRINTF_EDIT_MSG16("EM_CANUNDO");
556 DPRINTF_EDIT_MSG32("EM_CANUNDO");
557 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
561 DPRINTF_EDIT_MSG16("EM_UNDO");
566 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
567 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
571 DPRINTF_EDIT_MSG16("EM_FMTLINES");
574 DPRINTF_EDIT_MSG32("EM_FMTLINES");
575 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
578 case EM_LINEFROMCHAR16
:
579 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
581 case EM_LINEFROMCHAR
:
582 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
583 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
586 /* message 0x00ca missing from specs */
589 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
592 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
593 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
596 case EM_SETTABSTOPS16
:
597 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
598 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
601 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
602 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
605 case EM_SETPASSWORDCHAR16
:
606 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
608 case EM_SETPASSWORDCHAR
:
609 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
610 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
613 case EM_EMPTYUNDOBUFFER16
:
614 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
616 case EM_EMPTYUNDOBUFFER
:
617 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
618 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
621 case EM_GETFIRSTVISIBLELINE16
:
622 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
623 result
= es
->y_offset
;
625 case EM_GETFIRSTVISIBLELINE
:
626 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
627 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
630 case EM_SETREADONLY16
:
631 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
634 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
636 wnd
->dwStyle
|= ES_READONLY
;
637 es
->style
|= ES_READONLY
;
639 wnd
->dwStyle
&= ~ES_READONLY
;
640 es
->style
&= ~ES_READONLY
;
645 case EM_SETWORDBREAKPROC16
:
646 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
647 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
649 case EM_SETWORDBREAKPROC
:
650 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
651 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
654 case EM_GETWORDBREAKPROC16
:
655 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
656 result
= (LRESULT
)es
->word_break_proc16
;
658 case EM_GETWORDBREAKPROC
:
659 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
660 result
= (LRESULT
)es
->word_break_proc32A
;
663 case EM_GETPASSWORDCHAR16
:
664 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
666 case EM_GETPASSWORDCHAR
:
667 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
668 result
= es
->password_char
;
671 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
674 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
675 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
679 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
680 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
683 case EM_GETLIMITTEXT
:
684 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
685 result
= es
->buffer_limit
;
689 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
690 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
694 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
695 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
699 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
700 result
= (es
->style
& ES_MULTILINE
) ?
701 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
702 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
706 DPRINTF_EDIT_MSG32("WM_CHAR");
707 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
711 DPRINTF_EDIT_MSG32("WM_CLEAR");
712 EDIT_WM_Clear(wnd
, es
);
716 DPRINTF_EDIT_MSG32("WM_COMMAND");
717 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
721 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
722 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
726 DPRINTF_EDIT_MSG32("WM_COPY");
727 EDIT_WM_Copy(wnd
, es
);
731 DPRINTF_EDIT_MSG32("WM_CREATE");
732 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
736 DPRINTF_EDIT_MSG32("WM_CUT");
737 EDIT_WM_Cut(wnd
, es
);
741 DPRINTF_EDIT_MSG32("WM_ENABLE");
742 InvalidateRect(hwnd
, NULL
, TRUE
);
746 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
747 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
751 DPRINTF_EDIT_MSG32("WM_GETFONT");
752 result
= (LRESULT
)es
->font
;
756 DPRINTF_EDIT_MSG32("WM_GETTEXT");
757 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
760 case WM_GETTEXTLENGTH
:
761 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
762 result
= lstrlenA(es
->text
);
766 DPRINTF_EDIT_MSG32("WM_HSCROLL");
767 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
771 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
772 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
776 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
777 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
780 case WM_LBUTTONDBLCLK
:
781 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
782 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
786 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
787 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
791 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
792 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
795 case WM_MOUSEACTIVATE
:
797 * FIXME: maybe DefWindowProc() screws up, but it seems that
798 * modalless dialog boxes need this. If we don't do this, the focus
799 * will _not_ be set by DefWindowProc() for edit controls in a
800 * modalless dialog box ???
802 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
803 SetFocus(wnd
->hwndSelf
);
804 result
= MA_ACTIVATE
;
809 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
811 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
815 DPRINTF_EDIT_MSG32("WM_PAINT");
816 EDIT_WM_Paint(wnd
, es
);
820 DPRINTF_EDIT_MSG32("WM_PASTE");
821 EDIT_WM_Paste(wnd
, es
);
825 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
826 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
830 DPRINTF_EDIT_MSG32("WM_SETFONT");
831 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
835 DPRINTF_EDIT_MSG32("WM_SETTEXT");
836 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
841 DPRINTF_EDIT_MSG32("WM_SIZE");
842 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
846 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
847 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
851 DPRINTF_EDIT_MSG32("WM_TIMER");
852 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
856 DPRINTF_EDIT_MSG32("WM_VSCROLL");
857 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
861 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
864 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
866 WIN_ReleaseWndPtr(wnd
);
872 /*********************************************************************
874 * EDIT_BuildLineDefs_ML
876 * Build linked list of text lines.
877 * Lines can end with '\0' (last line), a character (if it is wrapped),
878 * a soft return '\r\r\n' or a hard return '\r\n'
881 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
887 LINEDEF
*current_def
;
888 LINEDEF
**previous_next
;
890 current_def
= es
->first_line_def
;
892 LINEDEF
*next_def
= current_def
->next
;
893 HeapFree(es
->heap
, 0, current_def
);
894 current_def
= next_def
;
895 } while (current_def
);
899 dc
= GetDC(wnd
->hwndSelf
);
901 old_font
= SelectObject(dc
, es
->font
);
903 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
905 previous_next
= &es
->first_line_def
;
907 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
908 current_def
->next
= NULL
;
911 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
916 current_def
->ending
= END_0
;
917 current_def
->net_length
= lstrlenA(start
);
918 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
919 current_def
->ending
= END_SOFT
;
920 current_def
->net_length
= cp
- start
- 1;
922 current_def
->ending
= END_HARD
;
923 current_def
->net_length
= cp
- start
;
925 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
926 start
, current_def
->net_length
,
927 es
->tabs_count
, es
->tabs
));
928 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
929 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
934 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
935 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
936 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
937 start
, next
, es
->tabs_count
, es
->tabs
));
938 } while (current_def
->width
<= fw
);
944 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
945 start
, next
, es
->tabs_count
, es
->tabs
));
946 } while (current_def
->width
<= fw
);
950 current_def
->net_length
= prev
;
951 current_def
->ending
= END_WRAP
;
952 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
953 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
955 switch (current_def
->ending
) {
957 current_def
->length
= current_def
->net_length
+ 3;
960 current_def
->length
= current_def
->net_length
+ 2;
964 current_def
->length
= current_def
->net_length
;
967 es
->text_width
= MAX(es
->text_width
, current_def
->width
);
968 start
+= current_def
->length
;
969 *previous_next
= current_def
;
970 previous_next
= ¤t_def
->next
;
972 } while (current_def
->ending
!= END_0
);
974 SelectObject(dc
, old_font
);
975 ReleaseDC(wnd
->hwndSelf
, dc
);
979 /*********************************************************************
981 * EDIT_CallWordBreakProc
983 * Call appropriate WordBreakProc (internal or external).
985 * Note: The "start" argument should always be an index refering
986 * to es->text. The actual wordbreak proc might be
987 * 16 bit, so we can't always pass any 32 bit LPSTR.
988 * Hence we assume that es->text is the buffer that holds
989 * the string under examination (we can decide this for ourselves).
992 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
994 if (es
->word_break_proc16
) {
995 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
996 SEGPTR segptr
= LocalLock16(hloc16
);
997 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
998 segptr
+ start
, index
, count
, action
);
999 LocalUnlock16(hloc16
);
1002 else if (es
->word_break_proc32A
)
1004 TRACE(relay
, "(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1005 es
->word_break_proc32A
, es
->text
+ start
, index
,
1007 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1011 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1015 /*********************************************************************
1019 * Beware: This is not the function called on EM_CHARFROMPOS
1020 * The position _can_ be outside the formatting / client
1022 * The return value is only the character index
1025 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1031 if (es
->style
& ES_MULTILINE
) {
1032 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1034 LINEDEF
*line_def
= es
->first_line_def
;
1036 while ((line
> 0) && line_def
->next
) {
1037 line_index
+= line_def
->length
;
1038 line_def
= line_def
->next
;
1041 x
+= es
->x_offset
- es
->format_rect
.left
;
1042 if (x
>= line_def
->width
) {
1044 *after_wrap
= (line_def
->ending
== END_WRAP
);
1045 return line_index
+ line_def
->net_length
;
1049 *after_wrap
= FALSE
;
1052 dc
= GetDC(wnd
->hwndSelf
);
1054 old_font
= SelectObject(dc
, es
->font
);
1055 low
= line_index
+ 1;
1056 high
= line_index
+ line_def
->net_length
+ 1;
1057 while (low
< high
- 1)
1059 INT mid
= (low
+ high
) / 2;
1060 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1066 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1067 (line_def
->ending
== END_WRAP
));
1072 *after_wrap
= FALSE
;
1073 x
-= es
->format_rect
.left
;
1075 return es
->x_offset
;
1076 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1077 dc
= GetDC(wnd
->hwndSelf
);
1079 old_font
= SelectObject(dc
, es
->font
);
1083 INT high
= es
->x_offset
;
1084 while (low
< high
- 1)
1086 INT mid
= (low
+ high
) / 2;
1087 GetTextExtentPoint32A( dc
, text
+ mid
,
1088 es
->x_offset
- mid
, &size
);
1089 if (size
.cx
> -x
) low
= mid
;
1096 INT low
= es
->x_offset
;
1097 INT high
= lstrlenA(es
->text
) + 1;
1098 while (low
< high
- 1)
1100 INT mid
= (low
+ high
) / 2;
1101 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1102 mid
- es
->x_offset
, &size
);
1103 if (size
.cx
> x
) high
= mid
;
1108 if (es
->style
& ES_PASSWORD
)
1109 HeapFree(es
->heap
, 0 ,text
);
1112 SelectObject(dc
, old_font
);
1113 ReleaseDC(wnd
->hwndSelf
, dc
);
1118 /*********************************************************************
1122 * adjusts the point to be within the formatting rectangle
1123 * (so CharFromPos returns the nearest _visible_ character)
1126 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1128 *x
= MIN(MAX(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1129 *y
= MIN(MAX(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1133 /*********************************************************************
1137 * Calculates the bounding rectangle for a line from a starting
1138 * column to an ending column.
1141 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1143 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1145 if (es
->style
& ES_MULTILINE
)
1146 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1148 rc
->top
= es
->format_rect
.top
;
1149 rc
->bottom
= rc
->top
+ es
->line_height
;
1150 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1151 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1155 /*********************************************************************
1157 * EDIT_GetPasswordPointer_SL
1159 * note: caller should free the (optionally) allocated buffer
1162 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1164 if (es
->style
& ES_PASSWORD
) {
1165 INT len
= lstrlenA(es
->text
);
1166 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1167 RtlFillMemory(text
, len
, es
->password_char
);
1175 /*********************************************************************
1179 * This acts as a LOCAL_Lock(), but it locks only once. This way
1180 * you can call it whenever you like, without unlocking.
1183 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1186 ERR(edit
, "no EDITSTATE ... please report\n");
1189 if (!(es
->style
& ES_MULTILINE
))
1193 es
->text
= LocalLock(es
->hloc32
);
1194 else if (es
->hloc16
)
1195 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1197 ERR(edit
, "no buffer ... please report\n");
1205 /*********************************************************************
1207 * EDIT_SL_InvalidateText
1209 * Called from EDIT_InvalidateText().
1210 * Does the job for single-line controls only.
1213 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1218 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1219 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1220 InvalidateRect(wnd
->hwndSelf
, &rc
, FALSE
);
1224 /*********************************************************************
1226 * EDIT_ML_InvalidateText
1228 * Called from EDIT_InvalidateText().
1229 * Does the job for multi-line controls only.
1232 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1234 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1235 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1236 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1245 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1248 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1249 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1250 if (sl
< es
->y_offset
) {
1254 if (el
> es
->y_offset
+ vlc
) {
1255 el
= es
->y_offset
+ vlc
;
1256 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1258 GetClientRect(wnd
->hwndSelf
, &rc1
);
1259 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1261 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1262 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1263 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1265 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1266 EDIT_EM_LineLength(wnd
, es
,
1267 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1269 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1270 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1271 for (l
= sl
+ 1 ; l
< el
; l
++) {
1272 EDIT_GetLineRect(wnd
, es
, l
, 0,
1273 EDIT_EM_LineLength(wnd
, es
,
1274 EDIT_EM_LineIndex(wnd
, es
, l
)),
1276 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1277 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1279 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1280 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1281 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1286 /*********************************************************************
1288 * EDIT_InvalidateText
1290 * Invalidate the text from offset start upto, but not including,
1291 * offset end. Useful for (re)painting the selection.
1292 * Regions outside the linewidth are not invalidated.
1293 * end == -1 means end == TextLength.
1294 * start and end need not be ordered.
1297 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1303 end
= lstrlenA(es
->text
);
1305 ORDER_INT(start
, end
);
1307 if (es
->style
& ES_MULTILINE
)
1308 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1310 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1314 /*********************************************************************
1318 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1321 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1326 if (size
<= es
->buffer_size
)
1328 if (size
> es
->buffer_limit
) {
1329 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1332 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1333 if (size
> es
->buffer_limit
)
1334 size
= es
->buffer_limit
;
1336 TRACE(edit
, "trying to ReAlloc to %d+1\n", size
);
1338 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1340 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1341 es
->buffer_size
= MIN(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1343 es
->buffer_size
= 0;
1344 } else if (es
->hloc32
) {
1345 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1346 TRACE(edit
, "Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1347 es
->hloc32
= hNew32
;
1348 es
->buffer_size
= MIN(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1350 } else if (es
->hloc16
) {
1351 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1352 TRACE(edit
, "Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1353 es
->hloc16
= hNew16
;
1354 es
->buffer_size
= MIN(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1357 if (es
->buffer_size
< size
) {
1358 EDIT_LockBuffer(wnd
, es
);
1359 WARN(edit
, "FAILED ! We now have %d+1\n", es
->buffer_size
);
1360 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1363 EDIT_LockBuffer(wnd
, es
);
1364 TRACE(edit
, "We now have %d+1\n", es
->buffer_size
);
1370 /*********************************************************************
1374 * Try to fit size + 1 bytes in the undo buffer.
1377 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1379 if (size
<= es
->undo_buffer_size
)
1381 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1383 TRACE(edit
, "trying to ReAlloc to %d+1\n", size
);
1385 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1386 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1387 if (es
->undo_buffer_size
< size
) {
1388 WARN(edit
, "FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1397 /*********************************************************************
1402 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1404 INT e
= es
->selection_end
;
1408 if ((es
->style
& ES_MULTILINE
) && e
&&
1409 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1411 if (e
&& (es
->text
[e
- 1] == '\r'))
1415 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1416 EDIT_EM_ScrollCaret(wnd
, es
);
1420 /*********************************************************************
1424 * Only for multi line controls
1425 * Move the caret one line down, on a column with the nearest
1426 * x coordinate on the screen (might be a different column).
1429 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1431 INT s
= es
->selection_start
;
1432 INT e
= es
->selection_end
;
1433 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1434 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1435 INT x
= SLOWORD(pos
);
1436 INT y
= SHIWORD(pos
);
1438 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1441 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1442 EDIT_EM_ScrollCaret(wnd
, es
);
1446 /*********************************************************************
1451 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1453 BOOL after_wrap
= FALSE
;
1456 if (es
->style
& ES_MULTILINE
)
1457 e
= EDIT_CharFromPos(wnd
, es
, 0x7fffffff,
1458 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1460 e
= lstrlenA(es
->text
);
1461 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1462 EDIT_EM_ScrollCaret(wnd
, es
);
1466 /*********************************************************************
1471 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1473 INT e
= es
->selection_end
;
1477 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1478 if (es
->text
[e
] == '\n')
1480 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1484 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1485 EDIT_EM_ScrollCaret(wnd
, es
);
1489 /*********************************************************************
1493 * Home key: move to beginning of line.
1496 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1500 if (es
->style
& ES_MULTILINE
)
1501 e
= EDIT_CharFromPos(wnd
, es
, 0x80000000,
1502 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1505 EDIT_EM_SetSel(wnd
, es
, e
, extend
? es
->selection_start
: e
, FALSE
);
1506 EDIT_EM_ScrollCaret(wnd
, es
);
1510 /*********************************************************************
1512 * EDIT_MovePageDown_ML
1514 * Only for multi line controls
1515 * Move the caret one page down, on a column with the nearest
1516 * x coordinate on the screen (might be a different column).
1519 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1521 INT s
= es
->selection_start
;
1522 INT e
= es
->selection_end
;
1523 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1524 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1525 INT x
= SLOWORD(pos
);
1526 INT y
= SHIWORD(pos
);
1528 e
= EDIT_CharFromPos(wnd
, es
, x
,
1529 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1533 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1534 EDIT_EM_ScrollCaret(wnd
, es
);
1538 /*********************************************************************
1540 * EDIT_MovePageUp_ML
1542 * Only for multi line controls
1543 * Move the caret one page up, on a column with the nearest
1544 * x coordinate on the screen (might be a different column).
1547 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1549 INT s
= es
->selection_start
;
1550 INT e
= es
->selection_end
;
1551 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1552 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1553 INT x
= SLOWORD(pos
);
1554 INT y
= SHIWORD(pos
);
1556 e
= EDIT_CharFromPos(wnd
, es
, x
,
1557 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1561 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1562 EDIT_EM_ScrollCaret(wnd
, es
);
1566 /*********************************************************************
1570 * Only for multi line controls
1571 * Move the caret one line up, on a column with the nearest
1572 * x coordinate on the screen (might be a different column).
1575 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1577 INT s
= es
->selection_start
;
1578 INT e
= es
->selection_end
;
1579 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1580 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1581 INT x
= SLOWORD(pos
);
1582 INT y
= SHIWORD(pos
);
1584 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1587 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1588 EDIT_EM_ScrollCaret(wnd
, es
);
1592 /*********************************************************************
1594 * EDIT_MoveWordBackward
1597 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1599 INT s
= es
->selection_start
;
1600 INT e
= es
->selection_end
;
1605 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1606 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1607 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1610 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1611 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1614 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1615 li
, e
- li
, ll
, WB_LEFT
);
1619 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1620 EDIT_EM_ScrollCaret(wnd
, es
);
1624 /*********************************************************************
1626 * EDIT_MoveWordForward
1629 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1631 INT s
= es
->selection_start
;
1632 INT e
= es
->selection_end
;
1637 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1638 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1639 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1641 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1642 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1644 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1645 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1649 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1650 EDIT_EM_ScrollCaret(wnd
, es
);
1654 /*********************************************************************
1659 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1661 INT s
= es
->selection_start
;
1662 INT e
= es
->selection_end
;
1669 if (es
->style
& ES_MULTILINE
) {
1670 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1671 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1676 TRACE(edit
, "line=%d\n", line
);
1678 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1681 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1682 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1683 s
= es
->selection_start
;
1684 e
= es
->selection_end
;
1686 s
= MIN(li
+ ll
, MAX(li
, s
));
1687 e
= MIN(li
+ ll
, MAX(li
, e
));
1688 if (rev
&& (s
!= e
) &&
1689 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1690 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1691 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1692 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1694 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1698 /*********************************************************************
1703 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1713 BkColor
= GetBkColor(dc
);
1714 TextColor
= GetTextColor(dc
);
1716 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1717 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1719 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1720 if (es
->style
& ES_MULTILINE
) {
1721 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1722 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1724 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1725 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1726 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1728 if (es
->style
& ES_PASSWORD
)
1729 HeapFree(es
->heap
, 0, text
);
1732 SetBkColor(dc
, BkColor
);
1733 SetTextColor(dc
, TextColor
);
1739 /*********************************************************************
1744 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1747 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1748 INT x
= SLOWORD(res
);
1749 INT y
= SHIWORD(res
);
1751 if(x
< es
->format_rect
.left
)
1752 x
= es
->format_rect
.left
;
1753 if(x
> es
->format_rect
.right
- 2)
1754 x
= es
->format_rect
.right
- 2;
1755 if(y
> es
->format_rect
.bottom
)
1756 y
= es
->format_rect
.bottom
;
1757 if(y
< es
->format_rect
.top
)
1758 y
= es
->format_rect
.top
;
1764 /*********************************************************************
1768 * note: this is not (exactly) the handler called on EM_SETRECTNP
1769 * it is also used to set the rect of a single line control
1772 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1774 CopyRect(&es
->format_rect
, rc
);
1775 if (es
->style
& WS_BORDER
) {
1776 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1777 if(TWEAK_WineLook
== WIN31_LOOK
)
1779 es
->format_rect
.left
+= bw
;
1780 es
->format_rect
.top
+= bw
;
1781 es
->format_rect
.right
-= bw
;
1782 es
->format_rect
.bottom
-= bw
;
1784 es
->format_rect
.left
+= es
->left_margin
;
1785 es
->format_rect
.right
-= es
->right_margin
;
1786 es
->format_rect
.right
= MAX(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1787 if (es
->style
& ES_MULTILINE
)
1788 es
->format_rect
.bottom
= es
->format_rect
.top
+
1789 MAX(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1791 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1792 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1793 EDIT_BuildLineDefs_ML(wnd
, es
);
1797 /*********************************************************************
1802 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1805 ERR(edit
, "no EDITSTATE ... please report\n");
1808 if (!(es
->style
& ES_MULTILINE
))
1810 if (!es
->lock_count
) {
1811 ERR(edit
, "lock_count == 0 ... please report\n");
1815 ERR(edit
, "es->text == 0 ... please report\n");
1818 if (force
|| (es
->lock_count
== 1)) {
1820 LocalUnlock(es
->hloc32
);
1822 } else if (es
->hloc16
) {
1823 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1831 /*********************************************************************
1833 * EDIT_WordBreakProc
1835 * Find the beginning of words.
1836 * Note: unlike the specs for a WordBreakProc, this function only
1837 * allows to be called without linebreaks between s[0] upto
1838 * s[count - 1]. Remember it is only called
1839 * internally, so we can decide this for ourselves.
1842 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1846 TRACE(edit
, "s=%p, index=%u, count=%u, action=%d\n",
1847 s
, index
, count
, action
);
1855 if (s
[index
] == ' ') {
1856 while (index
&& (s
[index
] == ' '))
1859 while (index
&& (s
[index
] != ' '))
1861 if (s
[index
] == ' ')
1865 while (index
&& (s
[index
] != ' '))
1867 if (s
[index
] == ' ')
1877 if (s
[index
] == ' ')
1878 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1880 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1882 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1886 case WB_ISDELIMITER
:
1887 ret
= (s
[index
] == ' ');
1890 ERR(edit
, "unknown action code, please report !\n");
1897 /*********************************************************************
1901 * returns line number (not index) in high-order word of result.
1902 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1903 * to Richedit, not to the edit control. Original documentation is valid.
1904 * FIXME: do the specs mean to return -1 if outside client area or
1905 * if outside formatting rectangle ???
1908 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1916 GetClientRect(wnd
->hwndSelf
, &rc
);
1917 if (!PtInRect(&rc
, pt
))
1920 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1921 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1925 /*********************************************************************
1929 * Enable or disable soft breaks.
1931 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1933 es
->flags
&= ~EF_USE_SOFTBRK
;
1935 es
->flags
|= EF_USE_SOFTBRK
;
1936 FIXME(edit
, "soft break enabled, not implemented\n");
1942 /*********************************************************************
1946 * Hopefully this won't fire back at us.
1947 * We always start with a fixed buffer in our own heap.
1948 * However, with this message a 32 bit application requests
1949 * a handle to 32 bit moveable local heap memory, where it expects
1951 * It's a pity that from this moment on we have to use this
1952 * local heap, because applications may rely on the handle
1955 * In this function we'll try to switch to local heap.
1958 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1964 if (!(es
->style
& ES_MULTILINE
))
1969 else if (es
->hloc16
)
1970 return (HLOCAL
)es
->hloc16
;
1972 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
1973 ERR(edit
, "could not allocate new 32 bit buffer\n");
1976 newSize
= MIN(LocalSize(newBuf
) - 1, es
->buffer_limit
);
1977 if (!(newText
= LocalLock(newBuf
))) {
1978 ERR(edit
, "could not lock new 32 bit buffer\n");
1982 lstrcpyA(newText
, es
->text
);
1983 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1985 HeapFree(es
->heap
, 0, es
->text
);
1986 es
->hloc32
= newBuf
;
1987 es
->hloc16
= (HLOCAL16
)NULL
;
1988 es
->buffer_size
= newSize
;
1990 EDIT_LockBuffer(wnd
, es
);
1991 TRACE(edit
, "switched to 32 bit local heap\n");
1997 /*********************************************************************
2001 * Hopefully this won't fire back at us.
2002 * We always start with a buffer in 32 bit linear memory.
2003 * However, with this message a 16 bit application requests
2004 * a handle of 16 bit local heap memory, where it expects to find
2006 * It's a pitty that from this moment on we have to use this
2007 * local heap, because applications may rely on the handle
2010 * In this function we'll try to switch to local heap.
2012 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2018 if (!(es
->style
& ES_MULTILINE
))
2024 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2025 if (!LocalInit16(wnd
->hInstance
, 0,
2026 GlobalSize16(wnd
->hInstance
))) {
2027 ERR(edit
, "could not initialize local heap\n");
2030 TRACE(edit
, "local heap initialized\n");
2032 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2033 ERR(edit
, "could not allocate new 16 bit buffer\n");
2036 newSize
= MIN(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2037 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2038 ERR(edit
, "could not lock new 16 bit buffer\n");
2039 LOCAL_Free(wnd
->hInstance
, newBuf
);
2042 lstrcpyA(newText
, es
->text
);
2043 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2045 HeapFree(es
->heap
, 0, es
->text
);
2046 else if (es
->hloc32
) {
2047 while (LocalFree(es
->hloc32
)) ;
2048 LocalFree(es
->hloc32
);
2050 es
->hloc32
= (HLOCAL
)NULL
;
2051 es
->hloc16
= newBuf
;
2052 es
->buffer_size
= newSize
;
2054 EDIT_LockBuffer(wnd
, es
);
2055 TRACE(edit
, "switched to 16 bit buffer\n");
2061 /*********************************************************************
2066 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2072 if (es
->style
& ES_MULTILINE
) {
2073 if (line
>= es
->line_count
)
2077 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2079 len
= MIN(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2080 for (i
= 0 ; i
< len
; i
++) {
2085 return (LRESULT
)len
;
2089 /*********************************************************************
2094 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2096 UINT s
= es
->selection_start
;
2097 UINT e
= es
->selection_end
;
2104 return MAKELONG(s
, e
);
2108 /*********************************************************************
2112 * FIXME: is this right ? (or should it be only VSCROLL)
2113 * (and maybe only for edit controls that really have their
2114 * own scrollbars) (and maybe only for multiline controls ?)
2115 * All in all: very poorly documented
2117 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2118 * WM_VSCROLL handlers
2121 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2123 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2124 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2128 /*********************************************************************
2133 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2138 if (!(es
->style
& ES_MULTILINE
))
2140 if (index
> lstrlenA(es
->text
))
2141 return es
->line_count
- 1;
2143 index
= MIN(es
->selection_start
, es
->selection_end
);
2146 line_def
= es
->first_line_def
;
2147 index
-= line_def
->length
;
2148 while ((index
>= 0) && line_def
->next
) {
2150 line_def
= line_def
->next
;
2151 index
-= line_def
->length
;
2157 /*********************************************************************
2162 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2167 if (!(es
->style
& ES_MULTILINE
))
2169 if (line
>= es
->line_count
)
2173 line_def
= es
->first_line_def
;
2175 INT index
= es
->selection_end
- line_def
->length
;
2176 while ((index
>= 0) && line_def
->next
) {
2177 line_index
+= line_def
->length
;
2178 line_def
= line_def
->next
;
2179 index
-= line_def
->length
;
2183 line_index
+= line_def
->length
;
2184 line_def
= line_def
->next
;
2192 /*********************************************************************
2197 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2201 if (!(es
->style
& ES_MULTILINE
))
2202 return lstrlenA(es
->text
);
2206 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2207 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2208 return es->selection_start - es->line_defs[sl].offset +
2209 es->line_defs[el].offset +
2210 es->line_defs[el].length - es->selection_end;
2214 line_def
= es
->first_line_def
;
2215 index
-= line_def
->length
;
2216 while ((index
>= 0) && line_def
->next
) {
2217 line_def
= line_def
->next
;
2218 index
-= line_def
->length
;
2220 return line_def
->net_length
;
2224 /*********************************************************************
2228 * FIXME: dx is in average character widths
2229 * However, we assume it is in pixels when we use this
2230 * function internally
2233 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2237 if (!(es
->style
& ES_MULTILINE
))
2240 if (-dx
> es
->x_offset
)
2242 if (dx
> es
->text_width
- es
->x_offset
)
2243 dx
= es
->text_width
- es
->x_offset
;
2244 nyoff
= MAX(0, es
->y_offset
+ dy
);
2245 if (nyoff
>= es
->line_count
)
2246 nyoff
= es
->line_count
- 1;
2247 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2251 GetClientRect(wnd
->hwndSelf
, &rc1
);
2252 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2253 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2254 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2255 es
->y_offset
= nyoff
;
2258 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2259 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2260 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2261 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2266 /*********************************************************************
2271 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2273 INT len
= lstrlenA(es
->text
);
2282 index
= MIN(index
, len
);
2283 dc
= GetDC(wnd
->hwndSelf
);
2285 old_font
= SelectObject(dc
, es
->font
);
2286 if (es
->style
& ES_MULTILINE
) {
2287 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2288 y
= (l
- es
->y_offset
) * es
->line_height
;
2289 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2290 if (after_wrap
&& (li
== index
) && l
) {
2292 LINEDEF
*line_def
= es
->first_line_def
;
2294 line_def
= line_def
->next
;
2297 if (line_def
->ending
== END_WRAP
) {
2299 y
-= es
->line_height
;
2300 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2303 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2304 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2306 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2307 if (index
< es
->x_offset
) {
2308 GetTextExtentPoint32A(dc
, text
+ index
,
2309 es
->x_offset
- index
, &size
);
2312 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2313 index
- es
->x_offset
, &size
);
2317 if (es
->style
& ES_PASSWORD
)
2318 HeapFree(es
->heap
, 0 ,text
);
2320 x
+= es
->format_rect
.left
;
2321 y
+= es
->format_rect
.top
;
2323 SelectObject(dc
, old_font
);
2324 ReleaseDC(wnd
->hwndSelf
, dc
);
2325 return MAKELONG((INT16
)x
, (INT16
)y
);
2329 /*********************************************************************
2333 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2336 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2338 INT strl
= lstrlenA(lpsz_replace
);
2339 INT tl
= lstrlenA(es
->text
);
2346 s
= es
->selection_start
;
2347 e
= es
->selection_end
;
2349 if ((s
== e
) && !strl
)
2354 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2358 /* there is something to be deleted */
2360 utl
= lstrlenA(es
->undo_text
);
2361 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2362 /* undo-buffer is extended to the right */
2363 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2364 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2365 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2366 /* undo-buffer is extended to the left */
2367 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2368 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2370 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2371 p
[i
] = (es
->text
+ s
)[i
];
2372 es
->undo_position
= s
;
2374 /* new undo-buffer */
2375 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2376 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2377 es
->undo_position
= s
;
2379 /* any deletion makes the old insertion-undo invalid */
2380 es
->undo_insert_count
= 0;
2382 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2385 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2388 /* there is an insertion */
2390 if ((s
== es
->undo_position
) ||
2391 ((es
->undo_insert_count
) &&
2392 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2394 * insertion is new and at delete position or
2395 * an extension to either left or right
2397 es
->undo_insert_count
+= strl
;
2399 /* new insertion undo */
2400 es
->undo_position
= s
;
2401 es
->undo_insert_count
= strl
;
2402 /* new insertion makes old delete-buffer invalid */
2403 *es
->undo_text
= '\0';
2406 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2409 tl
= lstrlenA(es
->text
);
2410 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2412 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2413 p
[i
] = lpsz_replace
[i
];
2414 if(es
->style
& ES_UPPERCASE
)
2415 CharUpperBuffA(p
, strl
);
2416 else if(es
->style
& ES_LOWERCASE
)
2417 CharLowerBuffA(p
, strl
);
2420 /* FIXME: really inefficient */
2421 if (es
->style
& ES_MULTILINE
)
2422 EDIT_BuildLineDefs_ML(wnd
, es
);
2424 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2425 es
->flags
|= EF_MODIFIED
;
2426 es
->flags
|= EF_UPDATE
;
2427 EDIT_EM_ScrollCaret(wnd
, es
);
2429 /* FIXME: really inefficient */
2430 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2434 /*********************************************************************
2439 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2443 if (!(es
->style
& ES_MULTILINE
))
2444 return (LRESULT
)FALSE
;
2454 if (es
->y_offset
< es
->line_count
- 1)
2459 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2462 if (es
->y_offset
< es
->line_count
- 1)
2463 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2466 return (LRESULT
)FALSE
;
2469 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2470 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2472 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2476 /*********************************************************************
2481 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2483 if (es
->style
& ES_MULTILINE
) {
2488 INT cw
= es
->char_width
;
2493 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2494 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2495 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2496 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2497 if (l
>= es
->y_offset
+ vlc
)
2498 dy
= l
- vlc
+ 1 - es
->y_offset
;
2499 if (l
< es
->y_offset
)
2500 dy
= l
- es
->y_offset
;
2501 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2502 if (x
< es
->format_rect
.left
)
2503 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2504 if (x
> es
->format_rect
.right
)
2505 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2507 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2513 if (!(es
->style
& ES_AUTOHSCROLL
))
2516 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2517 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2518 if (x
< es
->format_rect
.left
) {
2519 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2522 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2523 } while ((x
< goal
) && es
->x_offset
);
2524 /* FIXME: use ScrollWindow() somehow to improve performance */
2525 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2526 } else if (x
> es
->format_rect
.right
) {
2528 INT len
= lstrlenA(es
->text
);
2529 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2532 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2533 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2534 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2535 /* FIXME: use ScrollWindow() somehow to improve performance */
2536 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2542 /*********************************************************************
2546 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2549 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2551 if (!(es
->style
& ES_MULTILINE
))
2555 WARN(edit
, "called with NULL handle\n");
2559 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2561 * old buffer is freed by caller, unless
2562 * it is still in our own heap. (in that case
2563 * we free it, correcting the buggy caller.)
2566 HeapFree(es
->heap
, 0, es
->text
);
2568 es
->hloc16
= (HLOCAL16
)NULL
;
2571 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2572 EDIT_LockBuffer(wnd
, es
);
2574 es
->x_offset
= es
->y_offset
= 0;
2575 es
->selection_start
= es
->selection_end
= 0;
2576 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2577 es
->flags
&= ~EF_MODIFIED
;
2578 es
->flags
&= ~EF_UPDATE
;
2579 EDIT_BuildLineDefs_ML(wnd
, es
);
2580 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2581 EDIT_EM_ScrollCaret(wnd
, es
);
2585 /*********************************************************************
2589 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2592 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2594 if (!(es
->style
& ES_MULTILINE
))
2598 WARN(edit
, "called with NULL handle\n");
2602 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2604 * old buffer is freed by caller, unless
2605 * it is still in our own heap. (in that case
2606 * we free it, correcting the buggy caller.)
2609 HeapFree(es
->heap
, 0, es
->text
);
2612 es
->hloc32
= (HLOCAL
)NULL
;
2614 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2615 EDIT_LockBuffer(wnd
, es
);
2617 es
->x_offset
= es
->y_offset
= 0;
2618 es
->selection_start
= es
->selection_end
= 0;
2619 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2620 es
->flags
&= ~EF_MODIFIED
;
2621 es
->flags
&= ~EF_UPDATE
;
2622 EDIT_BuildLineDefs_ML(wnd
, es
);
2623 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2624 EDIT_EM_ScrollCaret(wnd
, es
);
2628 /*********************************************************************
2632 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2633 * However, the windows version is not complied to yet in all of edit.c
2636 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2638 if (es
->style
& ES_MULTILINE
) {
2640 es
->buffer_limit
= MIN(limit
, BUFLIMIT_MULTI
);
2642 es
->buffer_limit
= BUFLIMIT_MULTI
;
2645 es
->buffer_limit
= MIN(limit
, BUFLIMIT_SINGLE
);
2647 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2652 /*********************************************************************
2656 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2657 * action wParam despite what the docs say. It also appears not to affect
2658 * multiline controls??
2661 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2662 INT left
, INT right
)
2664 if (action
& EC_LEFTMARGIN
) {
2665 if (left
!= EC_USEFONTINFO
)
2666 es
->left_margin
= left
;
2668 if (es
->style
& ES_MULTILINE
)
2669 es
->left_margin
= 0; /* ?? */
2671 es
->left_margin
= es
->char_width
;
2674 if (action
& EC_RIGHTMARGIN
) {
2675 if (right
!= EC_USEFONTINFO
)
2676 es
->right_margin
= right
;
2678 if (es
->style
& ES_MULTILINE
)
2679 es
->right_margin
= 0; /* ?? */
2681 es
->right_margin
= es
->char_width
;
2683 TRACE(edit
, "left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2687 /*********************************************************************
2689 * EM_SETPASSWORDCHAR
2692 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2694 if (es
->style
& ES_MULTILINE
)
2697 if (es
->password_char
== c
)
2700 es
->password_char
= c
;
2702 wnd
->dwStyle
|= ES_PASSWORD
;
2703 es
->style
|= ES_PASSWORD
;
2705 wnd
->dwStyle
&= ~ES_PASSWORD
;
2706 es
->style
&= ~ES_PASSWORD
;
2708 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2712 /*********************************************************************
2716 * note: unlike the specs say: the order of start and end
2717 * _is_ preserved in Windows. (i.e. start can be > end)
2718 * In other words: this handler is OK
2721 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2723 UINT old_start
= es
->selection_start
;
2724 UINT old_end
= es
->selection_end
;
2725 UINT len
= lstrlenA(es
->text
);
2728 start
= es
->selection_end
;
2729 end
= es
->selection_end
;
2731 start
= MIN(start
, len
);
2732 end
= MIN(end
, len
);
2734 es
->selection_start
= start
;
2735 es
->selection_end
= end
;
2737 es
->flags
|= EF_AFTER_WRAP
;
2739 es
->flags
&= ~EF_AFTER_WRAP
;
2740 if (es
->flags
& EF_FOCUSED
)
2741 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2742 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2743 ORDER_UINT(start
, end
);
2744 ORDER_UINT(end
, old_end
);
2745 ORDER_UINT(start
, old_start
);
2746 ORDER_UINT(old_start
, old_end
);
2747 if (end
!= old_start
)
2751 * ORDER_UINT32(end, old_start);
2752 * EDIT_InvalidateText(wnd, es, start, end);
2753 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2754 * in place of the following if statement.
2756 if (old_start
> end
)
2758 EDIT_InvalidateText(wnd
, es
, start
, end
);
2759 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2763 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2764 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2767 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2771 /*********************************************************************
2776 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2778 if (!(es
->style
& ES_MULTILINE
))
2781 HeapFree(es
->heap
, 0, es
->tabs
);
2782 es
->tabs_count
= count
;
2786 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2787 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2793 /*********************************************************************
2798 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2800 if (!(es
->style
& ES_MULTILINE
))
2803 HeapFree(es
->heap
, 0, es
->tabs
);
2804 es
->tabs_count
= count
;
2809 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2810 for (i
= 0 ; i
< count
; i
++)
2811 es
->tabs
[i
] = *tabs
++;
2817 /*********************************************************************
2819 * EM_SETWORDBREAKPROC
2822 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2824 if (es
->word_break_proc32A
== wbp
)
2827 es
->word_break_proc32A
= wbp
;
2828 es
->word_break_proc16
= NULL
;
2829 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2830 EDIT_BuildLineDefs_ML(wnd
, es
);
2831 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2836 /*********************************************************************
2838 * EM_SETWORDBREAKPROC16
2841 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2843 if (es
->word_break_proc16
== wbp
)
2846 es
->word_break_proc32A
= NULL
;
2847 es
->word_break_proc16
= wbp
;
2848 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2849 EDIT_BuildLineDefs_ML(wnd
, es
);
2850 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2855 /*********************************************************************
2860 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2862 INT ulength
= lstrlenA(es
->undo_text
);
2863 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2865 lstrcpyA(utext
, es
->undo_text
);
2867 TRACE(edit
, "before UNDO:insertion length = %d, deletion buffer = %s\n",
2868 es
->undo_insert_count
, utext
);
2870 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2871 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2872 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2873 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2874 HeapFree(es
->heap
, 0, utext
);
2876 TRACE(edit
, "after UNDO:insertion length = %d, deletion buffer = %s\n",
2877 es
->undo_insert_count
, es
->undo_text
);
2883 /*********************************************************************
2888 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2893 if (es
->style
& ES_MULTILINE
) {
2894 if (es
->style
& ES_READONLY
) {
2895 EDIT_MoveHome(wnd
, es
, FALSE
);
2896 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2898 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2902 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2903 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2906 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2910 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2917 /*********************************************************************
2922 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
2924 if (code
|| control
)
2929 EDIT_EM_Undo(wnd
, es
);
2932 EDIT_WM_Cut(wnd
, es
);
2935 EDIT_WM_Copy(wnd
, es
);
2938 EDIT_WM_Paste(wnd
, es
);
2941 EDIT_WM_Clear(wnd
, es
);
2944 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
2945 EDIT_EM_ScrollCaret(wnd
, es
);
2948 ERR(edit
, "unknown menu item, please report\n");
2954 /*********************************************************************
2958 * Note: the resource files resource/sysres_??.rc cannot define a
2959 * single popup menu. Hence we use a (dummy) menubar
2960 * containing the single popup menu as its first item.
2962 * FIXME: the message identifiers have been chosen arbitrarily,
2963 * hence we use MF_BYPOSITION.
2964 * We might as well use the "real" values (anybody knows ?)
2965 * The menu definition is in resources/sysres_??.rc.
2966 * Once these are OK, we better use MF_BYCOMMAND here
2967 * (as we do in EDIT_WM_Command()).
2970 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
2972 HMENU menu
= LoadMenuIndirectA(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU
));
2973 HMENU popup
= GetSubMenu(menu
, 0);
2974 UINT start
= es
->selection_start
;
2975 UINT end
= es
->selection_end
;
2977 ORDER_UINT(start
, end
);
2980 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
2982 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2984 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2986 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
2988 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
2990 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
2992 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
2997 /*********************************************************************
3002 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3004 INT s
= es
->selection_start
;
3005 INT e
= es
->selection_end
;
3012 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3013 dst
= GlobalLock(hdst
);
3014 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3016 OpenClipboard(wnd
->hwndSelf
);
3018 SetClipboardData(CF_TEXT
, hdst
);
3023 /*********************************************************************
3028 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3031 * To initialize some final structure members, we call some helper
3032 * functions. However, since the EDITSTATE is not consistent (i.e.
3033 * not fully initialized), we should be very careful which
3034 * functions can be called, and in what order.
3036 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3037 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3039 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3040 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3041 /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */
3042 es
->selection_start
= es
->selection_end
= 0;
3043 EDIT_EM_ScrollCaret(wnd
, es
);
3049 /*********************************************************************
3054 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3057 while (LocalUnlock(es
->hloc32
)) ;
3058 LocalFree(es
->hloc32
);
3061 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3062 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3064 HeapDestroy(es
->heap
);
3065 HeapFree(GetProcessHeap(), 0, es
);
3066 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3070 /*********************************************************************
3075 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3080 if (!(brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
)))
3081 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3083 GetClientRect(wnd
->hwndSelf
, &rc
);
3084 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3085 GetClipBox(dc
, &rc
);
3087 * FIXME: specs say that we should UnrealizeObject() the brush,
3088 * but the specs of UnrealizeObject() say that we shouldn't
3089 * unrealize a stock object. The default brush that
3090 * DefWndProc() returns is ... a stock object.
3092 FillRect(dc
, &rc
, brush
);
3097 /*********************************************************************
3102 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3104 INT len
= lstrlenA(es
->text
);
3107 lstrcpyA(text
, es
->text
);
3114 /*********************************************************************
3118 * 16 bit notepad needs this. Actually it is not _our_ hack,
3119 * it is notepad's. Notepad is sending us scrollbar messages with
3120 * undocumented parameters without us even having a scrollbar ... !?!?
3123 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3126 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3129 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3130 ERR(edit
, "hacked WM_HSCROLL handler invoked\n");
3131 ERR(edit
, " if you are _not_ running 16 bit notepad, please report\n");
3132 ERR(edit
, " (this message is only displayed once per edit control)\n");
3133 es
->flags
|= EF_HSCROLL_HACK
;
3139 dx
= -es
->char_width
;
3142 if (es
->x_offset
< es
->text_width
)
3143 dx
= es
->char_width
;
3147 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3150 if (es
->x_offset
< es
->text_width
)
3151 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3158 if (es
->x_offset
< es
->text_width
)
3159 dx
= es
->text_width
- es
->x_offset
;
3162 es
->flags
|= EF_HSCROLL_TRACK
;
3163 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3165 case SB_THUMBPOSITION
:
3166 es
->flags
&= ~EF_HSCROLL_TRACK
;
3167 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3168 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3174 * FIXME : the next two are undocumented !
3175 * Are we doing the right thing ?
3176 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3177 * although it's also a regular control message.
3180 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3182 case EM_LINESCROLL16
:
3187 ERR(edit
, "undocumented (hacked) WM_HSCROLL parameter, please report\n");
3191 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3196 /*********************************************************************
3201 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3206 if (!(es
->style
& ES_MULTILINE
))
3209 if (!(es
->style
& ES_AUTOHSCROLL
))
3212 if (!(es
->style
& WS_HSCROLL
))
3213 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3216 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3220 dx
= -es
->char_width
;
3223 if (es
->x_offset
< es
->text_width
)
3224 dx
= es
->char_width
;
3228 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3231 if (es
->x_offset
< es
->text_width
)
3232 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3239 if (es
->x_offset
< es
->text_width
)
3240 dx
= es
->text_width
- es
->x_offset
;
3243 es
->flags
|= EF_HSCROLL_TRACK
;
3244 dx
= pos
- es
->x_offset
;
3246 case SB_THUMBPOSITION
:
3247 es
->flags
&= ~EF_HSCROLL_TRACK
;
3248 if (!(dx
= pos
- es
->x_offset
)) {
3249 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3250 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3257 ERR(edit
, "undocumented WM_HSCROLL parameter, please report\n");
3261 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3266 /*********************************************************************
3271 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3275 if (WIDGETS_IsControl(wnd
->parent
, BIC32_COMBO
) &&
3276 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3277 HWND hCombo
= wnd
->parent
->hwndSelf
;
3278 BOOL bUIFlip
= TRUE
;
3280 TRACE(combo
, "[%04x]: handling msg %04x (%04x)\n",
3281 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3284 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3286 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3287 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3291 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3293 /* make sure ComboLBox pops up */
3294 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3295 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3296 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3299 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3300 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3302 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3303 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3305 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3314 /*********************************************************************
3318 * Handling of special keys that don't produce a WM_CHAR
3319 * (i.e. non-printable keys) & Backspace & Delete
3322 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3327 if (GetKeyState(VK_MENU
) & 0x8000)
3330 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3331 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3336 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3342 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3343 EDIT_MoveUp_ML(wnd
, es
, shift
);
3346 EDIT_MoveWordBackward(wnd
, es
, shift
);
3348 EDIT_MoveBackward(wnd
, es
, shift
);
3351 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3355 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3356 EDIT_MoveDown_ML(wnd
, es
, shift
);
3358 EDIT_MoveWordForward(wnd
, es
, shift
);
3360 EDIT_MoveForward(wnd
, es
, shift
);
3363 EDIT_MoveHome(wnd
, es
, shift
);
3366 EDIT_MoveEnd(wnd
, es
, shift
);
3369 if (es
->style
& ES_MULTILINE
)
3370 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3373 if (es
->style
& ES_MULTILINE
)
3374 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3377 if (!(es
->style
& ES_READONLY
) && !control
) {
3378 if (es
->selection_start
!= es
->selection_end
)
3379 EDIT_WM_Clear(wnd
, es
);
3381 /* delete character left of caret */
3382 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3383 EDIT_MoveBackward(wnd
, es
, TRUE
);
3384 EDIT_WM_Clear(wnd
, es
);
3389 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3390 if (es
->selection_start
!= es
->selection_end
) {
3392 EDIT_WM_Cut(wnd
, es
);
3394 EDIT_WM_Clear(wnd
, es
);
3397 /* delete character left of caret */
3398 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3399 EDIT_MoveBackward(wnd
, es
, TRUE
);
3400 EDIT_WM_Clear(wnd
, es
);
3401 } else if (control
) {
3402 /* delete to end of line */
3403 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3404 EDIT_MoveEnd(wnd
, es
, TRUE
);
3405 EDIT_WM_Clear(wnd
, es
);
3407 /* delete character right of caret */
3408 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3409 EDIT_MoveForward(wnd
, es
, TRUE
);
3410 EDIT_WM_Clear(wnd
, es
);
3417 if (!(es
->style
& ES_READONLY
))
3418 EDIT_WM_Paste(wnd
, es
);
3420 EDIT_WM_Copy(wnd
, es
);
3427 /*********************************************************************
3432 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3434 es
->flags
&= ~EF_FOCUSED
;
3436 if(!(es
->style
& ES_NOHIDESEL
))
3437 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3438 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3443 /*********************************************************************
3447 * The caret position has been set on the WM_LBUTTONDOWN message
3450 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3453 INT e
= es
->selection_end
;
3458 if (!(es
->flags
& EF_FOCUSED
))
3461 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3462 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3463 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3464 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3465 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3466 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3467 EDIT_EM_ScrollCaret(wnd
, es
);
3472 /*********************************************************************
3477 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3482 if (!(es
->flags
& EF_FOCUSED
))
3485 SetCapture(wnd
->hwndSelf
);
3486 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3487 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3488 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3489 EDIT_EM_ScrollCaret(wnd
, es
);
3490 es
->region_posx
= es
->region_posy
= 0;
3491 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3496 /*********************************************************************
3501 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3503 if (GetCapture() == wnd
->hwndSelf
) {
3504 KillTimer(wnd
->hwndSelf
, 0);
3511 /*********************************************************************
3516 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3522 if (GetCapture() != wnd
->hwndSelf
)
3526 * FIXME: gotta do some scrolling if outside client
3527 * area. Maybe reset the timer ?
3530 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3531 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3532 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3533 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3534 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3539 /*********************************************************************
3544 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3548 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3550 *(EDITSTATE
**)wnd
->wExtra
= es
;
3553 * Note: since the EDITSTATE has not been fully initialized yet,
3554 * we can't use any API calls that may send
3555 * WM_XXX messages before WM_NCCREATE is completed.
3558 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3560 es
->style
= cs
->style
;
3562 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3563 wnd
->dwStyle
&= ~WS_BORDER
;
3565 if (es
->style
& ES_MULTILINE
) {
3566 es
->buffer_size
= BUFSTART_MULTI
;
3567 es
->buffer_limit
= BUFLIMIT_MULTI
;
3568 if (es
->style
& WS_VSCROLL
)
3569 es
->style
|= ES_AUTOVSCROLL
;
3570 if (es
->style
& WS_HSCROLL
)
3571 es
->style
|= ES_AUTOHSCROLL
;
3572 es
->style
&= ~ES_PASSWORD
;
3573 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3574 if (es
->style
& ES_RIGHT
)
3575 es
->style
&= ~ES_CENTER
;
3576 es
->style
&= ~WS_HSCROLL
;
3577 es
->style
&= ~ES_AUTOHSCROLL
;
3580 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3581 es
->style
|= ES_AUTOVSCROLL
;
3583 es
->buffer_size
= BUFSTART_SINGLE
;
3584 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3585 es
->style
&= ~ES_CENTER
;
3586 es
->style
&= ~ES_RIGHT
;
3587 es
->style
&= ~WS_HSCROLL
;
3588 es
->style
&= ~WS_VSCROLL
;
3589 es
->style
&= ~ES_AUTOVSCROLL
;
3590 es
->style
&= ~ES_WANTRETURN
;
3591 if (es
->style
& ES_UPPERCASE
) {
3592 es
->style
&= ~ES_LOWERCASE
;
3593 es
->style
&= ~ES_NUMBER
;
3594 } else if (es
->style
& ES_LOWERCASE
)
3595 es
->style
&= ~ES_NUMBER
;
3596 if (es
->style
& ES_PASSWORD
)
3597 es
->password_char
= '*';
3599 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3600 es
->style
|= ES_AUTOHSCROLL
;
3602 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3604 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3605 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3607 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3609 if (es
->style
& ES_MULTILINE
)
3610 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3617 /*********************************************************************
3622 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
)
3631 BOOL rev
= IsWindowEnabled(wnd
->hwndSelf
) &&
3632 ((es
->flags
& EF_FOCUSED
) ||
3633 (es
->style
& ES_NOHIDESEL
));
3635 if (es
->flags
& EF_UPDATE
)
3636 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3638 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3639 if(es
->style
& WS_BORDER
) {
3640 GetClientRect(wnd
->hwndSelf
, &rc
);
3641 if(es
->style
& ES_MULTILINE
) {
3642 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3643 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3645 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3647 IntersectClipRect(dc
, es
->format_rect
.left
,
3648 es
->format_rect
.top
,
3649 es
->format_rect
.right
,
3650 es
->format_rect
.bottom
);
3651 if (es
->style
& ES_MULTILINE
) {
3652 GetClientRect(wnd
->hwndSelf
, &rc
);
3653 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3656 old_font
= SelectObject(dc
, es
->font
);
3657 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3658 if (!IsWindowEnabled(wnd
->hwndSelf
))
3659 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3660 GetClipBox(dc
, &rcRgn
);
3661 if (es
->style
& ES_MULTILINE
) {
3662 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3663 for (i
= es
->y_offset
; i
<= MIN(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3664 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3665 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3666 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3669 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3670 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3671 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3674 SelectObject(dc
, old_font
);
3675 if (es
->flags
& EF_FOCUSED
)
3676 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3677 es
->flags
& EF_AFTER_WRAP
);
3678 EndPaint(wnd
->hwndSelf
, &ps
);
3679 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3680 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3682 si
.cbSize
= sizeof(SCROLLINFO
);
3683 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3685 si
.nMax
= es
->line_count
+ vlc
- 2;
3687 si
.nPos
= es
->y_offset
;
3688 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3690 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3692 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3693 si
.cbSize
= sizeof(SCROLLINFO
);
3694 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3696 si
.nMax
= es
->text_width
+ fw
- 1;
3698 si
.nPos
= es
->x_offset
;
3699 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3702 if (es
->flags
& EF_UPDATE
) {
3703 es
->flags
&= ~EF_UPDATE
;
3704 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3709 /*********************************************************************
3714 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3719 OpenClipboard(wnd
->hwndSelf
);
3720 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3721 src
= (LPSTR
)GlobalLock(hsrc
);
3722 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3729 /*********************************************************************
3734 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3736 es
->flags
|= EF_FOCUSED
;
3737 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3738 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3739 es
->flags
& EF_AFTER_WRAP
);
3740 if(!(es
->style
& ES_NOHIDESEL
))
3741 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3742 ShowCaret(wnd
->hwndSelf
);
3743 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3747 /*********************************************************************
3751 * With Win95 look the margins are set to default font value unless
3752 * the system font (font == 0) is being set, in which case they are left
3756 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3763 dc
= GetDC(wnd
->hwndSelf
);
3765 old_font
= SelectObject(dc
, font
);
3766 GetTextMetricsA(dc
, &tm
);
3767 es
->line_height
= tm
.tmHeight
;
3768 es
->char_width
= tm
.tmAveCharWidth
;
3770 SelectObject(dc
, old_font
);
3771 ReleaseDC(wnd
->hwndSelf
, dc
);
3772 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3773 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3774 EC_USEFONTINFO
, EC_USEFONTINFO
);
3775 if (es
->style
& ES_MULTILINE
)
3776 EDIT_BuildLineDefs_ML(wnd
, es
);
3779 GetClientRect(wnd
->hwndSelf
, &r
);
3780 EDIT_SetRectNP(wnd
, es
, &r
);
3783 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3784 if (es
->flags
& EF_FOCUSED
) {
3786 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3787 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3788 es
->flags
& EF_AFTER_WRAP
);
3789 ShowCaret(wnd
->hwndSelf
);
3794 /*********************************************************************
3799 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3800 * The modified flag is reset. No notifications are sent.
3802 * For single-line controls, reception of WM_SETTEXT triggers:
3803 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3806 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3808 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3810 TRACE(edit
, "\t'%s'\n", text
);
3811 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3813 TRACE(edit
, "\t<NULL>\n");
3814 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3817 if (es
->style
& ES_MULTILINE
) {
3818 es
->flags
&= ~EF_UPDATE
;
3820 es
->flags
|= EF_UPDATE
;
3822 es
->flags
&= ~EF_MODIFIED
;
3823 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3824 EDIT_EM_ScrollCaret(wnd
, es
);
3828 /*********************************************************************
3833 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3835 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3837 SetRect(&rc
, 0, 0, width
, height
);
3838 EDIT_SetRectNP(wnd
, es
, &rc
);
3839 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3844 /*********************************************************************
3849 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3851 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3852 if (EDIT_EM_CanUndo(wnd
, es
))
3853 EDIT_EM_Undo(wnd
, es
);
3855 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3856 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3858 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
3862 /*********************************************************************
3867 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
3869 if (es
->region_posx
< 0) {
3870 EDIT_MoveBackward(wnd
, es
, TRUE
);
3871 } else if (es
->region_posx
> 0) {
3872 EDIT_MoveForward(wnd
, es
, TRUE
);
3875 * FIXME: gotta do some vertical scrolling here, like
3876 * EDIT_EM_LineScroll(wnd, 0, 1);
3881 /*********************************************************************
3885 * 16 bit notepad needs this. Actually it is not _our_ hack,
3886 * it is notepad's. Notepad is sending us scrollbar messages with
3887 * undocumented parameters without us even having a scrollbar ... !?!?
3890 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3895 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3896 ERR(edit
, "hacked WM_VSCROLL handler invoked\n");
3897 ERR(edit
, " if you are _not_ running 16 bit notepad, please report\n");
3898 ERR(edit
, " (this message is only displayed once per edit control)\n");
3899 es
->flags
|= EF_VSCROLL_HACK
;
3907 EDIT_EM_Scroll(wnd
, es
, action
);
3913 dy
= es
->line_count
- 1 - es
->y_offset
;
3916 es
->flags
|= EF_VSCROLL_TRACK
;
3917 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
3919 case SB_THUMBPOSITION
:
3920 es
->flags
&= ~EF_VSCROLL_TRACK
;
3921 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
3922 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3928 * FIXME : the next two are undocumented !
3929 * Are we doing the right thing ?
3930 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3931 * although it's also a regular control message.
3934 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
3936 case EM_LINESCROLL16
:
3941 ERR(edit
, "undocumented (hacked) WM_VSCROLL parameter, please report\n");
3945 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
3950 /*********************************************************************
3955 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3959 if (!(es
->style
& ES_MULTILINE
))
3962 if (!(es
->style
& ES_AUTOVSCROLL
))
3965 if (!(es
->style
& WS_VSCROLL
))
3966 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3974 EDIT_EM_Scroll(wnd
, es
, action
);
3981 dy
= es
->line_count
- 1 - es
->y_offset
;
3984 es
->flags
|= EF_VSCROLL_TRACK
;
3985 dy
= pos
- es
->y_offset
;
3987 case SB_THUMBPOSITION
:
3988 es
->flags
&= ~EF_VSCROLL_TRACK
;
3989 if (!(dy
= pos
- es
->y_offset
)) {
3990 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
3991 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3998 ERR(edit
, "undocumented WM_VSCROLL action %d, please report\n",
4003 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);