4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
47 #include <wine/debug.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
50 WINE_DECLARE_DEBUG_CHANNEL(combo
);
51 WINE_DECLARE_DEBUG_CHANNEL(relay
);
53 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
54 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
55 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
56 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
59 * extra flags for EDITSTATE.flags field
61 #define EF_MODIFIED 0x0001 /* text has been modified */
62 #define EF_FOCUSED 0x0002 /* we have input focus */
63 #define EF_UPDATE 0x0004 /* notify parent of changed state */
64 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
65 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
66 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
67 wrapped line, instead of in front of the next character */
68 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
69 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
70 the text buffer if this is clear. */
71 #define EF_DIALOGMODE 0x0400 /* Indicates that we are inside a dialog window */
75 END_0
= 0, /* line ends with terminating '\0' character */
76 END_WRAP
, /* line is wrapped */
77 END_HARD
, /* line ends with a hard return '\r\n' */
78 END_SOFT
, /* line ends with a soft return '\r\r\n' */
79 END_RICH
/* line ends with a single '\n' */
82 typedef struct tagLINEDEF
{
83 INT length
; /* bruto length of a line in bytes */
84 INT net_length
; /* netto length of a line in visible characters */
86 INT width
; /* width of the line in pixels */
87 INT index
; /* line index into the buffer */
88 struct tagLINEDEF
*next
;
93 BOOL is_unicode
; /* how the control was created */
94 LPWSTR text
; /* the actual contents of the control */
95 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
96 UINT buffer_size
; /* the size of the buffer in characters */
97 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
98 HFONT font
; /* NULL means standard system font */
99 INT x_offset
; /* scroll offset for multi lines this is in pixels
100 for single lines it's in characters */
101 INT line_height
; /* height of a screen line in pixels */
102 INT char_width
; /* average character width in pixels */
103 DWORD style
; /* sane version of wnd->dwStyle */
104 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
105 INT undo_insert_count
; /* number of characters inserted in sequence */
106 UINT undo_position
; /* character index of the insertion and deletion */
107 LPWSTR undo_text
; /* deleted text */
108 UINT undo_buffer_size
; /* size of the deleted text buffer */
109 INT selection_start
; /* == selection_end if no selection */
110 INT selection_end
; /* == current caret position */
111 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
112 INT left_margin
; /* in pixels */
113 INT right_margin
; /* in pixels */
115 INT text_width
; /* width of the widest line in pixels for multi line controls
116 and just line width for single line controls */
117 INT region_posx
; /* Position of cursor relative to region: */
118 INT region_posy
; /* -1: to left, 0: within, 1: to right */
120 EDITWORDBREAKPROC16 word_break_proc16
;
122 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
123 INT line_count
; /* number of lines */
124 INT y_offset
; /* scroll offset in number of lines */
125 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
126 BOOL bEnableState
; /* flag keeping the enable state */
127 HWND hwndSelf
; /* the our window handle */
128 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
129 Even if parent will change, EN_* messages
130 should be sent to the first parent. */
131 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
133 * only for multi line controls
135 INT lock_count
; /* amount of re-entries in the EditWndProc */
138 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
139 HLOCAL hloc32W
; /* our unicode local memory block */
141 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
144 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
149 UINT composition_len
; /* length of composition, 0 == no composition */
150 int composition_start
; /* the character position for the composition */
154 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
155 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
157 /* used for disabled or read-only edit control */
158 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
160 { /* Notify parent which has created this edit control */ \
161 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
162 SendMessageW(es->hwndParent, WM_COMMAND, \
163 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
164 (LPARAM)(es->hwndSelf)); \
168 /*********************************************************************
173 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
175 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
179 /*********************************************************************
184 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
186 es
->undo_insert_count
= 0;
187 *es
->undo_text
= '\0';
191 /**********************************************************************
194 * Returns the window version in case Wine emulates a later version
195 * of windows than the application expects.
197 * In a number of cases when windows runs an application that was
198 * designed for an earlier windows version, windows reverts
199 * to "old" behaviour of that earlier version.
201 * An example is a disabled edit control that needs to be painted.
202 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
203 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
204 * applications with an expected version 0f 4.0 or higher.
207 static DWORD
get_app_version(void)
209 static DWORD version
;
212 DWORD dwEmulatedVersion
;
214 DWORD dwProcVersion
= GetProcessVersion(0);
216 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
217 GetVersionExW( &info
);
218 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
219 /* FIXME: this may not be 100% correct; see discussion on the
220 * wine developer list in Nov 1999 */
221 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
226 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
231 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
232 msg
= WM_CTLCOLORSTATIC
;
234 msg
= WM_CTLCOLOREDIT
;
236 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
237 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
239 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
244 /*********************************************************************
248 * Find the beginning of words.
249 * Note: unlike the specs for a WordBreakProc, this function only
250 * allows to be called without linebreaks between s[0] up to
251 * s[count - 1]. Remember it is only called
252 * internally, so we can decide this for ourselves.
255 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
259 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
269 if (s
[index
] == ' ') {
270 while (index
&& (s
[index
] == ' '))
273 while (index
&& (s
[index
] != ' '))
279 while (index
&& (s
[index
] != ' '))
292 while ((index
< count
) && (s
[index
] == ' ')) index
++;
294 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
296 while ((s
[index
] == ' ') && (index
< count
)) index
++;
301 ret
= (s
[index
] == ' ');
304 ERR("unknown action code, please report !\n");
311 /*********************************************************************
313 * EDIT_CallWordBreakProc
315 * Call appropriate WordBreakProc (internal or external).
317 * Note: The "start" argument should always be an index referring
318 * to es->text. The actual wordbreak proc might be
319 * 16 bit, so we can't always pass any 32 bit LPSTR.
320 * Hence we assume that es->text is the buffer that holds
321 * the string under examination (we can decide this for ourselves).
324 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
329 if (es
->word_break_proc16
) {
336 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
337 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
338 segptr
= WOWGlobalLock16(hglob16
);
339 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
340 args
[4] = SELECTOROF(segptr
);
341 args
[3] = OFFSETOF(segptr
);
345 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
346 ret
= LOWORD(result
);
347 GlobalUnlock16(hglob16
);
348 GlobalFree16(hglob16
);
350 else if (es
->word_break_proc
)
352 if (es
->word_break_proc
)
357 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
359 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
360 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
361 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
365 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
369 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
370 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
373 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
374 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
375 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
376 ret
= wbpA(textA
, index
, countA
, action
);
377 HeapFree(GetProcessHeap(), 0, textA
);
381 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
386 /*********************************************************************
388 * EDIT_BuildLineDefs_ML
390 * Build linked list of text lines.
391 * Lines can end with '\0' (last line), a character (if it is wrapped),
392 * a soft return '\r\r\n' or a hard return '\r\n'
395 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
399 LPWSTR current_position
, cp
;
401 LINEDEF
*current_line
;
402 LINEDEF
*previous_line
;
404 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
405 INT line_count
= es
->line_count
;
409 if (istart
== iend
&& delta
== 0)
412 dc
= GetDC(es
->hwndSelf
);
414 old_font
= SelectObject(dc
, es
->font
);
416 previous_line
= NULL
;
417 current_line
= es
->first_line_def
;
419 /* Find starting line. istart must lie inside an existing line or
420 * at the end of buffer */
422 if (istart
< current_line
->index
+ current_line
->length
||
423 current_line
->ending
== END_0
)
426 previous_line
= current_line
;
427 current_line
= current_line
->next
;
429 } while (current_line
);
431 if (!current_line
) /* Error occurred start is not inside previous buffer */
433 FIXME(" modification occurred outside buffer\n");
434 ReleaseDC(es
->hwndSelf
, dc
);
438 /* Remember start of modifications in order to calculate update region */
439 nstart_line
= line_index
;
440 nstart_index
= current_line
->index
;
442 /* We must start to reformat from the previous line since the modifications
443 * may have caused the line to wrap upwards. */
444 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
447 current_line
= previous_line
;
449 start_line
= current_line
;
451 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
452 current_position
= es
->text
+ current_line
->index
;
454 if (current_line
!= start_line
)
456 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
458 /* The buffer has been expanded, create a new line and
459 insert it into the link list */
460 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
461 if (new_line
== NULL
)
463 new_line
->next
= previous_line
->next
;
464 previous_line
->next
= new_line
;
465 current_line
= new_line
;
468 else if (current_line
->index
+ delta
< current_position
- es
->text
)
470 /* The previous line merged with this line so we delete this extra entry */
471 previous_line
->next
= current_line
->next
;
472 HeapFree(GetProcessHeap(), 0, current_line
);
473 current_line
= previous_line
->next
;
477 else /* current_line->index + delta == current_position */
479 if (current_position
- es
->text
> iend
)
480 break; /* We reached end of line modifications */
481 /* else recalculate this line */
485 current_line
->index
= current_position
- es
->text
;
486 orig_net_length
= current_line
->net_length
;
488 /* Find end of line */
489 cp
= current_position
;
491 if (*cp
== '\n') break;
492 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
497 /* Mark type of line termination */
499 current_line
->ending
= END_0
;
500 current_line
->net_length
= strlenW(current_position
);
501 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
502 current_line
->ending
= END_SOFT
;
503 current_line
->net_length
= cp
- current_position
- 1;
504 } else if (*cp
== '\n') {
505 current_line
->ending
= END_RICH
;
506 current_line
->net_length
= cp
- current_position
;
508 current_line
->ending
= END_HARD
;
509 current_line
->net_length
= cp
- current_position
;
512 /* Calculate line width */
513 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
514 current_position
, current_line
->net_length
,
515 es
->tabs_count
, es
->tabs
));
517 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
518 if (!(es
->style
& ES_AUTOHSCROLL
)) {
519 if (current_line
->width
> fw
) {
524 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
525 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
526 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
527 current_position
, next
, es
->tabs_count
, es
->tabs
));
528 } while (current_line
->width
<= fw
);
529 if (!prev
) { /* Didn't find a line break so force a break */
534 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
535 current_position
, next
, es
->tabs_count
, es
->tabs
));
536 } while (current_line
->width
<= fw
);
541 /* If the first line we are calculating, wrapped before istart, we must
542 * adjust istart in order for this to be reflected in the update region. */
543 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
544 istart
= current_line
->index
+ prev
;
545 /* else if we are updating the previous line before the first line we
546 * are re-calculating and it expanded */
547 else if (current_line
== start_line
&&
548 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
550 /* Line expanded due to an upwards line wrap so we must partially include
551 * previous line in update region */
552 nstart_line
= line_index
;
553 nstart_index
= current_line
->index
;
554 istart
= current_line
->index
+ orig_net_length
;
557 current_line
->net_length
= prev
;
558 current_line
->ending
= END_WRAP
;
559 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
560 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
562 else if (current_line
== start_line
&&
563 current_line
->index
!= nstart_index
&&
564 orig_net_length
< current_line
->net_length
) {
565 /* The previous line expanded but it's still not as wide as the client rect */
566 /* The expansion is due to an upwards line wrap so we must partially include
567 it in the update region */
568 nstart_line
= line_index
;
569 nstart_index
= current_line
->index
;
570 istart
= current_line
->index
+ orig_net_length
;
575 /* Adjust length to include line termination */
576 switch (current_line
->ending
) {
578 current_line
->length
= current_line
->net_length
+ 3;
581 current_line
->length
= current_line
->net_length
+ 1;
584 current_line
->length
= current_line
->net_length
+ 2;
588 current_line
->length
= current_line
->net_length
;
591 es
->text_width
= max(es
->text_width
, current_line
->width
);
592 current_position
+= current_line
->length
;
593 previous_line
= current_line
;
594 current_line
= current_line
->next
;
596 } while (previous_line
->ending
!= END_0
);
598 /* Finish adjusting line indexes by delta or remove hanging lines */
599 if (previous_line
->ending
== END_0
)
601 LINEDEF
*pnext
= NULL
;
603 previous_line
->next
= NULL
;
606 pnext
= current_line
->next
;
607 HeapFree(GetProcessHeap(), 0, current_line
);
608 current_line
= pnext
;
616 current_line
->index
+= delta
;
617 current_line
= current_line
->next
;
621 /* Calculate rest of modification rectangle */
626 * We calculate two rectangles. One for the first line which may have
627 * an indent with respect to the format rect. The other is a format-width
628 * rectangle that spans the rest of the lines that changed or moved.
630 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
631 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
632 rc
.bottom
= rc
.top
+ es
->line_height
;
633 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
634 rc
.left
= es
->format_rect
.left
;
636 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
637 es
->text
+ nstart_index
, istart
- nstart_index
,
638 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
639 rc
.right
= es
->format_rect
.right
;
640 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
643 rc
.left
= es
->format_rect
.left
;
644 rc
.right
= es
->format_rect
.right
;
646 * If lines were added or removed we must re-paint the remainder of the
647 * lines since the remaining lines were either shifted up or down.
649 if (line_count
< es
->line_count
) /* We added lines */
650 rc
.bottom
= es
->line_count
* es
->line_height
;
651 else if (line_count
> es
->line_count
) /* We removed lines */
652 rc
.bottom
= line_count
* es
->line_height
;
654 rc
.bottom
= line_index
* es
->line_height
;
655 rc
.bottom
+= es
->format_rect
.top
;
656 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
657 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
658 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
659 DeleteObject(tmphrgn
);
663 SelectObject(dc
, old_font
);
665 ReleaseDC(es
->hwndSelf
, dc
);
669 static inline UINT
get_text_length(EDITSTATE
*es
)
671 if(es
->text_length
== (UINT
)-1)
672 es
->text_length
= strlenW(es
->text
);
673 return es
->text_length
;
676 /*********************************************************************
678 * EDIT_GetPasswordPointer_SL
680 * note: caller should free the (optionally) allocated buffer
683 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
685 if (es
->style
& ES_PASSWORD
) {
686 INT len
= get_text_length(es
);
687 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
691 while(len
) text
[--len
] = es
->password_char
;
698 /*********************************************************************
700 * EDIT_CalcLineWidth_SL
703 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
710 text
= EDIT_GetPasswordPointer_SL(es
);
712 dc
= GetDC(es
->hwndSelf
);
714 old_font
= SelectObject(dc
, es
->font
);
716 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
719 SelectObject(dc
, old_font
);
720 ReleaseDC(es
->hwndSelf
, dc
);
722 if (es
->style
& ES_PASSWORD
)
723 HeapFree(GetProcessHeap(), 0, text
);
725 es
->text_width
= size
.cx
;
728 /*********************************************************************
732 * Beware: This is not the function called on EM_CHARFROMPOS
733 * The position _can_ be outside the formatting / client
735 * The return value is only the character index
738 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
743 INT x_high
= 0, x_low
= 0;
745 if (es
->style
& ES_MULTILINE
) {
746 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
748 LINEDEF
*line_def
= es
->first_line_def
;
750 while ((line
> 0) && line_def
->next
) {
751 line_index
+= line_def
->length
;
752 line_def
= line_def
->next
;
755 x
+= es
->x_offset
- es
->format_rect
.left
;
756 if (es
->style
& ES_RIGHT
)
757 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
758 else if (es
->style
& ES_CENTER
)
759 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
760 if (x
>= line_def
->width
) {
762 *after_wrap
= (line_def
->ending
== END_WRAP
);
763 return line_index
+ line_def
->net_length
;
770 dc
= GetDC(es
->hwndSelf
);
772 old_font
= SelectObject(dc
, es
->font
);
774 high
= line_index
+ line_def
->net_length
+ 1;
775 while (low
< high
- 1)
777 INT mid
= (low
+ high
) / 2;
778 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
787 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
793 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
794 (line_def
->ending
== END_WRAP
));
800 x
-= es
->format_rect
.left
;
806 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
807 if (es
->style
& ES_RIGHT
)
809 else if (es
->style
& ES_CENTER
)
813 text
= EDIT_GetPasswordPointer_SL(es
);
814 dc
= GetDC(es
->hwndSelf
);
816 old_font
= SelectObject(dc
, es
->font
);
820 INT high
= es
->x_offset
;
821 while (low
< high
- 1)
823 INT mid
= (low
+ high
) / 2;
824 GetTextExtentPoint32W( dc
, text
+ mid
,
825 es
->x_offset
- mid
, &size
);
834 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
841 INT low
= es
->x_offset
;
842 INT high
= get_text_length(es
) + 1;
843 while (low
< high
- 1)
845 INT mid
= (low
+ high
) / 2;
846 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
847 mid
- es
->x_offset
, &size
);
856 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
861 if (es
->style
& ES_PASSWORD
)
862 HeapFree(GetProcessHeap(), 0, text
);
865 SelectObject(dc
, old_font
);
866 ReleaseDC(es
->hwndSelf
, dc
);
871 /*********************************************************************
875 * adjusts the point to be within the formatting rectangle
876 * (so CharFromPos returns the nearest _visible_ character)
879 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
881 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
882 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
886 /*********************************************************************
891 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
896 if (!(es
->style
& ES_MULTILINE
))
898 if (index
> (INT
)get_text_length(es
))
899 return es
->line_count
- 1;
901 index
= min(es
->selection_start
, es
->selection_end
);
904 line_def
= es
->first_line_def
;
905 index
-= line_def
->length
;
906 while ((index
>= 0) && line_def
->next
) {
908 line_def
= line_def
->next
;
909 index
-= line_def
->length
;
915 /*********************************************************************
920 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
923 const LINEDEF
*line_def
;
925 if (!(es
->style
& ES_MULTILINE
))
927 if (line
>= es
->line_count
)
931 line_def
= es
->first_line_def
;
933 INT index
= es
->selection_end
- line_def
->length
;
934 while ((index
>= 0) && line_def
->next
) {
935 line_index
+= line_def
->length
;
936 line_def
= line_def
->next
;
937 index
-= line_def
->length
;
941 line_index
+= line_def
->length
;
942 line_def
= line_def
->next
;
950 /*********************************************************************
955 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
959 if (!(es
->style
& ES_MULTILINE
))
960 return get_text_length(es
);
963 /* get the number of remaining non-selected chars of selected lines */
964 INT32 l
; /* line number */
965 INT32 li
; /* index of first char in line */
967 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
968 /* # chars before start of selection area */
969 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
970 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
971 /* # chars after end of selection */
972 li
= EDIT_EM_LineIndex(es
, l
);
973 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
976 line_def
= es
->first_line_def
;
977 index
-= line_def
->length
;
978 while ((index
>= 0) && line_def
->next
) {
979 line_def
= line_def
->next
;
980 index
-= line_def
->length
;
982 return line_def
->net_length
;
986 /*********************************************************************
991 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
993 INT len
= get_text_length(es
);
1006 index
= min(index
, len
);
1007 dc
= GetDC(es
->hwndSelf
);
1009 old_font
= SelectObject(dc
, es
->font
);
1010 if (es
->style
& ES_MULTILINE
) {
1011 l
= EDIT_EM_LineFromChar(es
, index
);
1012 y
= (l
- es
->y_offset
) * es
->line_height
;
1013 li
= EDIT_EM_LineIndex(es
, l
);
1014 if (after_wrap
&& (li
== index
) && l
) {
1016 line_def
= es
->first_line_def
;
1018 line_def
= line_def
->next
;
1021 if (line_def
->ending
== END_WRAP
) {
1023 y
-= es
->line_height
;
1024 li
= EDIT_EM_LineIndex(es
, l
);
1028 line_def
= es
->first_line_def
;
1029 while (line_def
->index
!= li
)
1030 line_def
= line_def
->next
;
1032 ll
= line_def
->net_length
;
1033 lw
= line_def
->width
;
1035 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1036 if (es
->style
& ES_RIGHT
)
1038 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
1039 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1042 else if (es
->style
& ES_CENTER
)
1044 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1045 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1050 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1051 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1054 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
1055 if (index
< es
->x_offset
) {
1056 GetTextExtentPoint32W(dc
, text
+ index
,
1057 es
->x_offset
- index
, &size
);
1060 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
1061 index
- es
->x_offset
, &size
);
1064 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1066 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1067 if (w
> es
->text_width
)
1069 if (es
->style
& ES_RIGHT
)
1070 x
+= w
- es
->text_width
;
1071 else if (es
->style
& ES_CENTER
)
1072 x
+= (w
- es
->text_width
) / 2;
1077 if (es
->style
& ES_PASSWORD
)
1078 HeapFree(GetProcessHeap(), 0, text
);
1080 x
+= es
->format_rect
.left
;
1081 y
+= es
->format_rect
.top
;
1083 SelectObject(dc
, old_font
);
1084 ReleaseDC(es
->hwndSelf
, dc
);
1085 return MAKELONG((INT16
)x
, (INT16
)y
);
1089 /*********************************************************************
1093 * Calculates the bounding rectangle for a line from a starting
1094 * column to an ending column.
1097 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1099 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1101 if (es
->style
& ES_MULTILINE
)
1102 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1104 rc
->top
= es
->format_rect
.top
;
1105 rc
->bottom
= rc
->top
+ es
->line_height
;
1106 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1107 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1111 static inline void text_buffer_changed(EDITSTATE
*es
)
1113 es
->text_length
= (UINT
)-1;
1116 /*********************************************************************
1120 * This acts as a LocalLock16(), but it locks only once. This way
1121 * you can call it whenever you like, without unlocking.
1123 * Initially the edit control allocates a HLOCAL32 buffer
1124 * (32 bit linear memory handler). However, 16 bit application
1125 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1126 * handler). From that moment on we have to keep using this 16 bit memory
1127 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1128 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1132 static void EDIT_LockBuffer(EDITSTATE
*es
)
1135 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1136 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1142 BOOL _16bit
= FALSE
;
1149 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1150 textA
= LocalLock(es
->hloc32A
);
1151 countA
= strlen(textA
) + 1;
1156 HANDLE16 oldDS
= stack16
->ds
;
1157 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1158 stack16
->ds
= hInstance
;
1159 textA
= MapSL(LocalLock16(es
->hloc16
));
1160 stack16
->ds
= oldDS
;
1161 countA
= strlen(textA
) + 1;
1167 ERR("no buffer ... please report\n");
1174 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1175 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1176 if(countW_new
> es
->buffer_size
+ 1)
1178 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1179 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1180 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1183 es
->hloc32W
= hloc32W_new
;
1184 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1185 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1188 WARN("FAILED! Will synchronize partially\n");
1192 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1193 es
->text
= LocalLock(es
->hloc32W
);
1197 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1201 HANDLE16 oldDS
= stack16
->ds
;
1202 stack16
->ds
= hInstance
;
1203 LocalUnlock16(es
->hloc16
);
1204 stack16
->ds
= oldDS
;
1208 LocalUnlock(es
->hloc32A
);
1211 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1216 /*********************************************************************
1221 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1224 /* Edit window might be already destroyed */
1225 if(!IsWindow(es
->hwndSelf
))
1227 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1231 if (!es
->lock_count
) {
1232 ERR("lock_count == 0 ... please report\n");
1236 ERR("es->text == 0 ... please report\n");
1240 if (force
|| (es
->lock_count
== 1)) {
1244 UINT countW
= get_text_length(es
) + 1;
1246 STACK16FRAME
* stack16
= NULL
;
1252 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1253 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1254 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1255 countA
= LocalSize(es
->hloc32A
);
1256 if(countA_new
> countA
)
1259 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1260 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1261 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1264 es
->hloc32A
= hloc32A_new
;
1265 countA
= LocalSize(hloc32A_new
);
1266 TRACE("Real new size %d bytes\n", countA
);
1269 WARN("FAILED! Will synchronize partially\n");
1271 textA
= LocalLock(es
->hloc32A
);
1276 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1278 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1279 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1281 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1282 oldDS
= stack16
->ds
;
1283 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1285 countA
= LocalSize16(es
->hloc16
);
1286 if(countA_new
> countA
)
1288 HLOCAL16 hloc16_new
;
1289 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1290 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1291 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1294 es
->hloc16
= hloc16_new
;
1295 countA
= LocalSize16(hloc16_new
);
1296 TRACE("Real new size %d bytes\n", countA
);
1299 WARN("FAILED! Will synchronize partially\n");
1301 textA
= MapSL(LocalLock16(es
->hloc16
));
1307 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
1310 LocalUnlock16(es
->hloc16
);
1313 LocalUnlock(es
->hloc32A
);
1317 if (stack16
) stack16
->ds
= oldDS
;
1319 LocalUnlock(es
->hloc32W
);
1323 ERR("no buffer ... please report\n");
1331 /*********************************************************************
1335 * Try to fit size + 1 characters in the buffer.
1337 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1341 if (size
<= es
->buffer_size
)
1344 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1346 /* Force edit to unlock it's buffer. es->text now NULL */
1347 EDIT_UnlockBuffer(es
, TRUE
);
1350 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1351 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1352 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1353 es
->hloc32W
= hNew32W
;
1354 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1358 EDIT_LockBuffer(es
);
1360 if (es
->buffer_size
< size
) {
1361 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1362 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1365 TRACE("We now have %d+1\n", es
->buffer_size
);
1371 /*********************************************************************
1375 * Try to fit size + 1 bytes in the undo buffer.
1378 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1382 if (size
<= es
->undo_buffer_size
)
1385 TRACE("trying to ReAlloc to %d+1\n", size
);
1387 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1388 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1389 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1394 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1400 /*********************************************************************
1402 * EDIT_UpdateTextRegion
1405 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1407 if (es
->flags
& EF_UPDATE
) {
1408 es
->flags
&= ~EF_UPDATE
;
1409 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1411 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1415 /*********************************************************************
1420 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1422 if (es
->flags
& EF_UPDATE
) {
1423 es
->flags
&= ~EF_UPDATE
;
1424 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1426 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1429 /*********************************************************************
1431 * EDIT_SL_InvalidateText
1433 * Called from EDIT_InvalidateText().
1434 * Does the job for single-line controls only.
1437 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1442 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1443 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1444 EDIT_UpdateText(es
, &rc
, TRUE
);
1448 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
1450 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1454 /*********************************************************************
1456 * EDIT_ML_InvalidateText
1458 * Called from EDIT_InvalidateText().
1459 * Does the job for multi-line controls only.
1462 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1464 INT vlc
= get_vertical_line_count(es
);
1465 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1466 INT el
= EDIT_EM_LineFromChar(es
, end
);
1475 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1478 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1479 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1480 if (sl
< es
->y_offset
) {
1484 if (el
> es
->y_offset
+ vlc
) {
1485 el
= es
->y_offset
+ vlc
;
1486 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1488 GetClientRect(es
->hwndSelf
, &rc1
);
1489 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1491 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1492 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1493 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1495 EDIT_GetLineRect(es
, sl
, sc
,
1496 EDIT_EM_LineLength(es
,
1497 EDIT_EM_LineIndex(es
, sl
)),
1499 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1500 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1501 for (l
= sl
+ 1 ; l
< el
; l
++) {
1502 EDIT_GetLineRect(es
, l
, 0,
1503 EDIT_EM_LineLength(es
,
1504 EDIT_EM_LineIndex(es
, l
)),
1506 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1507 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1509 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1510 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1511 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1516 /*********************************************************************
1518 * EDIT_InvalidateText
1520 * Invalidate the text from offset start up to, but not including,
1521 * offset end. Useful for (re)painting the selection.
1522 * Regions outside the linewidth are not invalidated.
1523 * end == -1 means end == TextLength.
1524 * start and end need not be ordered.
1527 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1533 end
= get_text_length(es
);
1541 if (es
->style
& ES_MULTILINE
)
1542 EDIT_ML_InvalidateText(es
, start
, end
);
1544 EDIT_SL_InvalidateText(es
, start
, end
);
1548 /*********************************************************************
1552 * note: unlike the specs say: the order of start and end
1553 * _is_ preserved in Windows. (i.e. start can be > end)
1554 * In other words: this handler is OK
1557 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1559 UINT old_start
= es
->selection_start
;
1560 UINT old_end
= es
->selection_end
;
1561 UINT len
= get_text_length(es
);
1563 if (start
== (UINT
)-1) {
1564 start
= es
->selection_end
;
1565 end
= es
->selection_end
;
1567 start
= min(start
, len
);
1568 end
= min(end
, len
);
1570 es
->selection_start
= start
;
1571 es
->selection_end
= end
;
1573 es
->flags
|= EF_AFTER_WRAP
;
1575 es
->flags
&= ~EF_AFTER_WRAP
;
1576 /* Compute the necessary invalidation region. */
1577 /* Note that we don't need to invalidate regions which have
1578 * "never" been selected, or those which are "still" selected.
1579 * In fact, every time we hit a selection boundary, we can
1580 * *toggle* whether we need to invalidate. Thus we can optimize by
1581 * *sorting* the interval endpoints. Let's assume that we sort them
1583 * start <= end <= old_start <= old_end
1584 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1585 * in 5 comparisons; i.e. it is impossible to do better than the
1587 ORDER_UINT(end
, old_end
);
1588 ORDER_UINT(start
, old_start
);
1589 ORDER_UINT(old_start
, old_end
);
1590 ORDER_UINT(start
, end
);
1591 /* Note that at this point 'end' and 'old_start' are not in order, but
1592 * start is definitely the min. and old_end is definitely the max. */
1593 if (end
!= old_start
)
1597 * ORDER_UINT32(end, old_start);
1598 * EDIT_InvalidateText(es, start, end);
1599 * EDIT_InvalidateText(es, old_start, old_end);
1600 * in place of the following if statement.
1601 * (That would complete the optimal five-comparison four-element sort.)
1603 if (old_start
> end
)
1605 EDIT_InvalidateText(es
, start
, end
);
1606 EDIT_InvalidateText(es
, old_start
, old_end
);
1610 EDIT_InvalidateText(es
, start
, old_start
);
1611 EDIT_InvalidateText(es
, end
, old_end
);
1614 else EDIT_InvalidateText(es
, start
, old_end
);
1618 /*********************************************************************
1620 * EDIT_UpdateScrollInfo
1623 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1625 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1628 si
.cbSize
= sizeof(SCROLLINFO
);
1629 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1631 si
.nMax
= es
->line_count
- 1;
1632 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1633 si
.nPos
= es
->y_offset
;
1634 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1635 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1636 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1639 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1642 si
.cbSize
= sizeof(SCROLLINFO
);
1643 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1645 si
.nMax
= es
->text_width
- 1;
1646 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1647 si
.nPos
= es
->x_offset
;
1648 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1649 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1650 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1655 /*********************************************************************
1657 * EDIT_EM_LineScroll_internal
1659 * Version of EDIT_EM_LineScroll for internal use.
1660 * It doesn't refuse if ES_MULTILINE is set and assumes that
1661 * dx is in pixels, dy - in lines.
1664 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1667 INT x_offset_in_pixels
;
1668 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1671 if (es
->style
& ES_MULTILINE
)
1673 x_offset_in_pixels
= es
->x_offset
;
1678 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1681 if (-dx
> x_offset_in_pixels
)
1682 dx
= -x_offset_in_pixels
;
1683 if (dx
> es
->text_width
- x_offset_in_pixels
)
1684 dx
= es
->text_width
- x_offset_in_pixels
;
1685 nyoff
= max(0, es
->y_offset
+ dy
);
1686 if (nyoff
>= es
->line_count
- lines_per_page
)
1687 nyoff
= max(0, es
->line_count
- lines_per_page
);
1688 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1693 es
->y_offset
= nyoff
;
1694 if(es
->style
& ES_MULTILINE
)
1697 es
->x_offset
+= dx
/ es
->char_width
;
1699 GetClientRect(es
->hwndSelf
, &rc1
);
1700 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1701 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1702 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1703 /* force scroll info update */
1704 EDIT_UpdateScrollInfo(es
);
1706 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1707 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1708 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1709 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1713 /*********************************************************************
1717 * NOTE: dx is in average character widths, dy - in lines;
1720 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1722 if (!(es
->style
& ES_MULTILINE
))
1725 dx
*= es
->char_width
;
1726 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1730 /*********************************************************************
1735 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1739 if (!(es
->style
& ES_MULTILINE
))
1740 return (LRESULT
)FALSE
;
1750 if (es
->y_offset
< es
->line_count
- 1)
1755 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1758 if (es
->y_offset
< es
->line_count
- 1)
1759 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1762 return (LRESULT
)FALSE
;
1765 INT vlc
= get_vertical_line_count(es
);
1766 /* check if we are going to move too far */
1767 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1768 dy
= es
->line_count
- vlc
- es
->y_offset
;
1770 /* Notification is done in EDIT_EM_LineScroll */
1772 EDIT_EM_LineScroll(es
, 0, dy
);
1775 return MAKELONG((SHORT
)dy
, (BOOL
)TRUE
);
1777 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
1782 /*********************************************************************
1787 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1790 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1791 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1792 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1796 /*********************************************************************
1801 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1803 if (es
->style
& ES_MULTILINE
) {
1807 INT cw
= es
->char_width
;
1812 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1813 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1814 vlc
= get_vertical_line_count(es
);
1815 if (l
>= es
->y_offset
+ vlc
)
1816 dy
= l
- vlc
+ 1 - es
->y_offset
;
1817 if (l
< es
->y_offset
)
1818 dy
= l
- es
->y_offset
;
1819 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1820 if (x
< es
->format_rect
.left
)
1821 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1822 if (x
> es
->format_rect
.right
)
1823 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1824 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1826 /* check if we are going to move too far */
1827 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1828 dx
= es
->text_width
- ww
- es
->x_offset
;
1829 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1830 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1837 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1838 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1839 if (x
< es
->format_rect
.left
) {
1840 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1843 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1844 } while ((x
< goal
) && es
->x_offset
);
1845 /* FIXME: use ScrollWindow() somehow to improve performance */
1846 EDIT_UpdateText(es
, NULL
, TRUE
);
1847 } else if (x
> es
->format_rect
.right
) {
1849 INT len
= get_text_length(es
);
1850 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1853 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1854 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1855 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1856 /* FIXME: use ScrollWindow() somehow to improve performance */
1857 EDIT_UpdateText(es
, NULL
, TRUE
);
1861 if(es
->flags
& EF_FOCUSED
)
1862 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1866 /*********************************************************************
1871 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1873 INT e
= es
->selection_end
;
1877 if ((es
->style
& ES_MULTILINE
) && e
&&
1878 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1880 if (e
&& (es
->text
[e
- 1] == '\r'))
1884 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1885 EDIT_EM_ScrollCaret(es
);
1889 /*********************************************************************
1893 * Only for multi line controls
1894 * Move the caret one line down, on a column with the nearest
1895 * x coordinate on the screen (might be a different column).
1898 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1900 INT s
= es
->selection_start
;
1901 INT e
= es
->selection_end
;
1902 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1903 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1904 INT x
= (short)LOWORD(pos
);
1905 INT y
= (short)HIWORD(pos
);
1907 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1910 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1911 EDIT_EM_ScrollCaret(es
);
1915 /*********************************************************************
1920 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1922 BOOL after_wrap
= FALSE
;
1925 /* Pass a high value in x to make sure of receiving the end of the line */
1926 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1927 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1928 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1930 e
= get_text_length(es
);
1931 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1932 EDIT_EM_ScrollCaret(es
);
1936 /*********************************************************************
1941 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1943 INT e
= es
->selection_end
;
1947 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1948 if (es
->text
[e
] == '\n')
1950 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1954 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1955 EDIT_EM_ScrollCaret(es
);
1959 /*********************************************************************
1963 * Home key: move to beginning of line.
1966 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1970 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1971 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1972 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1973 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1976 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1977 EDIT_EM_ScrollCaret(es
);
1981 /*********************************************************************
1983 * EDIT_MovePageDown_ML
1985 * Only for multi line controls
1986 * Move the caret one page down, on a column with the nearest
1987 * x coordinate on the screen (might be a different column).
1990 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1992 INT s
= es
->selection_start
;
1993 INT e
= es
->selection_end
;
1994 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1995 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1996 INT x
= (short)LOWORD(pos
);
1997 INT y
= (short)HIWORD(pos
);
1999 e
= EDIT_CharFromPos(es
, x
,
2000 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2004 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2005 EDIT_EM_ScrollCaret(es
);
2009 /*********************************************************************
2011 * EDIT_MovePageUp_ML
2013 * Only for multi line controls
2014 * Move the caret one page up, on a column with the nearest
2015 * x coordinate on the screen (might be a different column).
2018 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2020 INT s
= es
->selection_start
;
2021 INT e
= es
->selection_end
;
2022 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2023 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2024 INT x
= (short)LOWORD(pos
);
2025 INT y
= (short)HIWORD(pos
);
2027 e
= EDIT_CharFromPos(es
, x
,
2028 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2032 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2033 EDIT_EM_ScrollCaret(es
);
2037 /*********************************************************************
2041 * Only for multi line controls
2042 * Move the caret one line up, on a column with the nearest
2043 * x coordinate on the screen (might be a different column).
2046 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2048 INT s
= es
->selection_start
;
2049 INT e
= es
->selection_end
;
2050 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2051 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2052 INT x
= (short)LOWORD(pos
);
2053 INT y
= (short)HIWORD(pos
);
2055 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2058 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2059 EDIT_EM_ScrollCaret(es
);
2063 /*********************************************************************
2065 * EDIT_MoveWordBackward
2068 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2070 INT s
= es
->selection_start
;
2071 INT e
= es
->selection_end
;
2076 l
= EDIT_EM_LineFromChar(es
, e
);
2077 ll
= EDIT_EM_LineLength(es
, e
);
2078 li
= EDIT_EM_LineIndex(es
, l
);
2081 li
= EDIT_EM_LineIndex(es
, l
- 1);
2082 e
= li
+ EDIT_EM_LineLength(es
, li
);
2085 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2089 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2090 EDIT_EM_ScrollCaret(es
);
2094 /*********************************************************************
2096 * EDIT_MoveWordForward
2099 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2101 INT s
= es
->selection_start
;
2102 INT e
= es
->selection_end
;
2107 l
= EDIT_EM_LineFromChar(es
, e
);
2108 ll
= EDIT_EM_LineLength(es
, e
);
2109 li
= EDIT_EM_LineIndex(es
, l
);
2111 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2112 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2114 e
= li
+ EDIT_CallWordBreakProc(es
,
2115 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2119 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2120 EDIT_EM_ScrollCaret(es
);
2124 /*********************************************************************
2129 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2133 LOGFONTW underline_font
;
2134 HFONT hUnderline
= 0;
2143 BkMode
= GetBkMode(dc
);
2144 BkColor
= GetBkColor(dc
);
2145 TextColor
= GetTextColor(dc
);
2147 if (es
->composition_len
== 0)
2149 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2150 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2151 SetBkMode( dc
, OPAQUE
);
2155 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2156 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2157 underline_font
.lfUnderline
= TRUE
;
2158 hUnderline
= CreateFontIndirectW(&underline_font
);
2159 old_font
= SelectObject(dc
,hUnderline
);
2162 li
= EDIT_EM_LineIndex(es
, line
);
2163 if (es
->style
& ES_MULTILINE
) {
2164 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2165 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2167 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2168 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2169 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2171 if (es
->style
& ES_PASSWORD
)
2172 HeapFree(GetProcessHeap(), 0, text
);
2175 if (es
->composition_len
== 0)
2177 SetBkColor(dc
, BkColor
);
2178 SetTextColor(dc
, TextColor
);
2179 SetBkMode( dc
, BkMode
);
2184 SelectObject(dc
,old_font
);
2186 DeleteObject(hUnderline
);
2193 /*********************************************************************
2198 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2200 INT s
= es
->selection_start
;
2201 INT e
= es
->selection_end
;
2208 if (es
->style
& ES_MULTILINE
) {
2209 INT vlc
= get_vertical_line_count(es
);
2211 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2216 TRACE("line=%d\n", line
);
2218 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2219 x
= (short)LOWORD(pos
);
2220 y
= (short)HIWORD(pos
);
2221 li
= EDIT_EM_LineIndex(es
, line
);
2222 ll
= EDIT_EM_LineLength(es
, li
);
2223 s
= min(es
->selection_start
, es
->selection_end
);
2224 e
= max(es
->selection_start
, es
->selection_end
);
2225 s
= min(li
+ ll
, max(li
, s
));
2226 e
= min(li
+ ll
, max(li
, e
));
2227 if (rev
&& (s
!= e
) &&
2228 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2229 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2230 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2231 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2233 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2237 /*********************************************************************
2239 * EDIT_AdjustFormatRect
2241 * Adjusts the format rectangle for the current font and the
2242 * current client rectangle.
2245 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2249 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2250 if (es
->style
& ES_MULTILINE
)
2252 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2254 vlc
= get_vertical_line_count(es
);
2255 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2257 /* correct es->x_offset */
2258 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2259 max_x_offset
= es
->text_width
- fw
;
2260 if(max_x_offset
< 0) max_x_offset
= 0;
2261 if(es
->x_offset
> max_x_offset
)
2262 es
->x_offset
= max_x_offset
;
2264 /* correct es->y_offset */
2265 max_y_offset
= es
->line_count
- vlc
;
2266 if(max_y_offset
< 0) max_y_offset
= 0;
2267 if(es
->y_offset
> max_y_offset
)
2268 es
->y_offset
= max_y_offset
;
2270 /* force scroll info update */
2271 EDIT_UpdateScrollInfo(es
);
2274 /* Windows doesn't care to fix text placement for SL controls */
2275 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2277 /* Always stay within the client area */
2278 GetClientRect(es
->hwndSelf
, &ClientRect
);
2279 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2281 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2282 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2284 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2288 /*********************************************************************
2292 * note: this is not (exactly) the handler called on EM_SETRECTNP
2293 * it is also used to set the rect of a single line control
2296 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2300 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2302 CopyRect(&es
->format_rect
, rc
);
2304 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2305 es
->format_rect
.left
++;
2306 es
->format_rect
.right
--;
2308 if (es
->format_rect
.bottom
- es
->format_rect
.top
2309 >= es
->line_height
+ 2)
2311 es
->format_rect
.top
++;
2312 es
->format_rect
.bottom
--;
2315 else if (es
->style
& WS_BORDER
) {
2316 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2317 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2318 es
->format_rect
.left
+= bw
;
2319 es
->format_rect
.right
-= bw
;
2320 if (es
->format_rect
.bottom
- es
->format_rect
.top
2321 >= es
->line_height
+ 2 * bh
)
2323 es
->format_rect
.top
+= bh
;
2324 es
->format_rect
.bottom
-= bh
;
2328 es
->format_rect
.left
+= es
->left_margin
;
2329 es
->format_rect
.right
-= es
->right_margin
;
2330 EDIT_AdjustFormatRect(es
);
2334 /*********************************************************************
2338 * returns line number (not index) in high-order word of result.
2339 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2340 * to Richedit, not to the edit control. Original documentation is valid.
2341 * FIXME: do the specs mean to return -1 if outside client area or
2342 * if outside formatting rectangle ???
2345 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2353 GetClientRect(es
->hwndSelf
, &rc
);
2354 if (!PtInRect(&rc
, pt
))
2357 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2358 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2362 /*********************************************************************
2366 * Enable or disable soft breaks.
2368 * This means: insert or remove the soft linebreak character (\r\r\n).
2369 * Take care to check if the text still fits the buffer after insertion.
2370 * If not, notify with EN_ERRSPACE.
2373 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2375 es
->flags
&= ~EF_USE_SOFTBRK
;
2377 es
->flags
|= EF_USE_SOFTBRK
;
2378 FIXME("soft break enabled, not implemented\n");
2384 /*********************************************************************
2388 * Hopefully this won't fire back at us.
2389 * We always start with a fixed buffer in the local heap.
2390 * Despite of the documentation says that the local heap is used
2391 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2392 * buffer on the local heap.
2395 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2399 if (!(es
->style
& ES_MULTILINE
))
2403 hLocal
= es
->hloc32W
;
2409 UINT countA
, alloc_size
;
2410 TRACE("Allocating 32-bit ANSI alias buffer\n");
2411 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2412 alloc_size
= ROUND_TO_GROW(countA
);
2413 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2415 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2418 textA
= LocalLock(es
->hloc32A
);
2419 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2420 LocalUnlock(es
->hloc32A
);
2422 hLocal
= es
->hloc32A
;
2425 es
->flags
|= EF_APP_HAS_HANDLE
;
2426 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2432 /*********************************************************************
2436 * Hopefully this won't fire back at us.
2437 * We always start with a buffer in 32 bit linear memory.
2438 * However, with this message a 16 bit application requests
2439 * a handle of 16 bit local heap memory, where it expects to find
2441 * It's a pitty that from this moment on we have to use this
2442 * local heap, because applications may rely on the handle
2445 * In this function we'll try to switch to local heap.
2447 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2450 UINT countA
, alloc_size
;
2451 STACK16FRAME
* stack16
;
2454 if (!(es
->style
& ES_MULTILINE
))
2460 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2461 oldDS
= stack16
->ds
;
2462 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2464 if (!LocalHeapSize16()) {
2466 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2467 ERR("could not initialize local heap\n");
2470 TRACE("local heap initialized\n");
2473 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2474 alloc_size
= ROUND_TO_GROW(countA
);
2476 TRACE("Allocating 16-bit ANSI alias buffer\n");
2477 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2478 ERR("could not allocate new 16 bit buffer\n");
2482 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2483 ERR("could not lock new 16 bit buffer\n");
2484 LocalFree16(es
->hloc16
);
2489 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2490 LocalUnlock16(es
->hloc16
);
2491 es
->flags
|= EF_APP_HAS_HANDLE
;
2493 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2496 stack16
->ds
= oldDS
;
2502 /*********************************************************************
2507 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2510 INT line_len
, dst_len
;
2513 if (es
->style
& ES_MULTILINE
) {
2514 if (line
>= es
->line_count
)
2518 i
= EDIT_EM_LineIndex(es
, line
);
2520 line_len
= EDIT_EM_LineLength(es
, i
);
2521 dst_len
= *(WORD
*)dst
;
2524 if(dst_len
<= line_len
)
2526 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2529 else /* Append 0 if enough space */
2531 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2538 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2539 if(!ret
&& line_len
) /* Insufficient buffer size */
2541 if(ret
< dst_len
) /* Append 0 if enough space */
2542 ((LPSTR
)dst
)[ret
] = 0;
2548 /*********************************************************************
2553 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2555 UINT s
= es
->selection_start
;
2556 UINT e
= es
->selection_end
;
2563 return MAKELONG(s
, e
);
2567 /*********************************************************************
2571 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2574 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2576 UINT strl
= strlenW(lpsz_replace
);
2577 UINT tl
= get_text_length(es
);
2588 TRACE("%s, can_undo %d, send_update %d\n",
2589 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2591 s
= es
->selection_start
;
2592 e
= es
->selection_end
;
2594 if ((s
== e
) && !strl
)
2599 size
= tl
- (e
- s
) + strl
;
2603 /* Issue the EN_MAXTEXT notification and continue with replacing text
2604 * such that buffer limit is honored. */
2605 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2606 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2607 /* Buffer limit can be smaller than the actual length of text in combobox */
2608 if (es
->buffer_limit
< (tl
- (e
-s
)))
2611 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2614 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2618 /* there is something to be deleted */
2619 TRACE("deleting stuff.\n");
2621 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2623 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2624 buf
[bufl
] = 0; /* ensure 0 termination */
2626 strcpyW(es
->text
+ s
, es
->text
+ e
);
2627 text_buffer_changed(es
);
2630 /* there is an insertion */
2631 tl
= get_text_length(es
);
2632 TRACE("inserting stuff (tl %d, strl %d, selstart %d (%s), text %s)\n", tl
, strl
, s
, debugstr_w(es
->text
+ s
), debugstr_w(es
->text
));
2633 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2635 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2636 p
[i
] = lpsz_replace
[i
];
2637 if(es
->style
& ES_UPPERCASE
)
2638 CharUpperBuffW(p
, strl
);
2639 else if(es
->style
& ES_LOWERCASE
)
2640 CharLowerBuffW(p
, strl
);
2641 text_buffer_changed(es
);
2643 if (es
->style
& ES_MULTILINE
)
2645 INT st
= min(es
->selection_start
, es
->selection_end
);
2646 INT vlc
= get_vertical_line_count(es
);
2648 hrgn
= CreateRectRgn(0, 0, 0, 0);
2649 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2650 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2651 /* if text is too long undo all changes */
2652 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2654 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2656 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2658 text_buffer_changed(es
);
2659 EDIT_BuildLineDefs_ML(es
, s
, e
,
2660 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2663 hrgn
= CreateRectRgn(0, 0, 0, 0);
2664 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2668 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2669 EDIT_CalcLineWidth_SL(es
);
2670 /* remove chars that don't fit */
2671 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2672 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2673 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2675 EDIT_CalcLineWidth_SL(es
);
2677 text_buffer_changed(es
);
2678 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2684 utl
= strlenW(es
->undo_text
);
2685 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2686 /* undo-buffer is extended to the right */
2687 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2688 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2689 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2690 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2691 /* undo-buffer is extended to the left */
2692 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2693 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2695 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2697 es
->undo_position
= s
;
2699 /* new undo-buffer */
2700 EDIT_MakeUndoFit(es
, e
- s
);
2701 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2702 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2703 es
->undo_position
= s
;
2705 /* any deletion makes the old insertion-undo invalid */
2706 es
->undo_insert_count
= 0;
2708 EDIT_EM_EmptyUndoBuffer(es
);
2712 if ((s
== es
->undo_position
) ||
2713 ((es
->undo_insert_count
) &&
2714 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2716 * insertion is new and at delete position or
2717 * an extension to either left or right
2719 es
->undo_insert_count
+= strl
;
2721 /* new insertion undo */
2722 es
->undo_position
= s
;
2723 es
->undo_insert_count
= strl
;
2724 /* new insertion makes old delete-buffer invalid */
2725 *es
->undo_text
= '\0';
2728 EDIT_EM_EmptyUndoBuffer(es
);
2732 HeapFree(GetProcessHeap(), 0, buf
);
2736 /* If text has been deleted and we're right or center aligned then scroll rightward */
2737 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2739 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2741 if (delta
< 0 && es
->x_offset
)
2743 if (abs(delta
) > es
->x_offset
)
2746 es
->x_offset
+= delta
;
2750 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2751 es
->flags
|= EF_MODIFIED
;
2752 if (send_update
) es
->flags
|= EF_UPDATE
;
2755 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2759 EDIT_UpdateText(es
, NULL
, TRUE
);
2761 EDIT_EM_ScrollCaret(es
);
2763 /* force scroll info update */
2764 EDIT_UpdateScrollInfo(es
);
2767 if(send_update
|| (es
->flags
& EF_UPDATE
))
2769 es
->flags
&= ~EF_UPDATE
;
2770 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2775 /*********************************************************************
2779 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2782 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2784 if (!(es
->style
& ES_MULTILINE
))
2788 WARN("called with NULL handle\n");
2792 EDIT_UnlockBuffer(es
, TRUE
);
2797 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2798 HANDLE16 oldDS
= stack16
->ds
;
2800 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2801 LocalFree16(es
->hloc16
);
2802 stack16
->ds
= oldDS
;
2811 LocalFree(es
->hloc32A
);
2823 countA
= LocalSize(hloc
);
2824 textA
= LocalLock(hloc
);
2825 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2826 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2828 ERR("Could not allocate new unicode buffer\n");
2831 textW
= LocalLock(hloc32W_new
);
2832 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2833 LocalUnlock(hloc32W_new
);
2837 LocalFree(es
->hloc32W
);
2839 es
->hloc32W
= hloc32W_new
;
2843 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2845 es
->flags
|= EF_APP_HAS_HANDLE
;
2846 EDIT_LockBuffer(es
);
2848 es
->x_offset
= es
->y_offset
= 0;
2849 es
->selection_start
= es
->selection_end
= 0;
2850 EDIT_EM_EmptyUndoBuffer(es
);
2851 es
->flags
&= ~EF_MODIFIED
;
2852 es
->flags
&= ~EF_UPDATE
;
2853 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2854 EDIT_UpdateText(es
, NULL
, TRUE
);
2855 EDIT_EM_ScrollCaret(es
);
2856 /* force scroll info update */
2857 EDIT_UpdateScrollInfo(es
);
2862 /*********************************************************************
2866 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2869 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
2871 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2872 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2873 HANDLE16 oldDS
= stack16
->ds
;
2879 if (!(es
->style
& ES_MULTILINE
))
2883 WARN("called with NULL handle\n");
2887 EDIT_UnlockBuffer(es
, TRUE
);
2891 LocalFree(es
->hloc32A
);
2895 stack16
->ds
= hInstance
;
2896 countA
= LocalSize16(hloc
);
2897 textA
= MapSL(LocalLock16(hloc
));
2898 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2899 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2901 ERR("Could not allocate new unicode buffer\n");
2904 textW
= LocalLock(hloc32W_new
);
2905 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2906 LocalUnlock(hloc32W_new
);
2907 LocalUnlock16(hloc
);
2908 stack16
->ds
= oldDS
;
2911 LocalFree(es
->hloc32W
);
2913 es
->hloc32W
= hloc32W_new
;
2916 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2918 es
->flags
|= EF_APP_HAS_HANDLE
;
2919 EDIT_LockBuffer(es
);
2921 es
->x_offset
= es
->y_offset
= 0;
2922 es
->selection_start
= es
->selection_end
= 0;
2923 EDIT_EM_EmptyUndoBuffer(es
);
2924 es
->flags
&= ~EF_MODIFIED
;
2925 es
->flags
&= ~EF_UPDATE
;
2926 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2927 EDIT_UpdateText(es
, NULL
, TRUE
);
2928 EDIT_EM_ScrollCaret(es
);
2929 /* force scroll info update */
2930 EDIT_UpdateScrollInfo(es
);
2935 /*********************************************************************
2939 * NOTE: this version currently implements WinNT limits
2942 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2944 if (!limit
) limit
= ~0u;
2945 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2946 es
->buffer_limit
= limit
;
2950 /*********************************************************************
2954 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2955 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2956 * margin according to the textmetrics of the current font.
2958 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2959 * of the char's width as the margin, but this is not how Windows handles this.
2960 * For all other fonts Windows sets the margins to zero.
2962 * FIXME - When EC_USEFONTINFO is used the margins only change if the
2963 * edit control is equal to or larger than a certain size.
2964 * Interestingly if one subtracts both the left and right margins from
2965 * this size one always seems to get an even number. The extents of
2966 * the (four character) string "'**'" match this quite closely, so
2967 * we'll use this until we come up with a better idea.
2969 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
2971 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
2974 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
2975 return sz
.cx
+ left
+ right
;
2978 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2979 WORD left
, WORD right
, BOOL repaint
)
2982 INT default_left_margin
= 0; /* in pixels */
2983 INT default_right_margin
= 0; /* in pixels */
2985 /* Set the default margins depending on the font */
2986 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2987 HDC dc
= GetDC(es
->hwndSelf
);
2988 HFONT old_font
= SelectObject(dc
, es
->font
);
2989 GetTextMetricsW(dc
, &tm
);
2990 /* The default margins are only non zero for TrueType or Vector fonts */
2991 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2994 /* This must be calculated more exactly! But how? */
2995 default_left_margin
= tm
.tmAveCharWidth
/ 2;
2996 default_right_margin
= tm
.tmAveCharWidth
/ 2;
2997 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
2998 GetClientRect(es
->hwndSelf
, &rc
);
2999 if(rc
.right
- rc
.left
< min_size
) {
3000 default_left_margin
= es
->left_margin
;
3001 default_right_margin
= es
->right_margin
;
3004 SelectObject(dc
, old_font
);
3005 ReleaseDC(es
->hwndSelf
, dc
);
3008 if (action
& EC_LEFTMARGIN
) {
3009 es
->format_rect
.left
-= es
->left_margin
;
3010 if (left
!= EC_USEFONTINFO
)
3011 es
->left_margin
= left
;
3013 es
->left_margin
= default_left_margin
;
3014 es
->format_rect
.left
+= es
->left_margin
;
3017 if (action
& EC_RIGHTMARGIN
) {
3018 es
->format_rect
.right
+= es
->right_margin
;
3019 if (right
!= EC_USEFONTINFO
)
3020 es
->right_margin
= right
;
3022 es
->right_margin
= default_right_margin
;
3023 es
->format_rect
.right
-= es
->right_margin
;
3026 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3027 EDIT_AdjustFormatRect(es
);
3028 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3031 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3035 /*********************************************************************
3037 * EM_SETPASSWORDCHAR
3040 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3044 if (es
->style
& ES_MULTILINE
)
3047 if (es
->password_char
== c
)
3050 style
= GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
);
3051 es
->password_char
= c
;
3053 SetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3054 es
->style
|= ES_PASSWORD
;
3056 SetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3057 es
->style
&= ~ES_PASSWORD
;
3059 EDIT_UpdateText(es
, NULL
, TRUE
);
3063 /*********************************************************************
3068 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3070 if (!(es
->style
& ES_MULTILINE
))
3072 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3073 es
->tabs_count
= count
;
3077 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3078 if (es
->tabs
== NULL
)
3083 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3090 /*********************************************************************
3095 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3097 if (!(es
->style
& ES_MULTILINE
))
3099 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3100 es
->tabs_count
= count
;
3105 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3106 for (i
= 0 ; i
< count
; i
++)
3107 es
->tabs
[i
] = *tabs
++;
3114 /*********************************************************************
3116 * EM_SETWORDBREAKPROC
3119 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3121 if (es
->word_break_proc
== wbp
)
3124 es
->word_break_proc
= wbp
;
3126 es
->word_break_proc16
= NULL
;
3129 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3130 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3131 EDIT_UpdateText(es
, NULL
, TRUE
);
3137 /*********************************************************************
3139 * EM_SETWORDBREAKPROC16
3142 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3144 if (es
->word_break_proc16
== wbp
)
3147 es
->word_break_proc
= NULL
;
3148 es
->word_break_proc16
= wbp
;
3149 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3150 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3151 EDIT_UpdateText(es
, NULL
, TRUE
);
3157 /*********************************************************************
3162 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3167 /* As per MSDN spec, for a single-line edit control,
3168 the return value is always TRUE */
3169 if( es
->style
& ES_READONLY
)
3170 return !(es
->style
& ES_MULTILINE
);
3172 ulength
= strlenW(es
->undo_text
);
3174 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3178 strcpyW(utext
, es
->undo_text
);
3180 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3181 es
->undo_insert_count
, debugstr_w(utext
));
3183 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3184 EDIT_EM_EmptyUndoBuffer(es
);
3185 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3186 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3187 /* send the notification after the selection start and end are set */
3188 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3189 EDIT_EM_ScrollCaret(es
);
3190 HeapFree(GetProcessHeap(), 0, utext
);
3192 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3193 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3198 /* Helper function for WM_CHAR
3200 * According to an MSDN blog article titled "Just because you're a control
3201 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3202 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3203 * a dialog box or not.
3205 static BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3207 return (es
->flags
& EF_DIALOGMODE
);
3211 /*********************************************************************
3216 static void EDIT_WM_Paste(EDITSTATE
*es
)
3221 /* Protect read-only edit control from modification */
3222 if(es
->style
& ES_READONLY
)
3225 OpenClipboard(es
->hwndSelf
);
3226 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
3227 src
= GlobalLock(hsrc
);
3228 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
3231 else if (es
->style
& ES_PASSWORD
) {
3232 /* clear selected text in password edit box even with empty clipboard */
3233 const WCHAR empty_strW
[] = { 0 };
3234 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
3240 /*********************************************************************
3245 static void EDIT_WM_Copy(EDITSTATE
*es
)
3247 INT s
= min(es
->selection_start
, es
->selection_end
);
3248 INT e
= max(es
->selection_start
, es
->selection_end
);
3256 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3257 dst
= GlobalLock(hdst
);
3258 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3259 dst
[len
] = 0; /* ensure 0 termination */
3260 TRACE("%s\n", debugstr_w(dst
));
3262 OpenClipboard(es
->hwndSelf
);
3264 SetClipboardData(CF_UNICODETEXT
, hdst
);
3269 /*********************************************************************
3274 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
3276 static const WCHAR empty_stringW
[] = {0};
3278 /* Protect read-only edit control from modification */
3279 if(es
->style
& ES_READONLY
)
3282 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
3286 /*********************************************************************
3291 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3298 /*********************************************************************
3303 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3307 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3311 /* If it's not a multiline edit box, it would be ignored below.
3312 * For multiline edit without ES_WANTRETURN, we have to make a
3315 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3316 if (EDIT_IsInsideDialog(es
))
3319 if (es
->style
& ES_MULTILINE
) {
3320 if (es
->style
& ES_READONLY
) {
3321 EDIT_MoveHome(es
, FALSE
, FALSE
);
3322 EDIT_MoveDown_ML(es
, FALSE
);
3324 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3325 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3330 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3332 static const WCHAR tabW
[] = {'\t',0};
3333 if (EDIT_IsInsideDialog(es
))
3335 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3339 if (!(es
->style
& ES_READONLY
) && !control
) {
3340 if (es
->selection_start
!= es
->selection_end
)
3343 /* delete character left of caret */
3344 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3345 EDIT_MoveBackward(es
, TRUE
);
3351 if (!(es
->style
& ES_PASSWORD
))
3352 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3355 if (!(es
->style
& ES_READONLY
))
3356 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3359 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3360 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3363 if (!(es
->style
& ES_READONLY
))
3364 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3368 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3369 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3372 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3376 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3384 /*********************************************************************
3388 * Note: the resource files resource/sysres_??.rc cannot define a
3389 * single popup menu. Hence we use a (dummy) menubar
3390 * containing the single popup menu as its first item.
3392 * FIXME: the message identifiers have been chosen arbitrarily,
3393 * hence we use MF_BYPOSITION.
3394 * We might as well use the "real" values (anybody knows ?)
3395 * The menu definition is in resources/sysres_??.rc.
3396 * Once these are OK, we better use MF_BYCOMMAND here
3397 * (as we do in EDIT_WM_Command()).
3400 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3403 HMENU menu
= LoadMenuA(User32Instance
, "EDITMENU");
3405 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3407 HMENU popup
= GetSubMenu(menu
, 0);
3408 UINT start
= es
->selection_start
;
3409 UINT end
= es
->selection_end
;
3412 ORDER_UINT(start
, end
);
3415 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3417 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3419 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3421 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3423 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3425 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3427 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3430 /* Windows places the menu at the edit's center in this case */
3431 GetClientRect(es
->hwndSelf
, &rc
);
3432 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
3433 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3434 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3437 selectedItem
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
, x
, y
, 0, es
->hwndSelf
, NULL
);
3439 switch (selectedItem
) {
3441 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3444 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3447 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3450 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3453 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3456 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3457 EDIT_EM_ScrollCaret(es
);
3460 ERR("unknown menu item, please report\n");
3468 /*********************************************************************
3473 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3475 if(!count
) return 0;
3479 lstrcpynW(dst
, es
->text
, count
);
3480 return strlenW(dst
);
3484 LPSTR textA
= (LPSTR
)dst
;
3485 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3486 textA
[count
- 1] = 0; /* ensure 0 termination */
3487 return strlen(textA
);
3491 /*********************************************************************
3496 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3498 HWND hLBox
= es
->hwndListBox
;
3506 hCombo
= GetParent(es
->hwndSelf
);
3510 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3512 if (key
== VK_UP
|| key
== VK_DOWN
)
3514 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3517 if (msg
== WM_KEYDOWN
|| nEUI
)
3518 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3524 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3526 /* make sure ComboLBox pops up */
3527 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3532 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3535 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3537 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3539 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
3544 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3550 /*********************************************************************
3554 * Handling of special keys that don't produce a WM_CHAR
3555 * (i.e. non-printable keys) & Backspace & Delete
3558 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3563 if (GetKeyState(VK_MENU
) & 0x8000)
3566 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3567 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3572 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3577 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3578 EDIT_MoveUp_ML(es
, shift
);
3581 EDIT_MoveWordBackward(es
, shift
);
3583 EDIT_MoveBackward(es
, shift
);
3586 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3590 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3591 EDIT_MoveDown_ML(es
, shift
);
3593 EDIT_MoveWordForward(es
, shift
);
3595 EDIT_MoveForward(es
, shift
);
3598 EDIT_MoveHome(es
, shift
, control
);
3601 EDIT_MoveEnd(es
, shift
, control
);
3604 if (es
->style
& ES_MULTILINE
)
3605 EDIT_MovePageUp_ML(es
, shift
);
3607 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3610 if (es
->style
& ES_MULTILINE
)
3611 EDIT_MovePageDown_ML(es
, shift
);
3613 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3616 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3617 if (es
->selection_start
!= es
->selection_end
) {
3624 /* delete character left of caret */
3625 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3626 EDIT_MoveBackward(es
, TRUE
);
3628 } else if (control
) {
3629 /* delete to end of line */
3630 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3631 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3634 /* delete character right of caret */
3635 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3636 EDIT_MoveForward(es
, TRUE
);
3644 if (!(es
->style
& ES_READONLY
))
3650 /* If the edit doesn't want the return send a message to the default object */
3651 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3655 if (!EDIT_IsInsideDialog(es
)) break;
3657 dw
= SendMessageW( es
->hwndParent
, DM_GETDEFID
, 0, 0 );
3658 if (HIWORD(dw
) == DC_HASDEFID
)
3660 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3663 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, (LPARAM
)TRUE
);
3664 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3670 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3671 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3674 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3675 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3682 /*********************************************************************
3687 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3689 es
->flags
&= ~EF_FOCUSED
;
3691 if(!(es
->style
& ES_NOHIDESEL
))
3692 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3693 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3698 /*********************************************************************
3702 * The caret position has been set on the WM_LBUTTONDOWN message
3705 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3708 INT e
= es
->selection_end
;
3713 es
->bCaptureState
= TRUE
;
3714 SetCapture(es
->hwndSelf
);
3716 l
= EDIT_EM_LineFromChar(es
, e
);
3717 li
= EDIT_EM_LineIndex(es
, l
);
3718 ll
= EDIT_EM_LineLength(es
, e
);
3719 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3720 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3721 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3722 EDIT_EM_ScrollCaret(es
);
3723 es
->region_posx
= es
->region_posy
= 0;
3724 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3729 /*********************************************************************
3734 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3739 es
->bCaptureState
= TRUE
;
3740 SetCapture(es
->hwndSelf
);
3741 EDIT_ConfinePoint(es
, &x
, &y
);
3742 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3743 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3744 EDIT_EM_ScrollCaret(es
);
3745 es
->region_posx
= es
->region_posy
= 0;
3746 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3748 if (!(es
->flags
& EF_FOCUSED
))
3749 SetFocus(es
->hwndSelf
);
3755 /*********************************************************************
3760 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3762 if (es
->bCaptureState
) {
3763 KillTimer(es
->hwndSelf
, 0);
3764 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3766 es
->bCaptureState
= FALSE
;
3771 /*********************************************************************
3776 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3778 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3783 /*********************************************************************
3788 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3794 /* If the mouse has been captured by process other than the edit control itself,
3795 * the windows edit controls will not select the strings with mouse move.
3797 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3801 * FIXME: gotta do some scrolling if outside client
3802 * area. Maybe reset the timer ?
3805 EDIT_ConfinePoint(es
, &x
, &y
);
3806 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3807 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3808 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3809 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3810 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3815 /*********************************************************************
3820 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3833 BOOL rev
= es
->bEnableState
&&
3834 ((es
->flags
& EF_FOCUSED
) ||
3835 (es
->style
& ES_NOHIDESEL
));
3836 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3838 GetClientRect(es
->hwndSelf
, &rcClient
);
3840 /* get the background brush */
3841 brush
= EDIT_NotifyCtlColor(es
, dc
);
3843 /* paint the border and the background */
3844 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3846 if(es
->style
& WS_BORDER
) {
3847 bw
= GetSystemMetrics(SM_CXBORDER
);
3848 bh
= GetSystemMetrics(SM_CYBORDER
);
3850 if(es
->style
& ES_MULTILINE
) {
3851 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3852 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3855 /* Draw the frame. Same code as in nonclient.c */
3856 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3857 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3858 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3859 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3860 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3861 SelectObject(dc
, old_brush
);
3863 /* Keep the border clean */
3864 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3865 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3868 GetClipBox(dc
, &rc
);
3869 FillRect(dc
, &rc
, brush
);
3871 IntersectClipRect(dc
, es
->format_rect
.left
,
3872 es
->format_rect
.top
,
3873 es
->format_rect
.right
,
3874 es
->format_rect
.bottom
);
3875 if (es
->style
& ES_MULTILINE
) {
3877 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3880 old_font
= SelectObject(dc
, es
->font
);
3882 if (!es
->bEnableState
)
3883 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3884 GetClipBox(dc
, &rcRgn
);
3885 if (es
->style
& ES_MULTILINE
) {
3886 INT vlc
= get_vertical_line_count(es
);
3887 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3888 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3889 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3890 EDIT_PaintLine(es
, dc
, i
, rev
);
3893 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3894 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3895 EDIT_PaintLine(es
, dc
, 0, rev
);
3898 SelectObject(dc
, old_font
);
3901 EndPaint(es
->hwndSelf
, &ps
);
3905 /*********************************************************************
3910 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3912 es
->flags
|= EF_FOCUSED
;
3914 if (!(es
->style
& ES_NOHIDESEL
))
3915 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3917 /* single line edit updates itself */
3918 if (!(es
->style
& ES_MULTILINE
))
3920 HDC hdc
= GetDC(es
->hwndSelf
);
3921 EDIT_WM_Paint(es
, hdc
);
3922 ReleaseDC(es
->hwndSelf
, hdc
);
3925 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3926 EDIT_SetCaretPos(es
, es
->selection_end
,
3927 es
->flags
& EF_AFTER_WRAP
);
3928 ShowCaret(es
->hwndSelf
);
3929 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3933 /*********************************************************************
3937 * With Win95 look the margins are set to default font value unless
3938 * the system font (font == 0) is being set, in which case they are left
3942 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3950 dc
= GetDC(es
->hwndSelf
);
3952 old_font
= SelectObject(dc
, font
);
3953 GetTextMetricsW(dc
, &tm
);
3954 es
->line_height
= tm
.tmHeight
;
3955 es
->char_width
= tm
.tmAveCharWidth
;
3957 SelectObject(dc
, old_font
);
3958 ReleaseDC(es
->hwndSelf
, dc
);
3960 /* Reset the format rect and the margins */
3961 GetClientRect(es
->hwndSelf
, &clientRect
);
3962 EDIT_SetRectNP(es
, &clientRect
);
3963 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3964 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3966 if (es
->style
& ES_MULTILINE
)
3967 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3969 EDIT_CalcLineWidth_SL(es
);
3972 EDIT_UpdateText(es
, NULL
, TRUE
);
3973 if (es
->flags
& EF_FOCUSED
) {
3975 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
3976 EDIT_SetCaretPos(es
, es
->selection_end
,
3977 es
->flags
& EF_AFTER_WRAP
);
3978 ShowCaret(es
->hwndSelf
);
3983 /*********************************************************************
3988 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3989 * The modified flag is reset. No notifications are sent.
3991 * For single-line controls, reception of WM_SETTEXT triggers:
3992 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3995 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
3997 LPWSTR textW
= NULL
;
3998 if (!unicode
&& text
)
4000 LPCSTR textA
= (LPCSTR
)text
;
4001 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4002 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
4004 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4008 if (es
->flags
& EF_UPDATE
)
4009 /* fixed this bug once; complain if we see it about to happen again. */
4010 ERR("SetSel may generate UPDATE message whose handler may reset "
4013 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4016 TRACE("%s\n", debugstr_w(text
));
4017 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4019 HeapFree(GetProcessHeap(), 0, textW
);
4023 static const WCHAR empty_stringW
[] = {0};
4025 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4028 es
->flags
&= ~EF_MODIFIED
;
4029 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4031 /* Send the notification after the selection start and end have been set
4032 * edit control doesn't send notification on WM_SETTEXT
4033 * if it is multiline, or it is part of combobox
4035 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4037 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
4038 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4040 EDIT_EM_ScrollCaret(es
);
4041 EDIT_UpdateScrollInfo(es
);
4045 /*********************************************************************
4050 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4052 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4054 TRACE("width = %d, height = %d\n", width
, height
);
4055 SetRect(&rc
, 0, 0, width
, height
);
4056 EDIT_SetRectNP(es
, &rc
);
4057 EDIT_UpdateText(es
, NULL
, TRUE
);
4062 /*********************************************************************
4066 * This message is sent by SetWindowLong on having changed either the Style
4067 * or the extended style.
4069 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4071 * See also EDIT_WM_NCCreate
4073 * It appears that the Windows version of the edit control allows the style
4074 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4075 * style variable which will generally be different. In this function we
4076 * update the internal style based on what changed in the externally visible
4079 * Much of this content as based upon the MSDN, especially:
4080 * Platform SDK Documentation -> User Interface Services ->
4081 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4082 * Edit Control Styles
4084 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4086 if (GWL_STYLE
== which
) {
4087 DWORD style_change_mask
;
4089 /* Only a subset of changes can be applied after the control
4092 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4094 if (es
->style
& ES_MULTILINE
)
4095 style_change_mask
|= ES_WANTRETURN
;
4097 new_style
= style
->styleNew
& style_change_mask
;
4099 /* Number overrides lowercase overrides uppercase (at least it
4100 * does in Win95). However I'll bet that ES_NUMBER would be
4101 * invalid under Win 3.1.
4103 if (new_style
& ES_NUMBER
) {
4104 ; /* do not override the ES_NUMBER */
4105 } else if (new_style
& ES_LOWERCASE
) {
4106 new_style
&= ~ES_UPPERCASE
;
4109 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4110 } else if (GWL_EXSTYLE
== which
) {
4111 ; /* FIXME - what is needed here */
4113 WARN ("Invalid style change %ld\n",which
);
4119 /*********************************************************************
4124 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4126 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4127 if (EDIT_EM_CanUndo(es
))
4130 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4131 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4134 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4138 /*********************************************************************
4143 static void EDIT_WM_Timer(EDITSTATE
*es
)
4145 if (es
->region_posx
< 0) {
4146 EDIT_MoveBackward(es
, TRUE
);
4147 } else if (es
->region_posx
> 0) {
4148 EDIT_MoveForward(es
, TRUE
);
4151 * FIXME: gotta do some vertical scrolling here, like
4152 * EDIT_EM_LineScroll(hwnd, 0, 1);
4156 /*********************************************************************
4161 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4166 if (!(es
->style
& ES_MULTILINE
))
4169 if (!(es
->style
& ES_AUTOHSCROLL
))
4173 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4176 TRACE("SB_LINELEFT\n");
4178 dx
= -es
->char_width
;
4181 TRACE("SB_LINERIGHT\n");
4182 if (es
->x_offset
< es
->text_width
)
4183 dx
= es
->char_width
;
4186 TRACE("SB_PAGELEFT\n");
4188 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4191 TRACE("SB_PAGERIGHT\n");
4192 if (es
->x_offset
< es
->text_width
)
4193 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4201 TRACE("SB_RIGHT\n");
4202 if (es
->x_offset
< es
->text_width
)
4203 dx
= es
->text_width
- es
->x_offset
;
4206 TRACE("SB_THUMBTRACK %d\n", pos
);
4207 es
->flags
|= EF_HSCROLL_TRACK
;
4208 if(es
->style
& WS_HSCROLL
)
4209 dx
= pos
- es
->x_offset
;
4214 if(pos
< 0 || pos
> 100) return 0;
4215 /* Assume default scroll range 0-100 */
4216 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4217 new_x
= pos
* (es
->text_width
- fw
) / 100;
4218 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4221 case SB_THUMBPOSITION
:
4222 TRACE("SB_THUMBPOSITION %d\n", pos
);
4223 es
->flags
&= ~EF_HSCROLL_TRACK
;
4224 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4225 dx
= pos
- es
->x_offset
;
4230 if(pos
< 0 || pos
> 100) return 0;
4231 /* Assume default scroll range 0-100 */
4232 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4233 new_x
= pos
* (es
->text_width
- fw
) / 100;
4234 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4237 /* force scroll info update */
4238 EDIT_UpdateScrollInfo(es
);
4239 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4243 TRACE("SB_ENDSCROLL\n");
4246 * FIXME : the next two are undocumented !
4247 * Are we doing the right thing ?
4248 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4249 * although it's also a regular control message.
4251 case EM_GETTHUMB
: /* this one is used by NT notepad */
4257 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4258 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4261 /* Assume default scroll range 0-100 */
4262 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4263 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4265 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4269 case EM_LINESCROLL16
:
4270 TRACE("EM_LINESCROLL16\n");
4276 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4282 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4283 /* check if we are going to move too far */
4284 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4285 dx
= es
->text_width
- fw
- es
->x_offset
;
4287 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4293 /*********************************************************************
4298 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4302 if (!(es
->style
& ES_MULTILINE
))
4305 if (!(es
->style
& ES_AUTOVSCROLL
))
4314 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4315 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4316 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4318 EDIT_EM_Scroll(es
, action
);
4325 TRACE("SB_BOTTOM\n");
4326 dy
= es
->line_count
- 1 - es
->y_offset
;
4329 TRACE("SB_THUMBTRACK %d\n", pos
);
4330 es
->flags
|= EF_VSCROLL_TRACK
;
4331 if(es
->style
& WS_VSCROLL
)
4332 dy
= pos
- es
->y_offset
;
4335 /* Assume default scroll range 0-100 */
4338 if(pos
< 0 || pos
> 100) return 0;
4339 vlc
= get_vertical_line_count(es
);
4340 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4341 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4342 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4343 es
->line_count
, es
->y_offset
, pos
, dy
);
4346 case SB_THUMBPOSITION
:
4347 TRACE("SB_THUMBPOSITION %d\n", pos
);
4348 es
->flags
&= ~EF_VSCROLL_TRACK
;
4349 if(es
->style
& WS_VSCROLL
)
4350 dy
= pos
- es
->y_offset
;
4353 /* Assume default scroll range 0-100 */
4356 if(pos
< 0 || pos
> 100) return 0;
4357 vlc
= get_vertical_line_count(es
);
4358 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4359 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4360 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4361 es
->line_count
, es
->y_offset
, pos
, dy
);
4365 /* force scroll info update */
4366 EDIT_UpdateScrollInfo(es
);
4367 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4371 TRACE("SB_ENDSCROLL\n");
4374 * FIXME : the next two are undocumented !
4375 * Are we doing the right thing ?
4376 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4377 * although it's also a regular control message.
4379 case EM_GETTHUMB
: /* this one is used by NT notepad */
4385 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4386 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4389 /* Assume default scroll range 0-100 */
4390 INT vlc
= get_vertical_line_count(es
);
4391 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4393 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4397 case EM_LINESCROLL16
:
4398 TRACE("EM_LINESCROLL16 %d\n", pos
);
4404 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4409 EDIT_EM_LineScroll(es
, 0, dy
);
4413 /*********************************************************************
4417 * FIXME: is this right ? (or should it be only VSCROLL)
4418 * (and maybe only for edit controls that really have their
4419 * own scrollbars) (and maybe only for multiline controls ?)
4420 * All in all: very poorly documented
4423 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4426 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4427 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4429 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
4430 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
4434 /********************************************************************
4436 * The Following code is to handle inline editing from IMEs
4439 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4442 LPWSTR lpCompStr
= NULL
;
4443 LPSTR lpCompStrAttr
= NULL
;
4446 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4453 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
4456 ERR("Unable to allocate IME CompositionString\n");
4461 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4462 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
4464 if (CompFlag
& GCS_COMPATTR
)
4467 * We do not use the attributes yet. it would tell us what characters
4468 * are in transition and which are converted or decided upon
4470 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4474 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4477 ERR("Unable to allocate IME Attribute String\n");
4478 HeapFree(GetProcessHeap(),0,lpCompStr
);
4481 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4483 lpCompStrAttr
[dwBufLenAttr
] = 0;
4486 lpCompStrAttr
= NULL
;
4489 /* check for change in composition start */
4490 if (es
->selection_end
< es
->composition_start
)
4491 es
->composition_start
= es
->selection_end
;
4493 /* replace existing selection string */
4494 es
->selection_start
= es
->composition_start
;
4496 if (es
->composition_len
> 0)
4497 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4499 es
->selection_end
= es
->selection_start
;
4501 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
4502 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4504 es
->selection_start
= es
->composition_start
;
4505 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4507 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4508 HeapFree(GetProcessHeap(),0,lpCompStr
);
4511 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4516 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4522 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
4525 ERR("Unable to alloc buffer for IME string\n");
4529 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4530 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
4532 /* check for change in composition start */
4533 if (es
->selection_end
< es
->composition_start
)
4534 es
->composition_start
= es
->selection_end
;
4536 es
->selection_start
= es
->composition_start
;
4537 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4538 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
4539 es
->composition_start
= es
->selection_end
;
4540 es
->composition_len
= 0;
4542 HeapFree(GetProcessHeap(),0,lpResultStr
);
4545 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4550 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4552 static const WCHAR empty_stringW
[] = {0};
4553 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4554 es
->composition_start
= es
->selection_end
;
4557 hIMC
= ImmGetContext(hwnd
);
4561 if (CompFlag
& GCS_RESULTSTR
)
4562 EDIT_GetResultStr(hIMC
, es
);
4563 if (CompFlag
& GCS_COMPSTR
)
4564 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4565 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4566 ImmReleaseContext(hwnd
, hIMC
);
4567 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4571 /*********************************************************************
4575 * See also EDIT_WM_StyleChanged
4577 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4582 TRACE("Creating %s edit control, style = %08x\n",
4583 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4585 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4587 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4590 * Note: since the EDITSTATE has not been fully initialized yet,
4591 * we can't use any API calls that may send
4592 * WM_XXX messages before WM_NCCREATE is completed.
4595 es
->is_unicode
= unicode
;
4596 es
->style
= lpcs
->style
;
4598 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4600 es
->hwndSelf
= hwnd
;
4601 /* Save parent, which will be notified by EN_* messages */
4602 es
->hwndParent
= lpcs
->hwndParent
;
4604 if (es
->style
& ES_COMBO
)
4605 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4607 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4608 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4610 /* Number overrides lowercase overrides uppercase (at least it
4611 * does in Win95). However I'll bet that ES_NUMBER would be
4612 * invalid under Win 3.1.
4614 if (es
->style
& ES_NUMBER
) {
4615 ; /* do not override the ES_NUMBER */
4616 } else if (es
->style
& ES_LOWERCASE
) {
4617 es
->style
&= ~ES_UPPERCASE
;
4619 if (es
->style
& ES_MULTILINE
) {
4620 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4621 if (es
->style
& WS_VSCROLL
)
4622 es
->style
|= ES_AUTOVSCROLL
;
4623 if (es
->style
& WS_HSCROLL
)
4624 es
->style
|= ES_AUTOHSCROLL
;
4625 es
->style
&= ~ES_PASSWORD
;
4626 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4627 /* Confirmed - RIGHT overrides CENTER */
4628 if (es
->style
& ES_RIGHT
)
4629 es
->style
&= ~ES_CENTER
;
4630 es
->style
&= ~WS_HSCROLL
;
4631 es
->style
&= ~ES_AUTOHSCROLL
;
4634 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4635 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4636 es
->style
&= ~ES_CENTER
;
4637 es
->style
&= ~WS_HSCROLL
;
4638 es
->style
&= ~WS_VSCROLL
;
4639 if (es
->style
& ES_PASSWORD
)
4640 es
->password_char
= '*';
4643 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4644 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4646 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4648 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4650 es
->undo_buffer_size
= es
->buffer_size
;
4652 if (es
->style
& ES_MULTILINE
)
4653 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4658 * In Win95 look and feel, the WS_BORDER style is replaced by the
4659 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4660 * control a nonclient area so we don't need to draw the border.
4661 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4662 * a nonclient area and we should handle painting the border ourselves.
4664 * When making modifications please ensure that the code still works
4665 * for edit controls created directly with style 0x50800000, exStyle 0
4666 * (which should have a single pixel border)
4668 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4669 es
->style
&= ~WS_BORDER
;
4670 else if (es
->style
& WS_BORDER
)
4671 SetWindowLongPtrW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4677 /*********************************************************************
4682 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4686 TRACE("%s\n", debugstr_w(name
));
4688 * To initialize some final structure members, we call some helper
4689 * functions. However, since the EDITSTATE is not consistent (i.e.
4690 * not fully initialized), we should be very careful which
4691 * functions can be called, and in what order.
4693 EDIT_WM_SetFont(es
, 0, FALSE
);
4694 EDIT_EM_EmptyUndoBuffer(es
);
4696 /* We need to calculate the format rect
4697 (applications may send EM_SETMARGINS before the control gets visible) */
4698 GetClientRect(es
->hwndSelf
, &clientRect
);
4699 EDIT_SetRectNP(es
, &clientRect
);
4701 if (name
&& *name
) {
4702 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4703 /* if we insert text to the editline, the text scrolls out
4704 * of the window, as the caret is placed after the insert
4705 * pos normally; thus we reset es->selection... to 0 and
4708 es
->selection_start
= es
->selection_end
= 0;
4709 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4710 * Messages are only to be sent when the USER does something to
4711 * change the contents. So I am removing this EN_CHANGE
4713 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4715 EDIT_EM_ScrollCaret(es
);
4717 /* force scroll info update */
4718 EDIT_UpdateScrollInfo(es
);
4719 /* The rule seems to return 1 here for success */
4720 /* Power Builder masked edit controls will crash */
4722 /* FIXME: is that in all cases so ? */
4727 /*********************************************************************
4732 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4737 LocalFree(es
->hloc32W
);
4740 LocalFree(es
->hloc32A
);
4744 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4745 HANDLE16 oldDS
= stack16
->ds
;
4747 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4748 while (LocalUnlock16(es
->hloc16
)) ;
4749 LocalFree16(es
->hloc16
);
4750 stack16
->ds
= oldDS
;
4754 pc
= es
->first_line_def
;
4758 HeapFree(GetProcessHeap(), 0, pc
);
4762 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4763 HeapFree(GetProcessHeap(), 0, es
);
4769 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4772 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4774 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4777 /*********************************************************************
4779 * EditWndProc_common
4781 * The messages are in the order of the actual integer values
4782 * (which can be found in include/windows.h)
4783 * Wherever possible the 16 bit versions are converted to
4784 * the 32 bit ones, so that we can 'fall through' to the
4785 * helper functions. These are mostly 32 bit (with a few
4786 * exceptions, clearly indicated by a '16' extension to their
4790 LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
4791 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4793 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4796 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4798 if (!es
&& msg
!= WM_NCCREATE
)
4799 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4801 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
4811 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4816 if ((short)LOWORD(lParam
) == -1)
4817 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4819 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
4821 EDIT_EM_ScrollCaret(es
);
4826 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4827 EDIT_EM_ScrollCaret(es
);
4835 RECT16
*r16
= MapSL(lParam
);
4836 r16
->left
= es
->format_rect
.left
;
4837 r16
->top
= es
->format_rect
.top
;
4838 r16
->right
= es
->format_rect
.right
;
4839 r16
->bottom
= es
->format_rect
.bottom
;
4845 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
4850 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4852 RECT16
*r16
= MapSL(lParam
);
4853 rc
.left
= r16
->left
;
4855 rc
.right
= r16
->right
;
4856 rc
.bottom
= r16
->bottom
;
4857 EDIT_SetRectNP(es
, &rc
);
4858 EDIT_UpdateText(es
, NULL
, TRUE
);
4863 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4864 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4865 EDIT_UpdateText(es
, NULL
, TRUE
);
4870 case EM_SETRECTNP16
:
4871 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4873 RECT16
*r16
= MapSL(lParam
);
4874 rc
.left
= r16
->left
;
4876 rc
.right
= r16
->right
;
4877 rc
.bottom
= r16
->bottom
;
4878 EDIT_SetRectNP(es
, &rc
);
4883 if ((es
->style
& ES_MULTILINE
) && lParam
)
4884 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4891 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4895 case EM_LINESCROLL16
:
4896 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
4897 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
4901 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4905 case EM_SCROLLCARET16
:
4907 case EM_SCROLLCARET
:
4908 EDIT_EM_ScrollCaret(es
);
4913 case EM_GETMODIFY16
:
4916 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4920 case EM_SETMODIFY16
:
4924 es
->flags
|= EF_MODIFIED
;
4926 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4930 case EM_GETLINECOUNT16
:
4932 case EM_GETLINECOUNT
:
4933 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4937 case EM_LINEINDEX16
:
4938 if ((INT16
)wParam
== -1)
4939 wParam
= (WPARAM
)-1;
4943 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4947 case EM_SETHANDLE16
:
4948 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
4952 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4956 case EM_GETHANDLE16
:
4957 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
4961 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4968 result
= EDIT_EM_GetThumb(es
);
4971 /* these messages missing from specs */
4980 FIXME("undocumented message 0x%x, please report\n", msg
);
4981 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4985 case EM_LINELENGTH16
:
4988 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4992 case EM_REPLACESEL16
:
4993 lParam
= (LPARAM
)MapSL(lParam
);
4994 unicode
= FALSE
; /* 16-bit message is always ascii */
5002 textW
= (LPWSTR
)lParam
;
5005 LPSTR textA
= (LPSTR
)lParam
;
5006 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5007 if(!(textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
)))) break;
5008 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5011 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
5015 HeapFree(GetProcessHeap(), 0, textW
);
5021 lParam
= (LPARAM
)MapSL(lParam
);
5022 unicode
= FALSE
; /* 16-bit message is always ascii */
5026 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5030 case EM_LIMITTEXT16
:
5032 case EM_SETLIMITTEXT
:
5033 EDIT_EM_SetLimitText(es
, wParam
);
5040 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
5048 result
= (LRESULT
)EDIT_EM_Undo(es
);
5055 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
5059 case EM_LINEFROMCHAR16
:
5061 case EM_LINEFROMCHAR
:
5062 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
5066 case EM_SETTABSTOPS16
:
5067 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
5070 case EM_SETTABSTOPS
:
5071 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
5075 case EM_SETPASSWORDCHAR16
:
5076 unicode
= FALSE
; /* 16-bit message is always ascii */
5079 case EM_SETPASSWORDCHAR
:
5084 charW
= (WCHAR
)wParam
;
5087 CHAR charA
= wParam
;
5088 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5091 EDIT_EM_SetPasswordChar(es
, charW
);
5096 case EM_EMPTYUNDOBUFFER16
:
5098 case EM_EMPTYUNDOBUFFER
:
5099 EDIT_EM_EmptyUndoBuffer(es
);
5103 case EM_GETFIRSTVISIBLELINE16
:
5104 result
= es
->y_offset
;
5107 case EM_GETFIRSTVISIBLELINE
:
5108 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
5112 case EM_SETREADONLY16
:
5114 case EM_SETREADONLY
:
5116 DWORD old_style
= es
->style
;
5119 SetWindowLongPtrW( hwnd
, GWL_STYLE
,
5120 GetWindowLongPtrW( hwnd
, GWL_STYLE
) | ES_READONLY
);
5121 es
->style
|= ES_READONLY
;
5123 SetWindowLongPtrW( hwnd
, GWL_STYLE
,
5124 GetWindowLongPtrW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
5125 es
->style
&= ~ES_READONLY
;
5128 if (old_style
^ es
->style
)
5129 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
5136 case EM_SETWORDBREAKPROC16
:
5137 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
5140 case EM_SETWORDBREAKPROC
:
5141 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
5145 case EM_GETWORDBREAKPROC16
:
5146 result
= (LRESULT
)es
->word_break_proc16
;
5149 case EM_GETWORDBREAKPROC
:
5150 result
= (LRESULT
)es
->word_break_proc
;
5154 case EM_GETPASSWORDCHAR16
:
5155 unicode
= FALSE
; /* 16-bit message is always ascii */
5158 case EM_GETPASSWORDCHAR
:
5161 result
= es
->password_char
;
5164 WCHAR charW
= es
->password_char
;
5166 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
5172 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
5175 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
5179 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
5182 case EM_GETLIMITTEXT
:
5183 result
= es
->buffer_limit
;
5186 case EM_POSFROMCHAR
:
5187 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
5188 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
5191 case EM_CHARFROMPOS
:
5192 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5195 /* End of the EM_ messages which were in numerical order; what order
5196 * are these in? vaguely alphabetical?
5200 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
5204 result
= EDIT_WM_Destroy(es
);
5209 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
5211 if (es
->style
& ES_MULTILINE
)
5212 result
|= DLGC_WANTALLKEYS
;
5216 es
->flags
|=EF_DIALOGMODE
;
5218 if (((LPMSG
)lParam
)->message
== WM_KEYDOWN
)
5220 int vk
= (int)((LPMSG
)lParam
)->wParam
;
5222 if (es
->hwndListBox
)
5224 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
5225 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5226 result
|= DLGC_WANTMESSAGE
;
5238 strng
[0] = wParam
>> 8;
5239 strng
[1] = wParam
& 0xff;
5240 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
5241 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
5242 result
= EDIT_WM_Char(es
, charW
);
5254 CHAR charA
= wParam
;
5255 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5258 if (es
->hwndListBox
)
5260 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
5262 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5263 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
5267 result
= EDIT_WM_Char(es
, charW
);
5274 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
5275 if (wParam
<= 0x000fffff)
5277 if(wParam
> 0xffff) /* convert to surrogates */
5280 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
5281 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
5283 else EDIT_WM_Char(es
, wParam
);
5293 case WM_CONTEXTMENU
:
5294 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5303 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
5306 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
5307 LPWSTR nameW
= NULL
;
5310 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
5311 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5312 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
5314 result
= EDIT_WM_Create(es
, nameW
);
5315 HeapFree(GetProcessHeap(), 0, nameW
);
5324 es
->bEnableState
= (BOOL
) wParam
;
5325 EDIT_UpdateText(es
, NULL
, TRUE
);
5329 /* we do the proper erase in EDIT_WM_Paint */
5334 result
= (LRESULT
)es
->font
;
5338 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5341 case WM_GETTEXTLENGTH
:
5342 if (unicode
) result
= get_text_length(es
);
5343 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
5344 NULL
, 0, NULL
, NULL
);
5348 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5352 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
5356 result
= EDIT_WM_KillFocus(es
);
5359 case WM_LBUTTONDBLCLK
:
5360 result
= EDIT_WM_LButtonDblClk(es
);
5363 case WM_LBUTTONDOWN
:
5364 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5368 result
= EDIT_WM_LButtonUp(es
);
5371 case WM_MBUTTONDOWN
:
5372 result
= EDIT_WM_MButtonDown(es
);
5376 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5379 case WM_PRINTCLIENT
:
5381 EDIT_WM_Paint(es
, (HDC
)wParam
);
5389 EDIT_WM_SetFocus(es
);
5393 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
5397 /* FIXME: actually set an internal flag and behave accordingly */
5401 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
5406 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
5409 case WM_STYLECHANGED
:
5410 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
5413 case WM_STYLECHANGING
:
5414 result
= 0; /* See EDIT_WM_StyleChanged */
5418 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5426 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5431 int gcWheelDelta
= 0;
5432 UINT pulScrollLines
= 3;
5433 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5435 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
5436 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5439 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
5440 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
5442 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
5443 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
5444 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
5450 /* IME messages to make the edit control IME aware */
5451 case WM_IME_SETCONTEXT
:
5454 case WM_IME_STARTCOMPOSITION
:
5455 es
->composition_start
= es
->selection_end
;
5456 es
->composition_len
= 0;
5459 case WM_IME_COMPOSITION
:
5460 EDIT_ImeComposition(hwnd
, lParam
, es
);
5463 case WM_IME_ENDCOMPOSITION
:
5464 if (es
->composition_len
> 0)
5466 static const WCHAR empty_stringW
[] = {0};
5467 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5468 es
->selection_end
= es
->selection_start
;
5469 es
->composition_len
= 0;
5473 case WM_IME_COMPOSITIONFULL
:
5479 case WM_IME_CONTROL
:
5483 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5487 if (IsWindow(hwnd
) && es
) EDIT_UnlockBuffer(es
, FALSE
);
5489 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5494 /*********************************************************************
5496 * EditWndProc (USER32.@)
5498 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5500 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
5503 /*********************************************************************
5505 * EditWndProcW (USER32.@)
5507 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5509 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
5512 /*********************************************************************
5513 * edit class descriptor
5515 static const WCHAR editW
[] = {'E','d','i','t',0};
5516 const struct builtin_class_descr EDIT_builtin_class
=
5519 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5520 EditWndProcA
, /* procA */
5521 EditWndProcW
, /* procW */
5523 sizeof(EDITSTATE
*), /* extra */
5525 sizeof(EDITSTATE
*) + sizeof(WORD
), /* extra */
5527 IDC_IBEAM
, /* cursor */