4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
47 #include <wine/debug.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
50 WINE_DECLARE_DEBUG_CHANNEL(combo
);
51 WINE_DECLARE_DEBUG_CHANNEL(relay
);
53 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
54 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
55 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
56 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
59 * extra flags for EDITSTATE.flags field
61 #define EF_MODIFIED 0x0001 /* text has been modified */
62 #define EF_FOCUSED 0x0002 /* we have input focus */
63 #define EF_UPDATE 0x0004 /* notify parent of changed state */
64 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
65 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
66 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
67 wrapped line, instead of in front of the next character */
68 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
69 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
70 the text buffer if this is clear. */
71 #define EF_DIALOGMODE 0x0400 /* Indicates that we are inside a dialog window */
75 END_0
= 0, /* line ends with terminating '\0' character */
76 END_WRAP
, /* line is wrapped */
77 END_HARD
, /* line ends with a hard return '\r\n' */
78 END_SOFT
, /* line ends with a soft return '\r\r\n' */
79 END_RICH
/* line ends with a single '\n' */
82 typedef struct tagLINEDEF
{
83 INT length
; /* bruto length of a line in bytes */
84 INT net_length
; /* netto length of a line in visible characters */
86 INT width
; /* width of the line in pixels */
87 INT index
; /* line index into the buffer */
88 struct tagLINEDEF
*next
;
93 BOOL is_unicode
; /* how the control was created */
94 LPWSTR text
; /* the actual contents of the control */
95 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
96 UINT buffer_size
; /* the size of the buffer in characters */
97 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
98 HFONT font
; /* NULL means standard system font */
99 INT x_offset
; /* scroll offset for multi lines this is in pixels
100 for single lines it's in characters */
101 INT line_height
; /* height of a screen line in pixels */
102 INT char_width
; /* average character width in pixels */
103 DWORD style
; /* sane version of wnd->dwStyle */
104 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
105 INT undo_insert_count
; /* number of characters inserted in sequence */
106 UINT undo_position
; /* character index of the insertion and deletion */
107 LPWSTR undo_text
; /* deleted text */
108 UINT undo_buffer_size
; /* size of the deleted text buffer */
109 INT selection_start
; /* == selection_end if no selection */
110 INT selection_end
; /* == current caret position */
111 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
112 INT left_margin
; /* in pixels */
113 INT right_margin
; /* in pixels */
115 INT text_width
; /* width of the widest line in pixels for multi line controls
116 and just line width for single line controls */
117 INT region_posx
; /* Position of cursor relative to region: */
118 INT region_posy
; /* -1: to left, 0: within, 1: to right */
120 EDITWORDBREAKPROC16 word_break_proc16
;
122 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
123 INT line_count
; /* number of lines */
124 INT y_offset
; /* scroll offset in number of lines */
125 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
126 BOOL bEnableState
; /* flag keeping the enable state */
127 HWND hwndSelf
; /* the our window handle */
128 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
129 Even if parent will change, EN_* messages
130 should be sent to the first parent. */
131 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
133 * only for multi line controls
135 INT lock_count
; /* amount of re-entries in the EditWndProc */
138 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
139 HLOCAL hloc32W
; /* our unicode local memory block */
141 HLOCAL16 hloc16
; /* alias for 16-bit control receiving EM_GETHANDLE16
144 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
149 UINT composition_len
; /* length of composition, 0 == no composition */
150 int composition_start
; /* the character position for the composition */
154 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
155 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
157 /* used for disabled or read-only edit control */
158 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
160 { /* Notify parent which has created this edit control */ \
161 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
162 SendMessageW(es->hwndParent, WM_COMMAND, \
163 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
164 (LPARAM)(es->hwndSelf)); \
167 /*********************************************************************
172 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
174 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
178 /*********************************************************************
183 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
185 es
->undo_insert_count
= 0;
186 *es
->undo_text
= '\0';
190 /**********************************************************************
193 * Returns the window version in case Wine emulates a later version
194 * of windows than the application expects.
196 * In a number of cases when windows runs an application that was
197 * designed for an earlier windows version, windows reverts
198 * to "old" behaviour of that earlier version.
200 * An example is a disabled edit control that needs to be painted.
201 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
202 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
203 * applications with an expected version 0f 4.0 or higher.
206 static DWORD
get_app_version(void)
208 static DWORD version
;
211 DWORD dwEmulatedVersion
;
213 DWORD dwProcVersion
= GetProcessVersion(0);
215 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
216 GetVersionExW( &info
);
217 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
218 /* FIXME: this may not be 100% correct; see discussion on the
219 * wine developer list in Nov 1999 */
220 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
225 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
230 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
231 msg
= WM_CTLCOLORSTATIC
;
233 msg
= WM_CTLCOLOREDIT
;
235 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
236 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
238 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
243 /*********************************************************************
247 * Find the beginning of words.
248 * Note: unlike the specs for a WordBreakProc, this function only
249 * allows to be called without linebreaks between s[0] up to
250 * s[count - 1]. Remember it is only called
251 * internally, so we can decide this for ourselves.
254 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
258 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
268 if (s
[index
] == ' ') {
269 while (index
&& (s
[index
] == ' '))
272 while (index
&& (s
[index
] != ' '))
278 while (index
&& (s
[index
] != ' '))
291 while ((index
< count
) && (s
[index
] == ' ')) index
++;
293 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
295 while ((s
[index
] == ' ') && (index
< count
)) index
++;
300 ret
= (s
[index
] == ' ');
303 ERR("unknown action code, please report !\n");
310 /*********************************************************************
312 * EDIT_CallWordBreakProc
314 * Call appropriate WordBreakProc (internal or external).
316 * Note: The "start" argument should always be an index referring
317 * to es->text. The actual wordbreak proc might be
318 * 16 bit, so we can't always pass any 32 bit LPSTR.
319 * Hence we assume that es->text is the buffer that holds
320 * the string under examination (we can decide this for ourselves).
323 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
328 if (es
->word_break_proc16
) {
335 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
336 hglob16
= GlobalAlloc16(GMEM_MOVEABLE
| GMEM_ZEROINIT
, countA
);
337 segptr
= WOWGlobalLock16(hglob16
);
338 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, MapSL(segptr
), countA
, NULL
, NULL
);
339 args
[4] = SELECTOROF(segptr
);
340 args
[3] = OFFSETOF(segptr
);
344 WOWCallback16Ex((DWORD
)es
->word_break_proc16
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
345 ret
= LOWORD(result
);
346 GlobalUnlock16(hglob16
);
347 GlobalFree16(hglob16
);
349 else if (es
->word_break_proc
)
351 if (es
->word_break_proc
)
356 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
358 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
359 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
360 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
364 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
368 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
369 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
372 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
373 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
374 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
375 ret
= wbpA(textA
, index
, countA
, action
);
376 HeapFree(GetProcessHeap(), 0, textA
);
380 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
385 /*********************************************************************
387 * EDIT_BuildLineDefs_ML
389 * Build linked list of text lines.
390 * Lines can end with '\0' (last line), a character (if it is wrapped),
391 * a soft return '\r\r\n' or a hard return '\r\n'
394 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
398 LPWSTR current_position
, cp
;
400 LINEDEF
*current_line
;
401 LINEDEF
*previous_line
;
403 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
404 INT line_count
= es
->line_count
;
408 if (istart
== iend
&& delta
== 0)
411 dc
= GetDC(es
->hwndSelf
);
413 old_font
= SelectObject(dc
, es
->font
);
415 previous_line
= NULL
;
416 current_line
= es
->first_line_def
;
418 /* Find starting line. istart must lie inside an existing line or
419 * at the end of buffer */
421 if (istart
< current_line
->index
+ current_line
->length
||
422 current_line
->ending
== END_0
)
425 previous_line
= current_line
;
426 current_line
= current_line
->next
;
428 } while (current_line
);
430 if (!current_line
) /* Error occurred start is not inside previous buffer */
432 FIXME(" modification occurred outside buffer\n");
433 ReleaseDC(es
->hwndSelf
, dc
);
437 /* Remember start of modifications in order to calculate update region */
438 nstart_line
= line_index
;
439 nstart_index
= current_line
->index
;
441 /* We must start to reformat from the previous line since the modifications
442 * may have caused the line to wrap upwards. */
443 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
446 current_line
= previous_line
;
448 start_line
= current_line
;
450 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
451 current_position
= es
->text
+ current_line
->index
;
453 if (current_line
!= start_line
)
455 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
457 /* The buffer has been expanded, create a new line and
458 insert it into the link list */
459 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
460 if (new_line
== NULL
)
462 new_line
->next
= previous_line
->next
;
463 previous_line
->next
= new_line
;
464 current_line
= new_line
;
467 else if (current_line
->index
+ delta
< current_position
- es
->text
)
469 /* The previous line merged with this line so we delete this extra entry */
470 previous_line
->next
= current_line
->next
;
471 HeapFree(GetProcessHeap(), 0, current_line
);
472 current_line
= previous_line
->next
;
476 else /* current_line->index + delta == current_position */
478 if (current_position
- es
->text
> iend
)
479 break; /* We reached end of line modifications */
480 /* else recalculate this line */
484 current_line
->index
= current_position
- es
->text
;
485 orig_net_length
= current_line
->net_length
;
487 /* Find end of line */
488 cp
= current_position
;
490 if (*cp
== '\n') break;
491 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
496 /* Mark type of line termination */
498 current_line
->ending
= END_0
;
499 current_line
->net_length
= strlenW(current_position
);
500 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
501 current_line
->ending
= END_SOFT
;
502 current_line
->net_length
= cp
- current_position
- 1;
503 } else if (*cp
== '\n') {
504 current_line
->ending
= END_RICH
;
505 current_line
->net_length
= cp
- current_position
;
507 current_line
->ending
= END_HARD
;
508 current_line
->net_length
= cp
- current_position
;
511 /* Calculate line width */
512 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
513 current_position
, current_line
->net_length
,
514 es
->tabs_count
, es
->tabs
));
516 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
517 if (!(es
->style
& ES_AUTOHSCROLL
)) {
518 if (current_line
->width
> fw
) {
523 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
524 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
525 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
526 current_position
, next
, es
->tabs_count
, es
->tabs
));
527 } while (current_line
->width
<= fw
);
528 if (!prev
) { /* Didn't find a line break so force a break */
533 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
534 current_position
, next
, es
->tabs_count
, es
->tabs
));
535 } while (current_line
->width
<= fw
);
540 /* If the first line we are calculating, wrapped before istart, we must
541 * adjust istart in order for this to be reflected in the update region. */
542 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
543 istart
= current_line
->index
+ prev
;
544 /* else if we are updating the previous line before the first line we
545 * are re-calculating and it expanded */
546 else if (current_line
== start_line
&&
547 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
549 /* Line expanded due to an upwards line wrap so we must partially include
550 * previous line in update region */
551 nstart_line
= line_index
;
552 nstart_index
= current_line
->index
;
553 istart
= current_line
->index
+ orig_net_length
;
556 current_line
->net_length
= prev
;
557 current_line
->ending
= END_WRAP
;
558 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
559 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
561 else if (current_line
== start_line
&&
562 current_line
->index
!= nstart_index
&&
563 orig_net_length
< current_line
->net_length
) {
564 /* The previous line expanded but it's still not as wide as the client rect */
565 /* The expansion is due to an upwards line wrap so we must partially include
566 it in the update region */
567 nstart_line
= line_index
;
568 nstart_index
= current_line
->index
;
569 istart
= current_line
->index
+ orig_net_length
;
574 /* Adjust length to include line termination */
575 switch (current_line
->ending
) {
577 current_line
->length
= current_line
->net_length
+ 3;
580 current_line
->length
= current_line
->net_length
+ 1;
583 current_line
->length
= current_line
->net_length
+ 2;
587 current_line
->length
= current_line
->net_length
;
590 es
->text_width
= max(es
->text_width
, current_line
->width
);
591 current_position
+= current_line
->length
;
592 previous_line
= current_line
;
593 current_line
= current_line
->next
;
595 } while (previous_line
->ending
!= END_0
);
597 /* Finish adjusting line indexes by delta or remove hanging lines */
598 if (previous_line
->ending
== END_0
)
600 LINEDEF
*pnext
= NULL
;
602 previous_line
->next
= NULL
;
605 pnext
= current_line
->next
;
606 HeapFree(GetProcessHeap(), 0, current_line
);
607 current_line
= pnext
;
615 current_line
->index
+= delta
;
616 current_line
= current_line
->next
;
620 /* Calculate rest of modification rectangle */
625 * We calculate two rectangles. One for the first line which may have
626 * an indent with respect to the format rect. The other is a format-width
627 * rectangle that spans the rest of the lines that changed or moved.
629 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
630 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
631 rc
.bottom
= rc
.top
+ es
->line_height
;
632 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
633 rc
.left
= es
->format_rect
.left
;
635 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
636 es
->text
+ nstart_index
, istart
- nstart_index
,
637 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
638 rc
.right
= es
->format_rect
.right
;
639 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
642 rc
.left
= es
->format_rect
.left
;
643 rc
.right
= es
->format_rect
.right
;
645 * If lines were added or removed we must re-paint the remainder of the
646 * lines since the remaining lines were either shifted up or down.
648 if (line_count
< es
->line_count
) /* We added lines */
649 rc
.bottom
= es
->line_count
* es
->line_height
;
650 else if (line_count
> es
->line_count
) /* We removed lines */
651 rc
.bottom
= line_count
* es
->line_height
;
653 rc
.bottom
= line_index
* es
->line_height
;
654 rc
.bottom
+= es
->format_rect
.top
;
655 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
656 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
657 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
658 DeleteObject(tmphrgn
);
662 SelectObject(dc
, old_font
);
664 ReleaseDC(es
->hwndSelf
, dc
);
668 static inline UINT
get_text_length(EDITSTATE
*es
)
670 if(es
->text_length
== (UINT
)-1)
671 es
->text_length
= strlenW(es
->text
);
672 return es
->text_length
;
675 /*********************************************************************
677 * EDIT_GetPasswordPointer_SL
679 * note: caller should free the (optionally) allocated buffer
682 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
684 if (es
->style
& ES_PASSWORD
) {
685 INT len
= get_text_length(es
);
686 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
690 while(len
) text
[--len
] = es
->password_char
;
697 /*********************************************************************
699 * EDIT_CalcLineWidth_SL
702 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
709 text
= EDIT_GetPasswordPointer_SL(es
);
711 dc
= GetDC(es
->hwndSelf
);
713 old_font
= SelectObject(dc
, es
->font
);
715 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
718 SelectObject(dc
, old_font
);
719 ReleaseDC(es
->hwndSelf
, dc
);
721 if (es
->style
& ES_PASSWORD
)
722 HeapFree(GetProcessHeap(), 0, text
);
724 es
->text_width
= size
.cx
;
727 /*********************************************************************
731 * Beware: This is not the function called on EM_CHARFROMPOS
732 * The position _can_ be outside the formatting / client
734 * The return value is only the character index
737 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
742 INT x_high
= 0, x_low
= 0;
744 if (es
->style
& ES_MULTILINE
) {
745 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
747 LINEDEF
*line_def
= es
->first_line_def
;
749 while ((line
> 0) && line_def
->next
) {
750 line_index
+= line_def
->length
;
751 line_def
= line_def
->next
;
754 x
+= es
->x_offset
- es
->format_rect
.left
;
755 if (es
->style
& ES_RIGHT
)
756 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
757 else if (es
->style
& ES_CENTER
)
758 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
759 if (x
>= line_def
->width
) {
761 *after_wrap
= (line_def
->ending
== END_WRAP
);
762 return line_index
+ line_def
->net_length
;
769 dc
= GetDC(es
->hwndSelf
);
771 old_font
= SelectObject(dc
, es
->font
);
773 high
= line_index
+ line_def
->net_length
+ 1;
774 while (low
< high
- 1)
776 INT mid
= (low
+ high
) / 2;
777 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
786 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
792 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
793 (line_def
->ending
== END_WRAP
));
799 x
-= es
->format_rect
.left
;
805 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
806 if (es
->style
& ES_RIGHT
)
808 else if (es
->style
& ES_CENTER
)
812 text
= EDIT_GetPasswordPointer_SL(es
);
813 dc
= GetDC(es
->hwndSelf
);
815 old_font
= SelectObject(dc
, es
->font
);
819 INT high
= es
->x_offset
;
820 while (low
< high
- 1)
822 INT mid
= (low
+ high
) / 2;
823 GetTextExtentPoint32W( dc
, text
+ mid
,
824 es
->x_offset
- mid
, &size
);
833 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
840 INT low
= es
->x_offset
;
841 INT high
= get_text_length(es
) + 1;
842 while (low
< high
- 1)
844 INT mid
= (low
+ high
) / 2;
845 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
846 mid
- es
->x_offset
, &size
);
855 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
860 if (es
->style
& ES_PASSWORD
)
861 HeapFree(GetProcessHeap(), 0, text
);
864 SelectObject(dc
, old_font
);
865 ReleaseDC(es
->hwndSelf
, dc
);
870 /*********************************************************************
874 * adjusts the point to be within the formatting rectangle
875 * (so CharFromPos returns the nearest _visible_ character)
878 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
880 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
881 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
885 /*********************************************************************
890 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
895 if (!(es
->style
& ES_MULTILINE
))
897 if (index
> (INT
)get_text_length(es
))
898 return es
->line_count
- 1;
900 index
= min(es
->selection_start
, es
->selection_end
);
903 line_def
= es
->first_line_def
;
904 index
-= line_def
->length
;
905 while ((index
>= 0) && line_def
->next
) {
907 line_def
= line_def
->next
;
908 index
-= line_def
->length
;
914 /*********************************************************************
919 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
922 const LINEDEF
*line_def
;
924 if (!(es
->style
& ES_MULTILINE
))
926 if (line
>= es
->line_count
)
930 line_def
= es
->first_line_def
;
932 INT index
= es
->selection_end
- line_def
->length
;
933 while ((index
>= 0) && line_def
->next
) {
934 line_index
+= line_def
->length
;
935 line_def
= line_def
->next
;
936 index
-= line_def
->length
;
940 line_index
+= line_def
->length
;
941 line_def
= line_def
->next
;
949 /*********************************************************************
954 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
958 if (!(es
->style
& ES_MULTILINE
))
959 return get_text_length(es
);
962 /* get the number of remaining non-selected chars of selected lines */
963 INT32 l
; /* line number */
964 INT32 li
; /* index of first char in line */
966 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
967 /* # chars before start of selection area */
968 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
969 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
970 /* # chars after end of selection */
971 li
= EDIT_EM_LineIndex(es
, l
);
972 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
975 line_def
= es
->first_line_def
;
976 index
-= line_def
->length
;
977 while ((index
>= 0) && line_def
->next
) {
978 line_def
= line_def
->next
;
979 index
-= line_def
->length
;
981 return line_def
->net_length
;
985 /*********************************************************************
990 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
992 INT len
= get_text_length(es
);
1005 index
= min(index
, len
);
1006 dc
= GetDC(es
->hwndSelf
);
1008 old_font
= SelectObject(dc
, es
->font
);
1009 if (es
->style
& ES_MULTILINE
) {
1010 l
= EDIT_EM_LineFromChar(es
, index
);
1011 y
= (l
- es
->y_offset
) * es
->line_height
;
1012 li
= EDIT_EM_LineIndex(es
, l
);
1013 if (after_wrap
&& (li
== index
) && l
) {
1015 line_def
= es
->first_line_def
;
1017 line_def
= line_def
->next
;
1020 if (line_def
->ending
== END_WRAP
) {
1022 y
-= es
->line_height
;
1023 li
= EDIT_EM_LineIndex(es
, l
);
1027 line_def
= es
->first_line_def
;
1028 while (line_def
->index
!= li
)
1029 line_def
= line_def
->next
;
1031 ll
= line_def
->net_length
;
1032 lw
= line_def
->width
;
1034 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1035 if (es
->style
& ES_RIGHT
)
1037 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
1038 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1041 else if (es
->style
& ES_CENTER
)
1043 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1044 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1049 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1050 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1053 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
1054 if (index
< es
->x_offset
) {
1055 GetTextExtentPoint32W(dc
, text
+ index
,
1056 es
->x_offset
- index
, &size
);
1059 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
1060 index
- es
->x_offset
, &size
);
1063 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1065 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1066 if (w
> es
->text_width
)
1068 if (es
->style
& ES_RIGHT
)
1069 x
+= w
- es
->text_width
;
1070 else if (es
->style
& ES_CENTER
)
1071 x
+= (w
- es
->text_width
) / 2;
1076 if (es
->style
& ES_PASSWORD
)
1077 HeapFree(GetProcessHeap(), 0, text
);
1079 x
+= es
->format_rect
.left
;
1080 y
+= es
->format_rect
.top
;
1082 SelectObject(dc
, old_font
);
1083 ReleaseDC(es
->hwndSelf
, dc
);
1084 return MAKELONG((INT16
)x
, (INT16
)y
);
1088 /*********************************************************************
1092 * Calculates the bounding rectangle for a line from a starting
1093 * column to an ending column.
1096 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1098 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1100 if (es
->style
& ES_MULTILINE
)
1101 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1103 rc
->top
= es
->format_rect
.top
;
1104 rc
->bottom
= rc
->top
+ es
->line_height
;
1105 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1106 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1110 static inline void text_buffer_changed(EDITSTATE
*es
)
1112 es
->text_length
= (UINT
)-1;
1115 /*********************************************************************
1119 * This acts as a LocalLock16(), but it locks only once. This way
1120 * you can call it whenever you like, without unlocking.
1122 * Initially the edit control allocates a HLOCAL32 buffer
1123 * (32 bit linear memory handler). However, 16 bit application
1124 * might send an EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1125 * handler). From that moment on we have to keep using this 16 bit memory
1126 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1127 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1131 static void EDIT_LockBuffer(EDITSTATE
*es
)
1134 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1135 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1141 BOOL _16bit
= FALSE
;
1148 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1149 textA
= LocalLock(es
->hloc32A
);
1150 countA
= strlen(textA
) + 1;
1155 HANDLE16 oldDS
= stack16
->ds
;
1156 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1157 stack16
->ds
= hInstance
;
1158 textA
= MapSL(LocalLock16(es
->hloc16
));
1159 stack16
->ds
= oldDS
;
1160 countA
= strlen(textA
) + 1;
1166 ERR("no buffer ... please report\n");
1173 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
1174 TRACE("%d bytes translated to %d WCHARs\n", countA
, countW_new
);
1175 if(countW_new
> es
->buffer_size
+ 1)
1177 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1178 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1179 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1182 es
->hloc32W
= hloc32W_new
;
1183 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1184 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1187 WARN("FAILED! Will synchronize partially\n");
1191 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1192 es
->text
= LocalLock(es
->hloc32W
);
1196 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, es
->text
, es
->buffer_size
+ 1);
1200 HANDLE16 oldDS
= stack16
->ds
;
1201 stack16
->ds
= hInstance
;
1202 LocalUnlock16(es
->hloc16
);
1203 stack16
->ds
= oldDS
;
1207 LocalUnlock(es
->hloc32A
);
1210 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1215 /*********************************************************************
1220 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1223 /* Edit window might be already destroyed */
1224 if(!IsWindow(es
->hwndSelf
))
1226 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1230 if (!es
->lock_count
) {
1231 ERR("lock_count == 0 ... please report\n");
1235 ERR("es->text == 0 ... please report\n");
1239 if (force
|| (es
->lock_count
== 1)) {
1243 UINT countW
= get_text_length(es
) + 1;
1245 STACK16FRAME
* stack16
= NULL
;
1251 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1252 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1253 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1254 countA
= LocalSize(es
->hloc32A
);
1255 if(countA_new
> countA
)
1258 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1259 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1260 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1263 es
->hloc32A
= hloc32A_new
;
1264 countA
= LocalSize(hloc32A_new
);
1265 TRACE("Real new size %d bytes\n", countA
);
1268 WARN("FAILED! Will synchronize partially\n");
1270 textA
= LocalLock(es
->hloc32A
);
1275 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1277 TRACE("Synchronizing with 16-bit ANSI buffer\n");
1278 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1280 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
1281 oldDS
= stack16
->ds
;
1282 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
1284 countA
= LocalSize16(es
->hloc16
);
1285 if(countA_new
> countA
)
1287 HLOCAL16 hloc16_new
;
1288 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1289 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1290 hloc16_new
= LocalReAlloc16(es
->hloc16
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1293 es
->hloc16
= hloc16_new
;
1294 countA
= LocalSize16(hloc16_new
);
1295 TRACE("Real new size %d bytes\n", countA
);
1298 WARN("FAILED! Will synchronize partially\n");
1300 textA
= MapSL(LocalLock16(es
->hloc16
));
1306 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, textA
, countA
, NULL
, NULL
);
1309 LocalUnlock16(es
->hloc16
);
1312 LocalUnlock(es
->hloc32A
);
1316 if (stack16
) stack16
->ds
= oldDS
;
1318 LocalUnlock(es
->hloc32W
);
1322 ERR("no buffer ... please report\n");
1330 /*********************************************************************
1334 * Try to fit size + 1 characters in the buffer.
1336 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1340 if (size
<= es
->buffer_size
)
1343 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1345 /* Force edit to unlock it's buffer. es->text now NULL */
1346 EDIT_UnlockBuffer(es
, TRUE
);
1349 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1350 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1351 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1352 es
->hloc32W
= hNew32W
;
1353 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1357 EDIT_LockBuffer(es
);
1359 if (es
->buffer_size
< size
) {
1360 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1361 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1364 TRACE("We now have %d+1\n", es
->buffer_size
);
1370 /*********************************************************************
1374 * Try to fit size + 1 bytes in the undo buffer.
1377 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1381 if (size
<= es
->undo_buffer_size
)
1384 TRACE("trying to ReAlloc to %d+1\n", size
);
1386 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1387 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1388 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1393 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1399 /*********************************************************************
1401 * EDIT_UpdateTextRegion
1404 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1406 if (es
->flags
& EF_UPDATE
) {
1407 es
->flags
&= ~EF_UPDATE
;
1408 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1410 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1414 /*********************************************************************
1419 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1421 if (es
->flags
& EF_UPDATE
) {
1422 es
->flags
&= ~EF_UPDATE
;
1423 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1425 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1428 /*********************************************************************
1430 * EDIT_SL_InvalidateText
1432 * Called from EDIT_InvalidateText().
1433 * Does the job for single-line controls only.
1436 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1441 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1442 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1443 EDIT_UpdateText(es
, &rc
, TRUE
);
1447 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
1449 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1453 /*********************************************************************
1455 * EDIT_ML_InvalidateText
1457 * Called from EDIT_InvalidateText().
1458 * Does the job for multi-line controls only.
1461 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1463 INT vlc
= get_vertical_line_count(es
);
1464 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1465 INT el
= EDIT_EM_LineFromChar(es
, end
);
1474 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1477 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1478 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1479 if (sl
< es
->y_offset
) {
1483 if (el
> es
->y_offset
+ vlc
) {
1484 el
= es
->y_offset
+ vlc
;
1485 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1487 GetClientRect(es
->hwndSelf
, &rc1
);
1488 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1490 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1491 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1492 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1494 EDIT_GetLineRect(es
, sl
, sc
,
1495 EDIT_EM_LineLength(es
,
1496 EDIT_EM_LineIndex(es
, sl
)),
1498 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1499 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1500 for (l
= sl
+ 1 ; l
< el
; l
++) {
1501 EDIT_GetLineRect(es
, l
, 0,
1502 EDIT_EM_LineLength(es
,
1503 EDIT_EM_LineIndex(es
, l
)),
1505 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1506 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1508 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1509 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1510 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1515 /*********************************************************************
1517 * EDIT_InvalidateText
1519 * Invalidate the text from offset start up to, but not including,
1520 * offset end. Useful for (re)painting the selection.
1521 * Regions outside the linewidth are not invalidated.
1522 * end == -1 means end == TextLength.
1523 * start and end need not be ordered.
1526 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1532 end
= get_text_length(es
);
1540 if (es
->style
& ES_MULTILINE
)
1541 EDIT_ML_InvalidateText(es
, start
, end
);
1543 EDIT_SL_InvalidateText(es
, start
, end
);
1547 /*********************************************************************
1551 * note: unlike the specs say: the order of start and end
1552 * _is_ preserved in Windows. (i.e. start can be > end)
1553 * In other words: this handler is OK
1556 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1558 UINT old_start
= es
->selection_start
;
1559 UINT old_end
= es
->selection_end
;
1560 UINT len
= get_text_length(es
);
1562 if (start
== (UINT
)-1) {
1563 start
= es
->selection_end
;
1564 end
= es
->selection_end
;
1566 start
= min(start
, len
);
1567 end
= min(end
, len
);
1569 es
->selection_start
= start
;
1570 es
->selection_end
= end
;
1572 es
->flags
|= EF_AFTER_WRAP
;
1574 es
->flags
&= ~EF_AFTER_WRAP
;
1575 /* Compute the necessary invalidation region. */
1576 /* Note that we don't need to invalidate regions which have
1577 * "never" been selected, or those which are "still" selected.
1578 * In fact, every time we hit a selection boundary, we can
1579 * *toggle* whether we need to invalidate. Thus we can optimize by
1580 * *sorting* the interval endpoints. Let's assume that we sort them
1582 * start <= end <= old_start <= old_end
1583 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1584 * in 5 comparisons; i.e. it is impossible to do better than the
1586 ORDER_UINT(end
, old_end
);
1587 ORDER_UINT(start
, old_start
);
1588 ORDER_UINT(old_start
, old_end
);
1589 ORDER_UINT(start
, end
);
1590 /* Note that at this point 'end' and 'old_start' are not in order, but
1591 * start is definitely the min. and old_end is definitely the max. */
1592 if (end
!= old_start
)
1596 * ORDER_UINT32(end, old_start);
1597 * EDIT_InvalidateText(es, start, end);
1598 * EDIT_InvalidateText(es, old_start, old_end);
1599 * in place of the following if statement.
1600 * (That would complete the optimal five-comparison four-element sort.)
1602 if (old_start
> end
)
1604 EDIT_InvalidateText(es
, start
, end
);
1605 EDIT_InvalidateText(es
, old_start
, old_end
);
1609 EDIT_InvalidateText(es
, start
, old_start
);
1610 EDIT_InvalidateText(es
, end
, old_end
);
1613 else EDIT_InvalidateText(es
, start
, old_end
);
1617 /*********************************************************************
1619 * EDIT_UpdateScrollInfo
1622 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1624 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1627 si
.cbSize
= sizeof(SCROLLINFO
);
1628 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1630 si
.nMax
= es
->line_count
- 1;
1631 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1632 si
.nPos
= es
->y_offset
;
1633 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1634 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1635 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1638 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1641 si
.cbSize
= sizeof(SCROLLINFO
);
1642 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1644 si
.nMax
= es
->text_width
- 1;
1645 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1646 si
.nPos
= es
->x_offset
;
1647 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1648 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1649 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1654 /*********************************************************************
1656 * EDIT_EM_LineScroll_internal
1658 * Version of EDIT_EM_LineScroll for internal use.
1659 * It doesn't refuse if ES_MULTILINE is set and assumes that
1660 * dx is in pixels, dy - in lines.
1663 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1666 INT x_offset_in_pixels
;
1667 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1670 if (es
->style
& ES_MULTILINE
)
1672 x_offset_in_pixels
= es
->x_offset
;
1677 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1680 if (-dx
> x_offset_in_pixels
)
1681 dx
= -x_offset_in_pixels
;
1682 if (dx
> es
->text_width
- x_offset_in_pixels
)
1683 dx
= es
->text_width
- x_offset_in_pixels
;
1684 nyoff
= max(0, es
->y_offset
+ dy
);
1685 if (nyoff
>= es
->line_count
- lines_per_page
)
1686 nyoff
= max(0, es
->line_count
- lines_per_page
);
1687 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1692 es
->y_offset
= nyoff
;
1693 if(es
->style
& ES_MULTILINE
)
1696 es
->x_offset
+= dx
/ es
->char_width
;
1698 GetClientRect(es
->hwndSelf
, &rc1
);
1699 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1700 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1701 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1702 /* force scroll info update */
1703 EDIT_UpdateScrollInfo(es
);
1705 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1706 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1707 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1708 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1712 /*********************************************************************
1716 * NOTE: dx is in average character widths, dy - in lines;
1719 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1721 if (!(es
->style
& ES_MULTILINE
))
1724 dx
*= es
->char_width
;
1725 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1729 /*********************************************************************
1734 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1738 if (!(es
->style
& ES_MULTILINE
))
1739 return (LRESULT
)FALSE
;
1749 if (es
->y_offset
< es
->line_count
- 1)
1754 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1757 if (es
->y_offset
< es
->line_count
- 1)
1758 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1761 return (LRESULT
)FALSE
;
1764 INT vlc
= get_vertical_line_count(es
);
1765 /* check if we are going to move too far */
1766 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1767 dy
= es
->line_count
- vlc
- es
->y_offset
;
1769 /* Notification is done in EDIT_EM_LineScroll */
1771 EDIT_EM_LineScroll(es
, 0, dy
);
1774 return MAKELONG((SHORT
)dy
, (BOOL
)TRUE
);
1776 return MAKELONG((INT16
)dy
, (BOOL16
)TRUE
);
1781 /*********************************************************************
1786 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1789 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1790 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1791 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1795 /*********************************************************************
1800 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1802 if (es
->style
& ES_MULTILINE
) {
1806 INT cw
= es
->char_width
;
1811 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1812 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1813 vlc
= get_vertical_line_count(es
);
1814 if (l
>= es
->y_offset
+ vlc
)
1815 dy
= l
- vlc
+ 1 - es
->y_offset
;
1816 if (l
< es
->y_offset
)
1817 dy
= l
- es
->y_offset
;
1818 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1819 if (x
< es
->format_rect
.left
)
1820 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1821 if (x
> es
->format_rect
.right
)
1822 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1823 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1825 /* check if we are going to move too far */
1826 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1827 dx
= es
->text_width
- ww
- es
->x_offset
;
1828 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1829 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1836 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1837 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1838 if (x
< es
->format_rect
.left
) {
1839 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1842 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1843 } while ((x
< goal
) && es
->x_offset
);
1844 /* FIXME: use ScrollWindow() somehow to improve performance */
1845 EDIT_UpdateText(es
, NULL
, TRUE
);
1846 } else if (x
> es
->format_rect
.right
) {
1848 INT len
= get_text_length(es
);
1849 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1852 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1853 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1854 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1855 /* FIXME: use ScrollWindow() somehow to improve performance */
1856 EDIT_UpdateText(es
, NULL
, TRUE
);
1860 if(es
->flags
& EF_FOCUSED
)
1861 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1865 /*********************************************************************
1870 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1872 INT e
= es
->selection_end
;
1876 if ((es
->style
& ES_MULTILINE
) && e
&&
1877 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1879 if (e
&& (es
->text
[e
- 1] == '\r'))
1883 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1884 EDIT_EM_ScrollCaret(es
);
1888 /*********************************************************************
1892 * Only for multi line controls
1893 * Move the caret one line down, on a column with the nearest
1894 * x coordinate on the screen (might be a different column).
1897 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1899 INT s
= es
->selection_start
;
1900 INT e
= es
->selection_end
;
1901 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1902 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1903 INT x
= (short)LOWORD(pos
);
1904 INT y
= (short)HIWORD(pos
);
1906 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1909 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1910 EDIT_EM_ScrollCaret(es
);
1914 /*********************************************************************
1919 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1921 BOOL after_wrap
= FALSE
;
1924 /* Pass a high value in x to make sure of receiving the end of the line */
1925 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1926 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1927 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1929 e
= get_text_length(es
);
1930 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1931 EDIT_EM_ScrollCaret(es
);
1935 /*********************************************************************
1940 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1942 INT e
= es
->selection_end
;
1946 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1947 if (es
->text
[e
] == '\n')
1949 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1953 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1954 EDIT_EM_ScrollCaret(es
);
1958 /*********************************************************************
1962 * Home key: move to beginning of line.
1965 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1969 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1970 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1971 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1972 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1975 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1976 EDIT_EM_ScrollCaret(es
);
1980 /*********************************************************************
1982 * EDIT_MovePageDown_ML
1984 * Only for multi line controls
1985 * Move the caret one page down, on a column with the nearest
1986 * x coordinate on the screen (might be a different column).
1989 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1991 INT s
= es
->selection_start
;
1992 INT e
= es
->selection_end
;
1993 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1994 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1995 INT x
= (short)LOWORD(pos
);
1996 INT y
= (short)HIWORD(pos
);
1998 e
= EDIT_CharFromPos(es
, x
,
1999 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2003 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2004 EDIT_EM_ScrollCaret(es
);
2008 /*********************************************************************
2010 * EDIT_MovePageUp_ML
2012 * Only for multi line controls
2013 * Move the caret one page up, on a column with the nearest
2014 * x coordinate on the screen (might be a different column).
2017 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2019 INT s
= es
->selection_start
;
2020 INT e
= es
->selection_end
;
2021 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2022 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2023 INT x
= (short)LOWORD(pos
);
2024 INT y
= (short)HIWORD(pos
);
2026 e
= EDIT_CharFromPos(es
, x
,
2027 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2031 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2032 EDIT_EM_ScrollCaret(es
);
2036 /*********************************************************************
2040 * Only for multi line controls
2041 * Move the caret one line up, on a column with the nearest
2042 * x coordinate on the screen (might be a different column).
2045 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2047 INT s
= es
->selection_start
;
2048 INT e
= es
->selection_end
;
2049 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2050 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2051 INT x
= (short)LOWORD(pos
);
2052 INT y
= (short)HIWORD(pos
);
2054 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2057 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2058 EDIT_EM_ScrollCaret(es
);
2062 /*********************************************************************
2064 * EDIT_MoveWordBackward
2067 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2069 INT s
= es
->selection_start
;
2070 INT e
= es
->selection_end
;
2075 l
= EDIT_EM_LineFromChar(es
, e
);
2076 ll
= EDIT_EM_LineLength(es
, e
);
2077 li
= EDIT_EM_LineIndex(es
, l
);
2080 li
= EDIT_EM_LineIndex(es
, l
- 1);
2081 e
= li
+ EDIT_EM_LineLength(es
, li
);
2084 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2088 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2089 EDIT_EM_ScrollCaret(es
);
2093 /*********************************************************************
2095 * EDIT_MoveWordForward
2098 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2100 INT s
= es
->selection_start
;
2101 INT e
= es
->selection_end
;
2106 l
= EDIT_EM_LineFromChar(es
, e
);
2107 ll
= EDIT_EM_LineLength(es
, e
);
2108 li
= EDIT_EM_LineIndex(es
, l
);
2110 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2111 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2113 e
= li
+ EDIT_CallWordBreakProc(es
,
2114 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2118 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2119 EDIT_EM_ScrollCaret(es
);
2123 /*********************************************************************
2128 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2132 LOGFONTW underline_font
;
2133 HFONT hUnderline
= 0;
2142 BkMode
= GetBkMode(dc
);
2143 BkColor
= GetBkColor(dc
);
2144 TextColor
= GetTextColor(dc
);
2146 if (es
->composition_len
== 0)
2148 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2149 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2150 SetBkMode( dc
, OPAQUE
);
2154 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2155 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2156 underline_font
.lfUnderline
= TRUE
;
2157 hUnderline
= CreateFontIndirectW(&underline_font
);
2158 old_font
= SelectObject(dc
,hUnderline
);
2161 li
= EDIT_EM_LineIndex(es
, line
);
2162 if (es
->style
& ES_MULTILINE
) {
2163 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2164 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2166 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2167 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2168 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2170 if (es
->style
& ES_PASSWORD
)
2171 HeapFree(GetProcessHeap(), 0, text
);
2174 if (es
->composition_len
== 0)
2176 SetBkColor(dc
, BkColor
);
2177 SetTextColor(dc
, TextColor
);
2178 SetBkMode( dc
, BkMode
);
2183 SelectObject(dc
,old_font
);
2185 DeleteObject(hUnderline
);
2192 /*********************************************************************
2197 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2199 INT s
= es
->selection_start
;
2200 INT e
= es
->selection_end
;
2207 if (es
->style
& ES_MULTILINE
) {
2208 INT vlc
= get_vertical_line_count(es
);
2210 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2215 TRACE("line=%d\n", line
);
2217 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2218 x
= (short)LOWORD(pos
);
2219 y
= (short)HIWORD(pos
);
2220 li
= EDIT_EM_LineIndex(es
, line
);
2221 ll
= EDIT_EM_LineLength(es
, li
);
2222 s
= min(es
->selection_start
, es
->selection_end
);
2223 e
= max(es
->selection_start
, es
->selection_end
);
2224 s
= min(li
+ ll
, max(li
, s
));
2225 e
= min(li
+ ll
, max(li
, e
));
2226 if (rev
&& (s
!= e
) &&
2227 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2228 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2229 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2230 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2232 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2236 /*********************************************************************
2238 * EDIT_AdjustFormatRect
2240 * Adjusts the format rectangle for the current font and the
2241 * current client rectangle.
2244 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2248 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2249 if (es
->style
& ES_MULTILINE
)
2251 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2253 vlc
= get_vertical_line_count(es
);
2254 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2256 /* correct es->x_offset */
2257 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2258 max_x_offset
= es
->text_width
- fw
;
2259 if(max_x_offset
< 0) max_x_offset
= 0;
2260 if(es
->x_offset
> max_x_offset
)
2261 es
->x_offset
= max_x_offset
;
2263 /* correct es->y_offset */
2264 max_y_offset
= es
->line_count
- vlc
;
2265 if(max_y_offset
< 0) max_y_offset
= 0;
2266 if(es
->y_offset
> max_y_offset
)
2267 es
->y_offset
= max_y_offset
;
2269 /* force scroll info update */
2270 EDIT_UpdateScrollInfo(es
);
2273 /* Windows doesn't care to fix text placement for SL controls */
2274 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2276 /* Always stay within the client area */
2277 GetClientRect(es
->hwndSelf
, &ClientRect
);
2278 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2280 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2281 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2283 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2287 /*********************************************************************
2291 * note: this is not (exactly) the handler called on EM_SETRECTNP
2292 * it is also used to set the rect of a single line control
2295 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2299 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2301 CopyRect(&es
->format_rect
, rc
);
2303 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2304 es
->format_rect
.left
++;
2305 es
->format_rect
.right
--;
2307 if (es
->format_rect
.bottom
- es
->format_rect
.top
2308 >= es
->line_height
+ 2)
2310 es
->format_rect
.top
++;
2311 es
->format_rect
.bottom
--;
2314 else if (es
->style
& WS_BORDER
) {
2315 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2316 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2317 es
->format_rect
.left
+= bw
;
2318 es
->format_rect
.right
-= bw
;
2319 if (es
->format_rect
.bottom
- es
->format_rect
.top
2320 >= es
->line_height
+ 2 * bh
)
2322 es
->format_rect
.top
+= bh
;
2323 es
->format_rect
.bottom
-= bh
;
2327 es
->format_rect
.left
+= es
->left_margin
;
2328 es
->format_rect
.right
-= es
->right_margin
;
2329 EDIT_AdjustFormatRect(es
);
2333 /*********************************************************************
2337 * returns line number (not index) in high-order word of result.
2338 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2339 * to Richedit, not to the edit control. Original documentation is valid.
2340 * FIXME: do the specs mean to return -1 if outside client area or
2341 * if outside formatting rectangle ???
2344 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2352 GetClientRect(es
->hwndSelf
, &rc
);
2353 if (!PtInRect(&rc
, pt
))
2356 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2357 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2361 /*********************************************************************
2365 * Enable or disable soft breaks.
2367 * This means: insert or remove the soft linebreak character (\r\r\n).
2368 * Take care to check if the text still fits the buffer after insertion.
2369 * If not, notify with EN_ERRSPACE.
2372 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2374 es
->flags
&= ~EF_USE_SOFTBRK
;
2376 es
->flags
|= EF_USE_SOFTBRK
;
2377 FIXME("soft break enabled, not implemented\n");
2383 /*********************************************************************
2387 * Hopefully this won't fire back at us.
2388 * We always start with a fixed buffer in the local heap.
2389 * Despite of the documentation says that the local heap is used
2390 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2391 * buffer on the local heap.
2394 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2398 if (!(es
->style
& ES_MULTILINE
))
2402 hLocal
= es
->hloc32W
;
2408 UINT countA
, alloc_size
;
2409 TRACE("Allocating 32-bit ANSI alias buffer\n");
2410 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2411 alloc_size
= ROUND_TO_GROW(countA
);
2412 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2414 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2417 textA
= LocalLock(es
->hloc32A
);
2418 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2419 LocalUnlock(es
->hloc32A
);
2421 hLocal
= es
->hloc32A
;
2424 es
->flags
|= EF_APP_HAS_HANDLE
;
2425 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2431 /*********************************************************************
2435 * Hopefully this won't fire back at us.
2436 * We always start with a buffer in 32 bit linear memory.
2437 * However, with this message a 16 bit application requests
2438 * a handle of 16 bit local heap memory, where it expects to find
2440 * It's a pitty that from this moment on we have to use this
2441 * local heap, because applications may rely on the handle
2444 * In this function we'll try to switch to local heap.
2446 static HLOCAL16
EDIT_EM_GetHandle16(EDITSTATE
*es
)
2449 UINT countA
, alloc_size
;
2450 STACK16FRAME
* stack16
;
2453 if (!(es
->style
& ES_MULTILINE
))
2459 stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2460 oldDS
= stack16
->ds
;
2461 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2463 if (!LocalHeapSize16()) {
2465 if (!LocalInit16(stack16
->ds
, 0, GlobalSize16(stack16
->ds
))) {
2466 ERR("could not initialize local heap\n");
2469 TRACE("local heap initialized\n");
2472 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2473 alloc_size
= ROUND_TO_GROW(countA
);
2475 TRACE("Allocating 16-bit ANSI alias buffer\n");
2476 if (!(es
->hloc16
= LocalAlloc16(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
))) {
2477 ERR("could not allocate new 16 bit buffer\n");
2481 if (!(textA
= MapSL(LocalLock16( es
->hloc16
)))) {
2482 ERR("could not lock new 16 bit buffer\n");
2483 LocalFree16(es
->hloc16
);
2488 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2489 LocalUnlock16(es
->hloc16
);
2490 es
->flags
|= EF_APP_HAS_HANDLE
;
2492 TRACE("Returning %04X, LocalSize() = %d\n", es
->hloc16
, LocalSize16(es
->hloc16
));
2495 stack16
->ds
= oldDS
;
2501 /*********************************************************************
2506 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2509 INT line_len
, dst_len
;
2512 if (es
->style
& ES_MULTILINE
) {
2513 if (line
>= es
->line_count
)
2517 i
= EDIT_EM_LineIndex(es
, line
);
2519 line_len
= EDIT_EM_LineLength(es
, i
);
2520 dst_len
= *(WORD
*)dst
;
2523 if(dst_len
<= line_len
)
2525 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2528 else /* Append 0 if enough space */
2530 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2537 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2538 if(!ret
&& line_len
) /* Insufficient buffer size */
2540 if(ret
< dst_len
) /* Append 0 if enough space */
2541 ((LPSTR
)dst
)[ret
] = 0;
2547 /*********************************************************************
2552 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2554 UINT s
= es
->selection_start
;
2555 UINT e
= es
->selection_end
;
2562 return MAKELONG(s
, e
);
2566 /*********************************************************************
2570 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2573 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2575 UINT strl
= strlenW(lpsz_replace
);
2576 UINT tl
= get_text_length(es
);
2587 TRACE("%s, can_undo %d, send_update %d\n",
2588 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2590 s
= es
->selection_start
;
2591 e
= es
->selection_end
;
2593 if ((s
== e
) && !strl
)
2598 size
= tl
- (e
- s
) + strl
;
2602 /* Issue the EN_MAXTEXT notification and continue with replacing text
2603 * such that buffer limit is honored. */
2604 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2605 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2606 /* Buffer limit can be smaller than the actual length of text in combobox */
2607 if (es
->buffer_limit
< (tl
- (e
-s
)))
2610 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2613 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2617 /* there is something to be deleted */
2618 TRACE("deleting stuff.\n");
2620 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2622 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2623 buf
[bufl
] = 0; /* ensure 0 termination */
2625 strcpyW(es
->text
+ s
, es
->text
+ e
);
2626 text_buffer_changed(es
);
2629 /* there is an insertion */
2630 tl
= get_text_length(es
);
2631 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
));
2632 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2634 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2635 p
[i
] = lpsz_replace
[i
];
2636 if(es
->style
& ES_UPPERCASE
)
2637 CharUpperBuffW(p
, strl
);
2638 else if(es
->style
& ES_LOWERCASE
)
2639 CharLowerBuffW(p
, strl
);
2640 text_buffer_changed(es
);
2642 if (es
->style
& ES_MULTILINE
)
2644 INT st
= min(es
->selection_start
, es
->selection_end
);
2645 INT vlc
= get_vertical_line_count(es
);
2647 hrgn
= CreateRectRgn(0, 0, 0, 0);
2648 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2649 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2650 /* if text is too long undo all changes */
2651 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2653 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2655 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2657 text_buffer_changed(es
);
2658 EDIT_BuildLineDefs_ML(es
, s
, e
,
2659 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2662 hrgn
= CreateRectRgn(0, 0, 0, 0);
2663 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2667 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2668 EDIT_CalcLineWidth_SL(es
);
2669 /* remove chars that don't fit */
2670 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2671 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2672 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2674 EDIT_CalcLineWidth_SL(es
);
2676 text_buffer_changed(es
);
2677 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2683 utl
= strlenW(es
->undo_text
);
2684 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2685 /* undo-buffer is extended to the right */
2686 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2687 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2688 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2689 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2690 /* undo-buffer is extended to the left */
2691 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2692 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2694 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2696 es
->undo_position
= s
;
2698 /* new undo-buffer */
2699 EDIT_MakeUndoFit(es
, e
- s
);
2700 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2701 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2702 es
->undo_position
= s
;
2704 /* any deletion makes the old insertion-undo invalid */
2705 es
->undo_insert_count
= 0;
2707 EDIT_EM_EmptyUndoBuffer(es
);
2711 if ((s
== es
->undo_position
) ||
2712 ((es
->undo_insert_count
) &&
2713 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2715 * insertion is new and at delete position or
2716 * an extension to either left or right
2718 es
->undo_insert_count
+= strl
;
2720 /* new insertion undo */
2721 es
->undo_position
= s
;
2722 es
->undo_insert_count
= strl
;
2723 /* new insertion makes old delete-buffer invalid */
2724 *es
->undo_text
= '\0';
2727 EDIT_EM_EmptyUndoBuffer(es
);
2731 HeapFree(GetProcessHeap(), 0, buf
);
2735 /* If text has been deleted and we're right or center aligned then scroll rightward */
2736 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2738 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2740 if (delta
< 0 && es
->x_offset
)
2742 if (abs(delta
) > es
->x_offset
)
2745 es
->x_offset
+= delta
;
2749 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2750 es
->flags
|= EF_MODIFIED
;
2751 if (send_update
) es
->flags
|= EF_UPDATE
;
2754 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2758 EDIT_UpdateText(es
, NULL
, TRUE
);
2760 EDIT_EM_ScrollCaret(es
);
2762 /* force scroll info update */
2763 EDIT_UpdateScrollInfo(es
);
2766 if(send_update
|| (es
->flags
& EF_UPDATE
))
2768 es
->flags
&= ~EF_UPDATE
;
2769 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2774 /*********************************************************************
2778 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2781 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2783 if (!(es
->style
& ES_MULTILINE
))
2787 WARN("called with NULL handle\n");
2791 EDIT_UnlockBuffer(es
, TRUE
);
2796 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2797 HANDLE16 oldDS
= stack16
->ds
;
2799 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2800 LocalFree16(es
->hloc16
);
2801 stack16
->ds
= oldDS
;
2810 LocalFree(es
->hloc32A
);
2822 countA
= LocalSize(hloc
);
2823 textA
= LocalLock(hloc
);
2824 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2825 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2827 ERR("Could not allocate new unicode buffer\n");
2830 textW
= LocalLock(hloc32W_new
);
2831 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2832 LocalUnlock(hloc32W_new
);
2836 LocalFree(es
->hloc32W
);
2838 es
->hloc32W
= hloc32W_new
;
2842 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2844 es
->flags
|= EF_APP_HAS_HANDLE
;
2845 EDIT_LockBuffer(es
);
2847 es
->x_offset
= es
->y_offset
= 0;
2848 es
->selection_start
= es
->selection_end
= 0;
2849 EDIT_EM_EmptyUndoBuffer(es
);
2850 es
->flags
&= ~EF_MODIFIED
;
2851 es
->flags
&= ~EF_UPDATE
;
2852 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2853 EDIT_UpdateText(es
, NULL
, TRUE
);
2854 EDIT_EM_ScrollCaret(es
);
2855 /* force scroll info update */
2856 EDIT_UpdateScrollInfo(es
);
2861 /*********************************************************************
2865 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2868 static void EDIT_EM_SetHandle16(EDITSTATE
*es
, HLOCAL16 hloc
)
2870 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
2871 HINSTANCE16 hInstance
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
2872 HANDLE16 oldDS
= stack16
->ds
;
2878 if (!(es
->style
& ES_MULTILINE
))
2882 WARN("called with NULL handle\n");
2886 EDIT_UnlockBuffer(es
, TRUE
);
2890 LocalFree(es
->hloc32A
);
2894 stack16
->ds
= hInstance
;
2895 countA
= LocalSize16(hloc
);
2896 textA
= MapSL(LocalLock16(hloc
));
2897 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2898 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2900 ERR("Could not allocate new unicode buffer\n");
2903 textW
= LocalLock(hloc32W_new
);
2904 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2905 LocalUnlock(hloc32W_new
);
2906 LocalUnlock16(hloc
);
2907 stack16
->ds
= oldDS
;
2910 LocalFree(es
->hloc32W
);
2912 es
->hloc32W
= hloc32W_new
;
2915 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2917 es
->flags
|= EF_APP_HAS_HANDLE
;
2918 EDIT_LockBuffer(es
);
2920 es
->x_offset
= es
->y_offset
= 0;
2921 es
->selection_start
= es
->selection_end
= 0;
2922 EDIT_EM_EmptyUndoBuffer(es
);
2923 es
->flags
&= ~EF_MODIFIED
;
2924 es
->flags
&= ~EF_UPDATE
;
2925 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2926 EDIT_UpdateText(es
, NULL
, TRUE
);
2927 EDIT_EM_ScrollCaret(es
);
2928 /* force scroll info update */
2929 EDIT_UpdateScrollInfo(es
);
2934 /*********************************************************************
2938 * NOTE: this version currently implements WinNT limits
2941 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2943 if (!limit
) limit
= ~0u;
2944 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2945 es
->buffer_limit
= limit
;
2949 /*********************************************************************
2953 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2954 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2955 * margin according to the textmetrics of the current font.
2957 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2958 * of the char's width as the margin, but this is not how Windows handles this.
2959 * For all other fonts Windows sets the margins to zero.
2961 * FIXME - When EC_USEFONTINFO is used the margins only change if the
2962 * edit control is equal to or larger than a certain size.
2963 * Interestingly if one subtracts both the left and right margins from
2964 * this size one always seems to get an even number. The extents of
2965 * the (four character) string "'**'" match this quite closely, so
2966 * we'll use this until we come up with a better idea.
2968 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
2970 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
2973 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
2974 return sz
.cx
+ left
+ right
;
2977 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2978 WORD left
, WORD right
, BOOL repaint
)
2981 INT default_left_margin
= 0; /* in pixels */
2982 INT default_right_margin
= 0; /* in pixels */
2984 /* Set the default margins depending on the font */
2985 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2986 HDC dc
= GetDC(es
->hwndSelf
);
2987 HFONT old_font
= SelectObject(dc
, es
->font
);
2988 GetTextMetricsW(dc
, &tm
);
2989 /* The default margins are only non zero for TrueType or Vector fonts */
2990 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2993 /* This must be calculated more exactly! But how? */
2994 default_left_margin
= tm
.tmAveCharWidth
/ 2;
2995 default_right_margin
= tm
.tmAveCharWidth
/ 2;
2996 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
2997 GetClientRect(es
->hwndSelf
, &rc
);
2998 if(rc
.right
- rc
.left
< min_size
) {
2999 default_left_margin
= es
->left_margin
;
3000 default_right_margin
= es
->right_margin
;
3003 SelectObject(dc
, old_font
);
3004 ReleaseDC(es
->hwndSelf
, dc
);
3007 if (action
& EC_LEFTMARGIN
) {
3008 es
->format_rect
.left
-= es
->left_margin
;
3009 if (left
!= EC_USEFONTINFO
)
3010 es
->left_margin
= left
;
3012 es
->left_margin
= default_left_margin
;
3013 es
->format_rect
.left
+= es
->left_margin
;
3016 if (action
& EC_RIGHTMARGIN
) {
3017 es
->format_rect
.right
+= es
->right_margin
;
3018 if (right
!= EC_USEFONTINFO
)
3019 es
->right_margin
= right
;
3021 es
->right_margin
= default_right_margin
;
3022 es
->format_rect
.right
-= es
->right_margin
;
3025 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
3026 EDIT_AdjustFormatRect(es
);
3027 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
3030 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
3034 /*********************************************************************
3036 * EM_SETPASSWORDCHAR
3039 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
3043 if (es
->style
& ES_MULTILINE
)
3046 if (es
->password_char
== c
)
3049 style
= GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
);
3050 es
->password_char
= c
;
3052 SetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
3053 es
->style
|= ES_PASSWORD
;
3055 SetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
3056 es
->style
&= ~ES_PASSWORD
;
3058 EDIT_UpdateText(es
, NULL
, TRUE
);
3062 /*********************************************************************
3067 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
3069 if (!(es
->style
& ES_MULTILINE
))
3071 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3072 es
->tabs_count
= count
;
3076 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3077 if (es
->tabs
== NULL
)
3082 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
3089 /*********************************************************************
3094 static BOOL
EDIT_EM_SetTabStops16(EDITSTATE
*es
, INT count
, const INT16
*tabs
)
3096 if (!(es
->style
& ES_MULTILINE
))
3098 HeapFree(GetProcessHeap(), 0, es
->tabs
);
3099 es
->tabs_count
= count
;
3104 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
3105 for (i
= 0 ; i
< count
; i
++)
3106 es
->tabs
[i
] = *tabs
++;
3113 /*********************************************************************
3115 * EM_SETWORDBREAKPROC
3118 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
3120 if (es
->word_break_proc
== wbp
)
3123 es
->word_break_proc
= wbp
;
3125 es
->word_break_proc16
= NULL
;
3128 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3129 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3130 EDIT_UpdateText(es
, NULL
, TRUE
);
3136 /*********************************************************************
3138 * EM_SETWORDBREAKPROC16
3141 static void EDIT_EM_SetWordBreakProc16(EDITSTATE
*es
, EDITWORDBREAKPROC16 wbp
)
3143 if (es
->word_break_proc16
== wbp
)
3146 es
->word_break_proc
= NULL
;
3147 es
->word_break_proc16
= wbp
;
3148 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3149 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3150 EDIT_UpdateText(es
, NULL
, TRUE
);
3156 /*********************************************************************
3161 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3166 /* As per MSDN spec, for a single-line edit control,
3167 the return value is always TRUE */
3168 if( es
->style
& ES_READONLY
)
3169 return !(es
->style
& ES_MULTILINE
);
3171 ulength
= strlenW(es
->undo_text
);
3173 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3177 strcpyW(utext
, es
->undo_text
);
3179 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3180 es
->undo_insert_count
, debugstr_w(utext
));
3182 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3183 EDIT_EM_EmptyUndoBuffer(es
);
3184 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3185 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3186 /* send the notification after the selection start and end are set */
3187 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3188 EDIT_EM_ScrollCaret(es
);
3189 HeapFree(GetProcessHeap(), 0, utext
);
3191 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3192 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3197 /* Helper function for WM_CHAR
3199 * According to an MSDN blog article titled "Just because you're a control
3200 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3201 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3202 * a dialog box or not.
3204 static BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3206 return (es
->flags
& EF_DIALOGMODE
);
3210 /*********************************************************************
3215 static void EDIT_WM_Paste(EDITSTATE
*es
)
3220 /* Protect read-only edit control from modification */
3221 if(es
->style
& ES_READONLY
)
3224 OpenClipboard(es
->hwndSelf
);
3225 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
3226 src
= GlobalLock(hsrc
);
3227 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
3230 else if (es
->style
& ES_PASSWORD
) {
3231 /* clear selected text in password edit box even with empty clipboard */
3232 const WCHAR empty_strW
[] = { 0 };
3233 EDIT_EM_ReplaceSel(es
, TRUE
, empty_strW
, TRUE
, TRUE
);
3239 /*********************************************************************
3244 static void EDIT_WM_Copy(EDITSTATE
*es
)
3246 INT s
= min(es
->selection_start
, es
->selection_end
);
3247 INT e
= max(es
->selection_start
, es
->selection_end
);
3255 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3256 dst
= GlobalLock(hdst
);
3257 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3258 dst
[len
] = 0; /* ensure 0 termination */
3259 TRACE("%s\n", debugstr_w(dst
));
3261 OpenClipboard(es
->hwndSelf
);
3263 SetClipboardData(CF_UNICODETEXT
, hdst
);
3268 /*********************************************************************
3273 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
3275 static const WCHAR empty_stringW
[] = {0};
3277 /* Protect read-only edit control from modification */
3278 if(es
->style
& ES_READONLY
)
3281 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
3285 /*********************************************************************
3290 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3297 /*********************************************************************
3302 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3306 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3310 /* If it's not a multiline edit box, it would be ignored below.
3311 * For multiline edit without ES_WANTRETURN, we have to make a
3314 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3315 if (EDIT_IsInsideDialog(es
))
3318 if (es
->style
& ES_MULTILINE
) {
3319 if (es
->style
& ES_READONLY
) {
3320 EDIT_MoveHome(es
, FALSE
, FALSE
);
3321 EDIT_MoveDown_ML(es
, FALSE
);
3323 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3324 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3329 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3331 static const WCHAR tabW
[] = {'\t',0};
3332 if (EDIT_IsInsideDialog(es
))
3334 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3338 if (!(es
->style
& ES_READONLY
) && !control
) {
3339 if (es
->selection_start
!= es
->selection_end
)
3342 /* delete character left of caret */
3343 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3344 EDIT_MoveBackward(es
, TRUE
);
3350 if (!(es
->style
& ES_PASSWORD
))
3351 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3354 if (!(es
->style
& ES_READONLY
))
3355 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3358 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3359 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3362 if (!(es
->style
& ES_READONLY
))
3363 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3367 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3368 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3371 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3375 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3383 /*********************************************************************
3388 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3390 if (code
|| control
)
3395 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3398 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3401 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3404 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3407 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3410 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3411 EDIT_EM_ScrollCaret(es
);
3414 ERR("unknown menu item, please report\n");
3420 /*********************************************************************
3424 * Note: the resource files resource/sysres_??.rc cannot define a
3425 * single popup menu. Hence we use a (dummy) menubar
3426 * containing the single popup menu as its first item.
3428 * FIXME: the message identifiers have been chosen arbitrarily,
3429 * hence we use MF_BYPOSITION.
3430 * We might as well use the "real" values (anybody knows ?)
3431 * The menu definition is in resources/sysres_??.rc.
3432 * Once these are OK, we better use MF_BYCOMMAND here
3433 * (as we do in EDIT_WM_Command()).
3436 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3439 HMENU menu
= LoadMenuA(User32Instance
, "EDITMENU");
3441 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3443 HMENU popup
= GetSubMenu(menu
, 0);
3444 UINT start
= es
->selection_start
;
3445 UINT end
= es
->selection_end
;
3447 ORDER_UINT(start
, end
);
3450 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3452 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3454 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3456 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3458 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3460 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3462 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3465 /* Windows places the menu at the edit's center in this case */
3466 GetClientRect(es
->hwndSelf
, &rc
);
3467 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
3468 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3469 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3472 TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
, x
, y
, 0, es
->hwndSelf
, NULL
);
3477 /*********************************************************************
3482 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3484 if(!count
) return 0;
3488 lstrcpynW(dst
, es
->text
, count
);
3489 return strlenW(dst
);
3493 LPSTR textA
= (LPSTR
)dst
;
3494 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3495 textA
[count
- 1] = 0; /* ensure 0 termination */
3496 return strlen(textA
);
3500 /*********************************************************************
3505 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3507 HWND hLBox
= es
->hwndListBox
;
3515 hCombo
= GetParent(es
->hwndSelf
);
3519 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3521 if (key
== VK_UP
|| key
== VK_DOWN
)
3523 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3526 if (msg
== WM_KEYDOWN
|| nEUI
)
3527 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3533 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3535 /* make sure ComboLBox pops up */
3536 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3541 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)key
, 0);
3544 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3546 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3548 SendMessageW(hLBox
, WM_KEYDOWN
, (WPARAM
)VK_F4
, 0);
3553 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3559 /*********************************************************************
3563 * Handling of special keys that don't produce a WM_CHAR
3564 * (i.e. non-printable keys) & Backspace & Delete
3567 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3572 if (GetKeyState(VK_MENU
) & 0x8000)
3575 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3576 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3581 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3586 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3587 EDIT_MoveUp_ML(es
, shift
);
3590 EDIT_MoveWordBackward(es
, shift
);
3592 EDIT_MoveBackward(es
, shift
);
3595 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3599 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3600 EDIT_MoveDown_ML(es
, shift
);
3602 EDIT_MoveWordForward(es
, shift
);
3604 EDIT_MoveForward(es
, shift
);
3607 EDIT_MoveHome(es
, shift
, control
);
3610 EDIT_MoveEnd(es
, shift
, control
);
3613 if (es
->style
& ES_MULTILINE
)
3614 EDIT_MovePageUp_ML(es
, shift
);
3616 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3619 if (es
->style
& ES_MULTILINE
)
3620 EDIT_MovePageDown_ML(es
, shift
);
3622 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3625 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3626 if (es
->selection_start
!= es
->selection_end
) {
3633 /* delete character left of caret */
3634 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3635 EDIT_MoveBackward(es
, TRUE
);
3637 } else if (control
) {
3638 /* delete to end of line */
3639 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3640 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3643 /* delete character right of caret */
3644 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3645 EDIT_MoveForward(es
, TRUE
);
3653 if (!(es
->style
& ES_READONLY
))
3659 /* If the edit doesn't want the return send a message to the default object */
3660 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3664 if (!EDIT_IsInsideDialog(es
)) break;
3666 dw
= SendMessageW( es
->hwndParent
, DM_GETDEFID
, 0, 0 );
3667 if (HIWORD(dw
) == DC_HASDEFID
)
3669 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3672 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, (LPARAM
)TRUE
);
3673 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3679 if (!(es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3680 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3683 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3684 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3691 /*********************************************************************
3696 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3698 es
->flags
&= ~EF_FOCUSED
;
3700 if(!(es
->style
& ES_NOHIDESEL
))
3701 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3702 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3707 /*********************************************************************
3711 * The caret position has been set on the WM_LBUTTONDOWN message
3714 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3717 INT e
= es
->selection_end
;
3722 es
->bCaptureState
= TRUE
;
3723 SetCapture(es
->hwndSelf
);
3725 l
= EDIT_EM_LineFromChar(es
, e
);
3726 li
= EDIT_EM_LineIndex(es
, l
);
3727 ll
= EDIT_EM_LineLength(es
, e
);
3728 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3729 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3730 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3731 EDIT_EM_ScrollCaret(es
);
3732 es
->region_posx
= es
->region_posy
= 0;
3733 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3738 /*********************************************************************
3743 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3748 es
->bCaptureState
= TRUE
;
3749 SetCapture(es
->hwndSelf
);
3750 EDIT_ConfinePoint(es
, &x
, &y
);
3751 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3752 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3753 EDIT_EM_ScrollCaret(es
);
3754 es
->region_posx
= es
->region_posy
= 0;
3755 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3757 if (!(es
->flags
& EF_FOCUSED
))
3758 SetFocus(es
->hwndSelf
);
3764 /*********************************************************************
3769 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3771 if (es
->bCaptureState
) {
3772 KillTimer(es
->hwndSelf
, 0);
3773 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3775 es
->bCaptureState
= FALSE
;
3780 /*********************************************************************
3785 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3787 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3792 /*********************************************************************
3797 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3803 /* If the mouse has been captured by process other than the edit control itself,
3804 * the windows edit controls will not select the strings with mouse move.
3806 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3810 * FIXME: gotta do some scrolling if outside client
3811 * area. Maybe reset the timer ?
3814 EDIT_ConfinePoint(es
, &x
, &y
);
3815 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3816 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3817 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3818 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3819 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3824 /*********************************************************************
3829 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3842 BOOL rev
= es
->bEnableState
&&
3843 ((es
->flags
& EF_FOCUSED
) ||
3844 (es
->style
& ES_NOHIDESEL
));
3845 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3847 GetClientRect(es
->hwndSelf
, &rcClient
);
3849 /* get the background brush */
3850 brush
= EDIT_NotifyCtlColor(es
, dc
);
3852 /* paint the border and the background */
3853 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3855 if(es
->style
& WS_BORDER
) {
3856 bw
= GetSystemMetrics(SM_CXBORDER
);
3857 bh
= GetSystemMetrics(SM_CYBORDER
);
3859 if(es
->style
& ES_MULTILINE
) {
3860 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3861 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3864 /* Draw the frame. Same code as in nonclient.c */
3865 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3866 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3867 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3868 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3869 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3870 SelectObject(dc
, old_brush
);
3872 /* Keep the border clean */
3873 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3874 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3877 GetClipBox(dc
, &rc
);
3878 FillRect(dc
, &rc
, brush
);
3880 IntersectClipRect(dc
, es
->format_rect
.left
,
3881 es
->format_rect
.top
,
3882 es
->format_rect
.right
,
3883 es
->format_rect
.bottom
);
3884 if (es
->style
& ES_MULTILINE
) {
3886 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3889 old_font
= SelectObject(dc
, es
->font
);
3891 if (!es
->bEnableState
)
3892 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3893 GetClipBox(dc
, &rcRgn
);
3894 if (es
->style
& ES_MULTILINE
) {
3895 INT vlc
= get_vertical_line_count(es
);
3896 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3897 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3898 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3899 EDIT_PaintLine(es
, dc
, i
, rev
);
3902 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3903 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3904 EDIT_PaintLine(es
, dc
, 0, rev
);
3907 SelectObject(dc
, old_font
);
3910 EndPaint(es
->hwndSelf
, &ps
);
3914 /*********************************************************************
3919 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3921 es
->flags
|= EF_FOCUSED
;
3923 if (!(es
->style
& ES_NOHIDESEL
))
3924 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3926 /* single line edit updates itself */
3927 if (!(es
->style
& ES_MULTILINE
))
3929 HDC hdc
= GetDC(es
->hwndSelf
);
3930 EDIT_WM_Paint(es
, hdc
);
3931 ReleaseDC(es
->hwndSelf
, hdc
);
3934 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3935 EDIT_SetCaretPos(es
, es
->selection_end
,
3936 es
->flags
& EF_AFTER_WRAP
);
3937 ShowCaret(es
->hwndSelf
);
3938 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3942 /*********************************************************************
3946 * With Win95 look the margins are set to default font value unless
3947 * the system font (font == 0) is being set, in which case they are left
3951 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3959 dc
= GetDC(es
->hwndSelf
);
3961 old_font
= SelectObject(dc
, font
);
3962 GetTextMetricsW(dc
, &tm
);
3963 es
->line_height
= tm
.tmHeight
;
3964 es
->char_width
= tm
.tmAveCharWidth
;
3966 SelectObject(dc
, old_font
);
3967 ReleaseDC(es
->hwndSelf
, dc
);
3969 /* Reset the format rect and the margins */
3970 GetClientRect(es
->hwndSelf
, &clientRect
);
3971 EDIT_SetRectNP(es
, &clientRect
);
3972 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3973 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3975 if (es
->style
& ES_MULTILINE
)
3976 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3978 EDIT_CalcLineWidth_SL(es
);
3981 EDIT_UpdateText(es
, NULL
, TRUE
);
3982 if (es
->flags
& EF_FOCUSED
) {
3984 CreateCaret(es
->hwndSelf
, 0, 2, es
->line_height
);
3985 EDIT_SetCaretPos(es
, es
->selection_end
,
3986 es
->flags
& EF_AFTER_WRAP
);
3987 ShowCaret(es
->hwndSelf
);
3992 /*********************************************************************
3997 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3998 * The modified flag is reset. No notifications are sent.
4000 * For single-line controls, reception of WM_SETTEXT triggers:
4001 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4004 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
4006 LPWSTR textW
= NULL
;
4007 if (!unicode
&& text
)
4009 LPCSTR textA
= (LPCSTR
)text
;
4010 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4011 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
4013 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4017 if (es
->flags
& EF_UPDATE
)
4018 /* fixed this bug once; complain if we see it about to happen again. */
4019 ERR("SetSel may generate UPDATE message whose handler may reset "
4022 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
4025 TRACE("%s\n", debugstr_w(text
));
4026 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
4028 HeapFree(GetProcessHeap(), 0, textW
);
4032 static const WCHAR empty_stringW
[] = {0};
4034 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
4037 es
->flags
&= ~EF_MODIFIED
;
4038 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
4040 /* Send the notification after the selection start and end have been set
4041 * edit control doesn't send notification on WM_SETTEXT
4042 * if it is multiline, or it is part of combobox
4044 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
4046 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
4047 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
4049 EDIT_EM_ScrollCaret(es
);
4050 EDIT_UpdateScrollInfo(es
);
4054 /*********************************************************************
4059 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
4061 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
4063 TRACE("width = %d, height = %d\n", width
, height
);
4064 SetRect(&rc
, 0, 0, width
, height
);
4065 EDIT_SetRectNP(es
, &rc
);
4066 EDIT_UpdateText(es
, NULL
, TRUE
);
4071 /*********************************************************************
4075 * This message is sent by SetWindowLong on having changed either the Style
4076 * or the extended style.
4078 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4080 * See also EDIT_WM_NCCreate
4082 * It appears that the Windows version of the edit control allows the style
4083 * (as retrieved by GetWindowLong) to be any value and maintains an internal
4084 * style variable which will generally be different. In this function we
4085 * update the internal style based on what changed in the externally visible
4088 * Much of this content as based upon the MSDN, especially:
4089 * Platform SDK Documentation -> User Interface Services ->
4090 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4091 * Edit Control Styles
4093 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
4095 if (GWL_STYLE
== which
) {
4096 DWORD style_change_mask
;
4098 /* Only a subset of changes can be applied after the control
4101 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
4103 if (es
->style
& ES_MULTILINE
)
4104 style_change_mask
|= ES_WANTRETURN
;
4106 new_style
= style
->styleNew
& style_change_mask
;
4108 /* Number overrides lowercase overrides uppercase (at least it
4109 * does in Win95). However I'll bet that ES_NUMBER would be
4110 * invalid under Win 3.1.
4112 if (new_style
& ES_NUMBER
) {
4113 ; /* do not override the ES_NUMBER */
4114 } else if (new_style
& ES_LOWERCASE
) {
4115 new_style
&= ~ES_UPPERCASE
;
4118 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4119 } else if (GWL_EXSTYLE
== which
) {
4120 ; /* FIXME - what is needed here */
4122 WARN ("Invalid style change %ld\n",which
);
4128 /*********************************************************************
4133 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4135 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4136 if (EDIT_EM_CanUndo(es
))
4139 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4140 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4143 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, (WPARAM
)key
, (LPARAM
)key_data
);
4147 /*********************************************************************
4152 static void EDIT_WM_Timer(EDITSTATE
*es
)
4154 if (es
->region_posx
< 0) {
4155 EDIT_MoveBackward(es
, TRUE
);
4156 } else if (es
->region_posx
> 0) {
4157 EDIT_MoveForward(es
, TRUE
);
4160 * FIXME: gotta do some vertical scrolling here, like
4161 * EDIT_EM_LineScroll(hwnd, 0, 1);
4165 /*********************************************************************
4170 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4175 if (!(es
->style
& ES_MULTILINE
))
4178 if (!(es
->style
& ES_AUTOHSCROLL
))
4182 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4185 TRACE("SB_LINELEFT\n");
4187 dx
= -es
->char_width
;
4190 TRACE("SB_LINERIGHT\n");
4191 if (es
->x_offset
< es
->text_width
)
4192 dx
= es
->char_width
;
4195 TRACE("SB_PAGELEFT\n");
4197 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4200 TRACE("SB_PAGERIGHT\n");
4201 if (es
->x_offset
< es
->text_width
)
4202 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4210 TRACE("SB_RIGHT\n");
4211 if (es
->x_offset
< es
->text_width
)
4212 dx
= es
->text_width
- es
->x_offset
;
4215 TRACE("SB_THUMBTRACK %d\n", pos
);
4216 es
->flags
|= EF_HSCROLL_TRACK
;
4217 if(es
->style
& WS_HSCROLL
)
4218 dx
= pos
- es
->x_offset
;
4223 if(pos
< 0 || pos
> 100) return 0;
4224 /* Assume default scroll range 0-100 */
4225 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4226 new_x
= pos
* (es
->text_width
- fw
) / 100;
4227 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4230 case SB_THUMBPOSITION
:
4231 TRACE("SB_THUMBPOSITION %d\n", pos
);
4232 es
->flags
&= ~EF_HSCROLL_TRACK
;
4233 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4234 dx
= pos
- es
->x_offset
;
4239 if(pos
< 0 || pos
> 100) return 0;
4240 /* Assume default scroll range 0-100 */
4241 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4242 new_x
= pos
* (es
->text_width
- fw
) / 100;
4243 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4246 /* force scroll info update */
4247 EDIT_UpdateScrollInfo(es
);
4248 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4252 TRACE("SB_ENDSCROLL\n");
4255 * FIXME : the next two are undocumented !
4256 * Are we doing the right thing ?
4257 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4258 * although it's also a regular control message.
4260 case EM_GETTHUMB
: /* this one is used by NT notepad */
4266 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4267 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4270 /* Assume default scroll range 0-100 */
4271 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4272 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4274 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4278 case EM_LINESCROLL16
:
4279 TRACE("EM_LINESCROLL16\n");
4285 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4291 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4292 /* check if we are going to move too far */
4293 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4294 dx
= es
->text_width
- fw
- es
->x_offset
;
4296 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4302 /*********************************************************************
4307 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4311 if (!(es
->style
& ES_MULTILINE
))
4314 if (!(es
->style
& ES_AUTOVSCROLL
))
4323 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4324 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4325 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4327 EDIT_EM_Scroll(es
, action
);
4334 TRACE("SB_BOTTOM\n");
4335 dy
= es
->line_count
- 1 - es
->y_offset
;
4338 TRACE("SB_THUMBTRACK %d\n", pos
);
4339 es
->flags
|= EF_VSCROLL_TRACK
;
4340 if(es
->style
& WS_VSCROLL
)
4341 dy
= pos
- es
->y_offset
;
4344 /* Assume default scroll range 0-100 */
4347 if(pos
< 0 || pos
> 100) return 0;
4348 vlc
= get_vertical_line_count(es
);
4349 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4350 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4351 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4352 es
->line_count
, es
->y_offset
, pos
, dy
);
4355 case SB_THUMBPOSITION
:
4356 TRACE("SB_THUMBPOSITION %d\n", pos
);
4357 es
->flags
&= ~EF_VSCROLL_TRACK
;
4358 if(es
->style
& WS_VSCROLL
)
4359 dy
= pos
- es
->y_offset
;
4362 /* Assume default scroll range 0-100 */
4365 if(pos
< 0 || pos
> 100) return 0;
4366 vlc
= get_vertical_line_count(es
);
4367 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4368 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4369 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4370 es
->line_count
, es
->y_offset
, pos
, dy
);
4374 /* force scroll info update */
4375 EDIT_UpdateScrollInfo(es
);
4376 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4380 TRACE("SB_ENDSCROLL\n");
4383 * FIXME : the next two are undocumented !
4384 * Are we doing the right thing ?
4385 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4386 * although it's also a regular control message.
4388 case EM_GETTHUMB
: /* this one is used by NT notepad */
4394 if(GetWindowLongPtrW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4395 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4398 /* Assume default scroll range 0-100 */
4399 INT vlc
= get_vertical_line_count(es
);
4400 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4402 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4406 case EM_LINESCROLL16
:
4407 TRACE("EM_LINESCROLL16 %d\n", pos
);
4413 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4418 EDIT_EM_LineScroll(es
, 0, dy
);
4422 /*********************************************************************
4426 * FIXME: is this right ? (or should it be only VSCROLL)
4427 * (and maybe only for edit controls that really have their
4428 * own scrollbars) (and maybe only for multiline controls ?)
4429 * All in all: very poorly documented
4432 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4435 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4436 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4438 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB16
, 0),
4439 EDIT_WM_HScroll(es
, EM_GETTHUMB16
, 0));
4443 /********************************************************************
4445 * The Following code is to handle inline editing from IMEs
4448 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4451 LPWSTR lpCompStr
= NULL
;
4452 LPSTR lpCompStrAttr
= NULL
;
4455 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4462 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
4465 ERR("Unable to allocate IME CompositionString\n");
4470 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4471 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
4473 if (CompFlag
& GCS_COMPATTR
)
4476 * We do not use the attributes yet. it would tell us what characters
4477 * are in transition and which are converted or decided upon
4479 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4483 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4486 ERR("Unable to allocate IME Attribute String\n");
4487 HeapFree(GetProcessHeap(),0,lpCompStr
);
4490 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4492 lpCompStrAttr
[dwBufLenAttr
] = 0;
4495 lpCompStrAttr
= NULL
;
4498 /* check for change in composition start */
4499 if (es
->selection_end
< es
->composition_start
)
4500 es
->composition_start
= es
->selection_end
;
4502 /* replace existing selection string */
4503 es
->selection_start
= es
->composition_start
;
4505 if (es
->composition_len
> 0)
4506 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4508 es
->selection_end
= es
->selection_start
;
4510 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
4511 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4513 es
->selection_start
= es
->composition_start
;
4514 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4516 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4517 HeapFree(GetProcessHeap(),0,lpCompStr
);
4520 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4525 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4531 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
4534 ERR("Unable to alloc buffer for IME string\n");
4538 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4539 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
4541 /* check for change in composition start */
4542 if (es
->selection_end
< es
->composition_start
)
4543 es
->composition_start
= es
->selection_end
;
4545 es
->selection_start
= es
->composition_start
;
4546 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4547 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
4548 es
->composition_start
= es
->selection_end
;
4549 es
->composition_len
= 0;
4551 HeapFree(GetProcessHeap(),0,lpResultStr
);
4554 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4559 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4561 static const WCHAR empty_stringW
[] = {0};
4562 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4563 es
->composition_start
= es
->selection_end
;
4566 hIMC
= ImmGetContext(hwnd
);
4570 if (CompFlag
& GCS_RESULTSTR
)
4571 EDIT_GetResultStr(hIMC
, es
);
4572 if (CompFlag
& GCS_COMPSTR
)
4573 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4574 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4575 ImmReleaseContext(hwnd
, hIMC
);
4576 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4580 /*********************************************************************
4584 * See also EDIT_WM_StyleChanged
4586 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4591 TRACE("Creating %s edit control, style = %08x\n",
4592 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4594 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4596 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4599 * Note: since the EDITSTATE has not been fully initialized yet,
4600 * we can't use any API calls that may send
4601 * WM_XXX messages before WM_NCCREATE is completed.
4604 es
->is_unicode
= unicode
;
4605 es
->style
= lpcs
->style
;
4607 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4609 es
->hwndSelf
= hwnd
;
4610 /* Save parent, which will be notified by EN_* messages */
4611 es
->hwndParent
= lpcs
->hwndParent
;
4613 if (es
->style
& ES_COMBO
)
4614 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4616 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4617 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4619 /* Number overrides lowercase overrides uppercase (at least it
4620 * does in Win95). However I'll bet that ES_NUMBER would be
4621 * invalid under Win 3.1.
4623 if (es
->style
& ES_NUMBER
) {
4624 ; /* do not override the ES_NUMBER */
4625 } else if (es
->style
& ES_LOWERCASE
) {
4626 es
->style
&= ~ES_UPPERCASE
;
4628 if (es
->style
& ES_MULTILINE
) {
4629 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4630 if (es
->style
& WS_VSCROLL
)
4631 es
->style
|= ES_AUTOVSCROLL
;
4632 if (es
->style
& WS_HSCROLL
)
4633 es
->style
|= ES_AUTOHSCROLL
;
4634 es
->style
&= ~ES_PASSWORD
;
4635 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4636 /* Confirmed - RIGHT overrides CENTER */
4637 if (es
->style
& ES_RIGHT
)
4638 es
->style
&= ~ES_CENTER
;
4639 es
->style
&= ~WS_HSCROLL
;
4640 es
->style
&= ~ES_AUTOHSCROLL
;
4643 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4644 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4645 es
->style
&= ~ES_CENTER
;
4646 es
->style
&= ~WS_HSCROLL
;
4647 es
->style
&= ~WS_VSCROLL
;
4648 if (es
->style
& ES_PASSWORD
)
4649 es
->password_char
= '*';
4652 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4653 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4655 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4657 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4659 es
->undo_buffer_size
= es
->buffer_size
;
4661 if (es
->style
& ES_MULTILINE
)
4662 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4667 * In Win95 look and feel, the WS_BORDER style is replaced by the
4668 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4669 * control a nonclient area so we don't need to draw the border.
4670 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4671 * a nonclient area and we should handle painting the border ourselves.
4673 * When making modifications please ensure that the code still works
4674 * for edit controls created directly with style 0x50800000, exStyle 0
4675 * (which should have a single pixel border)
4677 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4678 es
->style
&= ~WS_BORDER
;
4679 else if (es
->style
& WS_BORDER
)
4680 SetWindowLongPtrW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4686 /*********************************************************************
4691 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4695 TRACE("%s\n", debugstr_w(name
));
4697 * To initialize some final structure members, we call some helper
4698 * functions. However, since the EDITSTATE is not consistent (i.e.
4699 * not fully initialized), we should be very careful which
4700 * functions can be called, and in what order.
4702 EDIT_WM_SetFont(es
, 0, FALSE
);
4703 EDIT_EM_EmptyUndoBuffer(es
);
4705 /* We need to calculate the format rect
4706 (applications may send EM_SETMARGINS before the control gets visible) */
4707 GetClientRect(es
->hwndSelf
, &clientRect
);
4708 EDIT_SetRectNP(es
, &clientRect
);
4710 if (name
&& *name
) {
4711 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4712 /* if we insert text to the editline, the text scrolls out
4713 * of the window, as the caret is placed after the insert
4714 * pos normally; thus we reset es->selection... to 0 and
4717 es
->selection_start
= es
->selection_end
= 0;
4718 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4719 * Messages are only to be sent when the USER does something to
4720 * change the contents. So I am removing this EN_CHANGE
4722 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4724 EDIT_EM_ScrollCaret(es
);
4726 /* force scroll info update */
4727 EDIT_UpdateScrollInfo(es
);
4728 /* The rule seems to return 1 here for success */
4729 /* Power Builder masked edit controls will crash */
4731 /* FIXME: is that in all cases so ? */
4736 /*********************************************************************
4741 static LRESULT
EDIT_WM_Destroy(EDITSTATE
*es
)
4746 LocalFree(es
->hloc32W
);
4749 LocalFree(es
->hloc32A
);
4753 STACK16FRAME
* stack16
= MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved
));
4754 HANDLE16 oldDS
= stack16
->ds
;
4756 stack16
->ds
= GetWindowLongPtrW( es
->hwndSelf
, GWLP_HINSTANCE
);
4757 while (LocalUnlock16(es
->hloc16
)) ;
4758 LocalFree16(es
->hloc16
);
4759 stack16
->ds
= oldDS
;
4763 pc
= es
->first_line_def
;
4767 HeapFree(GetProcessHeap(), 0, pc
);
4771 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4772 HeapFree(GetProcessHeap(), 0, es
);
4778 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4781 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4783 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4786 /*********************************************************************
4788 * EditWndProc_common
4790 * The messages are in the order of the actual integer values
4791 * (which can be found in include/windows.h)
4792 * Wherever possible the 16 bit versions are converted to
4793 * the 32 bit ones, so that we can 'fall through' to the
4794 * helper functions. These are mostly 32 bit (with a few
4795 * exceptions, clearly indicated by a '16' extension to their
4799 LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
,
4800 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4802 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4805 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4807 if (!es
&& msg
!= WM_NCCREATE
)
4808 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4810 if (es
&& (msg
!= WM_DESTROY
)) EDIT_LockBuffer(es
);
4820 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4825 if ((short)LOWORD(lParam
) == -1)
4826 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
4828 EDIT_EM_SetSel(es
, LOWORD(lParam
), HIWORD(lParam
), FALSE
);
4830 EDIT_EM_ScrollCaret(es
);
4835 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4836 EDIT_EM_ScrollCaret(es
);
4844 RECT16
*r16
= MapSL(lParam
);
4845 r16
->left
= es
->format_rect
.left
;
4846 r16
->top
= es
->format_rect
.top
;
4847 r16
->right
= es
->format_rect
.right
;
4848 r16
->bottom
= es
->format_rect
.bottom
;
4854 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
4859 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4861 RECT16
*r16
= MapSL(lParam
);
4862 rc
.left
= r16
->left
;
4864 rc
.right
= r16
->right
;
4865 rc
.bottom
= r16
->bottom
;
4866 EDIT_SetRectNP(es
, &rc
);
4867 EDIT_UpdateText(es
, NULL
, TRUE
);
4872 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4873 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4874 EDIT_UpdateText(es
, NULL
, TRUE
);
4879 case EM_SETRECTNP16
:
4880 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4882 RECT16
*r16
= MapSL(lParam
);
4883 rc
.left
= r16
->left
;
4885 rc
.right
= r16
->right
;
4886 rc
.bottom
= r16
->bottom
;
4887 EDIT_SetRectNP(es
, &rc
);
4892 if ((es
->style
& ES_MULTILINE
) && lParam
)
4893 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4900 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4904 case EM_LINESCROLL16
:
4905 wParam
= (WPARAM
)(INT
)(SHORT
)HIWORD(lParam
);
4906 lParam
= (LPARAM
)(INT
)(SHORT
)LOWORD(lParam
);
4910 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4914 case EM_SCROLLCARET16
:
4916 case EM_SCROLLCARET
:
4917 EDIT_EM_ScrollCaret(es
);
4922 case EM_GETMODIFY16
:
4925 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4929 case EM_SETMODIFY16
:
4933 es
->flags
|= EF_MODIFIED
;
4935 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4939 case EM_GETLINECOUNT16
:
4941 case EM_GETLINECOUNT
:
4942 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4946 case EM_LINEINDEX16
:
4947 if ((INT16
)wParam
== -1)
4948 wParam
= (WPARAM
)-1;
4952 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4956 case EM_SETHANDLE16
:
4957 EDIT_EM_SetHandle16(es
, (HLOCAL16
)wParam
);
4961 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4965 case EM_GETHANDLE16
:
4966 result
= (LRESULT
)EDIT_EM_GetHandle16(es
);
4970 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4977 result
= EDIT_EM_GetThumb(es
);
4980 /* these messages missing from specs */
4989 FIXME("undocumented message 0x%x, please report\n", msg
);
4990 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4994 case EM_LINELENGTH16
:
4997 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
5001 case EM_REPLACESEL16
:
5002 lParam
= (LPARAM
)MapSL(lParam
);
5003 unicode
= FALSE
; /* 16-bit message is always ascii */
5011 textW
= (LPWSTR
)lParam
;
5014 LPSTR textA
= (LPSTR
)lParam
;
5015 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
5016 if((textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5017 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
5020 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
5024 HeapFree(GetProcessHeap(), 0, textW
);
5030 lParam
= (LPARAM
)MapSL(lParam
);
5031 unicode
= FALSE
; /* 16-bit message is always ascii */
5035 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5039 case EM_LIMITTEXT16
:
5041 case EM_SETLIMITTEXT
:
5042 EDIT_EM_SetLimitText(es
, wParam
);
5049 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
5057 result
= (LRESULT
)EDIT_EM_Undo(es
);
5064 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
5068 case EM_LINEFROMCHAR16
:
5070 case EM_LINEFROMCHAR
:
5071 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
5075 case EM_SETTABSTOPS16
:
5076 result
= (LRESULT
)EDIT_EM_SetTabStops16(es
, (INT
)wParam
, MapSL(lParam
));
5079 case EM_SETTABSTOPS
:
5080 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
5084 case EM_SETPASSWORDCHAR16
:
5085 unicode
= FALSE
; /* 16-bit message is always ascii */
5088 case EM_SETPASSWORDCHAR
:
5093 charW
= (WCHAR
)wParam
;
5096 CHAR charA
= wParam
;
5097 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5100 EDIT_EM_SetPasswordChar(es
, charW
);
5105 case EM_EMPTYUNDOBUFFER16
:
5107 case EM_EMPTYUNDOBUFFER
:
5108 EDIT_EM_EmptyUndoBuffer(es
);
5112 case EM_GETFIRSTVISIBLELINE16
:
5113 result
= es
->y_offset
;
5116 case EM_GETFIRSTVISIBLELINE
:
5117 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
5121 case EM_SETREADONLY16
:
5123 case EM_SETREADONLY
:
5125 SetWindowLongPtrW( hwnd
, GWL_STYLE
,
5126 GetWindowLongPtrW( hwnd
, GWL_STYLE
) | ES_READONLY
);
5127 es
->style
|= ES_READONLY
;
5129 SetWindowLongPtrW( hwnd
, GWL_STYLE
,
5130 GetWindowLongPtrW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
5131 es
->style
&= ~ES_READONLY
;
5137 case EM_SETWORDBREAKPROC16
:
5138 EDIT_EM_SetWordBreakProc16(es
, (EDITWORDBREAKPROC16
)lParam
);
5141 case EM_SETWORDBREAKPROC
:
5142 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
5146 case EM_GETWORDBREAKPROC16
:
5147 result
= (LRESULT
)es
->word_break_proc16
;
5150 case EM_GETWORDBREAKPROC
:
5151 result
= (LRESULT
)es
->word_break_proc
;
5155 case EM_GETPASSWORDCHAR16
:
5156 unicode
= FALSE
; /* 16-bit message is always ascii */
5159 case EM_GETPASSWORDCHAR
:
5162 result
= es
->password_char
;
5165 WCHAR charW
= es
->password_char
;
5167 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
5173 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
5176 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
5180 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
5183 case EM_GETLIMITTEXT
:
5184 result
= es
->buffer_limit
;
5187 case EM_POSFROMCHAR
:
5188 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
5189 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
5192 case EM_CHARFROMPOS
:
5193 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5196 /* End of the EM_ messages which were in numerical order; what order
5197 * are these in? vaguely alphabetical?
5201 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
5205 result
= EDIT_WM_Destroy(es
);
5210 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
5212 if (es
->style
& ES_MULTILINE
)
5213 result
|= DLGC_WANTALLKEYS
;
5217 es
->flags
|=EF_DIALOGMODE
;
5219 if (((LPMSG
)lParam
)->message
== WM_KEYDOWN
)
5221 int vk
= (int)((LPMSG
)lParam
)->wParam
;
5223 if (es
->hwndListBox
)
5225 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
5226 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5227 result
|= DLGC_WANTMESSAGE
;
5239 strng
[0] = wParam
>> 8;
5240 strng
[1] = wParam
& 0xff;
5241 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
5242 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
5243 result
= EDIT_WM_Char(es
, charW
);
5255 CHAR charA
= wParam
;
5256 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
5259 if (es
->hwndListBox
)
5261 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
5263 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
5264 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
5268 result
= EDIT_WM_Char(es
, charW
);
5275 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
5276 if (wParam
<= 0x000fffff)
5278 if(wParam
> 0xffff) /* convert to surrogates */
5281 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
5282 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
5284 else EDIT_WM_Char(es
, wParam
);
5295 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
5298 case WM_CONTEXTMENU
:
5299 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5308 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
5311 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
5312 LPWSTR nameW
= NULL
;
5315 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
5316 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5317 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
5319 result
= EDIT_WM_Create(es
, nameW
);
5320 HeapFree(GetProcessHeap(), 0, nameW
);
5329 es
->bEnableState
= (BOOL
) wParam
;
5330 EDIT_UpdateText(es
, NULL
, TRUE
);
5334 /* we do the proper erase in EDIT_WM_Paint */
5339 result
= (LRESULT
)es
->font
;
5343 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5346 case WM_GETTEXTLENGTH
:
5347 if (unicode
) result
= get_text_length(es
);
5348 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
5349 NULL
, 0, NULL
, NULL
);
5353 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5357 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
5361 result
= EDIT_WM_KillFocus(es
);
5364 case WM_LBUTTONDBLCLK
:
5365 result
= EDIT_WM_LButtonDblClk(es
);
5368 case WM_LBUTTONDOWN
:
5369 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5373 result
= EDIT_WM_LButtonUp(es
);
5376 case WM_MBUTTONDOWN
:
5377 result
= EDIT_WM_MButtonDown(es
);
5381 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5384 case WM_PRINTCLIENT
:
5386 EDIT_WM_Paint(es
, (HDC
)wParam
);
5394 EDIT_WM_SetFocus(es
);
5398 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
5402 /* FIXME: actually set an internal flag and behave accordingly */
5406 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
5411 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
5414 case WM_STYLECHANGED
:
5415 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
5418 case WM_STYLECHANGING
:
5419 result
= 0; /* See EDIT_WM_StyleChanged */
5423 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5431 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5436 int gcWheelDelta
= 0;
5437 UINT pulScrollLines
= 3;
5438 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5440 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
5441 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5444 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
5445 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
5447 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
5448 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
5449 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
5455 /* IME messages to make the edit control IME aware */
5456 case WM_IME_SETCONTEXT
:
5459 case WM_IME_STARTCOMPOSITION
:
5460 es
->composition_start
= es
->selection_end
;
5461 es
->composition_len
= 0;
5464 case WM_IME_COMPOSITION
:
5465 EDIT_ImeComposition(hwnd
, lParam
, es
);
5468 case WM_IME_ENDCOMPOSITION
:
5469 if (es
->composition_len
> 0)
5471 static const WCHAR empty_stringW
[] = {0};
5472 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5473 es
->selection_end
= es
->selection_start
;
5474 es
->composition_len
= 0;
5478 case WM_IME_COMPOSITIONFULL
:
5484 case WM_IME_CONTROL
:
5488 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5492 if (es
) EDIT_UnlockBuffer(es
, FALSE
);
5494 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5499 /*********************************************************************
5501 * EditWndProc (USER32.@)
5503 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5505 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
5508 /*********************************************************************
5510 * EditWndProcW (USER32.@)
5512 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5514 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
5517 /*********************************************************************
5518 * edit class descriptor
5520 static const WCHAR editW
[] = {'E','d','i','t',0};
5521 const struct builtin_class_descr EDIT_builtin_class
=
5524 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5525 EditWndProcA
, /* procA */
5526 EditWndProcW
, /* procW */
5527 sizeof(EDITSTATE
*), /* extra */
5528 IDC_IBEAM
, /* cursor */