4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
11 * please read EDIT.TODO (and update it when you change things)
19 #include "wine/winbase16.h"
23 #include "debugtools.h"
26 #include "winversion.h"
28 DEFAULT_DEBUG_CHANNEL(edit
)
29 DECLARE_DEBUG_CHANNEL(combo
)
30 DECLARE_DEBUG_CHANNEL(relay
)
32 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
33 FIXME: BTW, new specs say 65535 (do you dare ???) */
34 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
35 #define BUFSTART_MULTI 1024 /* starting size */
36 #define BUFSTART_SINGLE 256 /* starting size */
37 #define GROWLENGTH 64 /* buffers grow by this much */
38 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
41 * extra flags for EDITSTATE.flags field
43 #define EF_MODIFIED 0x0001 /* text has been modified */
44 #define EF_FOCUSED 0x0002 /* we have input focus */
45 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
46 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
47 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
48 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
49 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
50 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
51 wrapped line, instead of in front of the next character */
52 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
56 END_0
= 0, /* line ends with terminating '\0' character */
57 END_WRAP
, /* line is wrapped */
58 END_HARD
, /* line ends with a hard return '\r\n' */
59 END_SOFT
/* line ends with a soft return '\r\r\n' */
62 typedef struct tagLINEDEF
{
63 INT length
; /* bruto length of a line in bytes */
64 INT net_length
; /* netto length of a line in visible characters */
66 INT width
; /* width of the line in pixels */
67 struct tagLINEDEF
*next
;
72 HANDLE heap
; /* our own heap */
73 LPSTR text
; /* the actual contents of the control */
74 INT buffer_size
; /* the size of the buffer */
75 INT buffer_limit
; /* the maximum size to which the buffer may grow */
76 HFONT font
; /* NULL means standard system font */
77 INT x_offset
; /* scroll offset for multi lines this is in pixels
78 for single lines it's in characters */
79 INT line_height
; /* height of a screen line in pixels */
80 INT char_width
; /* average character width in pixels */
81 DWORD style
; /* sane version of wnd->dwStyle */
82 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
83 INT undo_insert_count
; /* number of characters inserted in sequence */
84 INT undo_position
; /* character index of the insertion and deletion */
85 LPSTR undo_text
; /* deleted text */
86 INT undo_buffer_size
; /* size of the deleted text buffer */
87 INT selection_start
; /* == selection_end if no selection */
88 INT selection_end
; /* == current caret position */
89 CHAR password_char
; /* == 0 if no password char, and for multi line controls */
90 INT left_margin
; /* in pixels */
91 INT right_margin
; /* in pixels */
93 INT region_posx
; /* Position of cursor relative to region: */
94 INT region_posy
; /* -1: to left, 0: within, 1: to right */
95 EDITWORDBREAKPROC16 word_break_proc16
;
96 EDITWORDBREAKPROCA word_break_proc32A
;
97 INT line_count
; /* number of lines */
98 INT y_offset
; /* scroll offset in number of lines */
99 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
100 BOOL bEnableState
; /* flag keeping the enable state */
102 * only for multi line controls
104 INT lock_count
; /* amount of re-entries in the EditWndProc */
107 INT text_width
; /* width of the widest line in pixels */
108 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
109 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
110 HLOCAL hloc32
; /* for controls receiving EM_GETHANDLE */
114 #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
115 #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
117 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
118 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
120 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
121 do {TRACE("notification " str " sent to hwnd=%08x\n", \
122 (UINT)(hwnd));} while(0)
124 /* used for disabled or read-only edit control */
125 #define EDIT_SEND_CTLCOLORSTATIC(wnd,hdc) \
126 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLORSTATIC, \
127 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
128 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
129 (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
130 (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf))
131 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
132 do {DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str); \
133 SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \
134 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
135 (LPARAM)(wnd)->hwndSelf);} while(0)
136 #define DPRINTF_EDIT_MSG16(str) \
138 "16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
139 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
140 #define DPRINTF_EDIT_MSG32(str) \
142 "32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
143 (UINT)hwnd, (UINT)wParam, (UINT)lParam)
145 /*********************************************************************
152 * These functions have trivial implementations
153 * We still like to call them internally
154 * "static inline" makes them more like macro's
156 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
157 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
158 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
159 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
162 * Helper functions only valid for one type of control
164 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
165 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
166 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
167 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
168 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
169 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
171 * Helper functions valid for both single line _and_ multi line controls
173 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
);
174 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
);
175 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
);
176 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
);
177 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
);
178 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
179 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
180 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
);
181 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
182 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
183 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
184 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
185 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
186 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
);
187 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT line
, BOOL rev
);
188 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC hdc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
);
189 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
, BOOL after_wrap
);
190 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT lprc
);
191 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
);
192 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
);
194 * EM_XXX message handlers
196 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
);
197 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
);
198 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
199 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
200 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
);
201 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
);
202 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
203 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
);
204 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
);
205 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
);
206 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
);
207 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
);
208 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
);
209 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
);
210 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
211 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
);
212 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
213 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
);
214 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
, INT left
, INT right
);
215 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
216 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
);
217 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
);
218 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
);
219 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
);
220 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
221 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
223 * WM_XXX message handlers
225 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
226 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND conrtol
);
227 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
);
228 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
229 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
);
230 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
231 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
);
232 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
);
233 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
234 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
235 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
);
236 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
237 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
238 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
239 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
);
240 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
);
241 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
);
242 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
243 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
);
244 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
);
245 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
246 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
);
247 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
);
248 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
);
249 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
);
252 /*********************************************************************
257 static inline BOOL
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
259 return (es
->undo_insert_count
|| lstrlenA(es
->undo_text
));
263 /*********************************************************************
268 static inline void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
270 es
->undo_insert_count
= 0;
271 *es
->undo_text
= '\0';
275 /*********************************************************************
280 static inline void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
282 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
286 /*********************************************************************
291 static inline void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
293 EDIT_WM_Copy(wnd
, es
);
294 EDIT_WM_Clear(wnd
, es
);
298 /*********************************************************************
302 * The messages are in the order of the actual integer values
303 * (which can be found in include/windows.h)
304 * Whereever possible the 16 bit versions are converted to
305 * the 32 bit ones, so that we can 'fall through' to the
306 * helper functions. These are mostly 32 bit (with a few
307 * exceptions, clearly indicated by a '16' extension to their
311 LRESULT WINAPI
EditWndProc( HWND hwnd
, UINT msg
,
312 WPARAM wParam
, LPARAM lParam
)
314 WND
*wnd
= WIN_FindWndPtr(hwnd
);
315 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
320 DPRINTF_EDIT_MSG32("WM_DESTROY");
321 EDIT_WM_Destroy(wnd
, es
);
326 DPRINTF_EDIT_MSG32("WM_NCCREATE");
327 result
= EDIT_WM_NCCreate(wnd
, (LPCREATESTRUCTA
)lParam
);
333 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
338 EDIT_LockBuffer(wnd
, es
);
341 DPRINTF_EDIT_MSG16("EM_GETSEL");
346 DPRINTF_EDIT_MSG32("EM_GETSEL");
347 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT
)wParam
, (LPUINT
)lParam
);
351 DPRINTF_EDIT_MSG16("EM_SETSEL");
352 if (SLOWORD(lParam
) == -1)
353 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
355 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
357 EDIT_EM_ScrollCaret(wnd
, es
);
361 DPRINTF_EDIT_MSG32("EM_SETSEL");
362 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
363 EDIT_EM_ScrollCaret(wnd
, es
);
368 DPRINTF_EDIT_MSG16("EM_GETRECT");
370 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
373 DPRINTF_EDIT_MSG32("EM_GETRECT");
375 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
379 DPRINTF_EDIT_MSG16("EM_SETRECT");
380 if ((es
->style
& ES_MULTILINE
) && lParam
) {
382 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
383 EDIT_SetRectNP(wnd
, es
, &rc
);
384 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
388 DPRINTF_EDIT_MSG32("EM_SETRECT");
389 if ((es
->style
& ES_MULTILINE
) && lParam
) {
390 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
391 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
396 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
397 if ((es
->style
& ES_MULTILINE
) && lParam
) {
399 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
400 EDIT_SetRectNP(wnd
, es
, &rc
);
404 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
405 if ((es
->style
& ES_MULTILINE
) && lParam
)
406 EDIT_SetRectNP(wnd
, es
, (LPRECT
)lParam
);
410 DPRINTF_EDIT_MSG16("EM_SCROLL");
413 DPRINTF_EDIT_MSG32("EM_SCROLL");
414 result
= EDIT_EM_Scroll(wnd
, es
, (INT
)wParam
);
417 case EM_LINESCROLL16
:
418 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
419 wParam
= (WPARAM
)(INT
)SHIWORD(lParam
);
420 lParam
= (LPARAM
)(INT
)SLOWORD(lParam
);
423 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
424 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT
)wParam
, (INT
)lParam
);
427 case EM_SCROLLCARET16
:
428 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
431 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
432 EDIT_EM_ScrollCaret(wnd
, es
);
437 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
440 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
441 result
= ((es
->flags
& EF_MODIFIED
) != 0);
445 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
448 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
450 es
->flags
|= EF_MODIFIED
;
452 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
455 case EM_GETLINECOUNT16
:
456 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
458 case EM_GETLINECOUNT
:
459 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
460 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
464 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
465 if ((INT16
)wParam
== -1)
469 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
470 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT
)wParam
);
474 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
475 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
478 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
479 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL
)wParam
);
483 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
484 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
487 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
488 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
492 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
495 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
496 result
= EDIT_EM_GetThumb(wnd
, es
);
499 /* messages 0x00bf and 0x00c0 missing from specs */
502 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
505 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
506 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
510 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
513 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
514 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
517 case EM_LINELENGTH16
:
518 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
521 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
522 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT
)wParam
);
525 case EM_REPLACESEL16
:
526 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
527 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
530 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
531 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL
)wParam
, (LPCSTR
)lParam
);
535 /* message 0x00c3 missing from specs */
538 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
541 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
542 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
546 DPRINTF_EDIT_MSG16("EM_GETLINE");
547 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
550 DPRINTF_EDIT_MSG32("EM_GETLINE");
551 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
555 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
557 case EM_SETLIMITTEXT
:
558 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
559 EDIT_EM_SetLimitText(wnd
, es
, (INT
)wParam
);
563 DPRINTF_EDIT_MSG16("EM_CANUNDO");
566 DPRINTF_EDIT_MSG32("EM_CANUNDO");
567 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
571 DPRINTF_EDIT_MSG16("EM_UNDO");
576 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
577 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
581 DPRINTF_EDIT_MSG16("EM_FMTLINES");
584 DPRINTF_EDIT_MSG32("EM_FMTLINES");
585 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL
)wParam
);
588 case EM_LINEFROMCHAR16
:
589 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
591 case EM_LINEFROMCHAR
:
592 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
593 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT
)wParam
);
596 /* message 0x00ca missing from specs */
599 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
602 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
603 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
606 case EM_SETTABSTOPS16
:
607 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
608 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
611 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
612 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT
)wParam
, (LPINT
)lParam
);
615 case EM_SETPASSWORDCHAR16
:
616 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
618 case EM_SETPASSWORDCHAR
:
619 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
620 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
623 case EM_EMPTYUNDOBUFFER16
:
624 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
626 case EM_EMPTYUNDOBUFFER
:
627 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
628 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
631 case EM_GETFIRSTVISIBLELINE16
:
632 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
633 result
= es
->y_offset
;
635 case EM_GETFIRSTVISIBLELINE
:
636 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
637 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
640 case EM_SETREADONLY16
:
641 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
644 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
646 wnd
->dwStyle
|= ES_READONLY
;
647 es
->style
|= ES_READONLY
;
649 wnd
->dwStyle
&= ~ES_READONLY
;
650 es
->style
&= ~ES_READONLY
;
655 case EM_SETWORDBREAKPROC16
:
656 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
657 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
659 case EM_SETWORDBREAKPROC
:
660 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
661 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROCA
)lParam
);
664 case EM_GETWORDBREAKPROC16
:
665 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
666 result
= (LRESULT
)es
->word_break_proc16
;
668 case EM_GETWORDBREAKPROC
:
669 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
670 result
= (LRESULT
)es
->word_break_proc32A
;
673 case EM_GETPASSWORDCHAR16
:
674 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
676 case EM_GETPASSWORDCHAR
:
677 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
678 result
= es
->password_char
;
681 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
684 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
685 EDIT_EM_SetMargins(wnd
, es
, (INT
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
689 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
690 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
693 case EM_GETLIMITTEXT
:
694 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
695 result
= es
->buffer_limit
;
699 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
700 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT
)wParam
, FALSE
);
704 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
705 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
709 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
710 result
= (es
->style
& ES_MULTILINE
) ?
711 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
712 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
716 DPRINTF_EDIT_MSG32("WM_CHAR");
717 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
721 DPRINTF_EDIT_MSG32("WM_CLEAR");
722 EDIT_WM_Clear(wnd
, es
);
726 DPRINTF_EDIT_MSG32("WM_COMMAND");
727 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
731 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
732 EDIT_WM_ContextMenu(wnd
, es
, (HWND
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
736 DPRINTF_EDIT_MSG32("WM_COPY");
737 EDIT_WM_Copy(wnd
, es
);
741 DPRINTF_EDIT_MSG32("WM_CREATE");
742 result
= EDIT_WM_Create(wnd
, es
, (LPCREATESTRUCTA
)lParam
);
746 DPRINTF_EDIT_MSG32("WM_CUT");
747 EDIT_WM_Cut(wnd
, es
);
751 DPRINTF_EDIT_MSG32("WM_ENABLE");
752 es
->bEnableState
= (BOOL
) wParam
;
753 InvalidateRect(hwnd
, NULL
, TRUE
);
757 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
758 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC
)wParam
);
762 DPRINTF_EDIT_MSG32("WM_GETFONT");
763 result
= (LRESULT
)es
->font
;
767 DPRINTF_EDIT_MSG32("WM_GETTEXT");
768 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT
)wParam
, (LPSTR
)lParam
);
771 case WM_GETTEXTLENGTH
:
772 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
773 result
= lstrlenA(es
->text
);
777 DPRINTF_EDIT_MSG32("WM_HSCROLL");
778 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)lParam
);
782 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
783 result
= EDIT_WM_KeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
787 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
788 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND
)wParam
);
791 case WM_LBUTTONDBLCLK
:
792 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
793 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
797 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
798 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
802 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
803 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
806 case WM_MOUSEACTIVATE
:
808 * FIXME: maybe DefWindowProc() screws up, but it seems that
809 * modalless dialog boxes need this. If we don't do this, the focus
810 * will _not_ be set by DefWindowProc() for edit controls in a
811 * modalless dialog box ???
813 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
814 SetFocus(wnd
->hwndSelf
);
815 result
= MA_ACTIVATE
;
820 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
822 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
826 DPRINTF_EDIT_MSG32("WM_PAINT");
827 EDIT_WM_Paint(wnd
, es
, wParam
);
831 DPRINTF_EDIT_MSG32("WM_PASTE");
832 EDIT_WM_Paste(wnd
, es
);
836 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
837 EDIT_WM_SetFocus(wnd
, es
, (HWND
)wParam
);
841 DPRINTF_EDIT_MSG32("WM_SETFONT");
842 EDIT_WM_SetFont(wnd
, es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
846 DPRINTF_EDIT_MSG32("WM_SETTEXT");
847 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
852 DPRINTF_EDIT_MSG32("WM_SIZE");
853 EDIT_WM_Size(wnd
, es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
857 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
858 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT
)wParam
, (DWORD
)lParam
);
862 DPRINTF_EDIT_MSG32("WM_TIMER");
863 EDIT_WM_Timer(wnd
, es
, (INT
)wParam
, (TIMERPROC
)lParam
);
867 DPRINTF_EDIT_MSG32("WM_VSCROLL");
868 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND
)(lParam
));
872 result
= DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
875 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
877 WIN_ReleaseWndPtr(wnd
);
883 /*********************************************************************
885 * EDIT_BuildLineDefs_ML
887 * Build linked list of text lines.
888 * Lines can end with '\0' (last line), a character (if it is wrapped),
889 * a soft return '\r\r\n' or a hard return '\r\n'
892 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
898 LINEDEF
*current_def
;
899 LINEDEF
**previous_next
;
901 current_def
= es
->first_line_def
;
903 LINEDEF
*next_def
= current_def
->next
;
904 HeapFree(es
->heap
, 0, current_def
);
905 current_def
= next_def
;
906 } while (current_def
);
910 dc
= GetDC(wnd
->hwndSelf
);
912 old_font
= SelectObject(dc
, es
->font
);
914 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
916 previous_next
= &es
->first_line_def
;
918 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
919 current_def
->next
= NULL
;
922 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
927 current_def
->ending
= END_0
;
928 current_def
->net_length
= lstrlenA(start
);
929 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
930 current_def
->ending
= END_SOFT
;
931 current_def
->net_length
= cp
- start
- 1;
933 current_def
->ending
= END_HARD
;
934 current_def
->net_length
= cp
- start
;
936 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
937 start
, current_def
->net_length
,
938 es
->tabs_count
, es
->tabs
));
939 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
940 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
945 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
946 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
947 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
948 start
, next
, es
->tabs_count
, es
->tabs
));
949 } while (current_def
->width
<= fw
);
955 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
,
956 start
, next
, es
->tabs_count
, es
->tabs
));
957 } while (current_def
->width
<= fw
);
961 current_def
->net_length
= prev
;
962 current_def
->ending
= END_WRAP
;
963 current_def
->width
= (INT
)LOWORD(GetTabbedTextExtentA(dc
, start
,
964 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
966 switch (current_def
->ending
) {
968 current_def
->length
= current_def
->net_length
+ 3;
971 current_def
->length
= current_def
->net_length
+ 2;
975 current_def
->length
= current_def
->net_length
;
978 es
->text_width
= MAX(es
->text_width
, current_def
->width
);
979 start
+= current_def
->length
;
980 *previous_next
= current_def
;
981 previous_next
= ¤t_def
->next
;
983 } while (current_def
->ending
!= END_0
);
985 SelectObject(dc
, old_font
);
986 ReleaseDC(wnd
->hwndSelf
, dc
);
990 /*********************************************************************
992 * EDIT_CallWordBreakProc
994 * Call appropriate WordBreakProc (internal or external).
996 * Note: The "start" argument should always be an index refering
997 * to es->text. The actual wordbreak proc might be
998 * 16 bit, so we can't always pass any 32 bit LPSTR.
999 * Hence we assume that es->text is the buffer that holds
1000 * the string under examination (we can decide this for ourselves).
1003 static INT
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
1005 if (es
->word_break_proc16
) {
1006 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
1007 SEGPTR segptr
= LocalLock16(hloc16
);
1008 INT ret
= (INT
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
1009 segptr
+ start
, index
, count
, action
);
1010 LocalUnlock16(hloc16
);
1013 else if (es
->word_break_proc32A
)
1015 TRACE_(relay
)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
1016 es
->word_break_proc32A
, es
->text
+ start
, index
,
1018 return (INT
)es
->word_break_proc32A( es
->text
+ start
, index
,
1022 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1026 /*********************************************************************
1030 * Beware: This is not the function called on EM_CHARFROMPOS
1031 * The position _can_ be outside the formatting / client
1033 * The return value is only the character index
1036 static INT
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
1042 if (es
->style
& ES_MULTILINE
) {
1043 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1045 LINEDEF
*line_def
= es
->first_line_def
;
1047 while ((line
> 0) && line_def
->next
) {
1048 line_index
+= line_def
->length
;
1049 line_def
= line_def
->next
;
1052 x
+= es
->x_offset
- es
->format_rect
.left
;
1053 if (x
>= line_def
->width
) {
1055 *after_wrap
= (line_def
->ending
== END_WRAP
);
1056 return line_index
+ line_def
->net_length
;
1060 *after_wrap
= FALSE
;
1063 dc
= GetDC(wnd
->hwndSelf
);
1065 old_font
= SelectObject(dc
, es
->font
);
1066 low
= line_index
+ 1;
1067 high
= line_index
+ line_def
->net_length
+ 1;
1068 while (low
< high
- 1)
1070 INT mid
= (low
+ high
) / 2;
1071 if (LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1077 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1078 (line_def
->ending
== END_WRAP
));
1083 *after_wrap
= FALSE
;
1084 x
-= es
->format_rect
.left
;
1086 return es
->x_offset
;
1087 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1088 dc
= GetDC(wnd
->hwndSelf
);
1090 old_font
= SelectObject(dc
, es
->font
);
1094 INT high
= es
->x_offset
;
1095 while (low
< high
- 1)
1097 INT mid
= (low
+ high
) / 2;
1098 GetTextExtentPoint32A( dc
, text
+ mid
,
1099 es
->x_offset
- mid
, &size
);
1100 if (size
.cx
> -x
) low
= mid
;
1107 INT low
= es
->x_offset
;
1108 INT high
= lstrlenA(es
->text
) + 1;
1109 while (low
< high
- 1)
1111 INT mid
= (low
+ high
) / 2;
1112 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1113 mid
- es
->x_offset
, &size
);
1114 if (size
.cx
> x
) high
= mid
;
1119 if (es
->style
& ES_PASSWORD
)
1120 HeapFree(es
->heap
, 0 ,text
);
1123 SelectObject(dc
, old_font
);
1124 ReleaseDC(wnd
->hwndSelf
, dc
);
1129 /*********************************************************************
1133 * adjusts the point to be within the formatting rectangle
1134 * (so CharFromPos returns the nearest _visible_ character)
1137 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT x
, LPINT y
)
1139 *x
= MIN(MAX(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1140 *y
= MIN(MAX(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1144 /*********************************************************************
1148 * Calculates the bounding rectangle for a line from a starting
1149 * column to an ending column.
1152 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1154 INT line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1156 if (es
->style
& ES_MULTILINE
)
1157 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1159 rc
->top
= es
->format_rect
.top
;
1160 rc
->bottom
= rc
->top
+ es
->line_height
;
1161 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1162 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1166 /*********************************************************************
1168 * EDIT_GetPasswordPointer_SL
1170 * note: caller should free the (optionally) allocated buffer
1173 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1175 if (es
->style
& ES_PASSWORD
) {
1176 INT len
= lstrlenA(es
->text
);
1177 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1178 RtlFillMemory(text
, len
, es
->password_char
);
1186 /*********************************************************************
1190 * This acts as a LOCAL_Lock(), but it locks only once. This way
1191 * you can call it whenever you like, without unlocking.
1194 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1197 ERR("no EDITSTATE ... please report\n");
1200 if (!(es
->style
& ES_MULTILINE
))
1204 es
->text
= LocalLock(es
->hloc32
);
1205 else if (es
->hloc16
)
1206 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1208 ERR("no buffer ... please report\n");
1216 /*********************************************************************
1218 * EDIT_SL_InvalidateText
1220 * Called from EDIT_InvalidateText().
1221 * Does the job for single-line controls only.
1224 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1229 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1230 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1231 InvalidateRect(wnd
->hwndSelf
, &rc
, FALSE
);
1235 /*********************************************************************
1237 * EDIT_ML_InvalidateText
1239 * Called from EDIT_InvalidateText().
1240 * Does the job for multi-line controls only.
1243 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1245 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1246 INT sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1247 INT el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1256 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1259 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1260 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1261 if (sl
< es
->y_offset
) {
1265 if (el
> es
->y_offset
+ vlc
) {
1266 el
= es
->y_offset
+ vlc
;
1267 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1269 GetClientRect(wnd
->hwndSelf
, &rc1
);
1270 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1272 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1273 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1274 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1276 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1277 EDIT_EM_LineLength(wnd
, es
,
1278 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1280 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1281 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1282 for (l
= sl
+ 1 ; l
< el
; l
++) {
1283 EDIT_GetLineRect(wnd
, es
, l
, 0,
1284 EDIT_EM_LineLength(wnd
, es
,
1285 EDIT_EM_LineIndex(wnd
, es
, l
)),
1287 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1288 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1290 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1291 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1292 InvalidateRect(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1297 /*********************************************************************
1299 * EDIT_InvalidateText
1301 * Invalidate the text from offset start upto, but not including,
1302 * offset end. Useful for (re)painting the selection.
1303 * Regions outside the linewidth are not invalidated.
1304 * end == -1 means end == TextLength.
1305 * start and end need not be ordered.
1308 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT start
, INT end
)
1314 end
= lstrlenA(es
->text
);
1316 ORDER_INT(start
, end
);
1318 if (es
->style
& ES_MULTILINE
)
1319 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1321 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1325 /*********************************************************************
1329 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1332 static BOOL
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1337 if (size
<= es
->buffer_size
)
1339 if (size
> es
->buffer_limit
) {
1340 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1343 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1344 if (size
> es
->buffer_limit
)
1345 size
= es
->buffer_limit
;
1347 TRACE("trying to ReAlloc to %d+1\n", size
);
1349 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1351 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1352 es
->buffer_size
= MIN(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1354 es
->buffer_size
= 0;
1355 } else if (es
->hloc32
) {
1356 if ((hNew32
= LocalReAlloc(es
->hloc32
, size
+ 1, 0))) {
1357 TRACE("Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1358 es
->hloc32
= hNew32
;
1359 es
->buffer_size
= MIN(LocalSize(es
->hloc32
) - 1, es
->buffer_limit
);
1361 } else if (es
->hloc16
) {
1362 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1363 TRACE("Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1364 es
->hloc16
= hNew16
;
1365 es
->buffer_size
= MIN(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1368 if (es
->buffer_size
< size
) {
1369 EDIT_LockBuffer(wnd
, es
);
1370 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1371 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1374 EDIT_LockBuffer(wnd
, es
);
1375 TRACE("We now have %d+1\n", es
->buffer_size
);
1381 /*********************************************************************
1385 * Try to fit size + 1 bytes in the undo buffer.
1388 static BOOL
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT size
)
1390 if (size
<= es
->undo_buffer_size
)
1392 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1394 TRACE("trying to ReAlloc to %d+1\n", size
);
1396 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1397 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1398 if (es
->undo_buffer_size
< size
) {
1399 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1408 /*********************************************************************
1413 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1415 INT e
= es
->selection_end
;
1419 if ((es
->style
& ES_MULTILINE
) && e
&&
1420 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1422 if (e
&& (es
->text
[e
- 1] == '\r'))
1426 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1427 EDIT_EM_ScrollCaret(wnd
, es
);
1431 /*********************************************************************
1435 * Only for multi line controls
1436 * Move the caret one line down, on a column with the nearest
1437 * x coordinate on the screen (might be a different column).
1440 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1442 INT s
= es
->selection_start
;
1443 INT e
= es
->selection_end
;
1444 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1445 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1446 INT x
= SLOWORD(pos
);
1447 INT y
= SHIWORD(pos
);
1449 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1452 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1453 EDIT_EM_ScrollCaret(wnd
, es
);
1457 /*********************************************************************
1462 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1464 BOOL after_wrap
= FALSE
;
1467 /* Pass a high value in x to make sure of receiving the en of the line */
1468 if (es
->style
& ES_MULTILINE
)
1469 e
= EDIT_CharFromPos(wnd
, es
, 0x3fffffff,
1470 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1472 e
= lstrlenA(es
->text
);
1473 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1474 EDIT_EM_ScrollCaret(wnd
, es
);
1478 /*********************************************************************
1483 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1485 INT e
= es
->selection_end
;
1489 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1490 if (es
->text
[e
] == '\n')
1492 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1496 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1497 EDIT_EM_ScrollCaret(wnd
, es
);
1501 /*********************************************************************
1505 * Home key: move to beginning of line.
1508 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1512 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1513 if (es
->style
& ES_MULTILINE
)
1514 e
= EDIT_CharFromPos(wnd
, es
, -es
->x_offset
,
1515 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1518 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1519 EDIT_EM_ScrollCaret(wnd
, es
);
1523 /*********************************************************************
1525 * EDIT_MovePageDown_ML
1527 * Only for multi line controls
1528 * Move the caret one page down, on a column with the nearest
1529 * x coordinate on the screen (might be a different column).
1532 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1534 INT s
= es
->selection_start
;
1535 INT e
= es
->selection_end
;
1536 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1537 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1538 INT x
= SLOWORD(pos
);
1539 INT y
= SHIWORD(pos
);
1541 e
= EDIT_CharFromPos(wnd
, es
, x
,
1542 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1546 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1547 EDIT_EM_ScrollCaret(wnd
, es
);
1551 /*********************************************************************
1553 * EDIT_MovePageUp_ML
1555 * Only for multi line controls
1556 * Move the caret one page up, on a column with the nearest
1557 * x coordinate on the screen (might be a different column).
1560 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1562 INT s
= es
->selection_start
;
1563 INT e
= es
->selection_end
;
1564 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1565 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1566 INT x
= SLOWORD(pos
);
1567 INT y
= SHIWORD(pos
);
1569 e
= EDIT_CharFromPos(wnd
, es
, x
,
1570 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1574 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1575 EDIT_EM_ScrollCaret(wnd
, es
);
1579 /*********************************************************************
1583 * Only for multi line controls
1584 * Move the caret one line up, on a column with the nearest
1585 * x coordinate on the screen (might be a different column).
1588 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1590 INT s
= es
->selection_start
;
1591 INT e
= es
->selection_end
;
1592 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1593 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1594 INT x
= SLOWORD(pos
);
1595 INT y
= SHIWORD(pos
);
1597 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1600 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1601 EDIT_EM_ScrollCaret(wnd
, es
);
1605 /*********************************************************************
1607 * EDIT_MoveWordBackward
1610 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1612 INT s
= es
->selection_start
;
1613 INT e
= es
->selection_end
;
1618 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1619 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1620 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1623 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1624 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1627 e
= li
+ (INT
)EDIT_CallWordBreakProc(wnd
, es
,
1628 li
, e
- li
, ll
, WB_LEFT
);
1632 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1633 EDIT_EM_ScrollCaret(wnd
, es
);
1637 /*********************************************************************
1639 * EDIT_MoveWordForward
1642 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL extend
)
1644 INT s
= es
->selection_start
;
1645 INT e
= es
->selection_end
;
1650 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1651 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1652 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1654 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1655 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1657 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1658 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1662 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1663 EDIT_EM_ScrollCaret(wnd
, es
);
1667 /*********************************************************************
1672 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
1674 INT s
= es
->selection_start
;
1675 INT e
= es
->selection_end
;
1682 if (es
->style
& ES_MULTILINE
) {
1683 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1684 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1689 TRACE("line=%d\n", line
);
1691 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1694 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1695 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1696 s
= es
->selection_start
;
1697 e
= es
->selection_end
;
1699 s
= MIN(li
+ ll
, MAX(li
, s
));
1700 e
= MIN(li
+ ll
, MAX(li
, e
));
1701 if (rev
&& (s
!= e
) &&
1702 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1703 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1704 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1705 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1707 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1711 /*********************************************************************
1716 static INT
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
1726 BkColor
= GetBkColor(dc
);
1727 TextColor
= GetTextColor(dc
);
1729 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
1730 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1732 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1733 if (es
->style
& ES_MULTILINE
) {
1734 ret
= (INT
)LOWORD(TabbedTextOutA(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1735 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1737 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1738 TextOutA(dc
, x
, y
, text
+ li
+ col
, count
);
1739 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1741 if (es
->style
& ES_PASSWORD
)
1742 HeapFree(es
->heap
, 0, text
);
1745 SetBkColor(dc
, BkColor
);
1746 SetTextColor(dc
, TextColor
);
1752 /*********************************************************************
1757 static void EDIT_SetCaretPos(WND
*wnd
, EDITSTATE
*es
, INT pos
,
1760 LRESULT res
= EDIT_EM_PosFromChar(wnd
, es
, pos
, after_wrap
);
1761 INT x
= SLOWORD(res
);
1762 INT y
= SHIWORD(res
);
1764 if(x
< es
->format_rect
.left
)
1765 x
= es
->format_rect
.left
;
1766 if(x
> es
->format_rect
.right
- 2)
1767 x
= es
->format_rect
.right
- 2;
1768 if(y
> es
->format_rect
.bottom
)
1769 y
= es
->format_rect
.bottom
;
1770 if(y
< es
->format_rect
.top
)
1771 y
= es
->format_rect
.top
;
1777 /*********************************************************************
1781 * note: this is not (exactly) the handler called on EM_SETRECTNP
1782 * it is also used to set the rect of a single line control
1785 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT rc
)
1787 CopyRect(&es
->format_rect
, rc
);
1788 if (es
->style
& WS_BORDER
) {
1789 INT bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
1790 if(TWEAK_WineLook
== WIN31_LOOK
)
1792 es
->format_rect
.left
+= bw
;
1793 es
->format_rect
.top
+= bw
;
1794 es
->format_rect
.right
-= bw
;
1795 es
->format_rect
.bottom
-= bw
;
1797 es
->format_rect
.left
+= es
->left_margin
;
1798 es
->format_rect
.right
-= es
->right_margin
;
1799 es
->format_rect
.right
= MAX(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1800 if (es
->style
& ES_MULTILINE
)
1801 es
->format_rect
.bottom
= es
->format_rect
.top
+
1802 MAX(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1804 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1805 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1806 EDIT_BuildLineDefs_ML(wnd
, es
);
1810 /*********************************************************************
1815 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL force
)
1818 ERR("no EDITSTATE ... please report\n");
1821 if (!(es
->style
& ES_MULTILINE
))
1823 if (!es
->lock_count
) {
1824 ERR("lock_count == 0 ... please report\n");
1828 ERR("es->text == 0 ... please report\n");
1831 if (force
|| (es
->lock_count
== 1)) {
1833 LocalUnlock(es
->hloc32
);
1835 } else if (es
->hloc16
) {
1836 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1844 /*********************************************************************
1846 * EDIT_WordBreakProc
1848 * Find the beginning of words.
1849 * Note: unlike the specs for a WordBreakProc, this function only
1850 * allows to be called without linebreaks between s[0] upto
1851 * s[count - 1]. Remember it is only called
1852 * internally, so we can decide this for ourselves.
1855 static INT
EDIT_WordBreakProc(LPSTR s
, INT index
, INT count
, INT action
)
1859 TRACE("s=%p, index=%u, count=%u, action=%d\n",
1860 s
, index
, count
, action
);
1868 if (s
[index
] == ' ') {
1869 while (index
&& (s
[index
] == ' '))
1872 while (index
&& (s
[index
] != ' '))
1874 if (s
[index
] == ' ')
1878 while (index
&& (s
[index
] != ' '))
1880 if (s
[index
] == ' ')
1890 if (s
[index
] == ' ')
1891 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1893 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1895 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1899 case WB_ISDELIMITER
:
1900 ret
= (s
[index
] == ' ');
1903 ERR("unknown action code, please report !\n");
1910 /*********************************************************************
1914 * returns line number (not index) in high-order word of result.
1915 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
1916 * to Richedit, not to the edit control. Original documentation is valid.
1917 * FIXME: do the specs mean to return -1 if outside client area or
1918 * if outside formatting rectangle ???
1921 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT x
, INT y
)
1929 GetClientRect(wnd
->hwndSelf
, &rc
);
1930 if (!PtInRect(&rc
, pt
))
1933 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1934 return MAKELONG(index
, EDIT_EM_LineFromChar(wnd
, es
, index
));
1938 /*********************************************************************
1942 * Enable or disable soft breaks.
1944 static BOOL
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL add_eol
)
1946 es
->flags
&= ~EF_USE_SOFTBRK
;
1948 es
->flags
|= EF_USE_SOFTBRK
;
1949 FIXME("soft break enabled, not implemented\n");
1955 /*********************************************************************
1959 * Hopefully this won't fire back at us.
1960 * We always start with a fixed buffer in our own heap.
1961 * However, with this message a 32 bit application requests
1962 * a handle to 32 bit moveable local heap memory, where it expects
1964 * It's a pity that from this moment on we have to use this
1965 * local heap, because applications may rely on the handle
1968 * In this function we'll try to switch to local heap.
1971 static HLOCAL
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1977 if (!(es
->style
& ES_MULTILINE
))
1982 else if (es
->hloc16
)
1983 return (HLOCAL
)es
->hloc16
;
1985 if (!(newBuf
= LocalAlloc(LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
1986 ERR("could not allocate new 32 bit buffer\n");
1989 newSize
= MIN(LocalSize(newBuf
) - 1, es
->buffer_limit
);
1990 if (!(newText
= LocalLock(newBuf
))) {
1991 ERR("could not lock new 32 bit buffer\n");
1995 lstrcpyA(newText
, es
->text
);
1996 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1998 HeapFree(es
->heap
, 0, es
->text
);
1999 es
->hloc32
= newBuf
;
2000 es
->hloc16
= (HLOCAL16
)NULL
;
2001 es
->buffer_size
= newSize
;
2003 EDIT_LockBuffer(wnd
, es
);
2004 TRACE("switched to 32 bit local heap\n");
2010 /*********************************************************************
2014 * Hopefully this won't fire back at us.
2015 * We always start with a buffer in 32 bit linear memory.
2016 * However, with this message a 16 bit application requests
2017 * a handle of 16 bit local heap memory, where it expects to find
2019 * It's a pitty that from this moment on we have to use this
2020 * local heap, because applications may rely on the handle
2023 * In this function we'll try to switch to local heap.
2025 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2031 if (!(es
->style
& ES_MULTILINE
))
2037 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2038 if (!LocalInit16(wnd
->hInstance
, 0,
2039 GlobalSize16(wnd
->hInstance
))) {
2040 ERR("could not initialize local heap\n");
2043 TRACE("local heap initialized\n");
2045 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlenA(es
->text
) + 1))) {
2046 ERR("could not allocate new 16 bit buffer\n");
2049 newSize
= MIN(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2050 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2051 ERR("could not lock new 16 bit buffer\n");
2052 LOCAL_Free(wnd
->hInstance
, newBuf
);
2055 lstrcpyA(newText
, es
->text
);
2056 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2058 HeapFree(es
->heap
, 0, es
->text
);
2059 else if (es
->hloc32
) {
2060 while (LocalFree(es
->hloc32
)) ;
2061 LocalFree(es
->hloc32
);
2063 es
->hloc32
= (HLOCAL
)NULL
;
2064 es
->hloc16
= newBuf
;
2065 es
->buffer_size
= newSize
;
2067 EDIT_LockBuffer(wnd
, es
);
2068 TRACE("switched to 16 bit buffer\n");
2074 /*********************************************************************
2079 static INT
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT line
, LPSTR lpch
)
2085 if (es
->style
& ES_MULTILINE
) {
2086 if (line
>= es
->line_count
)
2090 i
= EDIT_EM_LineIndex(wnd
, es
, line
);
2092 len
= MIN(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, i
));
2093 for (i
= 0 ; i
< len
; i
++) {
2098 return (LRESULT
)len
;
2102 /*********************************************************************
2107 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT start
, LPUINT end
)
2109 UINT s
= es
->selection_start
;
2110 UINT e
= es
->selection_end
;
2117 return MAKELONG(s
, e
);
2121 /*********************************************************************
2125 * FIXME: is this right ? (or should it be only VSCROLL)
2126 * (and maybe only for edit controls that really have their
2127 * own scrollbars) (and maybe only for multiline controls ?)
2128 * All in all: very poorly documented
2130 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2131 * WM_VSCROLL handlers
2134 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2136 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2137 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2141 /*********************************************************************
2146 static INT
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
)
2151 if (!(es
->style
& ES_MULTILINE
))
2153 if (index
> lstrlenA(es
->text
))
2154 return es
->line_count
- 1;
2156 index
= MIN(es
->selection_start
, es
->selection_end
);
2159 line_def
= es
->first_line_def
;
2160 index
-= line_def
->length
;
2161 while ((index
>= 0) && line_def
->next
) {
2163 line_def
= line_def
->next
;
2164 index
-= line_def
->length
;
2170 /*********************************************************************
2175 static INT
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT line
)
2180 if (!(es
->style
& ES_MULTILINE
))
2182 if (line
>= es
->line_count
)
2186 line_def
= es
->first_line_def
;
2188 INT index
= es
->selection_end
- line_def
->length
;
2189 while ((index
>= 0) && line_def
->next
) {
2190 line_index
+= line_def
->length
;
2191 line_def
= line_def
->next
;
2192 index
-= line_def
->length
;
2196 line_index
+= line_def
->length
;
2197 line_def
= line_def
->next
;
2205 /*********************************************************************
2210 static INT
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT index
)
2214 if (!(es
->style
& ES_MULTILINE
))
2215 return lstrlenA(es
->text
);
2219 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2220 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2221 return es->selection_start - es->line_defs[sl].offset +
2222 es->line_defs[el].offset +
2223 es->line_defs[el].length - es->selection_end;
2227 line_def
= es
->first_line_def
;
2228 index
-= line_def
->length
;
2229 while ((index
>= 0) && line_def
->next
) {
2230 line_def
= line_def
->next
;
2231 index
-= line_def
->length
;
2233 return line_def
->net_length
;
2237 /*********************************************************************
2241 * FIXME: dx is in average character widths
2242 * However, we assume it is in pixels when we use this
2243 * function internally
2246 static BOOL
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT dx
, INT dy
)
2250 if (!(es
->style
& ES_MULTILINE
))
2253 if (-dx
> es
->x_offset
)
2255 if (dx
> es
->text_width
- es
->x_offset
)
2256 dx
= es
->text_width
- es
->x_offset
;
2257 nyoff
= MAX(0, es
->y_offset
+ dy
);
2258 if (nyoff
>= es
->line_count
)
2259 nyoff
= es
->line_count
- 1;
2260 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2264 GetClientRect(wnd
->hwndSelf
, &rc1
);
2265 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
2266 ScrollWindowEx(wnd
->hwndSelf
, -dx
, dy
,
2267 NULL
, &rc
, (HRGN
)NULL
, NULL
, SW_INVALIDATE
);
2268 es
->y_offset
= nyoff
;
2271 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2272 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2273 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2274 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2279 /*********************************************************************
2284 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT index
, BOOL after_wrap
)
2286 INT len
= lstrlenA(es
->text
);
2295 index
= MIN(index
, len
);
2296 dc
= GetDC(wnd
->hwndSelf
);
2298 old_font
= SelectObject(dc
, es
->font
);
2299 if (es
->style
& ES_MULTILINE
) {
2300 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2301 y
= (l
- es
->y_offset
) * es
->line_height
;
2302 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2303 if (after_wrap
&& (li
== index
) && l
) {
2305 LINEDEF
*line_def
= es
->first_line_def
;
2307 line_def
= line_def
->next
;
2310 if (line_def
->ending
== END_WRAP
) {
2312 y
-= es
->line_height
;
2313 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2316 x
= LOWORD(GetTabbedTextExtentA(dc
, es
->text
+ li
, index
- li
,
2317 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2319 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2320 if (index
< es
->x_offset
) {
2321 GetTextExtentPoint32A(dc
, text
+ index
,
2322 es
->x_offset
- index
, &size
);
2325 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2326 index
- es
->x_offset
, &size
);
2330 if (es
->style
& ES_PASSWORD
)
2331 HeapFree(es
->heap
, 0 ,text
);
2333 x
+= es
->format_rect
.left
;
2334 y
+= es
->format_rect
.top
;
2336 SelectObject(dc
, old_font
);
2337 ReleaseDC(wnd
->hwndSelf
, dc
);
2338 return MAKELONG((INT16
)x
, (INT16
)y
);
2342 /*********************************************************************
2346 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2349 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL can_undo
, LPCSTR lpsz_replace
)
2351 INT strl
= lstrlenA(lpsz_replace
);
2352 INT tl
= lstrlenA(es
->text
);
2359 s
= es
->selection_start
;
2360 e
= es
->selection_end
;
2362 if ((s
== e
) && !strl
)
2367 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2371 /* there is something to be deleted */
2373 utl
= lstrlenA(es
->undo_text
);
2374 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2375 /* undo-buffer is extended to the right */
2376 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2377 lstrcpynA(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2378 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2379 /* undo-buffer is extended to the left */
2380 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2381 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2383 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2384 p
[i
] = (es
->text
+ s
)[i
];
2385 es
->undo_position
= s
;
2387 /* new undo-buffer */
2388 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2389 lstrcpynA(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2390 es
->undo_position
= s
;
2392 /* any deletion makes the old insertion-undo invalid */
2393 es
->undo_insert_count
= 0;
2395 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2398 lstrcpyA(es
->text
+ s
, es
->text
+ e
);
2401 /* there is an insertion */
2403 if ((s
== es
->undo_position
) ||
2404 ((es
->undo_insert_count
) &&
2405 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2407 * insertion is new and at delete position or
2408 * an extension to either left or right
2410 es
->undo_insert_count
+= strl
;
2412 /* new insertion undo */
2413 es
->undo_position
= s
;
2414 es
->undo_insert_count
= strl
;
2415 /* new insertion makes old delete-buffer invalid */
2416 *es
->undo_text
= '\0';
2419 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2422 tl
= lstrlenA(es
->text
);
2423 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2425 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2426 p
[i
] = lpsz_replace
[i
];
2427 if(es
->style
& ES_UPPERCASE
)
2428 CharUpperBuffA(p
, strl
);
2429 else if(es
->style
& ES_LOWERCASE
)
2430 CharLowerBuffA(p
, strl
);
2433 /* FIXME: really inefficient */
2434 if (es
->style
& ES_MULTILINE
)
2435 EDIT_BuildLineDefs_ML(wnd
, es
);
2437 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2438 es
->flags
|= EF_MODIFIED
;
2439 es
->flags
|= EF_UPDATE
;
2440 EDIT_EM_ScrollCaret(wnd
, es
);
2442 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
2444 /* FIXME: really inefficient */
2445 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2449 /*********************************************************************
2454 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT action
)
2458 if (!(es
->style
& ES_MULTILINE
))
2459 return (LRESULT
)FALSE
;
2469 if (es
->y_offset
< es
->line_count
- 1)
2474 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2477 if (es
->y_offset
< es
->line_count
- 1)
2478 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2481 return (LRESULT
)FALSE
;
2484 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2485 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2487 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2491 /*********************************************************************
2496 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
2498 if (es
->style
& ES_MULTILINE
) {
2503 INT cw
= es
->char_width
;
2508 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
2509 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2510 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
2511 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2512 if (l
>= es
->y_offset
+ vlc
)
2513 dy
= l
- vlc
+ 1 - es
->y_offset
;
2514 if (l
< es
->y_offset
)
2515 dy
= l
- es
->y_offset
;
2516 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
2517 if (x
< es
->format_rect
.left
)
2518 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2519 if (x
> es
->format_rect
.right
)
2520 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2522 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
2528 if (!(es
->style
& ES_AUTOHSCROLL
))
2531 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2532 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
2533 if (x
< es
->format_rect
.left
) {
2534 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
2537 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2538 } while ((x
< goal
) && es
->x_offset
);
2539 /* FIXME: use ScrollWindow() somehow to improve performance */
2540 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2541 } else if (x
> es
->format_rect
.right
) {
2543 INT len
= lstrlenA(es
->text
);
2544 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
2547 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
2548 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
2549 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
2550 /* FIXME: use ScrollWindow() somehow to improve performance */
2551 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2557 /*********************************************************************
2561 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2564 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL hloc
)
2566 if (!(es
->style
& ES_MULTILINE
))
2570 WARN("called with NULL handle\n");
2574 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2576 * old buffer is freed by caller, unless
2577 * it is still in our own heap. (in that case
2578 * we free it, correcting the buggy caller.)
2581 HeapFree(es
->heap
, 0, es
->text
);
2583 es
->hloc16
= (HLOCAL16
)NULL
;
2586 es
->buffer_size
= LocalSize(es
->hloc32
) - 1;
2587 EDIT_LockBuffer(wnd
, es
);
2589 es
->x_offset
= es
->y_offset
= 0;
2590 es
->selection_start
= es
->selection_end
= 0;
2591 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2592 es
->flags
&= ~EF_MODIFIED
;
2593 es
->flags
&= ~EF_UPDATE
;
2594 EDIT_BuildLineDefs_ML(wnd
, es
);
2595 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2596 EDIT_EM_ScrollCaret(wnd
, es
);
2600 /*********************************************************************
2604 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2607 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2609 if (!(es
->style
& ES_MULTILINE
))
2613 WARN("called with NULL handle\n");
2617 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2619 * old buffer is freed by caller, unless
2620 * it is still in our own heap. (in that case
2621 * we free it, correcting the buggy caller.)
2624 HeapFree(es
->heap
, 0, es
->text
);
2627 es
->hloc32
= (HLOCAL
)NULL
;
2629 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2630 EDIT_LockBuffer(wnd
, es
);
2632 es
->x_offset
= es
->y_offset
= 0;
2633 es
->selection_start
= es
->selection_end
= 0;
2634 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2635 es
->flags
&= ~EF_MODIFIED
;
2636 es
->flags
&= ~EF_UPDATE
;
2637 EDIT_BuildLineDefs_ML(wnd
, es
);
2638 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2639 EDIT_EM_ScrollCaret(wnd
, es
);
2643 /*********************************************************************
2647 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2648 * However, the windows version is not complied to yet in all of edit.c
2651 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT limit
)
2653 if (es
->style
& ES_MULTILINE
) {
2655 es
->buffer_limit
= MIN(limit
, BUFLIMIT_MULTI
);
2657 es
->buffer_limit
= BUFLIMIT_MULTI
;
2660 es
->buffer_limit
= MIN(limit
, BUFLIMIT_SINGLE
);
2662 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2667 /*********************************************************************
2671 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2672 * action wParam despite what the docs say. EC_USEFONTINFO means one third
2673 * of the char's width, according to the new docs.
2676 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT action
,
2677 INT left
, INT right
)
2679 if (action
& EC_LEFTMARGIN
) {
2680 if (left
!= EC_USEFONTINFO
)
2681 es
->left_margin
= left
;
2683 es
->left_margin
= es
->char_width
/ 3;
2686 if (action
& EC_RIGHTMARGIN
) {
2687 if (right
!= EC_USEFONTINFO
)
2688 es
->right_margin
= right
;
2690 es
->right_margin
= es
->char_width
/ 3;
2692 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2696 /*********************************************************************
2698 * EM_SETPASSWORDCHAR
2701 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2703 if (es
->style
& ES_MULTILINE
)
2706 if (es
->password_char
== c
)
2709 es
->password_char
= c
;
2711 wnd
->dwStyle
|= ES_PASSWORD
;
2712 es
->style
|= ES_PASSWORD
;
2714 wnd
->dwStyle
&= ~ES_PASSWORD
;
2715 es
->style
&= ~ES_PASSWORD
;
2717 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2721 /*********************************************************************
2725 * note: unlike the specs say: the order of start and end
2726 * _is_ preserved in Windows. (i.e. start can be > end)
2727 * In other words: this handler is OK
2730 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
2732 UINT old_start
= es
->selection_start
;
2733 UINT old_end
= es
->selection_end
;
2734 UINT len
= lstrlenA(es
->text
);
2737 start
= es
->selection_end
;
2738 end
= es
->selection_end
;
2740 start
= MIN(start
, len
);
2741 end
= MIN(end
, len
);
2743 es
->selection_start
= start
;
2744 es
->selection_end
= end
;
2746 es
->flags
|= EF_AFTER_WRAP
;
2748 es
->flags
&= ~EF_AFTER_WRAP
;
2749 if (es
->flags
& EF_FOCUSED
)
2750 EDIT_SetCaretPos(wnd
, es
, end
, after_wrap
);
2751 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2752 ORDER_UINT(start
, end
);
2753 ORDER_UINT(end
, old_end
);
2754 ORDER_UINT(start
, old_start
);
2755 ORDER_UINT(old_start
, old_end
);
2756 if (end
!= old_start
)
2760 * ORDER_UINT32(end, old_start);
2761 * EDIT_InvalidateText(wnd, es, start, end);
2762 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2763 * in place of the following if statement.
2765 if (old_start
> end
)
2767 EDIT_InvalidateText(wnd
, es
, start
, end
);
2768 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2772 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2773 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2776 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2780 /*********************************************************************
2785 static BOOL
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT tabs
)
2787 if (!(es
->style
& ES_MULTILINE
))
2790 HeapFree(es
->heap
, 0, es
->tabs
);
2791 es
->tabs_count
= count
;
2795 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2796 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2802 /*********************************************************************
2807 static BOOL
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT count
, LPINT16 tabs
)
2809 if (!(es
->style
& ES_MULTILINE
))
2812 HeapFree(es
->heap
, 0, es
->tabs
);
2813 es
->tabs_count
= count
;
2818 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT
));
2819 for (i
= 0 ; i
< count
; i
++)
2820 es
->tabs
[i
] = *tabs
++;
2826 /*********************************************************************
2828 * EM_SETWORDBREAKPROC
2831 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROCA wbp
)
2833 if (es
->word_break_proc32A
== wbp
)
2836 es
->word_break_proc32A
= wbp
;
2837 es
->word_break_proc16
= NULL
;
2838 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2839 EDIT_BuildLineDefs_ML(wnd
, es
);
2840 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2845 /*********************************************************************
2847 * EM_SETWORDBREAKPROC16
2850 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2852 if (es
->word_break_proc16
== wbp
)
2855 es
->word_break_proc32A
= NULL
;
2856 es
->word_break_proc16
= wbp
;
2857 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2858 EDIT_BuildLineDefs_ML(wnd
, es
);
2859 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
2864 /*********************************************************************
2869 static BOOL
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2871 INT ulength
= lstrlenA(es
->undo_text
);
2872 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2874 lstrcpyA(utext
, es
->undo_text
);
2876 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2877 es
->undo_insert_count
, utext
);
2879 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2880 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2881 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2882 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2883 HeapFree(es
->heap
, 0, utext
);
2885 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2886 es
->undo_insert_count
, es
->undo_text
);
2892 /*********************************************************************
2897 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2899 BOOL control
= GetKeyState(VK_CONTROL
) & 0x8000;
2902 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
2903 if(!(es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2906 if (es
->style
& ES_MULTILINE
) {
2907 if (es
->style
& ES_READONLY
) {
2908 EDIT_MoveHome(wnd
, es
, FALSE
);
2909 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2911 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2915 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2916 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2919 if (!(es
->style
& ES_READONLY
) && !control
) {
2920 if (es
->selection_start
!= es
->selection_end
)
2921 EDIT_WM_Clear(wnd
, es
);
2923 /* delete character left of caret */
2924 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
2925 EDIT_MoveBackward(wnd
, es
, TRUE
);
2926 EDIT_WM_Clear(wnd
, es
);
2931 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2935 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2942 /*********************************************************************
2947 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT code
, INT id
, HWND control
)
2949 if (code
|| control
)
2954 EDIT_EM_Undo(wnd
, es
);
2957 EDIT_WM_Cut(wnd
, es
);
2960 EDIT_WM_Copy(wnd
, es
);
2963 EDIT_WM_Paste(wnd
, es
);
2966 EDIT_WM_Clear(wnd
, es
);
2969 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
2970 EDIT_EM_ScrollCaret(wnd
, es
);
2973 ERR("unknown menu item, please report\n");
2979 /*********************************************************************
2983 * Note: the resource files resource/sysres_??.rc cannot define a
2984 * single popup menu. Hence we use a (dummy) menubar
2985 * containing the single popup menu as its first item.
2987 * FIXME: the message identifiers have been chosen arbitrarily,
2988 * hence we use MF_BYPOSITION.
2989 * We might as well use the "real" values (anybody knows ?)
2990 * The menu definition is in resources/sysres_??.rc.
2991 * Once these are OK, we better use MF_BYCOMMAND here
2992 * (as we do in EDIT_WM_Command()).
2995 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND hwnd
, INT x
, INT y
)
2997 HMENU menu
= LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
2998 HMENU popup
= GetSubMenu(menu
, 0);
2999 UINT start
= es
->selection_start
;
3000 UINT end
= es
->selection_end
;
3002 ORDER_UINT(start
, end
);
3005 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
3007 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3009 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3011 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
3013 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
3015 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlenA(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
3017 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
3022 /*********************************************************************
3027 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
3029 INT s
= es
->selection_start
;
3030 INT e
= es
->selection_end
;
3037 hdst
= GlobalAlloc(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
3038 dst
= GlobalLock(hdst
);
3039 lstrcpynA(dst
, es
->text
+ s
, e
- s
+ 1);
3041 OpenClipboard(wnd
->hwndSelf
);
3043 SetClipboardData(CF_TEXT
, hdst
);
3048 /*********************************************************************
3053 static LRESULT
EDIT_WM_Create(WND
*wnd
, EDITSTATE
*es
, LPCREATESTRUCTA cs
)
3056 * To initialize some final structure members, we call some helper
3057 * functions. However, since the EDITSTATE is not consistent (i.e.
3058 * not fully initialized), we should be very careful which
3059 * functions can be called, and in what order.
3061 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3062 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
3064 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3065 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3066 /* if we insert text to the editline, the text scrolls out
3067 * of the window, as the caret is placed after the insert
3068 * pos normally; thus we reset es->selection... to 0 and
3071 es
->selection_start
= es
->selection_end
= 0;
3072 EDIT_EM_ScrollCaret(wnd
, es
);
3078 /*********************************************************************
3083 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3086 while (LocalUnlock(es
->hloc32
)) ;
3087 LocalFree(es
->hloc32
);
3090 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3091 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3093 HeapDestroy(es
->heap
);
3094 HeapFree(GetProcessHeap(), 0, es
);
3095 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3099 /*********************************************************************
3104 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC dc
)
3109 if ( VERSION_AppWinVer() >= 0x40000 &&(
3110 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3111 brush
= (HBRUSH
)EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3113 brush
= (HBRUSH
)EDIT_SEND_CTLCOLOR(wnd
, dc
);
3116 brush
= (HBRUSH
)GetStockObject(WHITE_BRUSH
);
3118 GetClientRect(wnd
->hwndSelf
, &rc
);
3119 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3120 GetClipBox(dc
, &rc
);
3122 * FIXME: specs say that we should UnrealizeObject() the brush,
3123 * but the specs of UnrealizeObject() say that we shouldn't
3124 * unrealize a stock object. The default brush that
3125 * DefWndProc() returns is ... a stock object.
3127 FillRect(dc
, &rc
, brush
);
3132 /*********************************************************************
3137 static INT
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT count
, LPSTR text
)
3139 INT len
= lstrlenA(es
->text
);
3142 lstrcpyA(text
, es
->text
);
3149 /*********************************************************************
3153 * 16 bit notepad needs this. Actually it is not _our_ hack,
3154 * it is notepad's. Notepad is sending us scrollbar messages with
3155 * undocumented parameters without us even having a scrollbar ... !?!?
3158 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3161 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3164 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3165 ERR("hacked WM_HSCROLL handler invoked\n");
3166 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3167 ERR(" (this message is only displayed once per edit control)\n");
3168 es
->flags
|= EF_HSCROLL_HACK
;
3174 dx
= -es
->char_width
;
3177 if (es
->x_offset
< es
->text_width
)
3178 dx
= es
->char_width
;
3182 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3185 if (es
->x_offset
< es
->text_width
)
3186 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3193 if (es
->x_offset
< es
->text_width
)
3194 dx
= es
->text_width
- es
->x_offset
;
3197 es
->flags
|= EF_HSCROLL_TRACK
;
3198 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3200 case SB_THUMBPOSITION
:
3201 es
->flags
&= ~EF_HSCROLL_TRACK
;
3202 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3203 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3209 * FIXME : the next two are undocumented !
3210 * Are we doing the right thing ?
3211 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3212 * although it's also a regular control message.
3215 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3217 case EM_LINESCROLL16
:
3222 ERR("undocumented (hacked) WM_HSCROLL parameter, please report\n");
3226 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3231 /*********************************************************************
3236 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3241 if (!(es
->style
& ES_MULTILINE
))
3244 if (!(es
->style
& ES_AUTOHSCROLL
))
3247 if (!(es
->style
& WS_HSCROLL
))
3248 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3251 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3255 dx
= -es
->char_width
;
3258 if (es
->x_offset
< es
->text_width
)
3259 dx
= es
->char_width
;
3263 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3266 if (es
->x_offset
< es
->text_width
)
3267 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3274 if (es
->x_offset
< es
->text_width
)
3275 dx
= es
->text_width
- es
->x_offset
;
3278 es
->flags
|= EF_HSCROLL_TRACK
;
3279 dx
= pos
- es
->x_offset
;
3281 case SB_THUMBPOSITION
:
3282 es
->flags
&= ~EF_HSCROLL_TRACK
;
3283 if (!(dx
= pos
- es
->x_offset
)) {
3284 SetScrollPos(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3285 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3292 ERR("undocumented WM_HSCROLL parameter, please report\n");
3296 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3301 /*********************************************************************
3306 static BOOL
EDIT_CheckCombo(WND
*wnd
, UINT msg
, INT key
, DWORD key_data
)
3310 if (WIDGETS_IsControl(wnd
->parent
, BIC32_COMBO
) &&
3311 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3312 HWND hCombo
= wnd
->parent
->hwndSelf
;
3313 BOOL bUIFlip
= TRUE
;
3315 TRACE_(combo
)("[%04x]: handling msg %04x (%04x)\n",
3316 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3319 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3321 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3322 if (SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0))
3326 SendMessageA(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3328 /* make sure ComboLBox pops up */
3329 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 0, 0);
3330 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3331 SendMessageA(hCombo
, CB_SETEXTENDEDUI
, 1, 0);
3334 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3335 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETEXTENDEDUI
, 0, 0);
3337 bUIFlip
= (BOOL
)SendMessageA(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3338 SendMessageA(hCombo
, CB_SHOWDROPDOWN
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3340 SendMessageA(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3349 /*********************************************************************
3353 * Handling of special keys that don't produce a WM_CHAR
3354 * (i.e. non-printable keys) & Backspace & Delete
3357 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3362 if (GetKeyState(VK_MENU
) & 0x8000)
3365 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3366 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3371 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3377 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3378 EDIT_MoveUp_ML(wnd
, es
, shift
);
3381 EDIT_MoveWordBackward(wnd
, es
, shift
);
3383 EDIT_MoveBackward(wnd
, es
, shift
);
3386 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3390 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3391 EDIT_MoveDown_ML(wnd
, es
, shift
);
3393 EDIT_MoveWordForward(wnd
, es
, shift
);
3395 EDIT_MoveForward(wnd
, es
, shift
);
3398 EDIT_MoveHome(wnd
, es
, shift
);
3401 EDIT_MoveEnd(wnd
, es
, shift
);
3404 if (es
->style
& ES_MULTILINE
)
3405 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3408 if (es
->style
& ES_MULTILINE
)
3409 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3412 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3413 if (es
->selection_start
!= es
->selection_end
) {
3415 EDIT_WM_Cut(wnd
, es
);
3417 EDIT_WM_Clear(wnd
, es
);
3420 /* delete character left of caret */
3421 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3422 EDIT_MoveBackward(wnd
, es
, TRUE
);
3423 EDIT_WM_Clear(wnd
, es
);
3424 } else if (control
) {
3425 /* delete to end of line */
3426 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3427 EDIT_MoveEnd(wnd
, es
, TRUE
);
3428 EDIT_WM_Clear(wnd
, es
);
3430 /* delete character right of caret */
3431 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3432 EDIT_MoveForward(wnd
, es
, TRUE
);
3433 EDIT_WM_Clear(wnd
, es
);
3440 if (!(es
->style
& ES_READONLY
))
3441 EDIT_WM_Paste(wnd
, es
);
3443 EDIT_WM_Copy(wnd
, es
);
3446 /* If the edit doesn't want the return send a message to the default object */
3447 if(!(es
->style
& ES_WANTRETURN
))
3449 HWND hwndParent
= GetParent(wnd
->hwndSelf
);
3450 DWORD dw
= SendMessage16( hwndParent
, DM_GETDEFID
, 0, 0 );
3451 if (HIWORD(dw
) == DC_HASDEFID
)
3453 SendMessageA( hwndParent
, WM_COMMAND
,
3454 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3455 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3464 /*********************************************************************
3469 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_getting_focus
)
3471 es
->flags
&= ~EF_FOCUSED
;
3473 if(!(es
->style
& ES_NOHIDESEL
))
3474 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3475 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3480 /*********************************************************************
3484 * The caret position has been set on the WM_LBUTTONDOWN message
3487 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3490 INT e
= es
->selection_end
;
3495 if (!(es
->flags
& EF_FOCUSED
))
3498 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3499 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3500 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3501 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3502 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3503 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3504 EDIT_EM_ScrollCaret(wnd
, es
);
3509 /*********************************************************************
3514 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3519 if (!(es
->flags
& EF_FOCUSED
))
3522 es
->bCaptureState
= TRUE
;
3523 SetCapture(wnd
->hwndSelf
);
3524 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3525 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3526 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3527 EDIT_EM_ScrollCaret(wnd
, es
);
3528 es
->region_posx
= es
->region_posy
= 0;
3529 SetTimer(wnd
->hwndSelf
, 0, 100, NULL
);
3534 /*********************************************************************
3539 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3541 if (es
->bCaptureState
&& GetCapture() == wnd
->hwndSelf
) {
3542 KillTimer(wnd
->hwndSelf
, 0);
3545 es
->bCaptureState
= FALSE
;
3550 /*********************************************************************
3555 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3561 if (GetCapture() != wnd
->hwndSelf
)
3565 * FIXME: gotta do some scrolling if outside client
3566 * area. Maybe reset the timer ?
3569 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3570 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3571 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3572 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3573 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3578 /*********************************************************************
3583 static LRESULT
EDIT_WM_NCCreate(WND
*wnd
, LPCREATESTRUCTA cs
)
3587 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
3589 *(EDITSTATE
**)wnd
->wExtra
= es
;
3592 * Note: since the EDITSTATE has not been fully initialized yet,
3593 * we can't use any API calls that may send
3594 * WM_XXX messages before WM_NCCREATE is completed.
3597 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
3599 es
->style
= cs
->style
;
3601 es
->bEnableState
= !(cs
->style
& WS_DISABLED
);
3604 * In Win95 look and feel, the WS_BORDER style is replaced by the
3605 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
3606 * control a non client area.
3608 if (TWEAK_WineLook
!= WIN31_LOOK
)
3610 if (es
->style
& WS_BORDER
)
3612 es
->style
&= ~WS_BORDER
;
3613 wnd
->dwStyle
&= ~WS_BORDER
;
3614 wnd
->dwExStyle
|= WS_EX_CLIENTEDGE
;
3619 if ((es
->style
& WS_BORDER
) && !(es
->style
& WS_DLGFRAME
))
3620 wnd
->dwStyle
&= ~WS_BORDER
;
3623 if (es
->style
& ES_MULTILINE
) {
3624 es
->buffer_size
= BUFSTART_MULTI
;
3625 es
->buffer_limit
= BUFLIMIT_MULTI
;
3626 if (es
->style
& WS_VSCROLL
)
3627 es
->style
|= ES_AUTOVSCROLL
;
3628 if (es
->style
& WS_HSCROLL
)
3629 es
->style
|= ES_AUTOHSCROLL
;
3630 es
->style
&= ~ES_PASSWORD
;
3631 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3632 if (es
->style
& ES_RIGHT
)
3633 es
->style
&= ~ES_CENTER
;
3634 es
->style
&= ~WS_HSCROLL
;
3635 es
->style
&= ~ES_AUTOHSCROLL
;
3638 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3639 es
->style
|= ES_AUTOVSCROLL
;
3641 es
->buffer_size
= BUFSTART_SINGLE
;
3642 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3643 es
->style
&= ~ES_CENTER
;
3644 es
->style
&= ~ES_RIGHT
;
3645 es
->style
&= ~WS_HSCROLL
;
3646 es
->style
&= ~WS_VSCROLL
;
3647 es
->style
&= ~ES_AUTOVSCROLL
;
3648 es
->style
&= ~ES_WANTRETURN
;
3649 if (es
->style
& ES_UPPERCASE
) {
3650 es
->style
&= ~ES_LOWERCASE
;
3651 es
->style
&= ~ES_NUMBER
;
3652 } else if (es
->style
& ES_LOWERCASE
)
3653 es
->style
&= ~ES_NUMBER
;
3654 if (es
->style
& ES_PASSWORD
)
3655 es
->password_char
= '*';
3657 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3658 es
->style
|= ES_AUTOHSCROLL
;
3660 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3662 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3663 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3665 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3667 if (es
->style
& ES_MULTILINE
)
3668 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3675 /*********************************************************************
3680 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
, WPARAM wParam
)
3689 BOOL rev
= es
->bEnableState
&&
3690 ((es
->flags
& EF_FOCUSED
) ||
3691 (es
->style
& ES_NOHIDESEL
));
3693 dc
= BeginPaint(wnd
->hwndSelf
, &ps
);
3696 if(es
->style
& WS_BORDER
) {
3697 GetClientRect(wnd
->hwndSelf
, &rc
);
3698 if(es
->style
& ES_MULTILINE
) {
3699 if(es
->style
& WS_HSCROLL
) rc
.bottom
++;
3700 if(es
->style
& WS_VSCROLL
) rc
.right
++;
3702 Rectangle(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3704 IntersectClipRect(dc
, es
->format_rect
.left
,
3705 es
->format_rect
.top
,
3706 es
->format_rect
.right
,
3707 es
->format_rect
.bottom
);
3708 if (es
->style
& ES_MULTILINE
) {
3709 GetClientRect(wnd
->hwndSelf
, &rc
);
3710 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3713 old_font
= SelectObject(dc
, es
->font
);
3714 if ( VERSION_AppWinVer() >= 0x40000 &&(
3715 !es
->bEnableState
|| (es
->style
& ES_READONLY
)))
3716 EDIT_SEND_CTLCOLORSTATIC(wnd
, dc
);
3718 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3720 if (!es
->bEnableState
)
3721 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3722 GetClipBox(dc
, &rcRgn
);
3723 if (es
->style
& ES_MULTILINE
) {
3724 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3725 for (i
= es
->y_offset
; i
<= MIN(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3726 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3727 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3728 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3731 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3732 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3733 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3736 SelectObject(dc
, old_font
);
3737 if (es
->flags
& EF_FOCUSED
)
3738 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3739 es
->flags
& EF_AFTER_WRAP
);
3741 EndPaint(wnd
->hwndSelf
, &ps
);
3742 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3743 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3745 si
.cbSize
= sizeof(SCROLLINFO
);
3746 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3748 si
.nMax
= es
->line_count
+ vlc
- 2;
3750 si
.nPos
= es
->y_offset
;
3751 SetScrollInfo(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3753 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3755 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3756 si
.cbSize
= sizeof(SCROLLINFO
);
3757 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3759 si
.nMax
= es
->text_width
+ fw
- 1;
3761 si
.nPos
= es
->x_offset
;
3762 SetScrollInfo(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3765 if (es
->flags
& EF_UPDATE
) {
3766 es
->flags
&= ~EF_UPDATE
;
3767 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3772 /*********************************************************************
3777 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3782 OpenClipboard(wnd
->hwndSelf
);
3783 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
3784 src
= (LPSTR
)GlobalLock(hsrc
);
3785 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3792 /*********************************************************************
3797 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND window_losing_focus
)
3799 es
->flags
|= EF_FOCUSED
;
3800 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3801 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3802 es
->flags
& EF_AFTER_WRAP
);
3803 if(!(es
->style
& ES_NOHIDESEL
))
3804 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3805 ShowCaret(wnd
->hwndSelf
);
3806 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3810 /*********************************************************************
3814 * With Win95 look the margins are set to default font value unless
3815 * the system font (font == 0) is being set, in which case they are left
3819 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3827 dc
= GetDC(wnd
->hwndSelf
);
3829 old_font
= SelectObject(dc
, font
);
3830 GetTextMetricsA(dc
, &tm
);
3831 es
->line_height
= tm
.tmHeight
;
3832 es
->char_width
= tm
.tmAveCharWidth
;
3834 SelectObject(dc
, old_font
);
3835 ReleaseDC(wnd
->hwndSelf
, dc
);
3836 if (font
&& (TWEAK_WineLook
> WIN31_LOOK
))
3837 EDIT_EM_SetMargins(wnd
, es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3838 EC_USEFONTINFO
, EC_USEFONTINFO
);
3840 /* Force the recalculation of the format rect for each font change */
3841 GetClientRect(wnd
->hwndSelf
, &r
);
3842 EDIT_SetRectNP(wnd
, es
, &r
);
3844 if (es
->style
& ES_MULTILINE
)
3845 EDIT_BuildLineDefs_ML(wnd
, es
);
3848 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3849 if (es
->flags
& EF_FOCUSED
) {
3851 CreateCaret(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3852 EDIT_SetCaretPos(wnd
, es
, es
->selection_end
,
3853 es
->flags
& EF_AFTER_WRAP
);
3854 ShowCaret(wnd
->hwndSelf
);
3859 /*********************************************************************
3864 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3865 * The modified flag is reset. No notifications are sent.
3867 * For single-line controls, reception of WM_SETTEXT triggers:
3868 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3871 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3873 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3875 TRACE("\t'%s'\n", text
);
3876 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3878 TRACE("\t<NULL>\n");
3879 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, "");
3882 if (es
->style
& ES_MULTILINE
) {
3883 es
->flags
&= ~EF_UPDATE
;
3885 es
->flags
|= EF_UPDATE
;
3887 es
->flags
&= ~EF_MODIFIED
;
3888 EDIT_EM_SetSel(wnd
, es
, 0, 0, FALSE
);
3889 EDIT_EM_ScrollCaret(wnd
, es
);
3891 if (es
->flags
& EF_UPDATE
)
3892 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3896 /*********************************************************************
3901 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3903 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3905 SetRect(&rc
, 0, 0, width
, height
);
3906 EDIT_SetRectNP(wnd
, es
, &rc
);
3907 InvalidateRect(wnd
->hwndSelf
, NULL
, TRUE
);
3912 /*********************************************************************
3917 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT key
, DWORD key_data
)
3919 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3920 if (EDIT_EM_CanUndo(wnd
, es
))
3921 EDIT_EM_Undo(wnd
, es
);
3923 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3924 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3926 return DefWindowProcA(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
3930 /*********************************************************************
3935 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT id
, TIMERPROC timer_proc
)
3937 if (es
->region_posx
< 0) {
3938 EDIT_MoveBackward(wnd
, es
, TRUE
);
3939 } else if (es
->region_posx
> 0) {
3940 EDIT_MoveForward(wnd
, es
, TRUE
);
3943 * FIXME: gotta do some vertical scrolling here, like
3944 * EDIT_EM_LineScroll(wnd, 0, 1);
3949 /*********************************************************************
3953 * 16 bit notepad needs this. Actually it is not _our_ hack,
3954 * it is notepad's. Notepad is sending us scrollbar messages with
3955 * undocumented parameters without us even having a scrollbar ... !?!?
3958 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
3963 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3964 ERR("hacked WM_VSCROLL handler invoked\n");
3965 ERR(" if you are _not_ running 16 bit notepad, please report\n");
3966 ERR(" (this message is only displayed once per edit control)\n");
3967 es
->flags
|= EF_VSCROLL_HACK
;
3975 EDIT_EM_Scroll(wnd
, es
, action
);
3981 dy
= es
->line_count
- 1 - es
->y_offset
;
3984 es
->flags
|= EF_VSCROLL_TRACK
;
3985 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
3987 case SB_THUMBPOSITION
:
3988 es
->flags
&= ~EF_VSCROLL_TRACK
;
3989 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
3990 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3996 * FIXME : the next two are undocumented !
3997 * Are we doing the right thing ?
3998 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3999 * although it's also a regular control message.
4002 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
4004 case EM_LINESCROLL16
:
4009 ERR("undocumented (hacked) WM_VSCROLL parameter, please report\n");
4013 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
4018 /*********************************************************************
4023 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT action
, INT pos
, HWND scroll_bar
)
4027 if (!(es
->style
& ES_MULTILINE
))
4030 if (!(es
->style
& ES_AUTOVSCROLL
))
4033 if (!(es
->style
& WS_VSCROLL
))
4034 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
4042 EDIT_EM_Scroll(wnd
, es
, action
);
4049 dy
= es
->line_count
- 1 - es
->y_offset
;
4052 es
->flags
|= EF_VSCROLL_TRACK
;
4053 dy
= pos
- es
->y_offset
;
4055 case SB_THUMBPOSITION
:
4056 es
->flags
&= ~EF_VSCROLL_TRACK
;
4057 if (!(dy
= pos
- es
->y_offset
)) {
4058 SetScrollPos(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
4059 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
4066 ERR("undocumented WM_VSCROLL action %d, please report\n",
4071 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);