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", \
114 /* used for disabled or read-only edit control */
115 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
116 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
117 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
118 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
119 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
120 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
121 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
122 (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \
123 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
124 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
125 (LPARAM)(wnd)->hwndSelf))
126 #define DPRINTF_EDIT_MSG16(str) \
128 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
129 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
130 #define DPRINTF_EDIT_MSG32(str) \
132 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
133 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
135 /*********************************************************************
142 * These functions have trivial implementations
143 * We still like to call them internally
144 * "static __inline__" makes them more like macro's
146 static __inline__ BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
147 static __inline__
void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
148 static __inline__
void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
149 static __inline__
void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
151 * This is the only exported function
153 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
154 WPARAM wParam
, LPARAM lParam
);
156 * Helper functions only valid for one type of control
158 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
159 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
160 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
161 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
162 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
163 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
165 * Helper functions valid for both single line _and_ multi line controls
167 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
168 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
169 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
170 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
171 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
172 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
173 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
174 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
175 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
176 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
177 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
178 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
179 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
180 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
181 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
182 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
183 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
184 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
185 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
186 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
188 * EM_XXX message handlers
190 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
191 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
192 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
193 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
194 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
195 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
196 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
197 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
198 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
199 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
200 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
201 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
202 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
203 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
204 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
205 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
206 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
207 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
208 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
209 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
210 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
211 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
212 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
213 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
214 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
215 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
217 * WM_XXX message handlers
219 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
220 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
221 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
222 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
223 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
224 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
225 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
226 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
227 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
228 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
229 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
230 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
231 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
232 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
233 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
234 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
235 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
);
236 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
237 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
238 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
239 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
240 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
241 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
242 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
243 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
246 /*********************************************************************
251 static __inline__ BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
253 return (es
->undo_insert_count
|| lstrlenA(es
->undo_text
));
257 /*********************************************************************
262 static __inline__
void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
264 es
->undo_insert_count
= 0;
265 *es
->undo_text
= '\0';
269 /*********************************************************************
274 static __inline__
void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
276 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
280 /*********************************************************************
285 static __inline__
void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
287 EDIT_WM_Copy(wnd
, es
);
288 EDIT_WM_Clear(wnd
, es
);
292 /*********************************************************************
296 * The messages are in the order of the actual integer values
297 * (which can be found in include/windows.h)
298 * Whereever possible the 16 bit versions are converted to
299 * the 32 bit ones, so that we can 'fall through' to the
300 * helper functions. These are mostly 32 bit (with a few
301 * exceptions, clearly indicated by a '16' extension to their
305 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
306 WPARAM wParam
, LPARAM lParam
)
308 WND
*wnd
= WIN_FindWndPtr(hwnd
);
309 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
314 DPRINTF_EDIT_MSG32("WM_DESTROY");
315 EDIT_WM_Destroy(wnd
, es
);
320 DPRINTF_EDIT_MSG32("WM_NCCREATE");
321 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
327 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
332 EDIT_LockBuffer(wnd
, es
);
335 DPRINTF_EDIT_MSG16("EM_GETSEL");
340 DPRINTF_EDIT_MSG32("EM_GETSEL");
341 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
345 DPRINTF_EDIT_MSG16("EM_SETSEL");
346 if (SLOWORD(lParam
) == -1)
347 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
349 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
351 EDIT_EM_ScrollCaret(wnd
, es
);
355 DPRINTF_EDIT_MSG32("EM_SETSEL");
356 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
361 DPRINTF_EDIT_MSG16("EM_GETRECT");
363 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
366 DPRINTF_EDIT_MSG32("EM_GETRECT");
368 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
372 DPRINTF_EDIT_MSG16("EM_SETRECT");
373 if ((es
->style
& ES_MULTILINE
) && lParam
) {
375 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
376 EDIT_SetRectNP(wnd
, es
, &rc
);
377 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
381 DPRINTF_EDIT_MSG32("EM_SETRECT");
382 if ((es
->style
& ES_MULTILINE
) && lParam
) {
383 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
384 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
389 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
390 if ((es
->style
& ES_MULTILINE
) && lParam
) {
392 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
393 EDIT_SetRectNP(wnd
, es
, &rc
);
397 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
398 if ((es
->style
& ES_MULTILINE
) && lParam
)
399 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
403 DPRINTF_EDIT_MSG16("EM_SCROLL");
406 DPRINTF_EDIT_MSG32("EM_SCROLL");
407 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
410 case EM_LINESCROLL16
:
411 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
412 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
413 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
416 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
417 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
420 case EM_SCROLLCARET16
:
421 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
424 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
425 EDIT_EM_ScrollCaret(wnd
, es
);
430 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
433 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
434 return ((es
->flags
& EF_MODIFIED
) != 0);
438 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
441 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
443 es
->flags
|= EF_MODIFIED
;
445 es
->flags
&= ~EF_MODIFIED
;
448 case EM_GETLINECOUNT16
:
449 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
451 case EM_GETLINECOUNT
:
452 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
453 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
457 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
458 if ((INT16
)wParam
== -1)
462 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
463 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
467 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
468 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
471 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
472 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
476 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
477 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
480 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
481 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
485 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
488 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
489 result
= EDIT_EM_GetThumb(wnd
, es
);
492 /* messages 0x00bf and 0x00c0 missing from specs */
495 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
498 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
499 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
503 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
506 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
507 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
510 case EM_LINELENGTH16
:
511 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
514 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
515 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
518 case EM_REPLACESEL16
:
519 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
520 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
523 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
524 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
528 /* message 0x00c3 missing from specs */
531 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
534 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
535 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
539 DPRINTF_EDIT_MSG16("EM_GETLINE");
540 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
543 DPRINTF_EDIT_MSG32("EM_GETLINE");
544 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
548 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
550 case EM_SETLIMITTEXT
:
551 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
552 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
556 DPRINTF_EDIT_MSG16("EM_CANUNDO");
559 DPRINTF_EDIT_MSG32("EM_CANUNDO");
560 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
564 DPRINTF_EDIT_MSG16("EM_UNDO");
569 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
570 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
574 DPRINTF_EDIT_MSG16("EM_FMTLINES");
577 DPRINTF_EDIT_MSG32("EM_FMTLINES");
578 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
581 case EM_LINEFROMCHAR16
:
582 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
584 case EM_LINEFROMCHAR
:
585 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
586 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
589 /* message 0x00ca missing from specs */
592 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
595 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
596 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
599 case EM_SETTABSTOPS16
:
600 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
601 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
604 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
605 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
608 case EM_SETPASSWORDCHAR16
:
609 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
611 case EM_SETPASSWORDCHAR
:
612 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
613 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
616 case EM_EMPTYUNDOBUFFER16
:
617 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
619 case EM_EMPTYUNDOBUFFER
:
620 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
621 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
624 case EM_GETFIRSTVISIBLELINE16
:
625 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
626 result
= es
->y_offset
;
628 case EM_GETFIRSTVISIBLELINE
:
629 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
630 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
633 case EM_SETREADONLY16
:
634 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
637 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
639 wnd
->dwStyle
|= ES_READONLY
;
640 es
->style
|= ES_READONLY
;
642 wnd
->dwStyle
&= ~ES_READONLY
;
643 es
->style
&= ~ES_READONLY
;
648 case EM_SETWORDBREAKPROC16
:
649 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
650 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
652 case EM_SETWORDBREAKPROC
:
653 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
654 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
657 case EM_GETWORDBREAKPROC16
:
658 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
659 result
= (LRESULT
)es
->word_break_proc16
;
661 case EM_GETWORDBREAKPROC
:
662 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
663 result
= (LRESULT
)es
->word_break_proc32A
;
666 case EM_GETPASSWORDCHAR16
:
667 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
669 case EM_GETPASSWORDCHAR
:
670 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
671 result
= es
->password_char
;
674 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
677 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
678 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
682 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
683 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
686 case EM_GETLIMITTEXT
:
687 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
688 result
= es
->buffer_limit
;
692 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
693 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
697 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
698 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
702 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
703 result
= (es
->style
& ES_MULTILINE
) ?
704 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
705 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
709 DPRINTF_EDIT_MSG32("WM_CHAR");
710 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
714 DPRINTF_EDIT_MSG32("WM_CLEAR");
715 EDIT_WM_Clear(wnd
, es
);
719 DPRINTF_EDIT_MSG32("WM_COMMAND");
720 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
724 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
725 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
729 DPRINTF_EDIT_MSG32("WM_COPY");
730 EDIT_WM_Copy(wnd
, es
);
734 DPRINTF_EDIT_MSG32("WM_CREATE");
735 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
739 DPRINTF_EDIT_MSG32("WM_CUT");
740 EDIT_WM_Cut(wnd
, es
);
744 DPRINTF_EDIT_MSG32("WM_ENABLE");
745 InvalidateRect(hwnd
, NULL
, TRUE
);
749 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
750 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
754 DPRINTF_EDIT_MSG32("WM_GETFONT");
755 result
= (LRESULT
)es
->font
;
759 DPRINTF_EDIT_MSG32("WM_GETTEXT");
760 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
763 case WM_GETTEXTLENGTH
:
764 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
765 result
= lstrlenA(es
->text
);
769 DPRINTF_EDIT_MSG32("WM_HSCROLL");
770 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
774 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
775 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
779 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
780 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
783 case WM_LBUTTONDBLCLK
:
784 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
785 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
789 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
790 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
794 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
795 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
798 case WM_MOUSEACTIVATE
:
800 * FIXME: maybe DefWindowProc() screws up, but it seems that
801 * modalless dialog boxes need this. If we don't do this, the focus
802 * will _not_ be set by DefWindowProc() for edit controls in a
803 * modalless dialog box ???
805 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
806 SetFocus(wnd
->hwndSelf
);
807 result
= MA_ACTIVATE
;
812 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
814 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
818 DPRINTF_EDIT_MSG32("WM_PAINT");
819 EDIT_WM_Paint(wnd
, es
);
823 DPRINTF_EDIT_MSG32("WM_PASTE");
824 EDIT_WM_Paste(wnd
, es
);
828 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
829 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
833 DPRINTF_EDIT_MSG32("WM_SETFONT");
834 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
838 DPRINTF_EDIT_MSG32("WM_SETTEXT");
839 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
844 DPRINTF_EDIT_MSG32("WM_SIZE");
845 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
849 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
850 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
854 DPRINTF_EDIT_MSG32("WM_TIMER");
855 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
859 DPRINTF_EDIT_MSG32("WM_VSCROLL");
860 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
864 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
867 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
869 WIN_ReleaseWndPtr(wnd
);
875 /*********************************************************************
877 * EDIT_BuildLineDefs_ML
879 * Build linked list of text lines.
880 * Lines can end with '\0' (last line), a character (if it is wrapped),
881 * a soft return '\r\r\n' or a hard return '\r\n'
884 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
890 LINEDEF
*current_def
;
891 LINEDEF
**previous_next
;
893 current_def
= es
->first_line_def
;
895 LINEDEF
*next_def
= current_def
->next
;
896 HeapFree(es
->heap
, 0, current_def
);
897 current_def
= next_def
;
898 } while (current_def
);
902 dc
= GetDC(wnd
->hwndSelf
);
904 old_font
= SelectObject(dc
, es
->font
);
906 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
908 previous_next
= &es
->first_line_def
;
910 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
911 current_def
->next
= NULL
;
914 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
919 current_def
->ending
= END_0
;
920 current_def
->net_length
= lstrlenA(start
);
921 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
922 current_def
->ending
= END_SOFT
;
923 current_def
->net_length
= cp
- start
- 1;
925 current_def
->ending
= END_HARD
;
926 current_def
->net_length
= cp
- start
;
928 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
929 start
, current_def
->net_length
,
930 es
->tabs_count
, es
->tabs
));
931 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
932 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
937 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
938 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
939 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
940 start
, next
, es
->tabs_count
, es
->tabs
));
941 } while (current_def
->width
<= fw
);
947 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
948 start
, next
, es
->tabs_count
, es
->tabs
));
949 } while (current_def
->width
<= fw
);
953 current_def
->net_length
= prev
;
954 current_def
->ending
= END_WRAP
;
955 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
956 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
958 switch (current_def
->ending
) {
960 current_def
->length
= current_def
->net_length
+ 3;
963 current_def
->length
= current_def
->net_length
+ 2;
967 current_def
->length
= current_def
->net_length
;
970 es
->text_width
= MAX(es
->text_width
, current_def
->width
);
971 start
+= current_def
->length
;
972 *previous_next
= current_def
;
973 previous_next
= ¤t_def
->next
;
975 } while (current_def
->ending
!= END_0
);
977 SelectObject(dc
, old_font
);
978 ReleaseDC(wnd
->hwndSelf
, dc
);
982 /*********************************************************************
984 * EDIT_CallWordBreakProc
986 * Call appropriate WordBreakProc (internal or external).
988 * Note: The "start" argument should always be an index refering
989 * to es->text. The actual wordbreak proc might be
990 * 16 bit, so we can't always pass any 32 bit LPSTR.
991 * Hence we assume that es->text is the buffer that holds
992 * the string under examination (we can decide this for ourselves).
995 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
997 if (es
->word_break_proc16
) {
998 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
999 SEGPTR segptr
= LocalLock16(hloc16
);
1000 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1001 segptr
+ start
, index
, count
, action
);
1002 LocalUnlock16(hloc16
);
1005 else if (es
->word_break_proc32A
)
1007 TRACE(relay
, "(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1008 es
->word_break_proc32A
, es
->text
+ start
, index
,
1010 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1014 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1018 /*********************************************************************
1022 * Beware: This is not the function called on EM_CHARFROMPOS
1023 * The position _can_ be outside the formatting / client
1025 * The return value is only the character index
1028 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1034 if (es
->style
& ES_MULTILINE
) {
1035 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1037 LINEDEF
*line_def
= es
->first_line_def
;
1039 while ((line
> 0) && line_def
->next
) {
1040 line_index
+= line_def
->length
;
1041 line_def
= line_def
->next
;
1044 x
+= es
->x_offset
- es
->format_rect
.left
;
1045 if (x
>= line_def
->width
) {
1047 *after_wrap
= (line_def
->ending
== END_WRAP
);
1048 return line_index
+ line_def
->net_length
;
1052 *after_wrap
= FALSE
;
1055 dc
= GetDC(wnd
->hwndSelf
);
1057 old_font
= SelectObject(dc
, es
->font
);
1058 low
= line_index
+ 1;
1059 high
= line_index
+ line_def
->net_length
+ 1;
1060 while (low
< high
- 1)
1062 INT mid
= (low
+ high
) / 2;
1063 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1069 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1070 (line_def
->ending
== END_WRAP
));
1075 *after_wrap
= FALSE
;
1076 x
-= es
->format_rect
.left
;
1078 return es
->x_offset
;
1079 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1080 dc
= GetDC(wnd
->hwndSelf
);
1082 old_font
= SelectObject(dc
, es
->font
);
1086 INT high
= es
->x_offset
;
1087 while (low
< high
- 1)
1089 INT mid
= (low
+ high
) / 2;
1090 GetTextExtentPoint32A( dc
, text
+ mid
,
1091 es
->x_offset
- mid
, &size
);
1092 if (size
.cx
> -x
) low
= mid
;
1099 INT low
= es
->x_offset
;
1100 INT high
= lstrlenA(es
->text
) + 1;
1101 while (low
< high
- 1)
1103 INT mid
= (low
+ high
) / 2;
1104 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1105 mid
- es
->x_offset
, &size
);
1106 if (size
.cx
> x
) high
= mid
;
1111 if (es
->style
& ES_PASSWORD
)
1112 HeapFree(es
->heap
, 0 ,text
);
1115 SelectObject(dc
, old_font
);
1116 ReleaseDC(wnd
->hwndSelf
, dc
);
1121 /*********************************************************************
1125 * adjusts the point to be within the formatting rectangle
1126 * (so CharFromPos returns the nearest _visible_ character)
1129 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1131 *x
= MIN(MAX(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1132 *y
= MIN(MAX(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1136 /*********************************************************************
1140 * Calculates the bounding rectangle for a line from a starting
1141 * column to an ending column.
1144 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1146 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1148 if (es
->style
& ES_MULTILINE
)
1149 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1151 rc
->top
= es
->format_rect
.top
;
1152 rc
->bottom
= rc
->top
+ es
->line_height
;
1153 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1154 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1158 /*********************************************************************
1160 * EDIT_GetPasswordPointer_SL
1162 * note: caller should free the (optionally) allocated buffer
1165 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1167 if (es
->style
& ES_PASSWORD
) {
1168 INT len
= lstrlenA(es
->text
);
1169 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1170 RtlFillMemory(text
, len
, es
->password_char
);
1178 /*********************************************************************
1182 * This acts as a LOCAL_Lock(), but it locks only once. This way
1183 * you can call it whenever you like, without unlocking.
1186 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1189 ERR(edit
, "no EDITSTATE ... please report\n");
1192 if (!(es
->style
& ES_MULTILINE
))
1196 es
->text
= LocalLock(es
->hloc32
);
1197 else if (es
->hloc16
)
1198 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1200 ERR(edit
, "no buffer ... please report\n");
1208 /*********************************************************************
1210 * EDIT_SL_InvalidateText
1212 * Called from EDIT_InvalidateText().
1213 * Does the job for single-line controls only.
1216 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1221 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1222 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1223 InvalidateRect(wnd
->hwndSelf
, &rc
, FALSE
);
1227 /*********************************************************************
1229 * EDIT_ML_InvalidateText
1231 * Called from EDIT_InvalidateText().
1232 * Does the job for multi-line controls only.
1235 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1237 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1238 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1239 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1248 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1251 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1252 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1253 if (sl
< es
->y_offset
) {
1257 if (el
> es
->y_offset
+ vlc
) {
1258 el
= es
->y_offset
+ vlc
;
1259 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1261 GetClientRect(wnd
->hwndSelf
, &rc1
);
1262 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1264 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1265 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1266 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1268 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1269 EDIT_EM_LineLength(wnd
, es
,
1270 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1272 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1273 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1274 for (l
= sl
+ 1 ; l
< el
; l
++) {
1275 EDIT_GetLineRect(wnd
, es
, l
, 0,
1276 EDIT_EM_LineLength(wnd
, es
,
1277 EDIT_EM_LineIndex(wnd
, es
, l
)),
1279 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1280 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1282 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1283 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1284 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1289 /*********************************************************************
1291 * EDIT_InvalidateText
1293 * Invalidate the text from offset start upto, but not including,
1294 * offset end. Useful for (re)painting the selection.
1295 * Regions outside the linewidth are not invalidated.
1296 * end == -1 means end == TextLength.
1297 * start and end need not be ordered.
1300 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1306 end
= lstrlenA(es
->text
);
1308 ORDER_INT(start
, end
);
1310 if (es
->style
& ES_MULTILINE
)
1311 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1313 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1317 /*********************************************************************
1321 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1324 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1329 if (size
<= es
->buffer_size
)
1331 if (size
> es
->buffer_limit
) {
1332 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1335 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1336 if (size
> es
->buffer_limit
)
1337 size
= es
->buffer_limit
;
1339 TRACE(edit
, "trying to ReAlloc to %d+1\n", size
);
1341 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1343 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1344 es
->buffer_size
= MIN(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1346 es
->buffer_size
= 0;
1347 } else if (es
->hloc32
) {
1348 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1349 TRACE(edit
, "Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1350 es
->hloc32
= hNew32
;
1351 es
->buffer_size
= MIN(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1353 } else if (es
->hloc16
) {
1354 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1355 TRACE(edit
, "Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1356 es
->hloc16
= hNew16
;
1357 es
->buffer_size
= MIN(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1360 if (es
->buffer_size
< size
) {
1361 EDIT_LockBuffer(wnd
, es
);
1362 WARN(edit
, "FAILED ! We now have %d+1\n", es
->buffer_size
);
1363 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1366 EDIT_LockBuffer(wnd
, es
);
1367 TRACE(edit
, "We now have %d+1\n", es
->buffer_size
);
1373 /*********************************************************************
1377 * Try to fit size + 1 bytes in the undo buffer.
1380 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1382 if (size
<= es
->undo_buffer_size
)
1384 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1386 TRACE(edit
, "trying to ReAlloc to %d+1\n", size
);
1388 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1389 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1390 if (es
->undo_buffer_size
< size
) {
1391 WARN(edit
, "FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1400 /*********************************************************************
1405 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1407 INT e
= es
->selection_end
;
1411 if ((es
->style
& ES_MULTILINE
) && e
&&
1412 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1414 if (e
&& (es
->text
[e
- 1] == '\r'))
1418 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1419 EDIT_EM_ScrollCaret(wnd
, es
);
1423 /*********************************************************************
1427 * Only for multi line controls
1428 * Move the caret one line down, on a column with the nearest
1429 * x coordinate on the screen (might be a different column).
1432 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1434 INT s
= es
->selection_start
;
1435 INT e
= es
->selection_end
;
1436 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1437 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1438 INT x
= SLOWORD(pos
);
1439 INT y
= SHIWORD(pos
);
1441 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1444 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1445 EDIT_EM_ScrollCaret(wnd
, es
);
1449 /*********************************************************************
1454 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1456 BOOL after_wrap
= FALSE
;
1459 if (es
->style
& ES_MULTILINE
)
1460 e
= EDIT_CharFromPos(wnd
, es
, 0x7fffffff,
1461 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1463 e
= lstrlenA(es
->text
);
1464 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1465 EDIT_EM_ScrollCaret(wnd
, es
);
1469 /*********************************************************************
1474 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1476 INT e
= es
->selection_end
;
1480 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1481 if (es
->text
[e
] == '\n')
1483 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1487 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1488 EDIT_EM_ScrollCaret(wnd
, es
);
1492 /*********************************************************************
1496 * Home key: move to beginning of line.
1499 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1503 if (es
->style
& ES_MULTILINE
)
1504 e
= EDIT_CharFromPos(wnd
, es
, 0x80000000,
1505 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1508 EDIT_EM_SetSel(wnd
, es
, e
, extend
? es
->selection_start
: e
, FALSE
);
1509 EDIT_EM_ScrollCaret(wnd
, es
);
1513 /*********************************************************************
1515 * EDIT_MovePageDown_ML
1517 * Only for multi line controls
1518 * Move the caret one page down, on a column with the nearest
1519 * x coordinate on the screen (might be a different column).
1522 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1524 INT s
= es
->selection_start
;
1525 INT e
= es
->selection_end
;
1526 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1527 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1528 INT x
= SLOWORD(pos
);
1529 INT y
= SHIWORD(pos
);
1531 e
= EDIT_CharFromPos(wnd
, es
, x
,
1532 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1536 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1537 EDIT_EM_ScrollCaret(wnd
, es
);
1541 /*********************************************************************
1543 * EDIT_MovePageUp_ML
1545 * Only for multi line controls
1546 * Move the caret one page up, on a column with the nearest
1547 * x coordinate on the screen (might be a different column).
1550 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1552 INT s
= es
->selection_start
;
1553 INT e
= es
->selection_end
;
1554 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1555 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1556 INT x
= SLOWORD(pos
);
1557 INT y
= SHIWORD(pos
);
1559 e
= EDIT_CharFromPos(wnd
, es
, x
,
1560 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1564 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1565 EDIT_EM_ScrollCaret(wnd
, es
);
1569 /*********************************************************************
1573 * Only for multi line controls
1574 * Move the caret one line up, on a column with the nearest
1575 * x coordinate on the screen (might be a different column).
1578 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1580 INT s
= es
->selection_start
;
1581 INT e
= es
->selection_end
;
1582 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1583 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1584 INT x
= SLOWORD(pos
);
1585 INT y
= SHIWORD(pos
);
1587 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1590 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1591 EDIT_EM_ScrollCaret(wnd
, es
);
1595 /*********************************************************************
1597 * EDIT_MoveWordBackward
1600 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1602 INT s
= es
->selection_start
;
1603 INT e
= es
->selection_end
;
1608 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1609 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1610 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1613 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1614 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1617 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1618 li
, e
- li
, ll
, WB_LEFT
);
1622 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1623 EDIT_EM_ScrollCaret(wnd
, es
);
1627 /*********************************************************************
1629 * EDIT_MoveWordForward
1632 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1634 INT s
= es
->selection_start
;
1635 INT e
= es
->selection_end
;
1640 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1641 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1642 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1644 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1645 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1647 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1648 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1652 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1653 EDIT_EM_ScrollCaret(wnd
, es
);
1657 /*********************************************************************
1662 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1664 INT s
= es
->selection_start
;
1665 INT e
= es
->selection_end
;
1672 if (es
->style
& ES_MULTILINE
) {
1673 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1674 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1679 TRACE(edit
, "line=%d\n", line
);
1681 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1684 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1685 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1686 s
= es
->selection_start
;
1687 e
= es
->selection_end
;
1689 s
= MIN(li
+ ll
, MAX(li
, s
));
1690 e
= MIN(li
+ ll
, MAX(li
, e
));
1691 if (rev
&& (s
!= e
) &&
1692 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1693 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1694 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1695 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1697 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1701 /*********************************************************************
1706 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1716 BkColor
= GetBkColor(dc
);
1717 TextColor
= GetTextColor(dc
);
1719 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1720 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1722 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1723 if (es
->style
& ES_MULTILINE
) {
1724 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1725 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1727 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1728 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1729 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1731 if (es
->style
& ES_PASSWORD
)
1732 HeapFree(es
->heap
, 0, text
);
1735 SetBkColor(dc
, BkColor
);
1736 SetTextColor(dc
, TextColor
);
1742 /*********************************************************************
1747 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1750 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1751 INT x
= SLOWORD(res
);
1752 INT y
= SHIWORD(res
);
1754 if(x
< es
->format_rect
.left
)
1755 x
= es
->format_rect
.left
;
1756 if(x
> es
->format_rect
.right
- 2)
1757 x
= es
->format_rect
.right
- 2;
1758 if(y
> es
->format_rect
.bottom
)
1759 y
= es
->format_rect
.bottom
;
1760 if(y
< es
->format_rect
.top
)
1761 y
= es
->format_rect
.top
;
1767 /*********************************************************************
1771 * note: this is not (exactly) the handler called on EM_SETRECTNP
1772 * it is also used to set the rect of a single line control
1775 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1777 CopyRect(&es
->format_rect
, rc
);
1778 if (es
->style
& WS_BORDER
) {
1779 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1780 if(TWEAK_WineLook
== WIN31_LOOK
)
1782 es
->format_rect
.left
+= bw
;
1783 es
->format_rect
.top
+= bw
;
1784 es
->format_rect
.right
-= bw
;
1785 es
->format_rect
.bottom
-= bw
;
1787 es
->format_rect
.left
+= es
->left_margin
;
1788 es
->format_rect
.right
-= es
->right_margin
;
1789 es
->format_rect
.right
= MAX(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1790 if (es
->style
& ES_MULTILINE
)
1791 es
->format_rect
.bottom
= es
->format_rect
.top
+
1792 MAX(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1794 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1795 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1796 EDIT_BuildLineDefs_ML(wnd
, es
);
1800 /*********************************************************************
1805 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1808 ERR(edit
, "no EDITSTATE ... please report\n");
1811 if (!(es
->style
& ES_MULTILINE
))
1813 if (!es
->lock_count
) {
1814 ERR(edit
, "lock_count == 0 ... please report\n");
1818 ERR(edit
, "es->text == 0 ... please report\n");
1821 if (force
|| (es
->lock_count
== 1)) {
1823 LocalUnlock(es
->hloc32
);
1825 } else if (es
->hloc16
) {
1826 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1834 /*********************************************************************
1836 * EDIT_WordBreakProc
1838 * Find the beginning of words.
1839 * Note: unlike the specs for a WordBreakProc, this function only
1840 * allows to be called without linebreaks between s[0] upto
1841 * s[count - 1]. Remember it is only called
1842 * internally, so we can decide this for ourselves.
1845 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1849 TRACE(edit
, "s=%p, index=%u, count=%u, action=%d\n",
1850 s
, index
, count
, action
);
1858 if (s
[index
] == ' ') {
1859 while (index
&& (s
[index
] == ' '))
1862 while (index
&& (s
[index
] != ' '))
1864 if (s
[index
] == ' ')
1868 while (index
&& (s
[index
] != ' '))
1870 if (s
[index
] == ' ')
1880 if (s
[index
] == ' ')
1881 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1883 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1885 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1889 case WB_ISDELIMITER
:
1890 ret
= (s
[index
] == ' ');
1893 ERR(edit
, "unknown action code, please report !\n");
1900 /*********************************************************************
1904 * returns line number (not index) in high-order word of result.
1905 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1906 * to Richedit, not to the edit control. Original documentation is valid.
1907 * FIXME: do the specs mean to return -1 if outside client area or
1908 * if outside formatting rectangle ???
1911 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1919 GetClientRect(wnd
->hwndSelf
, &rc
);
1920 if (!PtInRect(&rc
, pt
))
1923 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1924 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1928 /*********************************************************************
1932 * Enable or disable soft breaks.
1934 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1936 es
->flags
&= ~EF_USE_SOFTBRK
;
1938 es
->flags
|= EF_USE_SOFTBRK
;
1939 FIXME(edit
, "soft break enabled, not implemented\n");
1945 /*********************************************************************
1949 * Hopefully this won't fire back at us.
1950 * We always start with a fixed buffer in our own heap.
1951 * However, with this message a 32 bit application requests
1952 * a handle to 32 bit moveable local heap memory, where it expects
1954 * It's a pity that from this moment on we have to use this
1955 * local heap, because applications may rely on the handle
1958 * In this function we'll try to switch to local heap.
1961 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1967 if (!(es
->style
& ES_MULTILINE
))
1972 else if (es
->hloc16
)
1973 return (HLOCAL
)es
->hloc16
;
1975 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
1976 ERR(edit
, "could not allocate new 32 bit buffer\n");
1979 newSize
= MIN(LocalSize(newBuf
) - 1, es
->buffer_limit
);
1980 if (!(newText
= LocalLock(newBuf
))) {
1981 ERR(edit
, "could not lock new 32 bit buffer\n");
1985 lstrcpyA(newText
, es
->text
);
1986 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1988 HeapFree(es
->heap
, 0, es
->text
);
1989 es
->hloc32
= newBuf
;
1990 es
->hloc16
= (HLOCAL16
)NULL
;
1991 es
->buffer_size
= newSize
;
1993 EDIT_LockBuffer(wnd
, es
);
1994 TRACE(edit
, "switched to 32 bit local heap\n");
2000 /*********************************************************************
2004 * Hopefully this won't fire back at us.
2005 * We always start with a buffer in 32 bit linear memory.
2006 * However, with this message a 16 bit application requests
2007 * a handle of 16 bit local heap memory, where it expects to find
2009 * It's a pitty that from this moment on we have to use this
2010 * local heap, because applications may rely on the handle
2013 * In this function we'll try to switch to local heap.
2015 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2021 if (!(es
->style
& ES_MULTILINE
))
2027 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2028 if (!LocalInit16(wnd
->hInstance
, 0,
2029 GlobalSize16(wnd
->hInstance
))) {
2030 ERR(edit
, "could not initialize local heap\n");
2033 TRACE(edit
, "local heap initialized\n");
2035 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2036 ERR(edit
, "could not allocate new 16 bit buffer\n");
2039 newSize
= MIN(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2040 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2041 ERR(edit
, "could not lock new 16 bit buffer\n");
2042 LOCAL_Free(wnd
->hInstance
, newBuf
);
2045 lstrcpyA(newText
, es
->text
);
2046 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2048 HeapFree(es
->heap
, 0, es
->text
);
2049 else if (es
->hloc32
) {
2050 while (LocalFree(es
->hloc32
)) ;
2051 LocalFree(es
->hloc32
);
2053 es
->hloc32
= (HLOCAL
)NULL
;
2054 es
->hloc16
= newBuf
;
2055 es
->buffer_size
= newSize
;
2057 EDIT_LockBuffer(wnd
, es
);
2058 TRACE(edit
, "switched to 16 bit buffer\n");
2064 /*********************************************************************
2069 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2075 if (es
->style
& ES_MULTILINE
) {
2076 if (line
>= es
->line_count
)
2080 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2082 len
= MIN(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2083 for (i
= 0 ; i
< len
; i
++) {
2088 return (LRESULT
)len
;
2092 /*********************************************************************
2097 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2099 UINT s
= es
->selection_start
;
2100 UINT e
= es
->selection_end
;
2107 return MAKELONG(s
, e
);
2111 /*********************************************************************
2115 * FIXME: is this right ? (or should it be only VSCROLL)
2116 * (and maybe only for edit controls that really have their
2117 * own scrollbars) (and maybe only for multiline controls ?)
2118 * All in all: very poorly documented
2120 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2121 * WM_VSCROLL handlers
2124 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2126 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2127 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2131 /*********************************************************************
2136 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2141 if (!(es
->style
& ES_MULTILINE
))
2143 if (index
> lstrlenA(es
->text
))
2144 return es
->line_count
- 1;
2146 index
= MIN(es
->selection_start
, es
->selection_end
);
2149 line_def
= es
->first_line_def
;
2150 index
-= line_def
->length
;
2151 while ((index
>= 0) && line_def
->next
) {
2153 line_def
= line_def
->next
;
2154 index
-= line_def
->length
;
2160 /*********************************************************************
2165 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2170 if (!(es
->style
& ES_MULTILINE
))
2172 if (line
>= es
->line_count
)
2176 line_def
= es
->first_line_def
;
2178 INT index
= es
->selection_end
- line_def
->length
;
2179 while ((index
>= 0) && line_def
->next
) {
2180 line_index
+= line_def
->length
;
2181 line_def
= line_def
->next
;
2182 index
-= line_def
->length
;
2186 line_index
+= line_def
->length
;
2187 line_def
= line_def
->next
;
2195 /*********************************************************************
2200 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2204 if (!(es
->style
& ES_MULTILINE
))
2205 return lstrlenA(es
->text
);
2209 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2210 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2211 return es->selection_start - es->line_defs[sl].offset +
2212 es->line_defs[el].offset +
2213 es->line_defs[el].length - es->selection_end;
2217 line_def
= es
->first_line_def
;
2218 index
-= line_def
->length
;
2219 while ((index
>= 0) && line_def
->next
) {
2220 line_def
= line_def
->next
;
2221 index
-= line_def
->length
;
2223 return line_def
->net_length
;
2227 /*********************************************************************
2231 * FIXME: dx is in average character widths
2232 * However, we assume it is in pixels when we use this
2233 * function internally
2236 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2240 if (!(es
->style
& ES_MULTILINE
))
2243 if (-dx
> es
->x_offset
)
2245 if (dx
> es
->text_width
- es
->x_offset
)
2246 dx
= es
->text_width
- es
->x_offset
;
2247 nyoff
= MAX(0, es
->y_offset
+ dy
);
2248 if (nyoff
>= es
->line_count
)
2249 nyoff
= es
->line_count
- 1;
2250 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2254 GetClientRect(wnd
->hwndSelf
, &rc1
);
2255 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2256 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2257 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2258 es
->y_offset
= nyoff
;
2261 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2262 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2263 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2264 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2269 /*********************************************************************
2274 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2276 INT len
= lstrlenA(es
->text
);
2285 index
= MIN(index
, len
);
2286 dc
= GetDC(wnd
->hwndSelf
);
2288 old_font
= SelectObject(dc
, es
->font
);
2289 if (es
->style
& ES_MULTILINE
) {
2290 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2291 y
= (l
- es
->y_offset
) * es
->line_height
;
2292 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2293 if (after_wrap
&& (li
== index
) && l
) {
2295 LINEDEF
*line_def
= es
->first_line_def
;
2297 line_def
= line_def
->next
;
2300 if (line_def
->ending
== END_WRAP
) {
2302 y
-= es
->line_height
;
2303 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2306 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2307 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2309 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2310 if (index
< es
->x_offset
) {
2311 GetTextExtentPoint32A(dc
, text
+ index
,
2312 es
->x_offset
- index
, &size
);
2315 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2316 index
- es
->x_offset
, &size
);
2320 if (es
->style
& ES_PASSWORD
)
2321 HeapFree(es
->heap
, 0 ,text
);
2323 x
+= es
->format_rect
.left
;
2324 y
+= es
->format_rect
.top
;
2326 SelectObject(dc
, old_font
);
2327 ReleaseDC(wnd
->hwndSelf
, dc
);
2328 return MAKELONG((INT16
)x
, (INT16
)y
);
2332 /*********************************************************************
2336 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2339 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2341 INT strl
= lstrlenA(lpsz_replace
);
2342 INT tl
= lstrlenA(es
->text
);
2349 s
= es
->selection_start
;
2350 e
= es
->selection_end
;
2352 if ((s
== e
) && !strl
)
2357 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2361 /* there is something to be deleted */
2363 utl
= lstrlenA(es
->undo_text
);
2364 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2365 /* undo-buffer is extended to the right */
2366 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2367 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2368 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2369 /* undo-buffer is extended to the left */
2370 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2371 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2373 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2374 p
[i
] = (es
->text
+ s
)[i
];
2375 es
->undo_position
= s
;
2377 /* new undo-buffer */
2378 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2379 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2380 es
->undo_position
= s
;
2382 /* any deletion makes the old insertion-undo invalid */
2383 es
->undo_insert_count
= 0;
2385 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2388 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2391 /* there is an insertion */
2393 if ((s
== es
->undo_position
) ||
2394 ((es
->undo_insert_count
) &&
2395 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2397 * insertion is new and at delete position or
2398 * an extension to either left or right
2400 es
->undo_insert_count
+= strl
;
2402 /* new insertion undo */
2403 es
->undo_position
= s
;
2404 es
->undo_insert_count
= strl
;
2405 /* new insertion makes old delete-buffer invalid */
2406 *es
->undo_text
= '\0';
2409 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2412 tl
= lstrlenA(es
->text
);
2413 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2415 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2416 p
[i
] = lpsz_replace
[i
];
2417 if(es
->style
& ES_UPPERCASE
)
2418 CharUpperBuffA(p
, strl
);
2419 else if(es
->style
& ES_LOWERCASE
)
2420 CharLowerBuffA(p
, strl
);
2423 /* FIXME: really inefficient */
2424 if (es
->style
& ES_MULTILINE
)
2425 EDIT_BuildLineDefs_ML(wnd
, es
);
2427 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2428 es
->flags
|= EF_MODIFIED
;
2429 es
->flags
|= EF_UPDATE
;
2430 EDIT_EM_ScrollCaret(wnd
, es
);
2432 /* FIXME: really inefficient */
2433 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2437 /*********************************************************************
2442 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2446 if (!(es
->style
& ES_MULTILINE
))
2447 return (LRESULT
)FALSE
;
2457 if (es
->y_offset
< es
->line_count
- 1)
2462 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2465 if (es
->y_offset
< es
->line_count
- 1)
2466 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2469 return (LRESULT
)FALSE
;
2472 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2473 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2475 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2479 /*********************************************************************
2484 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2486 if (es
->style
& ES_MULTILINE
) {
2491 INT cw
= es
->char_width
;
2496 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2497 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2498 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2499 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2500 if (l
>= es
->y_offset
+ vlc
)
2501 dy
= l
- vlc
+ 1 - es
->y_offset
;
2502 if (l
< es
->y_offset
)
2503 dy
= l
- es
->y_offset
;
2504 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2505 if (x
< es
->format_rect
.left
)
2506 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2507 if (x
> es
->format_rect
.right
)
2508 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2510 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2516 if (!(es
->style
& ES_AUTOHSCROLL
))
2519 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2520 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2521 if (x
< es
->format_rect
.left
) {
2522 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2525 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2526 } while ((x
< goal
) && es
->x_offset
);
2527 /* FIXME: use ScrollWindow() somehow to improve performance */
2528 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2529 } else if (x
> es
->format_rect
.right
) {
2531 INT len
= lstrlenA(es
->text
);
2532 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2535 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2536 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2537 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2538 /* FIXME: use ScrollWindow() somehow to improve performance */
2539 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2545 /*********************************************************************
2549 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2552 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2554 if (!(es
->style
& ES_MULTILINE
))
2558 WARN(edit
, "called with NULL handle\n");
2562 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2564 * old buffer is freed by caller, unless
2565 * it is still in our own heap. (in that case
2566 * we free it, correcting the buggy caller.)
2569 HeapFree(es
->heap
, 0, es
->text
);
2571 es
->hloc16
= (HLOCAL16
)NULL
;
2574 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2575 EDIT_LockBuffer(wnd
, es
);
2577 es
->x_offset
= es
->y_offset
= 0;
2578 es
->selection_start
= es
->selection_end
= 0;
2579 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2580 es
->flags
&= ~EF_MODIFIED
;
2581 es
->flags
&= ~EF_UPDATE
;
2582 EDIT_BuildLineDefs_ML(wnd
, es
);
2583 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2584 EDIT_EM_ScrollCaret(wnd
, es
);
2588 /*********************************************************************
2592 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2595 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2597 if (!(es
->style
& ES_MULTILINE
))
2601 WARN(edit
, "called with NULL handle\n");
2605 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2607 * old buffer is freed by caller, unless
2608 * it is still in our own heap. (in that case
2609 * we free it, correcting the buggy caller.)
2612 HeapFree(es
->heap
, 0, es
->text
);
2615 es
->hloc32
= (HLOCAL
)NULL
;
2617 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2618 EDIT_LockBuffer(wnd
, es
);
2620 es
->x_offset
= es
->y_offset
= 0;
2621 es
->selection_start
= es
->selection_end
= 0;
2622 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2623 es
->flags
&= ~EF_MODIFIED
;
2624 es
->flags
&= ~EF_UPDATE
;
2625 EDIT_BuildLineDefs_ML(wnd
, es
);
2626 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2627 EDIT_EM_ScrollCaret(wnd
, es
);
2631 /*********************************************************************
2635 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2636 * However, the windows version is not complied to yet in all of edit.c
2639 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2641 if (es
->style
& ES_MULTILINE
) {
2643 es
->buffer_limit
= MIN(limit
, BUFLIMIT_MULTI
);
2645 es
->buffer_limit
= BUFLIMIT_MULTI
;
2648 es
->buffer_limit
= MIN(limit
, BUFLIMIT_SINGLE
);
2650 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2655 /*********************************************************************
2659 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2660 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2661 * of the char's width, according to the new docs.
2664 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2665 INT left
, INT right
)
2667 if (action
& EC_LEFTMARGIN
) {
2668 if (left
!= EC_USEFONTINFO
)
2669 es
->left_margin
= left
;
2671 es
->left_margin
= es
->char_width
/ 3;
2674 if (action
& EC_RIGHTMARGIN
) {
2675 if (right
!= EC_USEFONTINFO
)
2676 es
->right_margin
= right
;
2678 es
->right_margin
= es
->char_width
/ 3;
2680 TRACE(edit
, "left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2684 /*********************************************************************
2686 * EM_SETPASSWORDCHAR
2689 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2691 if (es
->style
& ES_MULTILINE
)
2694 if (es
->password_char
== c
)
2697 es
->password_char
= c
;
2699 wnd
->dwStyle
|= ES_PASSWORD
;
2700 es
->style
|= ES_PASSWORD
;
2702 wnd
->dwStyle
&= ~ES_PASSWORD
;
2703 es
->style
&= ~ES_PASSWORD
;
2705 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2709 /*********************************************************************
2713 * note: unlike the specs say: the order of start and end
2714 * _is_ preserved in Windows. (i.e. start can be > end)
2715 * In other words: this handler is OK
2718 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2720 UINT old_start
= es
->selection_start
;
2721 UINT old_end
= es
->selection_end
;
2722 UINT len
= lstrlenA(es
->text
);
2725 start
= es
->selection_end
;
2726 end
= es
->selection_end
;
2728 start
= MIN(start
, len
);
2729 end
= MIN(end
, len
);
2731 es
->selection_start
= start
;
2732 es
->selection_end
= end
;
2734 es
->flags
|= EF_AFTER_WRAP
;
2736 es
->flags
&= ~EF_AFTER_WRAP
;
2737 if (es
->flags
& EF_FOCUSED
)
2738 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2739 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2740 ORDER_UINT(start
, end
);
2741 ORDER_UINT(end
, old_end
);
2742 ORDER_UINT(start
, old_start
);
2743 ORDER_UINT(old_start
, old_end
);
2744 if (end
!= old_start
)
2748 * ORDER_UINT32(end, old_start);
2749 * EDIT_InvalidateText(wnd, es, start, end);
2750 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2751 * in place of the following if statement.
2753 if (old_start
> end
)
2755 EDIT_InvalidateText(wnd
, es
, start
, end
);
2756 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2760 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2761 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2764 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2768 /*********************************************************************
2773 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2775 if (!(es
->style
& ES_MULTILINE
))
2778 HeapFree(es
->heap
, 0, es
->tabs
);
2779 es
->tabs_count
= count
;
2783 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2784 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2790 /*********************************************************************
2795 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2797 if (!(es
->style
& ES_MULTILINE
))
2800 HeapFree(es
->heap
, 0, es
->tabs
);
2801 es
->tabs_count
= count
;
2806 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2807 for (i
= 0 ; i
< count
; i
++)
2808 es
->tabs
[i
] = *tabs
++;
2814 /*********************************************************************
2816 * EM_SETWORDBREAKPROC
2819 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2821 if (es
->word_break_proc32A
== wbp
)
2824 es
->word_break_proc32A
= wbp
;
2825 es
->word_break_proc16
= NULL
;
2826 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2827 EDIT_BuildLineDefs_ML(wnd
, es
);
2828 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2833 /*********************************************************************
2835 * EM_SETWORDBREAKPROC16
2838 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2840 if (es
->word_break_proc16
== wbp
)
2843 es
->word_break_proc32A
= NULL
;
2844 es
->word_break_proc16
= wbp
;
2845 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2846 EDIT_BuildLineDefs_ML(wnd
, es
);
2847 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2852 /*********************************************************************
2857 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2859 INT ulength
= lstrlenA(es
->undo_text
);
2860 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2862 lstrcpyA(utext
, es
->undo_text
);
2864 TRACE(edit
, "before UNDO:insertion length = %d, deletion buffer = %s\n",
2865 es
->undo_insert_count
, utext
);
2867 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2868 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2869 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2870 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2871 HeapFree(es
->heap
, 0, utext
);
2873 TRACE(edit
, "after UNDO:insertion length = %d, deletion buffer = %s\n",
2874 es
->undo_insert_count
, es
->undo_text
);
2880 /*********************************************************************
2885 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2890 if (es
->style
& ES_MULTILINE
) {
2891 if (es
->style
& ES_READONLY
) {
2892 EDIT_MoveHome(wnd
, es
, FALSE
);
2893 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2895 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2899 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2900 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2903 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2907 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2914 /*********************************************************************
2919 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
2921 if (code
|| control
)
2926 EDIT_EM_Undo(wnd
, es
);
2929 EDIT_WM_Cut(wnd
, es
);
2932 EDIT_WM_Copy(wnd
, es
);
2935 EDIT_WM_Paste(wnd
, es
);
2938 EDIT_WM_Clear(wnd
, es
);
2941 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
2942 EDIT_EM_ScrollCaret(wnd
, es
);
2945 ERR(edit
, "unknown menu item, please report\n");
2951 /*********************************************************************
2955 * Note: the resource files resource/sysres_??.rc cannot define a
2956 * single popup menu. Hence we use a (dummy) menubar
2957 * containing the single popup menu as its first item.
2959 * FIXME: the message identifiers have been chosen arbitrarily,
2960 * hence we use MF_BYPOSITION.
2961 * We might as well use the "real" values (anybody knows ?)
2962 * The menu definition is in resources/sysres_??.rc.
2963 * Once these are OK, we better use MF_BYCOMMAND here
2964 * (as we do in EDIT_WM_Command()).
2967 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
2969 HMENU menu
= LoadMenuIndirectA(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU
));
2970 HMENU popup
= GetSubMenu(menu
, 0);
2971 UINT start
= es
->selection_start
;
2972 UINT end
= es
->selection_end
;
2974 ORDER_UINT(start
, end
);
2977 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
2979 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2981 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2983 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
2985 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
2987 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
2989 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
2994 /*********************************************************************
2999 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3001 INT s
= es
->selection_start
;
3002 INT e
= es
->selection_end
;
3009 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3010 dst
= GlobalLock(hdst
);
3011 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3013 OpenClipboard(wnd
->hwndSelf
);
3015 SetClipboardData(CF_TEXT
, hdst
);
3020 /*********************************************************************
3025 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3028 * To initialize some final structure members, we call some helper
3029 * functions. However, since the EDITSTATE is not consistent (i.e.
3030 * not fully initialized), we should be very careful which
3031 * functions can be called, and in what order.
3033 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3034 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3036 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3037 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3038 /* 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 */
3039 es
->selection_start
= es
->selection_end
= 0;
3040 EDIT_EM_ScrollCaret(wnd
, es
);
3046 /*********************************************************************
3051 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3054 while (LocalUnlock(es
->hloc32
)) ;
3055 LocalFree(es
->hloc32
);
3058 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3059 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3061 HeapDestroy(es
->heap
);
3062 HeapFree(GetProcessHeap(), 0, es
);
3063 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3067 /*********************************************************************
3072 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3077 if (IsWindowEnabled(wnd
->hwndSelf
) || (es
->style
& ES_READONLY
))
3078 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3080 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3083 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3085 GetClientRect(wnd
->hwndSelf
, &rc
);
3086 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3087 GetClipBox(dc
, &rc
);
3089 * FIXME: specs say that we should UnrealizeObject() the brush,
3090 * but the specs of UnrealizeObject() say that we shouldn't
3091 * unrealize a stock object. The default brush that
3092 * DefWndProc() returns is ... a stock object.
3094 FillRect(dc
, &rc
, brush
);
3099 /*********************************************************************
3104 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3106 INT len
= lstrlenA(es
->text
);
3109 lstrcpyA(text
, es
->text
);
3116 /*********************************************************************
3120 * 16 bit notepad needs this. Actually it is not _our_ hack,
3121 * it is notepad's. Notepad is sending us scrollbar messages with
3122 * undocumented parameters without us even having a scrollbar ... !?!?
3125 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3128 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3131 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3132 ERR(edit
, "hacked WM_HSCROLL handler invoked\n");
3133 ERR(edit
, " if you are _not_ running 16 bit notepad, please report\n");
3134 ERR(edit
, " (this message is only displayed once per edit control)\n");
3135 es
->flags
|= EF_HSCROLL_HACK
;
3141 dx
= -es
->char_width
;
3144 if (es
->x_offset
< es
->text_width
)
3145 dx
= es
->char_width
;
3149 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3152 if (es
->x_offset
< es
->text_width
)
3153 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3160 if (es
->x_offset
< es
->text_width
)
3161 dx
= es
->text_width
- es
->x_offset
;
3164 es
->flags
|= EF_HSCROLL_TRACK
;
3165 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3167 case SB_THUMBPOSITION
:
3168 es
->flags
&= ~EF_HSCROLL_TRACK
;
3169 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3170 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3176 * FIXME : the next two are undocumented !
3177 * Are we doing the right thing ?
3178 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3179 * although it's also a regular control message.
3182 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3184 case EM_LINESCROLL16
:
3189 ERR(edit
, "undocumented (hacked) WM_HSCROLL parameter, please report\n");
3193 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3198 /*********************************************************************
3203 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3208 if (!(es
->style
& ES_MULTILINE
))
3211 if (!(es
->style
& ES_AUTOHSCROLL
))
3214 if (!(es
->style
& WS_HSCROLL
))
3215 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3218 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3222 dx
= -es
->char_width
;
3225 if (es
->x_offset
< es
->text_width
)
3226 dx
= es
->char_width
;
3230 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3233 if (es
->x_offset
< es
->text_width
)
3234 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3241 if (es
->x_offset
< es
->text_width
)
3242 dx
= es
->text_width
- es
->x_offset
;
3245 es
->flags
|= EF_HSCROLL_TRACK
;
3246 dx
= pos
- es
->x_offset
;
3248 case SB_THUMBPOSITION
:
3249 es
->flags
&= ~EF_HSCROLL_TRACK
;
3250 if (!(dx
= pos
- es
->x_offset
)) {
3251 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3252 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3259 ERR(edit
, "undocumented WM_HSCROLL parameter, please report\n");
3263 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3268 /*********************************************************************
3273 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3277 if (WIDGETS_IsControl(wnd
->parent
, BIC32_COMBO
) &&
3278 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3279 HWND hCombo
= wnd
->parent
->hwndSelf
;
3280 BOOL bUIFlip
= TRUE
;
3282 TRACE(combo
, "[%04x]: handling msg %04x (%04x)\n",
3283 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3286 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3288 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3289 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3293 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3295 /* make sure ComboLBox pops up */
3296 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3297 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3298 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3301 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3302 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3304 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3305 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3307 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3316 /*********************************************************************
3320 * Handling of special keys that don't produce a WM_CHAR
3321 * (i.e. non-printable keys) & Backspace & Delete
3324 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3329 if (GetKeyState(VK_MENU
) & 0x8000)
3332 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3333 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3338 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3344 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3345 EDIT_MoveUp_ML(wnd
, es
, shift
);
3348 EDIT_MoveWordBackward(wnd
, es
, shift
);
3350 EDIT_MoveBackward(wnd
, es
, shift
);
3353 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3357 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3358 EDIT_MoveDown_ML(wnd
, es
, shift
);
3360 EDIT_MoveWordForward(wnd
, es
, shift
);
3362 EDIT_MoveForward(wnd
, es
, shift
);
3365 EDIT_MoveHome(wnd
, es
, shift
);
3368 EDIT_MoveEnd(wnd
, es
, shift
);
3371 if (es
->style
& ES_MULTILINE
)
3372 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3375 if (es
->style
& ES_MULTILINE
)
3376 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3379 if (!(es
->style
& ES_READONLY
) && !control
) {
3380 if (es
->selection_start
!= es
->selection_end
)
3381 EDIT_WM_Clear(wnd
, es
);
3383 /* delete character left of caret */
3384 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3385 EDIT_MoveBackward(wnd
, es
, TRUE
);
3386 EDIT_WM_Clear(wnd
, es
);
3391 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3392 if (es
->selection_start
!= es
->selection_end
) {
3394 EDIT_WM_Cut(wnd
, es
);
3396 EDIT_WM_Clear(wnd
, es
);
3399 /* delete character left of caret */
3400 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3401 EDIT_MoveBackward(wnd
, es
, TRUE
);
3402 EDIT_WM_Clear(wnd
, es
);
3403 } else if (control
) {
3404 /* delete to end of line */
3405 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3406 EDIT_MoveEnd(wnd
, es
, TRUE
);
3407 EDIT_WM_Clear(wnd
, es
);
3409 /* delete character right of caret */
3410 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3411 EDIT_MoveForward(wnd
, es
, TRUE
);
3412 EDIT_WM_Clear(wnd
, es
);
3419 if (!(es
->style
& ES_READONLY
))
3420 EDIT_WM_Paste(wnd
, es
);
3422 EDIT_WM_Copy(wnd
, es
);
3429 /*********************************************************************
3434 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3436 es
->flags
&= ~EF_FOCUSED
;
3438 if(!(es
->style
& ES_NOHIDESEL
))
3439 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3440 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3445 /*********************************************************************
3449 * The caret position has been set on the WM_LBUTTONDOWN message
3452 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3455 INT e
= es
->selection_end
;
3460 if (!(es
->flags
& EF_FOCUSED
))
3463 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3464 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3465 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3466 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3467 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3468 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3469 EDIT_EM_ScrollCaret(wnd
, es
);
3474 /*********************************************************************
3479 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3484 if (!(es
->flags
& EF_FOCUSED
))
3487 SetCapture(wnd
->hwndSelf
);
3488 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3489 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3490 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3491 EDIT_EM_ScrollCaret(wnd
, es
);
3492 es
->region_posx
= es
->region_posy
= 0;
3493 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3498 /*********************************************************************
3503 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3505 if (GetCapture() == wnd
->hwndSelf
) {
3506 KillTimer(wnd
->hwndSelf
, 0);
3513 /*********************************************************************
3518 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3524 if (GetCapture() != wnd
->hwndSelf
)
3528 * FIXME: gotta do some scrolling if outside client
3529 * area. Maybe reset the timer ?
3532 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3533 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3534 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3535 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3536 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3541 /*********************************************************************
3546 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3550 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3552 *(EDITSTATE
**)wnd
->wExtra
= es
;
3555 * Note: since the EDITSTATE has not been fully initialized yet,
3556 * we can't use any API calls that may send
3557 * WM_XXX messages before WM_NCCREATE is completed.
3560 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3562 es
->style
= cs
->style
;
3564 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3565 wnd
->dwStyle
&= ~WS_BORDER
;
3567 if (es
->style
& ES_MULTILINE
) {
3568 es
->buffer_size
= BUFSTART_MULTI
;
3569 es
->buffer_limit
= BUFLIMIT_MULTI
;
3570 if (es
->style
& WS_VSCROLL
)
3571 es
->style
|= ES_AUTOVSCROLL
;
3572 if (es
->style
& WS_HSCROLL
)
3573 es
->style
|= ES_AUTOHSCROLL
;
3574 es
->style
&= ~ES_PASSWORD
;
3575 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3576 if (es
->style
& ES_RIGHT
)
3577 es
->style
&= ~ES_CENTER
;
3578 es
->style
&= ~WS_HSCROLL
;
3579 es
->style
&= ~ES_AUTOHSCROLL
;
3582 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3583 es
->style
|= ES_AUTOVSCROLL
;
3585 es
->buffer_size
= BUFSTART_SINGLE
;
3586 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3587 es
->style
&= ~ES_CENTER
;
3588 es
->style
&= ~ES_RIGHT
;
3589 es
->style
&= ~WS_HSCROLL
;
3590 es
->style
&= ~WS_VSCROLL
;
3591 es
->style
&= ~ES_AUTOVSCROLL
;
3592 es
->style
&= ~ES_WANTRETURN
;
3593 if (es
->style
& ES_UPPERCASE
) {
3594 es
->style
&= ~ES_LOWERCASE
;
3595 es
->style
&= ~ES_NUMBER
;
3596 } else if (es
->style
& ES_LOWERCASE
)
3597 es
->style
&= ~ES_NUMBER
;
3598 if (es
->style
& ES_PASSWORD
)
3599 es
->password_char
= '*';
3601 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3602 es
->style
|= ES_AUTOHSCROLL
;
3604 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3606 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3607 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3609 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3611 if (es
->style
& ES_MULTILINE
)
3612 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3619 /*********************************************************************
3624 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
)
3633 BOOL rev
= IsWindowEnabled(wnd
->hwndSelf
) &&
3634 ((es
->flags
& EF_FOCUSED
) ||
3635 (es
->style
& ES_NOHIDESEL
));
3637 if (es
->flags
& EF_UPDATE
)
3638 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3640 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3641 if(es
->style
& WS_BORDER
) {
3642 GetClientRect(wnd
->hwndSelf
, &rc
);
3643 if(es
->style
& ES_MULTILINE
) {
3644 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3645 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3647 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3649 IntersectClipRect(dc
, es
->format_rect
.left
,
3650 es
->format_rect
.top
,
3651 es
->format_rect
.right
,
3652 es
->format_rect
.bottom
);
3653 if (es
->style
& ES_MULTILINE
) {
3654 GetClientRect(wnd
->hwndSelf
, &rc
);
3655 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3658 old_font
= SelectObject(dc
, es
->font
);
3659 if (IsWindowEnabled(wnd
->hwndSelf
) || (es
->style
& ES_READONLY
))
3660 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3662 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3663 if (!IsWindowEnabled(wnd
->hwndSelf
))
3664 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3665 GetClipBox(dc
, &rcRgn
);
3666 if (es
->style
& ES_MULTILINE
) {
3667 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3668 for (i
= es
->y_offset
; i
<= MIN(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3669 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3670 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3671 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3674 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3675 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3676 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3679 SelectObject(dc
, old_font
);
3680 if (es
->flags
& EF_FOCUSED
)
3681 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3682 es
->flags
& EF_AFTER_WRAP
);
3683 EndPaint(wnd
->hwndSelf
, &ps
);
3684 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3685 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3687 si
.cbSize
= sizeof(SCROLLINFO
);
3688 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3690 si
.nMax
= es
->line_count
+ vlc
- 2;
3692 si
.nPos
= es
->y_offset
;
3693 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3695 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3697 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3698 si
.cbSize
= sizeof(SCROLLINFO
);
3699 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3701 si
.nMax
= es
->text_width
+ fw
- 1;
3703 si
.nPos
= es
->x_offset
;
3704 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3707 if (es
->flags
& EF_UPDATE
) {
3708 es
->flags
&= ~EF_UPDATE
;
3709 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3714 /*********************************************************************
3719 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3724 OpenClipboard(wnd
->hwndSelf
);
3725 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3726 src
= (LPSTR
)GlobalLock(hsrc
);
3727 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3734 /*********************************************************************
3739 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3741 es
->flags
|= EF_FOCUSED
;
3742 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3743 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3744 es
->flags
& EF_AFTER_WRAP
);
3745 if(!(es
->style
& ES_NOHIDESEL
))
3746 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3747 ShowCaret(wnd
->hwndSelf
);
3748 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3752 /*********************************************************************
3756 * With Win95 look the margins are set to default font value unless
3757 * the system font (font == 0) is being set, in which case they are left
3761 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3768 dc
= GetDC(wnd
->hwndSelf
);
3770 old_font
= SelectObject(dc
, font
);
3771 GetTextMetricsA(dc
, &tm
);
3772 es
->line_height
= tm
.tmHeight
;
3773 es
->char_width
= tm
.tmAveCharWidth
;
3775 SelectObject(dc
, old_font
);
3776 ReleaseDC(wnd
->hwndSelf
, dc
);
3777 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3778 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3779 EC_USEFONTINFO
, EC_USEFONTINFO
);
3780 if (es
->style
& ES_MULTILINE
)
3781 EDIT_BuildLineDefs_ML(wnd
, es
);
3784 GetClientRect(wnd
->hwndSelf
, &r
);
3785 EDIT_SetRectNP(wnd
, es
, &r
);
3788 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3789 if (es
->flags
& EF_FOCUSED
) {
3791 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3792 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3793 es
->flags
& EF_AFTER_WRAP
);
3794 ShowCaret(wnd
->hwndSelf
);
3799 /*********************************************************************
3804 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3805 * The modified flag is reset. No notifications are sent.
3807 * For single-line controls, reception of WM_SETTEXT triggers:
3808 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3811 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3813 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3815 TRACE(edit
, "\t'%s'\n", text
);
3816 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3818 TRACE(edit
, "\t<NULL>\n");
3819 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3822 if (es
->style
& ES_MULTILINE
) {
3823 es
->flags
&= ~EF_UPDATE
;
3825 es
->flags
|= EF_UPDATE
;
3827 es
->flags
&= ~EF_MODIFIED
;
3828 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3829 EDIT_EM_ScrollCaret(wnd
, es
);
3833 /*********************************************************************
3838 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3840 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3842 SetRect(&rc
, 0, 0, width
, height
);
3843 EDIT_SetRectNP(wnd
, es
, &rc
);
3844 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3849 /*********************************************************************
3854 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3856 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3857 if (EDIT_EM_CanUndo(wnd
, es
))
3858 EDIT_EM_Undo(wnd
, es
);
3860 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3861 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3863 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
3867 /*********************************************************************
3872 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
3874 if (es
->region_posx
< 0) {
3875 EDIT_MoveBackward(wnd
, es
, TRUE
);
3876 } else if (es
->region_posx
> 0) {
3877 EDIT_MoveForward(wnd
, es
, TRUE
);
3880 * FIXME: gotta do some vertical scrolling here, like
3881 * EDIT_EM_LineScroll(wnd, 0, 1);
3886 /*********************************************************************
3890 * 16 bit notepad needs this. Actually it is not _our_ hack,
3891 * it is notepad's. Notepad is sending us scrollbar messages with
3892 * undocumented parameters without us even having a scrollbar ... !?!?
3895 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3900 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3901 ERR(edit
, "hacked WM_VSCROLL handler invoked\n");
3902 ERR(edit
, " if you are _not_ running 16 bit notepad, please report\n");
3903 ERR(edit
, " (this message is only displayed once per edit control)\n");
3904 es
->flags
|= EF_VSCROLL_HACK
;
3912 EDIT_EM_Scroll(wnd
, es
, action
);
3918 dy
= es
->line_count
- 1 - es
->y_offset
;
3921 es
->flags
|= EF_VSCROLL_TRACK
;
3922 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
3924 case SB_THUMBPOSITION
:
3925 es
->flags
&= ~EF_VSCROLL_TRACK
;
3926 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
3927 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3933 * FIXME : the next two are undocumented !
3934 * Are we doing the right thing ?
3935 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3936 * although it's also a regular control message.
3939 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
3941 case EM_LINESCROLL16
:
3946 ERR(edit
, "undocumented (hacked) WM_VSCROLL parameter, please report\n");
3950 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
3955 /*********************************************************************
3960 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3964 if (!(es
->style
& ES_MULTILINE
))
3967 if (!(es
->style
& ES_AUTOVSCROLL
))
3970 if (!(es
->style
& WS_VSCROLL
))
3971 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3979 EDIT_EM_Scroll(wnd
, es
, action
);
3986 dy
= es
->line_count
- 1 - es
->y_offset
;
3989 es
->flags
|= EF_VSCROLL_TRACK
;
3990 dy
= pos
- es
->y_offset
;
3992 case SB_THUMBPOSITION
:
3993 es
->flags
&= ~EF_VSCROLL_TRACK
;
3994 if (!(dy
= pos
- es
->y_offset
)) {
3995 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
3996 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4003 ERR(edit
, "undocumented WM_VSCROLL action %d, please report\n",
4008 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);