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)
19 #include "wine/winbase16.h"
23 #include "debugtools.h"
27 DECLARE_DEBUG_CHANNEL(combo
)
28 DECLARE_DEBUG_CHANNEL(edit
)
29 DECLARE_DEBUG_CHANNEL(relay
)
31 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
32 FIXME: BTW, new specs say 65535 (do you dare ???) */
33 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
34 #define BUFSTART_MULTI 1024 /* starting size */
35 #define BUFSTART_SINGLE 256 /* starting size */
36 #define GROWLENGTH 64 /* buffers grow by this much */
37 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
40 * extra flags for EDITSTATE.flags field
42 #define EF_MODIFIED 0x0001 /* text has been modified */
43 #define EF_FOCUSED 0x0002 /* we have input focus */
44 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
45 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
46 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
47 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
48 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
49 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
50 wrapped line, instead of in front of the next character */
51 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
55 END_0
= 0, /* line ends with terminating '\0' character */
56 END_WRAP
, /* line is wrapped */
57 END_HARD
, /* line ends with a hard return '\r\n' */
58 END_SOFT
/* line ends with a soft return '\r\r\n' */
61 typedef struct tagLINEDEF
{
62 INT length
; /* bruto length of a line in bytes */
63 INT net_length
; /* netto length of a line in visible characters */
65 INT width
; /* width of the line in pixels */
66 struct tagLINEDEF
*next
;
71 HANDLE heap
; /* our own heap */
72 LPSTR text
; /* the actual contents of the control */
73 INT buffer_size
; /* the size of the buffer */
74 INT buffer_limit
; /* the maximum size to which the buffer may grow */
75 HFONT font
; /* NULL means standard system font */
76 INT x_offset
; /* scroll offset for multi lines this is in pixels
77 for single lines it's in characters */
78 INT line_height
; /* height of a screen line in pixels */
79 INT char_width
; /* average character width in pixels */
80 DWORD style
; /* sane version of wnd->dwStyle */
81 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
82 INT undo_insert_count
; /* number of characters inserted in sequence */
83 INT undo_position
; /* character index of the insertion and deletion */
84 LPSTR undo_text
; /* deleted text */
85 INT undo_buffer_size
; /* size of the deleted text buffer */
86 INT selection_start
; /* == selection_end if no selection */
87 INT selection_end
; /* == current caret position */
88 CHAR password_char
; /* == 0 if no password char, and for multi line controls */
89 INT left_margin
; /* in pixels */
90 INT right_margin
; /* in pixels */
92 INT region_posx
; /* Position of cursor relative to region: */
93 INT region_posy
; /* -1: to left, 0: within, 1: to right */
94 EDITWORDBREAKPROC16 word_break_proc16
;
95 EDITWORDBREAKPROCA word_break_proc32A
;
96 INT line_count
; /* number of lines */
97 INT y_offset
; /* scroll offset in number of lines */
98 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
100 * only for multi line controls
102 INT lock_count
; /* amount of re-entries in the EditWndProc */
105 INT text_width
; /* width of the widest line in pixels */
106 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
107 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
108 HLOCAL hloc32
; /* for controls receiving EM_GETHANDLE */
112 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
113 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
115 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
116 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
118 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
119 do {TRACE_(edit)("notification " str " sent to hwnd=%08x\n", \
120 (UINT)(hwnd));} while(0)
122 /* used for disabled or read-only edit control */
123 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
124 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
125 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
126 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
127 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
128 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
129 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
130 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
131 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
132 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
133 (LPARAM)(wnd)->hwndSelf);} while(0)
134 #define DPRINTF_EDIT_MSG16(str) \
136 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
137 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
138 #define DPRINTF_EDIT_MSG32(str) \
140 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
141 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
143 /*********************************************************************
150 * These functions have trivial implementations
151 * We still like to call them internally
152 * "static inline" makes them more like macro's
154 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
155 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
156 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
157 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
160 * Helper functions only valid for one type of control
162 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
163 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
164 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
165 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
166 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
167 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
169 * Helper functions valid for both single line _and_ multi line controls
171 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
172 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
173 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
174 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
175 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
176 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
177 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
178 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
179 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
180 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
181 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
182 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
183 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
184 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
185 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
186 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
187 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
188 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
189 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
190 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
192 * EM_XXX message handlers
194 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
195 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
196 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
197 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
198 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
199 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
200 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
201 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
202 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
203 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
204 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
205 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
206 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
207 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
208 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
209 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
210 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
211 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
212 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
213 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
214 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
215 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
216 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
217 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
218 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
219 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
221 * WM_XXX message handlers
223 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
224 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
225 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
226 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
227 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
228 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
229 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
230 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
231 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
232 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
233 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
234 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
235 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
236 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
237 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
238 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
239 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
240 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
241 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
242 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
243 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
244 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
245 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
246 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
247 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
250 /*********************************************************************
255 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
257 return (es
->undo_insert_count
|| lstrlenA(es
->undo_text
));
261 /*********************************************************************
266 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
268 es
->undo_insert_count
= 0;
269 *es
->undo_text
= '\0';
273 /*********************************************************************
278 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
280 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
284 /*********************************************************************
289 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
291 EDIT_WM_Copy(wnd
, es
);
292 EDIT_WM_Clear(wnd
, es
);
296 /*********************************************************************
300 * The messages are in the order of the actual integer values
301 * (which can be found in include/windows.h)
302 * Whereever possible the 16 bit versions are converted to
303 * the 32 bit ones, so that we can 'fall through' to the
304 * helper functions. These are mostly 32 bit (with a few
305 * exceptions, clearly indicated by a '16' extension to their
309 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
310 WPARAM wParam
, LPARAM lParam
)
312 WND
*wnd
= WIN_FindWndPtr(hwnd
);
313 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
318 DPRINTF_EDIT_MSG32("WM_DESTROY");
319 EDIT_WM_Destroy(wnd
, es
);
324 DPRINTF_EDIT_MSG32("WM_NCCREATE");
325 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
331 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
336 EDIT_LockBuffer(wnd
, es
);
339 DPRINTF_EDIT_MSG16("EM_GETSEL");
344 DPRINTF_EDIT_MSG32("EM_GETSEL");
345 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
349 DPRINTF_EDIT_MSG16("EM_SETSEL");
350 if (SLOWORD(lParam
) == -1)
351 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
353 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
355 EDIT_EM_ScrollCaret(wnd
, es
);
359 DPRINTF_EDIT_MSG32("EM_SETSEL");
360 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
361 EDIT_EM_ScrollCaret(wnd
, es
);
366 DPRINTF_EDIT_MSG16("EM_GETRECT");
368 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
371 DPRINTF_EDIT_MSG32("EM_GETRECT");
373 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
377 DPRINTF_EDIT_MSG16("EM_SETRECT");
378 if ((es
->style
& ES_MULTILINE
) && lParam
) {
380 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
381 EDIT_SetRectNP(wnd
, es
, &rc
);
382 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
386 DPRINTF_EDIT_MSG32("EM_SETRECT");
387 if ((es
->style
& ES_MULTILINE
) && lParam
) {
388 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
389 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
394 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
395 if ((es
->style
& ES_MULTILINE
) && lParam
) {
397 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
398 EDIT_SetRectNP(wnd
, es
, &rc
);
402 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
403 if ((es
->style
& ES_MULTILINE
) && lParam
)
404 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
408 DPRINTF_EDIT_MSG16("EM_SCROLL");
411 DPRINTF_EDIT_MSG32("EM_SCROLL");
412 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
415 case EM_LINESCROLL16
:
416 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
417 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
418 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
421 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
422 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
425 case EM_SCROLLCARET16
:
426 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
429 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
430 EDIT_EM_ScrollCaret(wnd
, es
);
435 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
438 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
439 result
= ((es
->flags
& EF_MODIFIED
) != 0);
443 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
446 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
448 es
->flags
|= EF_MODIFIED
;
450 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
453 case EM_GETLINECOUNT16
:
454 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
456 case EM_GETLINECOUNT
:
457 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
458 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
462 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
463 if ((INT16
)wParam
== -1)
467 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
468 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
472 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
473 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
476 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
477 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
481 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
482 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
485 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
486 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
490 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
493 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
494 result
= EDIT_EM_GetThumb(wnd
, es
);
497 /* messages 0x00bf and 0x00c0 missing from specs */
500 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
503 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
504 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
508 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
511 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
512 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
515 case EM_LINELENGTH16
:
516 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
519 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
520 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
523 case EM_REPLACESEL16
:
524 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
525 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
528 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
529 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
533 /* message 0x00c3 missing from specs */
536 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
539 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
540 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
544 DPRINTF_EDIT_MSG16("EM_GETLINE");
545 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
548 DPRINTF_EDIT_MSG32("EM_GETLINE");
549 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
553 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
555 case EM_SETLIMITTEXT
:
556 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
557 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
561 DPRINTF_EDIT_MSG16("EM_CANUNDO");
564 DPRINTF_EDIT_MSG32("EM_CANUNDO");
565 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
569 DPRINTF_EDIT_MSG16("EM_UNDO");
574 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
575 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
579 DPRINTF_EDIT_MSG16("EM_FMTLINES");
582 DPRINTF_EDIT_MSG32("EM_FMTLINES");
583 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
586 case EM_LINEFROMCHAR16
:
587 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
589 case EM_LINEFROMCHAR
:
590 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
591 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
594 /* message 0x00ca missing from specs */
597 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
600 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
601 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
604 case EM_SETTABSTOPS16
:
605 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
606 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
609 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
610 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
613 case EM_SETPASSWORDCHAR16
:
614 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
616 case EM_SETPASSWORDCHAR
:
617 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
618 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
621 case EM_EMPTYUNDOBUFFER16
:
622 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
624 case EM_EMPTYUNDOBUFFER
:
625 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
626 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
629 case EM_GETFIRSTVISIBLELINE16
:
630 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
631 result
= es
->y_offset
;
633 case EM_GETFIRSTVISIBLELINE
:
634 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
635 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
638 case EM_SETREADONLY16
:
639 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
642 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
644 wnd
->dwStyle
|= ES_READONLY
;
645 es
->style
|= ES_READONLY
;
647 wnd
->dwStyle
&= ~ES_READONLY
;
648 es
->style
&= ~ES_READONLY
;
653 case EM_SETWORDBREAKPROC16
:
654 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
655 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
657 case EM_SETWORDBREAKPROC
:
658 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
659 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
662 case EM_GETWORDBREAKPROC16
:
663 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
664 result
= (LRESULT
)es
->word_break_proc16
;
666 case EM_GETWORDBREAKPROC
:
667 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
668 result
= (LRESULT
)es
->word_break_proc32A
;
671 case EM_GETPASSWORDCHAR16
:
672 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
674 case EM_GETPASSWORDCHAR
:
675 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
676 result
= es
->password_char
;
679 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
682 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
683 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
687 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
688 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
691 case EM_GETLIMITTEXT
:
692 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
693 result
= es
->buffer_limit
;
697 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
698 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
702 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
703 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
707 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
708 result
= (es
->style
& ES_MULTILINE
) ?
709 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
710 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
714 DPRINTF_EDIT_MSG32("WM_CHAR");
715 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
719 DPRINTF_EDIT_MSG32("WM_CLEAR");
720 EDIT_WM_Clear(wnd
, es
);
724 DPRINTF_EDIT_MSG32("WM_COMMAND");
725 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
729 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
730 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
734 DPRINTF_EDIT_MSG32("WM_COPY");
735 EDIT_WM_Copy(wnd
, es
);
739 DPRINTF_EDIT_MSG32("WM_CREATE");
740 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
744 DPRINTF_EDIT_MSG32("WM_CUT");
745 EDIT_WM_Cut(wnd
, es
);
749 DPRINTF_EDIT_MSG32("WM_ENABLE");
750 InvalidateRect(hwnd
, NULL
, TRUE
);
754 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
755 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
759 DPRINTF_EDIT_MSG32("WM_GETFONT");
760 result
= (LRESULT
)es
->font
;
764 DPRINTF_EDIT_MSG32("WM_GETTEXT");
765 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
768 case WM_GETTEXTLENGTH
:
769 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
770 result
= lstrlenA(es
->text
);
774 DPRINTF_EDIT_MSG32("WM_HSCROLL");
775 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
779 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
780 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
784 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
785 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
788 case WM_LBUTTONDBLCLK
:
789 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
790 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
794 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
795 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
799 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
800 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
803 case WM_MOUSEACTIVATE
:
805 * FIXME: maybe DefWindowProc() screws up, but it seems that
806 * modalless dialog boxes need this. If we don't do this, the focus
807 * will _not_ be set by DefWindowProc() for edit controls in a
808 * modalless dialog box ???
810 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
811 SetFocus(wnd
->hwndSelf
);
812 result
= MA_ACTIVATE
;
817 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
819 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
823 DPRINTF_EDIT_MSG32("WM_PAINT");
824 EDIT_WM_Paint(wnd
, es
, wParam
);
828 DPRINTF_EDIT_MSG32("WM_PASTE");
829 EDIT_WM_Paste(wnd
, es
);
833 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
834 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
838 DPRINTF_EDIT_MSG32("WM_SETFONT");
839 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
843 DPRINTF_EDIT_MSG32("WM_SETTEXT");
844 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
849 DPRINTF_EDIT_MSG32("WM_SIZE");
850 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
854 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
855 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
859 DPRINTF_EDIT_MSG32("WM_TIMER");
860 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
864 DPRINTF_EDIT_MSG32("WM_VSCROLL");
865 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
869 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
872 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
874 WIN_ReleaseWndPtr(wnd
);
880 /*********************************************************************
882 * EDIT_BuildLineDefs_ML
884 * Build linked list of text lines.
885 * Lines can end with '\0' (last line), a character (if it is wrapped),
886 * a soft return '\r\r\n' or a hard return '\r\n'
889 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
895 LINEDEF
*current_def
;
896 LINEDEF
**previous_next
;
898 current_def
= es
->first_line_def
;
900 LINEDEF
*next_def
= current_def
->next
;
901 HeapFree(es
->heap
, 0, current_def
);
902 current_def
= next_def
;
903 } while (current_def
);
907 dc
= GetDC(wnd
->hwndSelf
);
909 old_font
= SelectObject(dc
, es
->font
);
911 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
913 previous_next
= &es
->first_line_def
;
915 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
916 current_def
->next
= NULL
;
919 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
924 current_def
->ending
= END_0
;
925 current_def
->net_length
= lstrlenA(start
);
926 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
927 current_def
->ending
= END_SOFT
;
928 current_def
->net_length
= cp
- start
- 1;
930 current_def
->ending
= END_HARD
;
931 current_def
->net_length
= cp
- start
;
933 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
934 start
, current_def
->net_length
,
935 es
->tabs_count
, es
->tabs
));
936 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
937 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
942 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
943 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
944 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
945 start
, next
, es
->tabs_count
, es
->tabs
));
946 } while (current_def
->width
<= fw
);
952 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
953 start
, next
, es
->tabs_count
, es
->tabs
));
954 } while (current_def
->width
<= fw
);
958 current_def
->net_length
= prev
;
959 current_def
->ending
= END_WRAP
;
960 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
961 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
963 switch (current_def
->ending
) {
965 current_def
->length
= current_def
->net_length
+ 3;
968 current_def
->length
= current_def
->net_length
+ 2;
972 current_def
->length
= current_def
->net_length
;
975 es
->text_width
= MAX(es
->text_width
, current_def
->width
);
976 start
+= current_def
->length
;
977 *previous_next
= current_def
;
978 previous_next
= ¤t_def
->next
;
980 } while (current_def
->ending
!= END_0
);
982 SelectObject(dc
, old_font
);
983 ReleaseDC(wnd
->hwndSelf
, dc
);
987 /*********************************************************************
989 * EDIT_CallWordBreakProc
991 * Call appropriate WordBreakProc (internal or external).
993 * Note: The "start" argument should always be an index refering
994 * to es->text. The actual wordbreak proc might be
995 * 16 bit, so we can't always pass any 32 bit LPSTR.
996 * Hence we assume that es->text is the buffer that holds
997 * the string under examination (we can decide this for ourselves).
1000 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1002 if (es
->word_break_proc16
) {
1003 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1004 SEGPTR segptr
= LocalLock16(hloc16
);
1005 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1006 segptr
+ start
, index
, count
, action
);
1007 LocalUnlock16(hloc16
);
1010 else if (es
->word_break_proc32A
)
1012 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1013 es
->word_break_proc32A
, es
->text
+ start
, index
,
1015 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1019 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1023 /*********************************************************************
1027 * Beware: This is not the function called on EM_CHARFROMPOS
1028 * The position _can_ be outside the formatting / client
1030 * The return value is only the character index
1033 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1039 if (es
->style
& ES_MULTILINE
) {
1040 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1042 LINEDEF
*line_def
= es
->first_line_def
;
1044 while ((line
> 0) && line_def
->next
) {
1045 line_index
+= line_def
->length
;
1046 line_def
= line_def
->next
;
1049 x
+= es
->x_offset
- es
->format_rect
.left
;
1050 if (x
>= line_def
->width
) {
1052 *after_wrap
= (line_def
->ending
== END_WRAP
);
1053 return line_index
+ line_def
->net_length
;
1057 *after_wrap
= FALSE
;
1060 dc
= GetDC(wnd
->hwndSelf
);
1062 old_font
= SelectObject(dc
, es
->font
);
1063 low
= line_index
+ 1;
1064 high
= line_index
+ line_def
->net_length
+ 1;
1065 while (low
< high
- 1)
1067 INT mid
= (low
+ high
) / 2;
1068 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1074 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1075 (line_def
->ending
== END_WRAP
));
1080 *after_wrap
= FALSE
;
1081 x
-= es
->format_rect
.left
;
1083 return es
->x_offset
;
1084 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1085 dc
= GetDC(wnd
->hwndSelf
);
1087 old_font
= SelectObject(dc
, es
->font
);
1091 INT high
= es
->x_offset
;
1092 while (low
< high
- 1)
1094 INT mid
= (low
+ high
) / 2;
1095 GetTextExtentPoint32A( dc
, text
+ mid
,
1096 es
->x_offset
- mid
, &size
);
1097 if (size
.cx
> -x
) low
= mid
;
1104 INT low
= es
->x_offset
;
1105 INT high
= lstrlenA(es
->text
) + 1;
1106 while (low
< high
- 1)
1108 INT mid
= (low
+ high
) / 2;
1109 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1110 mid
- es
->x_offset
, &size
);
1111 if (size
.cx
> x
) high
= mid
;
1116 if (es
->style
& ES_PASSWORD
)
1117 HeapFree(es
->heap
, 0 ,text
);
1120 SelectObject(dc
, old_font
);
1121 ReleaseDC(wnd
->hwndSelf
, dc
);
1126 /*********************************************************************
1130 * adjusts the point to be within the formatting rectangle
1131 * (so CharFromPos returns the nearest _visible_ character)
1134 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1136 *x
= MIN(MAX(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1137 *y
= MIN(MAX(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1141 /*********************************************************************
1145 * Calculates the bounding rectangle for a line from a starting
1146 * column to an ending column.
1149 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1151 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1153 if (es
->style
& ES_MULTILINE
)
1154 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1156 rc
->top
= es
->format_rect
.top
;
1157 rc
->bottom
= rc
->top
+ es
->line_height
;
1158 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1159 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1163 /*********************************************************************
1165 * EDIT_GetPasswordPointer_SL
1167 * note: caller should free the (optionally) allocated buffer
1170 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1172 if (es
->style
& ES_PASSWORD
) {
1173 INT len
= lstrlenA(es
->text
);
1174 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1175 RtlFillMemory(text
, len
, es
->password_char
);
1183 /*********************************************************************
1187 * This acts as a LOCAL_Lock(), but it locks only once. This way
1188 * you can call it whenever you like, without unlocking.
1191 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1194 ERR_(edit
)("no EDITSTATE ... please report\n");
1197 if (!(es
->style
& ES_MULTILINE
))
1201 es
->text
= LocalLock(es
->hloc32
);
1202 else if (es
->hloc16
)
1203 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1205 ERR_(edit
)("no buffer ... please report\n");
1213 /*********************************************************************
1215 * EDIT_SL_InvalidateText
1217 * Called from EDIT_InvalidateText().
1218 * Does the job for single-line controls only.
1221 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1226 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1227 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1228 InvalidateRect(wnd
->hwndSelf
, &rc
, FALSE
);
1232 /*********************************************************************
1234 * EDIT_ML_InvalidateText
1236 * Called from EDIT_InvalidateText().
1237 * Does the job for multi-line controls only.
1240 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1242 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1243 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1244 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1253 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1256 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1257 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1258 if (sl
< es
->y_offset
) {
1262 if (el
> es
->y_offset
+ vlc
) {
1263 el
= es
->y_offset
+ vlc
;
1264 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1266 GetClientRect(wnd
->hwndSelf
, &rc1
);
1267 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1269 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1270 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1271 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1273 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1274 EDIT_EM_LineLength(wnd
, es
,
1275 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1277 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1278 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1279 for (l
= sl
+ 1 ; l
< el
; l
++) {
1280 EDIT_GetLineRect(wnd
, es
, l
, 0,
1281 EDIT_EM_LineLength(wnd
, es
,
1282 EDIT_EM_LineIndex(wnd
, es
, l
)),
1284 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1285 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1287 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1288 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1289 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1294 /*********************************************************************
1296 * EDIT_InvalidateText
1298 * Invalidate the text from offset start upto, but not including,
1299 * offset end. Useful for (re)painting the selection.
1300 * Regions outside the linewidth are not invalidated.
1301 * end == -1 means end == TextLength.
1302 * start and end need not be ordered.
1305 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1311 end
= lstrlenA(es
->text
);
1313 ORDER_INT(start
, end
);
1315 if (es
->style
& ES_MULTILINE
)
1316 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1318 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1322 /*********************************************************************
1326 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1329 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1334 if (size
<= es
->buffer_size
)
1336 if (size
> es
->buffer_limit
) {
1337 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1340 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1341 if (size
> es
->buffer_limit
)
1342 size
= es
->buffer_limit
;
1344 TRACE_(edit
)("trying to ReAlloc to %d+1\n", size
);
1346 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1348 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1349 es
->buffer_size
= MIN(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1351 es
->buffer_size
= 0;
1352 } else if (es
->hloc32
) {
1353 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1354 TRACE_(edit
)("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1355 es
->hloc32
= hNew32
;
1356 es
->buffer_size
= MIN(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1358 } else if (es
->hloc16
) {
1359 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1360 TRACE_(edit
)("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1361 es
->hloc16
= hNew16
;
1362 es
->buffer_size
= MIN(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1365 if (es
->buffer_size
< size
) {
1366 EDIT_LockBuffer(wnd
, es
);
1367 WARN_(edit
)("FAILED ! We now have %d+1\n", es
->buffer_size
);
1368 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1371 EDIT_LockBuffer(wnd
, es
);
1372 TRACE_(edit
)("We now have %d+1\n", es
->buffer_size
);
1378 /*********************************************************************
1382 * Try to fit size + 1 bytes in the undo buffer.
1385 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1387 if (size
<= es
->undo_buffer_size
)
1389 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1391 TRACE_(edit
)("trying to ReAlloc to %d+1\n", size
);
1393 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1394 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1395 if (es
->undo_buffer_size
< size
) {
1396 WARN_(edit
)("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1405 /*********************************************************************
1410 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1412 INT e
= es
->selection_end
;
1416 if ((es
->style
& ES_MULTILINE
) && e
&&
1417 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1419 if (e
&& (es
->text
[e
- 1] == '\r'))
1423 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1424 EDIT_EM_ScrollCaret(wnd
, es
);
1428 /*********************************************************************
1432 * Only for multi line controls
1433 * Move the caret one line down, on a column with the nearest
1434 * x coordinate on the screen (might be a different column).
1437 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1439 INT s
= es
->selection_start
;
1440 INT e
= es
->selection_end
;
1441 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1442 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1443 INT x
= SLOWORD(pos
);
1444 INT y
= SHIWORD(pos
);
1446 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1449 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1450 EDIT_EM_ScrollCaret(wnd
, es
);
1454 /*********************************************************************
1459 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1461 BOOL after_wrap
= FALSE
;
1464 if (es
->style
& ES_MULTILINE
)
1465 e
= EDIT_CharFromPos(wnd
, es
, 0x7fffffff,
1466 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1468 e
= lstrlenA(es
->text
);
1469 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1470 EDIT_EM_ScrollCaret(wnd
, es
);
1474 /*********************************************************************
1479 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1481 INT e
= es
->selection_end
;
1485 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1486 if (es
->text
[e
] == '\n')
1488 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1492 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1493 EDIT_EM_ScrollCaret(wnd
, es
);
1497 /*********************************************************************
1501 * Home key: move to beginning of line.
1504 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1508 if (es
->style
& ES_MULTILINE
)
1509 e
= EDIT_CharFromPos(wnd
, es
, 0x80000000,
1510 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1513 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1514 EDIT_EM_ScrollCaret(wnd
, es
);
1518 /*********************************************************************
1520 * EDIT_MovePageDown_ML
1522 * Only for multi line controls
1523 * Move the caret one page down, on a column with the nearest
1524 * x coordinate on the screen (might be a different column).
1527 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1529 INT s
= es
->selection_start
;
1530 INT e
= es
->selection_end
;
1531 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1532 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1533 INT x
= SLOWORD(pos
);
1534 INT y
= SHIWORD(pos
);
1536 e
= EDIT_CharFromPos(wnd
, es
, x
,
1537 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1541 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1542 EDIT_EM_ScrollCaret(wnd
, es
);
1546 /*********************************************************************
1548 * EDIT_MovePageUp_ML
1550 * Only for multi line controls
1551 * Move the caret one page up, on a column with the nearest
1552 * x coordinate on the screen (might be a different column).
1555 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1557 INT s
= es
->selection_start
;
1558 INT e
= es
->selection_end
;
1559 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1560 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1561 INT x
= SLOWORD(pos
);
1562 INT y
= SHIWORD(pos
);
1564 e
= EDIT_CharFromPos(wnd
, es
, x
,
1565 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1569 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1570 EDIT_EM_ScrollCaret(wnd
, es
);
1574 /*********************************************************************
1578 * Only for multi line controls
1579 * Move the caret one line up, on a column with the nearest
1580 * x coordinate on the screen (might be a different column).
1583 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1585 INT s
= es
->selection_start
;
1586 INT e
= es
->selection_end
;
1587 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1588 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1589 INT x
= SLOWORD(pos
);
1590 INT y
= SHIWORD(pos
);
1592 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1595 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1596 EDIT_EM_ScrollCaret(wnd
, es
);
1600 /*********************************************************************
1602 * EDIT_MoveWordBackward
1605 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1607 INT s
= es
->selection_start
;
1608 INT e
= es
->selection_end
;
1613 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1614 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1615 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1618 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1619 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1622 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1623 li
, e
- li
, ll
, WB_LEFT
);
1627 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1628 EDIT_EM_ScrollCaret(wnd
, es
);
1632 /*********************************************************************
1634 * EDIT_MoveWordForward
1637 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1639 INT s
= es
->selection_start
;
1640 INT e
= es
->selection_end
;
1645 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1646 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1647 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1649 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1650 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1652 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1653 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1657 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1658 EDIT_EM_ScrollCaret(wnd
, es
);
1662 /*********************************************************************
1667 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1669 INT s
= es
->selection_start
;
1670 INT e
= es
->selection_end
;
1677 if (es
->style
& ES_MULTILINE
) {
1678 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1679 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1684 TRACE_(edit
)("line=%d\n", line
);
1686 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1689 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1690 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1691 s
= es
->selection_start
;
1692 e
= es
->selection_end
;
1694 s
= MIN(li
+ ll
, MAX(li
, s
));
1695 e
= MIN(li
+ ll
, MAX(li
, e
));
1696 if (rev
&& (s
!= e
) &&
1697 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1698 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1699 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1700 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1702 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1706 /*********************************************************************
1711 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1721 BkColor
= GetBkColor(dc
);
1722 TextColor
= GetTextColor(dc
);
1724 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1725 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1727 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1728 if (es
->style
& ES_MULTILINE
) {
1729 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1730 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1732 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1733 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1734 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1736 if (es
->style
& ES_PASSWORD
)
1737 HeapFree(es
->heap
, 0, text
);
1740 SetBkColor(dc
, BkColor
);
1741 SetTextColor(dc
, TextColor
);
1747 /*********************************************************************
1752 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1755 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1756 INT x
= SLOWORD(res
);
1757 INT y
= SHIWORD(res
);
1759 if(x
< es
->format_rect
.left
)
1760 x
= es
->format_rect
.left
;
1761 if(x
> es
->format_rect
.right
- 2)
1762 x
= es
->format_rect
.right
- 2;
1763 if(y
> es
->format_rect
.bottom
)
1764 y
= es
->format_rect
.bottom
;
1765 if(y
< es
->format_rect
.top
)
1766 y
= es
->format_rect
.top
;
1772 /*********************************************************************
1776 * note: this is not (exactly) the handler called on EM_SETRECTNP
1777 * it is also used to set the rect of a single line control
1780 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1782 CopyRect(&es
->format_rect
, rc
);
1783 if (es
->style
& WS_BORDER
) {
1784 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1785 if(TWEAK_WineLook
== WIN31_LOOK
)
1787 es
->format_rect
.left
+= bw
;
1788 es
->format_rect
.top
+= bw
;
1789 es
->format_rect
.right
-= bw
;
1790 es
->format_rect
.bottom
-= bw
;
1792 es
->format_rect
.left
+= es
->left_margin
;
1793 es
->format_rect
.right
-= es
->right_margin
;
1794 es
->format_rect
.right
= MAX(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1795 if (es
->style
& ES_MULTILINE
)
1796 es
->format_rect
.bottom
= es
->format_rect
.top
+
1797 MAX(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1799 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1800 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1801 EDIT_BuildLineDefs_ML(wnd
, es
);
1805 /*********************************************************************
1810 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1813 ERR_(edit
)("no EDITSTATE ... please report\n");
1816 if (!(es
->style
& ES_MULTILINE
))
1818 if (!es
->lock_count
) {
1819 ERR_(edit
)("lock_count == 0 ... please report\n");
1823 ERR_(edit
)("es->text == 0 ... please report\n");
1826 if (force
|| (es
->lock_count
== 1)) {
1828 LocalUnlock(es
->hloc32
);
1830 } else if (es
->hloc16
) {
1831 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1839 /*********************************************************************
1841 * EDIT_WordBreakProc
1843 * Find the beginning of words.
1844 * Note: unlike the specs for a WordBreakProc, this function only
1845 * allows to be called without linebreaks between s[0] upto
1846 * s[count - 1]. Remember it is only called
1847 * internally, so we can decide this for ourselves.
1850 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1854 TRACE_(edit
)("s=%p, index=%u, count=%u, action=%d\n",
1855 s
, index
, count
, action
);
1863 if (s
[index
] == ' ') {
1864 while (index
&& (s
[index
] == ' '))
1867 while (index
&& (s
[index
] != ' '))
1869 if (s
[index
] == ' ')
1873 while (index
&& (s
[index
] != ' '))
1875 if (s
[index
] == ' ')
1885 if (s
[index
] == ' ')
1886 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1888 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1890 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1894 case WB_ISDELIMITER
:
1895 ret
= (s
[index
] == ' ');
1898 ERR_(edit
)("unknown action code, please report !\n");
1905 /*********************************************************************
1909 * returns line number (not index) in high-order word of result.
1910 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1911 * to Richedit, not to the edit control. Original documentation is valid.
1912 * FIXME: do the specs mean to return -1 if outside client area or
1913 * if outside formatting rectangle ???
1916 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1924 GetClientRect(wnd
->hwndSelf
, &rc
);
1925 if (!PtInRect(&rc
, pt
))
1928 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1929 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1933 /*********************************************************************
1937 * Enable or disable soft breaks.
1939 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1941 es
->flags
&= ~EF_USE_SOFTBRK
;
1943 es
->flags
|= EF_USE_SOFTBRK
;
1944 FIXME_(edit
)("soft break enabled, not implemented\n");
1950 /*********************************************************************
1954 * Hopefully this won't fire back at us.
1955 * We always start with a fixed buffer in our own heap.
1956 * However, with this message a 32 bit application requests
1957 * a handle to 32 bit moveable local heap memory, where it expects
1959 * It's a pity that from this moment on we have to use this
1960 * local heap, because applications may rely on the handle
1963 * In this function we'll try to switch to local heap.
1966 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1972 if (!(es
->style
& ES_MULTILINE
))
1977 else if (es
->hloc16
)
1978 return (HLOCAL
)es
->hloc16
;
1980 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
1981 ERR_(edit
)("could not allocate new 32 bit buffer\n");
1984 newSize
= MIN(LocalSize(newBuf
) - 1, es
->buffer_limit
);
1985 if (!(newText
= LocalLock(newBuf
))) {
1986 ERR_(edit
)("could not lock new 32 bit buffer\n");
1990 lstrcpyA(newText
, es
->text
);
1991 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1993 HeapFree(es
->heap
, 0, es
->text
);
1994 es
->hloc32
= newBuf
;
1995 es
->hloc16
= (HLOCAL16
)NULL
;
1996 es
->buffer_size
= newSize
;
1998 EDIT_LockBuffer(wnd
, es
);
1999 TRACE_(edit
)("switched to 32 bit local heap\n");
2005 /*********************************************************************
2009 * Hopefully this won't fire back at us.
2010 * We always start with a buffer in 32 bit linear memory.
2011 * However, with this message a 16 bit application requests
2012 * a handle of 16 bit local heap memory, where it expects to find
2014 * It's a pitty that from this moment on we have to use this
2015 * local heap, because applications may rely on the handle
2018 * In this function we'll try to switch to local heap.
2020 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2026 if (!(es
->style
& ES_MULTILINE
))
2032 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2033 if (!LocalInit16(wnd
->hInstance
, 0,
2034 GlobalSize16(wnd
->hInstance
))) {
2035 ERR_(edit
)("could not initialize local heap\n");
2038 TRACE_(edit
)("local heap initialized\n");
2040 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2041 ERR_(edit
)("could not allocate new 16 bit buffer\n");
2044 newSize
= MIN(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2045 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2046 ERR_(edit
)("could not lock new 16 bit buffer\n");
2047 LOCAL_Free(wnd
->hInstance
, newBuf
);
2050 lstrcpyA(newText
, es
->text
);
2051 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2053 HeapFree(es
->heap
, 0, es
->text
);
2054 else if (es
->hloc32
) {
2055 while (LocalFree(es
->hloc32
)) ;
2056 LocalFree(es
->hloc32
);
2058 es
->hloc32
= (HLOCAL
)NULL
;
2059 es
->hloc16
= newBuf
;
2060 es
->buffer_size
= newSize
;
2062 EDIT_LockBuffer(wnd
, es
);
2063 TRACE_(edit
)("switched to 16 bit buffer\n");
2069 /*********************************************************************
2074 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2080 if (es
->style
& ES_MULTILINE
) {
2081 if (line
>= es
->line_count
)
2085 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2087 len
= MIN(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2088 for (i
= 0 ; i
< len
; i
++) {
2093 return (LRESULT
)len
;
2097 /*********************************************************************
2102 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2104 UINT s
= es
->selection_start
;
2105 UINT e
= es
->selection_end
;
2112 return MAKELONG(s
, e
);
2116 /*********************************************************************
2120 * FIXME: is this right ? (or should it be only VSCROLL)
2121 * (and maybe only for edit controls that really have their
2122 * own scrollbars) (and maybe only for multiline controls ?)
2123 * All in all: very poorly documented
2125 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2126 * WM_VSCROLL handlers
2129 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2131 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2132 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2136 /*********************************************************************
2141 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2146 if (!(es
->style
& ES_MULTILINE
))
2148 if (index
> lstrlenA(es
->text
))
2149 return es
->line_count
- 1;
2151 index
= MIN(es
->selection_start
, es
->selection_end
);
2154 line_def
= es
->first_line_def
;
2155 index
-= line_def
->length
;
2156 while ((index
>= 0) && line_def
->next
) {
2158 line_def
= line_def
->next
;
2159 index
-= line_def
->length
;
2165 /*********************************************************************
2170 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2175 if (!(es
->style
& ES_MULTILINE
))
2177 if (line
>= es
->line_count
)
2181 line_def
= es
->first_line_def
;
2183 INT index
= es
->selection_end
- line_def
->length
;
2184 while ((index
>= 0) && line_def
->next
) {
2185 line_index
+= line_def
->length
;
2186 line_def
= line_def
->next
;
2187 index
-= line_def
->length
;
2191 line_index
+= line_def
->length
;
2192 line_def
= line_def
->next
;
2200 /*********************************************************************
2205 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2209 if (!(es
->style
& ES_MULTILINE
))
2210 return lstrlenA(es
->text
);
2214 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2215 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2216 return es->selection_start - es->line_defs[sl].offset +
2217 es->line_defs[el].offset +
2218 es->line_defs[el].length - es->selection_end;
2222 line_def
= es
->first_line_def
;
2223 index
-= line_def
->length
;
2224 while ((index
>= 0) && line_def
->next
) {
2225 line_def
= line_def
->next
;
2226 index
-= line_def
->length
;
2228 return line_def
->net_length
;
2232 /*********************************************************************
2236 * FIXME: dx is in average character widths
2237 * However, we assume it is in pixels when we use this
2238 * function internally
2241 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2245 if (!(es
->style
& ES_MULTILINE
))
2248 if (-dx
> es
->x_offset
)
2250 if (dx
> es
->text_width
- es
->x_offset
)
2251 dx
= es
->text_width
- es
->x_offset
;
2252 nyoff
= MAX(0, es
->y_offset
+ dy
);
2253 if (nyoff
>= es
->line_count
)
2254 nyoff
= es
->line_count
- 1;
2255 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2259 GetClientRect(wnd
->hwndSelf
, &rc1
);
2260 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2261 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2262 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2263 es
->y_offset
= nyoff
;
2266 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2267 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2268 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2269 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2274 /*********************************************************************
2279 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2281 INT len
= lstrlenA(es
->text
);
2290 index
= MIN(index
, len
);
2291 dc
= GetDC(wnd
->hwndSelf
);
2293 old_font
= SelectObject(dc
, es
->font
);
2294 if (es
->style
& ES_MULTILINE
) {
2295 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2296 y
= (l
- es
->y_offset
) * es
->line_height
;
2297 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2298 if (after_wrap
&& (li
== index
) && l
) {
2300 LINEDEF
*line_def
= es
->first_line_def
;
2302 line_def
= line_def
->next
;
2305 if (line_def
->ending
== END_WRAP
) {
2307 y
-= es
->line_height
;
2308 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2311 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2312 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2314 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2315 if (index
< es
->x_offset
) {
2316 GetTextExtentPoint32A(dc
, text
+ index
,
2317 es
->x_offset
- index
, &size
);
2320 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2321 index
- es
->x_offset
, &size
);
2325 if (es
->style
& ES_PASSWORD
)
2326 HeapFree(es
->heap
, 0 ,text
);
2328 x
+= es
->format_rect
.left
;
2329 y
+= es
->format_rect
.top
;
2331 SelectObject(dc
, old_font
);
2332 ReleaseDC(wnd
->hwndSelf
, dc
);
2333 return MAKELONG((INT16
)x
, (INT16
)y
);
2337 /*********************************************************************
2341 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2344 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2346 INT strl
= lstrlenA(lpsz_replace
);
2347 INT tl
= lstrlenA(es
->text
);
2354 s
= es
->selection_start
;
2355 e
= es
->selection_end
;
2357 if ((s
== e
) && !strl
)
2362 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2366 /* there is something to be deleted */
2368 utl
= lstrlenA(es
->undo_text
);
2369 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2370 /* undo-buffer is extended to the right */
2371 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2372 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2373 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2374 /* undo-buffer is extended to the left */
2375 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2376 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2378 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2379 p
[i
] = (es
->text
+ s
)[i
];
2380 es
->undo_position
= s
;
2382 /* new undo-buffer */
2383 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2384 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2385 es
->undo_position
= s
;
2387 /* any deletion makes the old insertion-undo invalid */
2388 es
->undo_insert_count
= 0;
2390 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2393 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2396 /* there is an insertion */
2398 if ((s
== es
->undo_position
) ||
2399 ((es
->undo_insert_count
) &&
2400 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2402 * insertion is new and at delete position or
2403 * an extension to either left or right
2405 es
->undo_insert_count
+= strl
;
2407 /* new insertion undo */
2408 es
->undo_position
= s
;
2409 es
->undo_insert_count
= strl
;
2410 /* new insertion makes old delete-buffer invalid */
2411 *es
->undo_text
= '\0';
2414 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2417 tl
= lstrlenA(es
->text
);
2418 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2420 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2421 p
[i
] = lpsz_replace
[i
];
2422 if(es
->style
& ES_UPPERCASE
)
2423 CharUpperBuffA(p
, strl
);
2424 else if(es
->style
& ES_LOWERCASE
)
2425 CharLowerBuffA(p
, strl
);
2428 /* FIXME: really inefficient */
2429 if (es
->style
& ES_MULTILINE
)
2430 EDIT_BuildLineDefs_ML(wnd
, es
);
2432 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2433 es
->flags
|= EF_MODIFIED
;
2434 es
->flags
|= EF_UPDATE
;
2435 EDIT_EM_ScrollCaret(wnd
, es
);
2437 /* FIXME: really inefficient */
2438 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2442 /*********************************************************************
2447 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2451 if (!(es
->style
& ES_MULTILINE
))
2452 return (LRESULT
)FALSE
;
2462 if (es
->y_offset
< es
->line_count
- 1)
2467 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2470 if (es
->y_offset
< es
->line_count
- 1)
2471 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2474 return (LRESULT
)FALSE
;
2477 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2478 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2480 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2484 /*********************************************************************
2489 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2491 if (es
->style
& ES_MULTILINE
) {
2496 INT cw
= es
->char_width
;
2501 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2502 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2503 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2504 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2505 if (l
>= es
->y_offset
+ vlc
)
2506 dy
= l
- vlc
+ 1 - es
->y_offset
;
2507 if (l
< es
->y_offset
)
2508 dy
= l
- es
->y_offset
;
2509 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2510 if (x
< es
->format_rect
.left
)
2511 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2512 if (x
> es
->format_rect
.right
)
2513 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2515 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2521 if (!(es
->style
& ES_AUTOHSCROLL
))
2524 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2525 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2526 if (x
< es
->format_rect
.left
) {
2527 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2530 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2531 } while ((x
< goal
) && es
->x_offset
);
2532 /* FIXME: use ScrollWindow() somehow to improve performance */
2533 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2534 } else if (x
> es
->format_rect
.right
) {
2536 INT len
= lstrlenA(es
->text
);
2537 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2540 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2541 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2542 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2543 /* FIXME: use ScrollWindow() somehow to improve performance */
2544 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2550 /*********************************************************************
2554 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2557 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2559 if (!(es
->style
& ES_MULTILINE
))
2563 WARN_(edit
)("called with NULL handle\n");
2567 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2569 * old buffer is freed by caller, unless
2570 * it is still in our own heap. (in that case
2571 * we free it, correcting the buggy caller.)
2574 HeapFree(es
->heap
, 0, es
->text
);
2576 es
->hloc16
= (HLOCAL16
)NULL
;
2579 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2580 EDIT_LockBuffer(wnd
, es
);
2582 es
->x_offset
= es
->y_offset
= 0;
2583 es
->selection_start
= es
->selection_end
= 0;
2584 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2585 es
->flags
&= ~EF_MODIFIED
;
2586 es
->flags
&= ~EF_UPDATE
;
2587 EDIT_BuildLineDefs_ML(wnd
, es
);
2588 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2589 EDIT_EM_ScrollCaret(wnd
, es
);
2593 /*********************************************************************
2597 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2600 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2602 if (!(es
->style
& ES_MULTILINE
))
2606 WARN_(edit
)("called with NULL handle\n");
2610 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2612 * old buffer is freed by caller, unless
2613 * it is still in our own heap. (in that case
2614 * we free it, correcting the buggy caller.)
2617 HeapFree(es
->heap
, 0, es
->text
);
2620 es
->hloc32
= (HLOCAL
)NULL
;
2622 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2623 EDIT_LockBuffer(wnd
, es
);
2625 es
->x_offset
= es
->y_offset
= 0;
2626 es
->selection_start
= es
->selection_end
= 0;
2627 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2628 es
->flags
&= ~EF_MODIFIED
;
2629 es
->flags
&= ~EF_UPDATE
;
2630 EDIT_BuildLineDefs_ML(wnd
, es
);
2631 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2632 EDIT_EM_ScrollCaret(wnd
, es
);
2636 /*********************************************************************
2640 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2641 * However, the windows version is not complied to yet in all of edit.c
2644 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2646 if (es
->style
& ES_MULTILINE
) {
2648 es
->buffer_limit
= MIN(limit
, BUFLIMIT_MULTI
);
2650 es
->buffer_limit
= BUFLIMIT_MULTI
;
2653 es
->buffer_limit
= MIN(limit
, BUFLIMIT_SINGLE
);
2655 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2660 /*********************************************************************
2664 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2665 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2666 * of the char's width, according to the new docs.
2669 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2670 INT left
, INT right
)
2672 if (action
& EC_LEFTMARGIN
) {
2673 if (left
!= EC_USEFONTINFO
)
2674 es
->left_margin
= left
;
2676 es
->left_margin
= es
->char_width
/ 3;
2679 if (action
& EC_RIGHTMARGIN
) {
2680 if (right
!= EC_USEFONTINFO
)
2681 es
->right_margin
= right
;
2683 es
->right_margin
= es
->char_width
/ 3;
2685 TRACE_(edit
)("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2689 /*********************************************************************
2691 * EM_SETPASSWORDCHAR
2694 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2696 if (es
->style
& ES_MULTILINE
)
2699 if (es
->password_char
== c
)
2702 es
->password_char
= c
;
2704 wnd
->dwStyle
|= ES_PASSWORD
;
2705 es
->style
|= ES_PASSWORD
;
2707 wnd
->dwStyle
&= ~ES_PASSWORD
;
2708 es
->style
&= ~ES_PASSWORD
;
2710 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2714 /*********************************************************************
2718 * note: unlike the specs say: the order of start and end
2719 * _is_ preserved in Windows. (i.e. start can be > end)
2720 * In other words: this handler is OK
2723 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2725 UINT old_start
= es
->selection_start
;
2726 UINT old_end
= es
->selection_end
;
2727 UINT len
= lstrlenA(es
->text
);
2730 start
= es
->selection_end
;
2731 end
= es
->selection_end
;
2733 start
= MIN(start
, len
);
2734 end
= MIN(end
, len
);
2736 es
->selection_start
= start
;
2737 es
->selection_end
= end
;
2739 es
->flags
|= EF_AFTER_WRAP
;
2741 es
->flags
&= ~EF_AFTER_WRAP
;
2742 if (es
->flags
& EF_FOCUSED
)
2743 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2744 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2745 ORDER_UINT(start
, end
);
2746 ORDER_UINT(end
, old_end
);
2747 ORDER_UINT(start
, old_start
);
2748 ORDER_UINT(old_start
, old_end
);
2749 if (end
!= old_start
)
2753 * ORDER_UINT32(end, old_start);
2754 * EDIT_InvalidateText(wnd, es, start, end);
2755 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2756 * in place of the following if statement.
2758 if (old_start
> end
)
2760 EDIT_InvalidateText(wnd
, es
, start
, end
);
2761 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2765 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2766 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2769 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2773 /*********************************************************************
2778 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2780 if (!(es
->style
& ES_MULTILINE
))
2783 HeapFree(es
->heap
, 0, es
->tabs
);
2784 es
->tabs_count
= count
;
2788 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2789 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2795 /*********************************************************************
2800 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2802 if (!(es
->style
& ES_MULTILINE
))
2805 HeapFree(es
->heap
, 0, es
->tabs
);
2806 es
->tabs_count
= count
;
2811 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2812 for (i
= 0 ; i
< count
; i
++)
2813 es
->tabs
[i
] = *tabs
++;
2819 /*********************************************************************
2821 * EM_SETWORDBREAKPROC
2824 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2826 if (es
->word_break_proc32A
== wbp
)
2829 es
->word_break_proc32A
= wbp
;
2830 es
->word_break_proc16
= NULL
;
2831 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2832 EDIT_BuildLineDefs_ML(wnd
, es
);
2833 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2838 /*********************************************************************
2840 * EM_SETWORDBREAKPROC16
2843 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2845 if (es
->word_break_proc16
== wbp
)
2848 es
->word_break_proc32A
= NULL
;
2849 es
->word_break_proc16
= wbp
;
2850 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2851 EDIT_BuildLineDefs_ML(wnd
, es
);
2852 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2857 /*********************************************************************
2862 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2864 INT ulength
= lstrlenA(es
->undo_text
);
2865 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2867 lstrcpyA(utext
, es
->undo_text
);
2869 TRACE_(edit
)("before UNDO:insertion length = %d, deletion buffer = %s\n",
2870 es
->undo_insert_count
, utext
);
2872 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2873 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2874 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2875 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2876 HeapFree(es
->heap
, 0, utext
);
2878 TRACE_(edit
)("after UNDO:insertion length = %d, deletion buffer = %s\n",
2879 es
->undo_insert_count
, es
->undo_text
);
2885 /*********************************************************************
2890 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2895 if (es
->style
& ES_MULTILINE
) {
2896 if (es
->style
& ES_READONLY
) {
2897 EDIT_MoveHome(wnd
, es
, FALSE
);
2898 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2900 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2904 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2905 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2908 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2912 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2919 /*********************************************************************
2924 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
2926 if (code
|| control
)
2931 EDIT_EM_Undo(wnd
, es
);
2934 EDIT_WM_Cut(wnd
, es
);
2937 EDIT_WM_Copy(wnd
, es
);
2940 EDIT_WM_Paste(wnd
, es
);
2943 EDIT_WM_Clear(wnd
, es
);
2946 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
2947 EDIT_EM_ScrollCaret(wnd
, es
);
2950 ERR_(edit
)("unknown menu item, please report\n");
2956 /*********************************************************************
2960 * Note: the resource files resource/sysres_??.rc cannot define a
2961 * single popup menu. Hence we use a (dummy) menubar
2962 * containing the single popup menu as its first item.
2964 * FIXME: the message identifiers have been chosen arbitrarily,
2965 * hence we use MF_BYPOSITION.
2966 * We might as well use the "real" values (anybody knows ?)
2967 * The menu definition is in resources/sysres_??.rc.
2968 * Once these are OK, we better use MF_BYCOMMAND here
2969 * (as we do in EDIT_WM_Command()).
2972 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
2974 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
2975 HMENU popup
= GetSubMenu(menu
, 0);
2976 UINT start
= es
->selection_start
;
2977 UINT end
= es
->selection_end
;
2979 ORDER_UINT(start
, end
);
2982 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
2984 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2986 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2988 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
2990 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
2992 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
2994 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
2999 /*********************************************************************
3004 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3006 INT s
= es
->selection_start
;
3007 INT e
= es
->selection_end
;
3014 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3015 dst
= GlobalLock(hdst
);
3016 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3018 OpenClipboard(wnd
->hwndSelf
);
3020 SetClipboardData(CF_TEXT
, hdst
);
3025 /*********************************************************************
3030 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3033 * To initialize some final structure members, we call some helper
3034 * functions. However, since the EDITSTATE is not consistent (i.e.
3035 * not fully initialized), we should be very careful which
3036 * functions can be called, and in what order.
3038 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3039 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3041 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3042 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3043 /* if we insert text to the editline, the text scrolls out
3044 * of the window, as the caret is placed after the insert
3045 * pos normally; thus we reset es->selection... to 0 and
3048 es
->selection_start
= es
->selection_end
= 0;
3049 EDIT_EM_ScrollCaret(wnd
, es
);
3055 /*********************************************************************
3060 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3063 while (LocalUnlock(es
->hloc32
)) ;
3064 LocalFree(es
->hloc32
);
3067 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3068 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3070 HeapDestroy(es
->heap
);
3071 HeapFree(GetProcessHeap(), 0, es
);
3072 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3076 /*********************************************************************
3081 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3086 if (!IsWindowEnabled(wnd
->hwndSelf
) || (es
->style
& ES_READONLY
))
3087 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3089 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3092 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3094 GetClientRect(wnd
->hwndSelf
, &rc
);
3095 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3096 GetClipBox(dc
, &rc
);
3098 * FIXME: specs say that we should UnrealizeObject() the brush,
3099 * but the specs of UnrealizeObject() say that we shouldn't
3100 * unrealize a stock object. The default brush that
3101 * DefWndProc() returns is ... a stock object.
3103 FillRect(dc
, &rc
, brush
);
3108 /*********************************************************************
3113 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3115 INT len
= lstrlenA(es
->text
);
3118 lstrcpyA(text
, es
->text
);
3125 /*********************************************************************
3129 * 16 bit notepad needs this. Actually it is not _our_ hack,
3130 * it is notepad's. Notepad is sending us scrollbar messages with
3131 * undocumented parameters without us even having a scrollbar ... !?!?
3134 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3137 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3140 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3141 ERR_(edit
)("hacked WM_HSCROLL handler invoked\n");
3142 ERR_(edit
)(" if you are _not_ running 16 bit notepad, please report\n");
3143 ERR_(edit
)(" (this message is only displayed once per edit control)\n");
3144 es
->flags
|= EF_HSCROLL_HACK
;
3150 dx
= -es
->char_width
;
3153 if (es
->x_offset
< es
->text_width
)
3154 dx
= es
->char_width
;
3158 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3161 if (es
->x_offset
< es
->text_width
)
3162 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3169 if (es
->x_offset
< es
->text_width
)
3170 dx
= es
->text_width
- es
->x_offset
;
3173 es
->flags
|= EF_HSCROLL_TRACK
;
3174 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3176 case SB_THUMBPOSITION
:
3177 es
->flags
&= ~EF_HSCROLL_TRACK
;
3178 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3179 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3185 * FIXME : the next two are undocumented !
3186 * Are we doing the right thing ?
3187 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3188 * although it's also a regular control message.
3191 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3193 case EM_LINESCROLL16
:
3198 ERR_(edit
)("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3202 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3207 /*********************************************************************
3212 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3217 if (!(es
->style
& ES_MULTILINE
))
3220 if (!(es
->style
& ES_AUTOHSCROLL
))
3223 if (!(es
->style
& WS_HSCROLL
))
3224 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3227 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3231 dx
= -es
->char_width
;
3234 if (es
->x_offset
< es
->text_width
)
3235 dx
= es
->char_width
;
3239 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3242 if (es
->x_offset
< es
->text_width
)
3243 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3250 if (es
->x_offset
< es
->text_width
)
3251 dx
= es
->text_width
- es
->x_offset
;
3254 es
->flags
|= EF_HSCROLL_TRACK
;
3255 dx
= pos
- es
->x_offset
;
3257 case SB_THUMBPOSITION
:
3258 es
->flags
&= ~EF_HSCROLL_TRACK
;
3259 if (!(dx
= pos
- es
->x_offset
)) {
3260 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3261 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3268 ERR_(edit
)("undocumented WM_HSCROLL parameter, please report\n");
3272 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3277 /*********************************************************************
3282 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3286 if (WIDGETS_IsControl(wnd
->parent
, BIC32_COMBO
) &&
3287 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3288 HWND hCombo
= wnd
->parent
->hwndSelf
;
3289 BOOL bUIFlip
= TRUE
;
3291 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3292 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3295 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3297 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3298 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3302 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3304 /* make sure ComboLBox pops up */
3305 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3306 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3307 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3310 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3311 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3313 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3314 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3316 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3325 /*********************************************************************
3329 * Handling of special keys that don't produce a WM_CHAR
3330 * (i.e. non-printable keys) & Backspace & Delete
3333 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3338 if (GetKeyState(VK_MENU
) & 0x8000)
3341 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3342 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3347 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3353 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3354 EDIT_MoveUp_ML(wnd
, es
, shift
);
3357 EDIT_MoveWordBackward(wnd
, es
, shift
);
3359 EDIT_MoveBackward(wnd
, es
, shift
);
3362 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3366 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3367 EDIT_MoveDown_ML(wnd
, es
, shift
);
3369 EDIT_MoveWordForward(wnd
, es
, shift
);
3371 EDIT_MoveForward(wnd
, es
, shift
);
3374 EDIT_MoveHome(wnd
, es
, shift
);
3377 EDIT_MoveEnd(wnd
, es
, shift
);
3380 if (es
->style
& ES_MULTILINE
)
3381 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3384 if (es
->style
& ES_MULTILINE
)
3385 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3388 if (!(es
->style
& ES_READONLY
) && !control
) {
3389 if (es
->selection_start
!= es
->selection_end
)
3390 EDIT_WM_Clear(wnd
, es
);
3392 /* delete character left of caret */
3393 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3394 EDIT_MoveBackward(wnd
, es
, TRUE
);
3395 EDIT_WM_Clear(wnd
, es
);
3400 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3401 if (es
->selection_start
!= es
->selection_end
) {
3403 EDIT_WM_Cut(wnd
, es
);
3405 EDIT_WM_Clear(wnd
, es
);
3408 /* delete character left of caret */
3409 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3410 EDIT_MoveBackward(wnd
, es
, TRUE
);
3411 EDIT_WM_Clear(wnd
, es
);
3412 } else if (control
) {
3413 /* delete to end of line */
3414 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3415 EDIT_MoveEnd(wnd
, es
, TRUE
);
3416 EDIT_WM_Clear(wnd
, es
);
3418 /* delete character right of caret */
3419 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3420 EDIT_MoveForward(wnd
, es
, TRUE
);
3421 EDIT_WM_Clear(wnd
, es
);
3428 if (!(es
->style
& ES_READONLY
))
3429 EDIT_WM_Paste(wnd
, es
);
3431 EDIT_WM_Copy(wnd
, es
);
3438 /*********************************************************************
3443 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3445 es
->flags
&= ~EF_FOCUSED
;
3447 if(!(es
->style
& ES_NOHIDESEL
))
3448 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3449 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3454 /*********************************************************************
3458 * The caret position has been set on the WM_LBUTTONDOWN message
3461 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3464 INT e
= es
->selection_end
;
3469 if (!(es
->flags
& EF_FOCUSED
))
3472 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3473 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3474 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3475 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3476 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3477 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3478 EDIT_EM_ScrollCaret(wnd
, es
);
3483 /*********************************************************************
3488 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3493 if (!(es
->flags
& EF_FOCUSED
))
3496 es
->bCaptureState
= TRUE
;
3497 SetCapture(wnd
->hwndSelf
);
3498 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3499 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3500 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3501 EDIT_EM_ScrollCaret(wnd
, es
);
3502 es
->region_posx
= es
->region_posy
= 0;
3503 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3508 /*********************************************************************
3513 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3515 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3516 KillTimer(wnd
->hwndSelf
, 0);
3519 es
->bCaptureState
= FALSE
;
3524 /*********************************************************************
3529 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3535 if (GetCapture() != wnd
->hwndSelf
)
3539 * FIXME: gotta do some scrolling if outside client
3540 * area. Maybe reset the timer ?
3543 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3544 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3545 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3546 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3547 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3552 /*********************************************************************
3557 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3561 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3563 *(EDITSTATE
**)wnd
->wExtra
= es
;
3566 * Note: since the EDITSTATE has not been fully initialized yet,
3567 * we can't use any API calls that may send
3568 * WM_XXX messages before WM_NCCREATE is completed.
3571 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3573 es
->style
= cs
->style
;
3576 * In Win95 look and feel, the WS_BORDER style is replaced by the
3577 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3578 * control a non client area.
3580 if (TWEAK_WineLook
!= WIN31_LOOK
)
3582 if (es
->style
& WS_BORDER
)
3584 es
->style
&= ~WS_BORDER
;
3585 wnd
->dwStyle
&= ~WS_BORDER
;
3586 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3591 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3592 wnd
->dwStyle
&= ~WS_BORDER
;
3595 if (es
->style
& ES_MULTILINE
) {
3596 es
->buffer_size
= BUFSTART_MULTI
;
3597 es
->buffer_limit
= BUFLIMIT_MULTI
;
3598 if (es
->style
& WS_VSCROLL
)
3599 es
->style
|= ES_AUTOVSCROLL
;
3600 if (es
->style
& WS_HSCROLL
)
3601 es
->style
|= ES_AUTOHSCROLL
;
3602 es
->style
&= ~ES_PASSWORD
;
3603 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3604 if (es
->style
& ES_RIGHT
)
3605 es
->style
&= ~ES_CENTER
;
3606 es
->style
&= ~WS_HSCROLL
;
3607 es
->style
&= ~ES_AUTOHSCROLL
;
3610 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3611 es
->style
|= ES_AUTOVSCROLL
;
3613 es
->buffer_size
= BUFSTART_SINGLE
;
3614 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3615 es
->style
&= ~ES_CENTER
;
3616 es
->style
&= ~ES_RIGHT
;
3617 es
->style
&= ~WS_HSCROLL
;
3618 es
->style
&= ~WS_VSCROLL
;
3619 es
->style
&= ~ES_AUTOVSCROLL
;
3620 es
->style
&= ~ES_WANTRETURN
;
3621 if (es
->style
& ES_UPPERCASE
) {
3622 es
->style
&= ~ES_LOWERCASE
;
3623 es
->style
&= ~ES_NUMBER
;
3624 } else if (es
->style
& ES_LOWERCASE
)
3625 es
->style
&= ~ES_NUMBER
;
3626 if (es
->style
& ES_PASSWORD
)
3627 es
->password_char
= '*';
3629 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3630 es
->style
|= ES_AUTOHSCROLL
;
3632 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3634 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3635 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3637 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3639 if (es
->style
& ES_MULTILINE
)
3640 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3647 /*********************************************************************
3652 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3661 BOOL rev
= IsWindowEnabled(wnd
->hwndSelf
) &&
3662 ((es
->flags
& EF_FOCUSED
) ||
3663 (es
->style
& ES_NOHIDESEL
));
3665 if (es
->flags
& EF_UPDATE
)
3666 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3669 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3672 if(es
->style
& WS_BORDER
) {
3673 GetClientRect(wnd
->hwndSelf
, &rc
);
3674 if(es
->style
& ES_MULTILINE
) {
3675 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3676 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3678 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3680 IntersectClipRect(dc
, es
->format_rect
.left
,
3681 es
->format_rect
.top
,
3682 es
->format_rect
.right
,
3683 es
->format_rect
.bottom
);
3684 if (es
->style
& ES_MULTILINE
) {
3685 GetClientRect(wnd
->hwndSelf
, &rc
);
3686 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3689 old_font
= SelectObject(dc
, es
->font
);
3690 if (!IsWindowEnabled(wnd
->hwndSelf
) || (es
->style
& ES_READONLY
))
3691 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3693 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3694 if (!IsWindowEnabled(wnd
->hwndSelf
))
3695 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3696 GetClipBox(dc
, &rcRgn
);
3697 if (es
->style
& ES_MULTILINE
) {
3698 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3699 for (i
= es
->y_offset
; i
<= MIN(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3700 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3701 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3702 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3705 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3706 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3707 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3710 SelectObject(dc
, old_font
);
3711 if (es
->flags
& EF_FOCUSED
)
3712 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3713 es
->flags
& EF_AFTER_WRAP
);
3715 EndPaint(wnd
->hwndSelf
, &ps
);
3716 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3717 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3719 si
.cbSize
= sizeof(SCROLLINFO
);
3720 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3722 si
.nMax
= es
->line_count
+ vlc
- 2;
3724 si
.nPos
= es
->y_offset
;
3725 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3727 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3729 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3730 si
.cbSize
= sizeof(SCROLLINFO
);
3731 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3733 si
.nMax
= es
->text_width
+ fw
- 1;
3735 si
.nPos
= es
->x_offset
;
3736 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3739 if (es
->flags
& EF_UPDATE
) {
3740 es
->flags
&= ~EF_UPDATE
;
3741 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3746 /*********************************************************************
3751 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3756 OpenClipboard(wnd
->hwndSelf
);
3757 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3758 src
= (LPSTR
)GlobalLock(hsrc
);
3759 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3766 /*********************************************************************
3771 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3773 es
->flags
|= EF_FOCUSED
;
3774 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3775 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3776 es
->flags
& EF_AFTER_WRAP
);
3777 if(!(es
->style
& ES_NOHIDESEL
))
3778 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3779 ShowCaret(wnd
->hwndSelf
);
3780 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3784 /*********************************************************************
3788 * With Win95 look the margins are set to default font value unless
3789 * the system font (font == 0) is being set, in which case they are left
3793 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3800 dc
= GetDC(wnd
->hwndSelf
);
3802 old_font
= SelectObject(dc
, font
);
3803 GetTextMetricsA(dc
, &tm
);
3804 es
->line_height
= tm
.tmHeight
;
3805 es
->char_width
= tm
.tmAveCharWidth
;
3807 SelectObject(dc
, old_font
);
3808 ReleaseDC(wnd
->hwndSelf
, dc
);
3809 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3810 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3811 EC_USEFONTINFO
, EC_USEFONTINFO
);
3812 if (es
->style
& ES_MULTILINE
)
3813 EDIT_BuildLineDefs_ML(wnd
, es
);
3816 GetClientRect(wnd
->hwndSelf
, &r
);
3817 EDIT_SetRectNP(wnd
, es
, &r
);
3820 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3821 if (es
->flags
& EF_FOCUSED
) {
3823 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3824 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3825 es
->flags
& EF_AFTER_WRAP
);
3826 ShowCaret(wnd
->hwndSelf
);
3831 /*********************************************************************
3836 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3837 * The modified flag is reset. No notifications are sent.
3839 * For single-line controls, reception of WM_SETTEXT triggers:
3840 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3843 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3845 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3847 TRACE_(edit
)("\t'%s'\n", text
);
3848 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3850 TRACE_(edit
)("\t<NULL>\n");
3851 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3854 if (es
->style
& ES_MULTILINE
) {
3855 es
->flags
&= ~EF_UPDATE
;
3857 es
->flags
|= EF_UPDATE
;
3859 es
->flags
&= ~EF_MODIFIED
;
3860 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3861 EDIT_EM_ScrollCaret(wnd
, es
);
3865 /*********************************************************************
3870 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3872 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3874 SetRect(&rc
, 0, 0, width
, height
);
3875 EDIT_SetRectNP(wnd
, es
, &rc
);
3876 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3881 /*********************************************************************
3886 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3888 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3889 if (EDIT_EM_CanUndo(wnd
, es
))
3890 EDIT_EM_Undo(wnd
, es
);
3892 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3893 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3895 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
3899 /*********************************************************************
3904 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
3906 if (es
->region_posx
< 0) {
3907 EDIT_MoveBackward(wnd
, es
, TRUE
);
3908 } else if (es
->region_posx
> 0) {
3909 EDIT_MoveForward(wnd
, es
, TRUE
);
3912 * FIXME: gotta do some vertical scrolling here, like
3913 * EDIT_EM_LineScroll(wnd, 0, 1);
3918 /*********************************************************************
3922 * 16 bit notepad needs this. Actually it is not _our_ hack,
3923 * it is notepad's. Notepad is sending us scrollbar messages with
3924 * undocumented parameters without us even having a scrollbar ... !?!?
3927 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3932 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3933 ERR_(edit
)("hacked WM_VSCROLL handler invoked\n");
3934 ERR_(edit
)(" if you are _not_ running 16 bit notepad, please report\n");
3935 ERR_(edit
)(" (this message is only displayed once per edit control)\n");
3936 es
->flags
|= EF_VSCROLL_HACK
;
3944 EDIT_EM_Scroll(wnd
, es
, action
);
3950 dy
= es
->line_count
- 1 - es
->y_offset
;
3953 es
->flags
|= EF_VSCROLL_TRACK
;
3954 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
3956 case SB_THUMBPOSITION
:
3957 es
->flags
&= ~EF_VSCROLL_TRACK
;
3958 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
3959 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3965 * FIXME : the next two are undocumented !
3966 * Are we doing the right thing ?
3967 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3968 * although it's also a regular control message.
3971 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
3973 case EM_LINESCROLL16
:
3978 ERR_(edit
)("undocumented (hacked) WM_VSCROLL parameter, please report\n");
3982 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
3987 /*********************************************************************
3992 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3996 if (!(es
->style
& ES_MULTILINE
))
3999 if (!(es
->style
& ES_AUTOVSCROLL
))
4002 if (!(es
->style
& WS_VSCROLL
))
4003 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4011 EDIT_EM_Scroll(wnd
, es
, action
);
4018 dy
= es
->line_count
- 1 - es
->y_offset
;
4021 es
->flags
|= EF_VSCROLL_TRACK
;
4022 dy
= pos
- es
->y_offset
;
4024 case SB_THUMBPOSITION
:
4025 es
->flags
&= ~EF_VSCROLL_TRACK
;
4026 if (!(dy
= pos
- es
->y_offset
)) {
4027 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4028 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4035 ERR_(edit
)("undocumented WM_VSCROLL action %d, please report\n",
4040 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);