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
57 #include "wine/winbase16.h"
58 #include "wine/winuser16.h"
59 #include "wine/unicode.h"
61 #include "user_private.h"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
65 WINE_DECLARE_DEBUG_CHANNEL(combo
);
66 WINE_DECLARE_DEBUG_CHANNEL(relay
);
68 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
69 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
70 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
71 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
74 * extra flags for EDITSTATE.flags field
76 #define EF_MODIFIED 0x0001 /* text has been modified */
77 #define EF_FOCUSED 0x0002 /* we have input focus */
78 #define EF_UPDATE 0x0004 /* notify parent of changed state */
79 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
80 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
81 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
82 wrapped line, instead of in front of the next character */
83 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
84 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
85 the text buffer if this is clear. */
86 #define EF_DIALOGMODE 0x0400 /* Indicates that we are inside a dialog window */
90 END_0
= 0, /* line ends with terminating '\0' character */
91 END_WRAP
, /* line is wrapped */
92 END_HARD
, /* line ends with a hard return '\r\n' */
93 END_SOFT
, /* line ends with a soft return '\r\r\n' */
94 END_RICH
/* line ends with a single '\n' */
97 typedef struct tagLINEDEF
{
98 INT length
; /* bruto length of a line in bytes */
99 INT net_length
; /* netto length of a line in visible characters */
101 INT width
; /* width of the line in pixels */
102 INT index
; /* line index into the buffer */
103 struct tagLINEDEF
*next
;
108 BOOL is_unicode
; /* how the control was created */
109 LPWSTR text
; /* the actual contents of the control */
110 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
111 UINT buffer_size
; /* the size of the buffer in characters */
112 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
113 HFONT font
; /* NULL means standard system font */
114 INT x_offset
; /* scroll offset for multi lines this is in pixels
115 for single lines it's in characters */
116 INT line_height
; /* height of a screen line in pixels */
117 INT char_width
; /* average character width in pixels */
118 DWORD style
; /* sane version of wnd->dwStyle */
119 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
120 INT undo_insert_count
; /* number of characters inserted in sequence */
121 UINT undo_position
; /* character index of the insertion and deletion */
122 LPWSTR undo_text
; /* deleted text */
123 UINT undo_buffer_size
; /* size of the deleted text buffer */
124 INT selection_start
; /* == selection_end if no selection */
125 INT selection_end
; /* == current caret position */
126 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
127 INT left_margin
; /* in pixels */
128 INT right_margin
; /* in pixels */
130 INT text_width
; /* width of the widest line in pixels for multi line controls
131 and just line width for single line controls */
132 INT region_posx
; /* Position of cursor relative to region: */
133 INT region_posy
; /* -1: to left, 0: within, 1: to right */
134 EDITWORDBREAKPROC16 word_break_proc16
;
135 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
136 INT line_count
; /* number of lines */
137 INT y_offset
; /* scroll offset in number of lines */
138 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
139 BOOL bEnableState
; /* flag keeping the enable state */
140 HWND hwndSelf
; /* the our window handle */
141 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
142 Even if parent will change, EN_* messages
143 should be sent to the first parent. */
144 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
146 * only for multi line controls
148 INT lock_count
; /* amount of re-entries in the EditWndProc */
151 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
152 HLOCAL hloc32W
; /* our unicode local memory block */
153 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
155 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
160 UINT composition_len
; /* length of composition, 0 == no composition */
161 int composition_start
; /* the character position for the composition */
165 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
166 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
168 /* used for disabled or read-only edit control */
169 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
171 { /* Notify parent which has created this edit control */ \
172 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
173 SendMessageW(es->hwndParent, WM_COMMAND, \
174 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
175 (LPARAM)(es->hwndSelf)); \
179 /*********************************************************************
184 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
186 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
190 /*********************************************************************
195 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
197 es
->undo_insert_count
= 0;
198 *es
->undo_text
= '\0';
202 /**********************************************************************
205 * Returns the window version in case Wine emulates a later version
206 * of windows than the application expects.
208 * In a number of cases when windows runs an application that was
209 * designed for an earlier windows version, windows reverts
210 * to "old" behaviour of that earlier version.
212 * An example is a disabled edit control that needs to be painted.
213 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
214 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
215 * applications with an expected version 0f 4.0 or higher.
218 static DWORD
get_app_version(void)
220 static DWORD version
;
223 DWORD dwEmulatedVersion
;
225 DWORD dwProcVersion
= GetProcessVersion(0);
227 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
228 GetVersionExW( &info
);
229 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
230 /* FIXME: this may not be 100% correct; see discussion on the
231 * wine developer list in Nov 1999 */
232 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
237 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
242 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
243 msg
= WM_CTLCOLORSTATIC
;
245 msg
= WM_CTLCOLOREDIT
;
247 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
248 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
250 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
255 /*********************************************************************
259 * Find the beginning of words.
260 * Note: unlike the specs for a WordBreakProc, this function only
261 * allows to be called without linebreaks between s[0] up to
262 * s[count - 1]. Remember it is only called
263 * internally, so we can decide this for ourselves.
266 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
270 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
280 if (s
[index
] == ' ') {
281 while (index
&& (s
[index
] == ' '))
284 while (index
&& (s
[index
] != ' '))
290 while (index
&& (s
[index
] != ' '))
303 while ((index
< count
) && (s
[index
] == ' ')) index
++;
305 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
307 while ((s
[index
] == ' ') && (index
< count
)) index
++;
312 ret
= (s
[index
] == ' ');
315 ERR("unknown action code, please report !\n");
322 /*********************************************************************
324 * EDIT_CallWordBreakProc
326 * Call appropriate WordBreakProc (internal or external).
328 * Note: The "start" argument should always be an index referring
329 * to es->text. The actual wordbreak proc might be
330 * 16 bit, so we can't always pass any 32 bit LPSTR.
331 * Hence we assume that es->text is the buffer that holds
332 * the string under examination (we can decide this for ourselves).
335 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
339 if (es
->word_break_proc16
) {
346 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
347 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
348 segptr
= WOWGlobalLock16(hglob16
);
349 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
350 args
[4] = SELECTOROF(segptr
);
351 args
[3] = OFFSETOF(segptr
);
355 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
356 ret
= LOWORD(result
);
357 GlobalUnlock16(hglob16
);
358 GlobalFree16(hglob16
);
360 else if (es
->word_break_proc
)
364 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
366 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
367 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
368 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
372 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
376 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
377 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
378 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
379 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
380 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
381 ret
= wbpA(textA
, index
, countA
, action
);
382 HeapFree(GetProcessHeap(), 0, textA
);
386 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
391 /*********************************************************************
393 * EDIT_BuildLineDefs_ML
395 * Build linked list of text lines.
396 * Lines can end with '\0' (last line), a character (if it is wrapped),
397 * a soft return '\r\r\n' or a hard return '\r\n'
400 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
404 LPWSTR current_position
, cp
;
406 LINEDEF
*current_line
;
407 LINEDEF
*previous_line
;
409 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
410 INT line_count
= es
->line_count
;
414 if (istart
== iend
&& delta
== 0)
417 dc
= GetDC(es
->hwndSelf
);
419 old_font
= SelectObject(dc
, es
->font
);
421 previous_line
= NULL
;
422 current_line
= es
->first_line_def
;
424 /* Find starting line. istart must lie inside an existing line or
425 * at the end of buffer */
427 if (istart
< current_line
->index
+ current_line
->length
||
428 current_line
->ending
== END_0
)
431 previous_line
= current_line
;
432 current_line
= current_line
->next
;
434 } while (current_line
);
436 if (!current_line
) /* Error occurred start is not inside previous buffer */
438 FIXME(" modification occurred outside buffer\n");
439 ReleaseDC(es
->hwndSelf
, dc
);
443 /* Remember start of modifications in order to calculate update region */
444 nstart_line
= line_index
;
445 nstart_index
= current_line
->index
;
447 /* We must start to reformat from the previous line since the modifications
448 * may have caused the line to wrap upwards. */
449 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
452 current_line
= previous_line
;
454 start_line
= current_line
;
456 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
457 current_position
= es
->text
+ current_line
->index
;
459 if (current_line
!= start_line
)
461 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
463 /* The buffer has been expanded, create a new line and
464 insert it into the link list */
465 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
466 new_line
->next
= previous_line
->next
;
467 previous_line
->next
= new_line
;
468 current_line
= new_line
;
471 else if (current_line
->index
+ delta
< current_position
- es
->text
)
473 /* The previous line merged with this line so we delete this extra entry */
474 previous_line
->next
= current_line
->next
;
475 HeapFree(GetProcessHeap(), 0, current_line
);
476 current_line
= previous_line
->next
;
480 else /* current_line->index + delta == current_position */
482 if (current_position
- es
->text
> iend
)
483 break; /* We reached end of line modifications */
484 /* else recalculate this line */
488 current_line
->index
= current_position
- es
->text
;
489 orig_net_length
= current_line
->net_length
;
491 /* Find end of line */
492 cp
= current_position
;
494 if (*cp
== '\n') break;
495 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
500 /* Mark type of line termination */
502 current_line
->ending
= END_0
;
503 current_line
->net_length
= strlenW(current_position
);
504 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
505 current_line
->ending
= END_SOFT
;
506 current_line
->net_length
= cp
- current_position
- 1;
507 } else if (*cp
== '\n') {
508 current_line
->ending
= END_RICH
;
509 current_line
->net_length
= cp
- current_position
;
511 current_line
->ending
= END_HARD
;
512 current_line
->net_length
= cp
- current_position
;
515 /* Calculate line width */
516 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
517 current_position
, current_line
->net_length
,
518 es
->tabs_count
, es
->tabs
));
520 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
521 if (!(es
->style
& ES_AUTOHSCROLL
)) {
522 if (current_line
->width
> fw
) {
527 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
528 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
529 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
530 current_position
, next
, es
->tabs_count
, es
->tabs
));
531 } while (current_line
->width
<= fw
);
532 if (!prev
) { /* Didn't find a line break so force a break */
537 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
538 current_position
, next
, es
->tabs_count
, es
->tabs
));
539 } while (current_line
->width
<= fw
);
544 /* If the first line we are calculating, wrapped before istart, we must
545 * adjust istart in order for this to be reflected in the update region. */
546 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
547 istart
= current_line
->index
+ prev
;
548 /* else if we are updating the previous line before the first line we
549 * are re-calculating and it expanded */
550 else if (current_line
== start_line
&&
551 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
553 /* Line expanded due to an upwards line wrap so we must partially include
554 * previous line in update region */
555 nstart_line
= line_index
;
556 nstart_index
= current_line
->index
;
557 istart
= current_line
->index
+ orig_net_length
;
560 current_line
->net_length
= prev
;
561 current_line
->ending
= END_WRAP
;
562 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
563 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
565 else if (current_line
== start_line
&&
566 current_line
->index
!= nstart_index
&&
567 orig_net_length
< current_line
->net_length
) {
568 /* The previous line expanded but it's still not as wide as the client rect */
569 /* The expansion is due to an upwards line wrap so we must partially include
570 it in the update region */
571 nstart_line
= line_index
;
572 nstart_index
= current_line
->index
;
573 istart
= current_line
->index
+ orig_net_length
;
578 /* Adjust length to include line termination */
579 switch (current_line
->ending
) {
581 current_line
->length
= current_line
->net_length
+ 3;
584 current_line
->length
= current_line
->net_length
+ 1;
587 current_line
->length
= current_line
->net_length
+ 2;
591 current_line
->length
= current_line
->net_length
;
594 es
->text_width
= max(es
->text_width
, current_line
->width
);
595 current_position
+= current_line
->length
;
596 previous_line
= current_line
;
597 current_line
= current_line
->next
;
599 } while (previous_line
->ending
!= END_0
);
601 /* Finish adjusting line indexes by delta or remove hanging lines */
602 if (previous_line
->ending
== END_0
)
604 LINEDEF
*pnext
= NULL
;
606 previous_line
->next
= NULL
;
609 pnext
= current_line
->next
;
610 HeapFree(GetProcessHeap(), 0, current_line
);
611 current_line
= pnext
;
619 current_line
->index
+= delta
;
620 current_line
= current_line
->next
;
624 /* Calculate rest of modification rectangle */
629 * We calculate two rectangles. One for the first line which may have
630 * an indent with respect to the format rect. The other is a format-width
631 * rectangle that spans the rest of the lines that changed or moved.
633 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
634 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
635 rc
.bottom
= rc
.top
+ es
->line_height
;
636 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
637 rc
.left
= es
->format_rect
.left
;
639 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
640 es
->text
+ nstart_index
, istart
- nstart_index
,
641 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
642 rc
.right
= es
->format_rect
.right
;
643 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
646 rc
.left
= es
->format_rect
.left
;
647 rc
.right
= es
->format_rect
.right
;
649 * If lines were added or removed we must re-paint the remainder of the
650 * lines since the remaining lines were either shifted up or down.
652 if (line_count
< es
->line_count
) /* We added lines */
653 rc
.bottom
= es
->line_count
* es
->line_height
;
654 else if (line_count
> es
->line_count
) /* We removed lines */
655 rc
.bottom
= line_count
* es
->line_height
;
657 rc
.bottom
= line_index
* es
->line_height
;
658 rc
.bottom
+= es
->format_rect
.top
;
659 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
660 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
661 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
662 DeleteObject(tmphrgn
);
666 SelectObject(dc
, old_font
);
668 ReleaseDC(es
->hwndSelf
, dc
);
672 static inline UINT
get_text_length(EDITSTATE
*es
)
674 if(es
->text_length
== (UINT
)-1)
675 es
->text_length
= strlenW(es
->text
);
676 return es
->text_length
;
679 /*********************************************************************
681 * EDIT_GetPasswordPointer_SL
683 * note: caller should free the (optionally) allocated buffer
686 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
688 if (es
->style
& ES_PASSWORD
) {
689 INT len
= get_text_length(es
);
690 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
692 while(len
) text
[--len
] = es
->password_char
;
699 /*********************************************************************
701 * EDIT_CalcLineWidth_SL
704 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
711 text
= EDIT_GetPasswordPointer_SL(es
);
713 dc
= GetDC(es
->hwndSelf
);
715 old_font
= SelectObject(dc
, es
->font
);
717 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
720 SelectObject(dc
, old_font
);
721 ReleaseDC(es
->hwndSelf
, dc
);
723 if (es
->style
& ES_PASSWORD
)
724 HeapFree(GetProcessHeap(), 0, text
);
726 es
->text_width
= size
.cx
;
729 /*********************************************************************
733 * Beware: This is not the function called on EM_CHARFROMPOS
734 * The position _can_ be outside the formatting / client
736 * The return value is only the character index
739 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
744 INT x_high
= 0, x_low
= 0;
746 if (es
->style
& ES_MULTILINE
) {
747 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
749 LINEDEF
*line_def
= es
->first_line_def
;
751 while ((line
> 0) && line_def
->next
) {
752 line_index
+= line_def
->length
;
753 line_def
= line_def
->next
;
756 x
+= es
->x_offset
- es
->format_rect
.left
;
757 if (es
->style
& ES_RIGHT
)
758 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
759 else if (es
->style
& ES_CENTER
)
760 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
761 if (x
>= line_def
->width
) {
763 *after_wrap
= (line_def
->ending
== END_WRAP
);
764 return line_index
+ line_def
->net_length
;
771 dc
= GetDC(es
->hwndSelf
);
773 old_font
= SelectObject(dc
, es
->font
);
775 high
= line_index
+ line_def
->net_length
+ 1;
776 while (low
< high
- 1)
778 INT mid
= (low
+ high
) / 2;
779 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
788 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
794 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
795 (line_def
->ending
== END_WRAP
));
801 x
-= es
->format_rect
.left
;
807 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
808 if (es
->style
& ES_RIGHT
)
810 else if (es
->style
& ES_CENTER
)
814 text
= EDIT_GetPasswordPointer_SL(es
);
815 dc
= GetDC(es
->hwndSelf
);
817 old_font
= SelectObject(dc
, es
->font
);
821 INT high
= es
->x_offset
;
822 while (low
< high
- 1)
824 INT mid
= (low
+ high
) / 2;
825 GetTextExtentPoint32W( dc
, text
+ mid
,
826 es
->x_offset
- mid
, &size
);
835 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
842 INT low
= es
->x_offset
;
843 INT high
= get_text_length(es
) + 1;
844 while (low
< high
- 1)
846 INT mid
= (low
+ high
) / 2;
847 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
848 mid
- es
->x_offset
, &size
);
857 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
862 if (es
->style
& ES_PASSWORD
)
863 HeapFree(GetProcessHeap(), 0, text
);
866 SelectObject(dc
, old_font
);
867 ReleaseDC(es
->hwndSelf
, dc
);
872 /*********************************************************************
876 * adjusts the point to be within the formatting rectangle
877 * (so CharFromPos returns the nearest _visible_ character)
880 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
882 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
883 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
887 /*********************************************************************
892 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
897 if (!(es
->style
& ES_MULTILINE
))
899 if (index
> (INT
)get_text_length(es
))
900 return es
->line_count
- 1;
902 index
= min(es
->selection_start
, es
->selection_end
);
905 line_def
= es
->first_line_def
;
906 index
-= line_def
->length
;
907 while ((index
>= 0) && line_def
->next
) {
909 line_def
= line_def
->next
;
910 index
-= line_def
->length
;
916 /*********************************************************************
921 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
924 const LINEDEF
*line_def
;
926 if (!(es
->style
& ES_MULTILINE
))
928 if (line
>= es
->line_count
)
932 line_def
= es
->first_line_def
;
934 INT index
= es
->selection_end
- line_def
->length
;
935 while ((index
>= 0) && line_def
->next
) {
936 line_index
+= line_def
->length
;
937 line_def
= line_def
->next
;
938 index
-= line_def
->length
;
942 line_index
+= line_def
->length
;
943 line_def
= line_def
->next
;
951 /*********************************************************************
956 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
960 if (!(es
->style
& ES_MULTILINE
))
961 return get_text_length(es
);
964 /* get the number of remaining non-selected chars of selected lines */
965 INT32 l
; /* line number */
966 INT32 li
; /* index of first char in line */
968 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
969 /* # chars before start of selection area */
970 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
971 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
972 /* # chars after end of selection */
973 li
= EDIT_EM_LineIndex(es
, l
);
974 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
977 line_def
= es
->first_line_def
;
978 index
-= line_def
->length
;
979 while ((index
>= 0) && line_def
->next
) {
980 line_def
= line_def
->next
;
981 index
-= line_def
->length
;
983 return line_def
->net_length
;
987 /*********************************************************************
992 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
994 INT len
= get_text_length(es
);
1007 index
= min(index
, len
);
1008 dc
= GetDC(es
->hwndSelf
);
1010 old_font
= SelectObject(dc
, es
->font
);
1011 if (es
->style
& ES_MULTILINE
) {
1012 l
= EDIT_EM_LineFromChar(es
, index
);
1013 y
= (l
- es
->y_offset
) * es
->line_height
;
1014 li
= EDIT_EM_LineIndex(es
, l
);
1015 if (after_wrap
&& (li
== index
) && l
) {
1017 line_def
= es
->first_line_def
;
1019 line_def
= line_def
->next
;
1022 if (line_def
->ending
== END_WRAP
) {
1024 y
-= es
->line_height
;
1025 li
= EDIT_EM_LineIndex(es
, l
);
1029 line_def
= es
->first_line_def
;
1030 while (line_def
->index
!= li
)
1031 line_def
= line_def
->next
;
1033 ll
= line_def
->net_length
;
1034 lw
= line_def
->width
;
1036 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1037 if (es
->style
& ES_RIGHT
)
1039 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
1040 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1043 else if (es
->style
& ES_CENTER
)
1045 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1046 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1051 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1052 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1055 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
1056 if (index
< es
->x_offset
) {
1057 GetTextExtentPoint32W(dc
, text
+ index
,
1058 es
->x_offset
- index
, &size
);
1061 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
1062 index
- es
->x_offset
, &size
);
1065 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1067 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1068 if (w
> es
->text_width
)
1070 if (es
->style
& ES_RIGHT
)
1071 x
+= w
- es
->text_width
;
1072 else if (es
->style
& ES_CENTER
)
1073 x
+= (w
- es
->text_width
) / 2;
1078 if (es
->style
& ES_PASSWORD
)
1079 HeapFree(GetProcessHeap(), 0, text
);
1081 x
+= es
->format_rect
.left
;
1082 y
+= es
->format_rect
.top
;
1084 SelectObject(dc
, old_font
);
1085 ReleaseDC(es
->hwndSelf
, dc
);
1086 return MAKELONG((INT16
)x
, (INT16
)y
);
1090 /*********************************************************************
1094 * Calculates the bounding rectangle for a line from a starting
1095 * column to an ending column.
1098 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1100 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1102 if (es
->style
& ES_MULTILINE
)
1103 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1105 rc
->top
= es
->format_rect
.top
;
1106 rc
->bottom
= rc
->top
+ es
->line_height
;
1107 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1108 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1112 static inline void text_buffer_changed(EDITSTATE
*es
)
1114 es
->text_length
= (UINT
)-1;
1117 /*********************************************************************
1121 * This acts as a LocalLock16(), but it locks only once. This way
1122 * you can call it whenever you like, without unlocking.
1124 * Initially the edit control allocates a HLOCAL32 buffer
1125 * (32 bit linear memory handler). However, 16 bit application
1126 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1127 * handler). From that moment on we have to keep using this 16 bit memory
1128 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1129 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1133 static void EDIT_LockBuffer(EDITSTATE
*es
)
1135 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1136 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1141 BOOL _16bit
= FALSE
;
1147 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1148 textA
= LocalLock(es
->hloc32A
);
1149 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;
1163 ERR("no buffer ... please report\n");
1170 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1171 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1172 if(countW_new
> es
->buffer_size
+ 1)
1174 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1175 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1176 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1179 es
->hloc32W
= hloc32W_new
;
1180 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1181 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1184 WARN("FAILED! Will synchronize partially\n");
1188 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1189 es
->text
= LocalLock(es
->hloc32W
);
1193 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1196 HANDLE16 oldDS
= stack16
->ds
;
1197 stack16
->ds
= hInstance
;
1198 LocalUnlock16(es
->hloc16
);
1199 stack16
->ds
= oldDS
;
1202 LocalUnlock(es
->hloc32A
);
1205 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1210 /*********************************************************************
1215 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1218 /* Edit window might be already destroyed */
1219 if(!IsWindow(es
->hwndSelf
))
1221 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1225 if (!es
->lock_count
) {
1226 ERR("lock_count == 0 ... please report\n");
1230 ERR("es->text == 0 ... please report\n");
1234 if (force
|| (es
->lock_count
== 1)) {
1238 UINT countW
= get_text_length(es
) + 1;
1239 STACK16FRAME
* stack16
= NULL
;
1244 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1245 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1246 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1247 countA
= LocalSize(es
->hloc32A
);
1248 if(countA_new
> countA
)
1251 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1252 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1253 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1256 es
->hloc32A
= hloc32A_new
;
1257 countA
= LocalSize(hloc32A_new
);
1258 TRACE("Real new size %d bytes\n", countA
);
1261 WARN("FAILED! Will synchronize partially\n");
1263 textA
= LocalLock(es
->hloc32A
);
1267 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1269 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1270 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1272 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1273 oldDS
= stack16
->ds
;
1274 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1276 countA
= LocalSize16(es
->hloc16
);
1277 if(countA_new
> countA
)
1279 HLOCAL16 hloc16_new
;
1280 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1281 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1282 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1285 es
->hloc16
= hloc16_new
;
1286 countA
= LocalSize16(hloc16_new
);
1287 TRACE("Real new size %d bytes\n", countA
);
1290 WARN("FAILED! Will synchronize partially\n");
1292 textA
= MapSL(LocalLock16(es
->hloc16
));
1297 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
1299 LocalUnlock16(es
->hloc16
);
1301 LocalUnlock(es
->hloc32A
);
1304 if (stack16
) stack16
->ds
= oldDS
;
1305 LocalUnlock(es
->hloc32W
);
1309 ERR("no buffer ... please report\n");
1317 /*********************************************************************
1321 * Try to fit size + 1 characters in the buffer.
1323 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1327 if (size
<= es
->buffer_size
)
1330 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1332 /* Force edit to unlock it's buffer. es->text now NULL */
1333 EDIT_UnlockBuffer(es
, TRUE
);
1336 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1337 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1338 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1339 es
->hloc32W
= hNew32W
;
1340 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1344 EDIT_LockBuffer(es
);
1346 if (es
->buffer_size
< size
) {
1347 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1348 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1351 TRACE("We now have %d+1\n", es
->buffer_size
);
1357 /*********************************************************************
1361 * Try to fit size + 1 bytes in the undo buffer.
1364 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1368 if (size
<= es
->undo_buffer_size
)
1371 TRACE("trying to ReAlloc to %d+1\n", size
);
1373 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1374 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1375 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1380 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1386 /*********************************************************************
1388 * EDIT_UpdateTextRegion
1391 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1393 if (es
->flags
& EF_UPDATE
) {
1394 es
->flags
&= ~EF_UPDATE
;
1395 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1397 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1401 /*********************************************************************
1406 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1408 if (es
->flags
& EF_UPDATE
) {
1409 es
->flags
&= ~EF_UPDATE
;
1410 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1412 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1415 /*********************************************************************
1417 * EDIT_SL_InvalidateText
1419 * Called from EDIT_InvalidateText().
1420 * Does the job for single-line controls only.
1423 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1428 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1429 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1430 EDIT_UpdateText(es
, &rc
, TRUE
);
1434 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
1436 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1440 /*********************************************************************
1442 * EDIT_ML_InvalidateText
1444 * Called from EDIT_InvalidateText().
1445 * Does the job for multi-line controls only.
1448 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1450 INT vlc
= get_vertical_line_count(es
);
1451 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1452 INT el
= EDIT_EM_LineFromChar(es
, end
);
1461 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1464 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1465 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1466 if (sl
< es
->y_offset
) {
1470 if (el
> es
->y_offset
+ vlc
) {
1471 el
= es
->y_offset
+ vlc
;
1472 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1474 GetClientRect(es
->hwndSelf
, &rc1
);
1475 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1477 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1478 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1479 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1481 EDIT_GetLineRect(es
, sl
, sc
,
1482 EDIT_EM_LineLength(es
,
1483 EDIT_EM_LineIndex(es
, sl
)),
1485 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1486 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1487 for (l
= sl
+ 1 ; l
< el
; l
++) {
1488 EDIT_GetLineRect(es
, l
, 0,
1489 EDIT_EM_LineLength(es
,
1490 EDIT_EM_LineIndex(es
, l
)),
1492 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1493 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1495 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1496 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1497 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1502 /*********************************************************************
1504 * EDIT_InvalidateText
1506 * Invalidate the text from offset start up to, but not including,
1507 * offset end. Useful for (re)painting the selection.
1508 * Regions outside the linewidth are not invalidated.
1509 * end == -1 means end == TextLength.
1510 * start and end need not be ordered.
1513 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1519 end
= get_text_length(es
);
1527 if (es
->style
& ES_MULTILINE
)
1528 EDIT_ML_InvalidateText(es
, start
, end
);
1530 EDIT_SL_InvalidateText(es
, start
, end
);
1534 /*********************************************************************
1538 * note: unlike the specs say: the order of start and end
1539 * _is_ preserved in Windows. (i.e. start can be > end)
1540 * In other words: this handler is OK
1543 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1545 UINT old_start
= es
->selection_start
;
1546 UINT old_end
= es
->selection_end
;
1547 UINT len
= get_text_length(es
);
1549 if (start
== (UINT
)-1) {
1550 start
= es
->selection_end
;
1551 end
= es
->selection_end
;
1553 start
= min(start
, len
);
1554 end
= min(end
, len
);
1556 es
->selection_start
= start
;
1557 es
->selection_end
= end
;
1559 es
->flags
|= EF_AFTER_WRAP
;
1561 es
->flags
&= ~EF_AFTER_WRAP
;
1562 /* Compute the necessary invalidation region. */
1563 /* Note that we don't need to invalidate regions which have
1564 * "never" been selected, or those which are "still" selected.
1565 * In fact, every time we hit a selection boundary, we can
1566 * *toggle* whether we need to invalidate. Thus we can optimize by
1567 * *sorting* the interval endpoints. Let's assume that we sort them
1569 * start <= end <= old_start <= old_end
1570 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1571 * in 5 comparisons; i.e. it is impossible to do better than the
1573 ORDER_UINT(end
, old_end
);
1574 ORDER_UINT(start
, old_start
);
1575 ORDER_UINT(old_start
, old_end
);
1576 ORDER_UINT(start
, end
);
1577 /* Note that at this point 'end' and 'old_start' are not in order, but
1578 * start is definitely the min. and old_end is definitely the max. */
1579 if (end
!= old_start
)
1583 * ORDER_UINT32(end, old_start);
1584 * EDIT_InvalidateText(es, start, end);
1585 * EDIT_InvalidateText(es, old_start, old_end);
1586 * in place of the following if statement.
1587 * (That would complete the optimal five-comparison four-element sort.)
1589 if (old_start
> end
)
1591 EDIT_InvalidateText(es
, start
, end
);
1592 EDIT_InvalidateText(es
, old_start
, old_end
);
1596 EDIT_InvalidateText(es
, start
, old_start
);
1597 EDIT_InvalidateText(es
, end
, old_end
);
1600 else EDIT_InvalidateText(es
, start
, old_end
);
1604 /*********************************************************************
1606 * EDIT_UpdateScrollInfo
1609 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1611 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1614 si
.cbSize
= sizeof(SCROLLINFO
);
1615 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1617 si
.nMax
= es
->line_count
- 1;
1618 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1619 si
.nPos
= es
->y_offset
;
1620 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1621 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1622 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1625 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1628 si
.cbSize
= sizeof(SCROLLINFO
);
1629 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1631 si
.nMax
= es
->text_width
- 1;
1632 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1633 si
.nPos
= es
->x_offset
;
1634 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1635 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1636 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1641 /*********************************************************************
1643 * EDIT_EM_LineScroll_internal
1645 * Version of EDIT_EM_LineScroll for internal use.
1646 * It doesn't refuse if ES_MULTILINE is set and assumes that
1647 * dx is in pixels, dy - in lines.
1650 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1653 INT x_offset_in_pixels
;
1654 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1657 if (es
->style
& ES_MULTILINE
)
1659 x_offset_in_pixels
= es
->x_offset
;
1664 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1667 if (-dx
> x_offset_in_pixels
)
1668 dx
= -x_offset_in_pixels
;
1669 if (dx
> es
->text_width
- x_offset_in_pixels
)
1670 dx
= es
->text_width
- x_offset_in_pixels
;
1671 nyoff
= max(0, es
->y_offset
+ dy
);
1672 if (nyoff
>= es
->line_count
- lines_per_page
)
1673 nyoff
= max(0, es
->line_count
- lines_per_page
);
1674 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1679 es
->y_offset
= nyoff
;
1680 if(es
->style
& ES_MULTILINE
)
1683 es
->x_offset
+= dx
/ es
->char_width
;
1685 GetClientRect(es
->hwndSelf
, &rc1
);
1686 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1687 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1688 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1689 /* force scroll info update */
1690 EDIT_UpdateScrollInfo(es
);
1692 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1693 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1694 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1695 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1699 /*********************************************************************
1703 * NOTE: dx is in average character widths, dy - in lines;
1706 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1708 if (!(es
->style
& ES_MULTILINE
))
1711 dx
*= es
->char_width
;
1712 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1716 /*********************************************************************
1721 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1725 if (!(es
->style
& ES_MULTILINE
))
1726 return (LRESULT
)FALSE
;
1736 if (es
->y_offset
< es
->line_count
- 1)
1741 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1744 if (es
->y_offset
< es
->line_count
- 1)
1745 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1748 return (LRESULT
)FALSE
;
1751 INT vlc
= get_vertical_line_count(es
);
1752 /* check if we are going to move too far */
1753 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1754 dy
= es
->line_count
- vlc
- es
->y_offset
;
1756 /* Notification is done in EDIT_EM_LineScroll */
1758 EDIT_EM_LineScroll(es
, 0, dy
);
1760 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
1764 /*********************************************************************
1769 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1772 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1773 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1774 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1778 /*********************************************************************
1783 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1785 if (es
->style
& ES_MULTILINE
) {
1789 INT cw
= es
->char_width
;
1794 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1795 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1796 vlc
= get_vertical_line_count(es
);
1797 if (l
>= es
->y_offset
+ vlc
)
1798 dy
= l
- vlc
+ 1 - es
->y_offset
;
1799 if (l
< es
->y_offset
)
1800 dy
= l
- es
->y_offset
;
1801 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1802 if (x
< es
->format_rect
.left
)
1803 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1804 if (x
> es
->format_rect
.right
)
1805 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1806 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1808 /* check if we are going to move too far */
1809 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1810 dx
= es
->text_width
- ww
- es
->x_offset
;
1811 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1812 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1819 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1820 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1821 if (x
< es
->format_rect
.left
) {
1822 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1825 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1826 } while ((x
< goal
) && es
->x_offset
);
1827 /* FIXME: use ScrollWindow() somehow to improve performance */
1828 EDIT_UpdateText(es
, NULL
, TRUE
);
1829 } else if (x
> es
->format_rect
.right
) {
1831 INT len
= get_text_length(es
);
1832 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1835 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1836 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1837 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1838 /* FIXME: use ScrollWindow() somehow to improve performance */
1839 EDIT_UpdateText(es
, NULL
, TRUE
);
1843 if(es
->flags
& EF_FOCUSED
)
1844 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1848 /*********************************************************************
1853 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1855 INT e
= es
->selection_end
;
1859 if ((es
->style
& ES_MULTILINE
) && e
&&
1860 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1862 if (e
&& (es
->text
[e
- 1] == '\r'))
1866 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1867 EDIT_EM_ScrollCaret(es
);
1871 /*********************************************************************
1875 * Only for multi line controls
1876 * Move the caret one line down, on a column with the nearest
1877 * x coordinate on the screen (might be a different column).
1880 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1882 INT s
= es
->selection_start
;
1883 INT e
= es
->selection_end
;
1884 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1885 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1886 INT x
= (short)LOWORD(pos
);
1887 INT y
= (short)HIWORD(pos
);
1889 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1892 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1893 EDIT_EM_ScrollCaret(es
);
1897 /*********************************************************************
1902 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1904 BOOL after_wrap
= FALSE
;
1907 /* Pass a high value in x to make sure of receiving the end of the line */
1908 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1909 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1910 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1912 e
= get_text_length(es
);
1913 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1914 EDIT_EM_ScrollCaret(es
);
1918 /*********************************************************************
1923 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1925 INT e
= es
->selection_end
;
1929 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1930 if (es
->text
[e
] == '\n')
1932 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1936 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1937 EDIT_EM_ScrollCaret(es
);
1941 /*********************************************************************
1945 * Home key: move to beginning of line.
1948 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1952 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1953 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1954 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1955 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1958 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1959 EDIT_EM_ScrollCaret(es
);
1963 /*********************************************************************
1965 * EDIT_MovePageDown_ML
1967 * Only for multi line controls
1968 * Move the caret one page down, on a column with the nearest
1969 * x coordinate on the screen (might be a different column).
1972 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1974 INT s
= es
->selection_start
;
1975 INT e
= es
->selection_end
;
1976 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1977 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1978 INT x
= (short)LOWORD(pos
);
1979 INT y
= (short)HIWORD(pos
);
1981 e
= EDIT_CharFromPos(es
, x
,
1982 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1986 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1987 EDIT_EM_ScrollCaret(es
);
1991 /*********************************************************************
1993 * EDIT_MovePageUp_ML
1995 * Only for multi line controls
1996 * Move the caret one page up, on a column with the nearest
1997 * x coordinate on the screen (might be a different column).
2000 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2002 INT s
= es
->selection_start
;
2003 INT e
= es
->selection_end
;
2004 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2005 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2006 INT x
= (short)LOWORD(pos
);
2007 INT y
= (short)HIWORD(pos
);
2009 e
= EDIT_CharFromPos(es
, x
,
2010 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2014 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2015 EDIT_EM_ScrollCaret(es
);
2019 /*********************************************************************
2023 * Only for multi line controls
2024 * Move the caret one line up, on a column with the nearest
2025 * x coordinate on the screen (might be a different column).
2028 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2030 INT s
= es
->selection_start
;
2031 INT e
= es
->selection_end
;
2032 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2033 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2034 INT x
= (short)LOWORD(pos
);
2035 INT y
= (short)HIWORD(pos
);
2037 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2040 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2041 EDIT_EM_ScrollCaret(es
);
2045 /*********************************************************************
2047 * EDIT_MoveWordBackward
2050 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2052 INT s
= es
->selection_start
;
2053 INT e
= es
->selection_end
;
2058 l
= EDIT_EM_LineFromChar(es
, e
);
2059 ll
= EDIT_EM_LineLength(es
, e
);
2060 li
= EDIT_EM_LineIndex(es
, l
);
2063 li
= EDIT_EM_LineIndex(es
, l
- 1);
2064 e
= li
+ EDIT_EM_LineLength(es
, li
);
2067 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2071 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2072 EDIT_EM_ScrollCaret(es
);
2076 /*********************************************************************
2078 * EDIT_MoveWordForward
2081 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2083 INT s
= es
->selection_start
;
2084 INT e
= es
->selection_end
;
2089 l
= EDIT_EM_LineFromChar(es
, e
);
2090 ll
= EDIT_EM_LineLength(es
, e
);
2091 li
= EDIT_EM_LineIndex(es
, l
);
2093 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2094 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2096 e
= li
+ EDIT_CallWordBreakProc(es
,
2097 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2101 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2102 EDIT_EM_ScrollCaret(es
);
2106 /*********************************************************************
2111 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2115 LOGFONTW underline_font
;
2116 HFONT hUnderline
= 0;
2125 BkMode
= GetBkMode(dc
);
2126 BkColor
= GetBkColor(dc
);
2127 TextColor
= GetTextColor(dc
);
2129 if (es
->composition_len
== 0)
2131 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2132 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2133 SetBkMode( dc
, OPAQUE
);
2137 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2138 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2139 underline_font
.lfUnderline
= TRUE
;
2140 hUnderline
= CreateFontIndirectW(&underline_font
);
2141 old_font
= SelectObject(dc
,hUnderline
);
2144 li
= EDIT_EM_LineIndex(es
, line
);
2145 if (es
->style
& ES_MULTILINE
) {
2146 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2147 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2149 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2150 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2151 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2153 if (es
->style
& ES_PASSWORD
)
2154 HeapFree(GetProcessHeap(), 0, text
);
2157 if (es
->composition_len
== 0)
2159 SetBkColor(dc
, BkColor
);
2160 SetTextColor(dc
, TextColor
);
2161 SetBkMode( dc
, BkMode
);
2166 SelectObject(dc
,old_font
);
2168 DeleteObject(hUnderline
);
2175 /*********************************************************************
2180 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2182 INT s
= es
->selection_start
;
2183 INT e
= es
->selection_end
;
2190 if (es
->style
& ES_MULTILINE
) {
2191 INT vlc
= get_vertical_line_count(es
);
2193 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2198 TRACE("line=%d\n", line
);
2200 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2201 x
= (short)LOWORD(pos
);
2202 y
= (short)HIWORD(pos
);
2203 li
= EDIT_EM_LineIndex(es
, line
);
2204 ll
= EDIT_EM_LineLength(es
, li
);
2205 s
= min(es
->selection_start
, es
->selection_end
);
2206 e
= max(es
->selection_start
, es
->selection_end
);
2207 s
= min(li
+ ll
, max(li
, s
));
2208 e
= min(li
+ ll
, max(li
, e
));
2209 if (rev
&& (s
!= e
) &&
2210 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2211 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2212 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2213 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2215 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2219 /*********************************************************************
2221 * EDIT_AdjustFormatRect
2223 * Adjusts the format rectangle for the current font and the
2224 * current client rectangle.
2227 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2231 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2232 if (es
->style
& ES_MULTILINE
)
2234 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2236 vlc
= get_vertical_line_count(es
);
2237 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2239 /* correct es->x_offset */
2240 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2241 max_x_offset
= es
->text_width
- fw
;
2242 if(max_x_offset
< 0) max_x_offset
= 0;
2243 if(es
->x_offset
> max_x_offset
)
2244 es
->x_offset
= max_x_offset
;
2246 /* correct es->y_offset */
2247 max_y_offset
= es
->line_count
- vlc
;
2248 if(max_y_offset
< 0) max_y_offset
= 0;
2249 if(es
->y_offset
> max_y_offset
)
2250 es
->y_offset
= max_y_offset
;
2252 /* force scroll info update */
2253 EDIT_UpdateScrollInfo(es
);
2256 /* Windows doesn't care to fix text placement for SL controls */
2257 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2259 /* Always stay within the client area */
2260 GetClientRect(es
->hwndSelf
, &ClientRect
);
2261 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2263 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2264 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2266 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2270 /*********************************************************************
2274 * note: this is not (exactly) the handler called on EM_SETRECTNP
2275 * it is also used to set the rect of a single line control
2278 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2282 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2284 CopyRect(&es
->format_rect
, rc
);
2286 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2287 es
->format_rect
.left
++;
2288 es
->format_rect
.right
--;
2290 if (es
->format_rect
.bottom
- es
->format_rect
.top
2291 >= es
->line_height
+ 2)
2293 es
->format_rect
.top
++;
2294 es
->format_rect
.bottom
--;
2297 else if (es
->style
& WS_BORDER
) {
2298 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2299 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2300 es
->format_rect
.left
+= bw
;
2301 es
->format_rect
.right
-= bw
;
2302 if (es
->format_rect
.bottom
- es
->format_rect
.top
2303 >= es
->line_height
+ 2 * bh
)
2305 es
->format_rect
.top
+= bh
;
2306 es
->format_rect
.bottom
-= bh
;
2310 es
->format_rect
.left
+= es
->left_margin
;
2311 es
->format_rect
.right
-= es
->right_margin
;
2312 EDIT_AdjustFormatRect(es
);
2316 /*********************************************************************
2320 * returns line number (not index) in high-order word of result.
2321 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2322 * to Richedit, not to the edit control. Original documentation is valid.
2323 * FIXME: do the specs mean to return -1 if outside client area or
2324 * if outside formatting rectangle ???
2327 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2335 GetClientRect(es
->hwndSelf
, &rc
);
2336 if (!PtInRect(&rc
, pt
))
2339 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2340 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2344 /*********************************************************************
2348 * Enable or disable soft breaks.
2350 * This means: insert or remove the soft linebreak character (\r\r\n).
2351 * Take care to check if the text still fits the buffer after insertion.
2352 * If not, notify with EN_ERRSPACE.
2355 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2357 es
->flags
&= ~EF_USE_SOFTBRK
;
2359 es
->flags
|= EF_USE_SOFTBRK
;
2360 FIXME("soft break enabled, not implemented\n");
2366 /*********************************************************************
2370 * Hopefully this won't fire back at us.
2371 * We always start with a fixed buffer in the local heap.
2372 * Despite of the documentation says that the local heap is used
2373 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2374 * buffer on the local heap.
2377 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2381 if (!(es
->style
& ES_MULTILINE
))
2385 hLocal
= es
->hloc32W
;
2391 UINT countA
, alloc_size
;
2392 TRACE("Allocating 32-bit ANSI alias buffer\n");
2393 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2394 alloc_size
= ROUND_TO_GROW(countA
);
2395 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2397 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2400 textA
= LocalLock(es
->hloc32A
);
2401 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2402 LocalUnlock(es
->hloc32A
);
2404 hLocal
= es
->hloc32A
;
2407 es
->flags
|= EF_APP_HAS_HANDLE
;
2408 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2413 /*********************************************************************
2417 * Hopefully this won't fire back at us.
2418 * We always start with a buffer in 32 bit linear memory.
2419 * However, with this message a 16 bit application requests
2420 * a handle of 16 bit local heap memory, where it expects to find
2422 * It's a pitty that from this moment on we have to use this
2423 * local heap, because applications may rely on the handle
2426 * In this function we'll try to switch to local heap.
2428 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2431 UINT countA
, alloc_size
;
2432 STACK16FRAME
* stack16
;
2435 if (!(es
->style
& ES_MULTILINE
))
2441 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2442 oldDS
= stack16
->ds
;
2443 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2445 if (!LocalHeapSize16()) {
2447 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2448 ERR("could not initialize local heap\n");
2451 TRACE("local heap initialized\n");
2454 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2455 alloc_size
= ROUND_TO_GROW(countA
);
2457 TRACE("Allocating 16-bit ANSI alias buffer\n");
2458 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2459 ERR("could not allocate new 16 bit buffer\n");
2463 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2464 ERR("could not lock new 16 bit buffer\n");
2465 LocalFree16(es
->hloc16
);
2470 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2471 LocalUnlock16(es
->hloc16
);
2472 es
->flags
|= EF_APP_HAS_HANDLE
;
2474 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2477 stack16
->ds
= oldDS
;
2482 /*********************************************************************
2487 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2490 INT line_len
, dst_len
;
2493 if (es
->style
& ES_MULTILINE
) {
2494 if (line
>= es
->line_count
)
2498 i
= EDIT_EM_LineIndex(es
, line
);
2500 line_len
= EDIT_EM_LineLength(es
, i
);
2501 dst_len
= *(WORD
*)dst
;
2504 if(dst_len
<= line_len
)
2506 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2509 else /* Append 0 if enough space */
2511 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2518 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2519 if(!ret
&& line_len
) /* Insufficient buffer size */
2521 if(ret
< dst_len
) /* Append 0 if enough space */
2522 ((LPSTR
)dst
)[ret
] = 0;
2528 /*********************************************************************
2533 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2535 UINT s
= es
->selection_start
;
2536 UINT e
= es
->selection_end
;
2543 return MAKELONG(s
, e
);
2547 /*********************************************************************
2551 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2554 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2556 UINT strl
= strlenW(lpsz_replace
);
2557 UINT tl
= get_text_length(es
);
2568 TRACE("%s, can_undo %d, send_update %d\n",
2569 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2571 s
= es
->selection_start
;
2572 e
= es
->selection_end
;
2574 if ((s
== e
) && !strl
)
2579 size
= tl
- (e
- s
) + strl
;
2583 /* Issue the EN_MAXTEXT notification and continue with replacing text
2584 * such that buffer limit is honored. */
2585 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2586 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2587 /* Buffer limit can be smaller than the actual length of text in combobox */
2588 if (es
->buffer_limit
< (tl
- (e
-s
)))
2591 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2594 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2598 /* there is something to be deleted */
2599 TRACE("deleting stuff.\n");
2601 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2603 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2604 buf
[bufl
] = 0; /* ensure 0 termination */
2606 strcpyW(es
->text
+ s
, es
->text
+ e
);
2607 text_buffer_changed(es
);
2610 /* there is an insertion */
2611 tl
= get_text_length(es
);
2612 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
));
2613 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2615 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2616 p
[i
] = lpsz_replace
[i
];
2617 if(es
->style
& ES_UPPERCASE
)
2618 CharUpperBuffW(p
, strl
);
2619 else if(es
->style
& ES_LOWERCASE
)
2620 CharLowerBuffW(p
, strl
);
2621 text_buffer_changed(es
);
2623 if (es
->style
& ES_MULTILINE
)
2625 INT st
= min(es
->selection_start
, es
->selection_end
);
2626 INT vlc
= get_vertical_line_count(es
);
2628 hrgn
= CreateRectRgn(0, 0, 0, 0);
2629 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2630 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2631 /* if text is too long undo all changes */
2632 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2634 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2636 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2638 text_buffer_changed(es
);
2639 EDIT_BuildLineDefs_ML(es
, s
, e
,
2640 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2643 hrgn
= CreateRectRgn(0, 0, 0, 0);
2644 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2648 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2649 EDIT_CalcLineWidth_SL(es
);
2650 /* remove chars that don't fit */
2651 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2652 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2653 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2655 EDIT_CalcLineWidth_SL(es
);
2657 text_buffer_changed(es
);
2658 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2664 utl
= strlenW(es
->undo_text
);
2665 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2666 /* undo-buffer is extended to the right */
2667 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2668 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2669 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2670 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2671 /* undo-buffer is extended to the left */
2672 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2673 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2675 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2677 es
->undo_position
= s
;
2679 /* new undo-buffer */
2680 EDIT_MakeUndoFit(es
, e
- s
);
2681 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2682 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2683 es
->undo_position
= s
;
2685 /* any deletion makes the old insertion-undo invalid */
2686 es
->undo_insert_count
= 0;
2688 EDIT_EM_EmptyUndoBuffer(es
);
2692 if ((s
== es
->undo_position
) ||
2693 ((es
->undo_insert_count
) &&
2694 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2696 * insertion is new and at delete position or
2697 * an extension to either left or right
2699 es
->undo_insert_count
+= strl
;
2701 /* new insertion undo */
2702 es
->undo_position
= s
;
2703 es
->undo_insert_count
= strl
;
2704 /* new insertion makes old delete-buffer invalid */
2705 *es
->undo_text
= '\0';
2708 EDIT_EM_EmptyUndoBuffer(es
);
2712 HeapFree(GetProcessHeap(), 0, buf
);
2716 /* If text has been deleted and we're right or center aligned then scroll rightward */
2717 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2719 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2721 if (delta
< 0 && es
->x_offset
)
2723 if (abs(delta
) > es
->x_offset
)
2726 es
->x_offset
+= delta
;
2730 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2731 es
->flags
|= EF_MODIFIED
;
2732 if (send_update
) es
->flags
|= EF_UPDATE
;
2735 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2739 EDIT_UpdateText(es
, NULL
, TRUE
);
2741 EDIT_EM_ScrollCaret(es
);
2743 /* force scroll info update */
2744 EDIT_UpdateScrollInfo(es
);
2747 if(send_update
|| (es
->flags
& EF_UPDATE
))
2749 es
->flags
&= ~EF_UPDATE
;
2750 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2755 /*********************************************************************
2759 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2762 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2764 if (!(es
->style
& ES_MULTILINE
))
2768 WARN("called with NULL handle\n");
2772 EDIT_UnlockBuffer(es
, TRUE
);
2776 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2777 HANDLE16 oldDS
= stack16
->ds
;
2779 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2780 LocalFree16(es
->hloc16
);
2781 stack16
->ds
= oldDS
;
2789 LocalFree(es
->hloc32A
);
2801 countA
= LocalSize(hloc
);
2802 textA
= LocalLock(hloc
);
2803 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2804 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2806 ERR("Could not allocate new unicode buffer\n");
2809 textW
= LocalLock(hloc32W_new
);
2810 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2811 LocalUnlock(hloc32W_new
);
2815 LocalFree(es
->hloc32W
);
2817 es
->hloc32W
= hloc32W_new
;
2821 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2823 es
->flags
|= EF_APP_HAS_HANDLE
;
2824 EDIT_LockBuffer(es
);
2826 es
->x_offset
= es
->y_offset
= 0;
2827 es
->selection_start
= es
->selection_end
= 0;
2828 EDIT_EM_EmptyUndoBuffer(es
);
2829 es
->flags
&= ~EF_MODIFIED
;
2830 es
->flags
&= ~EF_UPDATE
;
2831 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2832 EDIT_UpdateText(es
, NULL
, TRUE
);
2833 EDIT_EM_ScrollCaret(es
);
2834 /* force scroll info update */
2835 EDIT_UpdateScrollInfo(es
);
2839 /*********************************************************************
2843 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2846 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
2848 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2849 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2850 HANDLE16 oldDS
= stack16
->ds
;
2856 if (!(es
->style
& ES_MULTILINE
))
2860 WARN("called with NULL handle\n");
2864 EDIT_UnlockBuffer(es
, TRUE
);
2868 LocalFree(es
->hloc32A
);
2872 stack16
->ds
= hInstance
;
2873 countA
= LocalSize16(hloc
);
2874 textA
= MapSL(LocalLock16(hloc
));
2875 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2876 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2878 ERR("Could not allocate new unicode buffer\n");
2881 textW
= LocalLock(hloc32W_new
);
2882 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2883 LocalUnlock(hloc32W_new
);
2884 LocalUnlock16(hloc
);
2885 stack16
->ds
= oldDS
;
2888 LocalFree(es
->hloc32W
);
2890 es
->hloc32W
= hloc32W_new
;
2893 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2895 es
->flags
|= EF_APP_HAS_HANDLE
;
2896 EDIT_LockBuffer(es
);
2898 es
->x_offset
= es
->y_offset
= 0;
2899 es
->selection_start
= es
->selection_end
= 0;
2900 EDIT_EM_EmptyUndoBuffer(es
);
2901 es
->flags
&= ~EF_MODIFIED
;
2902 es
->flags
&= ~EF_UPDATE
;
2903 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2904 EDIT_UpdateText(es
, NULL
, TRUE
);
2905 EDIT_EM_ScrollCaret(es
);
2906 /* force scroll info update */
2907 EDIT_UpdateScrollInfo(es
);
2911 /*********************************************************************
2915 * NOTE: this version currently implements WinNT limits
2918 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2920 if (!limit
) limit
= ~0u;
2921 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2922 es
->buffer_limit
= limit
;
2926 /*********************************************************************
2930 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2931 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2932 * margin according to the textmetrics of the current font.
2934 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2935 * of the char's width as the margin, but this is not how Windows handles this.
2936 * For all other fonts Windows sets the margins to zero.
2938 * FIXME - When EC_USEFONTINFO is used the margins only change if the
2939 * edit control is equal to or larger than a certain size.
2940 * Interestingly if one subtracts both the left and right margins from
2941 * this size one always seems to get an even number. The extents of
2942 * the (four character) string "'**'" match this quite closely, so
2943 * we'll use this until we come up with a better idea.
2945 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
2947 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
2950 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
2951 return sz
.cx
+ left
+ right
;
2954 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2955 WORD left
, WORD right
, BOOL repaint
)
2958 INT default_left_margin
= 0; /* in pixels */
2959 INT default_right_margin
= 0; /* in pixels */
2961 /* Set the default margins depending on the font */
2962 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2963 HDC dc
= GetDC(es
->hwndSelf
);
2964 HFONT old_font
= SelectObject(dc
, es
->font
);
2965 GetTextMetricsW(dc
, &tm
);
2966 /* The default margins are only non zero for TrueType or Vector fonts */
2967 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2970 /* This must be calculated more exactly! But how? */
2971 default_left_margin
= tm
.tmAveCharWidth
/ 2;
2972 default_right_margin
= tm
.tmAveCharWidth
/ 2;
2973 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
2974 GetClientRect(es
->hwndSelf
, &rc
);
2975 if(rc
.right
- rc
.left
< min_size
) {
2976 default_left_margin
= es
->left_margin
;
2977 default_right_margin
= es
->right_margin
;
2980 SelectObject(dc
, old_font
);
2981 ReleaseDC(es
->hwndSelf
, dc
);
2984 if (action
& EC_LEFTMARGIN
) {
2985 es
->format_rect
.left
-= es
->left_margin
;
2986 if (left
!= EC_USEFONTINFO
)
2987 es
->left_margin
= left
;
2989 es
->left_margin
= default_left_margin
;
2990 es
->format_rect
.left
+= es
->left_margin
;
2993 if (action
& EC_RIGHTMARGIN
) {
2994 es
->format_rect
.right
+= es
->right_margin
;
2995 if (right
!= EC_USEFONTINFO
)
2996 es
->right_margin
= right
;
2998 es
->right_margin
= default_right_margin
;
2999 es
->format_rect
.right
-= es
->right_margin
;
3002 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3003 EDIT_AdjustFormatRect(es
);
3004 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3007 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3011 /*********************************************************************
3013 * EM_SETPASSWORDCHAR
3016 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3020 if (es
->style
& ES_MULTILINE
)
3023 if (es
->password_char
== c
)
3026 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
3027 es
->password_char
= c
;
3029 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3030 es
->style
|= ES_PASSWORD
;
3032 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3033 es
->style
&= ~ES_PASSWORD
;
3035 EDIT_UpdateText(es
, NULL
, TRUE
);
3039 /*********************************************************************
3044 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3046 if (!(es
->style
& ES_MULTILINE
))
3048 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3049 es
->tabs_count
= count
;
3053 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3054 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3060 /*********************************************************************
3065 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3067 if (!(es
->style
& ES_MULTILINE
))
3069 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3070 es
->tabs_count
= count
;
3075 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3076 for (i
= 0 ; i
< count
; i
++)
3077 es
->tabs
[i
] = *tabs
++;
3083 /*********************************************************************
3085 * EM_SETWORDBREAKPROC
3088 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3090 if (es
->word_break_proc
== wbp
)
3093 es
->word_break_proc
= wbp
;
3094 es
->word_break_proc16
= NULL
;
3096 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3097 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3098 EDIT_UpdateText(es
, NULL
, TRUE
);
3103 /*********************************************************************
3105 * EM_SETWORDBREAKPROC16
3108 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3110 if (es
->word_break_proc16
== wbp
)
3113 es
->word_break_proc
= NULL
;
3114 es
->word_break_proc16
= wbp
;
3115 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3116 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3117 EDIT_UpdateText(es
, NULL
, TRUE
);
3122 /*********************************************************************
3127 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3132 /* As per MSDN spec, for a single-line edit control,
3133 the return value is always TRUE */
3134 if( es
->style
& ES_READONLY
)
3135 return !(es
->style
& ES_MULTILINE
);
3137 ulength
= strlenW(es
->undo_text
);
3139 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3141 strcpyW(utext
, es
->undo_text
);
3143 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3144 es
->undo_insert_count
, debugstr_w(utext
));
3146 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3147 EDIT_EM_EmptyUndoBuffer(es
);
3148 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3149 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3150 /* send the notification after the selection start and end are set */
3151 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3152 EDIT_EM_ScrollCaret(es
);
3153 HeapFree(GetProcessHeap(), 0, utext
);
3155 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3156 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3161 /* Helper function for WM_CHAR
3163 * According to an MSDN blog article titled "Just because you're a control
3164 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3165 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3166 * a dialog box or not.
3168 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3170 return (es
->flags
& EF_DIALOGMODE
);
3174 /*********************************************************************
3179 static void EDIT_WM_Paste(EDITSTATE
*es
)
3184 /* Protect read-only edit control from modification */
3185 if(es
->style
& ES_READONLY
)
3188 OpenClipboard(es
->hwndSelf
);
3189 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
3190 src
= GlobalLock(hsrc
);
3191 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
3194 else if (es
->style
& ES_PASSWORD
) {
3195 /* clear selected text in password edit box even with empty clipboard */
3196 const WCHAR empty_strW
[] = { 0 };
3197 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
3203 /*********************************************************************
3208 static void EDIT_WM_Copy(EDITSTATE
*es
)
3210 INT s
= min(es
->selection_start
, es
->selection_end
);
3211 INT e
= max(es
->selection_start
, es
->selection_end
);
3219 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3220 dst
= GlobalLock(hdst
);
3221 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3222 dst
[len
] = 0; /* ensure 0 termination */
3223 TRACE("%s\n", debugstr_w(dst
));
3225 OpenClipboard(es
->hwndSelf
);
3227 SetClipboardData(CF_UNICODETEXT
, hdst
);
3232 /*********************************************************************
3237 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
3239 static const WCHAR empty_stringW
[] = {0};
3241 /* Protect read-only edit control from modification */
3242 if(es
->style
& ES_READONLY
)
3245 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
3249 /*********************************************************************
3254 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3261 /*********************************************************************
3266 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3270 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3274 /* If it's not a multiline edit box, it would be ignored below.
3275 * For multiline edit without ES_WANTRETURN, we have to make a
3278 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3279 if (EDIT_IsInsideDialog(es
))
3282 if (es
->style
& ES_MULTILINE
) {
3283 if (es
->style
& ES_READONLY
) {
3284 EDIT_MoveHome(es
, FALSE
, FALSE
);
3285 EDIT_MoveDown_ML(es
, FALSE
);
3287 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3288 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3293 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3295 static const WCHAR tabW
[] = {'\t',0};
3296 if (EDIT_IsInsideDialog(es
))
3298 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3302 if (!(es
->style
& ES_READONLY
) && !control
) {
3303 if (es
->selection_start
!= es
->selection_end
)
3306 /* delete character left of caret */
3307 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3308 EDIT_MoveBackward(es
, TRUE
);
3314 if (!(es
->style
& ES_PASSWORD
))
3315 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3318 if (!(es
->style
& ES_READONLY
))
3319 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3322 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3323 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3326 if (!(es
->style
& ES_READONLY
))
3327 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3331 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3332 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3335 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3339 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3347 /*********************************************************************
3352 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3354 if (code
|| control
)
3359 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3362 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3365 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3368 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3371 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3374 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3375 EDIT_EM_ScrollCaret(es
);
3378 ERR("unknown menu item, please report\n");
3384 /*********************************************************************
3388 * Note: the resource files resource/sysres_??.rc cannot define a
3389 * single popup menu. Hence we use a (dummy) menubar
3390 * containing the single popup menu as its first item.
3392 * FIXME: the message identifiers have been chosen arbitrarily,
3393 * hence we use MF_BYPOSITION.
3394 * We might as well use the "real" values (anybody knows ?)
3395 * The menu definition is in resources/sysres_??.rc.
3396 * Once these are OK, we better use MF_BYCOMMAND here
3397 * (as we do in EDIT_WM_Command()).
3400 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3402 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3403 HMENU popup
= GetSubMenu(menu
, 0);
3404 UINT start
= es
->selection_start
;
3405 UINT end
= es
->selection_end
;
3407 ORDER_UINT(start
, end
);
3410 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3412 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3414 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3416 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3418 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3420 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3422 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3425 /* Windows places the menu at the edit's center in this case */
3426 GetClientRect(es
->hwndSelf
, &rc
);
3427 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
3428 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3429 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3432 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, es
->hwndSelf
, NULL
);
3437 /*********************************************************************
3442 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3444 if(!count
) return 0;
3448 lstrcpynW(dst
, es
->text
, count
);
3449 return strlenW(dst
);
3453 LPSTR textA
= (LPSTR
)dst
;
3454 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3455 textA
[count
- 1] = 0; /* ensure 0 termination */
3456 return strlen(textA
);
3460 /*********************************************************************
3465 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3467 HWND hLBox
= es
->hwndListBox
;
3475 hCombo
= GetParent(es
->hwndSelf
);
3479 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3481 if (key
== VK_UP
|| key
== VK_DOWN
)
3483 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3486 if (msg
== WM_KEYDOWN
|| nEUI
)
3487 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3493 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3495 /* make sure ComboLBox pops up */
3496 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3501 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3504 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3506 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3508 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
3513 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3519 /*********************************************************************
3523 * Handling of special keys that don't produce a WM_CHAR
3524 * (i.e. non-printable keys) & Backspace & Delete
3527 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3532 if (GetKeyState(VK_MENU
) & 0x8000)
3535 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3536 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3541 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3546 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3547 EDIT_MoveUp_ML(es
, shift
);
3550 EDIT_MoveWordBackward(es
, shift
);
3552 EDIT_MoveBackward(es
, shift
);
3555 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3559 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3560 EDIT_MoveDown_ML(es
, shift
);
3562 EDIT_MoveWordForward(es
, shift
);
3564 EDIT_MoveForward(es
, shift
);
3567 EDIT_MoveHome(es
, shift
, control
);
3570 EDIT_MoveEnd(es
, shift
, control
);
3573 if (es
->style
& ES_MULTILINE
)
3574 EDIT_MovePageUp_ML(es
, shift
);
3576 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3579 if (es
->style
& ES_MULTILINE
)
3580 EDIT_MovePageDown_ML(es
, shift
);
3582 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3585 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3586 if (es
->selection_start
!= es
->selection_end
) {
3593 /* delete character left of caret */
3594 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3595 EDIT_MoveBackward(es
, TRUE
);
3597 } else if (control
) {
3598 /* delete to end of line */
3599 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3600 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3603 /* delete character right of caret */
3604 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3605 EDIT_MoveForward(es
, TRUE
);
3613 if (!(es
->style
& ES_READONLY
))
3619 /* If the edit doesn't want the return send a message to the default object */
3620 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3624 if (!EDIT_IsInsideDialog(es
)) break;
3626 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3627 if (HIWORD(dw
) == DC_HASDEFID
)
3629 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3632 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, (LPARAM
)TRUE
);
3633 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3639 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3640 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3643 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3644 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3651 /*********************************************************************
3656 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3658 es
->flags
&= ~EF_FOCUSED
;
3660 if(!(es
->style
& ES_NOHIDESEL
))
3661 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3662 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3667 /*********************************************************************
3671 * The caret position has been set on the WM_LBUTTONDOWN message
3674 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3677 INT e
= es
->selection_end
;
3682 es
->bCaptureState
= TRUE
;
3683 SetCapture(es
->hwndSelf
);
3685 l
= EDIT_EM_LineFromChar(es
, e
);
3686 li
= EDIT_EM_LineIndex(es
, l
);
3687 ll
= EDIT_EM_LineLength(es
, e
);
3688 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3689 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3690 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3691 EDIT_EM_ScrollCaret(es
);
3692 es
->region_posx
= es
->region_posy
= 0;
3693 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3698 /*********************************************************************
3703 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3708 es
->bCaptureState
= TRUE
;
3709 SetCapture(es
->hwndSelf
);
3710 EDIT_ConfinePoint(es
, &x
, &y
);
3711 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3712 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3713 EDIT_EM_ScrollCaret(es
);
3714 es
->region_posx
= es
->region_posy
= 0;
3715 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3717 if (!(es
->flags
& EF_FOCUSED
))
3718 SetFocus(es
->hwndSelf
);
3724 /*********************************************************************
3729 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3731 if (es
->bCaptureState
) {
3732 KillTimer(es
->hwndSelf
, 0);
3733 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3735 es
->bCaptureState
= FALSE
;
3740 /*********************************************************************
3745 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3747 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3752 /*********************************************************************
3757 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3763 /* If the mouse has been captured by process other than the edit control itself,
3764 * the windows edit controls will not select the strings with mouse move.
3766 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3770 * FIXME: gotta do some scrolling if outside client
3771 * area. Maybe reset the timer ?
3774 EDIT_ConfinePoint(es
, &x
, &y
);
3775 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3776 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3777 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3778 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3779 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3784 /*********************************************************************
3789 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3802 BOOL rev
= es
->bEnableState
&&
3803 ((es
->flags
& EF_FOCUSED
) ||
3804 (es
->style
& ES_NOHIDESEL
));
3805 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3807 GetClientRect(es
->hwndSelf
, &rcClient
);
3809 /* get the background brush */
3810 brush
= EDIT_NotifyCtlColor(es
, dc
);
3812 /* paint the border and the background */
3813 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3815 if(es
->style
& WS_BORDER
) {
3816 bw
= GetSystemMetrics(SM_CXBORDER
);
3817 bh
= GetSystemMetrics(SM_CYBORDER
);
3819 if(es
->style
& ES_MULTILINE
) {
3820 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3821 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3824 /* Draw the frame. Same code as in nonclient.c */
3825 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3826 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3827 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3828 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3829 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3830 SelectObject(dc
, old_brush
);
3832 /* Keep the border clean */
3833 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3834 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3837 GetClipBox(dc
, &rc
);
3838 FillRect(dc
, &rc
, brush
);
3840 IntersectClipRect(dc
, es
->format_rect
.left
,
3841 es
->format_rect
.top
,
3842 es
->format_rect
.right
,
3843 es
->format_rect
.bottom
);
3844 if (es
->style
& ES_MULTILINE
) {
3846 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3849 old_font
= SelectObject(dc
, es
->font
);
3851 if (!es
->bEnableState
)
3852 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3853 GetClipBox(dc
, &rcRgn
);
3854 if (es
->style
& ES_MULTILINE
) {
3855 INT vlc
= get_vertical_line_count(es
);
3856 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3857 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3858 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3859 EDIT_PaintLine(es
, dc
, i
, rev
);
3862 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3863 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3864 EDIT_PaintLine(es
, dc
, 0, rev
);
3867 SelectObject(dc
, old_font
);
3870 EndPaint(es
->hwndSelf
, &ps
);
3874 /*********************************************************************
3879 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3881 es
->flags
|= EF_FOCUSED
;
3883 if (!(es
->style
& ES_NOHIDESEL
))
3884 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3886 /* single line edit updates itself */
3887 if (!(es
->style
& ES_MULTILINE
))
3889 HDC hdc
= GetDC(es
->hwndSelf
);
3890 EDIT_WM_Paint(es
, hdc
);
3891 ReleaseDC(es
->hwndSelf
, hdc
);
3894 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3895 EDIT_SetCaretPos(es
, es
->selection_end
,
3896 es
->flags
& EF_AFTER_WRAP
);
3897 ShowCaret(es
->hwndSelf
);
3898 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3902 /*********************************************************************
3906 * With Win95 look the margins are set to default font value unless
3907 * the system font (font == 0) is being set, in which case they are left
3911 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3919 dc
= GetDC(es
->hwndSelf
);
3921 old_font
= SelectObject(dc
, font
);
3922 GetTextMetricsW(dc
, &tm
);
3923 es
->line_height
= tm
.tmHeight
;
3924 es
->char_width
= tm
.tmAveCharWidth
;
3926 SelectObject(dc
, old_font
);
3927 ReleaseDC(es
->hwndSelf
, dc
);
3929 /* Reset the format rect and the margins */
3930 GetClientRect(es
->hwndSelf
, &clientRect
);
3931 EDIT_SetRectNP(es
, &clientRect
);
3932 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3933 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3935 if (es
->style
& ES_MULTILINE
)
3936 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3938 EDIT_CalcLineWidth_SL(es
);
3941 EDIT_UpdateText(es
, NULL
, TRUE
);
3942 if (es
->flags
& EF_FOCUSED
) {
3944 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3945 EDIT_SetCaretPos(es
, es
->selection_end
,
3946 es
->flags
& EF_AFTER_WRAP
);
3947 ShowCaret(es
->hwndSelf
);
3952 /*********************************************************************
3957 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3958 * The modified flag is reset. No notifications are sent.
3960 * For single-line controls, reception of WM_SETTEXT triggers:
3961 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3964 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
3966 LPWSTR textW
= NULL
;
3967 if (!unicode
&& text
)
3969 LPCSTR textA
= (LPCSTR
)text
;
3970 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
3971 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
3973 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
3977 if (es
->flags
& EF_UPDATE
)
3978 /* fixed this bug once; complain if we see it about to happen again. */
3979 ERR("SetSel may generate UPDATE message whose handler may reset "
3982 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3985 TRACE("%s\n", debugstr_w(text
));
3986 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
3988 HeapFree(GetProcessHeap(), 0, textW
);
3992 static const WCHAR empty_stringW
[] = {0};
3994 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
3997 es
->flags
&= ~EF_MODIFIED
;
3998 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4000 /* Send the notification after the selection start and end have been set
4001 * edit control doesn't send notification on WM_SETTEXT
4002 * if it is multiline, or it is part of combobox
4004 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4006 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
4007 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4009 EDIT_EM_ScrollCaret(es
);
4010 EDIT_UpdateScrollInfo(es
);
4014 /*********************************************************************
4019 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4021 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4023 TRACE("width = %d, height = %d\n", width
, height
);
4024 SetRect(&rc
, 0, 0, width
, height
);
4025 EDIT_SetRectNP(es
, &rc
);
4026 EDIT_UpdateText(es
, NULL
, TRUE
);
4031 /*********************************************************************
4035 * This message is sent by SetWindowLong on having changed either the Style
4036 * or the extended style.
4038 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4040 * See also EDIT_WM_NCCreate
4042 * It appears that the Windows version of the edit control allows the style
4043 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4044 * style variable which will generally be different. In this function we
4045 * update the internal style based on what changed in the externally visible
4048 * Much of this content as based upon the MSDN, especially:
4049 * Platform SDK Documentation -> User Interface Services ->
4050 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4051 * Edit Control Styles
4053 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4055 if (GWL_STYLE
== which
) {
4056 DWORD style_change_mask
;
4058 /* Only a subset of changes can be applied after the control
4061 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4063 if (es
->style
& ES_MULTILINE
)
4064 style_change_mask
|= ES_WANTRETURN
;
4066 new_style
= style
->styleNew
& style_change_mask
;
4068 /* Number overrides lowercase overrides uppercase (at least it
4069 * does in Win95). However I'll bet that ES_NUMBER would be
4070 * invalid under Win 3.1.
4072 if (new_style
& ES_NUMBER
) {
4073 ; /* do not override the ES_NUMBER */
4074 } else if (new_style
& ES_LOWERCASE
) {
4075 new_style
&= ~ES_UPPERCASE
;
4078 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4079 } else if (GWL_EXSTYLE
== which
) {
4080 ; /* FIXME - what is needed here */
4082 WARN ("Invalid style change %ld\n",which
);
4088 /*********************************************************************
4093 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4095 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4096 if (EDIT_EM_CanUndo(es
))
4099 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4100 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4103 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4107 /*********************************************************************
4112 static void EDIT_WM_Timer(EDITSTATE
*es
)
4114 if (es
->region_posx
< 0) {
4115 EDIT_MoveBackward(es
, TRUE
);
4116 } else if (es
->region_posx
> 0) {
4117 EDIT_MoveForward(es
, TRUE
);
4120 * FIXME: gotta do some vertical scrolling here, like
4121 * EDIT_EM_LineScroll(hwnd, 0, 1);
4125 /*********************************************************************
4130 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4135 if (!(es
->style
& ES_MULTILINE
))
4138 if (!(es
->style
& ES_AUTOHSCROLL
))
4142 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4145 TRACE("SB_LINELEFT\n");
4147 dx
= -es
->char_width
;
4150 TRACE("SB_LINERIGHT\n");
4151 if (es
->x_offset
< es
->text_width
)
4152 dx
= es
->char_width
;
4155 TRACE("SB_PAGELEFT\n");
4157 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4160 TRACE("SB_PAGERIGHT\n");
4161 if (es
->x_offset
< es
->text_width
)
4162 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4170 TRACE("SB_RIGHT\n");
4171 if (es
->x_offset
< es
->text_width
)
4172 dx
= es
->text_width
- es
->x_offset
;
4175 TRACE("SB_THUMBTRACK %d\n", pos
);
4176 es
->flags
|= EF_HSCROLL_TRACK
;
4177 if(es
->style
& WS_HSCROLL
)
4178 dx
= pos
- es
->x_offset
;
4183 if(pos
< 0 || pos
> 100) return 0;
4184 /* Assume default scroll range 0-100 */
4185 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4186 new_x
= pos
* (es
->text_width
- fw
) / 100;
4187 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4190 case SB_THUMBPOSITION
:
4191 TRACE("SB_THUMBPOSITION %d\n", pos
);
4192 es
->flags
&= ~EF_HSCROLL_TRACK
;
4193 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4194 dx
= pos
- es
->x_offset
;
4199 if(pos
< 0 || pos
> 100) return 0;
4200 /* Assume default scroll range 0-100 */
4201 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4202 new_x
= pos
* (es
->text_width
- fw
) / 100;
4203 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4206 /* force scroll info update */
4207 EDIT_UpdateScrollInfo(es
);
4208 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4212 TRACE("SB_ENDSCROLL\n");
4215 * FIXME : the next two are undocumented !
4216 * Are we doing the right thing ?
4217 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4218 * although it's also a regular control message.
4220 case EM_GETTHUMB
: /* this one is used by NT notepad */
4224 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4225 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4228 /* Assume default scroll range 0-100 */
4229 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4230 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4232 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4235 case EM_LINESCROLL16
:
4236 TRACE("EM_LINESCROLL16\n");
4241 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4247 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4248 /* check if we are going to move too far */
4249 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4250 dx
= es
->text_width
- fw
- es
->x_offset
;
4252 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4258 /*********************************************************************
4263 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4267 if (!(es
->style
& ES_MULTILINE
))
4270 if (!(es
->style
& ES_AUTOVSCROLL
))
4279 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4280 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4281 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4283 EDIT_EM_Scroll(es
, action
);
4290 TRACE("SB_BOTTOM\n");
4291 dy
= es
->line_count
- 1 - es
->y_offset
;
4294 TRACE("SB_THUMBTRACK %d\n", pos
);
4295 es
->flags
|= EF_VSCROLL_TRACK
;
4296 if(es
->style
& WS_VSCROLL
)
4297 dy
= pos
- es
->y_offset
;
4300 /* Assume default scroll range 0-100 */
4303 if(pos
< 0 || pos
> 100) return 0;
4304 vlc
= get_vertical_line_count(es
);
4305 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4306 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4307 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4308 es
->line_count
, es
->y_offset
, pos
, dy
);
4311 case SB_THUMBPOSITION
:
4312 TRACE("SB_THUMBPOSITION %d\n", pos
);
4313 es
->flags
&= ~EF_VSCROLL_TRACK
;
4314 if(es
->style
& WS_VSCROLL
)
4315 dy
= pos
- es
->y_offset
;
4318 /* Assume default scroll range 0-100 */
4321 if(pos
< 0 || pos
> 100) return 0;
4322 vlc
= get_vertical_line_count(es
);
4323 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4324 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4325 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4326 es
->line_count
, es
->y_offset
, pos
, dy
);
4330 /* force scroll info update */
4331 EDIT_UpdateScrollInfo(es
);
4332 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4336 TRACE("SB_ENDSCROLL\n");
4339 * FIXME : the next two are undocumented !
4340 * Are we doing the right thing ?
4341 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4342 * although it's also a regular control message.
4344 case EM_GETTHUMB
: /* this one is used by NT notepad */
4348 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4349 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4352 /* Assume default scroll range 0-100 */
4353 INT vlc
= get_vertical_line_count(es
);
4354 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4356 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4359 case EM_LINESCROLL16
:
4360 TRACE("EM_LINESCROLL16 %d\n", pos
);
4365 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4370 EDIT_EM_LineScroll(es
, 0, dy
);
4374 /*********************************************************************
4378 * FIXME: is this right ? (or should it be only VSCROLL)
4379 * (and maybe only for edit controls that really have their
4380 * own scrollbars) (and maybe only for multiline controls ?)
4381 * All in all: very poorly documented
4384 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4386 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
4387 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
4391 /********************************************************************
4393 * The Following code is to handle inline editing from IMEs
4396 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4399 LPWSTR lpCompStr
= NULL
;
4400 LPSTR lpCompStrAttr
= NULL
;
4403 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4410 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
4413 ERR("Unable to allocate IME CompositionString\n");
4418 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4419 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
4421 if (CompFlag
& GCS_COMPATTR
)
4424 * We do not use the attributes yet. it would tell us what characters
4425 * are in transition and which are converted or decided upon
4427 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4431 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4434 ERR("Unable to allocate IME Attribute String\n");
4435 HeapFree(GetProcessHeap(),0,lpCompStr
);
4438 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4440 lpCompStrAttr
[dwBufLenAttr
] = 0;
4443 lpCompStrAttr
= NULL
;
4446 /* check for change in composition start */
4447 if (es
->selection_end
< es
->composition_start
)
4448 es
->composition_start
= es
->selection_end
;
4450 /* replace existing selection string */
4451 es
->selection_start
= es
->composition_start
;
4453 if (es
->composition_len
> 0)
4454 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4456 es
->selection_end
= es
->selection_start
;
4458 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
4459 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4461 es
->selection_start
= es
->composition_start
;
4462 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4464 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4465 HeapFree(GetProcessHeap(),0,lpCompStr
);
4468 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4473 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4479 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
4482 ERR("Unable to alloc buffer for IME string\n");
4486 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4487 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
4489 /* check for change in composition start */
4490 if (es
->selection_end
< es
->composition_start
)
4491 es
->composition_start
= es
->selection_end
;
4493 es
->selection_start
= es
->composition_start
;
4494 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4495 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
4496 es
->composition_start
= es
->selection_end
;
4497 es
->composition_len
= 0;
4499 HeapFree(GetProcessHeap(),0,lpResultStr
);
4502 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4507 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4509 static const WCHAR empty_stringW
[] = {0};
4510 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4511 es
->composition_start
= es
->selection_end
;
4514 hIMC
= ImmGetContext(hwnd
);
4518 if (CompFlag
& GCS_RESULTSTR
)
4519 EDIT_GetResultStr(hIMC
, es
);
4520 if (CompFlag
& GCS_COMPSTR
)
4521 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4522 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4523 ImmReleaseContext(hwnd
, hIMC
);
4524 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4528 /*********************************************************************
4532 * See also EDIT_WM_StyleChanged
4534 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4539 TRACE("Creating %s edit control, style = %08x\n",
4540 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4542 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4544 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4547 * Note: since the EDITSTATE has not been fully initialized yet,
4548 * we can't use any API calls that may send
4549 * WM_XXX messages before WM_NCCREATE is completed.
4552 es
->is_unicode
= unicode
;
4553 es
->style
= lpcs
->style
;
4555 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4557 es
->hwndSelf
= hwnd
;
4558 /* Save parent, which will be notified by EN_* messages */
4559 es
->hwndParent
= lpcs
->hwndParent
;
4561 if (es
->style
& ES_COMBO
)
4562 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4564 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4565 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4567 /* Number overrides lowercase overrides uppercase (at least it
4568 * does in Win95). However I'll bet that ES_NUMBER would be
4569 * invalid under Win 3.1.
4571 if (es
->style
& ES_NUMBER
) {
4572 ; /* do not override the ES_NUMBER */
4573 } else if (es
->style
& ES_LOWERCASE
) {
4574 es
->style
&= ~ES_UPPERCASE
;
4576 if (es
->style
& ES_MULTILINE
) {
4577 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4578 if (es
->style
& WS_VSCROLL
)
4579 es
->style
|= ES_AUTOVSCROLL
;
4580 if (es
->style
& WS_HSCROLL
)
4581 es
->style
|= ES_AUTOHSCROLL
;
4582 es
->style
&= ~ES_PASSWORD
;
4583 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4584 /* Confirmed - RIGHT overrides CENTER */
4585 if (es
->style
& ES_RIGHT
)
4586 es
->style
&= ~ES_CENTER
;
4587 es
->style
&= ~WS_HSCROLL
;
4588 es
->style
&= ~ES_AUTOHSCROLL
;
4591 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4592 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4593 es
->style
&= ~ES_CENTER
;
4594 es
->style
&= ~WS_HSCROLL
;
4595 es
->style
&= ~WS_VSCROLL
;
4596 if (es
->style
& ES_PASSWORD
)
4597 es
->password_char
= '*';
4600 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4601 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4603 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4605 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4607 es
->undo_buffer_size
= es
->buffer_size
;
4609 if (es
->style
& ES_MULTILINE
)
4610 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4615 * In Win95 look and feel, the WS_BORDER style is replaced by the
4616 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4617 * control a nonclient area so we don't need to draw the border.
4618 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4619 * a nonclient area and we should handle painting the border ourselves.
4621 * When making modifications please ensure that the code still works
4622 * for edit controls created directly with style 0x50800000, exStyle 0
4623 * (which should have a single pixel border)
4625 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4626 es
->style
&= ~WS_BORDER
;
4627 else if (es
->style
& WS_BORDER
)
4628 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4633 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4634 HeapFree(GetProcessHeap(), 0, es
->first_line_def
);
4635 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4636 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4637 HeapFree(GetProcessHeap(), 0, es
);
4642 /*********************************************************************
4647 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4651 TRACE("%s\n", debugstr_w(name
));
4653 * To initialize some final structure members, we call some helper
4654 * functions. However, since the EDITSTATE is not consistent (i.e.
4655 * not fully initialized), we should be very careful which
4656 * functions can be called, and in what order.
4658 EDIT_WM_SetFont(es
, 0, FALSE
);
4659 EDIT_EM_EmptyUndoBuffer(es
);
4661 /* We need to calculate the format rect
4662 (applications may send EM_SETMARGINS before the control gets visible) */
4663 GetClientRect(es
->hwndSelf
, &clientRect
);
4664 EDIT_SetRectNP(es
, &clientRect
);
4666 if (name
&& *name
) {
4667 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4668 /* if we insert text to the editline, the text scrolls out
4669 * of the window, as the caret is placed after the insert
4670 * pos normally; thus we reset es->selection... to 0 and
4673 es
->selection_start
= es
->selection_end
= 0;
4674 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4675 * Messages are only to be sent when the USER does something to
4676 * change the contents. So I am removing this EN_CHANGE
4678 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4680 EDIT_EM_ScrollCaret(es
);
4682 /* force scroll info update */
4683 EDIT_UpdateScrollInfo(es
);
4684 /* The rule seems to return 1 here for success */
4685 /* Power Builder masked edit controls will crash */
4687 /* FIXME: is that in all cases so ? */
4692 /*********************************************************************
4697 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4702 LocalFree(es
->hloc32W
);
4705 LocalFree(es
->hloc32A
);
4708 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4709 HANDLE16 oldDS
= stack16
->ds
;
4711 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4712 while (LocalUnlock16(es
->hloc16
)) ;
4713 LocalFree16(es
->hloc16
);
4714 stack16
->ds
= oldDS
;
4717 pc
= es
->first_line_def
;
4721 HeapFree(GetProcessHeap(), 0, pc
);
4725 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4726 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4727 HeapFree(GetProcessHeap(), 0, es
);
4733 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4736 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4738 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4741 /*********************************************************************
4743 * EditWndProc_common
4745 * The messages are in the order of the actual integer values
4746 * (which can be found in include/windows.h)
4747 * Wherever possible the 16 bit versions are converted to
4748 * the 32 bit ones, so that we can 'fall through' to the
4749 * helper functions. These are mostly 32 bit (with a few
4750 * exceptions, clearly indicated by a '16' extension to their
4754 static LRESULT
EditWndProc_common( HWND hwnd
, UINT msg
,
4755 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4757 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4760 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4762 if (!es
&& msg
!= WM_NCCREATE
)
4763 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4765 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
4773 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4777 if ((short)LOWORD(lParam
) == -1)
4778 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4780 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
4782 EDIT_EM_ScrollCaret(es
);
4786 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4787 EDIT_EM_ScrollCaret(es
);
4794 RECT16
*r16
= MapSL(lParam
);
4795 r16
->left
= es
->format_rect
.left
;
4796 r16
->top
= es
->format_rect
.top
;
4797 r16
->right
= es
->format_rect
.right
;
4798 r16
->bottom
= es
->format_rect
.bottom
;
4803 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
4807 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4809 RECT16
*r16
= MapSL(lParam
);
4810 rc
.left
= r16
->left
;
4812 rc
.right
= r16
->right
;
4813 rc
.bottom
= r16
->bottom
;
4814 EDIT_SetRectNP(es
, &rc
);
4815 EDIT_UpdateText(es
, NULL
, TRUE
);
4819 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4820 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4821 EDIT_UpdateText(es
, NULL
, TRUE
);
4825 case EM_SETRECTNP16
:
4826 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4828 RECT16
*r16
= MapSL(lParam
);
4829 rc
.left
= r16
->left
;
4831 rc
.right
= r16
->right
;
4832 rc
.bottom
= r16
->bottom
;
4833 EDIT_SetRectNP(es
, &rc
);
4837 if ((es
->style
& ES_MULTILINE
) && lParam
)
4838 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4843 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4846 case EM_LINESCROLL16
:
4847 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
4848 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
4851 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4854 case EM_SCROLLCARET16
:
4855 case EM_SCROLLCARET
:
4856 EDIT_EM_ScrollCaret(es
);
4860 case EM_GETMODIFY16
:
4862 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4865 case EM_SETMODIFY16
:
4868 es
->flags
|= EF_MODIFIED
;
4870 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4873 case EM_GETLINECOUNT16
:
4874 case EM_GETLINECOUNT
:
4875 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4878 case EM_LINEINDEX16
:
4879 if ((INT16
)wParam
== -1)
4880 wParam
= (WPARAM
)-1;
4883 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4886 case EM_SETHANDLE16
:
4887 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
4890 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4893 case EM_GETHANDLE16
:
4894 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
4897 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4902 result
= EDIT_EM_GetThumb(es
);
4905 /* these messages missing from specs */
4914 FIXME("undocumented message 0x%x, please report\n", msg
);
4915 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4918 case EM_LINELENGTH16
:
4920 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4923 case EM_REPLACESEL16
:
4924 lParam
= (LPARAM
)MapSL(lParam
);
4925 unicode
= FALSE
; /* 16-bit message is always ascii */
4932 textW
= (LPWSTR
)lParam
;
4935 LPSTR textA
= (LPSTR
)lParam
;
4936 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4937 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4938 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4941 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
4945 HeapFree(GetProcessHeap(), 0, textW
);
4950 lParam
= (LPARAM
)MapSL(lParam
);
4951 unicode
= FALSE
; /* 16-bit message is always ascii */
4954 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
4957 case EM_LIMITTEXT16
:
4958 case EM_SETLIMITTEXT
:
4959 EDIT_EM_SetLimitText(es
, wParam
);
4964 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4970 result
= (LRESULT
)EDIT_EM_Undo(es
);
4975 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4978 case EM_LINEFROMCHAR16
:
4979 case EM_LINEFROMCHAR
:
4980 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4983 case EM_SETTABSTOPS16
:
4984 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
4986 case EM_SETTABSTOPS
:
4987 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4990 case EM_SETPASSWORDCHAR16
:
4991 unicode
= FALSE
; /* 16-bit message is always ascii */
4993 case EM_SETPASSWORDCHAR
:
4998 charW
= (WCHAR
)wParam
;
5001 CHAR charA
= wParam
;
5002 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5005 EDIT_EM_SetPasswordChar(es
, charW
);
5009 case EM_EMPTYUNDOBUFFER16
:
5010 case EM_EMPTYUNDOBUFFER
:
5011 EDIT_EM_EmptyUndoBuffer(es
);
5014 case EM_GETFIRSTVISIBLELINE16
:
5015 result
= es
->y_offset
;
5017 case EM_GETFIRSTVISIBLELINE
:
5018 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
5021 case EM_SETREADONLY16
:
5022 case EM_SETREADONLY
:
5024 DWORD old_style
= es
->style
;
5027 SetWindowLongW( hwnd
, GWL_STYLE
,
5028 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
5029 es
->style
|= ES_READONLY
;
5031 SetWindowLongW( hwnd
, GWL_STYLE
,
5032 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
5033 es
->style
&= ~ES_READONLY
;
5036 if (old_style
^ es
->style
)
5037 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
5043 case EM_SETWORDBREAKPROC16
:
5044 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
5046 case EM_SETWORDBREAKPROC
:
5047 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
5050 case EM_GETWORDBREAKPROC16
:
5051 result
= (LRESULT
)es
->word_break_proc16
;
5053 case EM_GETWORDBREAKPROC
:
5054 result
= (LRESULT
)es
->word_break_proc
;
5057 case EM_GETPASSWORDCHAR16
:
5058 unicode
= FALSE
; /* 16-bit message is always ascii */
5060 case EM_GETPASSWORDCHAR
:
5063 result
= es
->password_char
;
5066 WCHAR charW
= es
->password_char
;
5068 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
5074 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
5077 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
5081 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
5084 case EM_GETLIMITTEXT
:
5085 result
= es
->buffer_limit
;
5088 case EM_POSFROMCHAR
:
5089 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
5090 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
5093 case EM_CHARFROMPOS
:
5094 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5097 /* End of the EM_ messages which were in numerical order; what order
5098 * are these in? vaguely alphabetical?
5102 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
5106 result
= EDIT_WM_Destroy(es
);
5111 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
5113 if (es
->style
& ES_MULTILINE
)
5114 result
|= DLGC_WANTALLKEYS
;
5118 es
->flags
|=EF_DIALOGMODE
;
5120 if (((LPMSG
)lParam
)->message
== WM_KEYDOWN
)
5122 int vk
= (int)((LPMSG
)lParam
)->wParam
;
5124 if (es
->hwndListBox
)
5126 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
5127 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5128 result
|= DLGC_WANTMESSAGE
;
5140 strng
[0] = wParam
>> 8;
5141 strng
[1] = wParam
& 0xff;
5142 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
5143 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
5144 result
= EDIT_WM_Char(es
, charW
);
5156 CHAR charA
= wParam
;
5157 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5160 if (es
->hwndListBox
)
5162 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
5164 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5165 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
5169 result
= EDIT_WM_Char(es
, charW
);
5176 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
5177 if (wParam
<= 0x000fffff)
5179 if(wParam
> 0xffff) /* convert to surrogates */
5182 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
5183 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
5185 else EDIT_WM_Char(es
, wParam
);
5196 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
5199 case WM_CONTEXTMENU
:
5200 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5209 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
5212 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
5213 LPWSTR nameW
= NULL
;
5216 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
5217 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5218 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
5220 result
= EDIT_WM_Create(es
, nameW
);
5221 HeapFree(GetProcessHeap(), 0, nameW
);
5230 es
->bEnableState
= (BOOL
) wParam
;
5231 EDIT_UpdateText(es
, NULL
, TRUE
);
5235 /* we do the proper erase in EDIT_WM_Paint */
5240 result
= (LRESULT
)es
->font
;
5244 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5247 case WM_GETTEXTLENGTH
:
5248 if (unicode
) result
= get_text_length(es
);
5249 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
5250 NULL
, 0, NULL
, NULL
);
5254 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5258 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
5262 result
= EDIT_WM_KillFocus(es
);
5265 case WM_LBUTTONDBLCLK
:
5266 result
= EDIT_WM_LButtonDblClk(es
);
5269 case WM_LBUTTONDOWN
:
5270 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5274 result
= EDIT_WM_LButtonUp(es
);
5277 case WM_MBUTTONDOWN
:
5278 result
= EDIT_WM_MButtonDown(es
);
5282 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5285 case WM_PRINTCLIENT
:
5287 EDIT_WM_Paint(es
, (HDC
)wParam
);
5295 EDIT_WM_SetFocus(es
);
5299 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
5303 /* FIXME: actually set an internal flag and behave accordingly */
5307 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
5312 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
5315 case WM_STYLECHANGED
:
5316 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
5319 case WM_STYLECHANGING
:
5320 result
= 0; /* See EDIT_WM_StyleChanged */
5324 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5332 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5337 int gcWheelDelta
= 0;
5338 UINT pulScrollLines
= 3;
5339 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5341 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
5342 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5345 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
5346 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
5348 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
5349 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
5350 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
5356 /* IME messages to make the edit control IME aware */
5357 case WM_IME_SETCONTEXT
:
5360 case WM_IME_STARTCOMPOSITION
:
5361 es
->composition_start
= es
->selection_end
;
5362 es
->composition_len
= 0;
5365 case WM_IME_COMPOSITION
:
5366 EDIT_ImeComposition(hwnd
, lParam
, es
);
5369 case WM_IME_ENDCOMPOSITION
:
5370 if (es
->composition_len
> 0)
5372 static const WCHAR empty_stringW
[] = {0};
5373 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5374 es
->selection_end
= es
->selection_start
;
5375 es
->composition_len
= 0;
5379 case WM_IME_COMPOSITIONFULL
:
5385 case WM_IME_CONTROL
:
5389 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5393 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
5395 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5400 /*********************************************************************
5402 * EditWndProc (USER32.@)
5404 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5406 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
5409 /*********************************************************************
5413 static LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5415 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
5418 /*********************************************************************
5419 * edit class descriptor
5421 static const WCHAR editW
[] = {'E','d','i','t',0};
5422 const struct builtin_class_descr EDIT_builtin_class
=
5425 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5426 EditWndProcA
, /* procA */
5427 EditWndProcW
, /* procW */
5429 sizeof(EDITSTATE
*), /* extra */
5431 sizeof(EDITSTATE
*) + sizeof(HANDLE16
), /* extra */
5433 IDC_IBEAM
, /* cursor */