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
46 #define WIN32_LEAN_AND_MEAN
49 #include <wine/debug.h>
51 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
52 WINE_DECLARE_DEBUG_CHANNEL(combo
);
53 WINE_DECLARE_DEBUG_CHANNEL(relay
);
55 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
56 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
57 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
58 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
61 * extra flags for EDITSTATE.flags field
63 #define EF_MODIFIED 0x0001 /* text has been modified */
64 #define EF_FOCUSED 0x0002 /* we have input focus */
65 #define EF_UPDATE 0x0004 /* notify parent of changed state */
66 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
67 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
68 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
69 wrapped line, instead of in front of the next character */
70 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
71 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
72 the text buffer if this is clear. */
73 #define EF_DIALOGMODE 0x0400 /* Indicates that we are inside a dialog window */
77 END_0
= 0, /* line ends with terminating '\0' character */
78 END_WRAP
, /* line is wrapped */
79 END_HARD
, /* line ends with a hard return '\r\n' */
80 END_SOFT
, /* line ends with a soft return '\r\r\n' */
81 END_RICH
/* line ends with a single '\n' */
84 typedef struct tagLINEDEF
{
85 INT length
; /* bruto length of a line in bytes */
86 INT net_length
; /* netto length of a line in visible characters */
88 INT width
; /* width of the line in pixels */
89 INT index
; /* line index into the buffer */
90 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data */
91 struct tagLINEDEF
*next
;
96 BOOL is_unicode
; /* how the control was created */
97 LPWSTR text
; /* the actual contents of the control */
98 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
99 UINT buffer_size
; /* the size of the buffer in characters */
100 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
101 HFONT font
; /* NULL means standard system font */
102 INT x_offset
; /* scroll offset for multi lines this is in pixels
103 for single lines it's in characters */
104 INT line_height
; /* height of a screen line in pixels */
105 INT char_width
; /* average character width in pixels */
106 DWORD style
; /* sane version of wnd->dwStyle */
107 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
108 INT undo_insert_count
; /* number of characters inserted in sequence */
109 UINT undo_position
; /* character index of the insertion and deletion */
110 LPWSTR undo_text
; /* deleted text */
111 UINT undo_buffer_size
; /* size of the deleted text buffer */
112 INT selection_start
; /* == selection_end if no selection */
113 INT selection_end
; /* == current caret position */
114 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
115 INT left_margin
; /* in pixels */
116 INT right_margin
; /* in pixels */
118 INT text_width
; /* width of the widest line in pixels for multi line controls
119 and just line width for single line controls */
120 INT region_posx
; /* Position of cursor relative to region: */
121 INT region_posy
; /* -1: to left, 0: within, 1: to right */
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 */
140 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
145 UINT composition_len
; /* length of composition, 0 == no composition */
146 int composition_start
; /* the character position for the composition */
150 SCRIPT_LOGATTR
*logAttr
;
151 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data for single line controls */
155 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
156 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
158 /* used for disabled or read-only edit control */
159 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
161 { /* Notify parent which has created this edit control */ \
162 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
163 SendMessageW(es->hwndParent, WM_COMMAND, \
164 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
165 (LPARAM)(es->hwndSelf)); \
168 static const WCHAR empty_stringW
[] = {0};
169 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
171 /*********************************************************************
176 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
178 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
182 /*********************************************************************
187 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
189 es
->undo_insert_count
= 0;
190 *es
->undo_text
= '\0';
194 /**********************************************************************
197 * Returns the window version in case Wine emulates a later version
198 * of windows than the application expects.
200 * In a number of cases when windows runs an application that was
201 * designed for an earlier windows version, windows reverts
202 * to "old" behaviour of that earlier version.
204 * An example is a disabled edit control that needs to be painted.
205 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
206 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
207 * applications with an expected version 0f 4.0 or higher.
210 static DWORD
get_app_version(void)
212 static DWORD version
;
215 DWORD dwEmulatedVersion
;
217 DWORD dwProcVersion
= GetProcessVersion(0);
219 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
220 GetVersionExW( &info
);
221 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
222 /* FIXME: this may not be 100% correct; see discussion on the
223 * wine developer list in Nov 1999 */
224 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
229 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
234 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
235 msg
= WM_CTLCOLORSTATIC
;
237 msg
= WM_CTLCOLOREDIT
;
239 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
240 hbrush
= GetControlBrush(es
->hwndSelf
, hdc
, msg
); // reactos r54259
245 static inline UINT
get_text_length(EDITSTATE
*es
)
247 if(es
->text_length
== (UINT
)-1)
248 es
->text_length
= strlenW(es
->text
);
249 return es
->text_length
;
253 /*********************************************************************
257 * Find the beginning of words.
258 * Note: unlike the specs for a WordBreakProc, this function only
259 * allows to be called without linebreaks between s[0] up to
260 * s[count - 1]. Remember it is only called
261 * internally, so we can decide this for ourselves.
262 * Additional we will always be breaking the full string.
265 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
269 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
277 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
278 psa
.eScript
= SCRIPT_UNDEFINED
;
280 es
->logAttr
= HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
281 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
288 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
295 while (s
[index
] && index
< count
&& !es
->logAttr
[index
].fSoftBreak
)
300 ret
= es
->logAttr
[index
].fWhiteSpace
;
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
)
327 if (es
->word_break_proc
)
331 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
333 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
334 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
335 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
339 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
343 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
344 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
345 if (textA
== NULL
) return 0; // reactos r33503
346 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
347 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
348 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
349 ret
= wbpA(textA
, index
, countA
, action
);
350 HeapFree(GetProcessHeap(), 0, textA
);
354 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+start
, count
+start
, action
) - start
;
359 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
363 ScriptStringFree(&line_def
->ssa
);
364 line_def
->ssa
= NULL
;
368 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
370 LINEDEF
*line_def
= es
->first_line_def
;
373 EDIT_InvalidateUniscribeData_linedef(line_def
);
374 line_def
= line_def
->next
;
378 ScriptStringFree(&es
->ssa
);
383 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
388 if (line_def
->net_length
&& !line_def
->ssa
)
390 int index
= line_def
->index
;
391 HFONT old_font
= NULL
;
393 SCRIPT_TABDEF tabdef
;
396 udc
= GetDC(es
->hwndSelf
);
398 old_font
= SelectObject(udc
, es
->font
);
400 tabdef
.cTabStops
= es
->tabs_count
;
402 tabdef
.pTabStops
= es
->tabs
;
403 tabdef
.iTabOrigin
= 0;
405 ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
, (3*line_def
->net_length
/2+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1, NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
408 SelectObject(udc
, old_font
);
410 ReleaseDC(es
->hwndSelf
, udc
);
413 return line_def
->ssa
;
416 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
418 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
422 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
426 if (!(es
->style
& ES_MULTILINE
))
430 INT length
= get_text_length(es
);
431 HFONT old_font
= NULL
;
435 udc
= GetDC(es
->hwndSelf
);
437 old_font
= SelectObject(udc
, es
->font
);
439 if (es
->style
& ES_PASSWORD
)
440 ScriptStringAnalyse(udc
, &es
->password_char
, length
, (3*length
/2+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_PASSWORD
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
442 ScriptStringAnalyse(udc
, es
->text
, length
, (3*length
/2+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
445 SelectObject(udc
, old_font
);
447 ReleaseDC(es
->hwndSelf
, udc
);
453 line_def
= es
->first_line_def
;
454 while (line_def
&& line
)
456 line_def
= line_def
->next
;
460 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
464 /*********************************************************************
466 * EDIT_BuildLineDefs_ML
468 * Build linked list of text lines.
469 * Lines can end with '\0' (last line), a character (if it is wrapped),
470 * a soft return '\r\r\n' or a hard return '\r\n'
473 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
475 LPWSTR current_position
, cp
;
477 LINEDEF
*current_line
;
478 LINEDEF
*previous_line
;
480 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
481 INT line_count
= es
->line_count
;
486 if (istart
== iend
&& delta
== 0)
489 previous_line
= NULL
;
490 current_line
= es
->first_line_def
;
492 /* Find starting line. istart must lie inside an existing line or
493 * at the end of buffer */
495 if (istart
< current_line
->index
+ current_line
->length
||
496 current_line
->ending
== END_0
)
499 previous_line
= current_line
;
500 current_line
= current_line
->next
;
502 } while (current_line
);
504 if (!current_line
) /* Error occurred start is not inside previous buffer */
506 FIXME(" modification occurred outside buffer\n");
510 /* Remember start of modifications in order to calculate update region */
511 nstart_line
= line_index
;
512 nstart_index
= current_line
->index
;
514 /* We must start to reformat from the previous line since the modifications
515 * may have caused the line to wrap upwards. */
516 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
519 current_line
= previous_line
;
521 start_line
= current_line
;
523 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
524 current_position
= es
->text
+ current_line
->index
;
525 vlc
= get_vertical_line_count(es
);
527 if (current_line
!= start_line
)
529 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
531 /* The buffer has been expanded, create a new line and
532 insert it into the link list */
533 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
));
534 if (new_line
== NULL
) // reactos r33509
535 break; // reactos r33509
536 new_line
->next
= previous_line
->next
;
537 previous_line
->next
= new_line
;
538 current_line
= new_line
;
541 else if (current_line
->index
+ delta
< current_position
- es
->text
)
543 /* The previous line merged with this line so we delete this extra entry */
544 previous_line
->next
= current_line
->next
;
545 HeapFree(GetProcessHeap(), 0, current_line
);
546 current_line
= previous_line
->next
;
550 else /* current_line->index + delta == current_position */
552 if (current_position
- es
->text
> iend
)
553 break; /* We reached end of line modifications */
554 /* else recalculate this line */
558 current_line
->index
= current_position
- es
->text
;
559 orig_net_length
= current_line
->net_length
;
561 /* Find end of line */
562 cp
= current_position
;
564 if (*cp
== '\n') break;
565 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
570 /* Mark type of line termination */
572 current_line
->ending
= END_0
;
573 current_line
->net_length
= strlenW(current_position
);
574 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
575 current_line
->ending
= END_SOFT
;
576 current_line
->net_length
= cp
- current_position
- 1;
577 } else if (*cp
== '\n') {
578 current_line
->ending
= END_RICH
;
579 current_line
->net_length
= cp
- current_position
;
581 current_line
->ending
= END_HARD
;
582 current_line
->net_length
= cp
- current_position
;
585 if (current_line
->net_length
)
588 EDIT_InvalidateUniscribeData_linedef(current_line
);
589 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
590 sz
= ScriptString_pSize(current_line
->ssa
);
591 /* Calculate line width */
592 current_line
->width
= sz
->cx
;
594 else current_line
->width
= 0;
596 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
598 /* Line breaks just look back from the end and find the next break and try that. */
600 if (!(es
->style
& ES_AUTOHSCROLL
)) {
601 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
608 prev
= current_line
->net_length
- 1;
609 w
= current_line
->net_length
;
610 d
= (float)current_line
->width
/(float)fw
;
611 if (d
> 1.2) d
-= 0.2;
613 if (next
>= prev
) next
= prev
-1;
615 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
616 next
, current_line
->net_length
, WB_LEFT
);
617 current_line
->net_length
= prev
;
618 EDIT_InvalidateUniscribeData_linedef(current_line
);
619 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
620 sz
= ScriptString_pSize(current_line
->ssa
);
622 current_line
->width
= sz
->cx
;
626 } while (prev
&& current_line
->width
> fw
);
627 current_line
->net_length
= w
;
629 if (prev
== 0) { /* Didn't find a line break so force a break */
633 EDIT_InvalidateUniscribeData_linedef(current_line
);
634 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
636 count
= ScriptString_pcOutChars(current_line
->ssa
);
637 piDx
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * (*count
));
638 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
640 prev
= current_line
->net_length
-1;
642 current_line
->width
-= piDx
[prev
];
644 } while ( prev
> 0 && current_line
->width
> fw
);
647 HeapFree(GetProcessHeap(),0,piDx
);
650 /* If the first line we are calculating, wrapped before istart, we must
651 * adjust istart in order for this to be reflected in the update region. */
652 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
653 istart
= current_line
->index
+ prev
;
654 /* else if we are updating the previous line before the first line we
655 * are re-calculating and it expanded */
656 else if (current_line
== start_line
&&
657 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
659 /* Line expanded due to an upwards line wrap so we must partially include
660 * previous line in update region */
661 nstart_line
= line_index
;
662 nstart_index
= current_line
->index
;
663 istart
= current_line
->index
+ orig_net_length
;
666 current_line
->net_length
= prev
;
667 current_line
->ending
= END_WRAP
;
669 if (current_line
->net_length
> 0)
671 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
672 sz
= ScriptString_pSize(current_line
->ssa
);
673 current_line
->width
= sz
->cx
;
675 else current_line
->width
= 0;
677 else if (current_line
== start_line
&&
678 current_line
->index
!= nstart_index
&&
679 orig_net_length
< current_line
->net_length
) {
680 /* The previous line expanded but it's still not as wide as the client rect */
681 /* The expansion is due to an upwards line wrap so we must partially include
682 it in the update region */
683 nstart_line
= line_index
;
684 nstart_index
= current_line
->index
;
685 istart
= current_line
->index
+ orig_net_length
;
690 /* Adjust length to include line termination */
691 switch (current_line
->ending
) {
693 current_line
->length
= current_line
->net_length
+ 3;
696 current_line
->length
= current_line
->net_length
+ 1;
699 current_line
->length
= current_line
->net_length
+ 2;
703 current_line
->length
= current_line
->net_length
;
706 es
->text_width
= max(es
->text_width
, current_line
->width
);
707 current_position
+= current_line
->length
;
708 previous_line
= current_line
;
710 /* Discard data for non-visible lines. It will be calculated as needed */
711 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
712 EDIT_InvalidateUniscribeData_linedef(current_line
);
714 current_line
= current_line
->next
;
716 } while (previous_line
->ending
!= END_0
);
718 /* Finish adjusting line indexes by delta or remove hanging lines */
719 if (previous_line
->ending
== END_0
)
721 LINEDEF
*pnext
= NULL
;
723 previous_line
->next
= NULL
;
726 pnext
= current_line
->next
;
727 EDIT_InvalidateUniscribeData_linedef(current_line
);
728 HeapFree(GetProcessHeap(), 0, current_line
);
729 current_line
= pnext
;
737 current_line
->index
+= delta
;
738 current_line
= current_line
->next
;
742 /* Calculate rest of modification rectangle */
747 * We calculate two rectangles. One for the first line which may have
748 * an indent with respect to the format rect. The other is a format-width
749 * rectangle that spans the rest of the lines that changed or moved.
751 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
752 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
753 rc
.bottom
= rc
.top
+ es
->line_height
;
754 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
755 rc
.left
= es
->format_rect
.left
;
757 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
758 rc
.right
= es
->format_rect
.right
;
759 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
762 rc
.left
= es
->format_rect
.left
;
763 rc
.right
= es
->format_rect
.right
;
765 * If lines were added or removed we must re-paint the remainder of the
766 * lines since the remaining lines were either shifted up or down.
768 if (line_count
< es
->line_count
) /* We added lines */
769 rc
.bottom
= es
->line_count
* es
->line_height
;
770 else if (line_count
> es
->line_count
) /* We removed lines */
771 rc
.bottom
= line_count
* es
->line_height
;
773 rc
.bottom
= line_index
* es
->line_height
;
774 rc
.bottom
+= es
->format_rect
.top
;
775 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
776 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
777 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
778 DeleteObject(tmphrgn
);
782 /*********************************************************************
784 * EDIT_CalcLineWidth_SL
787 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
789 EDIT_UpdateUniscribeData(es
, NULL
, 0);
793 size
= ScriptString_pSize(es
->ssa
);
794 es
->text_width
= size
->cx
;
800 /*********************************************************************
804 * Beware: This is not the function called on EM_CHARFROMPOS
805 * The position _can_ be outside the formatting / client
807 * The return value is only the character index
810 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
814 if (es
->style
& ES_MULTILINE
) {
816 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
818 LINEDEF
*line_def
= es
->first_line_def
;
819 EDIT_UpdateUniscribeData(es
, NULL
, line
);
820 while ((line
> 0) && line_def
->next
) {
821 line_index
+= line_def
->length
;
822 line_def
= line_def
->next
;
826 x
+= es
->x_offset
- es
->format_rect
.left
;
827 if (es
->style
& ES_RIGHT
)
828 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
829 else if (es
->style
& ES_CENTER
)
830 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
831 if (x
>= line_def
->width
) {
833 *after_wrap
= (line_def
->ending
== END_WRAP
);
834 return line_index
+ line_def
->net_length
;
836 if (x
<= 0 || !line_def
->ssa
) {
842 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
843 if (trailing
) index
++;
846 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
847 (line_def
->ending
== END_WRAP
));
853 x
-= es
->format_rect
.left
;
859 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
860 if (es
->style
& ES_RIGHT
)
862 else if (es
->style
& ES_CENTER
)
866 EDIT_UpdateUniscribeData(es
, NULL
, 0);
871 if (es
->x_offset
>= get_text_length(es
))
874 size
= ScriptString_pSize(es
->ssa
);
877 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
884 if (x
+ xoff
> 0 || !es
->ssa
)
886 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
887 if (trailing
) index
++;
896 const SIZE
*size
= NULL
;
898 size
= ScriptString_pSize(es
->ssa
);
901 else if (x
> size
->cx
)
902 index
= get_text_length(es
);
905 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
906 if (trailing
) index
++;
912 index
= es
->x_offset
;
919 /*********************************************************************
923 * adjusts the point to be within the formatting rectangle
924 * (so CharFromPos returns the nearest _visible_ character)
927 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
929 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
930 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
934 /*********************************************************************
939 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
944 if (!(es
->style
& ES_MULTILINE
))
946 if (index
> (INT
)get_text_length(es
))
947 return es
->line_count
- 1;
949 index
= min(es
->selection_start
, es
->selection_end
);
952 line_def
= es
->first_line_def
;
953 index
-= line_def
->length
;
954 while ((index
>= 0) && line_def
->next
) {
956 line_def
= line_def
->next
;
957 index
-= line_def
->length
;
963 /*********************************************************************
968 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
971 const LINEDEF
*line_def
;
973 if (!(es
->style
& ES_MULTILINE
))
975 if (line
>= es
->line_count
)
979 line_def
= es
->first_line_def
;
981 INT index
= es
->selection_end
- line_def
->length
;
982 while ((index
>= 0) && line_def
->next
) {
983 line_index
+= line_def
->length
;
984 line_def
= line_def
->next
;
985 index
-= line_def
->length
;
989 line_index
+= line_def
->length
;
990 line_def
= line_def
->next
;
998 /*********************************************************************
1003 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
1007 if (!(es
->style
& ES_MULTILINE
))
1008 return get_text_length(es
);
1011 /* get the number of remaining non-selected chars of selected lines */
1012 INT32 l
; /* line number */
1013 INT32 li
; /* index of first char in line */
1015 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
1016 /* # chars before start of selection area */
1017 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
1018 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1019 /* # chars after end of selection */
1020 li
= EDIT_EM_LineIndex(es
, l
);
1021 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
1024 line_def
= es
->first_line_def
;
1025 index
-= line_def
->length
;
1026 while ((index
>= 0) && line_def
->next
) {
1027 line_def
= line_def
->next
;
1028 index
-= line_def
->length
;
1030 return line_def
->net_length
;
1034 /*********************************************************************
1039 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1041 INT len
= get_text_length(es
);
1050 index
= min(index
, len
);
1051 if (es
->style
& ES_MULTILINE
) {
1052 l
= EDIT_EM_LineFromChar(es
, index
);
1053 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1055 y
= (l
- es
->y_offset
) * es
->line_height
;
1056 li
= EDIT_EM_LineIndex(es
, l
);
1057 if (after_wrap
&& (li
== index
) && l
) {
1059 line_def
= es
->first_line_def
;
1061 line_def
= line_def
->next
;
1064 if (line_def
->ending
== END_WRAP
) {
1066 y
-= es
->line_height
;
1067 li
= EDIT_EM_LineIndex(es
, l
);
1071 line_def
= es
->first_line_def
;
1072 while (line_def
->index
!= li
)
1073 line_def
= line_def
->next
;
1075 lw
= line_def
->width
;
1076 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1079 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1085 if (es
->style
& ES_RIGHT
)
1087 else if (es
->style
& ES_CENTER
)
1092 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1097 if (es
->x_offset
>= get_text_length(es
))
1099 int leftover
= es
->x_offset
- get_text_length(es
);
1103 size
= ScriptString_pSize(es
->ssa
);
1108 xoff
+= es
->char_width
* leftover
;
1111 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1118 if (index
>= get_text_length(es
))
1123 size
= ScriptString_pSize(es
->ssa
);
1130 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1136 if (index
>= es
->x_offset
) {
1137 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1139 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1140 if (w
> es
->text_width
)
1142 if (es
->style
& ES_RIGHT
)
1143 x
+= w
- es
->text_width
;
1144 else if (es
->style
& ES_CENTER
)
1145 x
+= (w
- es
->text_width
) / 2;
1151 x
+= es
->format_rect
.left
;
1152 y
+= es
->format_rect
.top
;
1153 return MAKELONG((INT16
)x
, (INT16
)y
);
1157 /*********************************************************************
1161 * Calculates the bounding rectangle for a line from a starting
1162 * column to an ending column.
1165 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1167 SCRIPT_STRING_ANALYSIS ssa
;
1171 if (es
->style
& ES_MULTILINE
)
1173 const LINEDEF
*line_def
= NULL
;
1174 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1175 if (line
>= es
->line_count
)
1178 line_def
= es
->first_line_def
;
1180 INT index
= es
->selection_end
- line_def
->length
;
1181 while ((index
>= 0) && line_def
->next
) {
1182 line_index
+= line_def
->length
;
1183 line_def
= line_def
->next
;
1184 index
-= line_def
->length
;
1188 line_index
+= line_def
->length
;
1189 line_def
= line_def
->next
;
1193 ssa
= line_def
->ssa
;
1198 rc
->top
= es
->format_rect
.top
;
1202 rc
->bottom
= rc
->top
+ es
->line_height
;
1203 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1204 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1207 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1208 pt3
+=es
->format_rect
.left
;
1211 rc
->right
= max(max(pt1
, pt2
),pt3
);
1212 rc
->left
= min(min(pt1
, pt2
),pt3
);
1216 static inline void text_buffer_changed(EDITSTATE
*es
)
1218 es
->text_length
= (UINT
)-1;
1220 HeapFree( GetProcessHeap(), 0, es
->logAttr
);
1222 EDIT_InvalidateUniscribeData(es
);
1225 /*********************************************************************
1229 static void EDIT_LockBuffer(EDITSTATE
*es
)
1233 CHAR
*textA
= NULL
; // ReactOS Hacked! r45670
1240 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1241 textA
= LocalLock(es
->hloc32A
);
1242 //countA = strlen(textA) + 1;
1246 ERR("no buffer ... please report\n");
1253 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
1254 if(countW_new
> es
->buffer_size
+ 1)
1256 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1257 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1258 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1261 es
->hloc32W
= hloc32W_new
;
1262 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1263 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1266 WARN("FAILED! Will synchronize partially\n");
1268 es
->text
= LocalLock(es
->hloc32W
);
1269 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, es
->text
, es
->buffer_size
+ 1);
1270 LocalUnlock(es
->hloc32A
);
1272 else es
->text
= LocalLock(es
->hloc32W
);
1274 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1279 /*********************************************************************
1284 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1287 /* Edit window might be already destroyed */
1288 if(!IsWindow(es
->hwndSelf
))
1290 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1294 if (!es
->lock_count
) {
1295 ERR("lock_count == 0 ... please report\n");
1299 ERR("es->text == 0 ... please report\n");
1303 if (force
|| (es
->lock_count
== 1)) {
1306 UINT countW
= get_text_length(es
) + 1;
1310 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1311 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1312 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1313 countA
= LocalSize(es
->hloc32A
);
1314 if(countA_new
> countA
)
1317 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1318 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1319 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1322 es
->hloc32A
= hloc32A_new
;
1323 countA
= LocalSize(hloc32A_new
);
1324 TRACE("Real new size %d bytes\n", countA
);
1327 WARN("FAILED! Will synchronize partially\n");
1329 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
,
1330 LocalLock(es
->hloc32A
), countA
, NULL
, NULL
);
1331 LocalUnlock(es
->hloc32A
);
1334 LocalUnlock(es
->hloc32W
);
1338 ERR("no buffer ... please report\n");
1346 /*********************************************************************
1350 * Try to fit size + 1 characters in the buffer.
1352 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1356 if (size
<= es
->buffer_size
)
1359 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1361 /* Force edit to unlock it's buffer. es->text now NULL */
1362 EDIT_UnlockBuffer(es
, TRUE
);
1365 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1366 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1367 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1368 es
->hloc32W
= hNew32W
;
1369 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1373 EDIT_LockBuffer(es
);
1375 if (es
->buffer_size
< size
) {
1376 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1377 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1380 TRACE("We now have %d+1\n", es
->buffer_size
);
1386 /*********************************************************************
1390 * Try to fit size + 1 bytes in the undo buffer.
1393 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1397 if (size
<= es
->undo_buffer_size
)
1400 TRACE("trying to ReAlloc to %d+1\n", size
);
1402 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1403 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1404 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1409 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1415 /*********************************************************************
1417 * EDIT_UpdateTextRegion
1420 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1422 if (es
->flags
& EF_UPDATE
) {
1423 es
->flags
&= ~EF_UPDATE
;
1424 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1426 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1430 /*********************************************************************
1435 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1437 if (es
->flags
& EF_UPDATE
) {
1438 es
->flags
&= ~EF_UPDATE
;
1439 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1441 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1444 /*********************************************************************
1446 * EDIT_SL_InvalidateText
1448 * Called from EDIT_InvalidateText().
1449 * Does the job for single-line controls only.
1452 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1457 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1458 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1459 EDIT_UpdateText(es
, &rc
, TRUE
);
1462 /*********************************************************************
1464 * EDIT_ML_InvalidateText
1466 * Called from EDIT_InvalidateText().
1467 * Does the job for multi-line controls only.
1470 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1472 INT vlc
= get_vertical_line_count(es
);
1473 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1474 INT el
= EDIT_EM_LineFromChar(es
, end
);
1483 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1486 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1487 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1488 if (sl
< es
->y_offset
) {
1492 if (el
> es
->y_offset
+ vlc
) {
1493 el
= es
->y_offset
+ vlc
;
1494 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1496 GetClientRect(es
->hwndSelf
, &rc1
);
1497 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1499 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1500 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1501 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1503 EDIT_GetLineRect(es
, sl
, sc
,
1504 EDIT_EM_LineLength(es
,
1505 EDIT_EM_LineIndex(es
, sl
)),
1507 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1508 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1509 for (l
= sl
+ 1 ; l
< el
; l
++) {
1510 EDIT_GetLineRect(es
, l
, 0,
1511 EDIT_EM_LineLength(es
,
1512 EDIT_EM_LineIndex(es
, l
)),
1514 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1515 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1517 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1518 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1519 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1524 /*********************************************************************
1526 * EDIT_InvalidateText
1528 * Invalidate the text from offset start up to, but not including,
1529 * offset end. Useful for (re)painting the selection.
1530 * Regions outside the linewidth are not invalidated.
1531 * end == -1 means end == TextLength.
1532 * start and end need not be ordered.
1535 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1541 end
= get_text_length(es
);
1549 if (es
->style
& ES_MULTILINE
)
1550 EDIT_ML_InvalidateText(es
, start
, end
);
1552 EDIT_SL_InvalidateText(es
, start
, end
);
1556 /*********************************************************************
1560 * note: unlike the specs say: the order of start and end
1561 * _is_ preserved in Windows. (i.e. start can be > end)
1562 * In other words: this handler is OK
1565 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1567 UINT old_start
= es
->selection_start
;
1568 UINT old_end
= es
->selection_end
;
1569 UINT len
= get_text_length(es
);
1571 if (start
== (UINT
)-1) {
1572 start
= es
->selection_end
;
1573 end
= es
->selection_end
;
1575 start
= min(start
, len
);
1576 end
= min(end
, len
);
1578 es
->selection_start
= start
;
1579 es
->selection_end
= end
;
1581 es
->flags
|= EF_AFTER_WRAP
;
1583 es
->flags
&= ~EF_AFTER_WRAP
;
1584 /* Compute the necessary invalidation region. */
1585 /* Note that we don't need to invalidate regions which have
1586 * "never" been selected, or those which are "still" selected.
1587 * In fact, every time we hit a selection boundary, we can
1588 * *toggle* whether we need to invalidate. Thus we can optimize by
1589 * *sorting* the interval endpoints. Let's assume that we sort them
1591 * start <= end <= old_start <= old_end
1592 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1593 * in 5 comparisons; i.e. it is impossible to do better than the
1595 ORDER_UINT(end
, old_end
);
1596 ORDER_UINT(start
, old_start
);
1597 ORDER_UINT(old_start
, old_end
);
1598 ORDER_UINT(start
, end
);
1599 /* Note that at this point 'end' and 'old_start' are not in order, but
1600 * start is definitely the min. and old_end is definitely the max. */
1601 if (end
!= old_start
)
1605 * ORDER_UINT32(end, old_start);
1606 * EDIT_InvalidateText(es, start, end);
1607 * EDIT_InvalidateText(es, old_start, old_end);
1608 * in place of the following if statement.
1609 * (That would complete the optimal five-comparison four-element sort.)
1611 if (old_start
> end
)
1613 EDIT_InvalidateText(es
, start
, end
);
1614 EDIT_InvalidateText(es
, old_start
, old_end
);
1618 EDIT_InvalidateText(es
, start
, old_start
);
1619 EDIT_InvalidateText(es
, end
, old_end
);
1622 else EDIT_InvalidateText(es
, start
, old_end
);
1626 /*********************************************************************
1628 * EDIT_UpdateScrollInfo
1631 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1633 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1636 si
.cbSize
= sizeof(SCROLLINFO
);
1637 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1639 si
.nMax
= es
->line_count
- 1;
1640 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1641 si
.nPos
= es
->y_offset
;
1642 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1643 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1644 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1647 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1650 si
.cbSize
= sizeof(SCROLLINFO
);
1651 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1653 si
.nMax
= es
->text_width
- 1;
1654 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1655 si
.nPos
= es
->x_offset
;
1656 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1657 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1658 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1663 /*********************************************************************
1665 * EDIT_EM_LineScroll_internal
1667 * Version of EDIT_EM_LineScroll for internal use.
1668 * It doesn't refuse if ES_MULTILINE is set and assumes that
1669 * dx is in pixels, dy - in lines.
1672 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1675 INT x_offset_in_pixels
;
1676 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1679 if (es
->style
& ES_MULTILINE
)
1681 x_offset_in_pixels
= es
->x_offset
;
1686 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1689 if (-dx
> x_offset_in_pixels
)
1690 dx
= -x_offset_in_pixels
;
1691 if (dx
> es
->text_width
- x_offset_in_pixels
)
1692 dx
= es
->text_width
- x_offset_in_pixels
;
1693 nyoff
= max(0, es
->y_offset
+ dy
);
1694 if (nyoff
>= es
->line_count
- lines_per_page
)
1695 nyoff
= max(0, es
->line_count
- lines_per_page
);
1696 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1701 es
->y_offset
= nyoff
;
1702 if(es
->style
& ES_MULTILINE
)
1705 es
->x_offset
+= dx
/ es
->char_width
;
1707 GetClientRect(es
->hwndSelf
, &rc1
);
1708 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1709 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1710 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1711 /* force scroll info update */
1712 EDIT_UpdateScrollInfo(es
);
1714 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1715 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1716 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1717 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1721 /*********************************************************************
1725 * NOTE: dx is in average character widths, dy - in lines;
1728 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1730 if (!(es
->style
& ES_MULTILINE
))
1733 dx
*= es
->char_width
;
1734 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1738 /*********************************************************************
1743 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1747 if (!(es
->style
& ES_MULTILINE
))
1748 return (LRESULT
)FALSE
;
1758 if (es
->y_offset
< es
->line_count
- 1)
1763 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1766 if (es
->y_offset
< es
->line_count
- 1)
1767 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1770 return (LRESULT
)FALSE
;
1773 INT vlc
= get_vertical_line_count(es
);
1774 /* check if we are going to move too far */
1775 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1776 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1778 /* Notification is done in EDIT_EM_LineScroll */
1780 EDIT_EM_LineScroll(es
, 0, dy
);
1781 return MAKELONG(dy
, TRUE
);
1785 return (LRESULT
)FALSE
;
1789 /*********************************************************************
1794 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1797 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1798 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1799 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1803 /*********************************************************************
1808 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1810 if (es
->style
& ES_MULTILINE
) {
1814 INT cw
= es
->char_width
;
1819 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1820 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1821 vlc
= get_vertical_line_count(es
);
1822 if (l
>= es
->y_offset
+ vlc
)
1823 dy
= l
- vlc
+ 1 - es
->y_offset
;
1824 if (l
< es
->y_offset
)
1825 dy
= l
- es
->y_offset
;
1826 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1827 if (x
< es
->format_rect
.left
)
1828 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1829 if (x
> es
->format_rect
.right
)
1830 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1831 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1833 /* check if we are going to move too far */
1834 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1835 dx
= es
->text_width
- ww
- es
->x_offset
;
1836 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1837 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1844 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1845 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1846 if (x
< es
->format_rect
.left
) {
1847 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1850 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1851 } while ((x
< goal
) && es
->x_offset
);
1852 /* FIXME: use ScrollWindow() somehow to improve performance */
1853 EDIT_UpdateText(es
, NULL
, TRUE
);
1854 } else if (x
> es
->format_rect
.right
) {
1856 INT len
= get_text_length(es
);
1857 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1860 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1861 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1862 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1863 /* FIXME: use ScrollWindow() somehow to improve performance */
1864 EDIT_UpdateText(es
, NULL
, TRUE
);
1868 if(es
->flags
& EF_FOCUSED
)
1869 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1873 /*********************************************************************
1878 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1880 INT e
= es
->selection_end
;
1884 if ((es
->style
& ES_MULTILINE
) && e
&&
1885 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1887 if (e
&& (es
->text
[e
- 1] == '\r'))
1891 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1892 EDIT_EM_ScrollCaret(es
);
1896 /*********************************************************************
1900 * Only for multi line controls
1901 * Move the caret one line down, on a column with the nearest
1902 * x coordinate on the screen (might be a different column).
1905 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1907 INT s
= es
->selection_start
;
1908 INT e
= es
->selection_end
;
1909 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1910 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1911 INT x
= (short)LOWORD(pos
);
1912 INT y
= (short)HIWORD(pos
);
1914 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1917 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1918 EDIT_EM_ScrollCaret(es
);
1922 /*********************************************************************
1927 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1929 BOOL after_wrap
= FALSE
;
1932 /* Pass a high value in x to make sure of receiving the end of the line */
1933 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1934 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1935 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1937 e
= get_text_length(es
);
1938 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1939 EDIT_EM_ScrollCaret(es
);
1943 /*********************************************************************
1948 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1950 INT e
= es
->selection_end
;
1954 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1955 if (es
->text
[e
] == '\n')
1957 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1961 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1962 EDIT_EM_ScrollCaret(es
);
1966 /*********************************************************************
1970 * Home key: move to beginning of line.
1973 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1977 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1978 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1979 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1980 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1983 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1984 EDIT_EM_ScrollCaret(es
);
1988 /*********************************************************************
1990 * EDIT_MovePageDown_ML
1992 * Only for multi line controls
1993 * Move the caret one page down, on a column with the nearest
1994 * x coordinate on the screen (might be a different column).
1997 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1999 INT s
= es
->selection_start
;
2000 INT e
= es
->selection_end
;
2001 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2002 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2003 INT x
= (short)LOWORD(pos
);
2004 INT y
= (short)HIWORD(pos
);
2006 e
= EDIT_CharFromPos(es
, x
,
2007 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2011 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2012 EDIT_EM_ScrollCaret(es
);
2016 /*********************************************************************
2018 * EDIT_MovePageUp_ML
2020 * Only for multi line controls
2021 * Move the caret one page up, on a column with the nearest
2022 * x coordinate on the screen (might be a different column).
2025 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2027 INT s
= es
->selection_start
;
2028 INT e
= es
->selection_end
;
2029 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2030 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2031 INT x
= (short)LOWORD(pos
);
2032 INT y
= (short)HIWORD(pos
);
2034 e
= EDIT_CharFromPos(es
, x
,
2035 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2039 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2040 EDIT_EM_ScrollCaret(es
);
2044 /*********************************************************************
2048 * Only for multi line controls
2049 * Move the caret one line up, on a column with the nearest
2050 * x coordinate on the screen (might be a different column).
2053 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2055 INT s
= es
->selection_start
;
2056 INT e
= es
->selection_end
;
2057 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2058 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2059 INT x
= (short)LOWORD(pos
);
2060 INT y
= (short)HIWORD(pos
);
2062 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2065 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2066 EDIT_EM_ScrollCaret(es
);
2070 /*********************************************************************
2072 * EDIT_MoveWordBackward
2075 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2077 INT s
= es
->selection_start
;
2078 INT e
= es
->selection_end
;
2083 l
= EDIT_EM_LineFromChar(es
, e
);
2084 ll
= EDIT_EM_LineLength(es
, e
);
2085 li
= EDIT_EM_LineIndex(es
, l
);
2088 li
= EDIT_EM_LineIndex(es
, l
- 1);
2089 e
= li
+ EDIT_EM_LineLength(es
, li
);
2092 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2096 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2097 EDIT_EM_ScrollCaret(es
);
2101 /*********************************************************************
2103 * EDIT_MoveWordForward
2106 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2108 INT s
= es
->selection_start
;
2109 INT e
= es
->selection_end
;
2114 l
= EDIT_EM_LineFromChar(es
, e
);
2115 ll
= EDIT_EM_LineLength(es
, e
);
2116 li
= EDIT_EM_LineIndex(es
, l
);
2118 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2119 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2121 e
= li
+ EDIT_CallWordBreakProc(es
,
2122 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2126 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2127 EDIT_EM_ScrollCaret(es
);
2131 /*********************************************************************
2136 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2140 LOGFONTW underline_font
;
2141 HFONT hUnderline
= 0;
2150 BkMode
= GetBkMode(dc
);
2151 BkColor
= GetBkColor(dc
);
2152 TextColor
= GetTextColor(dc
);
2154 if (es
->composition_len
== 0)
2156 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2157 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2158 SetBkMode( dc
, OPAQUE
);
2162 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2163 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2164 underline_font
.lfUnderline
= TRUE
;
2165 hUnderline
= CreateFontIndirectW(&underline_font
);
2166 old_font
= SelectObject(dc
,hUnderline
);
2169 li
= EDIT_EM_LineIndex(es
, line
);
2170 if (es
->style
& ES_MULTILINE
) {
2171 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2172 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2174 LPWSTR text
= es
->text
;
2175 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2176 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2178 if (es
->style
& ES_PASSWORD
)
2179 HeapFree(GetProcessHeap(), 0, text
);
2182 if (es
->composition_len
== 0)
2184 SetBkColor(dc
, BkColor
);
2185 SetTextColor(dc
, TextColor
);
2186 SetBkMode( dc
, BkMode
);
2191 SelectObject(dc
,old_font
);
2193 DeleteObject(hUnderline
);
2200 /*********************************************************************
2205 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2214 SCRIPT_STRING_ANALYSIS ssa
;
2216 if (es
->style
& ES_MULTILINE
) {
2217 INT vlc
= get_vertical_line_count(es
);
2219 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2224 TRACE("line=%d\n", line
);
2226 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2227 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2228 x
= (short)LOWORD(pos
);
2229 y
= (short)HIWORD(pos
);
2231 if (es
->style
& ES_MULTILINE
)
2233 int line_idx
= line
;
2235 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2237 LINEDEF
*line_def
= es
->first_line_def
;
2240 while (line_def
&& line_idx
)
2242 line_def
= line_def
->next
;
2245 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2246 lw
= line_def
->width
;
2248 if (es
->style
& ES_RIGHT
)
2250 else if (es
->style
& ES_CENTER
)
2253 x
+= es
->format_rect
.left
;
2258 li
= EDIT_EM_LineIndex(es
, line
);
2259 ll
= EDIT_EM_LineLength(es
, li
);
2260 s
= min(es
->selection_start
, es
->selection_end
);
2261 e
= max(es
->selection_start
, es
->selection_end
);
2262 s
= min(li
+ ll
, max(li
, s
));
2263 e
= min(li
+ ll
, max(li
, e
));
2267 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2268 else if (rev
&& (s
!= e
) &&
2269 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2270 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2271 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2272 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2274 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2278 /*********************************************************************
2280 * EDIT_AdjustFormatRect
2282 * Adjusts the format rectangle for the current font and the
2283 * current client rectangle.
2286 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2290 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2291 if (es
->style
& ES_MULTILINE
)
2293 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2295 vlc
= get_vertical_line_count(es
);
2296 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2298 /* correct es->x_offset */
2299 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2300 max_x_offset
= es
->text_width
- fw
;
2301 if(max_x_offset
< 0) max_x_offset
= 0;
2302 if(es
->x_offset
> max_x_offset
)
2303 es
->x_offset
= max_x_offset
;
2305 /* correct es->y_offset */
2306 max_y_offset
= es
->line_count
- vlc
;
2307 if(max_y_offset
< 0) max_y_offset
= 0;
2308 if(es
->y_offset
> max_y_offset
)
2309 es
->y_offset
= max_y_offset
;
2311 /* force scroll info update */
2312 EDIT_UpdateScrollInfo(es
);
2315 /* Windows doesn't care to fix text placement for SL controls */
2316 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2318 /* Always stay within the client area */
2319 GetClientRect(es
->hwndSelf
, &ClientRect
);
2320 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2322 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2323 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2325 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2329 /*********************************************************************
2333 * note: this is not (exactly) the handler called on EM_SETRECTNP
2334 * it is also used to set the rect of a single line control
2337 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2341 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2343 CopyRect(&es
->format_rect
, rc
);
2345 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2346 es
->format_rect
.left
++;
2347 es
->format_rect
.right
--;
2349 if (es
->format_rect
.bottom
- es
->format_rect
.top
2350 >= es
->line_height
+ 2)
2352 es
->format_rect
.top
++;
2353 es
->format_rect
.bottom
--;
2356 else if (es
->style
& WS_BORDER
) {
2357 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2358 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2359 es
->format_rect
.left
+= bw
;
2360 es
->format_rect
.right
-= bw
;
2361 if (es
->format_rect
.bottom
- es
->format_rect
.top
2362 >= es
->line_height
+ 2 * bh
)
2364 es
->format_rect
.top
+= bh
;
2365 es
->format_rect
.bottom
-= bh
;
2369 es
->format_rect
.left
+= es
->left_margin
;
2370 es
->format_rect
.right
-= es
->right_margin
;
2371 EDIT_AdjustFormatRect(es
);
2375 /*********************************************************************
2379 * returns line number (not index) in high-order word of result.
2380 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2381 * to Richedit, not to the edit control. Original documentation is valid.
2382 * FIXME: do the specs mean to return -1 if outside client area or
2383 * if outside formatting rectangle ???
2386 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2394 GetClientRect(es
->hwndSelf
, &rc
);
2395 if (!PtInRect(&rc
, pt
))
2398 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2399 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2403 /*********************************************************************
2407 * Enable or disable soft breaks.
2409 * This means: insert or remove the soft linebreak character (\r\r\n).
2410 * Take care to check if the text still fits the buffer after insertion.
2411 * If not, notify with EN_ERRSPACE.
2414 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2416 es
->flags
&= ~EF_USE_SOFTBRK
;
2418 es
->flags
|= EF_USE_SOFTBRK
;
2419 FIXME("soft break enabled, not implemented\n");
2425 /*********************************************************************
2429 * Hopefully this won't fire back at us.
2430 * We always start with a fixed buffer in the local heap.
2431 * Despite of the documentation says that the local heap is used
2432 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2433 * buffer on the local heap.
2436 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2440 if (!(es
->style
& ES_MULTILINE
))
2444 hLocal
= es
->hloc32W
;
2450 UINT countA
, alloc_size
;
2451 TRACE("Allocating 32-bit ANSI alias buffer\n");
2452 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2453 alloc_size
= ROUND_TO_GROW(countA
);
2454 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2456 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2459 textA
= LocalLock(es
->hloc32A
);
2460 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2461 LocalUnlock(es
->hloc32A
);
2463 hLocal
= es
->hloc32A
;
2466 es
->flags
|= EF_APP_HAS_HANDLE
;
2467 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2472 /*********************************************************************
2477 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2480 INT line_len
, dst_len
;
2483 if (es
->style
& ES_MULTILINE
) {
2484 if (line
>= es
->line_count
)
2488 i
= EDIT_EM_LineIndex(es
, line
);
2490 line_len
= EDIT_EM_LineLength(es
, i
);
2491 dst_len
= *(WORD
*)dst
;
2494 if(dst_len
<= line_len
)
2496 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2499 else /* Append 0 if enough space */
2501 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2508 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2509 if(!ret
&& line_len
) /* Insufficient buffer size */
2511 if(ret
< dst_len
) /* Append 0 if enough space */
2512 ((LPSTR
)dst
)[ret
] = 0;
2518 /*********************************************************************
2523 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2525 UINT s
= es
->selection_start
;
2526 UINT e
= es
->selection_end
;
2533 return MAKELONG(s
, e
);
2537 /*********************************************************************
2541 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2544 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2546 UINT strl
= strlenW(lpsz_replace
);
2547 UINT tl
= get_text_length(es
);
2558 TRACE("%s, can_undo %d, send_update %d\n",
2559 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2561 s
= es
->selection_start
;
2562 e
= es
->selection_end
;
2564 EDIT_InvalidateUniscribeData(es
);
2565 if ((s
== e
) && !strl
)
2570 size
= tl
- (e
- s
) + strl
;
2574 /* Issue the EN_MAXTEXT notification and continue with replacing text
2575 * such that buffer limit is honored. */
2576 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2577 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2578 /* Buffer limit can be smaller than the actual length of text in combobox */
2579 if (es
->buffer_limit
< (tl
- (e
-s
)))
2582 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2585 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2589 /* there is something to be deleted */
2590 TRACE("deleting stuff.\n");
2592 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2594 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2595 buf
[bufl
] = 0; /* ensure 0 termination */
2597 strcpyW(es
->text
+ s
, es
->text
+ e
);
2598 text_buffer_changed(es
);
2601 /* there is an insertion */
2602 tl
= get_text_length(es
);
2603 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
));
2604 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2606 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2607 p
[i
] = lpsz_replace
[i
];
2608 if(es
->style
& ES_UPPERCASE
)
2609 CharUpperBuffW(p
, strl
);
2610 else if(es
->style
& ES_LOWERCASE
)
2611 CharLowerBuffW(p
, strl
);
2612 text_buffer_changed(es
);
2614 if (es
->style
& ES_MULTILINE
)
2616 INT st
= min(es
->selection_start
, es
->selection_end
);
2617 INT vlc
= get_vertical_line_count(es
);
2619 hrgn
= CreateRectRgn(0, 0, 0, 0);
2620 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2621 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2622 /* if text is too long undo all changes */
2623 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2625 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2627 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2629 text_buffer_changed(es
);
2630 EDIT_BuildLineDefs_ML(es
, s
, e
,
2631 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2634 hrgn
= CreateRectRgn(0, 0, 0, 0);
2635 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2639 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2640 EDIT_InvalidateUniscribeData(es
);
2641 EDIT_CalcLineWidth_SL(es
);
2642 /* remove chars that don't fit */
2643 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2644 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2645 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2647 es
->text_length
= -1;
2648 EDIT_InvalidateUniscribeData(es
);
2649 EDIT_CalcLineWidth_SL(es
);
2651 text_buffer_changed(es
);
2652 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2658 utl
= strlenW(es
->undo_text
);
2659 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2660 /* undo-buffer is extended to the right */
2661 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2662 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2663 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2664 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2665 /* undo-buffer is extended to the left */
2666 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2667 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2669 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2671 es
->undo_position
= s
;
2673 /* new undo-buffer */
2674 EDIT_MakeUndoFit(es
, e
- s
);
2675 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2676 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2677 es
->undo_position
= s
;
2679 /* any deletion makes the old insertion-undo invalid */
2680 es
->undo_insert_count
= 0;
2682 EDIT_EM_EmptyUndoBuffer(es
);
2686 if ((s
== es
->undo_position
) ||
2687 ((es
->undo_insert_count
) &&
2688 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2690 * insertion is new and at delete position or
2691 * an extension to either left or right
2693 es
->undo_insert_count
+= strl
;
2695 /* new insertion undo */
2696 es
->undo_position
= s
;
2697 es
->undo_insert_count
= strl
;
2698 /* new insertion makes old delete-buffer invalid */
2699 *es
->undo_text
= '\0';
2702 EDIT_EM_EmptyUndoBuffer(es
);
2706 HeapFree(GetProcessHeap(), 0, buf
);
2710 /* If text has been deleted and we're right or center aligned then scroll rightward */
2711 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2713 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2715 if (delta
< 0 && es
->x_offset
)
2717 if (abs(delta
) > es
->x_offset
)
2720 es
->x_offset
+= delta
;
2724 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2725 es
->flags
|= EF_MODIFIED
;
2726 if (send_update
) es
->flags
|= EF_UPDATE
;
2729 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2733 EDIT_UpdateText(es
, NULL
, TRUE
);
2735 EDIT_EM_ScrollCaret(es
);
2737 /* force scroll info update */
2738 EDIT_UpdateScrollInfo(es
);
2741 if(send_update
|| (es
->flags
& EF_UPDATE
))
2743 es
->flags
&= ~EF_UPDATE
;
2744 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2746 EDIT_InvalidateUniscribeData(es
);
2750 /*********************************************************************
2754 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2757 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2759 if (!(es
->style
& ES_MULTILINE
))
2763 WARN("called with NULL handle\n");
2767 EDIT_UnlockBuffer(es
, TRUE
);
2773 LocalFree(es
->hloc32A
);
2785 countA
= LocalSize(hloc
);
2786 textA
= LocalLock(hloc
);
2787 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2788 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2790 ERR("Could not allocate new unicode buffer\n");
2793 textW
= LocalLock(hloc32W_new
);
2794 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2795 LocalUnlock(hloc32W_new
);
2799 LocalFree(es
->hloc32W
);
2801 es
->hloc32W
= hloc32W_new
;
2805 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2807 es
->flags
|= EF_APP_HAS_HANDLE
;
2808 EDIT_LockBuffer(es
);
2810 es
->x_offset
= es
->y_offset
= 0;
2811 es
->selection_start
= es
->selection_end
= 0;
2812 EDIT_EM_EmptyUndoBuffer(es
);
2813 es
->flags
&= ~EF_MODIFIED
;
2814 es
->flags
&= ~EF_UPDATE
;
2815 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2816 EDIT_UpdateText(es
, NULL
, TRUE
);
2817 EDIT_EM_ScrollCaret(es
);
2818 /* force scroll info update */
2819 EDIT_UpdateScrollInfo(es
);
2823 /*********************************************************************
2827 * NOTE: this version currently implements WinNT limits
2830 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2832 if (!limit
) limit
= ~0u;
2833 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2834 es
->buffer_limit
= limit
;
2838 /*********************************************************************
2842 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2843 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2844 * margin according to the textmetrics of the current font.
2846 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2847 * of the char's width as the margin, but this is not how Windows handles this.
2848 * For all other fonts Windows sets the margins to zero.
2850 * FIXME - When EC_USEFONTINFO is used the margins only change if the
2851 * edit control is equal to or larger than a certain size.
2852 * Interestingly if one subtracts both the left and right margins from
2853 * this size one always seems to get an even number. The extents of
2854 * the (four character) string "'**'" match this quite closely, so
2855 * we'll use this until we come up with a better idea.
2857 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
2859 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
2862 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
2863 return sz
.cx
+ left
+ right
;
2866 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2867 WORD left
, WORD right
, BOOL repaint
)
2870 INT default_left_margin
= 0; /* in pixels */
2871 INT default_right_margin
= 0; /* in pixels */
2873 /* Set the default margins depending on the font */
2874 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2875 HDC dc
= GetDC(es
->hwndSelf
);
2876 HFONT old_font
= SelectObject(dc
, es
->font
);
2877 GetTextMetricsW(dc
, &tm
);
2878 /* The default margins are only non zero for TrueType or Vector fonts */
2879 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2882 /* This must be calculated more exactly! But how? */
2883 default_left_margin
= tm
.tmAveCharWidth
/ 2;
2884 default_right_margin
= tm
.tmAveCharWidth
/ 2;
2885 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
2886 GetClientRect(es
->hwndSelf
, &rc
);
2887 if(rc
.right
- rc
.left
< min_size
) {
2888 default_left_margin
= es
->left_margin
;
2889 default_right_margin
= es
->right_margin
;
2892 SelectObject(dc
, old_font
);
2893 ReleaseDC(es
->hwndSelf
, dc
);
2896 if (action
& EC_LEFTMARGIN
) {
2897 es
->format_rect
.left
-= es
->left_margin
;
2898 if (left
!= EC_USEFONTINFO
)
2899 es
->left_margin
= left
;
2901 es
->left_margin
= default_left_margin
;
2902 es
->format_rect
.left
+= es
->left_margin
;
2905 if (action
& EC_RIGHTMARGIN
) {
2906 es
->format_rect
.right
+= es
->right_margin
;
2907 if (right
!= EC_USEFONTINFO
)
2908 es
->right_margin
= right
;
2910 es
->right_margin
= default_right_margin
;
2911 es
->format_rect
.right
-= es
->right_margin
;
2914 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2915 EDIT_AdjustFormatRect(es
);
2916 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2919 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2923 /*********************************************************************
2925 * EM_SETPASSWORDCHAR
2928 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2932 if (es
->style
& ES_MULTILINE
)
2935 if (es
->password_char
== c
)
2938 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2939 es
->password_char
= c
;
2941 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2942 es
->style
|= ES_PASSWORD
;
2944 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2945 es
->style
&= ~ES_PASSWORD
;
2947 EDIT_InvalidateUniscribeData(es
);
2948 EDIT_UpdateText(es
, NULL
, TRUE
);
2952 /*********************************************************************
2957 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2959 if (!(es
->style
& ES_MULTILINE
))
2961 HeapFree(GetProcessHeap(), 0, es
->tabs
);
2962 es
->tabs_count
= count
;
2966 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
2967 if (es
->tabs
== NULL
) // reactos r33503
2972 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2974 EDIT_InvalidateUniscribeData(es
);
2979 /*********************************************************************
2981 * EM_SETWORDBREAKPROC
2984 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
2986 if (es
->word_break_proc
== wbp
)
2989 es
->word_break_proc
= wbp
;
2991 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2992 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2993 EDIT_UpdateText(es
, NULL
, TRUE
);
2998 /*********************************************************************
3003 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3008 /* As per MSDN spec, for a single-line edit control,
3009 the return value is always TRUE */
3010 if( es
->style
& ES_READONLY
)
3011 return !(es
->style
& ES_MULTILINE
);
3013 ulength
= strlenW(es
->undo_text
);
3015 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3016 if (utext
== NULL
) // reactos r33503
3017 return FALSE
; // reactos r33503
3019 strcpyW(utext
, es
->undo_text
);
3021 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3022 es
->undo_insert_count
, debugstr_w(utext
));
3024 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3025 EDIT_EM_EmptyUndoBuffer(es
);
3026 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
3027 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3028 /* send the notification after the selection start and end are set */
3029 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3030 EDIT_EM_ScrollCaret(es
);
3031 HeapFree(GetProcessHeap(), 0, utext
);
3033 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3034 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3039 /* Helper function for WM_CHAR
3041 * According to an MSDN blog article titled "Just because you're a control
3042 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3043 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3044 * a dialog box or not.
3046 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3048 return (es
->flags
& EF_DIALOGMODE
);
3052 /*********************************************************************
3057 static void EDIT_WM_Paste(EDITSTATE
*es
)
3062 /* Protect read-only edit control from modification */
3063 if(es
->style
& ES_READONLY
)
3066 OpenClipboard(es
->hwndSelf
);
3067 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
3068 src
= GlobalLock(hsrc
);
3069 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
3072 else if (es
->style
& ES_PASSWORD
) {
3073 /* clear selected text in password edit box even with empty clipboard */
3074 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
3080 /*********************************************************************
3085 static void EDIT_WM_Copy(EDITSTATE
*es
)
3087 INT s
= min(es
->selection_start
, es
->selection_end
);
3088 INT e
= max(es
->selection_start
, es
->selection_end
);
3096 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3097 dst
= GlobalLock(hdst
);
3098 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3099 dst
[len
] = 0; /* ensure 0 termination */
3100 TRACE("%s\n", debugstr_w(dst
));
3102 OpenClipboard(es
->hwndSelf
);
3104 SetClipboardData(CF_UNICODETEXT
, hdst
);
3109 /*********************************************************************
3114 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
3116 /* Protect read-only edit control from modification */
3117 if(es
->style
& ES_READONLY
)
3120 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
3124 /*********************************************************************
3129 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3136 /*********************************************************************
3141 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3145 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3149 /* If it's not a multiline edit box, it would be ignored below.
3150 * For multiline edit without ES_WANTRETURN, we have to make a
3153 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3154 if (EDIT_IsInsideDialog(es
))
3157 if (es
->style
& ES_MULTILINE
) {
3158 if (es
->style
& ES_READONLY
) {
3159 EDIT_MoveHome(es
, FALSE
, FALSE
);
3160 EDIT_MoveDown_ML(es
, FALSE
);
3162 static const WCHAR cr_lfW
[] = {'\r','\n',0};
3163 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
3168 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3170 static const WCHAR tabW
[] = {'\t',0};
3171 if (EDIT_IsInsideDialog(es
))
3173 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3177 if (!(es
->style
& ES_READONLY
) && !control
) {
3178 if (es
->selection_start
!= es
->selection_end
)
3181 /* delete character left of caret */
3182 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3183 EDIT_MoveBackward(es
, TRUE
);
3189 if (!(es
->style
& ES_PASSWORD
))
3190 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3193 if (!(es
->style
& ES_READONLY
))
3194 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3197 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3198 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3201 if (!(es
->style
& ES_READONLY
))
3202 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3206 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3207 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3210 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3214 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3221 #if 0 // Removed see Revision 43925 comments.
3222 /*********************************************************************
3227 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3229 if (code
|| control
)
3234 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3237 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3240 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3243 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3246 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3249 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3250 EDIT_EM_ScrollCaret(es
);
3253 ERR("unknown menu item, please report\n");
3260 /*********************************************************************
3264 * Note: the resource files resource/sysres_??.rc cannot define a
3265 * single popup menu. Hence we use a (dummy) menubar
3266 * containing the single popup menu as its first item.
3268 * FIXME: the message identifiers have been chosen arbitrarily,
3269 * hence we use MF_BYPOSITION.
3270 * We might as well use the "real" values (anybody knows ?)
3271 * The menu definition is in resources/sysres_??.rc.
3272 * Once these are OK, we better use MF_BYCOMMAND here
3273 * (as we do in EDIT_WM_Command()).
3276 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3278 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3279 HMENU popup
= GetSubMenu(menu
, 0);
3280 UINT start
= es
->selection_start
;
3281 UINT end
= es
->selection_end
;
3283 BOOL selectedItem
; // reactos r40667
3284 ORDER_UINT(start
, end
);
3287 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3289 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3291 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3293 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3295 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3297 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3299 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3302 /* Windows places the menu at the edit's center in this case */
3304 GetClientRect(es
->hwndSelf
, &rc
);
3305 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
3306 //WIN_GetRectangles( es->hwndSelf, COORDS_SCREEN, NULL, &rc );
3307 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3308 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3311 if (!(es
->flags
& EF_FOCUSED
))
3312 SetFocus(es
->hwndSelf
);
3314 #ifdef __REACTOS__ // r40667
3315 selectedItem
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
, x
, y
, 0, es
->hwndSelf
, NULL
);
3316 // Added see Revision 43925 comments.
3317 switch (selectedItem
) {
3319 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3322 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3325 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3328 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3331 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3334 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3335 EDIT_EM_ScrollCaret(es
);
3338 ERR("unknown menu item, please report\n");
3346 /*********************************************************************
3351 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3353 if(!count
) return 0;
3357 lstrcpynW(dst
, es
->text
, count
);
3358 return strlenW(dst
);
3362 LPSTR textA
= (LPSTR
)dst
;
3363 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3364 textA
[count
- 1] = 0; /* ensure 0 termination */
3365 return strlen(textA
);
3369 /*********************************************************************
3374 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3376 HWND hLBox
= es
->hwndListBox
;
3384 hCombo
= GetParent(es
->hwndSelf
);
3388 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3390 if (key
== VK_UP
|| key
== VK_DOWN
)
3392 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3395 if (msg
== WM_KEYDOWN
|| nEUI
)
3396 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3402 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3404 /* make sure ComboLBox pops up */
3405 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3410 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3413 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3415 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3417 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3422 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3428 /*********************************************************************
3432 * Handling of special keys that don't produce a WM_CHAR
3433 * (i.e. non-printable keys) & Backspace & Delete
3436 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3441 if (GetKeyState(VK_MENU
) & 0x8000)
3444 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3445 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3450 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3455 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3456 EDIT_MoveUp_ML(es
, shift
);
3459 EDIT_MoveWordBackward(es
, shift
);
3461 EDIT_MoveBackward(es
, shift
);
3464 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3468 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3469 EDIT_MoveDown_ML(es
, shift
);
3471 EDIT_MoveWordForward(es
, shift
);
3473 EDIT_MoveForward(es
, shift
);
3476 EDIT_MoveHome(es
, shift
, control
);
3479 EDIT_MoveEnd(es
, shift
, control
);
3482 if (es
->style
& ES_MULTILINE
)
3483 EDIT_MovePageUp_ML(es
, shift
);
3485 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3488 if (es
->style
& ES_MULTILINE
)
3489 EDIT_MovePageDown_ML(es
, shift
);
3491 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3494 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3495 if (es
->selection_start
!= es
->selection_end
) {
3502 /* delete character left of caret */
3503 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3504 EDIT_MoveBackward(es
, TRUE
);
3506 } else if (control
) {
3507 /* delete to end of line */
3508 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3509 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3512 /* delete character right of caret */
3513 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3514 EDIT_MoveForward(es
, TRUE
);
3522 if (!(es
->style
& ES_READONLY
))
3528 /* If the edit doesn't want the return send a message to the default object */
3529 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3533 if (!EDIT_IsInsideDialog(es
)) break;
3535 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3536 if (HIWORD(dw
) == DC_HASDEFID
)
3538 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3541 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3542 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3548 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3549 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3552 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3553 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3558 FIXME("Ctrl+Backspace\n"); // See bug 1419.
3566 /*********************************************************************
3571 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3573 es
->flags
&= ~EF_FOCUSED
;
3575 if(!(es
->style
& ES_NOHIDESEL
))
3576 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3577 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3582 /*********************************************************************
3586 * The caret position has been set on the WM_LBUTTONDOWN message
3589 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3592 INT e
= es
->selection_end
;
3597 es
->bCaptureState
= TRUE
;
3598 SetCapture(es
->hwndSelf
);
3600 l
= EDIT_EM_LineFromChar(es
, e
);
3601 li
= EDIT_EM_LineIndex(es
, l
);
3602 ll
= EDIT_EM_LineLength(es
, e
);
3603 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3604 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3605 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3606 EDIT_EM_ScrollCaret(es
);
3607 es
->region_posx
= es
->region_posy
= 0;
3608 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3613 /*********************************************************************
3618 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3623 es
->bCaptureState
= TRUE
;
3624 SetCapture(es
->hwndSelf
);
3625 EDIT_ConfinePoint(es
, &x
, &y
);
3626 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3627 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3628 EDIT_EM_ScrollCaret(es
);
3629 es
->region_posx
= es
->region_posy
= 0;
3630 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3632 if (!(es
->flags
& EF_FOCUSED
))
3633 SetFocus(es
->hwndSelf
);
3639 /*********************************************************************
3644 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3646 if (es
->bCaptureState
) {
3647 KillTimer(es
->hwndSelf
, 0);
3648 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3650 es
->bCaptureState
= FALSE
;
3655 /*********************************************************************
3660 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3662 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3667 /*********************************************************************
3672 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3678 /* If the mouse has been captured by process other than the edit control itself,
3679 * the windows edit controls will not select the strings with mouse move.
3681 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3685 * FIXME: gotta do some scrolling if outside client
3686 * area. Maybe reset the timer ?
3689 EDIT_ConfinePoint(es
, &x
, &y
);
3690 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3691 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3692 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3693 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3694 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3699 /*********************************************************************
3704 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3717 BOOL rev
= es
->bEnableState
&&
3718 ((es
->flags
& EF_FOCUSED
) ||
3719 (es
->style
& ES_NOHIDESEL
));
3720 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3722 /* The dc we use for calculating may not be the one we paint into.
3723 This is the safest action. */
3724 EDIT_InvalidateUniscribeData(es
);
3725 GetClientRect(es
->hwndSelf
, &rcClient
);
3727 /* get the background brush */
3728 brush
= EDIT_NotifyCtlColor(es
, dc
);
3730 /* paint the border and the background */
3731 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3733 if(es
->style
& WS_BORDER
) {
3734 bw
= GetSystemMetrics(SM_CXBORDER
);
3735 bh
= GetSystemMetrics(SM_CYBORDER
);
3737 if(es
->style
& ES_MULTILINE
) {
3738 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3739 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3742 /* Draw the frame. Same code as in nonclient.c */
3743 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3744 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3745 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3746 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3747 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3748 SelectObject(dc
, old_brush
);
3750 /* Keep the border clean */
3751 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3752 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3755 GetClipBox(dc
, &rc
);
3756 FillRect(dc
, &rc
, brush
);
3758 IntersectClipRect(dc
, es
->format_rect
.left
,
3759 es
->format_rect
.top
,
3760 es
->format_rect
.right
,
3761 es
->format_rect
.bottom
);
3762 if (es
->style
& ES_MULTILINE
) {
3764 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3767 old_font
= SelectObject(dc
, es
->font
);
3769 if (!es
->bEnableState
)
3770 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3771 GetClipBox(dc
, &rcRgn
);
3772 if (es
->style
& ES_MULTILINE
) {
3773 INT vlc
= get_vertical_line_count(es
);
3774 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3775 EDIT_UpdateUniscribeData(es
, dc
, i
);
3776 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3777 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3778 EDIT_PaintLine(es
, dc
, i
, rev
);
3781 EDIT_UpdateUniscribeData(es
, dc
, 0);
3782 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3783 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3784 EDIT_PaintLine(es
, dc
, 0, rev
);
3787 SelectObject(dc
, old_font
);
3790 EndPaint(es
->hwndSelf
, &ps
);
3794 /*********************************************************************
3799 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3801 es
->flags
|= EF_FOCUSED
;
3803 if (!(es
->style
& ES_NOHIDESEL
))
3804 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3806 /* single line edit updates itself */
3807 if (!(es
->style
& ES_MULTILINE
))
3809 HDC hdc
= GetDC(es
->hwndSelf
);
3810 EDIT_WM_Paint(es
, hdc
);
3811 ReleaseDC(es
->hwndSelf
, hdc
);
3814 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3815 EDIT_SetCaretPos(es
, es
->selection_end
,
3816 es
->flags
& EF_AFTER_WRAP
);
3817 ShowCaret(es
->hwndSelf
);
3818 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3822 /*********************************************************************
3826 * With Win95 look the margins are set to default font value unless
3827 * the system font (font == 0) is being set, in which case they are left
3831 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3839 EDIT_InvalidateUniscribeData(es
);
3840 dc
= GetDC(es
->hwndSelf
);
3842 old_font
= SelectObject(dc
, font
);
3843 GetTextMetricsW(dc
, &tm
);
3844 es
->line_height
= tm
.tmHeight
;
3845 es
->char_width
= tm
.tmAveCharWidth
;
3847 SelectObject(dc
, old_font
);
3848 ReleaseDC(es
->hwndSelf
, dc
);
3850 /* Reset the format rect and the margins */
3851 GetClientRect(es
->hwndSelf
, &clientRect
);
3852 EDIT_SetRectNP(es
, &clientRect
);
3853 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3854 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3856 if (es
->style
& ES_MULTILINE
)
3857 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3859 EDIT_CalcLineWidth_SL(es
);
3862 EDIT_UpdateText(es
, NULL
, TRUE
);
3863 if (es
->flags
& EF_FOCUSED
) {
3865 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3866 EDIT_SetCaretPos(es
, es
->selection_end
,
3867 es
->flags
& EF_AFTER_WRAP
);
3868 ShowCaret(es
->hwndSelf
);
3873 /*********************************************************************
3878 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3879 * The modified flag is reset. No notifications are sent.
3881 * For single-line controls, reception of WM_SETTEXT triggers:
3882 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3885 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
3887 LPWSTR textW
= NULL
;
3888 if (!unicode
&& text
)
3890 LPCSTR textA
= (LPCSTR
)text
;
3891 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
3892 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
3894 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
3898 if (es
->flags
& EF_UPDATE
)
3899 /* fixed this bug once; complain if we see it about to happen again. */
3900 ERR("SetSel may generate UPDATE message whose handler may reset "
3903 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3906 TRACE("%s\n", debugstr_w(text
));
3907 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
3909 HeapFree(GetProcessHeap(), 0, textW
);
3914 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
3917 es
->flags
&= ~EF_MODIFIED
;
3918 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3920 /* Send the notification after the selection start and end have been set
3921 * edit control doesn't send notification on WM_SETTEXT
3922 * if it is multiline, or it is part of combobox
3924 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3926 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3927 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3929 EDIT_EM_ScrollCaret(es
);
3930 EDIT_UpdateScrollInfo(es
);
3931 EDIT_InvalidateUniscribeData(es
);
3935 /*********************************************************************
3940 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3942 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3944 TRACE("width = %d, height = %d\n", width
, height
);
3945 SetRect(&rc
, 0, 0, width
, height
);
3946 EDIT_SetRectNP(es
, &rc
);
3947 EDIT_UpdateText(es
, NULL
, TRUE
);
3952 /*********************************************************************
3956 * This message is sent by SetWindowLong on having changed either the Style
3957 * or the extended style.
3959 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3961 * See also EDIT_WM_NCCreate
3963 * It appears that the Windows version of the edit control allows the style
3964 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3965 * style variable which will generally be different. In this function we
3966 * update the internal style based on what changed in the externally visible
3969 * Much of this content as based upon the MSDN, especially:
3970 * Platform SDK Documentation -> User Interface Services ->
3971 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3972 * Edit Control Styles
3974 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3976 if (GWL_STYLE
== which
) {
3977 DWORD style_change_mask
;
3979 /* Only a subset of changes can be applied after the control
3982 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3984 if (es
->style
& ES_MULTILINE
)
3985 style_change_mask
|= ES_WANTRETURN
;
3987 new_style
= style
->styleNew
& style_change_mask
;
3989 /* Number overrides lowercase overrides uppercase (at least it
3990 * does in Win95). However I'll bet that ES_NUMBER would be
3991 * invalid under Win 3.1.
3993 if (new_style
& ES_NUMBER
) {
3994 ; /* do not override the ES_NUMBER */
3995 } else if (new_style
& ES_LOWERCASE
) {
3996 new_style
&= ~ES_UPPERCASE
;
3999 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
4000 } else if (GWL_EXSTYLE
== which
) {
4001 ; /* FIXME - what is needed here */
4003 WARN ("Invalid style change %ld\n",which
);
4009 /*********************************************************************
4014 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
4016 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
4017 if (EDIT_EM_CanUndo(es
))
4020 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
4021 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
4024 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
4028 /*********************************************************************
4033 static void EDIT_WM_Timer(EDITSTATE
*es
)
4035 if (es
->region_posx
< 0) {
4036 EDIT_MoveBackward(es
, TRUE
);
4037 } else if (es
->region_posx
> 0) {
4038 EDIT_MoveForward(es
, TRUE
);
4041 * FIXME: gotta do some vertical scrolling here, like
4042 * EDIT_EM_LineScroll(hwnd, 0, 1);
4046 /*********************************************************************
4051 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4056 if (!(es
->style
& ES_MULTILINE
))
4059 if (!(es
->style
& ES_AUTOHSCROLL
))
4063 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4066 TRACE("SB_LINELEFT\n");
4068 dx
= -es
->char_width
;
4071 TRACE("SB_LINERIGHT\n");
4072 if (es
->x_offset
< es
->text_width
)
4073 dx
= es
->char_width
;
4076 TRACE("SB_PAGELEFT\n");
4078 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4081 TRACE("SB_PAGERIGHT\n");
4082 if (es
->x_offset
< es
->text_width
)
4083 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4091 TRACE("SB_RIGHT\n");
4092 if (es
->x_offset
< es
->text_width
)
4093 dx
= es
->text_width
- es
->x_offset
;
4096 TRACE("SB_THUMBTRACK %d\n", pos
);
4097 es
->flags
|= EF_HSCROLL_TRACK
;
4098 if(es
->style
& WS_HSCROLL
)
4099 dx
= pos
- es
->x_offset
;
4104 if(pos
< 0 || pos
> 100) return 0;
4105 /* Assume default scroll range 0-100 */
4106 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4107 new_x
= pos
* (es
->text_width
- fw
) / 100;
4108 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4111 case SB_THUMBPOSITION
:
4112 TRACE("SB_THUMBPOSITION %d\n", pos
);
4113 es
->flags
&= ~EF_HSCROLL_TRACK
;
4114 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4115 dx
= pos
- es
->x_offset
;
4120 if(pos
< 0 || pos
> 100) return 0;
4121 /* Assume default scroll range 0-100 */
4122 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4123 new_x
= pos
* (es
->text_width
- fw
) / 100;
4124 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4127 /* force scroll info update */
4128 EDIT_UpdateScrollInfo(es
);
4129 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4133 TRACE("SB_ENDSCROLL\n");
4136 * FIXME : the next two are undocumented !
4137 * Are we doing the right thing ?
4138 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4139 * although it's also a regular control message.
4141 case EM_GETTHUMB
: /* this one is used by NT notepad */
4144 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4145 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4148 /* Assume default scroll range 0-100 */
4149 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4150 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4152 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4156 TRACE("EM_LINESCROLL16\n");
4161 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4167 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4168 /* check if we are going to move too far */
4169 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4170 dx
= es
->text_width
- fw
- es
->x_offset
;
4172 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4178 /*********************************************************************
4183 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4187 if (!(es
->style
& ES_MULTILINE
))
4190 if (!(es
->style
& ES_AUTOVSCROLL
))
4199 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4200 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4201 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4203 EDIT_EM_Scroll(es
, action
);
4210 TRACE("SB_BOTTOM\n");
4211 dy
= es
->line_count
- 1 - es
->y_offset
;
4214 TRACE("SB_THUMBTRACK %d\n", pos
);
4215 es
->flags
|= EF_VSCROLL_TRACK
;
4216 if(es
->style
& WS_VSCROLL
)
4217 dy
= pos
- es
->y_offset
;
4220 /* Assume default scroll range 0-100 */
4223 if(pos
< 0 || pos
> 100) return 0;
4224 vlc
= get_vertical_line_count(es
);
4225 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4226 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4227 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4228 es
->line_count
, es
->y_offset
, pos
, dy
);
4231 case SB_THUMBPOSITION
:
4232 TRACE("SB_THUMBPOSITION %d\n", pos
);
4233 es
->flags
&= ~EF_VSCROLL_TRACK
;
4234 if(es
->style
& WS_VSCROLL
)
4235 dy
= pos
- es
->y_offset
;
4238 /* Assume default scroll range 0-100 */
4241 if(pos
< 0 || pos
> 100) return 0;
4242 vlc
= get_vertical_line_count(es
);
4243 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4244 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4245 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4246 es
->line_count
, es
->y_offset
, pos
, dy
);
4250 /* force scroll info update */
4251 EDIT_UpdateScrollInfo(es
);
4252 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4256 TRACE("SB_ENDSCROLL\n");
4259 * FIXME : the next two are undocumented !
4260 * Are we doing the right thing ?
4261 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4262 * although it's also a regular control message.
4264 case EM_GETTHUMB
: /* this one is used by NT notepad */
4267 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4268 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4271 /* Assume default scroll range 0-100 */
4272 INT vlc
= get_vertical_line_count(es
);
4273 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4275 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4279 TRACE("EM_LINESCROLL %d\n", pos
);
4284 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4289 EDIT_EM_LineScroll(es
, 0, dy
);
4293 /*********************************************************************
4297 * FIXME: is this right ? (or should it be only VSCROLL)
4298 * (and maybe only for edit controls that really have their
4299 * own scrollbars) (and maybe only for multiline controls ?)
4300 * All in all: very poorly documented
4303 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4305 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4306 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4310 /********************************************************************
4312 * The Following code is to handle inline editing from IMEs
4315 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4318 LPWSTR lpCompStr
= NULL
;
4319 LPSTR lpCompStrAttr
= NULL
;
4322 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4329 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
4332 ERR("Unable to allocate IME CompositionString\n");
4337 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4338 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
4340 if (CompFlag
& GCS_COMPATTR
)
4343 * We do not use the attributes yet. it would tell us what characters
4344 * are in transition and which are converted or decided upon
4346 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4350 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4353 ERR("Unable to allocate IME Attribute String\n");
4354 HeapFree(GetProcessHeap(),0,lpCompStr
);
4357 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4359 lpCompStrAttr
[dwBufLenAttr
] = 0;
4362 lpCompStrAttr
= NULL
;
4365 /* check for change in composition start */
4366 if (es
->selection_end
< es
->composition_start
)
4367 es
->composition_start
= es
->selection_end
;
4369 /* replace existing selection string */
4370 es
->selection_start
= es
->composition_start
;
4372 if (es
->composition_len
> 0)
4373 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4375 es
->selection_end
= es
->selection_start
;
4377 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
4378 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4380 es
->selection_start
= es
->composition_start
;
4381 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4383 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4384 HeapFree(GetProcessHeap(),0,lpCompStr
);
4387 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4392 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4398 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
4401 ERR("Unable to alloc buffer for IME string\n");
4405 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4406 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
4408 /* check for change in composition start */
4409 if (es
->selection_end
< es
->composition_start
)
4410 es
->composition_start
= es
->selection_end
;
4412 es
->selection_start
= es
->composition_start
;
4413 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4414 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
4415 es
->composition_start
= es
->selection_end
;
4416 es
->composition_len
= 0;
4418 HeapFree(GetProcessHeap(),0,lpResultStr
);
4421 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4426 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4428 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4429 es
->composition_start
= es
->selection_end
;
4432 hIMC
= ImmGetContext(hwnd
);
4436 if (CompFlag
& GCS_RESULTSTR
)
4437 EDIT_GetResultStr(hIMC
, es
);
4438 if (CompFlag
& GCS_COMPSTR
)
4439 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4440 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4441 ImmReleaseContext(hwnd
, hIMC
);
4442 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4446 /*********************************************************************
4450 * See also EDIT_WM_StyleChanged
4452 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4457 TRACE("Creating %s edit control, style = %08x\n",
4458 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4460 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4462 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4465 * Note: since the EDITSTATE has not been fully initialized yet,
4466 * we can't use any API calls that may send
4467 * WM_XXX messages before WM_NCCREATE is completed.
4470 es
->is_unicode
= unicode
;
4471 es
->style
= lpcs
->style
;
4473 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4475 es
->hwndSelf
= hwnd
;
4476 /* Save parent, which will be notified by EN_* messages */
4477 es
->hwndParent
= lpcs
->hwndParent
;
4479 if (es
->style
& ES_COMBO
)
4480 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4482 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4483 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4485 /* Number overrides lowercase overrides uppercase (at least it
4486 * does in Win95). However I'll bet that ES_NUMBER would be
4487 * invalid under Win 3.1.
4489 if (es
->style
& ES_NUMBER
) {
4490 ; /* do not override the ES_NUMBER */
4491 } else if (es
->style
& ES_LOWERCASE
) {
4492 es
->style
&= ~ES_UPPERCASE
;
4494 if (es
->style
& ES_MULTILINE
) {
4495 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4496 if (es
->style
& WS_VSCROLL
)
4497 es
->style
|= ES_AUTOVSCROLL
;
4498 if (es
->style
& WS_HSCROLL
)
4499 es
->style
|= ES_AUTOHSCROLL
;
4500 es
->style
&= ~ES_PASSWORD
;
4501 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4502 /* Confirmed - RIGHT overrides CENTER */
4503 if (es
->style
& ES_RIGHT
)
4504 es
->style
&= ~ES_CENTER
;
4505 es
->style
&= ~WS_HSCROLL
;
4506 es
->style
&= ~ES_AUTOHSCROLL
;
4509 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4510 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4511 es
->style
&= ~ES_CENTER
;
4512 es
->style
&= ~WS_HSCROLL
;
4513 es
->style
&= ~WS_VSCROLL
;
4514 if (es
->style
& ES_PASSWORD
)
4515 es
->password_char
= '*';
4518 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4519 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4521 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4523 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4525 es
->undo_buffer_size
= es
->buffer_size
;
4527 if (es
->style
& ES_MULTILINE
)
4528 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4533 * In Win95 look and feel, the WS_BORDER style is replaced by the
4534 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4535 * control a nonclient area so we don't need to draw the border.
4536 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4537 * a nonclient area and we should handle painting the border ourselves.
4539 * When making modifications please ensure that the code still works
4540 * for edit controls created directly with style 0x50800000, exStyle 0
4541 * (which should have a single pixel border)
4543 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4544 es
->style
&= ~WS_BORDER
;
4545 else if (es
->style
& WS_BORDER
)
4546 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4551 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4552 EDIT_InvalidateUniscribeData(es
);
4553 HeapFree(GetProcessHeap(), 0, es
->first_line_def
);
4554 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4555 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4556 HeapFree(GetProcessHeap(), 0, es
->logAttr
);
4557 HeapFree(GetProcessHeap(), 0, es
);
4562 /*********************************************************************
4567 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4571 TRACE("%s\n", debugstr_w(name
));
4573 * To initialize some final structure members, we call some helper
4574 * functions. However, since the EDITSTATE is not consistent (i.e.
4575 * not fully initialized), we should be very careful which
4576 * functions can be called, and in what order.
4578 EDIT_WM_SetFont(es
, 0, FALSE
);
4579 EDIT_EM_EmptyUndoBuffer(es
);
4581 /* We need to calculate the format rect
4582 (applications may send EM_SETMARGINS before the control gets visible) */
4583 GetClientRect(es
->hwndSelf
, &clientRect
);
4584 EDIT_SetRectNP(es
, &clientRect
);
4586 if (name
&& *name
) {
4587 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4588 /* if we insert text to the editline, the text scrolls out
4589 * of the window, as the caret is placed after the insert
4590 * pos normally; thus we reset es->selection... to 0 and
4593 es
->selection_start
= es
->selection_end
= 0;
4594 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4595 * Messages are only to be sent when the USER does something to
4596 * change the contents. So I am removing this EN_CHANGE
4598 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4600 EDIT_EM_ScrollCaret(es
);
4602 /* force scroll info update */
4603 EDIT_UpdateScrollInfo(es
);
4604 /* The rule seems to return 1 here for success */
4605 /* Power Builder masked edit controls will crash */
4607 /* FIXME: is that in all cases so ? */
4612 /*********************************************************************
4617 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4622 LocalFree(es
->hloc32W
);
4625 LocalFree(es
->hloc32A
);
4627 pc
= es
->first_line_def
;
4631 HeapFree(GetProcessHeap(), 0, pc
);
4635 EDIT_InvalidateUniscribeData(es
);
4636 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4637 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4638 HeapFree(GetProcessHeap(), 0, es
);
4644 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4647 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4649 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4652 /*********************************************************************
4654 * EditWndProc_common
4656 * The messages are in the order of the actual integer values
4657 * (which can be found in include/windows.h)
4659 LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4661 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4663 #ifdef __REACTOS__ // r50219
4666 pWnd
= ValidateHwnd(hwnd
);
4671 NtUserSetWindowFNID(hwnd
, FNID_EDIT
);
4675 if (pWnd
->fnid
!= FNID_EDIT
)
4677 ERR("Wrong window class for Edit! fnId 0x%x\n",pWnd
->fnid
);
4684 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4686 if (!es
&& msg
!= WM_NCCREATE
)
4687 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4689 if (es
&& (msg
!= WM_NCDESTROY
)) EDIT_LockBuffer(es
);
4693 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4697 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4698 EDIT_EM_ScrollCaret(es
);
4704 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
4708 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4709 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4710 EDIT_UpdateText(es
, NULL
, TRUE
);
4715 if ((es
->style
& ES_MULTILINE
) && lParam
)
4716 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4720 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4724 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4727 case EM_SCROLLCARET
:
4728 EDIT_EM_ScrollCaret(es
);
4733 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4738 es
->flags
|= EF_MODIFIED
;
4740 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4743 case EM_GETLINECOUNT
:
4744 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4748 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4752 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4756 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4760 result
= EDIT_EM_GetThumb(es
);
4763 /* these messages missing from specs */
4768 FIXME("undocumented message 0x%x, please report\n", msg
);
4769 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4773 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4781 textW
= (LPWSTR
)lParam
;
4784 LPSTR textA
= (LPSTR
)lParam
;
4785 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4786 if (!(textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
)))) break;
4787 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4790 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
4794 HeapFree(GetProcessHeap(), 0, textW
);
4799 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
4802 case EM_SETLIMITTEXT
:
4803 EDIT_EM_SetLimitText(es
, wParam
);
4807 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4812 result
= (LRESULT
)EDIT_EM_Undo(es
);
4816 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4819 case EM_LINEFROMCHAR
:
4820 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4823 case EM_SETTABSTOPS
:
4824 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4827 case EM_SETPASSWORDCHAR
:
4832 charW
= (WCHAR
)wParam
;
4835 CHAR charA
= wParam
;
4836 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
4839 EDIT_EM_SetPasswordChar(es
, charW
);
4843 case EM_EMPTYUNDOBUFFER
:
4844 EDIT_EM_EmptyUndoBuffer(es
);
4847 case EM_GETFIRSTVISIBLELINE
:
4848 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4851 case EM_SETREADONLY
:
4853 DWORD old_style
= es
->style
;
4856 SetWindowLongW( hwnd
, GWL_STYLE
,
4857 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
4858 es
->style
|= ES_READONLY
;
4860 SetWindowLongW( hwnd
, GWL_STYLE
,
4861 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4862 es
->style
&= ~ES_READONLY
;
4865 if (old_style
^ es
->style
)
4866 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4872 case EM_SETWORDBREAKPROC
:
4873 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4876 case EM_GETWORDBREAKPROC
:
4877 result
= (LRESULT
)es
->word_break_proc
;
4880 case EM_GETPASSWORDCHAR
:
4883 result
= es
->password_char
;
4886 WCHAR charW
= es
->password_char
;
4888 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
4895 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4899 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4902 case EM_GETLIMITTEXT
:
4903 result
= es
->buffer_limit
;
4906 case EM_POSFROMCHAR
:
4907 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4908 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4911 case EM_CHARFROMPOS
:
4912 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4915 /* End of the EM_ messages which were in numerical order; what order
4916 * are these in? vaguely alphabetical?
4920 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
4924 result
= EDIT_WM_NCDestroy(es
);
4925 // es = NULL; reactos
4927 NtUserSetWindowFNID(hwnd
, FNID_DESTROY
);
4932 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4934 if (es
->style
& ES_MULTILINE
)
4935 result
|= DLGC_WANTALLKEYS
;
4939 es
->flags
|=EF_DIALOGMODE
;
4941 if (((LPMSG
)lParam
)->message
== WM_KEYDOWN
)
4943 int vk
= (int)((LPMSG
)lParam
)->wParam
;
4945 if (es
->hwndListBox
)
4947 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4948 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4949 result
|= DLGC_WANTMESSAGE
;
4961 strng
[0] = wParam
>> 8;
4962 strng
[1] = wParam
& 0xff;
4963 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
4964 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
4965 result
= EDIT_WM_Char(es
, charW
);
4977 CHAR charA
= wParam
;
4978 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
4981 if (es
->hwndListBox
)
4983 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4985 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4986 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4990 result
= EDIT_WM_Char(es
, charW
);
4997 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4998 if (wParam
<= 0x000fffff)
5000 if(wParam
> 0xffff) /* convert to surrogates */
5003 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
5004 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
5006 else EDIT_WM_Char(es
, wParam
);
5015 #if 0 // Removed see Revision 43925 comments.
5017 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
5020 case WM_CONTEXTMENU
:
5021 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5030 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
5033 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
5034 LPWSTR nameW
= NULL
;
5037 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
5038 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
5039 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
5041 result
= EDIT_WM_Create(es
, nameW
);
5042 HeapFree(GetProcessHeap(), 0, nameW
);
5051 es
->bEnableState
= (BOOL
) wParam
;
5052 EDIT_UpdateText(es
, NULL
, TRUE
);
5056 /* we do the proper erase in EDIT_WM_Paint */
5061 result
= (LRESULT
)es
->font
;
5065 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5068 case WM_GETTEXTLENGTH
:
5069 if (unicode
) result
= get_text_length(es
);
5070 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
5071 NULL
, 0, NULL
, NULL
);
5075 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5079 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
5083 result
= EDIT_WM_KillFocus(es
);
5086 case WM_LBUTTONDBLCLK
:
5087 result
= EDIT_WM_LButtonDblClk(es
);
5090 case WM_LBUTTONDOWN
:
5091 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5095 result
= EDIT_WM_LButtonUp(es
);
5098 case WM_MBUTTONDOWN
:
5099 result
= EDIT_WM_MButtonDown(es
);
5103 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5106 case WM_PRINTCLIENT
:
5108 EDIT_WM_Paint(es
, (HDC
)wParam
);
5116 EDIT_WM_SetFocus(es
);
5120 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
5124 /* FIXME: actually set an internal flag and behave accordingly */
5128 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
5133 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
5136 case WM_STYLECHANGED
:
5137 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
5140 case WM_STYLECHANGING
:
5141 result
= 0; /* See EDIT_WM_StyleChanged */
5145 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5153 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5158 int gcWheelDelta
= 0;
5159 UINT pulScrollLines
= 3;
5160 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5162 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
5163 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5166 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
5167 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
5169 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
5170 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
5171 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
5177 /* IME messages to make the edit control IME aware */
5178 case WM_IME_SETCONTEXT
:
5181 case WM_IME_STARTCOMPOSITION
:
5182 es
->composition_start
= es
->selection_end
;
5183 es
->composition_len
= 0;
5186 case WM_IME_COMPOSITION
:
5187 EDIT_ImeComposition(hwnd
, lParam
, es
);
5190 case WM_IME_ENDCOMPOSITION
:
5191 if (es
->composition_len
> 0)
5193 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
5194 es
->selection_end
= es
->selection_start
;
5195 es
->composition_len
= 0;
5199 case WM_IME_COMPOSITIONFULL
:
5205 case WM_IME_CONTROL
:
5209 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5213 /* reactos: check GetWindowLong in case es has been destroyed during processing */
5214 if (IsWindow(hwnd
) && es
&& GetWindowLongPtrW(hwnd
, 0))
5215 EDIT_UnlockBuffer(es
, FALSE
);
5217 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5223 /*********************************************************************
5225 * EditWndProc (USER32.@)
5227 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5229 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
5232 /*********************************************************************
5234 * EditWndProcW (USER32.@)
5236 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5238 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
5241 /*********************************************************************
5242 * edit class descriptor
5244 static const WCHAR editW
[] = {'E','d','i','t',0};
5245 const struct builtin_class_descr EDIT_builtin_class
=
5248 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5250 EditWndProcA
, /* procA */
5251 EditWndProcW
, /* procW */
5253 sizeof(EDITSTATE
*) + sizeof(WORD
), /* extra */
5255 sizeof(EDITSTATE
*), /* extra */
5257 IDC_IBEAM
, /* cursor */