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)
25 #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
26 FIXME: BTW, new specs say 65535 (do you dare ???) */
27 #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
28 #define BUFSTART_MULTI 1024 /* starting size */
29 #define BUFSTART_SINGLE 256 /* starting size */
30 #define GROWLENGTH 64 /* buffers grow by this much */
31 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
34 * extra flags for EDITSTATE.flags field
36 #define EF_MODIFIED 0x0001 /* text has been modified */
37 #define EF_FOCUSED 0x0002 /* we have input focus */
38 #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
39 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
40 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
41 #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
42 #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
43 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
44 wrapped line, instead of in front of the next character */
46 typedef BOOL32
*LPBOOL32
;
50 END_0
= 0, /* line ends with terminating '\0' character */
51 END_WRAP
, /* line is wrapped */
52 END_HARD
, /* line ends with a hard return '\r\n' */
53 END_SOFT
, /* line ends with a soft return '\r\r\n' */
56 typedef struct tagLINEDEF
{
57 INT32 length
; /* bruto length of a line in bytes */
58 INT32 net_length
; /* netto length of a line in visible characters */
60 INT32 width
; /* width of the line in pixels */
61 struct tagLINEDEF
*next
;
66 HANDLE32 heap
; /* our own heap */
67 LPSTR text
; /* the actual contents of the control */
68 INT32 buffer_size
; /* the size of the buffer */
69 INT32 buffer_limit
; /* the maximum size to which the buffer may grow */
70 HFONT32 font
; /* NULL means standard system font */
71 INT32 x_offset
; /* scroll offset for multi lines this is in pixels
72 for single lines it's in characters */
73 INT32 line_height
; /* height of a screen line in pixels */
74 INT32 char_width
; /* average character width in pixels */
75 DWORD style
; /* sane version of wnd->dwStyle */
76 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
77 INT32 undo_insert_count
; /* number of characters inserted in sequence */
78 INT32 undo_position
; /* character index of the insertion and deletion */
79 LPSTR undo_text
; /* deleted text */
80 INT32 undo_buffer_size
; /* size of the deleted text buffer */
81 INT32 selection_start
; /* == selection_end if no selection */
82 INT32 selection_end
; /* == current caret position */
83 CHAR password_char
; /* == 0 if no password char, and for multi line controls */
84 INT32 left_margin
; /* in pixels */
85 INT32 right_margin
; /* in pixels */
87 INT32 region_posx
; /* Position of cursor relative to region: */
88 INT32 region_posy
; /* -1: to left, 0: within, 1: to right */
89 EDITWORDBREAKPROC16 word_break_proc16
;
90 EDITWORDBREAKPROC32A word_break_proc32A
;
91 INT32 line_count
; /* number of lines */
92 INT32 y_offset
; /* scroll offset in number of lines */
94 * only for multi line controls
96 INT32 lock_count
; /* amount of re-entries in the EditWndProc */
99 INT32 text_width
; /* width of the widest line in pixels */
100 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
101 HLOCAL16 hloc16
; /* for controls receiving EM_GETHANDLE16 */
102 HLOCAL32 hloc32
; /* for controls receiving EM_GETHANDLE */
106 #define SWAP_INT32(x,y) do { INT32 temp = (INT32)(x); (x) = (INT32)(y); (y) = temp; } while(0)
107 #define ORDER_INT32(x,y) do { if ((INT32)(y) < (INT32)(x)) SWAP_INT32((x),(y)); } while(0)
109 #define SWAP_UINT32(x,y) do { UINT32 temp = (UINT32)(x); (x) = (UINT32)(y); (y) = temp; } while(0)
110 #define ORDER_UINT32(x,y) do { if ((UINT32)(y) < (UINT32)(x)) SWAP_UINT32((x),(y)); } while(0)
112 #define DPRINTF_EDIT_NOTIFY(hwnd, str) \
113 ({dprintf_edit(stddeb, \
114 "edit: notification " str " sent to hwnd=%08x\n", \
117 #define EDIT_SEND_CTLCOLOR(wnd,hdc) \
118 (SendMessage32A((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
119 (WPARAM32)(hdc), (LPARAM)(wnd)->hwndSelf))
120 #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
121 (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \
122 SendMessage32A((wnd)->parent->hwndSelf, WM_COMMAND, \
123 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
124 (LPARAM)(wnd)->hwndSelf))
125 #define DPRINTF_EDIT_MSG16(str) \
126 dprintf_edit(stddeb, \
127 "edit: 16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
128 (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam)
129 #define DPRINTF_EDIT_MSG32(str) \
130 dprintf_edit(stddeb, \
131 "edit: 32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
132 (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam)
135 /*********************************************************************
142 * These functions have trivial implementations
143 * We still like to call them internally
144 * "static __inline__" makes them more like macro's
146 static __inline__ BOOL32
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
);
147 static __inline__
void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
);
148 static __inline__
void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
);
149 static __inline__
void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
);
151 * This is the only exported function
153 LRESULT WINAPI
EditWndProc( HWND32 hwnd
, UINT32 msg
,
154 WPARAM32 wParam
, LPARAM lParam
);
156 * Helper functions only valid for one type of control
158 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
);
159 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
);
160 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
161 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
162 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
163 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
165 * Helper functions valid for both single line _and_ multi line controls
167 static INT32
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT32 start
, INT32 index
, INT32 count
, INT32 action
);
168 static INT32
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT32 x
, INT32 y
, LPBOOL32 after_wrap
);
169 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT32 x
, LPINT32 y
);
170 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT32 line
, INT32 scol
, INT32 ecol
, LPRECT32 rc
);
171 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT32 start
, INT32 end
);
172 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
);
173 static BOOL32
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT32 size
);
174 static BOOL32
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT32 size
);
175 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
176 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
177 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
178 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
179 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
180 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
);
181 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC32 hdc
, INT32 line
, BOOL32 rev
);
182 static INT32
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC32 hdc
, INT32 x
, INT32 y
, INT32 line
, INT32 col
, INT32 count
, BOOL32 rev
);
183 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT32 lprc
);
184 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL32 force
);
185 static INT32
EDIT_WordBreakProc(LPSTR s
, INT32 index
, INT32 count
, INT32 action
);
187 * EM_XXX message handlers
189 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT32 x
, INT32 y
);
190 static BOOL32
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL32 add_eol
);
191 static HLOCAL32
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
);
192 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
);
193 static INT32
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT32 line
, LPSTR lpch
);
194 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT32 start
, LPUINT32 end
);
195 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
);
196 static INT32
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT32 index
);
197 static INT32
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT32 line
);
198 static INT32
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT32 index
);
199 static BOOL32
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT32 dx
, INT32 dy
);
200 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT32 index
, BOOL32 after_wrap
);
201 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL32 can_undo
, LPCSTR lpsz_replace
);
202 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT32 action
);
203 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
);
204 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL32 hloc
);
205 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
);
206 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT32 limit
);
207 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 left
, INT32 right
);
208 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
);
209 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT32 start
, UINT32 end
, BOOL32 after_wrap
);
210 static BOOL32
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT32 count
, LPINT32 tabs
);
211 static BOOL32
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT32 count
, LPINT16 tabs
);
212 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC32A wbp
);
213 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
);
214 static BOOL32
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
);
216 * WM_XXX message handlers
218 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
);
219 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT32 code
, INT32 id
, HWND32 conrtol
);
220 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND32 hwnd
, INT32 x
, INT32 y
);
221 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
);
222 static LRESULT
EDIT_WM_Create(WND
*wnd
, LPCREATESTRUCT32A cs
);
223 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
);
224 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC32 dc
);
225 static INT32
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT32 count
, LPSTR text
);
226 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 pos
, HWND32 scroll_bar
);
227 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT32 key
, DWORD key_data
);
228 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND32 window_getting_focus
);
229 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
);
230 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
);
231 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
);
232 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
);
233 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
);
234 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
);
235 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND32 window_losing_focus
);
236 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT32 font
, BOOL32 redraw
);
237 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
);
238 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT32 action
, INT32 width
, INT32 height
);
239 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT32 key
, DWORD key_data
);
240 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT32 id
, TIMERPROC32 timer_proc
);
241 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 pos
, HWND32 scroll_bar
);
244 /*********************************************************************
249 static __inline__ BOOL32
EDIT_EM_CanUndo(WND
*wnd
, EDITSTATE
*es
)
251 return (es
->undo_insert_count
|| lstrlen32A(es
->undo_text
));
255 /*********************************************************************
260 static __inline__
void EDIT_EM_EmptyUndoBuffer(WND
*wnd
, EDITSTATE
*es
)
262 es
->undo_insert_count
= 0;
263 *es
->undo_text
= '\0';
267 /*********************************************************************
272 static __inline__
void EDIT_WM_Clear(WND
*wnd
, EDITSTATE
*es
)
274 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "");
278 /*********************************************************************
283 static __inline__
void EDIT_WM_Cut(WND
*wnd
, EDITSTATE
*es
)
285 EDIT_WM_Copy(wnd
, es
);
286 EDIT_WM_Clear(wnd
, es
);
290 /*********************************************************************
294 * The messages are in the order of the actual integer values
295 * (which can be found in include/windows.h)
296 * Whereever possible the 16 bit versions are converted to
297 * the 32 bit ones, so that we can 'fall through' to the
298 * helper functions. These are mostly 32 bit (with a few
299 * exceptions, clearly indicated by a '16' extension to their
303 LRESULT WINAPI
EditWndProc( HWND32 hwnd
, UINT32 msg
,
304 WPARAM32 wParam
, LPARAM lParam
)
306 WND
*wnd
= WIN_FindWndPtr(hwnd
);
307 EDITSTATE
*es
= *(EDITSTATE
**)((wnd
)->wExtra
);
312 DPRINTF_EDIT_MSG32("WM_CREATE");
313 return EDIT_WM_Create(wnd
, (LPCREATESTRUCT32A
)lParam
);
316 DPRINTF_EDIT_MSG32("WM_DESTROY");
317 EDIT_WM_Destroy(wnd
, es
);
322 return DefWindowProc32A(hwnd
, msg
, wParam
, lParam
);
324 EDIT_LockBuffer(wnd
, es
);
327 DPRINTF_EDIT_MSG16("EM_GETSEL");
332 DPRINTF_EDIT_MSG32("EM_GETSEL");
333 result
= EDIT_EM_GetSel(wnd
, es
, (LPUINT32
)wParam
, (LPUINT32
)lParam
);
337 DPRINTF_EDIT_MSG16("EM_SETSEL");
338 if (SLOWORD(lParam
) == -1)
339 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
341 EDIT_EM_SetSel(wnd
, es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
343 EDIT_EM_ScrollCaret(wnd
, es
);
347 DPRINTF_EDIT_MSG32("EM_SETSEL");
348 EDIT_EM_SetSel(wnd
, es
, wParam
, lParam
, FALSE
);
353 DPRINTF_EDIT_MSG16("EM_GETRECT");
355 CONV_RECT32TO16(&es
->format_rect
, (LPRECT16
)PTR_SEG_TO_LIN(lParam
));
358 DPRINTF_EDIT_MSG32("EM_GETRECT");
360 CopyRect32((LPRECT32
)lParam
, &es
->format_rect
);
364 DPRINTF_EDIT_MSG16("EM_SETRECT");
365 if ((es
->style
& ES_MULTILINE
) && lParam
) {
367 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
368 EDIT_SetRectNP(wnd
, es
, &rc
);
369 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
373 DPRINTF_EDIT_MSG32("EM_SETRECT");
374 if ((es
->style
& ES_MULTILINE
) && lParam
) {
375 EDIT_SetRectNP(wnd
, es
, (LPRECT32
)lParam
);
376 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
381 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
382 if ((es
->style
& ES_MULTILINE
) && lParam
) {
384 CONV_RECT16TO32((LPRECT16
)PTR_SEG_TO_LIN(lParam
), &rc
);
385 EDIT_SetRectNP(wnd
, es
, &rc
);
389 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
390 if ((es
->style
& ES_MULTILINE
) && lParam
)
391 EDIT_SetRectNP(wnd
, es
, (LPRECT32
)lParam
);
395 DPRINTF_EDIT_MSG16("EM_SCROLL");
398 DPRINTF_EDIT_MSG32("EM_SCROLL");
399 result
= EDIT_EM_Scroll(wnd
, es
, (INT32
)wParam
);
402 case EM_LINESCROLL16
:
403 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
404 wParam
= (WPARAM32
)(INT32
)SHIWORD(lParam
);
405 lParam
= (LPARAM
)(INT32
)SLOWORD(lParam
);
407 case EM_LINESCROLL32
:
408 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
409 result
= (LRESULT
)EDIT_EM_LineScroll(wnd
, es
, (INT32
)wParam
, (INT32
)lParam
);
412 case EM_SCROLLCARET16
:
413 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
415 case EM_SCROLLCARET32
:
416 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
417 EDIT_EM_ScrollCaret(wnd
, es
);
422 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
425 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
426 return ((es
->flags
& EF_MODIFIED
) != 0);
430 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
433 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
435 es
->flags
|= EF_MODIFIED
;
437 es
->flags
&= ~EF_MODIFIED
;
440 case EM_GETLINECOUNT16
:
441 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
443 case EM_GETLINECOUNT32
:
444 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
445 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
449 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
450 if ((INT16
)wParam
== -1)
451 wParam
= (WPARAM32
)-1;
454 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
455 result
= (LRESULT
)EDIT_EM_LineIndex(wnd
, es
, (INT32
)wParam
);
459 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
460 EDIT_EM_SetHandle16(wnd
, es
, (HLOCAL16
)wParam
);
463 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
464 EDIT_EM_SetHandle(wnd
, es
, (HLOCAL32
)wParam
);
468 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
469 result
= (LRESULT
)EDIT_EM_GetHandle16(wnd
, es
);
472 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
473 result
= (LRESULT
)EDIT_EM_GetHandle(wnd
, es
);
477 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
480 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
481 result
= EDIT_EM_GetThumb(wnd
, es
);
484 /* messages 0x00bf and 0x00c0 missing from specs */
487 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
490 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
491 result
= DefWindowProc32A(hwnd
, msg
, wParam
, lParam
);
495 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
498 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
499 result
= DefWindowProc32A(hwnd
, msg
, wParam
, lParam
);
502 case EM_LINELENGTH16
:
503 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
505 case EM_LINELENGTH32
:
506 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
507 result
= (LRESULT
)EDIT_EM_LineLength(wnd
, es
, (INT32
)wParam
);
510 case EM_REPLACESEL16
:
511 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
512 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
514 case EM_REPLACESEL32
:
515 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
516 EDIT_EM_ReplaceSel(wnd
, es
, (BOOL32
)wParam
, (LPCSTR
)lParam
);
519 /* message 0x00c3 missing from specs */
522 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
525 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
526 result
= DefWindowProc32A(hwnd
, msg
, wParam
, lParam
);
530 DPRINTF_EDIT_MSG16("EM_GETLINE");
531 lParam
= (LPARAM
)PTR_SEG_TO_LIN((SEGPTR
)lParam
);
534 DPRINTF_EDIT_MSG32("EM_GETLINE");
535 result
= (LRESULT
)EDIT_EM_GetLine(wnd
, es
, (INT32
)wParam
, (LPSTR
)lParam
);
539 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
541 case EM_SETLIMITTEXT32
:
542 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
543 EDIT_EM_SetLimitText(wnd
, es
, (INT32
)wParam
);
547 DPRINTF_EDIT_MSG16("EM_CANUNDO");
550 DPRINTF_EDIT_MSG32("EM_CANUNDO");
551 result
= (LRESULT
)EDIT_EM_CanUndo(wnd
, es
);
555 DPRINTF_EDIT_MSG16("EM_UNDO");
560 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
561 result
= (LRESULT
)EDIT_EM_Undo(wnd
, es
);
565 DPRINTF_EDIT_MSG16("EM_FMTLINES");
568 DPRINTF_EDIT_MSG32("EM_FMTLINES");
569 result
= (LRESULT
)EDIT_EM_FmtLines(wnd
, es
, (BOOL32
)wParam
);
572 case EM_LINEFROMCHAR16
:
573 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
575 case EM_LINEFROMCHAR32
:
576 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
577 result
= (LRESULT
)EDIT_EM_LineFromChar(wnd
, es
, (INT32
)wParam
);
580 /* message 0x00ca missing from specs */
583 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
586 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
587 result
= DefWindowProc32A(hwnd
, msg
, wParam
, lParam
);
590 case EM_SETTABSTOPS16
:
591 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
592 result
= (LRESULT
)EDIT_EM_SetTabStops16(wnd
, es
, (INT32
)wParam
, (LPINT16
)PTR_SEG_TO_LIN((SEGPTR
)lParam
));
594 case EM_SETTABSTOPS32
:
595 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
596 result
= (LRESULT
)EDIT_EM_SetTabStops(wnd
, es
, (INT32
)wParam
, (LPINT32
)lParam
);
599 case EM_SETPASSWORDCHAR16
:
600 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
602 case EM_SETPASSWORDCHAR32
:
603 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
604 EDIT_EM_SetPasswordChar(wnd
, es
, (CHAR
)wParam
);
607 case EM_EMPTYUNDOBUFFER16
:
608 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
610 case EM_EMPTYUNDOBUFFER32
:
611 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
612 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
615 case EM_GETFIRSTVISIBLELINE16
:
616 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
617 result
= es
->y_offset
;
619 case EM_GETFIRSTVISIBLELINE32
:
620 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
621 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
624 case EM_SETREADONLY16
:
625 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
627 case EM_SETREADONLY32
:
628 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
630 wnd
->dwStyle
|= ES_READONLY
;
631 es
->style
|= ES_READONLY
;
633 wnd
->dwStyle
&= ~ES_READONLY
;
634 es
->style
&= ~ES_READONLY
;
639 case EM_SETWORDBREAKPROC16
:
640 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
641 EDIT_EM_SetWordBreakProc16(wnd
, es
, (EDITWORDBREAKPROC16
)lParam
);
643 case EM_SETWORDBREAKPROC32
:
644 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
645 EDIT_EM_SetWordBreakProc(wnd
, es
, (EDITWORDBREAKPROC32A
)lParam
);
648 case EM_GETWORDBREAKPROC16
:
649 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
650 result
= (LRESULT
)es
->word_break_proc16
;
652 case EM_GETWORDBREAKPROC32
:
653 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
654 result
= (LRESULT
)es
->word_break_proc32A
;
657 case EM_GETPASSWORDCHAR16
:
658 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
660 case EM_GETPASSWORDCHAR32
:
661 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
662 result
= es
->password_char
;
665 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
667 case EM_SETMARGINS32
:
668 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
669 EDIT_EM_SetMargins(wnd
, es
, (INT32
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
672 case EM_GETMARGINS32
:
673 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
674 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
677 case EM_GETLIMITTEXT32
:
678 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
679 result
= es
->buffer_limit
;
682 case EM_POSFROMCHAR32
:
683 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
684 result
= EDIT_EM_PosFromChar(wnd
, es
, (INT32
)wParam
, FALSE
);
687 case EM_CHARFROMPOS32
:
688 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
689 result
= EDIT_EM_CharFromPos(wnd
, es
, SLOWORD(lParam
), SHIWORD(lParam
));
693 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
694 result
= (es
->style
& ES_MULTILINE
) ?
695 DLGC_WANTALLKEYS
| DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
:
696 DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
700 DPRINTF_EDIT_MSG32("WM_CHAR");
701 EDIT_WM_Char(wnd
, es
, (CHAR
)wParam
, (DWORD
)lParam
);
705 DPRINTF_EDIT_MSG32("WM_CLEAR");
706 EDIT_WM_Clear(wnd
, es
);
710 DPRINTF_EDIT_MSG32("WM_COMMAND");
711 EDIT_WM_Command(wnd
, es
, HIWORD(wParam
), LOWORD(wParam
), (HWND32
)lParam
);
715 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
716 EDIT_WM_ContextMenu(wnd
, es
, (HWND32
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
720 DPRINTF_EDIT_MSG32("WM_COPY");
721 EDIT_WM_Copy(wnd
, es
);
725 DPRINTF_EDIT_MSG32("WM_CUT");
726 EDIT_WM_Cut(wnd
, es
);
730 DPRINTF_EDIT_MSG32("WM_ENABLE");
731 InvalidateRect32(hwnd
, NULL
, TRUE
);
735 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
736 result
= EDIT_WM_EraseBkGnd(wnd
, es
, (HDC32
)wParam
);
740 DPRINTF_EDIT_MSG32("WM_GETFONT");
741 result
= (LRESULT
)es
->font
;
745 DPRINTF_EDIT_MSG32("WM_GETTEXT");
746 result
= (LRESULT
)EDIT_WM_GetText(wnd
, es
, (INT32
)wParam
, (LPSTR
)lParam
);
749 case WM_GETTEXTLENGTH
:
750 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
751 result
= lstrlen32A(es
->text
);
755 DPRINTF_EDIT_MSG32("WM_HSCROLL");
756 result
= EDIT_WM_HScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND32
)lParam
);
760 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
761 result
= EDIT_WM_KeyDown(wnd
, es
, (INT32
)wParam
, (DWORD
)lParam
);
765 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
766 result
= EDIT_WM_KillFocus(wnd
, es
, (HWND32
)wParam
);
769 case WM_LBUTTONDBLCLK
:
770 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
771 result
= EDIT_WM_LButtonDblClk(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
775 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
776 result
= EDIT_WM_LButtonDown(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
780 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
781 result
= EDIT_WM_LButtonUp(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
784 case WM_MOUSEACTIVATE
:
786 * FIXME: maybe DefWindowProc() screws up, but it seems that
787 * modalless dialog boxes need this. If we don't do this, the focus
788 * will _not_ be set by DefWindowProc() for edit controls in a
789 * modalless dialog box ???
791 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
792 SetFocus32(wnd
->hwndSelf
);
793 result
= MA_ACTIVATE
;
798 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
800 result
= EDIT_WM_MouseMove(wnd
, es
, (DWORD
)wParam
, SLOWORD(lParam
), SHIWORD(lParam
));
804 DPRINTF_EDIT_MSG32("WM_PAINT");
805 EDIT_WM_Paint(wnd
, es
);
809 DPRINTF_EDIT_MSG32("WM_PASTE");
810 EDIT_WM_Paste(wnd
, es
);
814 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
815 EDIT_WM_SetFocus(wnd
, es
, (HWND32
)wParam
);
819 DPRINTF_EDIT_MSG32("WM_SETFONT");
820 EDIT_WM_SetFont(wnd
, es
, (HFONT32
)wParam
, LOWORD(lParam
) != 0);
824 DPRINTF_EDIT_MSG32("WM_SETTEXT");
825 EDIT_WM_SetText(wnd
, es
, (LPCSTR
)lParam
);
830 DPRINTF_EDIT_MSG32("WM_SIZE");
831 EDIT_WM_Size(wnd
, es
, (UINT32
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
835 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
836 result
= EDIT_WM_SysKeyDown(wnd
, es
, (INT32
)wParam
, (DWORD
)lParam
);
840 DPRINTF_EDIT_MSG32("WM_TIMER");
841 EDIT_WM_Timer(wnd
, es
, (INT32
)wParam
, (TIMERPROC32
)lParam
);
845 DPRINTF_EDIT_MSG32("WM_VSCROLL");
846 result
= EDIT_WM_VScroll(wnd
, es
, LOWORD(wParam
), SHIWORD(wParam
), (HWND32
)(lParam
));
850 result
= DefWindowProc32A(hwnd
, msg
, wParam
, lParam
);
853 EDIT_UnlockBuffer(wnd
, es
, FALSE
);
858 /*********************************************************************
860 * EDIT_BuildLineDefs_ML
862 * Build linked list of text lines.
863 * Lines can end with '\0' (last line), a character (if it is wrapped),
864 * a soft return '\r\r\n' or a hard return '\r\n'
867 static void EDIT_BuildLineDefs_ML(WND
*wnd
, EDITSTATE
*es
)
870 HFONT32 old_font
= 0;
873 LINEDEF
*current_def
;
874 LINEDEF
**previous_next
;
876 current_def
= es
->first_line_def
;
878 LINEDEF
*next_def
= current_def
->next
;
879 HeapFree(es
->heap
, 0, current_def
);
880 current_def
= next_def
;
881 } while (current_def
);
885 dc
= GetDC32(wnd
->hwndSelf
);
887 old_font
= SelectObject32(dc
, es
->font
);
889 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
891 previous_next
= &es
->first_line_def
;
893 current_def
= HeapAlloc(es
->heap
, 0, sizeof(LINEDEF
));
894 current_def
->next
= NULL
;
897 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
902 current_def
->ending
= END_0
;
903 current_def
->net_length
= lstrlen32A(start
);
904 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
905 current_def
->ending
= END_SOFT
;
906 current_def
->net_length
= cp
- start
- 1;
908 current_def
->ending
= END_HARD
;
909 current_def
->net_length
= cp
- start
;
911 current_def
->width
= (INT32
)LOWORD(GetTabbedTextExtent32A(dc
,
912 start
, current_def
->net_length
,
913 es
->tabs_count
, es
->tabs
));
914 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
915 if ((!(es
->style
& ES_AUTOHSCROLL
)) && (current_def
->width
> fw
)) {
920 next
= EDIT_CallWordBreakProc(wnd
, es
, start
- es
->text
,
921 prev
+ 1, current_def
->net_length
, WB_RIGHT
);
922 current_def
->width
= (INT32
)LOWORD(GetTabbedTextExtent32A(dc
,
923 start
, next
, es
->tabs_count
, es
->tabs
));
924 } while (current_def
->width
<= fw
);
930 current_def
->width
= (INT32
)LOWORD(GetTabbedTextExtent32A(dc
,
931 start
, next
, es
->tabs_count
, es
->tabs
));
932 } while (current_def
->width
<= fw
);
936 current_def
->net_length
= prev
;
937 current_def
->ending
= END_WRAP
;
938 current_def
->width
= (INT32
)LOWORD(GetTabbedTextExtent32A(dc
, start
,
939 current_def
->net_length
, es
->tabs_count
, es
->tabs
));
941 switch (current_def
->ending
) {
943 current_def
->length
= current_def
->net_length
+ 3;
946 current_def
->length
= current_def
->net_length
+ 2;
950 current_def
->length
= current_def
->net_length
;
953 es
->text_width
= MAX(es
->text_width
, current_def
->width
);
954 start
+= current_def
->length
;
955 *previous_next
= current_def
;
956 previous_next
= ¤t_def
->next
;
958 } while (current_def
->ending
!= END_0
);
960 SelectObject32(dc
, old_font
);
961 ReleaseDC32(wnd
->hwndSelf
, dc
);
965 /*********************************************************************
967 * EDIT_CallWordBreakProc
969 * Call appropriate WordBreakProc (internal or external).
971 * Note: The "start" argument should always be an index refering
972 * to es->text. The actual wordbreak proc might be
973 * 16 bit, so we can't always pass any 32 bit LPSTR.
974 * Hence we assume that es->text is the buffer that holds
975 * the string under examination (we can decide this for ourselves).
978 static INT32
EDIT_CallWordBreakProc(WND
*wnd
, EDITSTATE
*es
, INT32 start
, INT32 index
, INT32 count
, INT32 action
)
980 if (es
->word_break_proc16
) {
981 HLOCAL16 hloc16
= EDIT_EM_GetHandle16(wnd
, es
);
982 SEGPTR segptr
= LocalLock16(hloc16
);
983 INT32 ret
= (INT32
)Callbacks
->CallWordBreakProc(es
->word_break_proc16
,
984 segptr
+ start
, index
, count
, action
);
985 LocalUnlock16(hloc16
);
988 else if (es
->word_break_proc32A
)
990 dprintf_relay( stddeb
, "CallTo32(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
991 es
->word_break_proc32A
, es
->text
+ start
, index
,
993 return (INT32
)es
->word_break_proc32A( es
->text
+ start
, index
,
997 return EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
1001 /*********************************************************************
1005 * Beware: This is not the function called on EM_CHARFROMPOS
1006 * The position _can_ be outside the formatting / client
1008 * The return value is only the character index
1011 static INT32
EDIT_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT32 x
, INT32 y
, LPBOOL32 after_wrap
)
1015 HFONT32 old_font
= 0;
1017 if (es
->style
& ES_MULTILINE
) {
1018 INT32 line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
1019 INT32 line_index
= 0;
1020 LINEDEF
*line_def
= es
->first_line_def
;
1022 while ((line
> 0) && line_def
->next
) {
1023 line_index
+= line_def
->length
;
1024 line_def
= line_def
->next
;
1027 x
+= es
->x_offset
- es
->format_rect
.left
;
1028 if (x
>= line_def
->width
) {
1030 *after_wrap
= (line_def
->ending
== END_WRAP
);
1031 return line_index
+ line_def
->net_length
;
1035 *after_wrap
= FALSE
;
1038 dc
= GetDC32(wnd
->hwndSelf
);
1040 old_font
= SelectObject32(dc
, es
->font
);
1041 low
= line_index
+ 1;
1042 high
= line_index
+ line_def
->net_length
+ 1;
1043 while (low
< high
- 1)
1045 INT32 mid
= (low
+ high
) / 2;
1046 if (LOWORD(GetTabbedTextExtent32A(dc
, es
->text
+ line_index
,mid
- line_index
, es
->tabs_count
, es
->tabs
)) > x
) high
= mid
;
1052 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
1053 (line_def
->ending
== END_WRAP
));
1058 *after_wrap
= FALSE
;
1059 x
-= es
->format_rect
.left
;
1061 return es
->x_offset
;
1062 text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1063 dc
= GetDC32(wnd
->hwndSelf
);
1065 old_font
= SelectObject32(dc
, es
->font
);
1069 INT32 high
= es
->x_offset
;
1070 while (low
< high
- 1)
1072 INT32 mid
= (low
+ high
) / 2;
1073 GetTextExtentPoint32A( dc
, text
+ mid
,
1074 es
->x_offset
- mid
, &size
);
1075 if (size
.cx
> -x
) low
= mid
;
1082 INT32 low
= es
->x_offset
;
1083 INT32 high
= lstrlen32A(es
->text
) + 1;
1084 while (low
< high
- 1)
1086 INT32 mid
= (low
+ high
) / 2;
1087 GetTextExtentPoint32A( dc
, text
+ es
->x_offset
,
1088 mid
- es
->x_offset
, &size
);
1089 if (size
.cx
> x
) high
= mid
;
1094 if (es
->style
& ES_PASSWORD
)
1095 HeapFree(es
->heap
, 0 ,text
);
1098 SelectObject32(dc
, old_font
);
1099 ReleaseDC32(wnd
->hwndSelf
, dc
);
1104 /*********************************************************************
1108 * adjusts the point to be within the formatting rectangle
1109 * (so CharFromPos returns the nearest _visible_ character)
1112 static void EDIT_ConfinePoint(WND
*wnd
, EDITSTATE
*es
, LPINT32 x
, LPINT32 y
)
1114 *x
= MIN(MAX(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
1115 *y
= MIN(MAX(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
1119 /*********************************************************************
1123 * Calculates the bounding rectangle for a line from a starting
1124 * column to an ending column.
1127 static void EDIT_GetLineRect(WND
*wnd
, EDITSTATE
*es
, INT32 line
, INT32 scol
, INT32 ecol
, LPRECT32 rc
)
1129 INT32 line_index
= EDIT_EM_LineIndex(wnd
, es
, line
);
1131 if (es
->style
& ES_MULTILINE
)
1132 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1134 rc
->top
= es
->format_rect
.top
;
1135 rc
->bottom
= rc
->top
+ es
->line_height
;
1136 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ scol
, TRUE
));
1137 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, line_index
+ ecol
, TRUE
));
1141 /*********************************************************************
1143 * EDIT_GetPasswordPointer_SL
1145 * note: caller should free the (optionally) allocated buffer
1148 static LPSTR
EDIT_GetPasswordPointer_SL(WND
*wnd
, EDITSTATE
*es
)
1150 if (es
->style
& ES_PASSWORD
) {
1151 INT32 len
= lstrlen32A(es
->text
);
1152 LPSTR text
= HeapAlloc(es
->heap
, 0, len
+ 1);
1153 RtlFillMemory(text
, len
, es
->password_char
);
1161 /*********************************************************************
1165 * This acts as a LOCAL_Lock(), but it locks only once. This way
1166 * you can call it whenever you like, without unlocking.
1169 static void EDIT_LockBuffer(WND
*wnd
, EDITSTATE
*es
)
1172 fprintf(stderr
, "edit: LockBuffer() without an EDITSTATE ... please report\n");
1175 if (!(es
->style
& ES_MULTILINE
))
1179 es
->text
= LocalLock32(es
->hloc32
);
1180 else if (es
->hloc16
)
1181 es
->text
= LOCAL_Lock(wnd
->hInstance
, es
->hloc16
);
1183 fprintf(stderr
, "edit: LockBuffer() without a buffer ... please report\n");
1191 /*********************************************************************
1193 * EDIT_SL_InvalidateText
1195 * Called from EDIT_InvalidateText().
1196 * Does the job for single-line controls only.
1199 static void EDIT_SL_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT32 start
, INT32 end
)
1204 EDIT_GetLineRect(wnd
, es
, 0, start
, end
, &line_rect
);
1205 if (IntersectRect32(&rc
, &line_rect
, &es
->format_rect
))
1206 InvalidateRect32(wnd
->hwndSelf
, &rc
, FALSE
);
1210 /*********************************************************************
1212 * EDIT_ML_InvalidateText
1214 * Called from EDIT_InvalidateText().
1215 * Does the job for multi-line controls only.
1218 static void EDIT_ML_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT32 start
, INT32 end
)
1220 INT32 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1221 INT32 sl
= EDIT_EM_LineFromChar(wnd
, es
, start
);
1222 INT32 el
= EDIT_EM_LineFromChar(wnd
, es
, end
);
1231 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1234 sc
= start
- EDIT_EM_LineIndex(wnd
, es
, sl
);
1235 ec
= end
- EDIT_EM_LineIndex(wnd
, es
, el
);
1236 if (sl
< es
->y_offset
) {
1240 if (el
> es
->y_offset
+ vlc
) {
1241 el
= es
->y_offset
+ vlc
;
1242 ec
= EDIT_EM_LineLength(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, el
));
1244 GetClientRect32(wnd
->hwndSelf
, &rc1
);
1245 IntersectRect32(&rcWnd
, &rc1
, &es
->format_rect
);
1247 EDIT_GetLineRect(wnd
, es
, sl
, sc
, ec
, &rcLine
);
1248 if (IntersectRect32(&rcUpdate
, &rcWnd
, &rcLine
))
1249 InvalidateRect32(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1251 EDIT_GetLineRect(wnd
, es
, sl
, sc
,
1252 EDIT_EM_LineLength(wnd
, es
,
1253 EDIT_EM_LineIndex(wnd
, es
, sl
)),
1255 if (IntersectRect32(&rcUpdate
, &rcWnd
, &rcLine
))
1256 InvalidateRect32(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1257 for (l
= sl
+ 1 ; l
< el
; l
++) {
1258 EDIT_GetLineRect(wnd
, es
, l
, 0,
1259 EDIT_EM_LineLength(wnd
, es
,
1260 EDIT_EM_LineIndex(wnd
, es
, l
)),
1262 if (IntersectRect32(&rcUpdate
, &rcWnd
, &rcLine
))
1263 InvalidateRect32(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1265 EDIT_GetLineRect(wnd
, es
, el
, 0, ec
, &rcLine
);
1266 if (IntersectRect32(&rcUpdate
, &rcWnd
, &rcLine
))
1267 InvalidateRect32(wnd
->hwndSelf
, &rcUpdate
, FALSE
);
1272 /*********************************************************************
1274 * EDIT_InvalidateText
1276 * Invalidate the text from offset start upto, but not including,
1277 * offset end. Useful for (re)painting the selection.
1278 * Regions outside the linewidth are not invalidated.
1279 * end == -1 means end == TextLength.
1280 * start and end need not be ordered.
1283 static void EDIT_InvalidateText(WND
*wnd
, EDITSTATE
*es
, INT32 start
, INT32 end
)
1289 end
= lstrlen32A(es
->text
);
1291 ORDER_INT32(start
, end
);
1293 if (es
->style
& ES_MULTILINE
)
1294 EDIT_ML_InvalidateText(wnd
, es
, start
, end
);
1296 EDIT_SL_InvalidateText(wnd
, es
, start
, end
);
1300 /*********************************************************************
1304 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
1307 static BOOL32
EDIT_MakeFit(WND
*wnd
, EDITSTATE
*es
, INT32 size
)
1312 if (size
<= es
->buffer_size
)
1314 if (size
> es
->buffer_limit
) {
1315 EDIT_NOTIFY_PARENT(wnd
, EN_MAXTEXT
, "EN_MAXTEXT");
1318 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1319 if (size
> es
->buffer_limit
)
1320 size
= es
->buffer_limit
;
1322 dprintf_edit(stddeb
, "edit: EDIT_MakeFit: trying to ReAlloc to %d+1\n", size
);
1324 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
1326 if ((es
->text
= HeapReAlloc(es
->heap
, 0, es
->text
, size
+ 1)))
1327 es
->buffer_size
= MIN(HeapSize(es
->heap
, 0, es
->text
) - 1, es
->buffer_limit
);
1329 es
->buffer_size
= 0;
1330 } else if (es
->hloc32
) {
1331 if ((hNew32
= LocalReAlloc32(es
->hloc32
, size
+ 1, 0))) {
1332 dprintf_edit(stddeb
, "edit: EDIT_MakeFit: Old 32 bit handle %08x, new handle %08x\n", es
->hloc32
, hNew32
);
1333 es
->hloc32
= hNew32
;
1334 es
->buffer_size
= MIN(LocalSize32(es
->hloc32
) - 1, es
->buffer_limit
);
1336 } else if (es
->hloc16
) {
1337 if ((hNew16
= LOCAL_ReAlloc(wnd
->hInstance
, es
->hloc16
, size
+ 1, LMEM_MOVEABLE
))) {
1338 dprintf_edit(stddeb
, "edit: EDIT_MakeFit: Old 16 bit handle %08x, new handle %08x\n", es
->hloc16
, hNew16
);
1339 es
->hloc16
= hNew16
;
1340 es
->buffer_size
= MIN(LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1, es
->buffer_limit
);
1343 if (es
->buffer_size
< size
) {
1344 EDIT_LockBuffer(wnd
, es
);
1345 dprintf_edit(stddeb
, "edit: EDIT_MakeFit: FAILED ! We now have %d+1\n", es
->buffer_size
);
1346 EDIT_NOTIFY_PARENT(wnd
, EN_ERRSPACE
, "EN_ERRSPACE");
1349 EDIT_LockBuffer(wnd
, es
);
1350 dprintf_edit(stddeb
, "edit: EDIT_MakeFit: We now have %d+1\n", es
->buffer_size
);
1356 /*********************************************************************
1360 * Try to fit size + 1 bytes in the undo buffer.
1363 static BOOL32
EDIT_MakeUndoFit(WND
*wnd
, EDITSTATE
*es
, INT32 size
)
1365 if (size
<= es
->undo_buffer_size
)
1367 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
1369 dprintf_edit(stddeb
, "edit: EDIT_MakeUndoFit: trying to ReAlloc to %d+1\n", size
);
1371 if ((es
->undo_text
= HeapReAlloc(es
->heap
, 0, es
->undo_text
, size
+ 1))) {
1372 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
1373 if (es
->undo_buffer_size
< size
) {
1374 dprintf_edit(stddeb
, "edit: EDIT_MakeUndoFit: FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1383 /*********************************************************************
1388 static void EDIT_MoveBackward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1390 INT32 e
= es
->selection_end
;
1394 if ((es
->style
& ES_MULTILINE
) && e
&&
1395 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1397 if (e
&& (es
->text
[e
- 1] == '\r'))
1401 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1402 EDIT_EM_ScrollCaret(wnd
, es
);
1406 /*********************************************************************
1410 * Only for multi line controls
1411 * Move the caret one line down, on a column with the nearest
1412 * x coordinate on the screen (might be a different column).
1415 static void EDIT_MoveDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1417 INT32 s
= es
->selection_start
;
1418 INT32 e
= es
->selection_end
;
1419 BOOL32 after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1420 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1421 INT32 x
= SLOWORD(pos
);
1422 INT32 y
= SHIWORD(pos
);
1424 e
= EDIT_CharFromPos(wnd
, es
, x
, y
+ es
->line_height
, &after_wrap
);
1427 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1428 EDIT_EM_ScrollCaret(wnd
, es
);
1432 /*********************************************************************
1437 static void EDIT_MoveEnd(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1439 BOOL32 after_wrap
= FALSE
;
1442 if (es
->style
& ES_MULTILINE
)
1443 e
= EDIT_CharFromPos(wnd
, es
, 0x7fffffff,
1444 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1446 e
= lstrlen32A(es
->text
);
1447 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1448 EDIT_EM_ScrollCaret(wnd
, es
);
1452 /*********************************************************************
1457 static void EDIT_MoveForward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1459 INT32 e
= es
->selection_end
;
1463 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1464 if (es
->text
[e
] == '\n')
1466 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1470 EDIT_EM_SetSel(wnd
, es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1471 EDIT_EM_ScrollCaret(wnd
, es
);
1475 /*********************************************************************
1479 * Home key: move to beginning of line.
1482 static void EDIT_MoveHome(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1486 if (es
->style
& ES_MULTILINE
)
1487 e
= EDIT_CharFromPos(wnd
, es
, 0x80000000,
1488 HIWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1491 EDIT_EM_SetSel(wnd
, es
, e
, extend
? es
->selection_start
: e
, FALSE
);
1492 EDIT_EM_ScrollCaret(wnd
, es
);
1496 /*********************************************************************
1498 * EDIT_MovePageDown_ML
1500 * Only for multi line controls
1501 * Move the caret one page down, on a column with the nearest
1502 * x coordinate on the screen (might be a different column).
1505 static void EDIT_MovePageDown_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1507 INT32 s
= es
->selection_start
;
1508 INT32 e
= es
->selection_end
;
1509 BOOL32 after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1510 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1511 INT32 x
= SLOWORD(pos
);
1512 INT32 y
= SHIWORD(pos
);
1514 e
= EDIT_CharFromPos(wnd
, es
, x
,
1515 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1519 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1520 EDIT_EM_ScrollCaret(wnd
, es
);
1524 /*********************************************************************
1526 * EDIT_MovePageUp_ML
1528 * Only for multi line controls
1529 * Move the caret one page up, on a column with the nearest
1530 * x coordinate on the screen (might be a different column).
1533 static void EDIT_MovePageUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1535 INT32 s
= es
->selection_start
;
1536 INT32 e
= es
->selection_end
;
1537 BOOL32 after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1538 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1539 INT32 x
= SLOWORD(pos
);
1540 INT32 y
= SHIWORD(pos
);
1542 e
= EDIT_CharFromPos(wnd
, es
, x
,
1543 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1547 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1548 EDIT_EM_ScrollCaret(wnd
, es
);
1552 /*********************************************************************
1556 * Only for multi line controls
1557 * Move the caret one line up, on a column with the nearest
1558 * x coordinate on the screen (might be a different column).
1561 static void EDIT_MoveUp_ML(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1563 INT32 s
= es
->selection_start
;
1564 INT32 e
= es
->selection_end
;
1565 BOOL32 after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1566 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, e
, after_wrap
);
1567 INT32 x
= SLOWORD(pos
);
1568 INT32 y
= SHIWORD(pos
);
1570 e
= EDIT_CharFromPos(wnd
, es
, x
, y
- es
->line_height
, &after_wrap
);
1573 EDIT_EM_SetSel(wnd
, es
, s
, e
, after_wrap
);
1574 EDIT_EM_ScrollCaret(wnd
, es
);
1578 /*********************************************************************
1580 * EDIT_MoveWordBackward
1583 static void EDIT_MoveWordBackward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1585 INT32 s
= es
->selection_start
;
1586 INT32 e
= es
->selection_end
;
1591 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1592 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1593 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1596 li
= EDIT_EM_LineIndex(wnd
, es
, l
- 1);
1597 e
= li
+ EDIT_EM_LineLength(wnd
, es
, li
);
1600 e
= li
+ (INT32
)EDIT_CallWordBreakProc(wnd
, es
,
1601 li
, e
- li
, ll
, WB_LEFT
);
1605 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1606 EDIT_EM_ScrollCaret(wnd
, es
);
1610 /*********************************************************************
1612 * EDIT_MoveWordForward
1615 static void EDIT_MoveWordForward(WND
*wnd
, EDITSTATE
*es
, BOOL32 extend
)
1617 INT32 s
= es
->selection_start
;
1618 INT32 e
= es
->selection_end
;
1623 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
1624 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
1625 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1627 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1628 e
= EDIT_EM_LineIndex(wnd
, es
, l
+ 1);
1630 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
,
1631 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1635 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
1636 EDIT_EM_ScrollCaret(wnd
, es
);
1640 /*********************************************************************
1645 static void EDIT_PaintLine(WND
*wnd
, EDITSTATE
*es
, HDC32 dc
, INT32 line
, BOOL32 rev
)
1647 INT32 s
= es
->selection_start
;
1648 INT32 e
= es
->selection_end
;
1655 if (es
->style
& ES_MULTILINE
) {
1656 INT32 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1657 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
1662 dprintf_edit(stddeb
, "edit: EDIT_PaintLine: line=%d\n", line
);
1664 pos
= EDIT_EM_PosFromChar(wnd
, es
, EDIT_EM_LineIndex(wnd
, es
, line
), FALSE
);
1667 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1668 ll
= EDIT_EM_LineLength(wnd
, es
, li
);
1669 s
= es
->selection_start
;
1670 e
= es
->selection_end
;
1672 s
= MIN(li
+ ll
, MAX(li
, s
));
1673 e
= MIN(li
+ ll
, MAX(li
, e
));
1674 if (rev
&& (s
!= e
) &&
1675 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
1676 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
1677 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1678 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1680 x
+= EDIT_PaintText(wnd
, es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
1684 /*********************************************************************
1689 static INT32
EDIT_PaintText(WND
*wnd
, EDITSTATE
*es
, HDC32 dc
, INT32 x
, INT32 y
, INT32 line
, INT32 col
, INT32 count
, BOOL32 rev
)
1699 BkColor
= GetBkColor32(dc
);
1700 TextColor
= GetTextColor32(dc
);
1702 SetBkColor32(dc
, GetSysColor32(COLOR_HIGHLIGHT
));
1703 SetTextColor32(dc
, GetSysColor32(COLOR_HIGHLIGHTTEXT
));
1705 li
= EDIT_EM_LineIndex(wnd
, es
, line
);
1706 if (es
->style
& ES_MULTILINE
) {
1707 ret
= (INT32
)LOWORD(TabbedTextOut32A(dc
, x
, y
, es
->text
+ li
+ col
, count
,
1708 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
1710 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
1711 TextOut32A(dc
, x
, y
, text
+ li
+ col
, count
);
1712 GetTextExtentPoint32A(dc
, text
+ li
+ col
, count
, &size
);
1714 if (es
->style
& ES_PASSWORD
)
1715 HeapFree(es
->heap
, 0, text
);
1718 SetBkColor32(dc
, BkColor
);
1719 SetTextColor32(dc
, TextColor
);
1725 /*********************************************************************
1730 static void EDIT_EM_ScrollCaret(WND
*wnd
, EDITSTATE
*es
)
1732 if (es
->style
& ES_MULTILINE
) {
1737 INT32 cw
= es
->char_width
;
1742 l
= EDIT_EM_LineFromChar(wnd
, es
, es
->selection_end
);
1743 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
1744 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1745 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1746 if (l
>= es
->y_offset
+ vlc
)
1747 dy
= l
- vlc
+ 1 - es
->y_offset
;
1748 if (l
< es
->y_offset
)
1749 dy
= l
- es
->y_offset
;
1750 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1751 if (x
< es
->format_rect
.left
)
1752 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1753 if (x
> es
->format_rect
.right
)
1754 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1756 EDIT_EM_LineScroll(wnd
, es
, dx
, dy
);
1762 if (!(es
->style
& ES_AUTOHSCROLL
))
1765 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
1766 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1767 if (x
< es
->format_rect
.left
) {
1768 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1771 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
1772 } while ((x
< goal
) && es
->x_offset
);
1773 /* FIXME: use ScrollWindow() somehow to improve performance */
1774 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
1775 } else if (x
> es
->format_rect
.right
) {
1777 INT32 len
= lstrlen32A(es
->text
);
1778 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1781 x
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, FALSE
));
1782 x_last
= SLOWORD(EDIT_EM_PosFromChar(wnd
, es
, len
, FALSE
));
1783 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1784 /* FIXME: use ScrollWindow() somehow to improve performance */
1785 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
1791 /*********************************************************************
1795 * note: this is not (exactly) the handler called on EM_SETRECTNP
1796 * it is also used to set the rect of a single line control
1799 static void EDIT_SetRectNP(WND
*wnd
, EDITSTATE
*es
, LPRECT32 rc
)
1801 CopyRect32(&es
->format_rect
, rc
);
1802 if (es
->style
& WS_BORDER
) {
1803 INT32 bw
= GetSystemMetrics32(SM_CXBORDER
) + 1;
1804 es
->format_rect
.left
+= bw
;
1805 es
->format_rect
.top
+= bw
;
1806 es
->format_rect
.right
-= bw
;
1807 es
->format_rect
.bottom
-= bw
;
1809 es
->format_rect
.left
+= es
->left_margin
;
1810 es
->format_rect
.right
-= es
->right_margin
;
1811 es
->format_rect
.right
= MAX(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
1812 if (es
->style
& ES_MULTILINE
)
1813 es
->format_rect
.bottom
= es
->format_rect
.top
+
1814 MAX(1, (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
) * es
->line_height
;
1816 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
1817 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
1818 EDIT_BuildLineDefs_ML(wnd
, es
);
1822 /*********************************************************************
1827 static void EDIT_UnlockBuffer(WND
*wnd
, EDITSTATE
*es
, BOOL32 force
)
1830 fprintf(stderr
, "edit: UnlockBuffer() without an EDITSTATE ... please report\n");
1833 if (!(es
->style
& ES_MULTILINE
))
1835 if (!es
->lock_count
) {
1836 fprintf(stderr
, "edit: UnlockBuffer() with lock_count == 0 ... please report\n");
1840 fprintf(stderr
, "edit: UnlockBuffer() with es->text == 0 ... please report\n");
1843 if (force
|| (es
->lock_count
== 1)) {
1845 LocalUnlock32(es
->hloc32
);
1847 } else if (es
->hloc16
) {
1848 LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
);
1856 /*********************************************************************
1858 * EDIT_WordBreakProc
1860 * Find the beginning of words.
1861 * Note: unlike the specs for a WordBreakProc, this function only
1862 * allows to be called without linebreaks between s[0] upto
1863 * s[count - 1]. Remember it is only called
1864 * internally, so we can decide this for ourselves.
1867 static INT32
EDIT_WordBreakProc(LPSTR s
, INT32 index
, INT32 count
, INT32 action
)
1871 dprintf_edit(stddeb
, "edit: EDIT_WordBreakProc: s=%p, index=%u"
1872 ", count=%u, action=%d\n", s
, index
, count
, action
);
1880 if (s
[index
] == ' ') {
1881 while (index
&& (s
[index
] == ' '))
1884 while (index
&& (s
[index
] != ' '))
1886 if (s
[index
] == ' ')
1890 while (index
&& (s
[index
] != ' '))
1892 if (s
[index
] == ' ')
1902 if (s
[index
] == ' ')
1903 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1905 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1907 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1911 case WB_ISDELIMITER
:
1912 ret
= (s
[index
] == ' ');
1915 fprintf(stderr
, "edit: EDIT_WordBreakProc: unknown action code, please report !\n");
1922 /*********************************************************************
1926 * FIXME: do the specs mean to return LineIndex or LineNumber ???
1927 * Let's assume LineIndex is meant
1928 * FIXME: do the specs mean to return -1 if outside client area or
1929 * if outside formatting rectangle ???
1932 static LRESULT
EDIT_EM_CharFromPos(WND
*wnd
, EDITSTATE
*es
, INT32 x
, INT32 y
)
1940 GetClientRect32(wnd
->hwndSelf
, &rc
);
1941 if (!PtInRect32(&rc
, pt
))
1944 index
= EDIT_CharFromPos(wnd
, es
, x
, y
, NULL
);
1945 return MAKELONG(index
, EDIT_EM_LineIndex(wnd
, es
,
1946 EDIT_EM_LineFromChar(wnd
, es
, index
)));
1950 /*********************************************************************
1955 static BOOL32
EDIT_EM_FmtLines(WND
*wnd
, EDITSTATE
*es
, BOOL32 add_eol
)
1957 fprintf(stdnimp
, "edit: EM_FMTLINES: message not implemented\n");
1962 /*********************************************************************
1966 * Hopefully this won't fire back at us.
1967 * We always start with a fixed buffer in our own heap.
1968 * However, with this message a 32 bit application requests
1969 * a handle to 32 bit moveable local heap memory, where it expects
1971 * It's a pitty that from this moment on we have to use this
1972 * local heap, because applications may rely on the handle
1975 * In this function we'll try to switch to local heap.
1978 static HLOCAL32
EDIT_EM_GetHandle(WND
*wnd
, EDITSTATE
*es
)
1984 if (!(es
->style
& ES_MULTILINE
))
1989 else if (es
->hloc16
)
1990 return (HLOCAL32
)es
->hloc16
;
1992 if (!(newBuf
= LocalAlloc32(LMEM_MOVEABLE
, lstrlen32A(es
->text
) + 1))) {
1993 fprintf(stderr
, "edit: EM_GETHANDLE: could not allocate new 32 bit buffer\n");
1996 newSize
= MIN(LocalSize32(newBuf
) - 1, es
->buffer_limit
);
1997 if (!(newText
= LocalLock32(newBuf
))) {
1998 fprintf(stderr
, "edit: EM_GETHANDLE: could not lock new 32 bit buffer\n");
1999 LocalFree32(newBuf
);
2002 lstrcpy32A(newText
, es
->text
);
2003 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2005 HeapFree(es
->heap
, 0, es
->text
);
2006 es
->hloc32
= newBuf
;
2007 es
->hloc16
= (HLOCAL16
)NULL
;
2008 es
->buffer_size
= newSize
;
2010 EDIT_LockBuffer(wnd
, es
);
2011 dprintf_edit(stddeb
, "edit: EM_GETHANDLE: switched to 32 bit local heap\n");
2017 /*********************************************************************
2021 * Hopefully this won't fire back at us.
2022 * We always start with a buffer in 32 bit linear memory.
2023 * However, with this message a 16 bit application requests
2024 * a handle of 16 bit local heap memory, where it expects to find
2026 * It's a pitty that from this moment on we have to use this
2027 * local heap, because applications may rely on the handle
2030 * In this function we'll try to switch to local heap.
2032 static HLOCAL16
EDIT_EM_GetHandle16(WND
*wnd
, EDITSTATE
*es
)
2038 if (!(es
->style
& ES_MULTILINE
))
2044 if (!LOCAL_HeapSize(wnd
->hInstance
)) {
2045 if (!LocalInit(wnd
->hInstance
, 0,
2046 GlobalSize16(wnd
->hInstance
))) {
2047 fprintf(stderr
, "edit: EM_GETHANDLE: could not initialize local heap\n");
2050 dprintf_edit(stddeb
, "edit: EM_GETHANDLE: local heap initialized\n");
2052 if (!(newBuf
= LOCAL_Alloc(wnd
->hInstance
, LMEM_MOVEABLE
, lstrlen32A(es
->text
) + 1))) {
2053 fprintf(stderr
, "edit: EM_GETHANDLE: could not allocate new 16 bit buffer\n");
2056 newSize
= MIN(LOCAL_Size(wnd
->hInstance
, newBuf
) - 1, es
->buffer_limit
);
2057 if (!(newText
= LOCAL_Lock(wnd
->hInstance
, newBuf
))) {
2058 fprintf(stderr
, "edit: EM_GETHANDLE: could not lock new 16 bit buffer\n");
2059 LOCAL_Free(wnd
->hInstance
, newBuf
);
2062 lstrcpy32A(newText
, es
->text
);
2063 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2065 HeapFree(es
->heap
, 0, es
->text
);
2066 else if (es
->hloc32
) {
2067 while (LocalFree32(es
->hloc32
)) ;
2068 LocalFree32(es
->hloc32
);
2070 es
->hloc32
= (HLOCAL32
)NULL
;
2071 es
->hloc16
= newBuf
;
2072 es
->buffer_size
= newSize
;
2074 EDIT_LockBuffer(wnd
, es
);
2075 dprintf_edit(stddeb
, "edit: EM_GETHANDLE: switched to 16 bit buffer\n");
2081 /*********************************************************************
2086 static INT32
EDIT_EM_GetLine(WND
*wnd
, EDITSTATE
*es
, INT32 line
, LPSTR lpch
)
2092 if (es
->style
& ES_MULTILINE
) {
2093 if (line
>= es
->line_count
)
2097 src
= es
->text
+ EDIT_EM_LineIndex(wnd
, es
, line
);
2098 len
= MIN(*(WORD
*)lpch
, EDIT_EM_LineLength(wnd
, es
, line
));
2099 for (i
= 0 ; i
< len
; i
++) {
2104 return (LRESULT
)len
;
2108 /*********************************************************************
2113 static LRESULT
EDIT_EM_GetSel(WND
*wnd
, EDITSTATE
*es
, LPUINT32 start
, LPUINT32 end
)
2115 UINT32 s
= es
->selection_start
;
2116 UINT32 e
= es
->selection_end
;
2123 return MAKELONG(s
, e
);
2127 /*********************************************************************
2131 * FIXME: is this right ? (or should it be only VSCROLL)
2132 * (and maybe only for edit controls that really have their
2133 * own scrollbars) (and maybe only for multiline controls ?)
2134 * All in all: very poorly documented
2136 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2137 * WM_VSCROLL handlers
2140 static LRESULT
EDIT_EM_GetThumb(WND
*wnd
, EDITSTATE
*es
)
2142 return MAKELONG(EDIT_WM_VScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0),
2143 EDIT_WM_HScroll(wnd
, es
, EM_GETTHUMB16
, 0, 0));
2147 /*********************************************************************
2152 static INT32
EDIT_EM_LineFromChar(WND
*wnd
, EDITSTATE
*es
, INT32 index
)
2157 if (!(es
->style
& ES_MULTILINE
))
2159 if (index
> lstrlen32A(es
->text
))
2160 return es
->line_count
- 1;
2162 index
= MIN(es
->selection_start
, es
->selection_end
);
2165 line_def
= es
->first_line_def
;
2166 index
-= line_def
->length
;
2167 while ((index
>= 0) && line_def
->next
) {
2169 line_def
= line_def
->next
;
2170 index
-= line_def
->length
;
2176 /*********************************************************************
2181 static INT32
EDIT_EM_LineIndex(WND
*wnd
, EDITSTATE
*es
, INT32 line
)
2186 if (!(es
->style
& ES_MULTILINE
))
2188 if (line
>= es
->line_count
)
2192 line_def
= es
->first_line_def
;
2194 INT32 index
= es
->selection_end
- line_def
->length
;
2195 while ((index
>= 0) && line_def
->next
) {
2196 line_index
+= line_def
->length
;
2197 line_def
= line_def
->next
;
2198 index
-= line_def
->length
;
2202 line_index
+= line_def
->length
;
2203 line_def
= line_def
->next
;
2211 /*********************************************************************
2216 static INT32
EDIT_EM_LineLength(WND
*wnd
, EDITSTATE
*es
, INT32 index
)
2220 if (!(es
->style
& ES_MULTILINE
))
2221 return lstrlen32A(es
->text
);
2225 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2226 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2227 return es->selection_start - es->line_defs[sl].offset +
2228 es->line_defs[el].offset +
2229 es->line_defs[el].length - es->selection_end;
2233 line_def
= es
->first_line_def
;
2234 index
-= line_def
->length
;
2235 while ((index
>= 0) && line_def
->next
) {
2236 line_def
= line_def
->next
;
2237 index
-= line_def
->length
;
2239 return line_def
->net_length
;
2243 /*********************************************************************
2247 * FIXME: dx is in average character widths
2248 * However, we assume it is in pixels when we use this
2249 * function internally
2252 static BOOL32
EDIT_EM_LineScroll(WND
*wnd
, EDITSTATE
*es
, INT32 dx
, INT32 dy
)
2256 if (!(es
->style
& ES_MULTILINE
))
2259 if (-dx
> es
->x_offset
)
2261 if (dx
> es
->text_width
- es
->x_offset
)
2262 dx
= es
->text_width
- es
->x_offset
;
2263 nyoff
= MAX(0, es
->y_offset
+ dy
);
2264 if (nyoff
>= es
->line_count
)
2265 nyoff
= es
->line_count
- 1;
2266 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
2270 GetClientRect32(wnd
->hwndSelf
, &rc1
);
2271 IntersectRect32(&rc
, &rc1
, &es
->format_rect
);
2272 ScrollWindowEx32(wnd
->hwndSelf
, -dx
, dy
,
2273 NULL
, &rc
, (HRGN32
)NULL
, NULL
, SW_INVALIDATE
);
2274 es
->y_offset
= nyoff
;
2277 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
2278 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
2279 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
2280 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2285 /*********************************************************************
2290 static LRESULT
EDIT_EM_PosFromChar(WND
*wnd
, EDITSTATE
*es
, INT32 index
, BOOL32 after_wrap
)
2292 INT32 len
= lstrlen32A(es
->text
);
2298 HFONT32 old_font
= 0;
2301 index
= MIN(index
, len
);
2302 dc
= GetDC32(wnd
->hwndSelf
);
2304 old_font
= SelectObject32(dc
, es
->font
);
2305 if (es
->style
& ES_MULTILINE
) {
2306 l
= EDIT_EM_LineFromChar(wnd
, es
, index
);
2307 y
= (l
- es
->y_offset
) * es
->line_height
;
2308 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2309 if (after_wrap
&& (li
== index
) && l
) {
2311 LINEDEF
*line_def
= es
->first_line_def
;
2313 line_def
= line_def
->next
;
2316 if (line_def
->ending
== END_WRAP
) {
2318 y
-= es
->line_height
;
2319 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
2322 x
= LOWORD(GetTabbedTextExtent32A(dc
, es
->text
+ li
, index
- li
,
2323 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
2325 LPSTR text
= EDIT_GetPasswordPointer_SL(wnd
, es
);
2326 if (index
< es
->x_offset
) {
2327 GetTextExtentPoint32A(dc
, text
+ index
,
2328 es
->x_offset
- index
, &size
);
2331 GetTextExtentPoint32A(dc
, text
+ es
->x_offset
,
2332 index
- es
->x_offset
, &size
);
2336 if (es
->style
& ES_PASSWORD
)
2337 HeapFree(es
->heap
, 0 ,text
);
2339 x
+= es
->format_rect
.left
;
2340 y
+= es
->format_rect
.top
;
2342 SelectObject32(dc
, old_font
);
2343 ReleaseDC32(wnd
->hwndSelf
, dc
);
2344 return MAKELONG((INT16
)x
, (INT16
)y
);
2348 /*********************************************************************
2352 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2355 static void EDIT_EM_ReplaceSel(WND
*wnd
, EDITSTATE
*es
, BOOL32 can_undo
, LPCSTR lpsz_replace
)
2357 INT32 strl
= lstrlen32A(lpsz_replace
);
2358 INT32 tl
= lstrlen32A(es
->text
);
2365 s
= es
->selection_start
;
2366 e
= es
->selection_end
;
2368 if ((s
== e
) && !strl
)
2373 if (!EDIT_MakeFit(wnd
, es
, tl
- (e
- s
) + strl
))
2377 /* there is something to be deleted */
2379 utl
= lstrlen32A(es
->undo_text
);
2380 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2381 /* undo-buffer is extended to the right */
2382 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2383 lstrcpyn32A(es
->undo_text
+ utl
, es
->text
+ s
, e
- s
+ 1);
2384 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2385 /* undo-buffer is extended to the left */
2386 EDIT_MakeUndoFit(wnd
, es
, utl
+ e
- s
);
2387 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2389 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2390 p
[i
] = (es
->text
+ s
)[i
];
2391 es
->undo_position
= s
;
2393 /* new undo-buffer */
2394 EDIT_MakeUndoFit(wnd
, es
, e
- s
);
2395 lstrcpyn32A(es
->undo_text
, es
->text
+ s
, e
- s
+ 1);
2396 es
->undo_position
= s
;
2398 /* any deletion makes the old insertion-undo invalid */
2399 es
->undo_insert_count
= 0;
2401 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2404 lstrcpy32A(es
->text
+ s
, es
->text
+ e
);
2407 /* there is an insertion */
2409 if ((s
== es
->undo_position
) ||
2410 ((es
->undo_insert_count
) &&
2411 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2413 * insertion is new and at delete position or
2414 * an extension to either left or right
2416 es
->undo_insert_count
+= strl
;
2418 /* new insertion undo */
2419 es
->undo_position
= s
;
2420 es
->undo_insert_count
= strl
;
2421 /* new insertion makes old delete-buffer invalid */
2422 *es
->undo_text
= '\0';
2425 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2428 tl
= lstrlen32A(es
->text
);
2429 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2431 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2432 p
[i
] = lpsz_replace
[i
];
2433 if(es
->style
& ES_UPPERCASE
)
2434 CharUpperBuff32A(p
, strl
);
2435 else if(es
->style
& ES_LOWERCASE
)
2436 CharLowerBuff32A(p
, strl
);
2439 /* FIXME: really inefficient */
2440 if (es
->style
& ES_MULTILINE
)
2441 EDIT_BuildLineDefs_ML(wnd
, es
);
2443 EDIT_EM_SetSel(wnd
, es
, s
, s
, FALSE
);
2444 es
->flags
|= EF_MODIFIED
;
2445 es
->flags
|= EF_UPDATE
;
2446 EDIT_EM_ScrollCaret(wnd
, es
);
2448 /* FIXME: really inefficient */
2449 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
2453 /*********************************************************************
2458 static LRESULT
EDIT_EM_Scroll(WND
*wnd
, EDITSTATE
*es
, INT32 action
)
2462 if (!(es
->style
& ES_MULTILINE
))
2463 return (LRESULT
)FALSE
;
2473 if (es
->y_offset
< es
->line_count
- 1)
2478 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2481 if (es
->y_offset
< es
->line_count
- 1)
2482 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
2485 return (LRESULT
)FALSE
;
2488 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
2489 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
2491 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
2495 /*********************************************************************
2499 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2502 static void EDIT_EM_SetHandle(WND
*wnd
, EDITSTATE
*es
, HLOCAL32 hloc
)
2504 if (!(es
->style
& ES_MULTILINE
))
2508 fprintf(stderr
, "edit: EM_SETHANDLE called with NULL handle\n");
2512 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2514 * old buffer is freed by caller, unless
2515 * it is still in our own heap. (in that case
2516 * we free it, correcting the buggy caller.)
2519 HeapFree(es
->heap
, 0, es
->text
);
2521 es
->hloc16
= (HLOCAL16
)NULL
;
2524 es
->buffer_size
= LocalSize32(es
->hloc32
) - 1;
2525 EDIT_LockBuffer(wnd
, es
);
2527 es
->x_offset
= es
->y_offset
= 0;
2528 es
->selection_start
= es
->selection_end
= 0;
2529 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2530 es
->flags
&= ~EF_MODIFIED
;
2531 es
->flags
&= ~EF_UPDATE
;
2532 EDIT_BuildLineDefs_ML(wnd
, es
);
2533 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
2534 EDIT_EM_ScrollCaret(wnd
, es
);
2538 /*********************************************************************
2542 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2545 static void EDIT_EM_SetHandle16(WND
*wnd
, EDITSTATE
*es
, HLOCAL16 hloc
)
2547 if (!(es
->style
& ES_MULTILINE
))
2551 fprintf(stderr
, "edit: EM_SETHANDLE called with NULL handle\n");
2555 EDIT_UnlockBuffer(wnd
, es
, TRUE
);
2557 * old buffer is freed by caller, unless
2558 * it is still in our own heap. (in that case
2559 * we free it, correcting the buggy caller.)
2562 HeapFree(es
->heap
, 0, es
->text
);
2565 es
->hloc32
= (HLOCAL32
)NULL
;
2567 es
->buffer_size
= LOCAL_Size(wnd
->hInstance
, es
->hloc16
) - 1;
2568 EDIT_LockBuffer(wnd
, es
);
2570 es
->x_offset
= es
->y_offset
= 0;
2571 es
->selection_start
= es
->selection_end
= 0;
2572 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2573 es
->flags
&= ~EF_MODIFIED
;
2574 es
->flags
&= ~EF_UPDATE
;
2575 EDIT_BuildLineDefs_ML(wnd
, es
);
2576 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
2577 EDIT_EM_ScrollCaret(wnd
, es
);
2581 /*********************************************************************
2585 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2586 * However, the windows version is not complied to yet in all of edit.c
2589 static void EDIT_EM_SetLimitText(WND
*wnd
, EDITSTATE
*es
, INT32 limit
)
2591 if (es
->style
& ES_MULTILINE
) {
2593 es
->buffer_limit
= MIN(limit
, BUFLIMIT_MULTI
);
2595 es
->buffer_limit
= BUFLIMIT_MULTI
;
2598 es
->buffer_limit
= MIN(limit
, BUFLIMIT_SINGLE
);
2600 es
->buffer_limit
= BUFLIMIT_SINGLE
;
2605 /*********************************************************************
2610 static void EDIT_EM_SetMargins(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 left
, INT32 right
)
2612 if (action
& EC_USEFONTINFO
) {
2613 if (es
->style
& ES_MULTILINE
) {
2615 * FIXME: do some GetABCCharWidth, or so
2616 * This is just preliminary
2618 es
->left_margin
= es
->right_margin
= es
->char_width
/4;
2620 es
->left_margin
= es
->right_margin
= es
->char_width
/4;
2622 if (action
& EC_LEFTMARGIN
)
2623 es
->left_margin
= left
;
2624 if (action
& EC_RIGHTMARGIN
)
2625 es
->right_margin
= right
;
2627 dprintf_edit(stddeb
, "EDIT_EM_SetMargins: left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2631 /*********************************************************************
2633 * EM_SETPASSWORDCHAR
2636 static void EDIT_EM_SetPasswordChar(WND
*wnd
, EDITSTATE
*es
, CHAR c
)
2638 if (es
->style
& ES_MULTILINE
)
2641 if (es
->password_char
== c
)
2644 es
->password_char
= c
;
2646 wnd
->dwStyle
|= ES_PASSWORD
;
2647 es
->style
|= ES_PASSWORD
;
2649 wnd
->dwStyle
&= ~ES_PASSWORD
;
2650 es
->style
&= ~ES_PASSWORD
;
2652 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
2656 /*********************************************************************
2660 * note: unlike the specs say: the order of start and end
2661 * _is_ preserved in Windows. (i.e. start can be > end)
2662 * In other words: this handler is OK
2665 static void EDIT_EM_SetSel(WND
*wnd
, EDITSTATE
*es
, UINT32 start
, UINT32 end
, BOOL32 after_wrap
)
2667 UINT32 old_start
= es
->selection_start
;
2668 UINT32 old_end
= es
->selection_end
;
2669 UINT32 len
= lstrlen32A(es
->text
);
2672 start
= es
->selection_end
;
2673 end
= es
->selection_end
;
2675 start
= MIN(start
, len
);
2676 end
= MIN(end
, len
);
2678 es
->selection_start
= start
;
2679 es
->selection_end
= end
;
2681 es
->flags
|= EF_AFTER_WRAP
;
2683 es
->flags
&= ~EF_AFTER_WRAP
;
2684 if (es
->flags
& EF_FOCUSED
) {
2685 LRESULT pos
= EDIT_EM_PosFromChar(wnd
, es
, end
, after_wrap
);
2686 SetCaretPos32(SLOWORD(pos
), SHIWORD(pos
));
2688 /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
2689 ORDER_UINT32(start
, end
);
2690 ORDER_UINT32(end
, old_end
);
2691 ORDER_UINT32(start
, old_start
);
2692 ORDER_UINT32(old_start
, old_end
);
2693 if (end
!= old_start
)
2697 * ORDER_UINT32(end, old_start);
2698 * EDIT_InvalidateText(wnd, es, start, end);
2699 * EDIT_InvalidateText(wnd, es, old_start, old_end);
2700 * in place of the following if statement.
2702 if (old_start
> end
)
2704 EDIT_InvalidateText(wnd
, es
, start
, end
);
2705 EDIT_InvalidateText(wnd
, es
, old_start
, old_end
);
2709 EDIT_InvalidateText(wnd
, es
, start
, old_start
);
2710 EDIT_InvalidateText(wnd
, es
, end
, old_end
);
2713 else EDIT_InvalidateText(wnd
, es
, start
, old_end
);
2717 /*********************************************************************
2722 static BOOL32
EDIT_EM_SetTabStops(WND
*wnd
, EDITSTATE
*es
, INT32 count
, LPINT32 tabs
)
2724 if (!(es
->style
& ES_MULTILINE
))
2727 HeapFree(es
->heap
, 0, es
->tabs
);
2728 es
->tabs_count
= count
;
2732 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT32
));
2733 memcpy(es
->tabs
, tabs
, count
* sizeof(INT32
));
2739 /*********************************************************************
2744 static BOOL32
EDIT_EM_SetTabStops16(WND
*wnd
, EDITSTATE
*es
, INT32 count
, LPINT16 tabs
)
2746 if (!(es
->style
& ES_MULTILINE
))
2749 HeapFree(es
->heap
, 0, es
->tabs
);
2750 es
->tabs_count
= count
;
2755 es
->tabs
= HeapAlloc(es
->heap
, 0, count
* sizeof(INT32
));
2756 for (i
= 0 ; i
< count
; i
++)
2757 es
->tabs
[i
] = *tabs
++;
2763 /*********************************************************************
2765 * EM_SETWORDBREAKPROC
2768 static void EDIT_EM_SetWordBreakProc(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC32A wbp
)
2770 if (es
->word_break_proc32A
== wbp
)
2773 es
->word_break_proc32A
= wbp
;
2774 es
->word_break_proc16
= NULL
;
2775 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2776 EDIT_BuildLineDefs_ML(wnd
, es
);
2777 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
2782 /*********************************************************************
2784 * EM_SETWORDBREAKPROC16
2787 static void EDIT_EM_SetWordBreakProc16(WND
*wnd
, EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
2789 if (es
->word_break_proc16
== wbp
)
2792 es
->word_break_proc32A
= NULL
;
2793 es
->word_break_proc16
= wbp
;
2794 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2795 EDIT_BuildLineDefs_ML(wnd
, es
);
2796 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
2801 /*********************************************************************
2806 static BOOL32
EDIT_EM_Undo(WND
*wnd
, EDITSTATE
*es
)
2808 INT32 ulength
= lstrlen32A(es
->undo_text
);
2809 LPSTR utext
= HeapAlloc(es
->heap
, 0, ulength
+ 1);
2811 lstrcpy32A(utext
, es
->undo_text
);
2813 dprintf_edit(stddeb
, "edit: before UNDO:insertion length = %d, deletion buffer = %s\n",
2814 es
->undo_insert_count
, utext
);
2816 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2817 EDIT_EM_EmptyUndoBuffer(wnd
, es
);
2818 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, utext
);
2819 EDIT_EM_SetSel(wnd
, es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2820 HeapFree(es
->heap
, 0, utext
);
2822 dprintf_edit(stddeb
, "edit: after UNDO: insertion length = %d, deletion buffer = %s\n",
2823 es
->undo_insert_count
, es
->undo_text
);
2829 /*********************************************************************
2834 static void EDIT_WM_Char(WND
*wnd
, EDITSTATE
*es
, CHAR c
, DWORD key_data
)
2839 if (es
->style
& ES_MULTILINE
) {
2840 if (es
->style
& ES_READONLY
) {
2841 EDIT_MoveHome(wnd
, es
, FALSE
);
2842 EDIT_MoveDown_ML(wnd
, es
, FALSE
);
2844 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\r\n");
2848 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2849 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, "\t");
2852 if (!(es
->style
& ES_READONLY
) && ((BYTE
)c
>= ' ') && (c
!= 127)) {
2856 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, str
);
2863 /*********************************************************************
2868 static void EDIT_WM_Command(WND
*wnd
, EDITSTATE
*es
, INT32 code
, INT32 id
, HWND32 control
)
2870 if (code
|| control
)
2875 EDIT_EM_Undo(wnd
, es
);
2878 EDIT_WM_Cut(wnd
, es
);
2881 EDIT_WM_Copy(wnd
, es
);
2884 EDIT_WM_Paste(wnd
, es
);
2887 EDIT_WM_Clear(wnd
, es
);
2890 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
2891 EDIT_EM_ScrollCaret(wnd
, es
);
2894 dprintf_edit(stddeb
, "edit: unknown menu item, please report\n");
2900 /*********************************************************************
2904 * Note: the resource files resource/sysres_??.rc cannot define a
2905 * single popup menu. Hence we use a (dummy) menubar
2906 * containing the single popup menu as its first item.
2908 * FIXME: the message identifiers have been chosen arbitrarily,
2909 * hence we use MF_BYPOSITION.
2910 * We might as well use the "real" values (anybody knows ?)
2911 * The menu definition is in resources/sysres_??.rc.
2912 * Once these are OK, we better use MF_BYCOMMAND here
2913 * (as we do in EDIT_WM_Command()).
2916 static void EDIT_WM_ContextMenu(WND
*wnd
, EDITSTATE
*es
, HWND32 hwnd
, INT32 x
, INT32 y
)
2918 HMENU32 menu
= LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU
));
2919 HMENU32 popup
= GetSubMenu32(menu
, 0);
2920 UINT32 start
= es
->selection_start
;
2921 UINT32 end
= es
->selection_end
;
2923 ORDER_UINT32(start
, end
);
2926 EnableMenuItem32(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(wnd
, es
) ? MF_ENABLED
: MF_GRAYED
));
2928 EnableMenuItem32(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2930 EnableMenuItem32(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
2932 EnableMenuItem32(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable32(CF_TEXT
) ? MF_ENABLED
: MF_GRAYED
));
2934 EnableMenuItem32(popup
, 5, MF_BYPOSITION
| ((end
- start
) ? MF_ENABLED
: MF_GRAYED
));
2936 EnableMenuItem32(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= lstrlen32A(es
->text
)) ? MF_ENABLED
: MF_GRAYED
));
2938 TrackPopupMenu32(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, wnd
->hwndSelf
, NULL
);
2939 DestroyMenu32(menu
);
2943 /*********************************************************************
2947 * FIXME: replace with 32 bit calls as soon as they are implemented
2948 * in the clipboard code
2951 static void EDIT_WM_Copy(WND
*wnd
, EDITSTATE
*es
)
2953 INT32 s
= es
->selection_start
;
2954 INT32 e
= es
->selection_end
;
2961 hdst
= GlobalAlloc16(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
2962 dst
= GlobalLock16(hdst
);
2963 lstrcpyn32A(dst
, es
->text
+ s
, e
- s
+ 1);
2964 GlobalUnlock16(hdst
);
2965 OpenClipboard32(wnd
->hwndSelf
);
2967 SetClipboardData16(CF_TEXT
, hdst
);
2972 /*********************************************************************
2977 static LRESULT
EDIT_WM_Create(WND
*wnd
, LPCREATESTRUCT32A cs
)
2981 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
2983 *(EDITSTATE
**)wnd
->wExtra
= es
;
2984 if (!(es
->heap
= HeapCreate(0, 0x10000, 0)))
2986 es
->style
= cs
->style
;
2988 /* remove the WS_CAPTION style if it has been set - this is really a */
2989 /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
2990 if ((es
->style
& WS_BORDER
) && (es
->style
& WS_DLGFRAME
))
2991 es
->style
^= WS_DLGFRAME
;
2993 if (es
->style
& ES_MULTILINE
) {
2994 es
->buffer_size
= BUFSTART_MULTI
;
2995 es
->buffer_limit
= BUFLIMIT_MULTI
;
2996 if (es
->style
& WS_VSCROLL
)
2997 es
->style
|= ES_AUTOVSCROLL
;
2998 if (es
->style
& WS_HSCROLL
)
2999 es
->style
|= ES_AUTOHSCROLL
;
3000 es
->style
&= ~ES_PASSWORD
;
3001 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
3002 if (es
->style
& ES_RIGHT
)
3003 es
->style
&= ~ES_CENTER
;
3004 es
->style
&= ~WS_HSCROLL
;
3005 es
->style
&= ~ES_AUTOHSCROLL
;
3008 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
3009 es
->style
|= ES_AUTOVSCROLL
;
3011 es
->buffer_size
= BUFSTART_SINGLE
;
3012 es
->buffer_limit
= BUFLIMIT_SINGLE
;
3013 es
->style
&= ~ES_CENTER
;
3014 es
->style
&= ~ES_RIGHT
;
3015 es
->style
&= ~WS_HSCROLL
;
3016 es
->style
&= ~WS_VSCROLL
;
3017 es
->style
&= ~ES_AUTOVSCROLL
;
3018 es
->style
&= ~ES_WANTRETURN
;
3019 if (es
->style
& ES_UPPERCASE
) {
3020 es
->style
&= ~ES_LOWERCASE
;
3021 es
->style
&= ~ES_NUMBER
;
3022 } else if (es
->style
& ES_LOWERCASE
)
3023 es
->style
&= ~ES_NUMBER
;
3024 if (es
->style
& ES_PASSWORD
)
3025 es
->password_char
= '*';
3027 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3028 es
->style
|= ES_AUTOHSCROLL
;
3030 if (!(es
->text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3032 es
->buffer_size
= HeapSize(es
->heap
, 0, es
->text
) - 1;
3033 if (!(es
->undo_text
= HeapAlloc(es
->heap
, 0, es
->buffer_size
+ 1)))
3035 es
->undo_buffer_size
= HeapSize(es
->heap
, 0, es
->undo_text
) - 1;
3037 if (es
->style
& ES_MULTILINE
)
3038 if (!(es
->first_line_def
= HeapAlloc(es
->heap
, HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
3042 * To initialize some final structure members, we call some helper
3043 * functions. However, since the EDITSTATE is not consistent (i.e.
3044 * not fully initialized), we should be very careful which
3045 * functions can be called, and in what order.
3047 EDIT_WM_SetFont(wnd
, es
, 0, FALSE
);
3048 if (cs
->lpszName
&& *(cs
->lpszName
) != '\0') {
3049 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, cs
->lpszName
);
3050 /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */
3051 es
->selection_start
= es
->selection_end
= 0;
3052 EDIT_EM_ScrollCaret(wnd
, es
);
3058 /*********************************************************************
3063 static void EDIT_WM_Destroy(WND
*wnd
, EDITSTATE
*es
)
3066 while (LocalUnlock32(es
->hloc32
)) ;
3067 LocalFree32(es
->hloc32
);
3070 while (LOCAL_Unlock(wnd
->hInstance
, es
->hloc16
)) ;
3071 LOCAL_Free(wnd
->hInstance
, es
->hloc16
);
3073 HeapDestroy(es
->heap
);
3074 HeapFree(GetProcessHeap(), 0, es
);
3075 *(EDITSTATE
**)wnd
->wExtra
= NULL
;
3079 /*********************************************************************
3084 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wnd
, EDITSTATE
*es
, HDC32 dc
)
3089 if (!(brush
= (HBRUSH32
)EDIT_SEND_CTLCOLOR(wnd
, dc
)))
3090 brush
= (HBRUSH32
)GetStockObject32(WHITE_BRUSH
);
3092 GetClientRect32(wnd
->hwndSelf
, &rc
);
3093 IntersectClipRect32(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3094 GetClipBox32(dc
, &rc
);
3096 * FIXME: specs say that we should UnrealizeObject() the brush,
3097 * but the specs of UnrealizeObject() say that we shouldn't
3098 * unrealize a stock object. The default brush that
3099 * DefWndProc() returns is ... a stock object.
3101 FillRect32(dc
, &rc
, brush
);
3106 /*********************************************************************
3111 static INT32
EDIT_WM_GetText(WND
*wnd
, EDITSTATE
*es
, INT32 count
, LPSTR text
)
3113 INT32 len
= lstrlen32A(es
->text
);
3116 lstrcpy32A(text
, es
->text
);
3123 /*********************************************************************
3127 * 16 bit notepad needs this. Actually it is not _our_ hack,
3128 * it is notepad's. Notepad is sending us scrollbar messages with
3129 * undocumented parameters without us even having a scrollbar ... !?!?
3132 static LRESULT
EDIT_HScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 pos
, HWND32 scroll_bar
)
3135 INT32 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3138 if (!(es
->flags
& EF_HSCROLL_HACK
)) {
3139 fprintf(stderr
, "edit: hacked WM_HSCROLL handler invoked\n");
3140 fprintf(stderr
, " if you are _not_ running 16 bit notepad, please report\n");
3141 fprintf(stderr
, " (this message is only displayed once per edit control)\n");
3142 es
->flags
|= EF_HSCROLL_HACK
;
3148 dx
= -es
->char_width
;
3151 if (es
->x_offset
< es
->text_width
)
3152 dx
= es
->char_width
;
3156 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3159 if (es
->x_offset
< es
->text_width
)
3160 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3167 if (es
->x_offset
< es
->text_width
)
3168 dx
= es
->text_width
- es
->x_offset
;
3171 es
->flags
|= EF_HSCROLL_TRACK
;
3172 dx
= pos
* es
->text_width
/ 100 - es
->x_offset
;
3174 case SB_THUMBPOSITION
:
3175 es
->flags
&= ~EF_HSCROLL_TRACK
;
3176 if (!(dx
= pos
* es
->text_width
/ 100 - es
->x_offset
))
3177 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3183 * FIXME : the next two are undocumented !
3184 * Are we doing the right thing ?
3185 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3186 * although it's also a regular control message.
3189 ret
= es
->text_width
? es
->x_offset
* 100 / es
->text_width
: 0;
3191 case EM_LINESCROLL16
:
3196 dprintf_edit(stddeb
, "edit: undocumented (hacked) WM_HSCROLL parameter, please report\n");
3200 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3205 /*********************************************************************
3210 static LRESULT
EDIT_WM_HScroll(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 pos
, HWND32 scroll_bar
)
3215 if (!(es
->style
& ES_MULTILINE
))
3218 if (!(es
->style
& ES_AUTOHSCROLL
))
3221 if (!(es
->style
& WS_HSCROLL
))
3222 return EDIT_HScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3225 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3229 dx
= -es
->char_width
;
3232 if (es
->x_offset
< es
->text_width
)
3233 dx
= es
->char_width
;
3237 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3240 if (es
->x_offset
< es
->text_width
)
3241 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3248 if (es
->x_offset
< es
->text_width
)
3249 dx
= es
->text_width
- es
->x_offset
;
3252 es
->flags
|= EF_HSCROLL_TRACK
;
3253 dx
= pos
- es
->x_offset
;
3255 case SB_THUMBPOSITION
:
3256 es
->flags
&= ~EF_HSCROLL_TRACK
;
3257 if (!(dx
= pos
- es
->x_offset
)) {
3258 SetScrollPos32(wnd
->hwndSelf
, SB_HORZ
, pos
, TRUE
);
3259 EDIT_NOTIFY_PARENT(wnd
, EN_HSCROLL
, "EN_HSCROLL");
3266 fprintf(stderr
, "edit: undocumented WM_HSCROLL parameter, please report\n");
3270 EDIT_EM_LineScroll(wnd
, es
, dx
, 0);
3275 /*********************************************************************
3280 static BOOL32
EDIT_CheckCombo(WND
*wnd
, UINT32 msg
, INT32 key
, DWORD key_data
)
3284 if (WIDGETS_IsControl32(wnd
->parent
, BIC32_COMBO
) &&
3285 (hLBox
= COMBO_GetLBWindow(wnd
->parent
))) {
3286 HWND32 hCombo
= wnd
->parent
->hwndSelf
;
3287 BOOL32 bUIFlip
= TRUE
;
3289 dprintf_combo(stddeb
, "EDIT_CheckCombo [%04x]: handling msg %04x (%04x)\n",
3290 wnd
->hwndSelf
, (UINT16
)msg
, (UINT16
)key
);
3293 case WM_KEYDOWN
: /* Handle F4 and arrow keys */
3295 bUIFlip
= (BOOL32
)SendMessage32A(hCombo
, CB_GETEXTENDEDUI32
, 0, 0);
3296 if (SendMessage32A(hCombo
, CB_GETDROPPEDSTATE32
, 0, 0))
3300 SendMessage32A(hLBox
, WM_KEYDOWN
, (WPARAM32
)key
, 0);
3302 /* make sure ComboLBox pops up */
3303 SendMessage32A(hCombo
, CB_SETEXTENDEDUI32
, 0, 0);
3304 SendMessage32A(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3305 SendMessage32A(hCombo
, CB_SETEXTENDEDUI32
, 1, 0);
3308 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3309 bUIFlip
= (BOOL32
)SendMessage32A(hCombo
, CB_GETEXTENDEDUI32
, 0, 0);
3311 bUIFlip
= (BOOL32
)SendMessage32A(hCombo
, CB_GETDROPPEDSTATE32
, 0, 0);
3312 SendMessage32A(hCombo
, CB_SHOWDROPDOWN32
, (bUIFlip
) ? FALSE
: TRUE
, 0);
3314 SendMessage32A(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3323 /*********************************************************************
3327 * Handling of special keys that don't produce a WM_CHAR
3328 * (i.e. non-printable keys) & Backspace & Delete
3331 static LRESULT
EDIT_WM_KeyDown(WND
*wnd
, EDITSTATE
*es
, INT32 key
, DWORD key_data
)
3336 if (GetKeyState32(VK_MENU
) & 0x8000)
3339 shift
= GetKeyState32(VK_SHIFT
) & 0x8000;
3340 control
= GetKeyState32(VK_CONTROL
) & 0x8000;
3345 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3351 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3352 EDIT_MoveUp_ML(wnd
, es
, shift
);
3355 EDIT_MoveWordBackward(wnd
, es
, shift
);
3357 EDIT_MoveBackward(wnd
, es
, shift
);
3360 if (EDIT_CheckCombo(wnd
, WM_KEYDOWN
, key
, key_data
))
3364 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3365 EDIT_MoveDown_ML(wnd
, es
, shift
);
3367 EDIT_MoveWordForward(wnd
, es
, shift
);
3369 EDIT_MoveForward(wnd
, es
, shift
);
3372 EDIT_MoveHome(wnd
, es
, shift
);
3375 EDIT_MoveEnd(wnd
, es
, shift
);
3378 if (es
->style
& ES_MULTILINE
)
3379 EDIT_MovePageUp_ML(wnd
, es
, shift
);
3382 if (es
->style
& ES_MULTILINE
)
3383 EDIT_MovePageDown_ML(wnd
, es
, shift
);
3386 if (!(es
->style
& ES_READONLY
) && !control
)
3387 if (es
->selection_start
!= es
->selection_end
)
3388 EDIT_WM_Clear(wnd
, es
);
3390 /* delete character left of caret */
3391 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3392 EDIT_MoveBackward(wnd
, es
, TRUE
);
3393 EDIT_WM_Clear(wnd
, es
);
3397 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
))
3398 if (es
->selection_start
!= es
->selection_end
) {
3400 EDIT_WM_Cut(wnd
, es
);
3402 EDIT_WM_Clear(wnd
, es
);
3405 /* delete character left of caret */
3406 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3407 EDIT_MoveBackward(wnd
, es
, TRUE
);
3408 EDIT_WM_Clear(wnd
, es
);
3409 } else if (control
) {
3410 /* delete to end of line */
3411 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3412 EDIT_MoveEnd(wnd
, es
, TRUE
);
3413 EDIT_WM_Clear(wnd
, es
);
3415 /* delete character right of caret */
3416 EDIT_EM_SetSel(wnd
, es
, -1, 0, FALSE
);
3417 EDIT_MoveForward(wnd
, es
, TRUE
);
3418 EDIT_WM_Clear(wnd
, es
);
3424 if (!(es
->style
& ES_READONLY
))
3425 EDIT_WM_Paste(wnd
, es
);
3427 EDIT_WM_Copy(wnd
, es
);
3434 /*********************************************************************
3439 static LRESULT
EDIT_WM_KillFocus(WND
*wnd
, EDITSTATE
*es
, HWND32 window_getting_focus
)
3441 es
->flags
&= ~EF_FOCUSED
;
3443 if(!(es
->style
& ES_NOHIDESEL
))
3444 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3445 EDIT_NOTIFY_PARENT(wnd
, EN_KILLFOCUS
, "EN_KILLFOCUS");
3450 /*********************************************************************
3454 * The caret position has been set on the WM_LBUTTONDOWN message
3457 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
)
3460 INT32 e
= es
->selection_end
;
3465 if (!(es
->flags
& EF_FOCUSED
))
3468 l
= EDIT_EM_LineFromChar(wnd
, es
, e
);
3469 li
= EDIT_EM_LineIndex(wnd
, es
, l
);
3470 ll
= EDIT_EM_LineLength(wnd
, es
, e
);
3471 s
= li
+ EDIT_CallWordBreakProc (wnd
, es
, li
, e
- li
, ll
, WB_LEFT
);
3472 e
= li
+ EDIT_CallWordBreakProc(wnd
, es
, li
, e
- li
, ll
, WB_RIGHT
);
3473 EDIT_EM_SetSel(wnd
, es
, s
, e
, FALSE
);
3474 EDIT_EM_ScrollCaret(wnd
, es
);
3479 /*********************************************************************
3484 static LRESULT
EDIT_WM_LButtonDown(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
)
3489 if (!(es
->flags
& EF_FOCUSED
))
3492 SetCapture32(wnd
->hwndSelf
);
3493 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3494 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3495 EDIT_EM_SetSel(wnd
, es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3496 EDIT_EM_ScrollCaret(wnd
, es
);
3497 es
->region_posx
= es
->region_posy
= 0;
3498 SetTimer32(wnd
->hwndSelf
, 0, 100, NULL
);
3503 /*********************************************************************
3508 static LRESULT
EDIT_WM_LButtonUp(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
)
3510 if (GetCapture32() == wnd
->hwndSelf
) {
3511 KillTimer32(wnd
->hwndSelf
, 0);
3518 /*********************************************************************
3523 static LRESULT
EDIT_WM_MouseMove(WND
*wnd
, EDITSTATE
*es
, DWORD keys
, INT32 x
, INT32 y
)
3529 if (GetCapture32() != wnd
->hwndSelf
)
3533 * FIXME: gotta do some scrolling if outside client
3534 * area. Maybe reset the timer ?
3537 EDIT_ConfinePoint(wnd
, es
, &x
, &y
);
3538 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3539 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3540 e
= EDIT_CharFromPos(wnd
, es
, x
, y
, &after_wrap
);
3541 EDIT_EM_SetSel(wnd
, es
, es
->selection_start
, e
, after_wrap
);
3546 /*********************************************************************
3551 static void EDIT_WM_Paint(WND
*wnd
, EDITSTATE
*es
)
3556 HFONT32 old_font
= 0;
3561 BOOL32 rev
= IsWindowEnabled32(wnd
->hwndSelf
) &&
3562 ((es
->flags
& EF_FOCUSED
) ||
3563 (es
->style
& ES_NOHIDESEL
));
3565 if (es
->flags
& EF_UPDATE
)
3566 EDIT_NOTIFY_PARENT(wnd
, EN_UPDATE
, "EN_UPDATE");
3568 dc
= BeginPaint32(wnd
->hwndSelf
, &ps
);
3569 IntersectClipRect32(dc
, es
->format_rect
.left
,
3570 es
->format_rect
.top
,
3571 es
->format_rect
.right
,
3572 es
->format_rect
.bottom
);
3573 if (es
->style
& ES_MULTILINE
) {
3574 GetClientRect32(wnd
->hwndSelf
, &rc
);
3575 IntersectClipRect32(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3578 old_font
= SelectObject32(dc
, es
->font
);
3579 EDIT_SEND_CTLCOLOR(wnd
, dc
);
3580 if (!IsWindowEnabled32(wnd
->hwndSelf
))
3581 SetTextColor32(dc
, GetSysColor32(COLOR_GRAYTEXT
));
3582 GetClipBox32(dc
, &rcRgn
);
3583 if (es
->style
& ES_MULTILINE
) {
3584 INT32 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3585 for (i
= es
->y_offset
; i
<= MIN(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3586 EDIT_GetLineRect(wnd
, es
, i
, 0, -1, &rcLine
);
3587 if (IntersectRect32(&rc
, &rcRgn
, &rcLine
))
3588 EDIT_PaintLine(wnd
, es
, dc
, i
, rev
);
3591 EDIT_GetLineRect(wnd
, es
, 0, 0, -1, &rcLine
);
3592 if (IntersectRect32(&rc
, &rcRgn
, &rcLine
))
3593 EDIT_PaintLine(wnd
, es
, dc
, 0, rev
);
3596 SelectObject32(dc
, old_font
);
3597 if (es
->flags
& EF_FOCUSED
) {
3598 pos
= EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3599 SetCaretPos32(SLOWORD(pos
), SHIWORD(pos
));
3601 EndPaint32(wnd
->hwndSelf
, &ps
);
3602 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
)) {
3603 INT32 vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
3605 si
.cbSize
= sizeof(SCROLLINFO
);
3606 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3608 si
.nMax
= es
->line_count
+ vlc
- 2;
3610 si
.nPos
= es
->y_offset
;
3611 SetScrollInfo32(wnd
->hwndSelf
, SB_VERT
, &si
, TRUE
);
3613 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
)) {
3615 INT32 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3616 si
.cbSize
= sizeof(SCROLLINFO
);
3617 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
3619 si
.nMax
= es
->text_width
+ fw
- 1;
3621 si
.nPos
= es
->x_offset
;
3622 SetScrollInfo32(wnd
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
3625 if (es
->flags
& EF_UPDATE
) {
3626 es
->flags
&= ~EF_UPDATE
;
3627 EDIT_NOTIFY_PARENT(wnd
, EN_CHANGE
, "EN_CHANGE");
3632 /*********************************************************************
3636 * FIXME: replace with 32 bit handler once GetClipboardData32() is
3637 * implemented in misc/clipboard.c
3640 static void EDIT_WM_Paste(WND
*wnd
, EDITSTATE
*es
)
3645 OpenClipboard32(wnd
->hwndSelf
);
3646 if ((hsrc
= GetClipboardData16(CF_TEXT
))) {
3647 src
= (LPSTR
)GlobalLock16(hsrc
);
3648 EDIT_EM_ReplaceSel(wnd
, es
, TRUE
, src
);
3649 GlobalUnlock16(hsrc
);
3655 /*********************************************************************
3660 static void EDIT_WM_SetFocus(WND
*wnd
, EDITSTATE
*es
, HWND32 window_losing_focus
)
3664 es
->flags
|= EF_FOCUSED
;
3665 CreateCaret32(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3666 pos
= EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3667 SetCaretPos32(SLOWORD(pos
), SHIWORD(pos
));
3668 if(!(es
->style
& ES_NOHIDESEL
))
3669 EDIT_InvalidateText(wnd
, es
, es
->selection_start
, es
->selection_end
);
3670 ShowCaret32(wnd
->hwndSelf
);
3671 EDIT_NOTIFY_PARENT(wnd
, EN_SETFOCUS
, "EN_SETFOCUS");
3675 /*********************************************************************
3680 static void EDIT_WM_SetFont(WND
*wnd
, EDITSTATE
*es
, HFONT32 font
, BOOL32 redraw
)
3684 HFONT32 old_font
= 0;
3687 dc
= GetDC32(wnd
->hwndSelf
);
3689 old_font
= SelectObject32(dc
, font
);
3690 GetTextMetrics32A(dc
, &tm
);
3691 es
->line_height
= tm
.tmHeight
;
3692 es
->char_width
= tm
.tmAveCharWidth
;
3694 SelectObject32(dc
, old_font
);
3695 ReleaseDC32(wnd
->hwndSelf
, dc
);
3696 if (wnd
->flags
& WIN_ISWIN32
)
3697 EDIT_EM_SetMargins(wnd
, es
, EC_USEFONTINFO
, 0, 0);
3698 if (es
->style
& ES_MULTILINE
)
3699 EDIT_BuildLineDefs_ML(wnd
, es
);
3701 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
3702 if (es
->flags
& EF_FOCUSED
) {
3705 CreateCaret32(wnd
->hwndSelf
, 0, 2, es
->line_height
);
3706 pos
= EDIT_EM_PosFromChar(wnd
, es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3707 SetCaretPos32(SLOWORD(pos
), SHIWORD(pos
));
3708 ShowCaret32(wnd
->hwndSelf
);
3713 /*********************************************************************
3718 static void EDIT_WM_SetText(WND
*wnd
, EDITSTATE
*es
, LPCSTR text
)
3720 EDIT_EM_SetSel(wnd
, es
, 0, -1, FALSE
);
3722 dprintf_edit(stddeb
, "\t'%s'\n", text
);
3723 EDIT_EM_ReplaceSel(wnd
, es
, FALSE
, text
);
3726 es
->flags
|= EF_MODIFIED
;
3727 es
->flags
|= EF_UPDATE
;
3728 EDIT_EM_ScrollCaret(wnd
, es
);
3732 /*********************************************************************
3737 static void EDIT_WM_Size(WND
*wnd
, EDITSTATE
*es
, UINT32 action
, INT32 width
, INT32 height
)
3739 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3741 SetRect32(&rc
, 0, 0, width
, height
);
3742 EDIT_SetRectNP(wnd
, es
, &rc
);
3743 InvalidateRect32(wnd
->hwndSelf
, NULL
, TRUE
);
3748 /*********************************************************************
3753 static LRESULT
EDIT_WM_SysKeyDown(WND
*wnd
, EDITSTATE
*es
, INT32 key
, DWORD key_data
)
3755 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3756 if (EDIT_EM_CanUndo(wnd
, es
))
3757 EDIT_EM_Undo(wnd
, es
);
3759 } else if (key
== VK_UP
|| key
== VK_DOWN
)
3760 if (EDIT_CheckCombo(wnd
, WM_SYSKEYDOWN
, key
, key_data
))
3762 return DefWindowProc32A(wnd
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM32
)key
, (LPARAM
)key_data
);
3766 /*********************************************************************
3771 static void EDIT_WM_Timer(WND
*wnd
, EDITSTATE
*es
, INT32 id
, TIMERPROC32 timer_proc
)
3773 if (es
->region_posx
< 0) {
3774 EDIT_MoveBackward(wnd
, es
, TRUE
);
3775 } else if (es
->region_posx
> 0) {
3776 EDIT_MoveForward(wnd
, es
, TRUE
);
3779 * FIXME: gotta do some vertical scrolling here, like
3780 * EDIT_EM_LineScroll(wnd, 0, 1);
3785 /*********************************************************************
3789 * 16 bit notepad needs this. Actually it is not _our_ hack,
3790 * it is notepad's. Notepad is sending us scrollbar messages with
3791 * undocumented parameters without us even having a scrollbar ... !?!?
3794 static LRESULT
EDIT_VScroll_Hack(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 pos
, HWND32 scroll_bar
)
3799 if (!(es
->flags
& EF_VSCROLL_HACK
)) {
3800 fprintf(stderr
, "edit: hacked WM_VSCROLL handler invoked\n");
3801 fprintf(stderr
, " if you are _not_ running 16 bit notepad, please report\n");
3802 fprintf(stderr
, " (this message is only displayed once per edit control)\n");
3803 es
->flags
|= EF_VSCROLL_HACK
;
3811 EDIT_EM_Scroll(wnd
, es
, action
);
3817 dy
= es
->line_count
- 1 - es
->y_offset
;
3820 es
->flags
|= EF_VSCROLL_TRACK
;
3821 dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
;
3823 case SB_THUMBPOSITION
:
3824 es
->flags
&= ~EF_VSCROLL_TRACK
;
3825 if (!(dy
= (pos
* (es
->line_count
- 1) + 50) / 100 - es
->y_offset
))
3826 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3832 * FIXME : the next two are undocumented !
3833 * Are we doing the right thing ?
3834 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3835 * although it's also a regular control message.
3838 ret
= (es
->line_count
> 1) ? es
->y_offset
* 100 / (es
->line_count
- 1) : 0;
3840 case EM_LINESCROLL16
:
3845 fprintf(stderr
, "edit: undocumented (hacked) WM_VSCROLL parameter, please report\n");
3849 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);
3854 /*********************************************************************
3859 static LRESULT
EDIT_WM_VScroll(WND
*wnd
, EDITSTATE
*es
, INT32 action
, INT32 pos
, HWND32 scroll_bar
)
3863 if (!(es
->style
& ES_MULTILINE
))
3866 if (!(es
->style
& ES_AUTOVSCROLL
))
3869 if (!(es
->style
& WS_VSCROLL
))
3870 return EDIT_VScroll_Hack(wnd
, es
, action
, pos
, scroll_bar
);
3878 EDIT_EM_Scroll(wnd
, es
, action
);
3885 dy
= es
->line_count
- 1 - es
->y_offset
;
3888 es
->flags
|= EF_VSCROLL_TRACK
;
3889 dy
= pos
- es
->y_offset
;
3891 case SB_THUMBPOSITION
:
3892 es
->flags
&= ~EF_VSCROLL_TRACK
;
3893 if (!(dy
= pos
- es
->y_offset
)) {
3894 SetScrollPos32(wnd
->hwndSelf
, SB_VERT
, pos
, TRUE
);
3895 EDIT_NOTIFY_PARENT(wnd
, EN_VSCROLL
, "EN_VSCROLL");
3902 fprintf(stderr
, "edit: undocumented WM_VSCROLL parameter, please report\n");
3906 EDIT_EM_LineScroll(wnd
, es
, 0, dy
);