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. */
73 END_0
= 0, /* line ends with terminating '\0' character */
74 END_WRAP
, /* line is wrapped */
75 END_HARD
, /* line ends with a hard return '\r\n' */
76 END_SOFT
, /* line ends with a soft return '\r\r\n' */
77 END_RICH
/* line ends with a single '\n' */
80 typedef struct tagLINEDEF
{
81 INT length
; /* bruto length of a line in bytes */
82 INT net_length
; /* netto length of a line in visible characters */
84 INT width
; /* width of the line in pixels */
85 INT index
; /* line index into the buffer */
86 struct tagLINEDEF
*next
;
91 BOOL is_unicode
; /* how the control was created */
92 LPWSTR text
; /* the actual contents of the control */
93 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
94 UINT buffer_size
; /* the size of the buffer in characters */
95 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
96 HFONT font
; /* NULL means standard system font */
97 INT x_offset
; /* scroll offset for multi lines this is in pixels
98 for single lines it's in characters */
99 INT line_height
; /* height of a screen line in pixels */
100 INT char_width
; /* average character width in pixels */
101 DWORD style
; /* sane version of wnd->dwStyle */
102 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
103 INT undo_insert_count
; /* number of characters inserted in sequence */
104 UINT undo_position
; /* character index of the insertion and deletion */
105 LPWSTR undo_text
; /* deleted text */
106 UINT undo_buffer_size
; /* size of the deleted text buffer */
107 INT selection_start
; /* == selection_end if no selection */
108 INT selection_end
; /* == current caret position */
109 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
110 INT left_margin
; /* in pixels */
111 INT right_margin
; /* in pixels */
113 INT text_width
; /* width of the widest line in pixels for multi line controls
114 and just line width for single line controls */
115 INT region_posx
; /* Position of cursor relative to region: */
116 INT region_posy
; /* -1: to left, 0: within, 1: to right */
118 EDITWORDBREAKPROC16 word_break_proc16
;
120 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
121 INT line_count
; /* number of lines */
122 INT y_offset
; /* scroll offset in number of lines */
123 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
124 BOOL bEnableState
; /* flag keeping the enable state */
125 HWND hwndSelf
; /* the our window handle */
126 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
127 Even if parent will change, EN_* messages
128 should be sent to the first parent. */
129 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
131 * only for multi line controls
133 INT lock_count
; /* amount of re-entries in the EditWndProc */
136 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
137 HLOCAL hloc32W
; /* our unicode local memory block */
139 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
142 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
147 UINT composition_len
; /* length of composition, 0 == no composition */
148 int composition_start
; /* the character position for the composition */
152 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
153 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
155 /* used for disabled or read-only edit control */
156 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
158 { /* Notify parent which has created this edit control */ \
159 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
160 SendMessageW(es->hwndParent, WM_COMMAND, \
161 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
162 (LPARAM)(es->hwndSelf)); \
165 /*********************************************************************
170 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
172 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
176 /*********************************************************************
181 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
183 es
->undo_insert_count
= 0;
184 *es
->undo_text
= '\0';
188 /**********************************************************************
191 * Returns the window version in case Wine emulates a later version
192 * of windows than the application expects.
194 * In a number of cases when windows runs an application that was
195 * designed for an earlier windows version, windows reverts
196 * to "old" behaviour of that earlier version.
198 * An example is a disabled edit control that needs to be painted.
199 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
200 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
201 * applications with an expected version 0f 4.0 or higher.
204 static DWORD
get_app_version(void)
206 static DWORD version
;
209 DWORD dwEmulatedVersion
;
211 DWORD dwProcVersion
= GetProcessVersion(0);
213 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
214 GetVersionExW( &info
);
215 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
216 /* FIXME: this may not be 100% correct; see discussion on the
217 * wine developer list in Nov 1999 */
218 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
223 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
228 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
229 msg
= WM_CTLCOLORSTATIC
;
231 msg
= WM_CTLCOLOREDIT
;
233 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
234 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
236 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
241 /*********************************************************************
245 * Find the beginning of words.
246 * Note: unlike the specs for a WordBreakProc, this function only
247 * allows to be called without linebreaks between s[0] up to
248 * s[count - 1]. Remember it is only called
249 * internally, so we can decide this for ourselves.
252 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
256 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
266 if (s
[index
] == ' ') {
267 while (index
&& (s
[index
] == ' '))
270 while (index
&& (s
[index
] != ' '))
276 while (index
&& (s
[index
] != ' '))
289 while ((index
< count
) && (s
[index
] == ' ')) index
++;
291 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
293 while ((s
[index
] == ' ') && (index
< count
)) index
++;
298 ret
= (s
[index
] == ' ');
301 ERR("unknown action code, please report !\n");
308 /*********************************************************************
310 * EDIT_CallWordBreakProc
312 * Call appropriate WordBreakProc (internal or external).
314 * Note: The "start" argument should always be an index referring
315 * to es->text. The actual wordbreak proc might be
316 * 16 bit, so we can't always pass any 32 bit LPSTR.
317 * Hence we assume that es->text is the buffer that holds
318 * the string under examination (we can decide this for ourselves).
321 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
326 if (es
->word_break_proc16
) {
333 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
334 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
335 segptr
= WOWGlobalLock16(hglob16
);
336 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
337 args
[4] = SELECTOROF(segptr
);
338 args
[3] = OFFSETOF(segptr
);
342 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
343 ret
= LOWORD(result
);
344 GlobalUnlock16(hglob16
);
345 GlobalFree16(hglob16
);
347 else if (es
->word_break_proc
)
349 if (es
->word_break_proc
)
354 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
356 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
357 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
358 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
362 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
366 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
367 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
370 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
371 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
372 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
373 ret
= wbpA(textA
, index
, countA
, action
);
374 HeapFree(GetProcessHeap(), 0, textA
);
378 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
383 /*********************************************************************
385 * EDIT_BuildLineDefs_ML
387 * Build linked list of text lines.
388 * Lines can end with '\0' (last line), a character (if it is wrapped),
389 * a soft return '\r\r\n' or a hard return '\r\n'
392 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
396 LPWSTR current_position
, cp
;
398 LINEDEF
*current_line
;
399 LINEDEF
*previous_line
;
401 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
402 INT line_count
= es
->line_count
;
406 if (istart
== iend
&& delta
== 0)
409 dc
= GetDC(es
->hwndSelf
);
411 old_font
= SelectObject(dc
, es
->font
);
413 previous_line
= NULL
;
414 current_line
= es
->first_line_def
;
416 /* Find starting line. istart must lie inside an existing line or
417 * at the end of buffer */
419 if (istart
< current_line
->index
+ current_line
->length
||
420 current_line
->ending
== END_0
)
423 previous_line
= current_line
;
424 current_line
= current_line
->next
;
426 } while (current_line
);
428 if (!current_line
) /* Error occurred start is not inside previous buffer */
430 FIXME(" modification occurred outside buffer\n");
431 ReleaseDC(es
->hwndSelf
, dc
);
435 /* Remember start of modifications in order to calculate update region */
436 nstart_line
= line_index
;
437 nstart_index
= current_line
->index
;
439 /* We must start to reformat from the previous line since the modifications
440 * may have caused the line to wrap upwards. */
441 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
444 current_line
= previous_line
;
446 start_line
= current_line
;
448 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
449 current_position
= es
->text
+ current_line
->index
;
451 if (current_line
!= start_line
)
453 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
455 /* The buffer has been expanded, create a new line and
456 insert it into the link list */
457 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
458 if (new_line
== NULL
)
460 new_line
->next
= previous_line
->next
;
461 previous_line
->next
= new_line
;
462 current_line
= new_line
;
465 else if (current_line
->index
+ delta
< current_position
- es
->text
)
467 /* The previous line merged with this line so we delete this extra entry */
468 previous_line
->next
= current_line
->next
;
469 HeapFree(GetProcessHeap(), 0, current_line
);
470 current_line
= previous_line
->next
;
474 else /* current_line->index + delta == current_position */
476 if (current_position
- es
->text
> iend
)
477 break; /* We reached end of line modifications */
478 /* else recalculate this line */
482 current_line
->index
= current_position
- es
->text
;
483 orig_net_length
= current_line
->net_length
;
485 /* Find end of line */
486 cp
= current_position
;
488 if (*cp
== '\n') break;
489 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
494 /* Mark type of line termination */
496 current_line
->ending
= END_0
;
497 current_line
->net_length
= strlenW(current_position
);
498 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
499 current_line
->ending
= END_SOFT
;
500 current_line
->net_length
= cp
- current_position
- 1;
501 } else if (*cp
== '\n') {
502 current_line
->ending
= END_RICH
;
503 current_line
->net_length
= cp
- current_position
;
505 current_line
->ending
= END_HARD
;
506 current_line
->net_length
= cp
- current_position
;
509 /* Calculate line width */
510 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
511 current_position
, current_line
->net_length
,
512 es
->tabs_count
, es
->tabs
));
514 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
515 if (!(es
->style
& ES_AUTOHSCROLL
)) {
516 if (current_line
->width
> fw
) {
521 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
522 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
523 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
524 current_position
, next
, es
->tabs_count
, es
->tabs
));
525 } while (current_line
->width
<= fw
);
526 if (!prev
) { /* Didn't find a line break so force a break */
531 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
532 current_position
, next
, es
->tabs_count
, es
->tabs
));
533 } while (current_line
->width
<= fw
);
538 /* If the first line we are calculating, wrapped before istart, we must
539 * adjust istart in order for this to be reflected in the update region. */
540 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
541 istart
= current_line
->index
+ prev
;
542 /* else if we are updating the previous line before the first line we
543 * are re-calculating and it expanded */
544 else if (current_line
== start_line
&&
545 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
547 /* Line expanded due to an upwards line wrap so we must partially include
548 * previous line in update region */
549 nstart_line
= line_index
;
550 nstart_index
= current_line
->index
;
551 istart
= current_line
->index
+ orig_net_length
;
554 current_line
->net_length
= prev
;
555 current_line
->ending
= END_WRAP
;
556 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
557 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
559 else if (current_line
== start_line
&&
560 current_line
->index
!= nstart_index
&&
561 orig_net_length
< current_line
->net_length
) {
562 /* The previous line expanded but it's still not as wide as the client rect */
563 /* The expansion is due to an upwards line wrap so we must partially include
564 it in the update region */
565 nstart_line
= line_index
;
566 nstart_index
= current_line
->index
;
567 istart
= current_line
->index
+ orig_net_length
;
572 /* Adjust length to include line termination */
573 switch (current_line
->ending
) {
575 current_line
->length
= current_line
->net_length
+ 3;
578 current_line
->length
= current_line
->net_length
+ 1;
581 current_line
->length
= current_line
->net_length
+ 2;
585 current_line
->length
= current_line
->net_length
;
588 es
->text_width
= max(es
->text_width
, current_line
->width
);
589 current_position
+= current_line
->length
;
590 previous_line
= current_line
;
591 current_line
= current_line
->next
;
593 } while (previous_line
->ending
!= END_0
);
595 /* Finish adjusting line indexes by delta or remove hanging lines */
596 if (previous_line
->ending
== END_0
)
598 LINEDEF
*pnext
= NULL
;
600 previous_line
->next
= NULL
;
603 pnext
= current_line
->next
;
604 HeapFree(GetProcessHeap(), 0, current_line
);
605 current_line
= pnext
;
613 current_line
->index
+= delta
;
614 current_line
= current_line
->next
;
618 /* Calculate rest of modification rectangle */
623 * We calculate two rectangles. One for the first line which may have
624 * an indent with respect to the format rect. The other is a format-width
625 * rectangle that spans the rest of the lines that changed or moved.
627 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
628 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
629 rc
.bottom
= rc
.top
+ es
->line_height
;
630 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
631 rc
.left
= es
->format_rect
.left
;
633 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
634 es
->text
+ nstart_index
, istart
- nstart_index
,
635 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
636 rc
.right
= es
->format_rect
.right
;
637 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
640 rc
.left
= es
->format_rect
.left
;
641 rc
.right
= es
->format_rect
.right
;
643 * If lines were added or removed we must re-paint the remainder of the
644 * lines since the remaining lines were either shifted up or down.
646 if (line_count
< es
->line_count
) /* We added lines */
647 rc
.bottom
= es
->line_count
* es
->line_height
;
648 else if (line_count
> es
->line_count
) /* We removed lines */
649 rc
.bottom
= line_count
* es
->line_height
;
651 rc
.bottom
= line_index
* es
->line_height
;
652 rc
.bottom
+= es
->format_rect
.top
;
653 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
654 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
655 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
656 DeleteObject(tmphrgn
);
660 SelectObject(dc
, old_font
);
662 ReleaseDC(es
->hwndSelf
, dc
);
666 static inline UINT
get_text_length(EDITSTATE
*es
)
668 if(es
->text_length
== (UINT
)-1)
669 es
->text_length
= strlenW(es
->text
);
670 return es
->text_length
;
673 /*********************************************************************
675 * EDIT_GetPasswordPointer_SL
677 * note: caller should free the (optionally) allocated buffer
680 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
682 if (es
->style
& ES_PASSWORD
) {
683 INT len
= get_text_length(es
);
684 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
688 while(len
) text
[--len
] = es
->password_char
;
695 /*********************************************************************
697 * EDIT_CalcLineWidth_SL
700 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
707 text
= EDIT_GetPasswordPointer_SL(es
);
709 dc
= GetDC(es
->hwndSelf
);
711 old_font
= SelectObject(dc
, es
->font
);
713 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
716 SelectObject(dc
, old_font
);
717 ReleaseDC(es
->hwndSelf
, dc
);
719 if (es
->style
& ES_PASSWORD
)
720 HeapFree(GetProcessHeap(), 0, text
);
722 es
->text_width
= size
.cx
;
725 /*********************************************************************
729 * Beware: This is not the function called on EM_CHARFROMPOS
730 * The position _can_ be outside the formatting / client
732 * The return value is only the character index
735 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
740 INT x_high
= 0, x_low
= 0;
742 if (es
->style
& ES_MULTILINE
) {
743 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
745 LINEDEF
*line_def
= es
->first_line_def
;
747 while ((line
> 0) && line_def
->next
) {
748 line_index
+= line_def
->length
;
749 line_def
= line_def
->next
;
752 x
+= es
->x_offset
- es
->format_rect
.left
;
753 if (es
->style
& ES_RIGHT
)
754 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
755 else if (es
->style
& ES_CENTER
)
756 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
757 if (x
>= line_def
->width
) {
759 *after_wrap
= (line_def
->ending
== END_WRAP
);
760 return line_index
+ line_def
->net_length
;
767 dc
= GetDC(es
->hwndSelf
);
769 old_font
= SelectObject(dc
, es
->font
);
771 high
= line_index
+ line_def
->net_length
+ 1;
772 while (low
< high
- 1)
774 INT mid
= (low
+ high
) / 2;
775 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
784 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
790 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
791 (line_def
->ending
== END_WRAP
));
797 x
-= es
->format_rect
.left
;
803 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
804 if (es
->style
& ES_RIGHT
)
806 else if (es
->style
& ES_CENTER
)
810 text
= EDIT_GetPasswordPointer_SL(es
);
811 dc
= GetDC(es
->hwndSelf
);
813 old_font
= SelectObject(dc
, es
->font
);
817 INT high
= es
->x_offset
;
818 while (low
< high
- 1)
820 INT mid
= (low
+ high
) / 2;
821 GetTextExtentPoint32W( dc
, text
+ mid
,
822 es
->x_offset
- mid
, &size
);
831 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
838 INT low
= es
->x_offset
;
839 INT high
= get_text_length(es
) + 1;
840 while (low
< high
- 1)
842 INT mid
= (low
+ high
) / 2;
843 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
844 mid
- es
->x_offset
, &size
);
853 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
858 if (es
->style
& ES_PASSWORD
)
859 HeapFree(GetProcessHeap(), 0, text
);
862 SelectObject(dc
, old_font
);
863 ReleaseDC(es
->hwndSelf
, dc
);
868 /*********************************************************************
872 * adjusts the point to be within the formatting rectangle
873 * (so CharFromPos returns the nearest _visible_ character)
876 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
878 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
879 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
883 /*********************************************************************
888 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
893 if (!(es
->style
& ES_MULTILINE
))
895 if (index
> (INT
)get_text_length(es
))
896 return es
->line_count
- 1;
898 index
= min(es
->selection_start
, es
->selection_end
);
901 line_def
= es
->first_line_def
;
902 index
-= line_def
->length
;
903 while ((index
>= 0) && line_def
->next
) {
905 line_def
= line_def
->next
;
906 index
-= line_def
->length
;
912 /*********************************************************************
917 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
920 const LINEDEF
*line_def
;
922 if (!(es
->style
& ES_MULTILINE
))
924 if (line
>= es
->line_count
)
928 line_def
= es
->first_line_def
;
930 INT index
= es
->selection_end
- line_def
->length
;
931 while ((index
>= 0) && line_def
->next
) {
932 line_index
+= line_def
->length
;
933 line_def
= line_def
->next
;
934 index
-= line_def
->length
;
938 line_index
+= line_def
->length
;
939 line_def
= line_def
->next
;
947 /*********************************************************************
952 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
956 if (!(es
->style
& ES_MULTILINE
))
957 return get_text_length(es
);
960 /* get the number of remaining non-selected chars of selected lines */
961 INT32 l
; /* line number */
962 INT32 li
; /* index of first char in line */
964 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
965 /* # chars before start of selection area */
966 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
967 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
968 /* # chars after end of selection */
969 li
= EDIT_EM_LineIndex(es
, l
);
970 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
973 line_def
= es
->first_line_def
;
974 index
-= line_def
->length
;
975 while ((index
>= 0) && line_def
->next
) {
976 line_def
= line_def
->next
;
977 index
-= line_def
->length
;
979 return line_def
->net_length
;
983 /*********************************************************************
988 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
990 INT len
= get_text_length(es
);
1003 index
= min(index
, len
);
1004 dc
= GetDC(es
->hwndSelf
);
1006 old_font
= SelectObject(dc
, es
->font
);
1007 if (es
->style
& ES_MULTILINE
) {
1008 l
= EDIT_EM_LineFromChar(es
, index
);
1009 y
= (l
- es
->y_offset
) * es
->line_height
;
1010 li
= EDIT_EM_LineIndex(es
, l
);
1011 if (after_wrap
&& (li
== index
) && l
) {
1013 line_def
= es
->first_line_def
;
1015 line_def
= line_def
->next
;
1018 if (line_def
->ending
== END_WRAP
) {
1020 y
-= es
->line_height
;
1021 li
= EDIT_EM_LineIndex(es
, l
);
1025 line_def
= es
->first_line_def
;
1026 while (line_def
->index
!= li
)
1027 line_def
= line_def
->next
;
1029 ll
= line_def
->net_length
;
1030 lw
= line_def
->width
;
1032 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1033 if (es
->style
& ES_RIGHT
)
1035 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
1036 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1039 else if (es
->style
& ES_CENTER
)
1041 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1042 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1047 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1048 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1051 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
1052 if (index
< es
->x_offset
) {
1053 GetTextExtentPoint32W(dc
, text
+ index
,
1054 es
->x_offset
- index
, &size
);
1057 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
1058 index
- es
->x_offset
, &size
);
1061 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1063 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1064 if (w
> es
->text_width
)
1066 if (es
->style
& ES_RIGHT
)
1067 x
+= w
- es
->text_width
;
1068 else if (es
->style
& ES_CENTER
)
1069 x
+= (w
- es
->text_width
) / 2;
1074 if (es
->style
& ES_PASSWORD
)
1075 HeapFree(GetProcessHeap(), 0, text
);
1077 x
+= es
->format_rect
.left
;
1078 y
+= es
->format_rect
.top
;
1080 SelectObject(dc
, old_font
);
1081 ReleaseDC(es
->hwndSelf
, dc
);
1082 return MAKELONG((INT16
)x
, (INT16
)y
);
1086 /*********************************************************************
1090 * Calculates the bounding rectangle for a line from a starting
1091 * column to an ending column.
1094 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1096 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1098 if (es
->style
& ES_MULTILINE
)
1099 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1101 rc
->top
= es
->format_rect
.top
;
1102 rc
->bottom
= rc
->top
+ es
->line_height
;
1103 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1104 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1108 static inline void text_buffer_changed(EDITSTATE
*es
)
1110 es
->text_length
= (UINT
)-1;
1113 /*********************************************************************
1117 * This acts as a LocalLock16(), but it locks only once. This way
1118 * you can call it whenever you like, without unlocking.
1120 * Initially the edit control allocates a HLOCAL32 buffer
1121 * (32 bit linear memory handler). However, 16 bit application
1122 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1123 * handler). From that moment on we have to keep using this 16 bit memory
1124 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1125 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1129 static void EDIT_LockBuffer(EDITSTATE
*es
)
1132 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1133 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1139 BOOL _16bit
= FALSE
;
1146 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1147 textA
= LocalLock(es
->hloc32A
);
1148 countA
= strlen(textA
) + 1;
1153 HANDLE16 oldDS
= stack16
->ds
;
1154 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1155 stack16
->ds
= hInstance
;
1156 textA
= MapSL(LocalLock16(es
->hloc16
));
1157 stack16
->ds
= oldDS
;
1158 countA
= strlen(textA
) + 1;
1164 ERR("no buffer ... please report\n");
1171 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1172 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1173 if(countW_new
> es
->buffer_size
+ 1)
1175 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1176 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1177 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1180 es
->hloc32W
= hloc32W_new
;
1181 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1182 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1185 WARN("FAILED! Will synchronize partially\n");
1189 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1190 es
->text
= LocalLock(es
->hloc32W
);
1194 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1198 HANDLE16 oldDS
= stack16
->ds
;
1199 stack16
->ds
= hInstance
;
1200 LocalUnlock16(es
->hloc16
);
1201 stack16
->ds
= oldDS
;
1205 LocalUnlock(es
->hloc32A
);
1208 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1213 /*********************************************************************
1218 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1221 /* Edit window might be already destroyed */
1222 if(!IsWindow(es
->hwndSelf
))
1224 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1228 if (!es
->lock_count
) {
1229 ERR("lock_count == 0 ... please report\n");
1233 ERR("es->text == 0 ... please report\n");
1237 if (force
|| (es
->lock_count
== 1)) {
1241 UINT countW
= get_text_length(es
) + 1;
1243 STACK16FRAME
* stack16
= NULL
;
1249 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1250 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1251 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1252 countA
= LocalSize(es
->hloc32A
);
1253 if(countA_new
> countA
)
1256 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1257 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1258 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1261 es
->hloc32A
= hloc32A_new
;
1262 countA
= LocalSize(hloc32A_new
);
1263 TRACE("Real new size %d bytes\n", countA
);
1266 WARN("FAILED! Will synchronize partially\n");
1268 textA
= LocalLock(es
->hloc32A
);
1273 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1275 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1276 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1278 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1279 oldDS
= stack16
->ds
;
1280 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1282 countA
= LocalSize16(es
->hloc16
);
1283 if(countA_new
> countA
)
1285 HLOCAL16 hloc16_new
;
1286 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1287 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1288 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1291 es
->hloc16
= hloc16_new
;
1292 countA
= LocalSize16(hloc16_new
);
1293 TRACE("Real new size %d bytes\n", countA
);
1296 WARN("FAILED! Will synchronize partially\n");
1298 textA
= MapSL(LocalLock16(es
->hloc16
));
1304 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
1307 LocalUnlock16(es
->hloc16
);
1310 LocalUnlock(es
->hloc32A
);
1314 if (stack16
) stack16
->ds
= oldDS
;
1316 LocalUnlock(es
->hloc32W
);
1320 ERR("no buffer ... please report\n");
1328 /*********************************************************************
1332 * Try to fit size + 1 characters in the buffer.
1334 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1338 if (size
<= es
->buffer_size
)
1341 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1343 /* Force edit to unlock it's buffer. es->text now NULL */
1344 EDIT_UnlockBuffer(es
, TRUE
);
1347 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1348 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1349 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1350 es
->hloc32W
= hNew32W
;
1351 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1355 EDIT_LockBuffer(es
);
1357 if (es
->buffer_size
< size
) {
1358 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1359 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1362 TRACE("We now have %d+1\n", es
->buffer_size
);
1368 /*********************************************************************
1372 * Try to fit size + 1 bytes in the undo buffer.
1375 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1379 if (size
<= es
->undo_buffer_size
)
1382 TRACE("trying to ReAlloc to %d+1\n", size
);
1384 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1385 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1386 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1391 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1397 /*********************************************************************
1399 * EDIT_UpdateTextRegion
1402 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1404 if (es
->flags
& EF_UPDATE
) {
1405 es
->flags
&= ~EF_UPDATE
;
1406 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1408 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1412 /*********************************************************************
1417 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1419 if (es
->flags
& EF_UPDATE
) {
1420 es
->flags
&= ~EF_UPDATE
;
1421 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1423 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1426 /*********************************************************************
1428 * EDIT_SL_InvalidateText
1430 * Called from EDIT_InvalidateText().
1431 * Does the job for single-line controls only.
1434 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1439 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1440 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1441 EDIT_UpdateText(es
, &rc
, TRUE
);
1445 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
1447 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1451 /*********************************************************************
1453 * EDIT_ML_InvalidateText
1455 * Called from EDIT_InvalidateText().
1456 * Does the job for multi-line controls only.
1459 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1461 INT vlc
= get_vertical_line_count(es
);
1462 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1463 INT el
= EDIT_EM_LineFromChar(es
, end
);
1472 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1475 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1476 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1477 if (sl
< es
->y_offset
) {
1481 if (el
> es
->y_offset
+ vlc
) {
1482 el
= es
->y_offset
+ vlc
;
1483 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1485 GetClientRect(es
->hwndSelf
, &rc1
);
1486 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1488 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1489 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1490 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1492 EDIT_GetLineRect(es
, sl
, sc
,
1493 EDIT_EM_LineLength(es
,
1494 EDIT_EM_LineIndex(es
, sl
)),
1496 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1497 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1498 for (l
= sl
+ 1 ; l
< el
; l
++) {
1499 EDIT_GetLineRect(es
, l
, 0,
1500 EDIT_EM_LineLength(es
,
1501 EDIT_EM_LineIndex(es
, l
)),
1503 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1504 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1506 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1507 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1508 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1513 /*********************************************************************
1515 * EDIT_InvalidateText
1517 * Invalidate the text from offset start up to, but not including,
1518 * offset end. Useful for (re)painting the selection.
1519 * Regions outside the linewidth are not invalidated.
1520 * end == -1 means end == TextLength.
1521 * start and end need not be ordered.
1524 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1530 end
= get_text_length(es
);
1538 if (es
->style
& ES_MULTILINE
)
1539 EDIT_ML_InvalidateText(es
, start
, end
);
1541 EDIT_SL_InvalidateText(es
, start
, end
);
1545 /*********************************************************************
1549 * note: unlike the specs say: the order of start and end
1550 * _is_ preserved in Windows. (i.e. start can be > end)
1551 * In other words: this handler is OK
1554 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1556 UINT old_start
= es
->selection_start
;
1557 UINT old_end
= es
->selection_end
;
1558 UINT len
= get_text_length(es
);
1560 if (start
== (UINT
)-1) {
1561 start
= es
->selection_end
;
1562 end
= es
->selection_end
;
1564 start
= min(start
, len
);
1565 end
= min(end
, len
);
1567 es
->selection_start
= start
;
1568 es
->selection_end
= end
;
1570 es
->flags
|= EF_AFTER_WRAP
;
1572 es
->flags
&= ~EF_AFTER_WRAP
;
1573 /* Compute the necessary invalidation region. */
1574 /* Note that we don't need to invalidate regions which have
1575 * "never" been selected, or those which are "still" selected.
1576 * In fact, every time we hit a selection boundary, we can
1577 * *toggle* whether we need to invalidate. Thus we can optimize by
1578 * *sorting* the interval endpoints. Let's assume that we sort them
1580 * start <= end <= old_start <= old_end
1581 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1582 * in 5 comparisons; i.e. it is impossible to do better than the
1584 ORDER_UINT(end
, old_end
);
1585 ORDER_UINT(start
, old_start
);
1586 ORDER_UINT(old_start
, old_end
);
1587 ORDER_UINT(start
, end
);
1588 /* Note that at this point 'end' and 'old_start' are not in order, but
1589 * start is definitely the min. and old_end is definitely the max. */
1590 if (end
!= old_start
)
1594 * ORDER_UINT32(end, old_start);
1595 * EDIT_InvalidateText(es, start, end);
1596 * EDIT_InvalidateText(es, old_start, old_end);
1597 * in place of the following if statement.
1598 * (That would complete the optimal five-comparison four-element sort.)
1600 if (old_start
> end
)
1602 EDIT_InvalidateText(es
, start
, end
);
1603 EDIT_InvalidateText(es
, old_start
, old_end
);
1607 EDIT_InvalidateText(es
, start
, old_start
);
1608 EDIT_InvalidateText(es
, end
, old_end
);
1611 else EDIT_InvalidateText(es
, start
, old_end
);
1615 /*********************************************************************
1617 * EDIT_UpdateScrollInfo
1620 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1622 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1625 si
.cbSize
= sizeof(SCROLLINFO
);
1626 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1628 si
.nMax
= es
->line_count
- 1;
1629 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1630 si
.nPos
= es
->y_offset
;
1631 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1632 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1633 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1636 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1639 si
.cbSize
= sizeof(SCROLLINFO
);
1640 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1642 si
.nMax
= es
->text_width
- 1;
1643 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1644 si
.nPos
= es
->x_offset
;
1645 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1646 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1647 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1652 /*********************************************************************
1654 * EDIT_EM_LineScroll_internal
1656 * Version of EDIT_EM_LineScroll for internal use.
1657 * It doesn't refuse if ES_MULTILINE is set and assumes that
1658 * dx is in pixels, dy - in lines.
1661 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1664 INT x_offset_in_pixels
;
1665 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1668 if (es
->style
& ES_MULTILINE
)
1670 x_offset_in_pixels
= es
->x_offset
;
1675 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1678 if (-dx
> x_offset_in_pixels
)
1679 dx
= -x_offset_in_pixels
;
1680 if (dx
> es
->text_width
- x_offset_in_pixels
)
1681 dx
= es
->text_width
- x_offset_in_pixels
;
1682 nyoff
= max(0, es
->y_offset
+ dy
);
1683 if (nyoff
>= es
->line_count
- lines_per_page
)
1684 nyoff
= max(0, es
->line_count
- lines_per_page
);
1685 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1690 es
->y_offset
= nyoff
;
1691 if(es
->style
& ES_MULTILINE
)
1694 es
->x_offset
+= dx
/ es
->char_width
;
1696 GetClientRect(es
->hwndSelf
, &rc1
);
1697 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1698 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1699 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1700 /* force scroll info update */
1701 EDIT_UpdateScrollInfo(es
);
1703 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1704 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1705 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1706 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1710 /*********************************************************************
1714 * NOTE: dx is in average character widths, dy - in lines;
1717 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1719 if (!(es
->style
& ES_MULTILINE
))
1722 dx
*= es
->char_width
;
1723 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1727 /*********************************************************************
1732 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1736 if (!(es
->style
& ES_MULTILINE
))
1737 return (LRESULT
)FALSE
;
1747 if (es
->y_offset
< es
->line_count
- 1)
1752 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1755 if (es
->y_offset
< es
->line_count
- 1)
1756 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1759 return (LRESULT
)FALSE
;
1762 INT vlc
= get_vertical_line_count(es
);
1763 /* check if we are going to move too far */
1764 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1765 dy
= es
->line_count
- vlc
- es
->y_offset
;
1767 /* Notification is done in EDIT_EM_LineScroll */
1769 EDIT_EM_LineScroll(es
, 0, dy
);
1772 return MAKELONG((SHORT
)dy
, (BOOL
)TRUE
);
1774 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
1779 /*********************************************************************
1784 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1787 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1788 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1789 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1793 /*********************************************************************
1798 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1800 if (es
->style
& ES_MULTILINE
) {
1804 INT cw
= es
->char_width
;
1809 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1810 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1811 vlc
= get_vertical_line_count(es
);
1812 if (l
>= es
->y_offset
+ vlc
)
1813 dy
= l
- vlc
+ 1 - es
->y_offset
;
1814 if (l
< es
->y_offset
)
1815 dy
= l
- es
->y_offset
;
1816 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1817 if (x
< es
->format_rect
.left
)
1818 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1819 if (x
> es
->format_rect
.right
)
1820 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1821 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1823 /* check if we are going to move too far */
1824 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1825 dx
= es
->text_width
- ww
- es
->x_offset
;
1826 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1827 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1834 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1835 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1836 if (x
< es
->format_rect
.left
) {
1837 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1840 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1841 } while ((x
< goal
) && es
->x_offset
);
1842 /* FIXME: use ScrollWindow() somehow to improve performance */
1843 EDIT_UpdateText(es
, NULL
, TRUE
);
1844 } else if (x
> es
->format_rect
.right
) {
1846 INT len
= get_text_length(es
);
1847 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1850 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1851 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1852 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1853 /* FIXME: use ScrollWindow() somehow to improve performance */
1854 EDIT_UpdateText(es
, NULL
, TRUE
);
1858 if(es
->flags
& EF_FOCUSED
)
1859 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1863 /*********************************************************************
1868 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1870 INT e
= es
->selection_end
;
1874 if ((es
->style
& ES_MULTILINE
) && e
&&
1875 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1877 if (e
&& (es
->text
[e
- 1] == '\r'))
1881 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1882 EDIT_EM_ScrollCaret(es
);
1886 /*********************************************************************
1890 * Only for multi line controls
1891 * Move the caret one line down, on a column with the nearest
1892 * x coordinate on the screen (might be a different column).
1895 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1897 INT s
= es
->selection_start
;
1898 INT e
= es
->selection_end
;
1899 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1900 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1901 INT x
= (short)LOWORD(pos
);
1902 INT y
= (short)HIWORD(pos
);
1904 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1907 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1908 EDIT_EM_ScrollCaret(es
);
1912 /*********************************************************************
1917 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1919 BOOL after_wrap
= FALSE
;
1922 /* Pass a high value in x to make sure of receiving the end of the line */
1923 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1924 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1925 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1927 e
= get_text_length(es
);
1928 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1929 EDIT_EM_ScrollCaret(es
);
1933 /*********************************************************************
1938 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1940 INT e
= es
->selection_end
;
1944 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1945 if (es
->text
[e
] == '\n')
1947 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1951 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1952 EDIT_EM_ScrollCaret(es
);
1956 /*********************************************************************
1960 * Home key: move to beginning of line.
1963 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1967 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1968 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1969 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1970 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1973 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1974 EDIT_EM_ScrollCaret(es
);
1978 /*********************************************************************
1980 * EDIT_MovePageDown_ML
1982 * Only for multi line controls
1983 * Move the caret one page down, on a column with the nearest
1984 * x coordinate on the screen (might be a different column).
1987 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1989 INT s
= es
->selection_start
;
1990 INT e
= es
->selection_end
;
1991 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1992 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1993 INT x
= (short)LOWORD(pos
);
1994 INT y
= (short)HIWORD(pos
);
1996 e
= EDIT_CharFromPos(es
, x
,
1997 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2001 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2002 EDIT_EM_ScrollCaret(es
);
2006 /*********************************************************************
2008 * EDIT_MovePageUp_ML
2010 * Only for multi line controls
2011 * Move the caret one page up, on a column with the nearest
2012 * x coordinate on the screen (might be a different column).
2015 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2017 INT s
= es
->selection_start
;
2018 INT e
= es
->selection_end
;
2019 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2020 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2021 INT x
= (short)LOWORD(pos
);
2022 INT y
= (short)HIWORD(pos
);
2024 e
= EDIT_CharFromPos(es
, x
,
2025 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2029 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2030 EDIT_EM_ScrollCaret(es
);
2034 /*********************************************************************
2038 * Only for multi line controls
2039 * Move the caret one line up, on a column with the nearest
2040 * x coordinate on the screen (might be a different column).
2043 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2045 INT s
= es
->selection_start
;
2046 INT e
= es
->selection_end
;
2047 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2048 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2049 INT x
= (short)LOWORD(pos
);
2050 INT y
= (short)HIWORD(pos
);
2052 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2055 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2056 EDIT_EM_ScrollCaret(es
);
2060 /*********************************************************************
2062 * EDIT_MoveWordBackward
2065 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2067 INT s
= es
->selection_start
;
2068 INT e
= es
->selection_end
;
2073 l
= EDIT_EM_LineFromChar(es
, e
);
2074 ll
= EDIT_EM_LineLength(es
, e
);
2075 li
= EDIT_EM_LineIndex(es
, l
);
2078 li
= EDIT_EM_LineIndex(es
, l
- 1);
2079 e
= li
+ EDIT_EM_LineLength(es
, li
);
2082 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2086 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2087 EDIT_EM_ScrollCaret(es
);
2091 /*********************************************************************
2093 * EDIT_MoveWordForward
2096 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2098 INT s
= es
->selection_start
;
2099 INT e
= es
->selection_end
;
2104 l
= EDIT_EM_LineFromChar(es
, e
);
2105 ll
= EDIT_EM_LineLength(es
, e
);
2106 li
= EDIT_EM_LineIndex(es
, l
);
2108 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2109 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2111 e
= li
+ EDIT_CallWordBreakProc(es
,
2112 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2116 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2117 EDIT_EM_ScrollCaret(es
);
2121 /*********************************************************************
2126 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2130 LOGFONTW underline_font
;
2131 HFONT hUnderline
= 0;
2140 BkMode
= GetBkMode(dc
);
2141 BkColor
= GetBkColor(dc
);
2142 TextColor
= GetTextColor(dc
);
2144 if (es
->composition_len
== 0)
2146 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2147 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2148 SetBkMode( dc
, OPAQUE
);
2152 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2153 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2154 underline_font
.lfUnderline
= TRUE
;
2155 hUnderline
= CreateFontIndirectW(&underline_font
);
2156 old_font
= SelectObject(dc
,hUnderline
);
2159 li
= EDIT_EM_LineIndex(es
, line
);
2160 if (es
->style
& ES_MULTILINE
) {
2161 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2162 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2164 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2165 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2166 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2168 if (es
->style
& ES_PASSWORD
)
2169 HeapFree(GetProcessHeap(), 0, text
);
2172 if (es
->composition_len
== 0)
2174 SetBkColor(dc
, BkColor
);
2175 SetTextColor(dc
, TextColor
);
2176 SetBkMode( dc
, BkMode
);
2181 SelectObject(dc
,old_font
);
2183 DeleteObject(hUnderline
);
2190 /*********************************************************************
2195 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2197 INT s
= es
->selection_start
;
2198 INT e
= es
->selection_end
;
2205 if (es
->style
& ES_MULTILINE
) {
2206 INT vlc
= get_vertical_line_count(es
);
2208 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2213 TRACE("line=%d\n", line
);
2215 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2216 x
= (short)LOWORD(pos
);
2217 y
= (short)HIWORD(pos
);
2218 li
= EDIT_EM_LineIndex(es
, line
);
2219 ll
= EDIT_EM_LineLength(es
, li
);
2220 s
= min(es
->selection_start
, es
->selection_end
);
2221 e
= max(es
->selection_start
, es
->selection_end
);
2222 s
= min(li
+ ll
, max(li
, s
));
2223 e
= min(li
+ ll
, max(li
, e
));
2224 if (rev
&& (s
!= e
) &&
2225 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2226 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2227 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2228 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2230 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2234 /*********************************************************************
2236 * EDIT_AdjustFormatRect
2238 * Adjusts the format rectangle for the current font and the
2239 * current client rectangle.
2242 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2246 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2247 if (es
->style
& ES_MULTILINE
)
2249 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2251 vlc
= get_vertical_line_count(es
);
2252 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2254 /* correct es->x_offset */
2255 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2256 max_x_offset
= es
->text_width
- fw
;
2257 if(max_x_offset
< 0) max_x_offset
= 0;
2258 if(es
->x_offset
> max_x_offset
)
2259 es
->x_offset
= max_x_offset
;
2261 /* correct es->y_offset */
2262 max_y_offset
= es
->line_count
- vlc
;
2263 if(max_y_offset
< 0) max_y_offset
= 0;
2264 if(es
->y_offset
> max_y_offset
)
2265 es
->y_offset
= max_y_offset
;
2267 /* force scroll info update */
2268 EDIT_UpdateScrollInfo(es
);
2271 /* Windows doesn't care to fix text placement for SL controls */
2272 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2274 /* Always stay within the client area */
2275 GetClientRect(es
->hwndSelf
, &ClientRect
);
2276 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2278 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2279 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2281 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2285 /*********************************************************************
2289 * note: this is not (exactly) the handler called on EM_SETRECTNP
2290 * it is also used to set the rect of a single line control
2293 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2297 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2299 CopyRect(&es
->format_rect
, rc
);
2301 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2302 es
->format_rect
.left
++;
2303 es
->format_rect
.right
--;
2305 if (es
->format_rect
.bottom
- es
->format_rect
.top
2306 >= es
->line_height
+ 2)
2308 es
->format_rect
.top
++;
2309 es
->format_rect
.bottom
--;
2312 else if (es
->style
& WS_BORDER
) {
2313 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2314 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2315 es
->format_rect
.left
+= bw
;
2316 es
->format_rect
.right
-= bw
;
2317 if (es
->format_rect
.bottom
- es
->format_rect
.top
2318 >= es
->line_height
+ 2 * bh
)
2320 es
->format_rect
.top
+= bh
;
2321 es
->format_rect
.bottom
-= bh
;
2325 es
->format_rect
.left
+= es
->left_margin
;
2326 es
->format_rect
.right
-= es
->right_margin
;
2327 EDIT_AdjustFormatRect(es
);
2331 /*********************************************************************
2335 * returns line number (not index) in high-order word of result.
2336 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2337 * to Richedit, not to the edit control. Original documentation is valid.
2338 * FIXME: do the specs mean to return -1 if outside client area or
2339 * if outside formatting rectangle ???
2342 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2350 GetClientRect(es
->hwndSelf
, &rc
);
2351 if (!PtInRect(&rc
, pt
))
2354 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2355 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2359 /*********************************************************************
2363 * Enable or disable soft breaks.
2365 * This means: insert or remove the soft linebreak character (\r\r\n).
2366 * Take care to check if the text still fits the buffer after insertion.
2367 * If not, notify with EN_ERRSPACE.
2370 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2372 es
->flags
&= ~EF_USE_SOFTBRK
;
2374 es
->flags
|= EF_USE_SOFTBRK
;
2375 FIXME("soft break enabled, not implemented\n");
2381 /*********************************************************************
2385 * Hopefully this won't fire back at us.
2386 * We always start with a fixed buffer in the local heap.
2387 * Despite of the documentation says that the local heap is used
2388 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2389 * buffer on the local heap.
2392 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2396 if (!(es
->style
& ES_MULTILINE
))
2400 hLocal
= es
->hloc32W
;
2406 UINT countA
, alloc_size
;
2407 TRACE("Allocating 32-bit ANSI alias buffer\n");
2408 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2409 alloc_size
= ROUND_TO_GROW(countA
);
2410 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2412 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2415 textA
= LocalLock(es
->hloc32A
);
2416 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2417 LocalUnlock(es
->hloc32A
);
2419 hLocal
= es
->hloc32A
;
2422 es
->flags
|= EF_APP_HAS_HANDLE
;
2423 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2429 /*********************************************************************
2433 * Hopefully this won't fire back at us.
2434 * We always start with a buffer in 32 bit linear memory.
2435 * However, with this message a 16 bit application requests
2436 * a handle of 16 bit local heap memory, where it expects to find
2438 * It's a pitty that from this moment on we have to use this
2439 * local heap, because applications may rely on the handle
2442 * In this function we'll try to switch to local heap.
2444 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2447 UINT countA
, alloc_size
;
2448 STACK16FRAME
* stack16
;
2451 if (!(es
->style
& ES_MULTILINE
))
2457 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2458 oldDS
= stack16
->ds
;
2459 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2461 if (!LocalHeapSize16()) {
2463 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2464 ERR("could not initialize local heap\n");
2467 TRACE("local heap initialized\n");
2470 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2471 alloc_size
= ROUND_TO_GROW(countA
);
2473 TRACE("Allocating 16-bit ANSI alias buffer\n");
2474 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2475 ERR("could not allocate new 16 bit buffer\n");
2479 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2480 ERR("could not lock new 16 bit buffer\n");
2481 LocalFree16(es
->hloc16
);
2486 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2487 LocalUnlock16(es
->hloc16
);
2488 es
->flags
|= EF_APP_HAS_HANDLE
;
2490 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2493 stack16
->ds
= oldDS
;
2499 /*********************************************************************
2504 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2507 INT line_len
, dst_len
;
2510 if (es
->style
& ES_MULTILINE
) {
2511 if (line
>= es
->line_count
)
2515 i
= EDIT_EM_LineIndex(es
, line
);
2517 line_len
= EDIT_EM_LineLength(es
, i
);
2518 dst_len
= *(WORD
*)dst
;
2521 if(dst_len
<= line_len
)
2523 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2526 else /* Append 0 if enough space */
2528 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2535 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2536 if(!ret
&& line_len
) /* Insufficient buffer size */
2538 if(ret
< dst_len
) /* Append 0 if enough space */
2539 ((LPSTR
)dst
)[ret
] = 0;
2545 /*********************************************************************
2550 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2552 UINT s
= es
->selection_start
;
2553 UINT e
= es
->selection_end
;
2560 return MAKELONG(s
, e
);
2564 /*********************************************************************
2568 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2571 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2573 UINT strl
= strlenW(lpsz_replace
);
2574 UINT tl
= get_text_length(es
);
2585 TRACE("%s, can_undo %d, send_update %d\n",
2586 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2588 s
= es
->selection_start
;
2589 e
= es
->selection_end
;
2591 if ((s
== e
) && !strl
)
2596 size
= tl
- (e
- s
) + strl
;
2600 /* Issue the EN_MAXTEXT notification and continue with replacing text
2601 * such that buffer limit is honored. */
2602 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2603 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2604 /* Buffer limit can be smaller than the actual length of text in combobox */
2605 if (es
->buffer_limit
< (tl
- (e
-s
)))
2608 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2611 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2615 /* there is something to be deleted */
2616 TRACE("deleting stuff.\n");
2618 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2620 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2621 buf
[bufl
] = 0; /* ensure 0 termination */
2623 strcpyW(es
->text
+ s
, es
->text
+ e
);
2624 text_buffer_changed(es
);
2627 /* there is an insertion */
2628 tl
= get_text_length(es
);
2629 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
));
2630 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2632 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2633 p
[i
] = lpsz_replace
[i
];
2634 if(es
->style
& ES_UPPERCASE
)
2635 CharUpperBuffW(p
, strl
);
2636 else if(es
->style
& ES_LOWERCASE
)
2637 CharLowerBuffW(p
, strl
);
2638 text_buffer_changed(es
);
2640 if (es
->style
& ES_MULTILINE
)
2642 INT st
= min(es
->selection_start
, es
->selection_end
);
2643 INT vlc
= get_vertical_line_count(es
);
2645 hrgn
= CreateRectRgn(0, 0, 0, 0);
2646 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2647 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2648 /* if text is too long undo all changes */
2649 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2651 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2653 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2655 text_buffer_changed(es
);
2656 EDIT_BuildLineDefs_ML(es
, s
, e
,
2657 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2660 hrgn
= CreateRectRgn(0, 0, 0, 0);
2661 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2665 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2666 EDIT_CalcLineWidth_SL(es
);
2667 /* remove chars that don't fit */
2668 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2669 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2670 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2672 EDIT_CalcLineWidth_SL(es
);
2674 text_buffer_changed(es
);
2675 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2681 utl
= strlenW(es
->undo_text
);
2682 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2683 /* undo-buffer is extended to the right */
2684 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2685 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2686 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2687 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2688 /* undo-buffer is extended to the left */
2689 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2690 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2692 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2694 es
->undo_position
= s
;
2696 /* new undo-buffer */
2697 EDIT_MakeUndoFit(es
, e
- s
);
2698 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2699 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2700 es
->undo_position
= s
;
2702 /* any deletion makes the old insertion-undo invalid */
2703 es
->undo_insert_count
= 0;
2705 EDIT_EM_EmptyUndoBuffer(es
);
2709 if ((s
== es
->undo_position
) ||
2710 ((es
->undo_insert_count
) &&
2711 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2713 * insertion is new and at delete position or
2714 * an extension to either left or right
2716 es
->undo_insert_count
+= strl
;
2718 /* new insertion undo */
2719 es
->undo_position
= s
;
2720 es
->undo_insert_count
= strl
;
2721 /* new insertion makes old delete-buffer invalid */
2722 *es
->undo_text
= '\0';
2725 EDIT_EM_EmptyUndoBuffer(es
);
2729 HeapFree(GetProcessHeap(), 0, buf
);
2733 /* If text has been deleted and we're right or center aligned then scroll rightward */
2734 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2736 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2738 if (delta
< 0 && es
->x_offset
)
2740 if (abs(delta
) > es
->x_offset
)
2743 es
->x_offset
+= delta
;
2747 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2748 es
->flags
|= EF_MODIFIED
;
2749 if (send_update
) es
->flags
|= EF_UPDATE
;
2752 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2756 EDIT_UpdateText(es
, NULL
, TRUE
);
2758 EDIT_EM_ScrollCaret(es
);
2760 /* force scroll info update */
2761 EDIT_UpdateScrollInfo(es
);
2764 if(send_update
|| (es
->flags
& EF_UPDATE
))
2766 es
->flags
&= ~EF_UPDATE
;
2767 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2772 /*********************************************************************
2776 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2779 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2781 if (!(es
->style
& ES_MULTILINE
))
2785 WARN("called with NULL handle\n");
2789 EDIT_UnlockBuffer(es
, TRUE
);
2794 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2795 HANDLE16 oldDS
= stack16
->ds
;
2797 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2798 LocalFree16(es
->hloc16
);
2799 stack16
->ds
= oldDS
;
2808 LocalFree(es
->hloc32A
);
2820 countA
= LocalSize(hloc
);
2821 textA
= LocalLock(hloc
);
2822 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2823 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2825 ERR("Could not allocate new unicode buffer\n");
2828 textW
= LocalLock(hloc32W_new
);
2829 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2830 LocalUnlock(hloc32W_new
);
2834 LocalFree(es
->hloc32W
);
2836 es
->hloc32W
= hloc32W_new
;
2840 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2842 es
->flags
|= EF_APP_HAS_HANDLE
;
2843 EDIT_LockBuffer(es
);
2845 es
->x_offset
= es
->y_offset
= 0;
2846 es
->selection_start
= es
->selection_end
= 0;
2847 EDIT_EM_EmptyUndoBuffer(es
);
2848 es
->flags
&= ~EF_MODIFIED
;
2849 es
->flags
&= ~EF_UPDATE
;
2850 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2851 EDIT_UpdateText(es
, NULL
, TRUE
);
2852 EDIT_EM_ScrollCaret(es
);
2853 /* force scroll info update */
2854 EDIT_UpdateScrollInfo(es
);
2859 /*********************************************************************
2863 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2866 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
2868 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2869 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2870 HANDLE16 oldDS
= stack16
->ds
;
2876 if (!(es
->style
& ES_MULTILINE
))
2880 WARN("called with NULL handle\n");
2884 EDIT_UnlockBuffer(es
, TRUE
);
2888 LocalFree(es
->hloc32A
);
2892 stack16
->ds
= hInstance
;
2893 countA
= LocalSize16(hloc
);
2894 textA
= MapSL(LocalLock16(hloc
));
2895 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2896 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2898 ERR("Could not allocate new unicode buffer\n");
2901 textW
= LocalLock(hloc32W_new
);
2902 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2903 LocalUnlock(hloc32W_new
);
2904 LocalUnlock16(hloc
);
2905 stack16
->ds
= oldDS
;
2908 LocalFree(es
->hloc32W
);
2910 es
->hloc32W
= hloc32W_new
;
2913 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2915 es
->flags
|= EF_APP_HAS_HANDLE
;
2916 EDIT_LockBuffer(es
);
2918 es
->x_offset
= es
->y_offset
= 0;
2919 es
->selection_start
= es
->selection_end
= 0;
2920 EDIT_EM_EmptyUndoBuffer(es
);
2921 es
->flags
&= ~EF_MODIFIED
;
2922 es
->flags
&= ~EF_UPDATE
;
2923 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2924 EDIT_UpdateText(es
, NULL
, TRUE
);
2925 EDIT_EM_ScrollCaret(es
);
2926 /* force scroll info update */
2927 EDIT_UpdateScrollInfo(es
);
2932 /*********************************************************************
2936 * NOTE: this version currently implements WinNT limits
2939 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2941 if (!limit
) limit
= ~0u;
2942 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2943 es
->buffer_limit
= limit
;
2947 /*********************************************************************
2951 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2952 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2953 * margin according to the textmetrics of the current font.
2955 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2956 * of the char's width as the margin, but this is not how Windows handles this.
2957 * For all other fonts Windows sets the margins to zero.
2959 * FIXME - When EC_USEFONTINFO is used the margins only change if the
2960 * edit control is equal to or larger than a certain size.
2961 * Interestingly if one subtracts both the left and right margins from
2962 * this size one always seems to get an even number. The extents of
2963 * the (four character) string "'**'" match this quite closely, so
2964 * we'll use this until we come up with a better idea.
2966 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
2968 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
2971 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
2972 return sz
.cx
+ left
+ right
;
2975 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2976 WORD left
, WORD right
, BOOL repaint
)
2979 INT default_left_margin
= 0; /* in pixels */
2980 INT default_right_margin
= 0; /* in pixels */
2982 /* Set the default margins depending on the font */
2983 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2984 HDC dc
= GetDC(es
->hwndSelf
);
2985 HFONT old_font
= SelectObject(dc
, es
->font
);
2986 GetTextMetricsW(dc
, &tm
);
2987 /* The default margins are only non zero for TrueType or Vector fonts */
2988 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2991 /* This must be calculated more exactly! But how? */
2992 default_left_margin
= tm
.tmAveCharWidth
/ 2;
2993 default_right_margin
= tm
.tmAveCharWidth
/ 2;
2994 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
2995 GetClientRect(es
->hwndSelf
, &rc
);
2996 if(rc
.right
- rc
.left
< min_size
) {
2997 default_left_margin
= es
->left_margin
;
2998 default_right_margin
= es
->right_margin
;
3001 SelectObject(dc
, old_font
);
3002 ReleaseDC(es
->hwndSelf
, dc
);
3005 if (action
& EC_LEFTMARGIN
) {
3006 es
->format_rect
.left
-= es
->left_margin
;
3007 if (left
!= EC_USEFONTINFO
)
3008 es
->left_margin
= left
;
3010 es
->left_margin
= default_left_margin
;
3011 es
->format_rect
.left
+= es
->left_margin
;
3014 if (action
& EC_RIGHTMARGIN
) {
3015 es
->format_rect
.right
+= es
->right_margin
;
3016 if (right
!= EC_USEFONTINFO
)
3017 es
->right_margin
= right
;
3019 es
->right_margin
= default_right_margin
;
3020 es
->format_rect
.right
-= es
->right_margin
;
3023 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3024 EDIT_AdjustFormatRect(es
);
3025 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3028 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3032 /*********************************************************************
3034 * EM_SETPASSWORDCHAR
3037 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3041 if (es
->style
& ES_MULTILINE
)
3044 if (es
->password_char
== c
)
3047 style
= GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
);
3048 es
->password_char
= c
;
3050 SetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3051 es
->style
|= ES_PASSWORD
;
3053 SetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3054 es
->style
&= ~ES_PASSWORD
;
3056 EDIT_UpdateText(es
, NULL
, TRUE
);
3060 /*********************************************************************
3065 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3067 if (!(es
->style
& ES_MULTILINE
))
3069 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3070 es
->tabs_count
= count
;
3074 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3075 if (es
->tabs
== NULL
)
3080 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3087 /*********************************************************************
3092 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3094 if (!(es
->style
& ES_MULTILINE
))
3096 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3097 es
->tabs_count
= count
;
3102 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3103 for (i
= 0 ; i
< count
; i
++)
3104 es
->tabs
[i
] = *tabs
++;
3111 /*********************************************************************
3113 * EM_SETWORDBREAKPROC
3116 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3118 if (es
->word_break_proc
== wbp
)
3121 es
->word_break_proc
= wbp
;
3123 es
->word_break_proc16
= NULL
;
3126 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3127 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3128 EDIT_UpdateText(es
, NULL
, TRUE
);
3134 /*********************************************************************
3136 * EM_SETWORDBREAKPROC16
3139 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3141 if (es
->word_break_proc16
== wbp
)
3144 es
->word_break_proc
= NULL
;
3145 es
->word_break_proc16
= wbp
;
3146 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3147 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3148 EDIT_UpdateText(es
, NULL
, TRUE
);
3154 /*********************************************************************
3159 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3164 /* As per MSDN spec, for a single-line edit control,
3165 the return value is always TRUE */
3166 if( es
->style
& ES_READONLY
)
3167 return !(es
->style
& ES_MULTILINE
);
3169 ulength
= strlenW(es
->undo_text
);
3171 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3175 strcpyW(utext
, es
->undo_text
);
3177 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3178 es
->undo_insert_count
, debugstr_w(utext
));
3180 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3181 EDIT_EM_EmptyUndoBuffer(es
);
3182 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3183 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3184 /* send the notification after the selection start and end are set */
3185 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3186 EDIT_EM_ScrollCaret(es
);
3187 HeapFree(GetProcessHeap(), 0, utext
);
3189 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3190 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3195 /* Helper function for WM_CHAR
3197 * According to an MSDN blog article titled "Just because you're a control
3198 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3199 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3200 * a dialog box or not.
3202 static BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3205 if (es
->hwndParent
&& es
->hwndParent
!= GetDesktopWindow())
3207 if (GetClassLongPtrW (es
->hwndParent
, GCW_ATOM
) == (DWORD
)MAKEINTATOM(32770))
3217 pParent
= WIN_GetPtr(es
->hwndParent
);
3218 if (pParent
&& pParent
!= WND_OTHER_PROCESS
&& pParent
!= WND_DESKTOP
)
3220 if (pParent
->flags
& WIN_ISDIALOG
)
3222 WIN_ReleasePtr(pParent
);
3230 /*********************************************************************
3235 static void EDIT_WM_Paste(EDITSTATE
*es
)
3240 /* Protect read-only edit control from modification */
3241 if(es
->style
& ES_READONLY
)
3244 OpenClipboard(es
->hwndSelf
);
3245 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
3246 src
= GlobalLock(hsrc
);
3247 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
3250 else if (es
->style
& ES_PASSWORD
) {
3251 /* clear selected text in password edit box even with empty clipboard */
3252 const WCHAR empty_strW
[] = { 0 };
3253 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
3259 /*********************************************************************
3264 static void EDIT_WM_Copy(EDITSTATE
*es
)
3266 INT s
= min(es
->selection_start
, es
->selection_end
);
3267 INT e
= max(es
->selection_start
, es
->selection_end
);
3275 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3276 dst
= GlobalLock(hdst
);
3277 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3278 dst
[len
] = 0; /* ensure 0 termination */
3279 TRACE("%s\n", debugstr_w(dst
));
3281 OpenClipboard(es
->hwndSelf
);
3283 SetClipboardData(CF_UNICODETEXT
, hdst
);
3288 /*********************************************************************
3293 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
3295 static const WCHAR empty_stringW
[] = {0};
3297 /* Protect read-only edit control from modification */
3298 if(es
->style
& ES_READONLY
)
3301 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
3305 /*********************************************************************
3310 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3317 /*********************************************************************
3322 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3326 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3330 /* If it's not a multiline edit box, it would be ignored below.
3331 * For multiline edit without ES_WANTRETURN, we have to make a
3334 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3335 if (EDIT_IsInsideDialog(es
))
3338 if (es
->style
& ES_MULTILINE
) {
3339 if (es
->style
& ES_READONLY
) {
3340 EDIT_MoveHome(es
, FALSE
, FALSE
);
3341 EDIT_MoveDown_ML(es
, FALSE
);
3343 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3344 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3349 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3351 static const WCHAR tabW
[] = {'\t',0};
3352 if (EDIT_IsInsideDialog(es
))
3354 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3358 if (!(es
->style
& ES_READONLY
) && !control
) {
3359 if (es
->selection_start
!= es
->selection_end
)
3362 /* delete character left of caret */
3363 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3364 EDIT_MoveBackward(es
, TRUE
);
3370 if (!(es
->style
& ES_PASSWORD
))
3371 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3374 if (!(es
->style
& ES_READONLY
))
3375 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3378 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3379 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3382 if (!(es
->style
& ES_READONLY
))
3383 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3387 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3388 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3391 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3395 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3403 /*********************************************************************
3408 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3410 if (code
|| control
)
3415 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3418 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3421 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3424 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3427 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3430 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3431 EDIT_EM_ScrollCaret(es
);
3434 ERR("unknown menu item, please report\n");
3440 /*********************************************************************
3444 * Note: the resource files resource/sysres_??.rc cannot define a
3445 * single popup menu. Hence we use a (dummy) menubar
3446 * containing the single popup menu as its first item.
3448 * FIXME: the message identifiers have been chosen arbitrarily,
3449 * hence we use MF_BYPOSITION.
3450 * We might as well use the "real" values (anybody knows ?)
3451 * The menu definition is in resources/sysres_??.rc.
3452 * Once these are OK, we better use MF_BYCOMMAND here
3453 * (as we do in EDIT_WM_Command()).
3456 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3459 HMENU menu
= LoadMenuA(User32Instance
, "EDITMENU");
3461 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3463 HMENU popup
= GetSubMenu(menu
, 0);
3464 UINT start
= es
->selection_start
;
3465 UINT end
= es
->selection_end
;
3467 ORDER_UINT(start
, end
);
3470 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3472 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3474 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3476 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3478 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3480 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3482 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3485 /* Windows places the menu at the edit's center in this case */
3486 GetClientRect(es
->hwndSelf
, &rc
);
3487 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
3488 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3489 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3492 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
, x
, y
, 0, es
->hwndSelf
, NULL
);
3497 /*********************************************************************
3502 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3504 if(!count
) return 0;
3508 lstrcpynW(dst
, es
->text
, count
);
3509 return strlenW(dst
);
3513 LPSTR textA
= (LPSTR
)dst
;
3514 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3515 textA
[count
- 1] = 0; /* ensure 0 termination */
3516 return strlen(textA
);
3520 /*********************************************************************
3525 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3527 HWND hLBox
= es
->hwndListBox
;
3535 hCombo
= GetParent(es
->hwndSelf
);
3539 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3541 if (key
== VK_UP
|| key
== VK_DOWN
)
3543 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3546 if (msg
== WM_KEYDOWN
|| nEUI
)
3547 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3553 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3555 /* make sure ComboLBox pops up */
3556 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3561 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3564 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3566 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3568 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
3573 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3579 /*********************************************************************
3583 * Handling of special keys that don't produce a WM_CHAR
3584 * (i.e. non-printable keys) & Backspace & Delete
3587 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3592 if (GetKeyState(VK_MENU
) & 0x8000)
3595 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3596 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3601 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3606 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3607 EDIT_MoveUp_ML(es
, shift
);
3610 EDIT_MoveWordBackward(es
, shift
);
3612 EDIT_MoveBackward(es
, shift
);
3615 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3619 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3620 EDIT_MoveDown_ML(es
, shift
);
3622 EDIT_MoveWordForward(es
, shift
);
3624 EDIT_MoveForward(es
, shift
);
3627 EDIT_MoveHome(es
, shift
, control
);
3630 EDIT_MoveEnd(es
, shift
, control
);
3633 if (es
->style
& ES_MULTILINE
)
3634 EDIT_MovePageUp_ML(es
, shift
);
3636 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3639 if (es
->style
& ES_MULTILINE
)
3640 EDIT_MovePageDown_ML(es
, shift
);
3642 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3645 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3646 if (es
->selection_start
!= es
->selection_end
) {
3653 /* delete character left of caret */
3654 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3655 EDIT_MoveBackward(es
, TRUE
);
3657 } else if (control
) {
3658 /* delete to end of line */
3659 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3660 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3663 /* delete character right of caret */
3664 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3665 EDIT_MoveForward(es
, TRUE
);
3673 if (!(es
->style
& ES_READONLY
))
3679 /* If the edit doesn't want the return send a message to the default object */
3680 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3685 if (!EDIT_IsInsideDialog(es
)) return 1;
3687 hwndParent
= GetParent(es
->hwndSelf
);
3688 dw
= SendMessageW( hwndParent
, DM_GETDEFID
, 0, 0 );
3689 if (HIWORD(dw
) == DC_HASDEFID
)
3691 SendMessageW( hwndParent
, WM_COMMAND
,
3692 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
3693 (LPARAM
)GetDlgItem( hwndParent
, LOWORD(dw
) ) );
3696 SendMessageW( hwndParent
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndParent
, IDOK
) );
3700 if (!(es
->style
& ES_MULTILINE
))
3701 SendMessageW(GetParent(es
->hwndSelf
), WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( GetParent(es
->hwndSelf
), IDCANCEL
) );
3704 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3711 /*********************************************************************
3716 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3718 es
->flags
&= ~EF_FOCUSED
;
3720 if(!(es
->style
& ES_NOHIDESEL
))
3721 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3722 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3727 /*********************************************************************
3731 * The caret position has been set on the WM_LBUTTONDOWN message
3734 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3737 INT e
= es
->selection_end
;
3742 es
->bCaptureState
= TRUE
;
3743 SetCapture(es
->hwndSelf
);
3745 l
= EDIT_EM_LineFromChar(es
, e
);
3746 li
= EDIT_EM_LineIndex(es
, l
);
3747 ll
= EDIT_EM_LineLength(es
, e
);
3748 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3749 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3750 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3751 EDIT_EM_ScrollCaret(es
);
3752 es
->region_posx
= es
->region_posy
= 0;
3753 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3758 /*********************************************************************
3763 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3768 es
->bCaptureState
= TRUE
;
3769 SetCapture(es
->hwndSelf
);
3770 EDIT_ConfinePoint(es
, &x
, &y
);
3771 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3772 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3773 EDIT_EM_ScrollCaret(es
);
3774 es
->region_posx
= es
->region_posy
= 0;
3775 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3777 if (!(es
->flags
& EF_FOCUSED
))
3778 SetFocus(es
->hwndSelf
);
3784 /*********************************************************************
3789 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3791 if (es
->bCaptureState
) {
3792 KillTimer(es
->hwndSelf
, 0);
3793 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3795 es
->bCaptureState
= FALSE
;
3800 /*********************************************************************
3805 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3807 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3812 /*********************************************************************
3817 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3823 /* If the mouse has been captured by process other than the edit control itself,
3824 * the windows edit controls will not select the strings with mouse move.
3826 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3830 * FIXME: gotta do some scrolling if outside client
3831 * area. Maybe reset the timer ?
3834 EDIT_ConfinePoint(es
, &x
, &y
);
3835 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3836 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3837 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3838 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3839 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3844 /*********************************************************************
3849 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3862 BOOL rev
= es
->bEnableState
&&
3863 ((es
->flags
& EF_FOCUSED
) ||
3864 (es
->style
& ES_NOHIDESEL
));
3865 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3867 GetClientRect(es
->hwndSelf
, &rcClient
);
3869 /* get the background brush */
3870 brush
= EDIT_NotifyCtlColor(es
, dc
);
3872 /* paint the border and the background */
3873 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3875 if(es
->style
& WS_BORDER
) {
3876 bw
= GetSystemMetrics(SM_CXBORDER
);
3877 bh
= GetSystemMetrics(SM_CYBORDER
);
3879 if(es
->style
& ES_MULTILINE
) {
3880 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3881 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3884 /* Draw the frame. Same code as in nonclient.c */
3885 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3886 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3887 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3888 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3889 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3890 SelectObject(dc
, old_brush
);
3892 /* Keep the border clean */
3893 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3894 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3897 GetClipBox(dc
, &rc
);
3898 FillRect(dc
, &rc
, brush
);
3900 IntersectClipRect(dc
, es
->format_rect
.left
,
3901 es
->format_rect
.top
,
3902 es
->format_rect
.right
,
3903 es
->format_rect
.bottom
);
3904 if (es
->style
& ES_MULTILINE
) {
3906 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3909 old_font
= SelectObject(dc
, es
->font
);
3911 if (!es
->bEnableState
)
3912 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3913 GetClipBox(dc
, &rcRgn
);
3914 if (es
->style
& ES_MULTILINE
) {
3915 INT vlc
= get_vertical_line_count(es
);
3916 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3917 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3918 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3919 EDIT_PaintLine(es
, dc
, i
, rev
);
3922 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3923 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3924 EDIT_PaintLine(es
, dc
, 0, rev
);
3927 SelectObject(dc
, old_font
);
3930 EndPaint(es
->hwndSelf
, &ps
);
3934 /*********************************************************************
3939 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3941 es
->flags
|= EF_FOCUSED
;
3943 if (!(es
->style
& ES_NOHIDESEL
))
3944 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3946 /* single line edit updates itself */
3947 if (!(es
->style
& ES_MULTILINE
))
3949 HDC hdc
= GetDC(es
->hwndSelf
);
3950 EDIT_WM_Paint(es
, hdc
);
3951 ReleaseDC(es
->hwndSelf
, hdc
);
3954 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3955 EDIT_SetCaretPos(es
, es
->selection_end
,
3956 es
->flags
& EF_AFTER_WRAP
);
3957 ShowCaret(es
->hwndSelf
);
3958 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3962 /*********************************************************************
3966 * With Win95 look the margins are set to default font value unless
3967 * the system font (font == 0) is being set, in which case they are left
3971 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3979 dc
= GetDC(es
->hwndSelf
);
3981 old_font
= SelectObject(dc
, font
);
3982 GetTextMetricsW(dc
, &tm
);
3983 es
->line_height
= tm
.tmHeight
;
3984 es
->char_width
= tm
.tmAveCharWidth
;
3986 SelectObject(dc
, old_font
);
3987 ReleaseDC(es
->hwndSelf
, dc
);
3989 /* Reset the format rect and the margins */
3990 GetClientRect(es
->hwndSelf
, &clientRect
);
3991 EDIT_SetRectNP(es
, &clientRect
);
3992 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3993 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3995 if (es
->style
& ES_MULTILINE
)
3996 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3998 EDIT_CalcLineWidth_SL(es
);
4001 EDIT_UpdateText(es
, NULL
, TRUE
);
4002 if (es
->flags
& EF_FOCUSED
) {
4004 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
4005 EDIT_SetCaretPos(es
, es
->selection_end
,
4006 es
->flags
& EF_AFTER_WRAP
);
4007 ShowCaret(es
->hwndSelf
);
4012 /*********************************************************************
4017 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4018 * The modified flag is reset. No notifications are sent.
4020 * For single-line controls, reception of WM_SETTEXT triggers:
4021 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4024 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
4026 LPWSTR textW
= NULL
;
4027 if (!unicode
&& text
)
4029 LPCSTR textA
= (LPCSTR
)text
;
4030 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4031 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
4033 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4037 if (es
->flags
& EF_UPDATE
)
4038 /* fixed this bug once; complain if we see it about to happen again. */
4039 ERR("SetSel may generate UPDATE message whose handler may reset "
4042 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4045 TRACE("%s\n", debugstr_w(text
));
4046 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4048 HeapFree(GetProcessHeap(), 0, textW
);
4052 static const WCHAR empty_stringW
[] = {0};
4054 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4057 es
->flags
&= ~EF_MODIFIED
;
4058 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4060 /* Send the notification after the selection start and end have been set
4061 * edit control doesn't send notification on WM_SETTEXT
4062 * if it is multiline, or it is part of combobox
4064 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4066 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
4067 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4069 EDIT_EM_ScrollCaret(es
);
4070 EDIT_UpdateScrollInfo(es
);
4074 /*********************************************************************
4079 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4081 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4083 TRACE("width = %d, height = %d\n", width
, height
);
4084 SetRect(&rc
, 0, 0, width
, height
);
4085 EDIT_SetRectNP(es
, &rc
);
4086 EDIT_UpdateText(es
, NULL
, TRUE
);
4091 /*********************************************************************
4095 * This message is sent by SetWindowLong on having changed either the Style
4096 * or the extended style.
4098 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4100 * See also EDIT_WM_NCCreate
4102 * It appears that the Windows version of the edit control allows the style
4103 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4104 * style variable which will generally be different. In this function we
4105 * update the internal style based on what changed in the externally visible
4108 * Much of this content as based upon the MSDN, especially:
4109 * Platform SDK Documentation -> User Interface Services ->
4110 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4111 * Edit Control Styles
4113 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4115 if (GWL_STYLE
== which
) {
4116 DWORD style_change_mask
;
4118 /* Only a subset of changes can be applied after the control
4121 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4123 if (es
->style
& ES_MULTILINE
)
4124 style_change_mask
|= ES_WANTRETURN
;
4126 new_style
= style
->styleNew
& style_change_mask
;
4128 /* Number overrides lowercase overrides uppercase (at least it
4129 * does in Win95). However I'll bet that ES_NUMBER would be
4130 * invalid under Win 3.1.
4132 if (new_style
& ES_NUMBER
) {
4133 ; /* do not override the ES_NUMBER */
4134 } else if (new_style
& ES_LOWERCASE
) {
4135 new_style
&= ~ES_UPPERCASE
;
4138 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4139 } else if (GWL_EXSTYLE
== which
) {
4140 ; /* FIXME - what is needed here */
4142 WARN ("Invalid style change %ld\n",which
);
4148 /*********************************************************************
4153 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4155 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4156 if (EDIT_EM_CanUndo(es
))
4159 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4160 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4163 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4167 /*********************************************************************
4172 static void EDIT_WM_Timer(EDITSTATE
*es
)
4174 if (es
->region_posx
< 0) {
4175 EDIT_MoveBackward(es
, TRUE
);
4176 } else if (es
->region_posx
> 0) {
4177 EDIT_MoveForward(es
, TRUE
);
4180 * FIXME: gotta do some vertical scrolling here, like
4181 * EDIT_EM_LineScroll(hwnd, 0, 1);
4185 /*********************************************************************
4190 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4195 if (!(es
->style
& ES_MULTILINE
))
4198 if (!(es
->style
& ES_AUTOHSCROLL
))
4202 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4205 TRACE("SB_LINELEFT\n");
4207 dx
= -es
->char_width
;
4210 TRACE("SB_LINERIGHT\n");
4211 if (es
->x_offset
< es
->text_width
)
4212 dx
= es
->char_width
;
4215 TRACE("SB_PAGELEFT\n");
4217 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4220 TRACE("SB_PAGERIGHT\n");
4221 if (es
->x_offset
< es
->text_width
)
4222 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4230 TRACE("SB_RIGHT\n");
4231 if (es
->x_offset
< es
->text_width
)
4232 dx
= es
->text_width
- es
->x_offset
;
4235 TRACE("SB_THUMBTRACK %d\n", pos
);
4236 es
->flags
|= EF_HSCROLL_TRACK
;
4237 if(es
->style
& WS_HSCROLL
)
4238 dx
= pos
- es
->x_offset
;
4243 if(pos
< 0 || pos
> 100) return 0;
4244 /* Assume default scroll range 0-100 */
4245 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4246 new_x
= pos
* (es
->text_width
- fw
) / 100;
4247 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4250 case SB_THUMBPOSITION
:
4251 TRACE("SB_THUMBPOSITION %d\n", pos
);
4252 es
->flags
&= ~EF_HSCROLL_TRACK
;
4253 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4254 dx
= pos
- es
->x_offset
;
4259 if(pos
< 0 || pos
> 100) return 0;
4260 /* Assume default scroll range 0-100 */
4261 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4262 new_x
= pos
* (es
->text_width
- fw
) / 100;
4263 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4266 /* force scroll info update */
4267 EDIT_UpdateScrollInfo(es
);
4268 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4272 TRACE("SB_ENDSCROLL\n");
4275 * FIXME : the next two are undocumented !
4276 * Are we doing the right thing ?
4277 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4278 * although it's also a regular control message.
4280 case EM_GETTHUMB
: /* this one is used by NT notepad */
4286 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4287 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4290 /* Assume default scroll range 0-100 */
4291 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4292 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4294 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4298 case EM_LINESCROLL16
:
4299 TRACE("EM_LINESCROLL16\n");
4305 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4311 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4312 /* check if we are going to move too far */
4313 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4314 dx
= es
->text_width
- fw
- es
->x_offset
;
4316 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4322 /*********************************************************************
4327 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4331 if (!(es
->style
& ES_MULTILINE
))
4334 if (!(es
->style
& ES_AUTOVSCROLL
))
4343 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4344 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4345 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4347 EDIT_EM_Scroll(es
, action
);
4354 TRACE("SB_BOTTOM\n");
4355 dy
= es
->line_count
- 1 - es
->y_offset
;
4358 TRACE("SB_THUMBTRACK %d\n", pos
);
4359 es
->flags
|= EF_VSCROLL_TRACK
;
4360 if(es
->style
& WS_VSCROLL
)
4361 dy
= pos
- es
->y_offset
;
4364 /* Assume default scroll range 0-100 */
4367 if(pos
< 0 || pos
> 100) return 0;
4368 vlc
= get_vertical_line_count(es
);
4369 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4370 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4371 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4372 es
->line_count
, es
->y_offset
, pos
, dy
);
4375 case SB_THUMBPOSITION
:
4376 TRACE("SB_THUMBPOSITION %d\n", pos
);
4377 es
->flags
&= ~EF_VSCROLL_TRACK
;
4378 if(es
->style
& WS_VSCROLL
)
4379 dy
= pos
- es
->y_offset
;
4382 /* Assume default scroll range 0-100 */
4385 if(pos
< 0 || pos
> 100) return 0;
4386 vlc
= get_vertical_line_count(es
);
4387 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4388 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4389 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4390 es
->line_count
, es
->y_offset
, pos
, dy
);
4394 /* force scroll info update */
4395 EDIT_UpdateScrollInfo(es
);
4396 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4400 TRACE("SB_ENDSCROLL\n");
4403 * FIXME : the next two are undocumented !
4404 * Are we doing the right thing ?
4405 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4406 * although it's also a regular control message.
4408 case EM_GETTHUMB
: /* this one is used by NT notepad */
4414 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4415 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4418 /* Assume default scroll range 0-100 */
4419 INT vlc
= get_vertical_line_count(es
);
4420 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4422 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4426 case EM_LINESCROLL16
:
4427 TRACE("EM_LINESCROLL16 %d\n", pos
);
4433 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4438 EDIT_EM_LineScroll(es
, 0, dy
);
4442 /*********************************************************************
4446 * FIXME: is this right ? (or should it be only VSCROLL)
4447 * (and maybe only for edit controls that really have their
4448 * own scrollbars) (and maybe only for multiline controls ?)
4449 * All in all: very poorly documented
4452 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4455 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4456 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4458 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
4459 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
4463 /********************************************************************
4465 * The Following code is to handle inline editing from IMEs
4468 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4471 LPWSTR lpCompStr
= NULL
;
4472 LPSTR lpCompStrAttr
= NULL
;
4475 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4482 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
4485 ERR("Unable to allocate IME CompositionString\n");
4490 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4491 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
4493 if (CompFlag
& GCS_COMPATTR
)
4496 * We do not use the attributes yet. it would tell us what characters
4497 * are in transition and which are converted or decided upon
4499 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4503 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4506 ERR("Unable to allocate IME Attribute String\n");
4507 HeapFree(GetProcessHeap(),0,lpCompStr
);
4510 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4512 lpCompStrAttr
[dwBufLenAttr
] = 0;
4515 lpCompStrAttr
= NULL
;
4518 /* check for change in composition start */
4519 if (es
->selection_end
< es
->composition_start
)
4520 es
->composition_start
= es
->selection_end
;
4522 /* replace existing selection string */
4523 es
->selection_start
= es
->composition_start
;
4525 if (es
->composition_len
> 0)
4526 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4528 es
->selection_end
= es
->selection_start
;
4530 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
4531 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4533 es
->selection_start
= es
->composition_start
;
4534 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4536 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4537 HeapFree(GetProcessHeap(),0,lpCompStr
);
4540 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4545 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4551 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
4554 ERR("Unable to alloc buffer for IME string\n");
4558 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4559 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
4561 /* check for change in composition start */
4562 if (es
->selection_end
< es
->composition_start
)
4563 es
->composition_start
= es
->selection_end
;
4565 es
->selection_start
= es
->composition_start
;
4566 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4567 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
4568 es
->composition_start
= es
->selection_end
;
4569 es
->composition_len
= 0;
4571 HeapFree(GetProcessHeap(),0,lpResultStr
);
4574 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4579 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4581 static const WCHAR empty_stringW
[] = {0};
4582 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4583 es
->composition_start
= es
->selection_end
;
4586 hIMC
= ImmGetContext(hwnd
);
4590 if (CompFlag
& GCS_RESULTSTR
)
4591 EDIT_GetResultStr(hIMC
, es
);
4592 if (CompFlag
& GCS_COMPSTR
)
4593 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4594 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4595 ImmReleaseContext(hwnd
, hIMC
);
4596 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4600 /*********************************************************************
4604 * See also EDIT_WM_StyleChanged
4606 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4611 TRACE("Creating %s edit control, style = %08x\n",
4612 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4614 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4616 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4619 * Note: since the EDITSTATE has not been fully initialized yet,
4620 * we can't use any API calls that may send
4621 * WM_XXX messages before WM_NCCREATE is completed.
4624 es
->is_unicode
= unicode
;
4625 es
->style
= lpcs
->style
;
4627 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4629 es
->hwndSelf
= hwnd
;
4630 /* Save parent, which will be notified by EN_* messages */
4631 es
->hwndParent
= lpcs
->hwndParent
;
4633 if (es
->style
& ES_COMBO
)
4634 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4636 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4637 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4639 /* Number overrides lowercase overrides uppercase (at least it
4640 * does in Win95). However I'll bet that ES_NUMBER would be
4641 * invalid under Win 3.1.
4643 if (es
->style
& ES_NUMBER
) {
4644 ; /* do not override the ES_NUMBER */
4645 } else if (es
->style
& ES_LOWERCASE
) {
4646 es
->style
&= ~ES_UPPERCASE
;
4648 if (es
->style
& ES_MULTILINE
) {
4649 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4650 if (es
->style
& WS_VSCROLL
)
4651 es
->style
|= ES_AUTOVSCROLL
;
4652 if (es
->style
& WS_HSCROLL
)
4653 es
->style
|= ES_AUTOHSCROLL
;
4654 es
->style
&= ~ES_PASSWORD
;
4655 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4656 /* Confirmed - RIGHT overrides CENTER */
4657 if (es
->style
& ES_RIGHT
)
4658 es
->style
&= ~ES_CENTER
;
4659 es
->style
&= ~WS_HSCROLL
;
4660 es
->style
&= ~ES_AUTOHSCROLL
;
4663 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4664 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4665 es
->style
&= ~ES_CENTER
;
4666 es
->style
&= ~WS_HSCROLL
;
4667 es
->style
&= ~WS_VSCROLL
;
4668 if (es
->style
& ES_PASSWORD
)
4669 es
->password_char
= '*';
4672 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4673 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4675 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4677 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4679 es
->undo_buffer_size
= es
->buffer_size
;
4681 if (es
->style
& ES_MULTILINE
)
4682 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4687 * In Win95 look and feel, the WS_BORDER style is replaced by the
4688 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4689 * control a nonclient area so we don't need to draw the border.
4690 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4691 * a nonclient area and we should handle painting the border ourselves.
4693 * When making modifications please ensure that the code still works
4694 * for edit controls created directly with style 0x50800000, exStyle 0
4695 * (which should have a single pixel border)
4697 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4698 es
->style
&= ~WS_BORDER
;
4699 else if (es
->style
& WS_BORDER
)
4700 SetWindowLongPtrW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4706 /*********************************************************************
4711 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4715 TRACE("%s\n", debugstr_w(name
));
4717 * To initialize some final structure members, we call some helper
4718 * functions. However, since the EDITSTATE is not consistent (i.e.
4719 * not fully initialized), we should be very careful which
4720 * functions can be called, and in what order.
4722 EDIT_WM_SetFont(es
, 0, FALSE
);
4723 EDIT_EM_EmptyUndoBuffer(es
);
4725 /* We need to calculate the format rect
4726 (applications may send EM_SETMARGINS before the control gets visible) */
4727 GetClientRect(es
->hwndSelf
, &clientRect
);
4728 EDIT_SetRectNP(es
, &clientRect
);
4730 if (name
&& *name
) {
4731 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4732 /* if we insert text to the editline, the text scrolls out
4733 * of the window, as the caret is placed after the insert
4734 * pos normally; thus we reset es->selection... to 0 and
4737 es
->selection_start
= es
->selection_end
= 0;
4738 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4739 * Messages are only to be sent when the USER does something to
4740 * change the contents. So I am removing this EN_CHANGE
4742 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4744 EDIT_EM_ScrollCaret(es
);
4746 /* force scroll info update */
4747 EDIT_UpdateScrollInfo(es
);
4748 /* The rule seems to return 1 here for success */
4749 /* Power Builder masked edit controls will crash */
4751 /* FIXME: is that in all cases so ? */
4756 /*********************************************************************
4761 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4766 LocalFree(es
->hloc32W
);
4769 LocalFree(es
->hloc32A
);
4773 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4774 HANDLE16 oldDS
= stack16
->ds
;
4776 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4777 while (LocalUnlock16(es
->hloc16
)) ;
4778 LocalFree16(es
->hloc16
);
4779 stack16
->ds
= oldDS
;
4783 pc
= es
->first_line_def
;
4787 HeapFree(GetProcessHeap(), 0, pc
);
4791 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4792 HeapFree(GetProcessHeap(), 0, es
);
4798 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4801 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4803 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4806 /*********************************************************************
4808 * EditWndProc_common
4810 * The messages are in the order of the actual integer values
4811 * (which can be found in include/windows.h)
4812 * Wherever possible the 16 bit versions are converted to
4813 * the 32 bit ones, so that we can 'fall through' to the
4814 * helper functions. These are mostly 32 bit (with a few
4815 * exceptions, clearly indicated by a '16' extension to their
4819 static LRESULT
EditWndProc_common( HWND hwnd
, UINT msg
,
4820 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4822 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4825 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4827 if (!es
&& msg
!= WM_NCCREATE
)
4828 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4830 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
4840 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4845 if ((short)LOWORD(lParam
) == -1)
4846 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4848 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
4850 EDIT_EM_ScrollCaret(es
);
4855 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4856 EDIT_EM_ScrollCaret(es
);
4864 RECT16
*r16
= MapSL(lParam
);
4865 r16
->left
= es
->format_rect
.left
;
4866 r16
->top
= es
->format_rect
.top
;
4867 r16
->right
= es
->format_rect
.right
;
4868 r16
->bottom
= es
->format_rect
.bottom
;
4874 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
4879 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4881 RECT16
*r16
= MapSL(lParam
);
4882 rc
.left
= r16
->left
;
4884 rc
.right
= r16
->right
;
4885 rc
.bottom
= r16
->bottom
;
4886 EDIT_SetRectNP(es
, &rc
);
4887 EDIT_UpdateText(es
, NULL
, TRUE
);
4892 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4893 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4894 EDIT_UpdateText(es
, NULL
, TRUE
);
4899 case EM_SETRECTNP16
:
4900 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4902 RECT16
*r16
= MapSL(lParam
);
4903 rc
.left
= r16
->left
;
4905 rc
.right
= r16
->right
;
4906 rc
.bottom
= r16
->bottom
;
4907 EDIT_SetRectNP(es
, &rc
);
4912 if ((es
->style
& ES_MULTILINE
) && lParam
)
4913 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4920 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4924 case EM_LINESCROLL16
:
4925 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
4926 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
4930 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4934 case EM_SCROLLCARET16
:
4936 case EM_SCROLLCARET
:
4937 EDIT_EM_ScrollCaret(es
);
4942 case EM_GETMODIFY16
:
4945 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4949 case EM_SETMODIFY16
:
4953 es
->flags
|= EF_MODIFIED
;
4955 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4959 case EM_GETLINECOUNT16
:
4961 case EM_GETLINECOUNT
:
4962 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4966 case EM_LINEINDEX16
:
4967 if ((INT16
)wParam
== -1)
4968 wParam
= (WPARAM
)-1;
4972 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4976 case EM_SETHANDLE16
:
4977 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
4981 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4985 case EM_GETHANDLE16
:
4986 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
4990 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4997 result
= EDIT_EM_GetThumb(es
);
5000 /* these messages missing from specs */
5009 FIXME("undocumented message 0x%x, please report\n", msg
);
5010 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5014 case EM_LINELENGTH16
:
5017 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
5021 case EM_REPLACESEL16
:
5022 lParam
= (LPARAM
)MapSL(lParam
);
5023 unicode
= FALSE
; /* 16-bit message is always ascii */
5031 textW
= (LPWSTR
)lParam
;
5034 LPSTR textA
= (LPSTR
)lParam
;
5035 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5036 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5037 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5040 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
5044 HeapFree(GetProcessHeap(), 0, textW
);
5050 lParam
= (LPARAM
)MapSL(lParam
);
5051 unicode
= FALSE
; /* 16-bit message is always ascii */
5055 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5059 case EM_LIMITTEXT16
:
5061 case EM_SETLIMITTEXT
:
5062 EDIT_EM_SetLimitText(es
, wParam
);
5069 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
5077 result
= (LRESULT
)EDIT_EM_Undo(es
);
5084 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
5088 case EM_LINEFROMCHAR16
:
5090 case EM_LINEFROMCHAR
:
5091 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
5095 case EM_SETTABSTOPS16
:
5096 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
5099 case EM_SETTABSTOPS
:
5100 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
5104 case EM_SETPASSWORDCHAR16
:
5105 unicode
= FALSE
; /* 16-bit message is always ascii */
5108 case EM_SETPASSWORDCHAR
:
5113 charW
= (WCHAR
)wParam
;
5116 CHAR charA
= wParam
;
5117 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5120 EDIT_EM_SetPasswordChar(es
, charW
);
5125 case EM_EMPTYUNDOBUFFER16
:
5127 case EM_EMPTYUNDOBUFFER
:
5128 EDIT_EM_EmptyUndoBuffer(es
);
5132 case EM_GETFIRSTVISIBLELINE16
:
5133 result
= es
->y_offset
;
5136 case EM_GETFIRSTVISIBLELINE
:
5137 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
5141 case EM_SETREADONLY16
:
5143 case EM_SETREADONLY
:
5145 SetWindowLongPtrW( hwnd
, GWL_STYLE
,
5146 GetWindowLongPtrW( hwnd
, GWL_STYLE
) | ES_READONLY
);
5147 es
->style
|= ES_READONLY
;
5149 SetWindowLongPtrW( hwnd
, GWL_STYLE
,
5150 GetWindowLongPtrW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
5151 es
->style
&= ~ES_READONLY
;
5157 case EM_SETWORDBREAKPROC16
:
5158 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
5161 case EM_SETWORDBREAKPROC
:
5162 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
5166 case EM_GETWORDBREAKPROC16
:
5167 result
= (LRESULT
)es
->word_break_proc16
;
5170 case EM_GETWORDBREAKPROC
:
5171 result
= (LRESULT
)es
->word_break_proc
;
5175 case EM_GETPASSWORDCHAR16
:
5176 unicode
= FALSE
; /* 16-bit message is always ascii */
5179 case EM_GETPASSWORDCHAR
:
5182 result
= es
->password_char
;
5185 WCHAR charW
= es
->password_char
;
5187 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
5193 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
5196 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
5200 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
5203 case EM_GETLIMITTEXT
:
5204 result
= es
->buffer_limit
;
5207 case EM_POSFROMCHAR
:
5208 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
5209 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
5212 case EM_CHARFROMPOS
:
5213 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5216 /* End of the EM_ messages which were in numerical order; what order
5217 * are these in? vaguely alphabetical?
5221 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
5225 result
= EDIT_WM_Destroy(es
);
5230 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
5232 if (es
->style
& ES_MULTILINE
)
5233 result
|= DLGC_WANTALLKEYS
;
5235 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
5237 int vk
= (int)((LPMSG
)lParam
)->wParam
;
5239 if (es
->hwndListBox
)
5241 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
5242 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5243 result
|= DLGC_WANTMESSAGE
;
5250 SendMessageW(GetParent(hwnd
), WM_CLOSE
, 0, 0);
5265 strng
[0] = wParam
>> 8;
5266 strng
[1] = wParam
& 0xff;
5267 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
5268 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
5269 result
= EDIT_WM_Char(es
, charW
);
5281 CHAR charA
= wParam
;
5282 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5285 if (es
->hwndListBox
)
5287 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
5289 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5290 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
5294 result
= EDIT_WM_Char(es
, charW
);
5301 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
5302 if (wParam
<= 0x000fffff)
5304 if(wParam
> 0xffff) /* convert to surrogates */
5307 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
5308 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
5310 else EDIT_WM_Char(es
, wParam
);
5321 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
5324 case WM_CONTEXTMENU
:
5325 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5334 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
5337 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
5338 LPWSTR nameW
= NULL
;
5341 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
5342 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5343 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
5345 result
= EDIT_WM_Create(es
, nameW
);
5346 HeapFree(GetProcessHeap(), 0, nameW
);
5355 es
->bEnableState
= (BOOL
) wParam
;
5356 EDIT_UpdateText(es
, NULL
, TRUE
);
5360 /* we do the proper erase in EDIT_WM_Paint */
5365 result
= (LRESULT
)es
->font
;
5369 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5372 case WM_GETTEXTLENGTH
:
5373 if (unicode
) result
= get_text_length(es
);
5374 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
5375 NULL
, 0, NULL
, NULL
);
5379 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5383 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
5387 result
= EDIT_WM_KillFocus(es
);
5390 case WM_LBUTTONDBLCLK
:
5391 result
= EDIT_WM_LButtonDblClk(es
);
5394 case WM_LBUTTONDOWN
:
5395 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5399 result
= EDIT_WM_LButtonUp(es
);
5402 case WM_MBUTTONDOWN
:
5403 result
= EDIT_WM_MButtonDown(es
);
5407 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5410 case WM_PRINTCLIENT
:
5412 EDIT_WM_Paint(es
, (HDC
)wParam
);
5420 EDIT_WM_SetFocus(es
);
5424 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
5428 /* FIXME: actually set an internal flag and behave accordingly */
5432 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
5437 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
5440 case WM_STYLECHANGED
:
5441 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
5444 case WM_STYLECHANGING
:
5445 result
= 0; /* See EDIT_WM_StyleChanged */
5449 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5457 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5462 int gcWheelDelta
= 0;
5463 UINT pulScrollLines
= 3;
5464 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5466 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
5467 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5470 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
5471 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
5473 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
5474 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
5475 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
5481 /* IME messages to make the edit control IME aware */
5482 case WM_IME_SETCONTEXT
:
5485 case WM_IME_STARTCOMPOSITION
:
5486 es
->composition_start
= es
->selection_end
;
5487 es
->composition_len
= 0;
5490 case WM_IME_COMPOSITION
:
5491 EDIT_ImeComposition(hwnd
, lParam
, es
);
5494 case WM_IME_ENDCOMPOSITION
:
5495 if (es
->composition_len
> 0)
5497 static const WCHAR empty_stringW
[] = {0};
5498 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5499 es
->selection_end
= es
->selection_start
;
5500 es
->composition_len
= 0;
5504 case WM_IME_COMPOSITIONFULL
:
5510 case WM_IME_CONTROL
:
5514 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5518 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
5520 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5525 /*********************************************************************
5527 * EditWndProc (USER32.@)
5529 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5531 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
5534 /*********************************************************************
5536 * EditWndProcW (USER32.@)
5538 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5540 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
5543 /*********************************************************************
5544 * edit class descriptor
5546 static const WCHAR editW
[] = {'E','d','i','t',0};
5547 const struct builtin_class_descr EDIT_builtin_class
=
5550 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5551 EditWndProcA
, /* procA */
5552 EditWndProcW
, /* procW */
5553 sizeof(EDITSTATE
*), /* extra */
5554 IDC_IBEAM
, /* cursor */