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
));
874 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
877 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
879 WIN_ReleaseWndPtr(wnd
);
885 /*********************************************************************
887 * EDIT_BuildLineDefs_ML
889 * Build linked list of text lines.
890 * Lines can end with '\0' (last line), a character (if it is wrapped),
891 * a soft return '\r\r\n' or a hard return '\r\n'
894 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
900 LINEDEF
*current_def
;
901 LINEDEF
**previous_next
;
903 current_def
= es
->first_line_def
;
905 LINEDEF
*next_def
= current_def
->next
;
906 HeapFree(es
->heap
, 0, current_def
);
907 current_def
= next_def
;
908 } while (current_def
);
912 dc
= GetDC(wnd
->hwndSelf
);
914 old_font
= SelectObject(dc
, es
->font
);
916 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
918 previous_next
= &es
->first_line_def
;
920 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
921 current_def
->next
= NULL
;
924 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
929 current_def
->ending
= END_0
;
930 current_def
->net_length
= lstrlenA(start
);
931 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
932 current_def
->ending
= END_SOFT
;
933 current_def
->net_length
= cp
- start
- 1;
935 current_def
->ending
= END_HARD
;
936 current_def
->net_length
= cp
- start
;
938 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
939 start
, current_def
->net_length
,
940 es
->tabs_count
, es
->tabs
));
941 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
942 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
947 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
948 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
949 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
950 start
, next
, es
->tabs_count
, es
->tabs
));
951 } while (current_def
->width
<= fw
);
957 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
958 start
, next
, es
->tabs_count
, es
->tabs
));
959 } while (current_def
->width
<= fw
);
963 current_def
->net_length
= prev
;
964 current_def
->ending
= END_WRAP
;
965 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
966 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
968 switch (current_def
->ending
) {
970 current_def
->length
= current_def
->net_length
+ 3;
973 current_def
->length
= current_def
->net_length
+ 2;
977 current_def
->length
= current_def
->net_length
;
980 es
->text_width
= max(es
->text_width
, current_def
->width
);
981 start
+= current_def
->length
;
982 *previous_next
= current_def
;
983 previous_next
= ¤t_def
->next
;
985 } while (current_def
->ending
!= END_0
);
987 SelectObject(dc
, old_font
);
988 ReleaseDC(wnd
->hwndSelf
, dc
);
992 /*********************************************************************
994 * EDIT_CallWordBreakProc
996 * Call appropriate WordBreakProc (internal or external).
998 * Note: The "start" argument should always be an index refering
999 * to es->text. The actual wordbreak proc might be
1000 * 16 bit, so we can't always pass any 32 bit LPSTR.
1001 * Hence we assume that es->text is the buffer that holds
1002 * the string under examination (we can decide this for ourselves).
1005 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1007 if (es
->word_break_proc16
) {
1008 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1009 SEGPTR segptr
= LocalLock16(hloc16
);
1010 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1011 segptr
+ start
, index
, count
, action
);
1012 LocalUnlock16(hloc16
);
1015 else if (es
->word_break_proc32A
)
1017 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1018 es
->word_break_proc32A
, es
->text
+ start
, index
,
1020 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1024 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1028 /*********************************************************************
1032 * Beware: This is not the function called on EM_CHARFROMPOS
1033 * The position _can_ be outside the formatting / client
1035 * The return value is only the character index
1038 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1044 if (es
->style
& ES_MULTILINE
) {
1045 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1047 LINEDEF
*line_def
= es
->first_line_def
;
1049 while ((line
> 0) && line_def
->next
) {
1050 line_index
+= line_def
->length
;
1051 line_def
= line_def
->next
;
1054 x
+= es
->x_offset
- es
->format_rect
.left
;
1055 if (x
>= line_def
->width
) {
1057 *after_wrap
= (line_def
->ending
== END_WRAP
);
1058 return line_index
+ line_def
->net_length
;
1062 *after_wrap
= FALSE
;
1065 dc
= GetDC(wnd
->hwndSelf
);
1067 old_font
= SelectObject(dc
, es
->font
);
1068 low
= line_index
+ 1;
1069 high
= line_index
+ line_def
->net_length
+ 1;
1070 while (low
< high
- 1)
1072 INT mid
= (low
+ high
) / 2;
1073 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1079 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1080 (line_def
->ending
== END_WRAP
));
1085 *after_wrap
= FALSE
;
1086 x
-= es
->format_rect
.left
;
1088 return es
->x_offset
;
1089 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1090 dc
= GetDC(wnd
->hwndSelf
);
1092 old_font
= SelectObject(dc
, es
->font
);
1096 INT high
= es
->x_offset
;
1097 while (low
< high
- 1)
1099 INT mid
= (low
+ high
) / 2;
1100 GetTextExtentPoint32A( dc
, text
+ mid
,
1101 es
->x_offset
- mid
, &size
);
1102 if (size
.cx
> -x
) low
= mid
;
1109 INT low
= es
->x_offset
;
1110 INT high
= lstrlenA(es
->text
) + 1;
1111 while (low
< high
- 1)
1113 INT mid
= (low
+ high
) / 2;
1114 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1115 mid
- es
->x_offset
, &size
);
1116 if (size
.cx
> x
) high
= mid
;
1121 if (es
->style
& ES_PASSWORD
)
1122 HeapFree(es
->heap
, 0 ,text
);
1125 SelectObject(dc
, old_font
);
1126 ReleaseDC(wnd
->hwndSelf
, dc
);
1131 /*********************************************************************
1135 * adjusts the point to be within the formatting rectangle
1136 * (so CharFromPos returns the nearest _visible_ character)
1139 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1141 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1142 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1146 /*********************************************************************
1150 * Calculates the bounding rectangle for a line from a starting
1151 * column to an ending column.
1154 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1156 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1158 if (es
->style
& ES_MULTILINE
)
1159 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1161 rc
->top
= es
->format_rect
.top
;
1162 rc
->bottom
= rc
->top
+ es
->line_height
;
1163 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1164 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1168 /*********************************************************************
1170 * EDIT_GetPasswordPointer_SL
1172 * note: caller should free the (optionally) allocated buffer
1175 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1177 if (es
->style
& ES_PASSWORD
) {
1178 INT len
= lstrlenA(es
->text
);
1179 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1180 RtlFillMemory(text
, len
, es
->password_char
);
1188 /*********************************************************************
1192 * This acts as a LOCAL_Lock(), but it locks only once. This way
1193 * you can call it whenever you like, without unlocking.
1196 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1199 ERR("no EDITSTATE ... please report\n");
1202 if (!(es
->style
& ES_MULTILINE
))
1206 es
->text
= LocalLock(es
->hloc32
);
1207 else if (es
->hloc16
)
1208 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1210 ERR("no buffer ... please report\n");
1218 /*********************************************************************
1220 * EDIT_SL_InvalidateText
1222 * Called from EDIT_InvalidateText().
1223 * Does the job for single-line controls only.
1226 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1231 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1232 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1233 InvalidateRect(wnd
->hwndSelf
, &rc
, FALSE
);
1237 /*********************************************************************
1239 * EDIT_ML_InvalidateText
1241 * Called from EDIT_InvalidateText().
1242 * Does the job for multi-line controls only.
1245 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1247 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1248 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1249 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1258 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1261 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1262 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1263 if (sl
< es
->y_offset
) {
1267 if (el
> es
->y_offset
+ vlc
) {
1268 el
= es
->y_offset
+ vlc
;
1269 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1271 GetClientRect(wnd
->hwndSelf
, &rc1
);
1272 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1274 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1275 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1276 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1278 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1279 EDIT_EM_LineLength(wnd
, es
,
1280 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1282 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1283 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1284 for (l
= sl
+ 1 ; l
< el
; l
++) {
1285 EDIT_GetLineRect(wnd
, es
, l
, 0,
1286 EDIT_EM_LineLength(wnd
, es
,
1287 EDIT_EM_LineIndex(wnd
, es
, l
)),
1289 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1290 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1292 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1293 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1294 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1299 /*********************************************************************
1301 * EDIT_InvalidateText
1303 * Invalidate the text from offset start upto, but not including,
1304 * offset end. Useful for (re)painting the selection.
1305 * Regions outside the linewidth are not invalidated.
1306 * end == -1 means end == TextLength.
1307 * start and end need not be ordered.
1310 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1316 end
= lstrlenA(es
->text
);
1318 ORDER_INT(start
, end
);
1320 if (es
->style
& ES_MULTILINE
)
1321 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1323 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1327 /*********************************************************************
1331 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1334 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1339 if (size
<= es
->buffer_size
)
1341 if (size
> es
->buffer_limit
) {
1342 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1345 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1346 if (size
> es
->buffer_limit
)
1347 size
= es
->buffer_limit
;
1349 TRACE("trying to ReAlloc to %d+1\n", size
);
1351 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1353 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1354 es
->buffer_size
= min(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1356 es
->buffer_size
= 0;
1357 } else if (es
->hloc32
) {
1358 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1359 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1360 es
->hloc32
= hNew32
;
1361 es
->buffer_size
= min(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1363 } else if (es
->hloc16
) {
1364 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1365 TRACE("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1366 es
->hloc16
= hNew16
;
1367 es
->buffer_size
= min(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1370 if (es
->buffer_size
< size
) {
1371 EDIT_LockBuffer(wnd
, es
);
1372 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1373 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1376 EDIT_LockBuffer(wnd
, es
);
1377 TRACE("We now have %d+1\n", es
->buffer_size
);
1383 /*********************************************************************
1387 * Try to fit size + 1 bytes in the undo buffer.
1390 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1392 if (size
<= es
->undo_buffer_size
)
1394 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1396 TRACE("trying to ReAlloc to %d+1\n", size
);
1398 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1399 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1400 if (es
->undo_buffer_size
< size
) {
1401 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1410 /*********************************************************************
1415 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1417 INT e
= es
->selection_end
;
1421 if ((es
->style
& ES_MULTILINE
) && e
&&
1422 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1424 if (e
&& (es
->text
[e
- 1] == '\r'))
1428 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1429 EDIT_EM_ScrollCaret(wnd
, es
);
1433 /*********************************************************************
1437 * Only for multi line controls
1438 * Move the caret one line down, on a column with the nearest
1439 * x coordinate on the screen (might be a different column).
1442 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1444 INT s
= es
->selection_start
;
1445 INT e
= es
->selection_end
;
1446 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1447 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1448 INT x
= SLOWORD(pos
);
1449 INT y
= SHIWORD(pos
);
1451 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1454 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1455 EDIT_EM_ScrollCaret(wnd
, es
);
1459 /*********************************************************************
1464 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1466 BOOL after_wrap
= FALSE
;
1469 /* Pass a high value in x to make sure of receiving the en of the line */
1470 if (es
->style
& ES_MULTILINE
)
1471 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1472 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1474 e
= lstrlenA(es
->text
);
1475 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1476 EDIT_EM_ScrollCaret(wnd
, es
);
1480 /*********************************************************************
1485 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1487 INT e
= es
->selection_end
;
1491 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1492 if (es
->text
[e
] == '\n')
1494 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1498 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1499 EDIT_EM_ScrollCaret(wnd
, es
);
1503 /*********************************************************************
1507 * Home key: move to beginning of line.
1510 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1514 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1515 if (es
->style
& ES_MULTILINE
)
1516 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1517 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1520 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1521 EDIT_EM_ScrollCaret(wnd
, es
);
1525 /*********************************************************************
1527 * EDIT_MovePageDown_ML
1529 * Only for multi line controls
1530 * Move the caret one page down, on a column with the nearest
1531 * x coordinate on the screen (might be a different column).
1534 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1536 INT s
= es
->selection_start
;
1537 INT e
= es
->selection_end
;
1538 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1539 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1540 INT x
= SLOWORD(pos
);
1541 INT y
= SHIWORD(pos
);
1543 e
= EDIT_CharFromPos(wnd
, es
, x
,
1544 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1548 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1549 EDIT_EM_ScrollCaret(wnd
, es
);
1553 /*********************************************************************
1555 * EDIT_MovePageUp_ML
1557 * Only for multi line controls
1558 * Move the caret one page up, on a column with the nearest
1559 * x coordinate on the screen (might be a different column).
1562 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1564 INT s
= es
->selection_start
;
1565 INT e
= es
->selection_end
;
1566 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1567 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1568 INT x
= SLOWORD(pos
);
1569 INT y
= SHIWORD(pos
);
1571 e
= EDIT_CharFromPos(wnd
, es
, x
,
1572 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1576 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1577 EDIT_EM_ScrollCaret(wnd
, es
);
1581 /*********************************************************************
1585 * Only for multi line controls
1586 * Move the caret one line up, on a column with the nearest
1587 * x coordinate on the screen (might be a different column).
1590 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1592 INT s
= es
->selection_start
;
1593 INT e
= es
->selection_end
;
1594 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1595 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1596 INT x
= SLOWORD(pos
);
1597 INT y
= SHIWORD(pos
);
1599 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1602 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1603 EDIT_EM_ScrollCaret(wnd
, es
);
1607 /*********************************************************************
1609 * EDIT_MoveWordBackward
1612 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1614 INT s
= es
->selection_start
;
1615 INT e
= es
->selection_end
;
1620 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1621 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1622 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1625 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1626 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1629 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1630 li
, e
- li
, ll
, WB_LEFT
);
1634 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1635 EDIT_EM_ScrollCaret(wnd
, es
);
1639 /*********************************************************************
1641 * EDIT_MoveWordForward
1644 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1646 INT s
= es
->selection_start
;
1647 INT e
= es
->selection_end
;
1652 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1653 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1654 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1656 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1657 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1659 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1660 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1664 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1665 EDIT_EM_ScrollCaret(wnd
, es
);
1669 /*********************************************************************
1674 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1676 INT s
= es
->selection_start
;
1677 INT e
= es
->selection_end
;
1684 if (es
->style
& ES_MULTILINE
) {
1685 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1686 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1691 TRACE("line=%d\n", line
);
1693 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1696 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1697 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1698 s
= es
->selection_start
;
1699 e
= es
->selection_end
;
1701 s
= min(li
+ ll
, max(li
, s
));
1702 e
= min(li
+ ll
, max(li
, e
));
1703 if (rev
&& (s
!= e
) &&
1704 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1705 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1706 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1707 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1709 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1713 /*********************************************************************
1718 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1728 BkColor
= GetBkColor(dc
);
1729 TextColor
= GetTextColor(dc
);
1731 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1732 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1734 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1735 if (es
->style
& ES_MULTILINE
) {
1736 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1737 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1739 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1740 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1741 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1743 if (es
->style
& ES_PASSWORD
)
1744 HeapFree(es
->heap
, 0, text
);
1747 SetBkColor(dc
, BkColor
);
1748 SetTextColor(dc
, TextColor
);
1754 /*********************************************************************
1759 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1762 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1763 INT x
= SLOWORD(res
);
1764 INT y
= SHIWORD(res
);
1766 if(x
< es
->format_rect
.left
)
1767 x
= es
->format_rect
.left
;
1768 if(x
> es
->format_rect
.right
- 2)
1769 x
= es
->format_rect
.right
- 2;
1770 if(y
> es
->format_rect
.bottom
)
1771 y
= es
->format_rect
.bottom
;
1772 if(y
< es
->format_rect
.top
)
1773 y
= es
->format_rect
.top
;
1779 /*********************************************************************
1783 * note: this is not (exactly) the handler called on EM_SETRECTNP
1784 * it is also used to set the rect of a single line control
1787 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1789 CopyRect(&es
->format_rect
, rc
);
1790 if (es
->style
& WS_BORDER
) {
1791 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1792 if(TWEAK_WineLook
== WIN31_LOOK
)
1794 es
->format_rect
.left
+= bw
;
1795 es
->format_rect
.top
+= bw
;
1796 es
->format_rect
.right
-= bw
;
1797 es
->format_rect
.bottom
-= bw
;
1799 es
->format_rect
.left
+= es
->left_margin
;
1800 es
->format_rect
.right
-= es
->right_margin
;
1801 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1802 if (es
->style
& ES_MULTILINE
)
1803 es
->format_rect
.bottom
= es
->format_rect
.top
+
1804 max(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1806 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1807 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1808 EDIT_BuildLineDefs_ML(wnd
, es
);
1812 /*********************************************************************
1817 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1820 ERR("no EDITSTATE ... please report\n");
1823 if (!(es
->style
& ES_MULTILINE
))
1825 if (!es
->lock_count
) {
1826 ERR("lock_count == 0 ... please report\n");
1830 ERR("es->text == 0 ... please report\n");
1833 if (force
|| (es
->lock_count
== 1)) {
1835 LocalUnlock(es
->hloc32
);
1837 } else if (es
->hloc16
) {
1838 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1846 /*********************************************************************
1848 * EDIT_WordBreakProc
1850 * Find the beginning of words.
1851 * Note: unlike the specs for a WordBreakProc, this function only
1852 * allows to be called without linebreaks between s[0] upto
1853 * s[count - 1]. Remember it is only called
1854 * internally, so we can decide this for ourselves.
1857 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1861 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1862 s
, index
, count
, action
);
1870 if (s
[index
] == ' ') {
1871 while (index
&& (s
[index
] == ' '))
1874 while (index
&& (s
[index
] != ' '))
1876 if (s
[index
] == ' ')
1880 while (index
&& (s
[index
] != ' '))
1882 if (s
[index
] == ' ')
1892 if (s
[index
] == ' ')
1893 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1895 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1897 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1901 case WB_ISDELIMITER
:
1902 ret
= (s
[index
] == ' ');
1905 ERR("unknown action code, please report !\n");
1912 /*********************************************************************
1916 * returns line number (not index) in high-order word of result.
1917 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1918 * to Richedit, not to the edit control. Original documentation is valid.
1919 * FIXME: do the specs mean to return -1 if outside client area or
1920 * if outside formatting rectangle ???
1923 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1931 GetClientRect(wnd
->hwndSelf
, &rc
);
1932 if (!PtInRect(&rc
, pt
))
1935 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1936 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1940 /*********************************************************************
1944 * Enable or disable soft breaks.
1946 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1948 es
->flags
&= ~EF_USE_SOFTBRK
;
1950 es
->flags
|= EF_USE_SOFTBRK
;
1951 FIXME("soft break enabled, not implemented\n");
1957 /*********************************************************************
1961 * Hopefully this won't fire back at us.
1962 * We always start with a fixed buffer in our own heap.
1963 * However, with this message a 32 bit application requests
1964 * a handle to 32 bit moveable local heap memory, where it expects
1966 * It's a pity that from this moment on we have to use this
1967 * local heap, because applications may rely on the handle
1970 * In this function we'll try to switch to local heap.
1973 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1979 if (!(es
->style
& ES_MULTILINE
))
1984 else if (es
->hloc16
)
1985 return (HLOCAL
)es
->hloc16
;
1987 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
1988 ERR("could not allocate new 32 bit buffer\n");
1991 newSize
= min(LocalSize(newBuf
) - 1, es
->buffer_limit
);
1992 if (!(newText
= LocalLock(newBuf
))) {
1993 ERR("could not lock new 32 bit buffer\n");
1997 lstrcpyA(newText
, es
->text
);
1998 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2000 HeapFree(es
->heap
, 0, es
->text
);
2001 es
->hloc32
= newBuf
;
2002 es
->hloc16
= (HLOCAL16
)NULL
;
2003 es
->buffer_size
= newSize
;
2005 EDIT_LockBuffer(wnd
, es
);
2006 TRACE("switched to 32 bit local heap\n");
2012 /*********************************************************************
2016 * Hopefully this won't fire back at us.
2017 * We always start with a buffer in 32 bit linear memory.
2018 * However, with this message a 16 bit application requests
2019 * a handle of 16 bit local heap memory, where it expects to find
2021 * It's a pitty that from this moment on we have to use this
2022 * local heap, because applications may rely on the handle
2025 * In this function we'll try to switch to local heap.
2027 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2033 if (!(es
->style
& ES_MULTILINE
))
2039 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2040 if (!LocalInit16(wnd
->hInstance
, 0,
2041 GlobalSize16(wnd
->hInstance
))) {
2042 ERR("could not initialize local heap\n");
2045 TRACE("local heap initialized\n");
2047 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2048 ERR("could not allocate new 16 bit buffer\n");
2051 newSize
= min(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2052 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2053 ERR("could not lock new 16 bit buffer\n");
2054 LOCAL_Free(wnd
->hInstance
, newBuf
);
2057 lstrcpyA(newText
, es
->text
);
2058 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2060 HeapFree(es
->heap
, 0, es
->text
);
2061 else if (es
->hloc32
) {
2062 while (LocalFree(es
->hloc32
)) ;
2063 LocalFree(es
->hloc32
);
2065 es
->hloc32
= (HLOCAL
)NULL
;
2066 es
->hloc16
= newBuf
;
2067 es
->buffer_size
= newSize
;
2069 EDIT_LockBuffer(wnd
, es
);
2070 TRACE("switched to 16 bit buffer\n");
2076 /*********************************************************************
2081 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2087 if (es
->style
& ES_MULTILINE
) {
2088 if (line
>= es
->line_count
)
2092 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2094 len
= min(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2095 for (i
= 0 ; i
< len
; i
++) {
2100 return (LRESULT
)len
;
2104 /*********************************************************************
2109 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2111 UINT s
= es
->selection_start
;
2112 UINT e
= es
->selection_end
;
2119 return MAKELONG(s
, e
);
2123 /*********************************************************************
2127 * FIXME: is this right ? (or should it be only VSCROLL)
2128 * (and maybe only for edit controls that really have their
2129 * own scrollbars) (and maybe only for multiline controls ?)
2130 * All in all: very poorly documented
2132 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2133 * WM_VSCROLL handlers
2136 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2138 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2139 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2143 /*********************************************************************
2148 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2153 if (!(es
->style
& ES_MULTILINE
))
2155 if (index
> lstrlenA(es
->text
))
2156 return es
->line_count
- 1;
2158 index
= min(es
->selection_start
, es
->selection_end
);
2161 line_def
= es
->first_line_def
;
2162 index
-= line_def
->length
;
2163 while ((index
>= 0) && line_def
->next
) {
2165 line_def
= line_def
->next
;
2166 index
-= line_def
->length
;
2172 /*********************************************************************
2177 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2182 if (!(es
->style
& ES_MULTILINE
))
2184 if (line
>= es
->line_count
)
2188 line_def
= es
->first_line_def
;
2190 INT index
= es
->selection_end
- line_def
->length
;
2191 while ((index
>= 0) && line_def
->next
) {
2192 line_index
+= line_def
->length
;
2193 line_def
= line_def
->next
;
2194 index
-= line_def
->length
;
2198 line_index
+= line_def
->length
;
2199 line_def
= line_def
->next
;
2207 /*********************************************************************
2212 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2216 if (!(es
->style
& ES_MULTILINE
))
2217 return lstrlenA(es
->text
);
2221 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2222 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2223 return es->selection_start - es->line_defs[sl].offset +
2224 es->line_defs[el].offset +
2225 es->line_defs[el].length - es->selection_end;
2229 line_def
= es
->first_line_def
;
2230 index
-= line_def
->length
;
2231 while ((index
>= 0) && line_def
->next
) {
2232 line_def
= line_def
->next
;
2233 index
-= line_def
->length
;
2235 return line_def
->net_length
;
2239 /*********************************************************************
2243 * FIXME: dx is in average character widths
2244 * However, we assume it is in pixels when we use this
2245 * function internally
2248 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2252 if (!(es
->style
& ES_MULTILINE
))
2255 if (-dx
> es
->x_offset
)
2257 if (dx
> es
->text_width
- es
->x_offset
)
2258 dx
= es
->text_width
- es
->x_offset
;
2259 nyoff
= max(0, es
->y_offset
+ dy
);
2260 if (nyoff
>= es
->line_count
)
2261 nyoff
= es
->line_count
- 1;
2262 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2266 GetClientRect(wnd
->hwndSelf
, &rc1
);
2267 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2268 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2269 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2270 es
->y_offset
= nyoff
;
2273 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2274 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2275 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2276 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2281 /*********************************************************************
2286 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2288 INT len
= lstrlenA(es
->text
);
2297 index
= min(index
, len
);
2298 dc
= GetDC(wnd
->hwndSelf
);
2300 old_font
= SelectObject(dc
, es
->font
);
2301 if (es
->style
& ES_MULTILINE
) {
2302 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2303 y
= (l
- es
->y_offset
) * es
->line_height
;
2304 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2305 if (after_wrap
&& (li
== index
) && l
) {
2307 LINEDEF
*line_def
= es
->first_line_def
;
2309 line_def
= line_def
->next
;
2312 if (line_def
->ending
== END_WRAP
) {
2314 y
-= es
->line_height
;
2315 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2318 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2319 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2321 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2322 if (index
< es
->x_offset
) {
2323 GetTextExtentPoint32A(dc
, text
+ index
,
2324 es
->x_offset
- index
, &size
);
2327 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2328 index
- es
->x_offset
, &size
);
2332 if (es
->style
& ES_PASSWORD
)
2333 HeapFree(es
->heap
, 0 ,text
);
2335 x
+= es
->format_rect
.left
;
2336 y
+= es
->format_rect
.top
;
2338 SelectObject(dc
, old_font
);
2339 ReleaseDC(wnd
->hwndSelf
, dc
);
2340 return MAKELONG((INT16
)x
, (INT16
)y
);
2344 /*********************************************************************
2348 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2351 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2353 INT strl
= lstrlenA(lpsz_replace
);
2354 INT tl
= lstrlenA(es
->text
);
2361 s
= es
->selection_start
;
2362 e
= es
->selection_end
;
2364 if ((s
== e
) && !strl
)
2369 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2373 /* there is something to be deleted */
2375 utl
= lstrlenA(es
->undo_text
);
2376 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2377 /* undo-buffer is extended to the right */
2378 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2379 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2380 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2381 /* undo-buffer is extended to the left */
2382 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2383 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2385 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2386 p
[i
] = (es
->text
+ s
)[i
];
2387 es
->undo_position
= s
;
2389 /* new undo-buffer */
2390 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2391 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2392 es
->undo_position
= s
;
2394 /* any deletion makes the old insertion-undo invalid */
2395 es
->undo_insert_count
= 0;
2397 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2400 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2403 /* there is an insertion */
2405 if ((s
== es
->undo_position
) ||
2406 ((es
->undo_insert_count
) &&
2407 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2409 * insertion is new and at delete position or
2410 * an extension to either left or right
2412 es
->undo_insert_count
+= strl
;
2414 /* new insertion undo */
2415 es
->undo_position
= s
;
2416 es
->undo_insert_count
= strl
;
2417 /* new insertion makes old delete-buffer invalid */
2418 *es
->undo_text
= '\0';
2421 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2424 tl
= lstrlenA(es
->text
);
2425 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2427 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2428 p
[i
] = lpsz_replace
[i
];
2429 if(es
->style
& ES_UPPERCASE
)
2430 CharUpperBuffA(p
, strl
);
2431 else if(es
->style
& ES_LOWERCASE
)
2432 CharLowerBuffA(p
, strl
);
2435 /* FIXME: really inefficient */
2436 if (es
->style
& ES_MULTILINE
)
2437 EDIT_BuildLineDefs_ML(wnd
, es
);
2439 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2440 es
->flags
|= EF_MODIFIED
;
2441 es
->flags
|= EF_UPDATE
;
2442 EDIT_EM_ScrollCaret(wnd
, es
);
2444 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
2446 /* FIXME: really inefficient */
2447 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2451 /*********************************************************************
2456 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2460 if (!(es
->style
& ES_MULTILINE
))
2461 return (LRESULT
)FALSE
;
2471 if (es
->y_offset
< es
->line_count
- 1)
2476 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2479 if (es
->y_offset
< es
->line_count
- 1)
2480 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2483 return (LRESULT
)FALSE
;
2486 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2487 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2489 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2493 /*********************************************************************
2498 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2500 if (es
->style
& ES_MULTILINE
) {
2505 INT cw
= es
->char_width
;
2510 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2511 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2512 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2513 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2514 if (l
>= es
->y_offset
+ vlc
)
2515 dy
= l
- vlc
+ 1 - es
->y_offset
;
2516 if (l
< es
->y_offset
)
2517 dy
= l
- es
->y_offset
;
2518 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2519 if (x
< es
->format_rect
.left
)
2520 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2521 if (x
> es
->format_rect
.right
)
2522 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2524 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2530 if (!(es
->style
& ES_AUTOHSCROLL
))
2533 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2534 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2535 if (x
< es
->format_rect
.left
) {
2536 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2539 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2540 } while ((x
< goal
) && es
->x_offset
);
2541 /* FIXME: use ScrollWindow() somehow to improve performance */
2542 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2543 } else if (x
> es
->format_rect
.right
) {
2545 INT len
= lstrlenA(es
->text
);
2546 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2549 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2550 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2551 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2552 /* FIXME: use ScrollWindow() somehow to improve performance */
2553 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2559 /*********************************************************************
2563 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2566 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2568 if (!(es
->style
& ES_MULTILINE
))
2572 WARN("called with NULL handle\n");
2576 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2578 * old buffer is freed by caller, unless
2579 * it is still in our own heap. (in that case
2580 * we free it, correcting the buggy caller.)
2583 HeapFree(es
->heap
, 0, es
->text
);
2585 es
->hloc16
= (HLOCAL16
)NULL
;
2588 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2589 EDIT_LockBuffer(wnd
, es
);
2591 es
->x_offset
= es
->y_offset
= 0;
2592 es
->selection_start
= es
->selection_end
= 0;
2593 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2594 es
->flags
&= ~EF_MODIFIED
;
2595 es
->flags
&= ~EF_UPDATE
;
2596 EDIT_BuildLineDefs_ML(wnd
, es
);
2597 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2598 EDIT_EM_ScrollCaret(wnd
, es
);
2602 /*********************************************************************
2606 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2609 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2611 if (!(es
->style
& ES_MULTILINE
))
2615 WARN("called with NULL handle\n");
2619 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2621 * old buffer is freed by caller, unless
2622 * it is still in our own heap. (in that case
2623 * we free it, correcting the buggy caller.)
2626 HeapFree(es
->heap
, 0, es
->text
);
2629 es
->hloc32
= (HLOCAL
)NULL
;
2631 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2632 EDIT_LockBuffer(wnd
, es
);
2634 es
->x_offset
= es
->y_offset
= 0;
2635 es
->selection_start
= es
->selection_end
= 0;
2636 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2637 es
->flags
&= ~EF_MODIFIED
;
2638 es
->flags
&= ~EF_UPDATE
;
2639 EDIT_BuildLineDefs_ML(wnd
, es
);
2640 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2641 EDIT_EM_ScrollCaret(wnd
, es
);
2645 /*********************************************************************
2649 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2650 * However, the windows version is not complied to yet in all of edit.c
2653 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2655 if (es
->style
& ES_MULTILINE
) {
2657 es
->buffer_limit
= min(limit
, BUFLIMIT_MULTI
);
2659 es
->buffer_limit
= BUFLIMIT_MULTI
;
2662 es
->buffer_limit
= min(limit
, BUFLIMIT_SINGLE
);
2664 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2669 /*********************************************************************
2673 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2674 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2675 * of the char's width, according to the new docs.
2678 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2679 INT left
, INT right
)
2681 if (action
& EC_LEFTMARGIN
) {
2682 if (left
!= EC_USEFONTINFO
)
2683 es
->left_margin
= left
;
2685 es
->left_margin
= es
->char_width
/ 3;
2688 if (action
& EC_RIGHTMARGIN
) {
2689 if (right
!= EC_USEFONTINFO
)
2690 es
->right_margin
= right
;
2692 es
->right_margin
= es
->char_width
/ 3;
2694 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2698 /*********************************************************************
2700 * EM_SETPASSWORDCHAR
2703 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2705 if (es
->style
& ES_MULTILINE
)
2708 if (es
->password_char
== c
)
2711 es
->password_char
= c
;
2713 wnd
->dwStyle
|= ES_PASSWORD
;
2714 es
->style
|= ES_PASSWORD
;
2716 wnd
->dwStyle
&= ~ES_PASSWORD
;
2717 es
->style
&= ~ES_PASSWORD
;
2719 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2723 /*********************************************************************
2727 * note: unlike the specs say: the order of start and end
2728 * _is_ preserved in Windows. (i.e. start can be > end)
2729 * In other words: this handler is OK
2732 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2734 UINT old_start
= es
->selection_start
;
2735 UINT old_end
= es
->selection_end
;
2736 UINT len
= lstrlenA(es
->text
);
2739 start
= es
->selection_end
;
2740 end
= es
->selection_end
;
2742 start
= min(start
, len
);
2743 end
= min(end
, len
);
2745 es
->selection_start
= start
;
2746 es
->selection_end
= end
;
2748 es
->flags
|= EF_AFTER_WRAP
;
2750 es
->flags
&= ~EF_AFTER_WRAP
;
2751 if (es
->flags
& EF_FOCUSED
)
2752 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2753 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2754 ORDER_UINT(start
, end
);
2755 ORDER_UINT(end
, old_end
);
2756 ORDER_UINT(start
, old_start
);
2757 ORDER_UINT(old_start
, old_end
);
2758 if (end
!= old_start
)
2762 * ORDER_UINT32(end, old_start);
2763 * EDIT_InvalidateText(wnd, es, start, end);
2764 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2765 * in place of the following if statement.
2767 if (old_start
> end
)
2769 EDIT_InvalidateText(wnd
, es
, start
, end
);
2770 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2774 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2775 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2778 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2782 /*********************************************************************
2787 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2789 if (!(es
->style
& ES_MULTILINE
))
2792 HeapFree(es
->heap
, 0, es
->tabs
);
2793 es
->tabs_count
= count
;
2797 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2798 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2804 /*********************************************************************
2809 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2811 if (!(es
->style
& ES_MULTILINE
))
2814 HeapFree(es
->heap
, 0, es
->tabs
);
2815 es
->tabs_count
= count
;
2820 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2821 for (i
= 0 ; i
< count
; i
++)
2822 es
->tabs
[i
] = *tabs
++;
2828 /*********************************************************************
2830 * EM_SETWORDBREAKPROC
2833 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2835 if (es
->word_break_proc32A
== wbp
)
2838 es
->word_break_proc32A
= wbp
;
2839 es
->word_break_proc16
= NULL
;
2840 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2841 EDIT_BuildLineDefs_ML(wnd
, es
);
2842 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2847 /*********************************************************************
2849 * EM_SETWORDBREAKPROC16
2852 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2854 if (es
->word_break_proc16
== wbp
)
2857 es
->word_break_proc32A
= NULL
;
2858 es
->word_break_proc16
= wbp
;
2859 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2860 EDIT_BuildLineDefs_ML(wnd
, es
);
2861 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2866 /*********************************************************************
2871 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2873 INT ulength
= lstrlenA(es
->undo_text
);
2874 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2876 lstrcpyA(utext
, es
->undo_text
);
2878 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2879 es
->undo_insert_count
, utext
);
2881 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2882 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2883 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2884 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2885 HeapFree(es
->heap
, 0, utext
);
2887 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2888 es
->undo_insert_count
, es
->undo_text
);
2894 /*********************************************************************
2899 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2901 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
2904 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2905 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2908 if (es
->style
& ES_MULTILINE
) {
2909 if (es
->style
& ES_READONLY
) {
2910 EDIT_MoveHome(wnd
, es
, FALSE
);
2911 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2913 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2917 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2918 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2921 if (!(es
->style
& ES_READONLY
) && !control
) {
2922 if (es
->selection_start
!= es
->selection_end
)
2923 EDIT_WM_Clear(wnd
, es
);
2925 /* delete character left of caret */
2926 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
2927 EDIT_MoveBackward(wnd
, es
, TRUE
);
2928 EDIT_WM_Clear(wnd
, es
);
2933 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2937 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2944 /*********************************************************************
2949 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
2951 if (code
|| control
)
2956 EDIT_EM_Undo(wnd
, es
);
2959 EDIT_WM_Cut(wnd
, es
);
2962 EDIT_WM_Copy(wnd
, es
);
2965 EDIT_WM_Paste(wnd
, es
);
2968 EDIT_WM_Clear(wnd
, es
);
2971 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
2972 EDIT_EM_ScrollCaret(wnd
, es
);
2975 ERR("unknown menu item, please report\n");
2981 /*********************************************************************
2985 * Note: the resource files resource/sysres_??.rc cannot define a
2986 * single popup menu. Hence we use a (dummy) menubar
2987 * containing the single popup menu as its first item.
2989 * FIXME: the message identifiers have been chosen arbitrarily,
2990 * hence we use MF_BYPOSITION.
2991 * We might as well use the "real" values (anybody knows ?)
2992 * The menu definition is in resources/sysres_??.rc.
2993 * Once these are OK, we better use MF_BYCOMMAND here
2994 * (as we do in EDIT_WM_Command()).
2997 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
2999 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
3000 HMENU popup
= GetSubMenu(menu
, 0);
3001 UINT start
= es
->selection_start
;
3002 UINT end
= es
->selection_end
;
3004 ORDER_UINT(start
, end
);
3007 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
3009 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3011 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3013 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
3015 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3017 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3019 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3024 /*********************************************************************
3029 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3031 INT s
= es
->selection_start
;
3032 INT e
= es
->selection_end
;
3039 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3040 dst
= GlobalLock(hdst
);
3041 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3043 OpenClipboard(wnd
->hwndSelf
);
3045 SetClipboardData(CF_TEXT
, hdst
);
3050 /*********************************************************************
3055 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3058 * To initialize some final structure members, we call some helper
3059 * functions. However, since the EDITSTATE is not consistent (i.e.
3060 * not fully initialized), we should be very careful which
3061 * functions can be called, and in what order.
3063 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3064 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3066 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3067 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3068 /* if we insert text to the editline, the text scrolls out
3069 * of the window, as the caret is placed after the insert
3070 * pos normally; thus we reset es->selection... to 0 and
3073 es
->selection_start
= es
->selection_end
= 0;
3074 EDIT_EM_ScrollCaret(wnd
, es
);
3080 /*********************************************************************
3085 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3088 while (LocalUnlock(es
->hloc32
)) ;
3089 LocalFree(es
->hloc32
);
3092 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3093 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3095 HeapDestroy(es
->heap
);
3096 HeapFree(GetProcessHeap(), 0, es
);
3097 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3101 /*********************************************************************
3106 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3111 if ( VERSION_AppWinVer() >= 0x40000 &&(
3112 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3113 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3115 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3118 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3120 GetClientRect(wnd
->hwndSelf
, &rc
);
3121 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3122 GetClipBox(dc
, &rc
);
3124 * FIXME: specs say that we should UnrealizeObject() the brush,
3125 * but the specs of UnrealizeObject() say that we shouldn't
3126 * unrealize a stock object. The default brush that
3127 * DefWndProc() returns is ... a stock object.
3129 FillRect(dc
, &rc
, brush
);
3134 /*********************************************************************
3139 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3141 INT len
= lstrlenA(es
->text
);
3144 lstrcpyA(text
, es
->text
);
3151 /*********************************************************************
3155 * 16 bit notepad needs this. Actually it is not _our_ hack,
3156 * it is notepad's. Notepad is sending us scrollbar messages with
3157 * undocumented parameters without us even having a scrollbar ... !?!?
3160 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3163 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3166 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3167 ERR("hacked WM_HSCROLL handler invoked\n");
3168 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3169 ERR(" (this message is only displayed once per edit control)\n");
3170 es
->flags
|= EF_HSCROLL_HACK
;
3176 dx
= -es
->char_width
;
3179 if (es
->x_offset
< es
->text_width
)
3180 dx
= es
->char_width
;
3184 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3187 if (es
->x_offset
< es
->text_width
)
3188 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3195 if (es
->x_offset
< es
->text_width
)
3196 dx
= es
->text_width
- es
->x_offset
;
3199 es
->flags
|= EF_HSCROLL_TRACK
;
3200 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3202 case SB_THUMBPOSITION
:
3203 es
->flags
&= ~EF_HSCROLL_TRACK
;
3204 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3205 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3211 * FIXME : the next two are undocumented !
3212 * Are we doing the right thing ?
3213 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3214 * although it's also a regular control message.
3217 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3219 case EM_LINESCROLL16
:
3224 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3228 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3233 /*********************************************************************
3238 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3243 if (!(es
->style
& ES_MULTILINE
))
3246 if (!(es
->style
& ES_AUTOHSCROLL
))
3249 if (!(es
->style
& WS_HSCROLL
))
3250 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3253 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3257 dx
= -es
->char_width
;
3260 if (es
->x_offset
< es
->text_width
)
3261 dx
= es
->char_width
;
3265 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3268 if (es
->x_offset
< es
->text_width
)
3269 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3276 if (es
->x_offset
< es
->text_width
)
3277 dx
= es
->text_width
- es
->x_offset
;
3280 es
->flags
|= EF_HSCROLL_TRACK
;
3281 dx
= pos
- es
->x_offset
;
3283 case SB_THUMBPOSITION
:
3284 es
->flags
&= ~EF_HSCROLL_TRACK
;
3285 if (!(dx
= pos
- es
->x_offset
)) {
3286 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3287 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3294 ERR("undocumented WM_HSCROLL parameter, please report\n");
3298 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3303 /*********************************************************************
3308 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3312 if (WIDGETS_IsControl(wnd
->parent
, BIC32_COMBO
) &&
3313 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3314 HWND hCombo
= wnd
->parent
->hwndSelf
;
3315 BOOL bUIFlip
= TRUE
;
3317 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3318 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3321 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3323 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3324 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3328 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3330 /* make sure ComboLBox pops up */
3331 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3332 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3333 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3336 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3337 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3339 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3340 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3342 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3351 /*********************************************************************
3355 * Handling of special keys that don't produce a WM_CHAR
3356 * (i.e. non-printable keys) & Backspace & Delete
3359 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3364 if (GetKeyState(VK_MENU
) & 0x8000)
3367 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3368 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3373 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3379 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3380 EDIT_MoveUp_ML(wnd
, es
, shift
);
3383 EDIT_MoveWordBackward(wnd
, es
, shift
);
3385 EDIT_MoveBackward(wnd
, es
, shift
);
3388 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3392 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3393 EDIT_MoveDown_ML(wnd
, es
, shift
);
3395 EDIT_MoveWordForward(wnd
, es
, shift
);
3397 EDIT_MoveForward(wnd
, es
, shift
);
3400 EDIT_MoveHome(wnd
, es
, shift
);
3403 EDIT_MoveEnd(wnd
, es
, shift
);
3406 if (es
->style
& ES_MULTILINE
)
3407 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3410 if (es
->style
& ES_MULTILINE
)
3411 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3414 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3415 if (es
->selection_start
!= es
->selection_end
) {
3417 EDIT_WM_Cut(wnd
, es
);
3419 EDIT_WM_Clear(wnd
, es
);
3422 /* delete character left of caret */
3423 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3424 EDIT_MoveBackward(wnd
, es
, TRUE
);
3425 EDIT_WM_Clear(wnd
, es
);
3426 } else if (control
) {
3427 /* delete to end of line */
3428 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3429 EDIT_MoveEnd(wnd
, es
, TRUE
);
3430 EDIT_WM_Clear(wnd
, es
);
3432 /* delete character right of caret */
3433 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3434 EDIT_MoveForward(wnd
, es
, TRUE
);
3435 EDIT_WM_Clear(wnd
, es
);
3442 if (!(es
->style
& ES_READONLY
))
3443 EDIT_WM_Paste(wnd
, es
);
3445 EDIT_WM_Copy(wnd
, es
);
3448 /* If the edit doesn't want the return send a message to the default object */
3449 if(!(es
->style
& ES_WANTRETURN
))
3451 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
3452 DWORD dw
= SendMessage16( hwndParent
, DM_GETDEFID
, 0, 0 );
3453 if (HIWORD(dw
) == DC_HASDEFID
)
3455 SendMessageA( hwndParent
, WM_COMMAND
,
3456 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3457 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3466 /*********************************************************************
3471 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3473 es
->flags
&= ~EF_FOCUSED
;
3475 if(!(es
->style
& ES_NOHIDESEL
))
3476 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3477 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3482 /*********************************************************************
3486 * The caret position has been set on the WM_LBUTTONDOWN message
3489 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3492 INT e
= es
->selection_end
;
3497 if (!(es
->flags
& EF_FOCUSED
))
3500 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3501 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3502 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3503 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3504 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3505 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3506 EDIT_EM_ScrollCaret(wnd
, es
);
3511 /*********************************************************************
3516 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3521 if (!(es
->flags
& EF_FOCUSED
))
3524 es
->bCaptureState
= TRUE
;
3525 SetCapture(wnd
->hwndSelf
);
3526 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3527 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3528 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3529 EDIT_EM_ScrollCaret(wnd
, es
);
3530 es
->region_posx
= es
->region_posy
= 0;
3531 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3536 /*********************************************************************
3541 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3543 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3544 KillTimer(wnd
->hwndSelf
, 0);
3547 es
->bCaptureState
= FALSE
;
3552 /*********************************************************************
3557 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3563 if (GetCapture() != wnd
->hwndSelf
)
3567 * FIXME: gotta do some scrolling if outside client
3568 * area. Maybe reset the timer ?
3571 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3572 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3573 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3574 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3575 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3580 /*********************************************************************
3585 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3589 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3591 *(EDITSTATE
**)wnd
->wExtra
= es
;
3594 * Note: since the EDITSTATE has not been fully initialized yet,
3595 * we can't use any API calls that may send
3596 * WM_XXX messages before WM_NCCREATE is completed.
3599 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3601 es
->style
= cs
->style
;
3603 es
->bEnableState
= !(cs
->style
& WS_DISABLED
);
3606 * In Win95 look and feel, the WS_BORDER style is replaced by the
3607 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3608 * control a non client area.
3610 if (TWEAK_WineLook
!= WIN31_LOOK
)
3612 if (es
->style
& WS_BORDER
)
3614 es
->style
&= ~WS_BORDER
;
3615 wnd
->dwStyle
&= ~WS_BORDER
;
3616 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3621 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3622 wnd
->dwStyle
&= ~WS_BORDER
;
3625 if (es
->style
& ES_MULTILINE
) {
3626 es
->buffer_size
= BUFSTART_MULTI
;
3627 es
->buffer_limit
= BUFLIMIT_MULTI
;
3628 if (es
->style
& WS_VSCROLL
)
3629 es
->style
|= ES_AUTOVSCROLL
;
3630 if (es
->style
& WS_HSCROLL
)
3631 es
->style
|= ES_AUTOHSCROLL
;
3632 es
->style
&= ~ES_PASSWORD
;
3633 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3634 if (es
->style
& ES_RIGHT
)
3635 es
->style
&= ~ES_CENTER
;
3636 es
->style
&= ~WS_HSCROLL
;
3637 es
->style
&= ~ES_AUTOHSCROLL
;
3640 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3641 es
->style
|= ES_AUTOVSCROLL
;
3643 es
->buffer_size
= BUFSTART_SINGLE
;
3644 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3645 es
->style
&= ~ES_CENTER
;
3646 es
->style
&= ~ES_RIGHT
;
3647 es
->style
&= ~WS_HSCROLL
;
3648 es
->style
&= ~WS_VSCROLL
;
3649 es
->style
&= ~ES_AUTOVSCROLL
;
3650 es
->style
&= ~ES_WANTRETURN
;
3651 if (es
->style
& ES_UPPERCASE
) {
3652 es
->style
&= ~ES_LOWERCASE
;
3653 es
->style
&= ~ES_NUMBER
;
3654 } else if (es
->style
& ES_LOWERCASE
)
3655 es
->style
&= ~ES_NUMBER
;
3656 if (es
->style
& ES_PASSWORD
)
3657 es
->password_char
= '*';
3659 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3660 es
->style
|= ES_AUTOHSCROLL
;
3662 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3664 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3665 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3667 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3669 if (es
->style
& ES_MULTILINE
)
3670 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3677 /*********************************************************************
3682 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3691 BOOL rev
= es
->bEnableState
&&
3692 ((es
->flags
& EF_FOCUSED
) ||
3693 (es
->style
& ES_NOHIDESEL
));
3695 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3698 if(es
->style
& WS_BORDER
) {
3699 GetClientRect(wnd
->hwndSelf
, &rc
);
3700 if(es
->style
& ES_MULTILINE
) {
3701 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3702 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3704 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3706 IntersectClipRect(dc
, es
->format_rect
.left
,
3707 es
->format_rect
.top
,
3708 es
->format_rect
.right
,
3709 es
->format_rect
.bottom
);
3710 if (es
->style
& ES_MULTILINE
) {
3711 GetClientRect(wnd
->hwndSelf
, &rc
);
3712 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3715 old_font
= SelectObject(dc
, es
->font
);
3716 if ( VERSION_AppWinVer() >= 0x40000 &&(
3717 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3718 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3720 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3722 if (!es
->bEnableState
)
3723 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3724 GetClipBox(dc
, &rcRgn
);
3725 if (es
->style
& ES_MULTILINE
) {
3726 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3727 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3728 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3729 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3730 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3733 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3734 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3735 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3738 SelectObject(dc
, old_font
);
3739 if (es
->flags
& EF_FOCUSED
)
3740 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3741 es
->flags
& EF_AFTER_WRAP
);
3743 EndPaint(wnd
->hwndSelf
, &ps
);
3744 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3745 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3747 si
.cbSize
= sizeof(SCROLLINFO
);
3748 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3750 si
.nMax
= es
->line_count
+ vlc
- 2;
3752 si
.nPos
= es
->y_offset
;
3753 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3755 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3757 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3758 si
.cbSize
= sizeof(SCROLLINFO
);
3759 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3761 si
.nMax
= es
->text_width
+ fw
- 1;
3763 si
.nPos
= es
->x_offset
;
3764 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3767 if (es
->flags
& EF_UPDATE
) {
3768 es
->flags
&= ~EF_UPDATE
;
3769 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3774 /*********************************************************************
3779 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3784 OpenClipboard(wnd
->hwndSelf
);
3785 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3786 src
= (LPSTR
)GlobalLock(hsrc
);
3787 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3794 /*********************************************************************
3799 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3801 es
->flags
|= EF_FOCUSED
;
3802 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3803 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3804 es
->flags
& EF_AFTER_WRAP
);
3805 if(!(es
->style
& ES_NOHIDESEL
))
3806 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3807 ShowCaret(wnd
->hwndSelf
);
3808 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3812 /*********************************************************************
3816 * With Win95 look the margins are set to default font value unless
3817 * the system font (font == 0) is being set, in which case they are left
3821 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3829 dc
= GetDC(wnd
->hwndSelf
);
3831 old_font
= SelectObject(dc
, font
);
3832 GetTextMetricsA(dc
, &tm
);
3833 es
->line_height
= tm
.tmHeight
;
3834 es
->char_width
= tm
.tmAveCharWidth
;
3836 SelectObject(dc
, old_font
);
3837 ReleaseDC(wnd
->hwndSelf
, dc
);
3838 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3839 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3840 EC_USEFONTINFO
, EC_USEFONTINFO
);
3842 /* Force the recalculation of the format rect for each font change */
3843 GetClientRect(wnd
->hwndSelf
, &r
);
3844 EDIT_SetRectNP(wnd
, es
, &r
);
3846 if (es
->style
& ES_MULTILINE
)
3847 EDIT_BuildLineDefs_ML(wnd
, es
);
3850 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3851 if (es
->flags
& EF_FOCUSED
) {
3853 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3854 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3855 es
->flags
& EF_AFTER_WRAP
);
3856 ShowCaret(wnd
->hwndSelf
);
3861 /*********************************************************************
3866 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3867 * The modified flag is reset. No notifications are sent.
3869 * For single-line controls, reception of WM_SETTEXT triggers:
3870 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3873 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3875 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3877 TRACE("\t'%s'\n", text
);
3878 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3880 TRACE("\t<NULL>\n");
3881 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3884 if (es
->style
& ES_MULTILINE
) {
3885 es
->flags
&= ~EF_UPDATE
;
3887 es
->flags
|= EF_UPDATE
;
3889 es
->flags
&= ~EF_MODIFIED
;
3890 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3891 EDIT_EM_ScrollCaret(wnd
, es
);
3893 if (es
->flags
& EF_UPDATE
)
3894 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3898 /*********************************************************************
3903 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3905 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3907 SetRect(&rc
, 0, 0, width
, height
);
3908 EDIT_SetRectNP(wnd
, es
, &rc
);
3909 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3914 /*********************************************************************
3919 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3921 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3922 if (EDIT_EM_CanUndo(wnd
, es
))
3923 EDIT_EM_Undo(wnd
, es
);
3925 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3926 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3928 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
3932 /*********************************************************************
3937 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
3939 if (es
->region_posx
< 0) {
3940 EDIT_MoveBackward(wnd
, es
, TRUE
);
3941 } else if (es
->region_posx
> 0) {
3942 EDIT_MoveForward(wnd
, es
, TRUE
);
3945 * FIXME: gotta do some vertical scrolling here, like
3946 * EDIT_EM_LineScroll(wnd, 0, 1);
3951 /*********************************************************************
3955 * 16 bit notepad needs this. Actually it is not _our_ hack,
3956 * it is notepad's. Notepad is sending us scrollbar messages with
3957 * undocumented parameters without us even having a scrollbar ... !?!?
3960 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3965 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3966 ERR("hacked WM_VSCROLL handler invoked\n");
3967 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3968 ERR(" (this message is only displayed once per edit control)\n");
3969 es
->flags
|= EF_VSCROLL_HACK
;
3977 EDIT_EM_Scroll(wnd
, es
, action
);
3983 dy
= es
->line_count
- 1 - es
->y_offset
;
3986 es
->flags
|= EF_VSCROLL_TRACK
;
3987 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
3989 case SB_THUMBPOSITION
:
3990 es
->flags
&= ~EF_VSCROLL_TRACK
;
3991 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
3992 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3998 * FIXME : the next two are undocumented !
3999 * Are we doing the right thing ?
4000 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4001 * although it's also a regular control message.
4004 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
4006 case EM_LINESCROLL16
:
4011 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4015 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4020 /*********************************************************************
4025 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4029 if (!(es
->style
& ES_MULTILINE
))
4032 if (!(es
->style
& ES_AUTOVSCROLL
))
4035 if (!(es
->style
& WS_VSCROLL
))
4036 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4044 EDIT_EM_Scroll(wnd
, es
, action
);
4051 dy
= es
->line_count
- 1 - es
->y_offset
;
4054 es
->flags
|= EF_VSCROLL_TRACK
;
4055 dy
= pos
- es
->y_offset
;
4057 case SB_THUMBPOSITION
:
4058 es
->flags
&= ~EF_VSCROLL_TRACK
;
4059 if (!(dy
= pos
- es
->y_offset
)) {
4060 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4061 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4068 ERR("undocumented WM_VSCROLL action %d, please report\n",
4073 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);