4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
11 * please read EDIT.TODO (and update it when you change things)
21 #include "wine/winbase16.h"
24 #include "selectors.h"
25 #include "debugtools.h"
28 #include "winversion.h"
30 DEFAULT_DEBUG_CHANNEL(edit
)
31 DECLARE_DEBUG_CHANNEL(combo
)
32 DECLARE_DEBUG_CHANNEL(relay
)
34 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
35 FIXME: BTW, new specs say 65535 (do you dare ???) */
36 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
37 #define BUFSTART_MULTI 1024 /* starting size */
38 #define BUFSTART_SINGLE 256 /* starting size */
39 #define GROWLENGTH 64 /* buffers grow by this much */
40 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
43 * extra flags for EDITSTATE.flags field
45 #define EF_MODIFIED 0x0001 /* text has been modified */
46 #define EF_FOCUSED 0x0002 /* we have input focus */
47 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
48 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
49 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
50 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
51 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
52 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
53 wrapped line, instead of in front of the next character */
54 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
58 END_0
= 0, /* line ends with terminating '\0' character */
59 END_WRAP
, /* line is wrapped */
60 END_HARD
, /* line ends with a hard return '\r\n' */
61 END_SOFT
/* line ends with a soft return '\r\r\n' */
64 typedef struct tagLINEDEF
{
65 INT length
; /* bruto length of a line in bytes */
66 INT net_length
; /* netto length of a line in visible characters */
68 INT width
; /* width of the line in pixels */
69 struct tagLINEDEF
*next
;
74 HANDLE heap
; /* our own heap */
75 LPSTR text
; /* the actual contents of the control */
76 INT buffer_size
; /* the size of the buffer */
77 INT buffer_limit
; /* the maximum size to which the buffer may grow */
78 HFONT font
; /* NULL means standard system font */
79 INT x_offset
; /* scroll offset for multi lines this is in pixels
80 for single lines it's in characters */
81 INT line_height
; /* height of a screen line in pixels */
82 INT char_width
; /* average character width in pixels */
83 DWORD style
; /* sane version of wnd->dwStyle */
84 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
85 INT undo_insert_count
; /* number of characters inserted in sequence */
86 INT undo_position
; /* character index of the insertion and deletion */
87 LPSTR undo_text
; /* deleted text */
88 INT undo_buffer_size
; /* size of the deleted text buffer */
89 INT selection_start
; /* == selection_end if no selection */
90 INT selection_end
; /* == current caret position */
91 CHAR password_char
; /* == 0 if no password char, and for multi line controls */
92 INT left_margin
; /* in pixels */
93 INT right_margin
; /* in pixels */
95 INT region_posx
; /* Position of cursor relative to region: */
96 INT region_posy
; /* -1: to left, 0: within, 1: to right */
97 EDITWORDBREAKPROC16 word_break_proc16
;
98 EDITWORDBREAKPROCA word_break_proc32A
;
99 INT line_count
; /* number of lines */
100 INT y_offset
; /* scroll offset in number of lines */
101 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
102 BOOL bEnableState
; /* flag keeping the enable state */
104 * only for multi line controls
106 INT lock_count
; /* amount of re-entries in the EditWndProc */
109 INT text_width
; /* width of the widest line in pixels */
110 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
111 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
112 HLOCAL hloc32
; /* for controls receiving EM_GETHANDLE */
116 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
117 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
119 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
120 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
122 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
123 do {TRACE("notification " str " sent to hwnd=%08x\n", \
124 (UINT)(hwnd));} while(0)
126 /* used for disabled or read-only edit control */
127 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
128 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
129 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
130 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
131 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
132 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
133 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
134 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
135 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
136 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
137 (LPARAM)(wnd)->hwndSelf);} while(0)
138 #define DPRINTF_EDIT_MSG16(str) \
140 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
141 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
142 #define DPRINTF_EDIT_MSG32(str) \
144 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
145 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
147 /*********************************************************************
154 * These functions have trivial implementations
155 * We still like to call them internally
156 * "static inline" makes them more like macro's
158 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
159 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
160 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
161 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
164 * Helper functions only valid for one type of control
166 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
167 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
168 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
169 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
170 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
171 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
173 * Helper functions valid for both single line _and_ multi line controls
175 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
176 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
177 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
178 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
179 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
180 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
181 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
182 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
183 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
184 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
185 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
186 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
187 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
188 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
189 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
190 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
191 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
192 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
193 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
194 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
196 * EM_XXX message handlers
198 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
199 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
200 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
201 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
202 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
203 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
204 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
205 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
206 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
207 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
208 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
209 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
210 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
211 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
212 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
213 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
214 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
215 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
216 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
217 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
218 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
219 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
220 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
221 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
222 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
223 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
225 * WM_XXX message handlers
227 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
228 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
229 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
230 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
231 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
232 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
233 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
234 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
235 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
236 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
237 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
238 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
239 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
240 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
241 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
242 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
243 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
244 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
245 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
246 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
247 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
248 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
249 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
250 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
251 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
254 /*********************************************************************
259 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
261 return (es
->undo_insert_count
|| lstrlenA(es
->undo_text
));
265 /*********************************************************************
270 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
272 es
->undo_insert_count
= 0;
273 *es
->undo_text
= '\0';
277 /*********************************************************************
282 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
284 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
288 /*********************************************************************
293 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
295 EDIT_WM_Copy(wnd
, es
);
296 EDIT_WM_Clear(wnd
, es
);
300 /*********************************************************************
304 * The messages are in the order of the actual integer values
305 * (which can be found in include/windows.h)
306 * Whereever possible the 16 bit versions are converted to
307 * the 32 bit ones, so that we can 'fall through' to the
308 * helper functions. These are mostly 32 bit (with a few
309 * exceptions, clearly indicated by a '16' extension to their
313 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
314 WPARAM wParam
, LPARAM lParam
)
316 WND
*wnd
= WIN_FindWndPtr(hwnd
);
317 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
322 DPRINTF_EDIT_MSG32("WM_DESTROY");
323 EDIT_WM_Destroy(wnd
, es
);
328 DPRINTF_EDIT_MSG32("WM_NCCREATE");
329 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
335 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
340 EDIT_LockBuffer(wnd
, es
);
343 DPRINTF_EDIT_MSG16("EM_GETSEL");
348 DPRINTF_EDIT_MSG32("EM_GETSEL");
349 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
353 DPRINTF_EDIT_MSG16("EM_SETSEL");
354 if (SLOWORD(lParam
) == -1)
355 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
357 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
359 EDIT_EM_ScrollCaret(wnd
, es
);
363 DPRINTF_EDIT_MSG32("EM_SETSEL");
364 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
365 EDIT_EM_ScrollCaret(wnd
, es
);
370 DPRINTF_EDIT_MSG16("EM_GETRECT");
372 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
375 DPRINTF_EDIT_MSG32("EM_GETRECT");
377 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
381 DPRINTF_EDIT_MSG16("EM_SETRECT");
382 if ((es
->style
& ES_MULTILINE
) && lParam
) {
384 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
385 EDIT_SetRectNP(wnd
, es
, &rc
);
386 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
390 DPRINTF_EDIT_MSG32("EM_SETRECT");
391 if ((es
->style
& ES_MULTILINE
) && lParam
) {
392 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
393 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
398 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
399 if ((es
->style
& ES_MULTILINE
) && lParam
) {
401 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
402 EDIT_SetRectNP(wnd
, es
, &rc
);
406 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
407 if ((es
->style
& ES_MULTILINE
) && lParam
)
408 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
412 DPRINTF_EDIT_MSG16("EM_SCROLL");
415 DPRINTF_EDIT_MSG32("EM_SCROLL");
416 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
419 case EM_LINESCROLL16
:
420 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
421 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
422 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
425 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
426 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
429 case EM_SCROLLCARET16
:
430 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
433 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
434 EDIT_EM_ScrollCaret(wnd
, es
);
439 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
442 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
443 result
= ((es
->flags
& EF_MODIFIED
) != 0);
447 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
450 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
452 es
->flags
|= EF_MODIFIED
;
454 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
457 case EM_GETLINECOUNT16
:
458 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
460 case EM_GETLINECOUNT
:
461 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
462 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
466 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
467 if ((INT16
)wParam
== -1)
471 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
472 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
476 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
477 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
480 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
481 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
485 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
486 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
489 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
490 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
494 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
497 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
498 result
= EDIT_EM_GetThumb(wnd
, es
);
501 /* messages 0x00bf and 0x00c0 missing from specs */
504 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
507 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
508 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
512 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
515 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
516 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
519 case EM_LINELENGTH16
:
520 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
523 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
524 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
527 case EM_REPLACESEL16
:
528 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
529 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
532 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
533 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
537 /* message 0x00c3 missing from specs */
540 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
543 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
544 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
548 DPRINTF_EDIT_MSG16("EM_GETLINE");
549 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
552 DPRINTF_EDIT_MSG32("EM_GETLINE");
553 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
557 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
559 case EM_SETLIMITTEXT
:
560 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
561 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
565 DPRINTF_EDIT_MSG16("EM_CANUNDO");
568 DPRINTF_EDIT_MSG32("EM_CANUNDO");
569 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
573 DPRINTF_EDIT_MSG16("EM_UNDO");
578 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
579 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
583 DPRINTF_EDIT_MSG16("EM_FMTLINES");
586 DPRINTF_EDIT_MSG32("EM_FMTLINES");
587 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
590 case EM_LINEFROMCHAR16
:
591 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
593 case EM_LINEFROMCHAR
:
594 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
595 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
598 /* message 0x00ca missing from specs */
601 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
604 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
605 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
608 case EM_SETTABSTOPS16
:
609 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
610 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
613 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
614 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
617 case EM_SETPASSWORDCHAR16
:
618 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
620 case EM_SETPASSWORDCHAR
:
621 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
622 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
625 case EM_EMPTYUNDOBUFFER16
:
626 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
628 case EM_EMPTYUNDOBUFFER
:
629 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
630 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
633 case EM_GETFIRSTVISIBLELINE16
:
634 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
635 result
= es
->y_offset
;
637 case EM_GETFIRSTVISIBLELINE
:
638 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
639 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
642 case EM_SETREADONLY16
:
643 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
646 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
648 wnd
->dwStyle
|= ES_READONLY
;
649 es
->style
|= ES_READONLY
;
651 wnd
->dwStyle
&= ~ES_READONLY
;
652 es
->style
&= ~ES_READONLY
;
657 case EM_SETWORDBREAKPROC16
:
658 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
659 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
661 case EM_SETWORDBREAKPROC
:
662 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
663 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
666 case EM_GETWORDBREAKPROC16
:
667 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
668 result
= (LRESULT
)es
->word_break_proc16
;
670 case EM_GETWORDBREAKPROC
:
671 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
672 result
= (LRESULT
)es
->word_break_proc32A
;
675 case EM_GETPASSWORDCHAR16
:
676 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
678 case EM_GETPASSWORDCHAR
:
679 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
680 result
= es
->password_char
;
683 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
686 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
687 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
691 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
692 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
695 case EM_GETLIMITTEXT
:
696 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
697 result
= es
->buffer_limit
;
701 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
702 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
706 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
707 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
711 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
712 result
= (es
->style
& ES_MULTILINE
) ?
713 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
714 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
718 DPRINTF_EDIT_MSG32("WM_CHAR");
719 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
723 DPRINTF_EDIT_MSG32("WM_CLEAR");
724 EDIT_WM_Clear(wnd
, es
);
728 DPRINTF_EDIT_MSG32("WM_COMMAND");
729 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
733 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
734 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
738 DPRINTF_EDIT_MSG32("WM_COPY");
739 EDIT_WM_Copy(wnd
, es
);
743 DPRINTF_EDIT_MSG32("WM_CREATE");
744 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
748 DPRINTF_EDIT_MSG32("WM_CUT");
749 EDIT_WM_Cut(wnd
, es
);
753 DPRINTF_EDIT_MSG32("WM_ENABLE");
754 es
->bEnableState
= (BOOL
) wParam
;
755 InvalidateRect(hwnd
, NULL
, TRUE
);
759 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
760 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
764 DPRINTF_EDIT_MSG32("WM_GETFONT");
765 result
= (LRESULT
)es
->font
;
769 DPRINTF_EDIT_MSG32("WM_GETTEXT");
770 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
773 case WM_GETTEXTLENGTH
:
774 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
775 result
= lstrlenA(es
->text
);
779 DPRINTF_EDIT_MSG32("WM_HSCROLL");
780 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
784 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
785 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
789 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
790 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
793 case WM_LBUTTONDBLCLK
:
794 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
795 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
799 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
800 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
804 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
805 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
808 case WM_MOUSEACTIVATE
:
810 * FIXME: maybe DefWindowProc() screws up, but it seems that
811 * modalless dialog boxes need this. If we don't do this, the focus
812 * will _not_ be set by DefWindowProc() for edit controls in a
813 * modalless dialog box ???
815 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
816 SetFocus(wnd
->hwndSelf
);
817 result
= MA_ACTIVATE
;
822 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
824 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
828 DPRINTF_EDIT_MSG32("WM_PAINT");
829 EDIT_WM_Paint(wnd
, es
, wParam
);
833 DPRINTF_EDIT_MSG32("WM_PASTE");
834 EDIT_WM_Paste(wnd
, es
);
838 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
839 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
843 DPRINTF_EDIT_MSG32("WM_SETFONT");
844 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
848 DPRINTF_EDIT_MSG32("WM_SETTEXT");
849 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
854 DPRINTF_EDIT_MSG32("WM_SIZE");
855 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
859 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
860 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
864 DPRINTF_EDIT_MSG32("WM_TIMER");
865 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
869 DPRINTF_EDIT_MSG32("WM_VSCROLL");
870 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
875 short gcWheelDelta
= 0;
876 UINT pulScrollLines
= 3;
877 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
879 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
880 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
883 gcWheelDelta
-= (short) HIWORD(wParam
);
884 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
886 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
887 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
888 result
= EDIT_EM_LineScroll(wnd
, es
, 0, cLineScroll
);
893 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
896 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
898 WIN_ReleaseWndPtr(wnd
);
904 /*********************************************************************
906 * EDIT_BuildLineDefs_ML
908 * Build linked list of text lines.
909 * Lines can end with '\0' (last line), a character (if it is wrapped),
910 * a soft return '\r\r\n' or a hard return '\r\n'
913 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
919 LINEDEF
*current_def
;
920 LINEDEF
**previous_next
;
922 current_def
= es
->first_line_def
;
924 LINEDEF
*next_def
= current_def
->next
;
925 HeapFree(es
->heap
, 0, current_def
);
926 current_def
= next_def
;
927 } while (current_def
);
931 dc
= GetDC(wnd
->hwndSelf
);
933 old_font
= SelectObject(dc
, es
->font
);
935 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
937 previous_next
= &es
->first_line_def
;
939 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
940 current_def
->next
= NULL
;
943 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
948 current_def
->ending
= END_0
;
949 current_def
->net_length
= lstrlenA(start
);
950 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
951 current_def
->ending
= END_SOFT
;
952 current_def
->net_length
= cp
- start
- 1;
954 current_def
->ending
= END_HARD
;
955 current_def
->net_length
= cp
- start
;
957 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
958 start
, current_def
->net_length
,
959 es
->tabs_count
, es
->tabs
));
960 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
961 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
966 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
967 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
968 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
969 start
, next
, es
->tabs_count
, es
->tabs
));
970 } while (current_def
->width
<= fw
);
976 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
977 start
, next
, es
->tabs_count
, es
->tabs
));
978 } while (current_def
->width
<= fw
);
982 current_def
->net_length
= prev
;
983 current_def
->ending
= END_WRAP
;
984 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
985 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
987 switch (current_def
->ending
) {
989 current_def
->length
= current_def
->net_length
+ 3;
992 current_def
->length
= current_def
->net_length
+ 2;
996 current_def
->length
= current_def
->net_length
;
999 es
->text_width
= max(es
->text_width
, current_def
->width
);
1000 start
+= current_def
->length
;
1001 *previous_next
= current_def
;
1002 previous_next
= ¤t_def
->next
;
1004 } while (current_def
->ending
!= END_0
);
1006 SelectObject(dc
, old_font
);
1007 ReleaseDC(wnd
->hwndSelf
, dc
);
1011 /*********************************************************************
1013 * EDIT_CallWordBreakProc
1015 * Call appropriate WordBreakProc (internal or external).
1017 * Note: The "start" argument should always be an index refering
1018 * to es->text. The actual wordbreak proc might be
1019 * 16 bit, so we can't always pass any 32 bit LPSTR.
1020 * Hence we assume that es->text is the buffer that holds
1021 * the string under examination (we can decide this for ourselves).
1024 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1026 if (es
->word_break_proc16
) {
1027 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1028 SEGPTR segptr
= LocalLock16(hloc16
);
1029 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1030 segptr
+ start
, index
, count
, action
);
1031 LocalUnlock16(hloc16
);
1034 else if (es
->word_break_proc32A
)
1036 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1037 es
->word_break_proc32A
, es
->text
+ start
, index
,
1039 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1043 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1047 /*********************************************************************
1051 * Beware: This is not the function called on EM_CHARFROMPOS
1052 * The position _can_ be outside the formatting / client
1054 * The return value is only the character index
1057 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1063 if (es
->style
& ES_MULTILINE
) {
1064 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1066 LINEDEF
*line_def
= es
->first_line_def
;
1068 while ((line
> 0) && line_def
->next
) {
1069 line_index
+= line_def
->length
;
1070 line_def
= line_def
->next
;
1073 x
+= es
->x_offset
- es
->format_rect
.left
;
1074 if (x
>= line_def
->width
) {
1076 *after_wrap
= (line_def
->ending
== END_WRAP
);
1077 return line_index
+ line_def
->net_length
;
1081 *after_wrap
= FALSE
;
1084 dc
= GetDC(wnd
->hwndSelf
);
1086 old_font
= SelectObject(dc
, es
->font
);
1087 low
= line_index
+ 1;
1088 high
= line_index
+ line_def
->net_length
+ 1;
1089 while (low
< high
- 1)
1091 INT mid
= (low
+ high
) / 2;
1092 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1098 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1099 (line_def
->ending
== END_WRAP
));
1104 *after_wrap
= FALSE
;
1105 x
-= es
->format_rect
.left
;
1107 return es
->x_offset
;
1108 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1109 dc
= GetDC(wnd
->hwndSelf
);
1111 old_font
= SelectObject(dc
, es
->font
);
1115 INT high
= es
->x_offset
;
1116 while (low
< high
- 1)
1118 INT mid
= (low
+ high
) / 2;
1119 GetTextExtentPoint32A( dc
, text
+ mid
,
1120 es
->x_offset
- mid
, &size
);
1121 if (size
.cx
> -x
) low
= mid
;
1128 INT low
= es
->x_offset
;
1129 INT high
= lstrlenA(es
->text
) + 1;
1130 while (low
< high
- 1)
1132 INT mid
= (low
+ high
) / 2;
1133 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1134 mid
- es
->x_offset
, &size
);
1135 if (size
.cx
> x
) high
= mid
;
1140 if (es
->style
& ES_PASSWORD
)
1141 HeapFree(es
->heap
, 0 ,text
);
1144 SelectObject(dc
, old_font
);
1145 ReleaseDC(wnd
->hwndSelf
, dc
);
1150 /*********************************************************************
1154 * adjusts the point to be within the formatting rectangle
1155 * (so CharFromPos returns the nearest _visible_ character)
1158 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1160 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1161 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1165 /*********************************************************************
1169 * Calculates the bounding rectangle for a line from a starting
1170 * column to an ending column.
1173 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1175 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1177 if (es
->style
& ES_MULTILINE
)
1178 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1180 rc
->top
= es
->format_rect
.top
;
1181 rc
->bottom
= rc
->top
+ es
->line_height
;
1182 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1183 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1187 /*********************************************************************
1189 * EDIT_GetPasswordPointer_SL
1191 * note: caller should free the (optionally) allocated buffer
1194 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1196 if (es
->style
& ES_PASSWORD
) {
1197 INT len
= lstrlenA(es
->text
);
1198 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1199 RtlFillMemory(text
, len
, es
->password_char
);
1207 /*********************************************************************
1211 * This acts as a LOCAL_Lock(), but it locks only once. This way
1212 * you can call it whenever you like, without unlocking.
1215 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1218 ERR("no EDITSTATE ... please report\n");
1221 if (!(es
->style
& ES_MULTILINE
))
1225 es
->text
= LocalLock(es
->hloc32
);
1226 else if (es
->hloc16
)
1227 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1229 ERR("no buffer ... please report\n");
1237 /*********************************************************************
1239 * EDIT_SL_InvalidateText
1241 * Called from EDIT_InvalidateText().
1242 * Does the job for single-line controls only.
1245 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1250 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1251 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1252 InvalidateRect(wnd
->hwndSelf
, &rc
, FALSE
);
1256 /*********************************************************************
1258 * EDIT_ML_InvalidateText
1260 * Called from EDIT_InvalidateText().
1261 * Does the job for multi-line controls only.
1264 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1266 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1267 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1268 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1277 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1280 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1281 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1282 if (sl
< es
->y_offset
) {
1286 if (el
> es
->y_offset
+ vlc
) {
1287 el
= es
->y_offset
+ vlc
;
1288 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1290 GetClientRect(wnd
->hwndSelf
, &rc1
);
1291 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1293 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1294 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1295 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1297 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1298 EDIT_EM_LineLength(wnd
, es
,
1299 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1301 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1302 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1303 for (l
= sl
+ 1 ; l
< el
; l
++) {
1304 EDIT_GetLineRect(wnd
, es
, l
, 0,
1305 EDIT_EM_LineLength(wnd
, es
,
1306 EDIT_EM_LineIndex(wnd
, es
, l
)),
1308 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1309 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1311 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1312 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1313 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1318 /*********************************************************************
1320 * EDIT_InvalidateText
1322 * Invalidate the text from offset start upto, but not including,
1323 * offset end. Useful for (re)painting the selection.
1324 * Regions outside the linewidth are not invalidated.
1325 * end == -1 means end == TextLength.
1326 * start and end need not be ordered.
1329 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1335 end
= lstrlenA(es
->text
);
1337 ORDER_INT(start
, end
);
1339 if (es
->style
& ES_MULTILINE
)
1340 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1342 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1346 /*********************************************************************
1350 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1353 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1358 if (size
<= es
->buffer_size
)
1360 if (size
> es
->buffer_limit
) {
1361 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1364 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1365 if (size
> es
->buffer_limit
)
1366 size
= es
->buffer_limit
;
1368 TRACE("trying to ReAlloc to %d+1\n", size
);
1370 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1372 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1373 es
->buffer_size
= min(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1375 es
->buffer_size
= 0;
1376 } else if (es
->hloc32
) {
1377 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1378 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1379 es
->hloc32
= hNew32
;
1380 es
->buffer_size
= min(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1382 } else if (es
->hloc16
) {
1383 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1384 TRACE("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1385 es
->hloc16
= hNew16
;
1386 es
->buffer_size
= min(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1389 if (es
->buffer_size
< size
) {
1390 EDIT_LockBuffer(wnd
, es
);
1391 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1392 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1395 EDIT_LockBuffer(wnd
, es
);
1396 TRACE("We now have %d+1\n", es
->buffer_size
);
1402 /*********************************************************************
1406 * Try to fit size + 1 bytes in the undo buffer.
1409 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1411 if (size
<= es
->undo_buffer_size
)
1413 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1415 TRACE("trying to ReAlloc to %d+1\n", size
);
1417 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1418 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1419 if (es
->undo_buffer_size
< size
) {
1420 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1429 /*********************************************************************
1434 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1436 INT e
= es
->selection_end
;
1440 if ((es
->style
& ES_MULTILINE
) && e
&&
1441 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1443 if (e
&& (es
->text
[e
- 1] == '\r'))
1447 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1448 EDIT_EM_ScrollCaret(wnd
, es
);
1452 /*********************************************************************
1456 * Only for multi line controls
1457 * Move the caret one line down, on a column with the nearest
1458 * x coordinate on the screen (might be a different column).
1461 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1463 INT s
= es
->selection_start
;
1464 INT e
= es
->selection_end
;
1465 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1466 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1467 INT x
= SLOWORD(pos
);
1468 INT y
= SHIWORD(pos
);
1470 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1473 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1474 EDIT_EM_ScrollCaret(wnd
, es
);
1478 /*********************************************************************
1483 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1485 BOOL after_wrap
= FALSE
;
1488 /* Pass a high value in x to make sure of receiving the en of the line */
1489 if (es
->style
& ES_MULTILINE
)
1490 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1491 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1493 e
= lstrlenA(es
->text
);
1494 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1495 EDIT_EM_ScrollCaret(wnd
, es
);
1499 /*********************************************************************
1504 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1506 INT e
= es
->selection_end
;
1510 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1511 if (es
->text
[e
] == '\n')
1513 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1517 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1518 EDIT_EM_ScrollCaret(wnd
, es
);
1522 /*********************************************************************
1526 * Home key: move to beginning of line.
1529 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1533 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1534 if (es
->style
& ES_MULTILINE
)
1535 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1536 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1539 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1540 EDIT_EM_ScrollCaret(wnd
, es
);
1544 /*********************************************************************
1546 * EDIT_MovePageDown_ML
1548 * Only for multi line controls
1549 * Move the caret one page down, on a column with the nearest
1550 * x coordinate on the screen (might be a different column).
1553 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1555 INT s
= es
->selection_start
;
1556 INT e
= es
->selection_end
;
1557 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1558 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1559 INT x
= SLOWORD(pos
);
1560 INT y
= SHIWORD(pos
);
1562 e
= EDIT_CharFromPos(wnd
, es
, x
,
1563 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1567 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1568 EDIT_EM_ScrollCaret(wnd
, es
);
1572 /*********************************************************************
1574 * EDIT_MovePageUp_ML
1576 * Only for multi line controls
1577 * Move the caret one page up, on a column with the nearest
1578 * x coordinate on the screen (might be a different column).
1581 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1583 INT s
= es
->selection_start
;
1584 INT e
= es
->selection_end
;
1585 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1586 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1587 INT x
= SLOWORD(pos
);
1588 INT y
= SHIWORD(pos
);
1590 e
= EDIT_CharFromPos(wnd
, es
, x
,
1591 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1595 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1596 EDIT_EM_ScrollCaret(wnd
, es
);
1600 /*********************************************************************
1604 * Only for multi line controls
1605 * Move the caret one line up, on a column with the nearest
1606 * x coordinate on the screen (might be a different column).
1609 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1611 INT s
= es
->selection_start
;
1612 INT e
= es
->selection_end
;
1613 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1614 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1615 INT x
= SLOWORD(pos
);
1616 INT y
= SHIWORD(pos
);
1618 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1621 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1622 EDIT_EM_ScrollCaret(wnd
, es
);
1626 /*********************************************************************
1628 * EDIT_MoveWordBackward
1631 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1633 INT s
= es
->selection_start
;
1634 INT e
= es
->selection_end
;
1639 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1640 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1641 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1644 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1645 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1648 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1649 li
, e
- li
, ll
, WB_LEFT
);
1653 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1654 EDIT_EM_ScrollCaret(wnd
, es
);
1658 /*********************************************************************
1660 * EDIT_MoveWordForward
1663 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1665 INT s
= es
->selection_start
;
1666 INT e
= es
->selection_end
;
1671 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1672 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1673 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1675 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1676 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1678 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1679 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1683 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1684 EDIT_EM_ScrollCaret(wnd
, es
);
1688 /*********************************************************************
1693 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1695 INT s
= es
->selection_start
;
1696 INT e
= es
->selection_end
;
1703 if (es
->style
& ES_MULTILINE
) {
1704 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1705 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1710 TRACE("line=%d\n", line
);
1712 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1715 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1716 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1717 s
= es
->selection_start
;
1718 e
= es
->selection_end
;
1720 s
= min(li
+ ll
, max(li
, s
));
1721 e
= min(li
+ ll
, max(li
, e
));
1722 if (rev
&& (s
!= e
) &&
1723 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1724 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1725 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1726 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1728 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1732 /*********************************************************************
1737 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1747 BkColor
= GetBkColor(dc
);
1748 TextColor
= GetTextColor(dc
);
1750 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1751 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1753 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1754 if (es
->style
& ES_MULTILINE
) {
1755 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1756 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1758 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1759 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1760 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1762 if (es
->style
& ES_PASSWORD
)
1763 HeapFree(es
->heap
, 0, text
);
1766 SetBkColor(dc
, BkColor
);
1767 SetTextColor(dc
, TextColor
);
1773 /*********************************************************************
1778 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1781 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1782 INT x
= SLOWORD(res
);
1783 INT y
= SHIWORD(res
);
1785 if(x
< es
->format_rect
.left
)
1786 x
= es
->format_rect
.left
;
1787 if(x
> es
->format_rect
.right
- 2)
1788 x
= es
->format_rect
.right
- 2;
1789 if(y
> es
->format_rect
.bottom
)
1790 y
= es
->format_rect
.bottom
;
1791 if(y
< es
->format_rect
.top
)
1792 y
= es
->format_rect
.top
;
1798 /*********************************************************************
1802 * note: this is not (exactly) the handler called on EM_SETRECTNP
1803 * it is also used to set the rect of a single line control
1806 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1808 CopyRect(&es
->format_rect
, rc
);
1809 if (es
->style
& WS_BORDER
) {
1810 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1811 if(TWEAK_WineLook
== WIN31_LOOK
)
1813 es
->format_rect
.left
+= bw
;
1814 es
->format_rect
.top
+= bw
;
1815 es
->format_rect
.right
-= bw
;
1816 es
->format_rect
.bottom
-= bw
;
1818 es
->format_rect
.left
+= es
->left_margin
;
1819 es
->format_rect
.right
-= es
->right_margin
;
1820 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1821 if (es
->style
& ES_MULTILINE
)
1822 es
->format_rect
.bottom
= es
->format_rect
.top
+
1823 max(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1825 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1826 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1827 EDIT_BuildLineDefs_ML(wnd
, es
);
1831 /*********************************************************************
1836 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1839 ERR("no EDITSTATE ... please report\n");
1842 if (!(es
->style
& ES_MULTILINE
))
1844 if (!es
->lock_count
) {
1845 ERR("lock_count == 0 ... please report\n");
1849 ERR("es->text == 0 ... please report\n");
1852 if (force
|| (es
->lock_count
== 1)) {
1854 LocalUnlock(es
->hloc32
);
1856 } else if (es
->hloc16
) {
1857 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1865 /*********************************************************************
1867 * EDIT_WordBreakProc
1869 * Find the beginning of words.
1870 * Note: unlike the specs for a WordBreakProc, this function only
1871 * allows to be called without linebreaks between s[0] upto
1872 * s[count - 1]. Remember it is only called
1873 * internally, so we can decide this for ourselves.
1876 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1880 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1881 s
, index
, count
, action
);
1889 if (s
[index
] == ' ') {
1890 while (index
&& (s
[index
] == ' '))
1893 while (index
&& (s
[index
] != ' '))
1895 if (s
[index
] == ' ')
1899 while (index
&& (s
[index
] != ' '))
1901 if (s
[index
] == ' ')
1911 if (s
[index
] == ' ')
1912 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1914 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1916 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1920 case WB_ISDELIMITER
:
1921 ret
= (s
[index
] == ' ');
1924 ERR("unknown action code, please report !\n");
1931 /*********************************************************************
1935 * returns line number (not index) in high-order word of result.
1936 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1937 * to Richedit, not to the edit control. Original documentation is valid.
1938 * FIXME: do the specs mean to return -1 if outside client area or
1939 * if outside formatting rectangle ???
1942 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1950 GetClientRect(wnd
->hwndSelf
, &rc
);
1951 if (!PtInRect(&rc
, pt
))
1954 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1955 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1959 /*********************************************************************
1963 * Enable or disable soft breaks.
1965 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1967 es
->flags
&= ~EF_USE_SOFTBRK
;
1969 es
->flags
|= EF_USE_SOFTBRK
;
1970 FIXME("soft break enabled, not implemented\n");
1976 /*********************************************************************
1980 * Hopefully this won't fire back at us.
1981 * We always start with a fixed buffer in our own heap.
1982 * However, with this message a 32 bit application requests
1983 * a handle to 32 bit moveable local heap memory, where it expects
1985 * It's a pity that from this moment on we have to use this
1986 * local heap, because applications may rely on the handle
1989 * In this function we'll try to switch to local heap.
1992 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1998 if (!(es
->style
& ES_MULTILINE
))
2003 else if (es
->hloc16
)
2004 return (HLOCAL
)es
->hloc16
;
2006 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2007 ERR("could not allocate new 32 bit buffer\n");
2010 newSize
= min(LocalSize(newBuf
) - 1, es
->buffer_limit
);
2011 if (!(newText
= LocalLock(newBuf
))) {
2012 ERR("could not lock new 32 bit buffer\n");
2016 lstrcpyA(newText
, es
->text
);
2017 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2019 HeapFree(es
->heap
, 0, es
->text
);
2020 es
->hloc32
= newBuf
;
2021 es
->hloc16
= (HLOCAL16
)NULL
;
2022 es
->buffer_size
= newSize
;
2024 EDIT_LockBuffer(wnd
, es
);
2025 TRACE("switched to 32 bit local heap\n");
2031 /*********************************************************************
2035 * Hopefully this won't fire back at us.
2036 * We always start with a buffer in 32 bit linear memory.
2037 * However, with this message a 16 bit application requests
2038 * a handle of 16 bit local heap memory, where it expects to find
2040 * It's a pitty that from this moment on we have to use this
2041 * local heap, because applications may rely on the handle
2044 * In this function we'll try to switch to local heap.
2046 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2052 if (!(es
->style
& ES_MULTILINE
))
2058 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2059 if (!LocalInit16(wnd
->hInstance
, 0,
2060 GlobalSize16(wnd
->hInstance
))) {
2061 ERR("could not initialize local heap\n");
2064 TRACE("local heap initialized\n");
2066 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2067 ERR("could not allocate new 16 bit buffer\n");
2070 newSize
= min(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2071 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2072 ERR("could not lock new 16 bit buffer\n");
2073 LOCAL_Free(wnd
->hInstance
, newBuf
);
2076 lstrcpyA(newText
, es
->text
);
2077 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2079 HeapFree(es
->heap
, 0, es
->text
);
2080 else if (es
->hloc32
) {
2081 while (LocalFree(es
->hloc32
)) ;
2082 LocalFree(es
->hloc32
);
2084 es
->hloc32
= (HLOCAL
)NULL
;
2085 es
->hloc16
= newBuf
;
2086 es
->buffer_size
= newSize
;
2088 EDIT_LockBuffer(wnd
, es
);
2089 TRACE("switched to 16 bit buffer\n");
2095 /*********************************************************************
2100 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2106 if (es
->style
& ES_MULTILINE
) {
2107 if (line
>= es
->line_count
)
2111 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2113 len
= min(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2114 for (i
= 0 ; i
< len
; i
++) {
2119 return (LRESULT
)len
;
2123 /*********************************************************************
2128 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2130 UINT s
= es
->selection_start
;
2131 UINT e
= es
->selection_end
;
2138 return MAKELONG(s
, e
);
2142 /*********************************************************************
2146 * FIXME: is this right ? (or should it be only VSCROLL)
2147 * (and maybe only for edit controls that really have their
2148 * own scrollbars) (and maybe only for multiline controls ?)
2149 * All in all: very poorly documented
2151 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2152 * WM_VSCROLL handlers
2155 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2157 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2158 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2162 /*********************************************************************
2167 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2172 if (!(es
->style
& ES_MULTILINE
))
2174 if (index
> lstrlenA(es
->text
))
2175 return es
->line_count
- 1;
2177 index
= min(es
->selection_start
, es
->selection_end
);
2180 line_def
= es
->first_line_def
;
2181 index
-= line_def
->length
;
2182 while ((index
>= 0) && line_def
->next
) {
2184 line_def
= line_def
->next
;
2185 index
-= line_def
->length
;
2191 /*********************************************************************
2196 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2201 if (!(es
->style
& ES_MULTILINE
))
2203 if (line
>= es
->line_count
)
2207 line_def
= es
->first_line_def
;
2209 INT index
= es
->selection_end
- line_def
->length
;
2210 while ((index
>= 0) && line_def
->next
) {
2211 line_index
+= line_def
->length
;
2212 line_def
= line_def
->next
;
2213 index
-= line_def
->length
;
2217 line_index
+= line_def
->length
;
2218 line_def
= line_def
->next
;
2226 /*********************************************************************
2231 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2235 if (!(es
->style
& ES_MULTILINE
))
2236 return lstrlenA(es
->text
);
2240 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2241 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2242 return es->selection_start - es->line_defs[sl].offset +
2243 es->line_defs[el].offset +
2244 es->line_defs[el].length - es->selection_end;
2248 line_def
= es
->first_line_def
;
2249 index
-= line_def
->length
;
2250 while ((index
>= 0) && line_def
->next
) {
2251 line_def
= line_def
->next
;
2252 index
-= line_def
->length
;
2254 return line_def
->net_length
;
2258 /*********************************************************************
2262 * FIXME: dx is in average character widths
2263 * However, we assume it is in pixels when we use this
2264 * function internally
2267 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2271 if (!(es
->style
& ES_MULTILINE
))
2274 if (-dx
> es
->x_offset
)
2276 if (dx
> es
->text_width
- es
->x_offset
)
2277 dx
= es
->text_width
- es
->x_offset
;
2278 nyoff
= max(0, es
->y_offset
+ dy
);
2279 if (nyoff
>= es
->line_count
)
2280 nyoff
= es
->line_count
- 1;
2281 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2285 GetClientRect(wnd
->hwndSelf
, &rc1
);
2286 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2287 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2288 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2289 es
->y_offset
= nyoff
;
2292 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2293 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2294 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2295 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2300 /*********************************************************************
2305 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2307 INT len
= lstrlenA(es
->text
);
2316 index
= min(index
, len
);
2317 dc
= GetDC(wnd
->hwndSelf
);
2319 old_font
= SelectObject(dc
, es
->font
);
2320 if (es
->style
& ES_MULTILINE
) {
2321 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2322 y
= (l
- es
->y_offset
) * es
->line_height
;
2323 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2324 if (after_wrap
&& (li
== index
) && l
) {
2326 LINEDEF
*line_def
= es
->first_line_def
;
2328 line_def
= line_def
->next
;
2331 if (line_def
->ending
== END_WRAP
) {
2333 y
-= es
->line_height
;
2334 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2337 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2338 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2340 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2341 if (index
< es
->x_offset
) {
2342 GetTextExtentPoint32A(dc
, text
+ index
,
2343 es
->x_offset
- index
, &size
);
2346 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2347 index
- es
->x_offset
, &size
);
2351 if (es
->style
& ES_PASSWORD
)
2352 HeapFree(es
->heap
, 0 ,text
);
2354 x
+= es
->format_rect
.left
;
2355 y
+= es
->format_rect
.top
;
2357 SelectObject(dc
, old_font
);
2358 ReleaseDC(wnd
->hwndSelf
, dc
);
2359 return MAKELONG((INT16
)x
, (INT16
)y
);
2363 /*********************************************************************
2367 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2370 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2372 INT strl
= lstrlenA(lpsz_replace
);
2373 INT tl
= lstrlenA(es
->text
);
2380 s
= es
->selection_start
;
2381 e
= es
->selection_end
;
2383 if ((s
== e
) && !strl
)
2388 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2392 /* there is something to be deleted */
2394 utl
= lstrlenA(es
->undo_text
);
2395 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2396 /* undo-buffer is extended to the right */
2397 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2398 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2399 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2400 /* undo-buffer is extended to the left */
2401 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2402 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2404 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2405 p
[i
] = (es
->text
+ s
)[i
];
2406 es
->undo_position
= s
;
2408 /* new undo-buffer */
2409 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2410 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2411 es
->undo_position
= s
;
2413 /* any deletion makes the old insertion-undo invalid */
2414 es
->undo_insert_count
= 0;
2416 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2419 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2422 /* there is an insertion */
2424 if ((s
== es
->undo_position
) ||
2425 ((es
->undo_insert_count
) &&
2426 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2428 * insertion is new and at delete position or
2429 * an extension to either left or right
2431 es
->undo_insert_count
+= strl
;
2433 /* new insertion undo */
2434 es
->undo_position
= s
;
2435 es
->undo_insert_count
= strl
;
2436 /* new insertion makes old delete-buffer invalid */
2437 *es
->undo_text
= '\0';
2440 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2443 tl
= lstrlenA(es
->text
);
2444 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2446 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2447 p
[i
] = lpsz_replace
[i
];
2448 if(es
->style
& ES_UPPERCASE
)
2449 CharUpperBuffA(p
, strl
);
2450 else if(es
->style
& ES_LOWERCASE
)
2451 CharLowerBuffA(p
, strl
);
2454 /* FIXME: really inefficient */
2455 if (es
->style
& ES_MULTILINE
)
2456 EDIT_BuildLineDefs_ML(wnd
, es
);
2458 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2459 es
->flags
|= EF_MODIFIED
;
2460 es
->flags
|= EF_UPDATE
;
2461 EDIT_EM_ScrollCaret(wnd
, es
);
2463 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
2465 /* FIXME: really inefficient */
2466 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2470 /*********************************************************************
2475 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2479 if (!(es
->style
& ES_MULTILINE
))
2480 return (LRESULT
)FALSE
;
2490 if (es
->y_offset
< es
->line_count
- 1)
2495 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2498 if (es
->y_offset
< es
->line_count
- 1)
2499 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2502 return (LRESULT
)FALSE
;
2505 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2506 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2508 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2512 /*********************************************************************
2517 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2519 if (es
->style
& ES_MULTILINE
) {
2524 INT cw
= es
->char_width
;
2529 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2530 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2531 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2532 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2533 if (l
>= es
->y_offset
+ vlc
)
2534 dy
= l
- vlc
+ 1 - es
->y_offset
;
2535 if (l
< es
->y_offset
)
2536 dy
= l
- es
->y_offset
;
2537 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2538 if (x
< es
->format_rect
.left
)
2539 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2540 if (x
> es
->format_rect
.right
)
2541 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2543 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2549 if (!(es
->style
& ES_AUTOHSCROLL
))
2552 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2553 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2554 if (x
< es
->format_rect
.left
) {
2555 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2558 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2559 } while ((x
< goal
) && es
->x_offset
);
2560 /* FIXME: use ScrollWindow() somehow to improve performance */
2561 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2562 } else if (x
> es
->format_rect
.right
) {
2564 INT len
= lstrlenA(es
->text
);
2565 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2568 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2569 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2570 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2571 /* FIXME: use ScrollWindow() somehow to improve performance */
2572 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2578 /*********************************************************************
2582 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2585 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2587 if (!(es
->style
& ES_MULTILINE
))
2591 WARN("called with NULL handle\n");
2595 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2597 * old buffer is freed by caller, unless
2598 * it is still in our own heap. (in that case
2599 * we free it, correcting the buggy caller.)
2602 HeapFree(es
->heap
, 0, es
->text
);
2604 es
->hloc16
= (HLOCAL16
)NULL
;
2607 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2608 EDIT_LockBuffer(wnd
, es
);
2610 es
->x_offset
= es
->y_offset
= 0;
2611 es
->selection_start
= es
->selection_end
= 0;
2612 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2613 es
->flags
&= ~EF_MODIFIED
;
2614 es
->flags
&= ~EF_UPDATE
;
2615 EDIT_BuildLineDefs_ML(wnd
, es
);
2616 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2617 EDIT_EM_ScrollCaret(wnd
, es
);
2621 /*********************************************************************
2625 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2628 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2630 if (!(es
->style
& ES_MULTILINE
))
2634 WARN("called with NULL handle\n");
2638 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2640 * old buffer is freed by caller, unless
2641 * it is still in our own heap. (in that case
2642 * we free it, correcting the buggy caller.)
2645 HeapFree(es
->heap
, 0, es
->text
);
2648 es
->hloc32
= (HLOCAL
)NULL
;
2650 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2651 EDIT_LockBuffer(wnd
, es
);
2653 es
->x_offset
= es
->y_offset
= 0;
2654 es
->selection_start
= es
->selection_end
= 0;
2655 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2656 es
->flags
&= ~EF_MODIFIED
;
2657 es
->flags
&= ~EF_UPDATE
;
2658 EDIT_BuildLineDefs_ML(wnd
, es
);
2659 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2660 EDIT_EM_ScrollCaret(wnd
, es
);
2664 /*********************************************************************
2668 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2669 * However, the windows version is not complied to yet in all of edit.c
2672 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2674 if (es
->style
& ES_MULTILINE
) {
2676 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
2678 es
->buffer_limit
= BUFLIMIT_MULTI
;
2681 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
2683 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2688 /*********************************************************************
2692 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2693 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2694 * of the char's width, according to the new docs.
2697 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2698 INT left
, INT right
)
2700 if (action
& EC_LEFTMARGIN
) {
2701 if (left
!= EC_USEFONTINFO
)
2702 es
->left_margin
= left
;
2704 es
->left_margin
= es
->char_width
/ 3;
2707 if (action
& EC_RIGHTMARGIN
) {
2708 if (right
!= EC_USEFONTINFO
)
2709 es
->right_margin
= right
;
2711 es
->right_margin
= es
->char_width
/ 3;
2713 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2717 /*********************************************************************
2719 * EM_SETPASSWORDCHAR
2722 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2724 if (es
->style
& ES_MULTILINE
)
2727 if (es
->password_char
== c
)
2730 es
->password_char
= c
;
2732 wnd
->dwStyle
|= ES_PASSWORD
;
2733 es
->style
|= ES_PASSWORD
;
2735 wnd
->dwStyle
&= ~ES_PASSWORD
;
2736 es
->style
&= ~ES_PASSWORD
;
2738 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2742 /*********************************************************************
2746 * note: unlike the specs say: the order of start and end
2747 * _is_ preserved in Windows. (i.e. start can be > end)
2748 * In other words: this handler is OK
2751 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2753 UINT old_start
= es
->selection_start
;
2754 UINT old_end
= es
->selection_end
;
2755 UINT len
= lstrlenA(es
->text
);
2758 start
= es
->selection_end
;
2759 end
= es
->selection_end
;
2761 start
= min(start
, len
);
2762 end
= min(end
, len
);
2764 es
->selection_start
= start
;
2765 es
->selection_end
= end
;
2767 es
->flags
|= EF_AFTER_WRAP
;
2769 es
->flags
&= ~EF_AFTER_WRAP
;
2770 if (es
->flags
& EF_FOCUSED
)
2771 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2772 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2773 ORDER_UINT(start
, end
);
2774 ORDER_UINT(end
, old_end
);
2775 ORDER_UINT(start
, old_start
);
2776 ORDER_UINT(old_start
, old_end
);
2777 if (end
!= old_start
)
2781 * ORDER_UINT32(end, old_start);
2782 * EDIT_InvalidateText(wnd, es, start, end);
2783 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2784 * in place of the following if statement.
2786 if (old_start
> end
)
2788 EDIT_InvalidateText(wnd
, es
, start
, end
);
2789 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2793 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2794 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2797 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2801 /*********************************************************************
2806 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2808 if (!(es
->style
& ES_MULTILINE
))
2811 HeapFree(es
->heap
, 0, es
->tabs
);
2812 es
->tabs_count
= count
;
2816 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2817 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2823 /*********************************************************************
2828 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2830 if (!(es
->style
& ES_MULTILINE
))
2833 HeapFree(es
->heap
, 0, es
->tabs
);
2834 es
->tabs_count
= count
;
2839 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2840 for (i
= 0 ; i
< count
; i
++)
2841 es
->tabs
[i
] = *tabs
++;
2847 /*********************************************************************
2849 * EM_SETWORDBREAKPROC
2852 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2854 if (es
->word_break_proc32A
== wbp
)
2857 es
->word_break_proc32A
= wbp
;
2858 es
->word_break_proc16
= NULL
;
2859 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2860 EDIT_BuildLineDefs_ML(wnd
, es
);
2861 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2866 /*********************************************************************
2868 * EM_SETWORDBREAKPROC16
2871 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2873 if (es
->word_break_proc16
== wbp
)
2876 es
->word_break_proc32A
= NULL
;
2877 es
->word_break_proc16
= wbp
;
2878 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2879 EDIT_BuildLineDefs_ML(wnd
, es
);
2880 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2885 /*********************************************************************
2890 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2892 INT ulength
= lstrlenA(es
->undo_text
);
2893 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2895 lstrcpyA(utext
, es
->undo_text
);
2897 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2898 es
->undo_insert_count
, utext
);
2900 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2901 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2902 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2903 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2904 HeapFree(es
->heap
, 0, utext
);
2906 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2907 es
->undo_insert_count
, es
->undo_text
);
2913 /*********************************************************************
2918 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2920 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
2923 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2924 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2927 if (es
->style
& ES_MULTILINE
) {
2928 if (es
->style
& ES_READONLY
) {
2929 EDIT_MoveHome(wnd
, es
, FALSE
);
2930 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2932 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2936 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2937 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2940 if (!(es
->style
& ES_READONLY
) && !control
) {
2941 if (es
->selection_start
!= es
->selection_end
)
2942 EDIT_WM_Clear(wnd
, es
);
2944 /* delete character left of caret */
2945 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
2946 EDIT_MoveBackward(wnd
, es
, TRUE
);
2947 EDIT_WM_Clear(wnd
, es
);
2951 case 0x03: /* Ctrl-C */
2952 EDIT_WM_Copy(wnd
, es
);
2954 case 0x16: /* Ctrl-V */
2955 if (!(es
->style
& ES_READONLY
))
2956 EDIT_WM_Paste(wnd
, es
);
2958 case 0x18: /* Ctrl-X */
2959 if (!(es
->style
& ES_READONLY
))
2960 EDIT_WM_Cut(wnd
, es
);
2964 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2968 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2975 /*********************************************************************
2980 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
2982 if (code
|| control
)
2987 EDIT_EM_Undo(wnd
, es
);
2990 EDIT_WM_Cut(wnd
, es
);
2993 EDIT_WM_Copy(wnd
, es
);
2996 EDIT_WM_Paste(wnd
, es
);
2999 EDIT_WM_Clear(wnd
, es
);
3002 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3003 EDIT_EM_ScrollCaret(wnd
, es
);
3006 ERR("unknown menu item, please report\n");
3012 /*********************************************************************
3016 * Note: the resource files resource/sysres_??.rc cannot define a
3017 * single popup menu. Hence we use a (dummy) menubar
3018 * containing the single popup menu as its first item.
3020 * FIXME: the message identifiers have been chosen arbitrarily,
3021 * hence we use MF_BYPOSITION.
3022 * We might as well use the "real" values (anybody knows ?)
3023 * The menu definition is in resources/sysres_??.rc.
3024 * Once these are OK, we better use MF_BYCOMMAND here
3025 * (as we do in EDIT_WM_Command()).
3028 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
3030 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3031 HMENU popup
= GetSubMenu(menu
, 0);
3032 UINT start
= es
->selection_start
;
3033 UINT end
= es
->selection_end
;
3035 ORDER_UINT(start
, end
);
3038 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
3040 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3042 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3044 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
3046 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3048 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3050 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3055 /*********************************************************************
3060 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3062 INT s
= es
->selection_start
;
3063 INT e
= es
->selection_end
;
3070 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3071 dst
= GlobalLock(hdst
);
3072 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3074 OpenClipboard(wnd
->hwndSelf
);
3076 SetClipboardData(CF_TEXT
, hdst
);
3081 /*********************************************************************
3086 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3089 * To initialize some final structure members, we call some helper
3090 * functions. However, since the EDITSTATE is not consistent (i.e.
3091 * not fully initialized), we should be very careful which
3092 * functions can be called, and in what order.
3094 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3095 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3097 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3098 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3099 /* if we insert text to the editline, the text scrolls out
3100 * of the window, as the caret is placed after the insert
3101 * pos normally; thus we reset es->selection... to 0 and
3104 es
->selection_start
= es
->selection_end
= 0;
3105 EDIT_EM_ScrollCaret(wnd
, es
);
3111 /*********************************************************************
3116 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3119 while (LocalUnlock(es
->hloc32
)) ;
3120 LocalFree(es
->hloc32
);
3123 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3124 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3126 HeapDestroy(es
->heap
);
3127 HeapFree(GetProcessHeap(), 0, es
);
3128 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3132 /*********************************************************************
3137 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3142 if ( VERSION_AppWinVer() >= 0x40000 &&(
3143 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3144 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3146 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3149 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3151 GetClientRect(wnd
->hwndSelf
, &rc
);
3152 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3153 GetClipBox(dc
, &rc
);
3155 * FIXME: specs say that we should UnrealizeObject() the brush,
3156 * but the specs of UnrealizeObject() say that we shouldn't
3157 * unrealize a stock object. The default brush that
3158 * DefWndProc() returns is ... a stock object.
3160 FillRect(dc
, &rc
, brush
);
3165 /*********************************************************************
3170 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3172 lstrcpynA(text
, es
->text
, count
);
3173 return strlen(text
);
3177 /*********************************************************************
3181 * 16 bit notepad needs this. Actually it is not _our_ hack,
3182 * it is notepad's. Notepad is sending us scrollbar messages with
3183 * undocumented parameters without us even having a scrollbar ... !?!?
3186 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3189 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3192 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3193 ERR("hacked WM_HSCROLL handler invoked\n");
3194 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3195 ERR(" (this message is only displayed once per edit control)\n");
3196 es
->flags
|= EF_HSCROLL_HACK
;
3202 dx
= -es
->char_width
;
3205 if (es
->x_offset
< es
->text_width
)
3206 dx
= es
->char_width
;
3210 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3213 if (es
->x_offset
< es
->text_width
)
3214 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3221 if (es
->x_offset
< es
->text_width
)
3222 dx
= es
->text_width
- es
->x_offset
;
3225 es
->flags
|= EF_HSCROLL_TRACK
;
3226 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3228 case SB_THUMBPOSITION
:
3229 es
->flags
&= ~EF_HSCROLL_TRACK
;
3230 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3231 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3237 * FIXME : the next two are undocumented !
3238 * Are we doing the right thing ?
3239 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3240 * although it's also a regular control message.
3243 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3245 case EM_LINESCROLL16
:
3250 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3254 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3259 /*********************************************************************
3264 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3269 if (!(es
->style
& ES_MULTILINE
))
3272 if (!(es
->style
& ES_AUTOHSCROLL
))
3275 if (!(es
->style
& WS_HSCROLL
))
3276 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3279 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3283 dx
= -es
->char_width
;
3286 if (es
->x_offset
< es
->text_width
)
3287 dx
= es
->char_width
;
3291 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3294 if (es
->x_offset
< es
->text_width
)
3295 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3302 if (es
->x_offset
< es
->text_width
)
3303 dx
= es
->text_width
- es
->x_offset
;
3306 es
->flags
|= EF_HSCROLL_TRACK
;
3307 dx
= pos
- es
->x_offset
;
3309 case SB_THUMBPOSITION
:
3310 es
->flags
&= ~EF_HSCROLL_TRACK
;
3311 if (!(dx
= pos
- es
->x_offset
)) {
3312 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3313 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3320 ERR("undocumented WM_HSCROLL parameter, please report\n");
3324 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3329 /*********************************************************************
3334 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3338 if (WIDGETS_IsControl(wnd
->parent
, BIC32_COMBO
) &&
3339 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3340 HWND hCombo
= wnd
->parent
->hwndSelf
;
3341 BOOL bUIFlip
= TRUE
;
3343 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3344 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3347 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3349 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3350 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3354 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3356 /* make sure ComboLBox pops up */
3357 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3358 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3359 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3362 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3363 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3365 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3366 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3368 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3377 /*********************************************************************
3381 * Handling of special keys that don't produce a WM_CHAR
3382 * (i.e. non-printable keys) & Backspace & Delete
3385 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3390 if (GetKeyState(VK_MENU
) & 0x8000)
3393 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3394 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3399 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3405 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3406 EDIT_MoveUp_ML(wnd
, es
, shift
);
3409 EDIT_MoveWordBackward(wnd
, es
, shift
);
3411 EDIT_MoveBackward(wnd
, es
, shift
);
3414 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3418 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3419 EDIT_MoveDown_ML(wnd
, es
, shift
);
3421 EDIT_MoveWordForward(wnd
, es
, shift
);
3423 EDIT_MoveForward(wnd
, es
, shift
);
3426 EDIT_MoveHome(wnd
, es
, shift
);
3429 EDIT_MoveEnd(wnd
, es
, shift
);
3432 if (es
->style
& ES_MULTILINE
)
3433 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3436 if (es
->style
& ES_MULTILINE
)
3437 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3440 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3441 if (es
->selection_start
!= es
->selection_end
) {
3443 EDIT_WM_Cut(wnd
, es
);
3445 EDIT_WM_Clear(wnd
, es
);
3448 /* delete character left of caret */
3449 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3450 EDIT_MoveBackward(wnd
, es
, TRUE
);
3451 EDIT_WM_Clear(wnd
, es
);
3452 } else if (control
) {
3453 /* delete to end of line */
3454 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3455 EDIT_MoveEnd(wnd
, es
, TRUE
);
3456 EDIT_WM_Clear(wnd
, es
);
3458 /* delete character right of caret */
3459 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3460 EDIT_MoveForward(wnd
, es
, TRUE
);
3461 EDIT_WM_Clear(wnd
, es
);
3468 if (!(es
->style
& ES_READONLY
))
3469 EDIT_WM_Paste(wnd
, es
);
3471 EDIT_WM_Copy(wnd
, es
);
3474 /* If the edit doesn't want the return send a message to the default object */
3475 if(!(es
->style
& ES_WANTRETURN
))
3477 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
3478 DWORD dw
= SendMessage16( hwndParent
, DM_GETDEFID
, 0, 0 );
3479 if (HIWORD(dw
) == DC_HASDEFID
)
3481 SendMessageA( hwndParent
, WM_COMMAND
,
3482 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3483 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3492 /*********************************************************************
3497 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3499 es
->flags
&= ~EF_FOCUSED
;
3501 if(!(es
->style
& ES_NOHIDESEL
))
3502 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3503 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3508 /*********************************************************************
3512 * The caret position has been set on the WM_LBUTTONDOWN message
3515 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3518 INT e
= es
->selection_end
;
3523 if (!(es
->flags
& EF_FOCUSED
))
3526 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3527 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3528 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3529 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3530 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3531 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3532 EDIT_EM_ScrollCaret(wnd
, es
);
3537 /*********************************************************************
3542 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3547 if (!(es
->flags
& EF_FOCUSED
))
3550 es
->bCaptureState
= TRUE
;
3551 SetCapture(wnd
->hwndSelf
);
3552 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3553 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3554 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3555 EDIT_EM_ScrollCaret(wnd
, es
);
3556 es
->region_posx
= es
->region_posy
= 0;
3557 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3562 /*********************************************************************
3567 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3569 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3570 KillTimer(wnd
->hwndSelf
, 0);
3573 es
->bCaptureState
= FALSE
;
3578 /*********************************************************************
3583 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3589 if (GetCapture() != wnd
->hwndSelf
)
3593 * FIXME: gotta do some scrolling if outside client
3594 * area. Maybe reset the timer ?
3597 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3598 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3599 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3600 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3601 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3606 /*********************************************************************
3611 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3615 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3617 *(EDITSTATE
**)wnd
->wExtra
= es
;
3620 * Note: since the EDITSTATE has not been fully initialized yet,
3621 * we can't use any API calls that may send
3622 * WM_XXX messages before WM_NCCREATE is completed.
3625 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3627 es
->style
= cs
->style
;
3629 es
->bEnableState
= !(cs
->style
& WS_DISABLED
);
3632 * In Win95 look and feel, the WS_BORDER style is replaced by the
3633 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3634 * control a non client area.
3636 if (TWEAK_WineLook
!= WIN31_LOOK
)
3638 if (es
->style
& WS_BORDER
)
3640 es
->style
&= ~WS_BORDER
;
3641 wnd
->dwStyle
&= ~WS_BORDER
;
3642 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3647 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3648 wnd
->dwStyle
&= ~WS_BORDER
;
3651 if (es
->style
& ES_MULTILINE
) {
3652 es
->buffer_size
= BUFSTART_MULTI
;
3653 es
->buffer_limit
= BUFLIMIT_MULTI
;
3654 if (es
->style
& WS_VSCROLL
)
3655 es
->style
|= ES_AUTOVSCROLL
;
3656 if (es
->style
& WS_HSCROLL
)
3657 es
->style
|= ES_AUTOHSCROLL
;
3658 es
->style
&= ~ES_PASSWORD
;
3659 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3660 if (es
->style
& ES_RIGHT
)
3661 es
->style
&= ~ES_CENTER
;
3662 es
->style
&= ~WS_HSCROLL
;
3663 es
->style
&= ~ES_AUTOHSCROLL
;
3666 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3667 es
->style
|= ES_AUTOVSCROLL
;
3669 es
->buffer_size
= BUFSTART_SINGLE
;
3670 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3671 es
->style
&= ~ES_CENTER
;
3672 es
->style
&= ~ES_RIGHT
;
3673 es
->style
&= ~WS_HSCROLL
;
3674 es
->style
&= ~WS_VSCROLL
;
3675 es
->style
&= ~ES_AUTOVSCROLL
;
3676 es
->style
&= ~ES_WANTRETURN
;
3677 if (es
->style
& ES_UPPERCASE
) {
3678 es
->style
&= ~ES_LOWERCASE
;
3679 es
->style
&= ~ES_NUMBER
;
3680 } else if (es
->style
& ES_LOWERCASE
)
3681 es
->style
&= ~ES_NUMBER
;
3682 if (es
->style
& ES_PASSWORD
)
3683 es
->password_char
= '*';
3685 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3686 es
->style
|= ES_AUTOHSCROLL
;
3688 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3690 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3691 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3693 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3695 if (es
->style
& ES_MULTILINE
)
3696 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3703 /*********************************************************************
3708 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3717 BOOL rev
= es
->bEnableState
&&
3718 ((es
->flags
& EF_FOCUSED
) ||
3719 (es
->style
& ES_NOHIDESEL
));
3721 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3724 if(es
->style
& WS_BORDER
) {
3725 GetClientRect(wnd
->hwndSelf
, &rc
);
3726 if(es
->style
& ES_MULTILINE
) {
3727 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3728 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3730 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3732 IntersectClipRect(dc
, es
->format_rect
.left
,
3733 es
->format_rect
.top
,
3734 es
->format_rect
.right
,
3735 es
->format_rect
.bottom
);
3736 if (es
->style
& ES_MULTILINE
) {
3737 GetClientRect(wnd
->hwndSelf
, &rc
);
3738 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3741 old_font
= SelectObject(dc
, es
->font
);
3742 if ( VERSION_AppWinVer() >= 0x40000 &&(
3743 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3744 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3746 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3748 if (!es
->bEnableState
)
3749 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3750 GetClipBox(dc
, &rcRgn
);
3751 if (es
->style
& ES_MULTILINE
) {
3752 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3753 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3754 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3755 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3756 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3759 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3760 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3761 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3764 SelectObject(dc
, old_font
);
3765 if (es
->flags
& EF_FOCUSED
)
3766 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3767 es
->flags
& EF_AFTER_WRAP
);
3769 EndPaint(wnd
->hwndSelf
, &ps
);
3770 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3771 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3773 si
.cbSize
= sizeof(SCROLLINFO
);
3774 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3776 si
.nMax
= es
->line_count
+ vlc
- 2;
3778 si
.nPos
= es
->y_offset
;
3779 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3781 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3783 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3784 si
.cbSize
= sizeof(SCROLLINFO
);
3785 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3787 si
.nMax
= es
->text_width
+ fw
- 1;
3789 si
.nPos
= es
->x_offset
;
3790 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3793 if (es
->flags
& EF_UPDATE
) {
3794 es
->flags
&= ~EF_UPDATE
;
3795 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3800 /*********************************************************************
3805 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3810 OpenClipboard(wnd
->hwndSelf
);
3811 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3812 src
= (LPSTR
)GlobalLock(hsrc
);
3813 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3820 /*********************************************************************
3825 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3827 es
->flags
|= EF_FOCUSED
;
3828 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3829 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3830 es
->flags
& EF_AFTER_WRAP
);
3831 if(!(es
->style
& ES_NOHIDESEL
))
3832 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3833 ShowCaret(wnd
->hwndSelf
);
3834 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3838 /*********************************************************************
3842 * With Win95 look the margins are set to default font value unless
3843 * the system font (font == 0) is being set, in which case they are left
3847 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3855 dc
= GetDC(wnd
->hwndSelf
);
3857 old_font
= SelectObject(dc
, font
);
3858 GetTextMetricsA(dc
, &tm
);
3859 es
->line_height
= tm
.tmHeight
;
3860 es
->char_width
= tm
.tmAveCharWidth
;
3862 SelectObject(dc
, old_font
);
3863 ReleaseDC(wnd
->hwndSelf
, dc
);
3864 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3865 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3866 EC_USEFONTINFO
, EC_USEFONTINFO
);
3868 /* Force the recalculation of the format rect for each font change */
3869 GetClientRect(wnd
->hwndSelf
, &r
);
3870 EDIT_SetRectNP(wnd
, es
, &r
);
3872 if (es
->style
& ES_MULTILINE
)
3873 EDIT_BuildLineDefs_ML(wnd
, es
);
3876 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3877 if (es
->flags
& EF_FOCUSED
) {
3879 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3880 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3881 es
->flags
& EF_AFTER_WRAP
);
3882 ShowCaret(wnd
->hwndSelf
);
3887 /*********************************************************************
3892 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3893 * The modified flag is reset. No notifications are sent.
3895 * For single-line controls, reception of WM_SETTEXT triggers:
3896 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3899 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3901 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3903 TRACE("\t'%s'\n", text
);
3904 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3906 TRACE("\t<NULL>\n");
3907 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3910 if (es
->style
& ES_MULTILINE
) {
3911 es
->flags
&= ~EF_UPDATE
;
3913 es
->flags
|= EF_UPDATE
;
3915 es
->flags
&= ~EF_MODIFIED
;
3916 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3917 EDIT_EM_ScrollCaret(wnd
, es
);
3919 if (es
->flags
& EF_UPDATE
)
3920 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3924 /*********************************************************************
3929 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3931 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3933 SetRect(&rc
, 0, 0, width
, height
);
3934 EDIT_SetRectNP(wnd
, es
, &rc
);
3935 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3940 /*********************************************************************
3945 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3947 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3948 if (EDIT_EM_CanUndo(wnd
, es
))
3949 EDIT_EM_Undo(wnd
, es
);
3951 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3952 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3954 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
3958 /*********************************************************************
3963 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
3965 if (es
->region_posx
< 0) {
3966 EDIT_MoveBackward(wnd
, es
, TRUE
);
3967 } else if (es
->region_posx
> 0) {
3968 EDIT_MoveForward(wnd
, es
, TRUE
);
3971 * FIXME: gotta do some vertical scrolling here, like
3972 * EDIT_EM_LineScroll(wnd, 0, 1);
3977 /*********************************************************************
3981 * 16 bit notepad needs this. Actually it is not _our_ hack,
3982 * it is notepad's. Notepad is sending us scrollbar messages with
3983 * undocumented parameters without us even having a scrollbar ... !?!?
3986 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3991 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3992 ERR("hacked WM_VSCROLL handler invoked\n");
3993 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3994 ERR(" (this message is only displayed once per edit control)\n");
3995 es
->flags
|= EF_VSCROLL_HACK
;
4003 EDIT_EM_Scroll(wnd
, es
, action
);
4009 dy
= es
->line_count
- 1 - es
->y_offset
;
4012 es
->flags
|= EF_VSCROLL_TRACK
;
4013 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
4015 case SB_THUMBPOSITION
:
4016 es
->flags
&= ~EF_VSCROLL_TRACK
;
4017 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
4018 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4024 * FIXME : the next two are undocumented !
4025 * Are we doing the right thing ?
4026 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4027 * although it's also a regular control message.
4030 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
4032 case EM_LINESCROLL16
:
4037 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4041 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4046 /*********************************************************************
4051 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4055 if (!(es
->style
& ES_MULTILINE
))
4058 if (!(es
->style
& ES_AUTOVSCROLL
))
4061 if (!(es
->style
& WS_VSCROLL
))
4062 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4070 EDIT_EM_Scroll(wnd
, es
, action
);
4077 dy
= es
->line_count
- 1 - es
->y_offset
;
4080 es
->flags
|= EF_VSCROLL_TRACK
;
4081 dy
= pos
- es
->y_offset
;
4083 case SB_THUMBPOSITION
:
4084 es
->flags
&= ~EF_VSCROLL_TRACK
;
4085 if (!(dy
= pos
- es
->y_offset
)) {
4086 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4087 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4094 ERR("undocumented WM_VSCROLL action %d, please report\n",
4099 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);