4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 8, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - EDITBALLOONTIP structure
34 * - EM_GETCUEBANNER/Edit_GetCueBannerText
35 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
36 * - EM_SETCUEBANNER/Edit_SetCueBannerText
37 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
38 * - EM_GETIMESTATUS, EM_SETIMESTATUS
47 #include <wine/debug.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
50 WINE_DECLARE_DEBUG_CHANNEL(combo
);
51 WINE_DECLARE_DEBUG_CHANNEL(relay
);
53 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
54 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
55 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
56 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
59 * extra flags for EDITSTATE.flags field
61 #define EF_MODIFIED 0x0001 /* text has been modified */
62 #define EF_FOCUSED 0x0002 /* we have input focus */
63 #define EF_UPDATE 0x0004 /* notify parent of changed state */
64 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
65 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
66 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
67 wrapped line, instead of in front of the next character */
68 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
69 #define EF_APP_HAS_HANDLE 0x0200 /* Set when an app sends EM_[G|S]ETHANDLE. We are in sole control of
70 the text buffer if this is clear. */
71 #define EF_DIALOGMODE 0x0400 /* Indicates that we are inside a dialog window */
75 END_0
= 0, /* line ends with terminating '\0' character */
76 END_WRAP
, /* line is wrapped */
77 END_HARD
, /* line ends with a hard return '\r\n' */
78 END_SOFT
, /* line ends with a soft return '\r\r\n' */
79 END_RICH
/* line ends with a single '\n' */
82 typedef struct tagLINEDEF
{
83 INT length
; /* bruto length of a line in bytes */
84 INT net_length
; /* netto length of a line in visible characters */
86 INT width
; /* width of the line in pixels */
87 INT index
; /* line index into the buffer */
88 struct tagLINEDEF
*next
;
93 BOOL is_unicode
; /* how the control was created */
94 LPWSTR text
; /* the actual contents of the control */
95 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
96 UINT buffer_size
; /* the size of the buffer in characters */
97 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
98 HFONT font
; /* NULL means standard system font */
99 INT x_offset
; /* scroll offset for multi lines this is in pixels
100 for single lines it's in characters */
101 INT line_height
; /* height of a screen line in pixels */
102 INT char_width
; /* average character width in pixels */
103 DWORD style
; /* sane version of wnd->dwStyle */
104 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
105 INT undo_insert_count
; /* number of characters inserted in sequence */
106 UINT undo_position
; /* character index of the insertion and deletion */
107 LPWSTR undo_text
; /* deleted text */
108 UINT undo_buffer_size
; /* size of the deleted text buffer */
109 INT selection_start
; /* == selection_end if no selection */
110 INT selection_end
; /* == current caret position */
111 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
112 INT left_margin
; /* in pixels */
113 INT right_margin
; /* in pixels */
115 INT text_width
; /* width of the widest line in pixels for multi line controls
116 and just line width for single line controls */
117 INT region_posx
; /* Position of cursor relative to region: */
118 INT region_posy
; /* -1: to left, 0: within, 1: to right */
119 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
120 INT line_count
; /* number of lines */
121 INT y_offset
; /* scroll offset in number of lines */
122 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
123 BOOL bEnableState
; /* flag keeping the enable state */
124 HWND hwndSelf
; /* the our window handle */
125 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
126 Even if parent will change, EN_* messages
127 should be sent to the first parent. */
128 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
130 * only for multi line controls
132 INT lock_count
; /* amount of re-entries in the EditWndProc */
135 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
136 HLOCAL hloc32W
; /* our unicode local memory block */
137 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
142 UINT composition_len
; /* length of composition, 0 == no composition */
143 int composition_start
; /* the character position for the composition */
147 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
148 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
150 /* used for disabled or read-only edit control */
151 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
153 { /* Notify parent which has created this edit control */ \
154 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
155 SendMessageW(es->hwndParent, WM_COMMAND, \
156 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
157 (LPARAM)(es->hwndSelf)); \
160 static const WCHAR empty_stringW
[] = {0};
162 /*********************************************************************
167 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
169 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
173 /*********************************************************************
178 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
180 es
->undo_insert_count
= 0;
181 *es
->undo_text
= '\0';
185 /**********************************************************************
188 * Returns the window version in case Wine emulates a later version
189 * of windows than the application expects.
191 * In a number of cases when windows runs an application that was
192 * designed for an earlier windows version, windows reverts
193 * to "old" behaviour of that earlier version.
195 * An example is a disabled edit control that needs to be painted.
196 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
197 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
198 * applications with an expected version 0f 4.0 or higher.
201 static DWORD
get_app_version(void)
203 static DWORD version
;
206 DWORD dwEmulatedVersion
;
208 DWORD dwProcVersion
= GetProcessVersion(0);
210 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
211 GetVersionExW( &info
);
212 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
213 /* FIXME: this may not be 100% correct; see discussion on the
214 * wine developer list in Nov 1999 */
215 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
220 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
225 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
226 msg
= WM_CTLCOLORSTATIC
;
228 msg
= WM_CTLCOLOREDIT
;
230 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
231 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
233 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
238 /*********************************************************************
242 * Find the beginning of words.
243 * Note: unlike the specs for a WordBreakProc, this function only
244 * allows to be called without linebreaks between s[0] up to
245 * s[count - 1]. Remember it is only called
246 * internally, so we can decide this for ourselves.
249 static INT
EDIT_WordBreakProc(LPWSTR s
, INT index
, INT count
, INT action
)
253 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
263 if (s
[index
] == ' ') {
264 while (index
&& (s
[index
] == ' '))
267 while (index
&& (s
[index
] != ' '))
273 while (index
&& (s
[index
] != ' '))
286 while ((index
< count
) && (s
[index
] == ' ')) index
++;
288 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
290 while ((s
[index
] == ' ') && (index
< count
)) index
++;
295 ret
= (s
[index
] == ' ');
298 ERR("unknown action code, please report !\n");
305 /*********************************************************************
307 * EDIT_CallWordBreakProc
309 * Call appropriate WordBreakProc (internal or external).
311 * Note: The "start" argument should always be an index referring
312 * to es->text. The actual wordbreak proc might be
313 * 16 bit, so we can't always pass any 32 bit LPSTR.
314 * Hence we assume that es->text is the buffer that holds
315 * the string under examination (we can decide this for ourselves).
318 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
322 if (es
->word_break_proc
)
326 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
328 TRACE_(relay
)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
329 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
330 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
334 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
338 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
339 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
340 if (textA
== NULL
) return 0;
341 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
342 TRACE_(relay
)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
343 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
344 ret
= wbpA(textA
, index
, countA
, action
);
345 HeapFree(GetProcessHeap(), 0, textA
);
349 ret
= EDIT_WordBreakProc(es
->text
+ start
, index
, count
, action
);
354 /*********************************************************************
356 * EDIT_BuildLineDefs_ML
358 * Build linked list of text lines.
359 * Lines can end with '\0' (last line), a character (if it is wrapped),
360 * a soft return '\r\r\n' or a hard return '\r\n'
363 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
367 LPWSTR current_position
, cp
;
369 LINEDEF
*current_line
;
370 LINEDEF
*previous_line
;
372 INT line_index
= 0, nstart_line
= 0, nstart_index
= 0;
373 INT line_count
= es
->line_count
;
377 if (istart
== iend
&& delta
== 0)
380 dc
= GetDC(es
->hwndSelf
);
382 old_font
= SelectObject(dc
, es
->font
);
384 previous_line
= NULL
;
385 current_line
= es
->first_line_def
;
387 /* Find starting line. istart must lie inside an existing line or
388 * at the end of buffer */
390 if (istart
< current_line
->index
+ current_line
->length
||
391 current_line
->ending
== END_0
)
394 previous_line
= current_line
;
395 current_line
= current_line
->next
;
397 } while (current_line
);
399 if (!current_line
) /* Error occurred start is not inside previous buffer */
401 FIXME(" modification occurred outside buffer\n");
402 ReleaseDC(es
->hwndSelf
, dc
);
406 /* Remember start of modifications in order to calculate update region */
407 nstart_line
= line_index
;
408 nstart_index
= current_line
->index
;
410 /* We must start to reformat from the previous line since the modifications
411 * may have caused the line to wrap upwards. */
412 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
415 current_line
= previous_line
;
417 start_line
= current_line
;
419 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
420 current_position
= es
->text
+ current_line
->index
;
422 if (current_line
!= start_line
)
424 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
426 /* The buffer has been expanded, create a new line and
427 insert it into the link list */
428 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF
));
429 if (new_line
== NULL
) // reactos r33509
430 break; // reactos r33509
431 new_line
->next
= previous_line
->next
;
432 previous_line
->next
= new_line
;
433 current_line
= new_line
;
436 else if (current_line
->index
+ delta
< current_position
- es
->text
)
438 /* The previous line merged with this line so we delete this extra entry */
439 previous_line
->next
= current_line
->next
;
440 HeapFree(GetProcessHeap(), 0, current_line
);
441 current_line
= previous_line
->next
;
445 else /* current_line->index + delta == current_position */
447 if (current_position
- es
->text
> iend
)
448 break; /* We reached end of line modifications */
449 /* else recalculate this line */
453 current_line
->index
= current_position
- es
->text
;
454 orig_net_length
= current_line
->net_length
;
456 /* Find end of line */
457 cp
= current_position
;
459 if (*cp
== '\n') break;
460 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
465 /* Mark type of line termination */
467 current_line
->ending
= END_0
;
468 current_line
->net_length
= strlenW(current_position
);
469 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
470 current_line
->ending
= END_SOFT
;
471 current_line
->net_length
= cp
- current_position
- 1;
472 } else if (*cp
== '\n') {
473 current_line
->ending
= END_RICH
;
474 current_line
->net_length
= cp
- current_position
;
476 current_line
->ending
= END_HARD
;
477 current_line
->net_length
= cp
- current_position
;
480 /* Calculate line width */
481 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
482 current_position
, current_line
->net_length
,
483 es
->tabs_count
, es
->tabs
));
485 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
486 if (!(es
->style
& ES_AUTOHSCROLL
)) {
487 if (current_line
->width
> fw
) {
492 next
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
493 prev
+ 1, current_line
->net_length
, WB_RIGHT
);
494 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
495 current_position
, next
, es
->tabs_count
, es
->tabs
));
496 } while (current_line
->width
<= fw
);
497 if (!prev
) { /* Didn't find a line break so force a break */
502 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
,
503 current_position
, next
, es
->tabs_count
, es
->tabs
));
504 } while (current_line
->width
<= fw
);
509 /* If the first line we are calculating, wrapped before istart, we must
510 * adjust istart in order for this to be reflected in the update region. */
511 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
512 istart
= current_line
->index
+ prev
;
513 /* else if we are updating the previous line before the first line we
514 * are re-calculating and it expanded */
515 else if (current_line
== start_line
&&
516 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
518 /* Line expanded due to an upwards line wrap so we must partially include
519 * previous line in update region */
520 nstart_line
= line_index
;
521 nstart_index
= current_line
->index
;
522 istart
= current_line
->index
+ orig_net_length
;
525 current_line
->net_length
= prev
;
526 current_line
->ending
= END_WRAP
;
527 current_line
->width
= (INT
)LOWORD(GetTabbedTextExtentW(dc
, current_position
,
528 current_line
->net_length
, es
->tabs_count
, es
->tabs
));
530 else if (current_line
== start_line
&&
531 current_line
->index
!= nstart_index
&&
532 orig_net_length
< current_line
->net_length
) {
533 /* The previous line expanded but it's still not as wide as the client rect */
534 /* The expansion is due to an upwards line wrap so we must partially include
535 it in the update region */
536 nstart_line
= line_index
;
537 nstart_index
= current_line
->index
;
538 istart
= current_line
->index
+ orig_net_length
;
543 /* Adjust length to include line termination */
544 switch (current_line
->ending
) {
546 current_line
->length
= current_line
->net_length
+ 3;
549 current_line
->length
= current_line
->net_length
+ 1;
552 current_line
->length
= current_line
->net_length
+ 2;
556 current_line
->length
= current_line
->net_length
;
559 es
->text_width
= max(es
->text_width
, current_line
->width
);
560 current_position
+= current_line
->length
;
561 previous_line
= current_line
;
562 current_line
= current_line
->next
;
564 } while (previous_line
->ending
!= END_0
);
566 /* Finish adjusting line indexes by delta or remove hanging lines */
567 if (previous_line
->ending
== END_0
)
569 LINEDEF
*pnext
= NULL
;
571 previous_line
->next
= NULL
;
574 pnext
= current_line
->next
;
575 HeapFree(GetProcessHeap(), 0, current_line
);
576 current_line
= pnext
;
584 current_line
->index
+= delta
;
585 current_line
= current_line
->next
;
589 /* Calculate rest of modification rectangle */
594 * We calculate two rectangles. One for the first line which may have
595 * an indent with respect to the format rect. The other is a format-width
596 * rectangle that spans the rest of the lines that changed or moved.
598 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
599 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
600 rc
.bottom
= rc
.top
+ es
->line_height
;
601 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
602 rc
.left
= es
->format_rect
.left
;
604 rc
.left
= es
->format_rect
.left
+ (INT
)LOWORD(GetTabbedTextExtentW(dc
,
605 es
->text
+ nstart_index
, istart
- nstart_index
,
606 es
->tabs_count
, es
->tabs
)) - es
->x_offset
; /* Adjust for horz scroll */
607 rc
.right
= es
->format_rect
.right
;
608 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
611 rc
.left
= es
->format_rect
.left
;
612 rc
.right
= es
->format_rect
.right
;
614 * If lines were added or removed we must re-paint the remainder of the
615 * lines since the remaining lines were either shifted up or down.
617 if (line_count
< es
->line_count
) /* We added lines */
618 rc
.bottom
= es
->line_count
* es
->line_height
;
619 else if (line_count
> es
->line_count
) /* We removed lines */
620 rc
.bottom
= line_count
* es
->line_height
;
622 rc
.bottom
= line_index
* es
->line_height
;
623 rc
.bottom
+= es
->format_rect
.top
;
624 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
625 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
626 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
627 DeleteObject(tmphrgn
);
631 SelectObject(dc
, old_font
);
633 ReleaseDC(es
->hwndSelf
, dc
);
637 static inline UINT
get_text_length(EDITSTATE
*es
)
639 if(es
->text_length
== (UINT
)-1)
640 es
->text_length
= strlenW(es
->text
);
641 return es
->text_length
;
644 /*********************************************************************
646 * EDIT_GetPasswordPointer_SL
648 * note: caller should free the (optionally) allocated buffer
651 static LPWSTR
EDIT_GetPasswordPointer_SL(EDITSTATE
*es
)
653 if (es
->style
& ES_PASSWORD
) {
654 INT len
= get_text_length(es
);
655 LPWSTR text
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
659 while(len
) text
[--len
] = es
->password_char
;
666 /*********************************************************************
668 * EDIT_CalcLineWidth_SL
671 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
678 text
= EDIT_GetPasswordPointer_SL(es
);
680 dc
= GetDC(es
->hwndSelf
);
682 old_font
= SelectObject(dc
, es
->font
);
684 GetTextExtentPoint32W(dc
, text
, strlenW(text
), &size
);
687 SelectObject(dc
, old_font
);
688 ReleaseDC(es
->hwndSelf
, dc
);
690 if (es
->style
& ES_PASSWORD
)
691 HeapFree(GetProcessHeap(), 0, text
);
693 es
->text_width
= size
.cx
;
696 /*********************************************************************
700 * Beware: This is not the function called on EM_CHARFROMPOS
701 * The position _can_ be outside the formatting / client
703 * The return value is only the character index
706 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
711 INT x_high
= 0, x_low
= 0;
713 if (es
->style
& ES_MULTILINE
) {
714 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
716 LINEDEF
*line_def
= es
->first_line_def
;
718 while ((line
> 0) && line_def
->next
) {
719 line_index
+= line_def
->length
;
720 line_def
= line_def
->next
;
723 x
+= es
->x_offset
- es
->format_rect
.left
;
724 if (es
->style
& ES_RIGHT
)
725 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
726 else if (es
->style
& ES_CENTER
)
727 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
728 if (x
>= line_def
->width
) {
730 *after_wrap
= (line_def
->ending
== END_WRAP
);
731 return line_index
+ line_def
->net_length
;
738 dc
= GetDC(es
->hwndSelf
);
740 old_font
= SelectObject(dc
, es
->font
);
742 high
= line_index
+ line_def
->net_length
+ 1;
743 while (low
< high
- 1)
745 INT mid
= (low
+ high
) / 2;
746 INT x_now
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ line_index
, mid
- line_index
, es
->tabs_count
, es
->tabs
));
755 if (abs(x_high
- x
) + 1 <= abs(x_low
- x
))
761 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
762 (line_def
->ending
== END_WRAP
));
768 x
-= es
->format_rect
.left
;
774 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
775 if (es
->style
& ES_RIGHT
)
777 else if (es
->style
& ES_CENTER
)
781 text
= EDIT_GetPasswordPointer_SL(es
);
782 dc
= GetDC(es
->hwndSelf
);
784 old_font
= SelectObject(dc
, es
->font
);
788 INT high
= es
->x_offset
;
789 while (low
< high
- 1)
791 INT mid
= (low
+ high
) / 2;
792 GetTextExtentPoint32W( dc
, text
+ mid
,
793 es
->x_offset
- mid
, &size
);
802 if (abs(x_high
+ x
) <= abs(x_low
+ x
) + 1)
809 INT low
= es
->x_offset
;
810 INT high
= get_text_length(es
) + 1;
811 while (low
< high
- 1)
813 INT mid
= (low
+ high
) / 2;
814 GetTextExtentPoint32W( dc
, text
+ es
->x_offset
,
815 mid
- es
->x_offset
, &size
);
824 if (abs(x_high
- x
) <= abs(x_low
- x
) + 1)
829 if (es
->style
& ES_PASSWORD
)
830 HeapFree(GetProcessHeap(), 0, text
);
833 SelectObject(dc
, old_font
);
834 ReleaseDC(es
->hwndSelf
, dc
);
839 /*********************************************************************
843 * adjusts the point to be within the formatting rectangle
844 * (so CharFromPos returns the nearest _visible_ character)
847 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
849 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
850 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
854 /*********************************************************************
859 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
864 if (!(es
->style
& ES_MULTILINE
))
866 if (index
> (INT
)get_text_length(es
))
867 return es
->line_count
- 1;
869 index
= min(es
->selection_start
, es
->selection_end
);
872 line_def
= es
->first_line_def
;
873 index
-= line_def
->length
;
874 while ((index
>= 0) && line_def
->next
) {
876 line_def
= line_def
->next
;
877 index
-= line_def
->length
;
883 /*********************************************************************
888 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
891 const LINEDEF
*line_def
;
893 if (!(es
->style
& ES_MULTILINE
))
895 if (line
>= es
->line_count
)
899 line_def
= es
->first_line_def
;
901 INT index
= es
->selection_end
- line_def
->length
;
902 while ((index
>= 0) && line_def
->next
) {
903 line_index
+= line_def
->length
;
904 line_def
= line_def
->next
;
905 index
-= line_def
->length
;
909 line_index
+= line_def
->length
;
910 line_def
= line_def
->next
;
918 /*********************************************************************
923 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
927 if (!(es
->style
& ES_MULTILINE
))
928 return get_text_length(es
);
931 /* get the number of remaining non-selected chars of selected lines */
932 INT32 l
; /* line number */
933 INT32 li
; /* index of first char in line */
935 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
936 /* # chars before start of selection area */
937 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
938 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
939 /* # chars after end of selection */
940 li
= EDIT_EM_LineIndex(es
, l
);
941 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
944 line_def
= es
->first_line_def
;
945 index
-= line_def
->length
;
946 while ((index
>= 0) && line_def
->next
) {
947 line_def
= line_def
->next
;
948 index
-= line_def
->length
;
950 return line_def
->net_length
;
954 /*********************************************************************
959 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
961 INT len
= get_text_length(es
);
974 index
= min(index
, len
);
975 dc
= GetDC(es
->hwndSelf
);
977 old_font
= SelectObject(dc
, es
->font
);
978 if (es
->style
& ES_MULTILINE
) {
979 l
= EDIT_EM_LineFromChar(es
, index
);
980 y
= (l
- es
->y_offset
) * es
->line_height
;
981 li
= EDIT_EM_LineIndex(es
, l
);
982 if (after_wrap
&& (li
== index
) && l
) {
984 line_def
= es
->first_line_def
;
986 line_def
= line_def
->next
;
989 if (line_def
->ending
== END_WRAP
) {
991 y
-= es
->line_height
;
992 li
= EDIT_EM_LineIndex(es
, l
);
996 line_def
= es
->first_line_def
;
997 while (line_def
->index
!= li
)
998 line_def
= line_def
->next
;
1000 ll
= line_def
->net_length
;
1001 lw
= line_def
->width
;
1003 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1004 if (es
->style
& ES_RIGHT
)
1006 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
+ (index
- li
), ll
- (index
- li
),
1007 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1010 else if (es
->style
& ES_CENTER
)
1012 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1013 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1018 x
= LOWORD(GetTabbedTextExtentW(dc
, es
->text
+ li
, index
- li
,
1019 es
->tabs_count
, es
->tabs
)) - es
->x_offset
;
1022 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
1023 if (index
< es
->x_offset
) {
1024 GetTextExtentPoint32W(dc
, text
+ index
,
1025 es
->x_offset
- index
, &size
);
1028 GetTextExtentPoint32W(dc
, text
+ es
->x_offset
,
1029 index
- es
->x_offset
, &size
);
1032 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1034 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1035 if (w
> es
->text_width
)
1037 if (es
->style
& ES_RIGHT
)
1038 x
+= w
- es
->text_width
;
1039 else if (es
->style
& ES_CENTER
)
1040 x
+= (w
- es
->text_width
) / 2;
1045 if (es
->style
& ES_PASSWORD
)
1046 HeapFree(GetProcessHeap(), 0, text
);
1048 x
+= es
->format_rect
.left
;
1049 y
+= es
->format_rect
.top
;
1051 SelectObject(dc
, old_font
);
1052 ReleaseDC(es
->hwndSelf
, dc
);
1053 return MAKELONG((INT16
)x
, (INT16
)y
);
1057 /*********************************************************************
1061 * Calculates the bounding rectangle for a line from a starting
1062 * column to an ending column.
1065 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1067 INT line_index
= EDIT_EM_LineIndex(es
, line
);
1069 if (es
->style
& ES_MULTILINE
)
1070 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1072 rc
->top
= es
->format_rect
.top
;
1073 rc
->bottom
= rc
->top
+ es
->line_height
;
1074 rc
->left
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1075 rc
->right
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1079 static inline void text_buffer_changed(EDITSTATE
*es
)
1081 es
->text_length
= (UINT
)-1;
1084 /*********************************************************************
1088 static void EDIT_LockBuffer(EDITSTATE
*es
)
1092 CHAR
*textA
= NULL
; // ReactOS Hacked!
1099 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1100 textA
= LocalLock(es
->hloc32A
);
1101 countA
= strlen(textA
) + 1;
1105 ERR("no buffer ... please report\n");
1112 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
1113 if(countW_new
> es
->buffer_size
+ 1)
1115 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1116 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1117 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1120 es
->hloc32W
= hloc32W_new
;
1121 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1122 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1125 WARN("FAILED! Will synchronize partially\n");
1127 es
->text
= LocalLock(es
->hloc32W
);
1128 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, es
->text
, es
->buffer_size
+ 1);
1129 LocalUnlock(es
->hloc32A
);
1131 else es
->text
= LocalLock(es
->hloc32W
);
1133 if(es
->flags
& EF_APP_HAS_HANDLE
) text_buffer_changed(es
);
1138 /*********************************************************************
1143 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1146 /* Edit window might be already destroyed */
1147 if(!IsWindow(es
->hwndSelf
))
1149 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1153 if (!es
->lock_count
) {
1154 ERR("lock_count == 0 ... please report\n");
1158 ERR("es->text == 0 ... please report\n");
1162 if (force
|| (es
->lock_count
== 1)) {
1165 UINT countW
= get_text_length(es
) + 1;
1169 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1170 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1171 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1172 countA
= LocalSize(es
->hloc32A
);
1173 if(countA_new
> countA
)
1176 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1177 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1178 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1181 es
->hloc32A
= hloc32A_new
;
1182 countA
= LocalSize(hloc32A_new
);
1183 TRACE("Real new size %d bytes\n", countA
);
1186 WARN("FAILED! Will synchronize partially\n");
1188 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
,
1189 LocalLock(es
->hloc32A
), countA
, NULL
, NULL
);
1190 LocalUnlock(es
->hloc32A
);
1193 LocalUnlock(es
->hloc32W
);
1197 ERR("no buffer ... please report\n");
1205 /*********************************************************************
1209 * Try to fit size + 1 characters in the buffer.
1211 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1215 if (size
<= es
->buffer_size
)
1218 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1220 /* Force edit to unlock it's buffer. es->text now NULL */
1221 EDIT_UnlockBuffer(es
, TRUE
);
1224 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1225 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1226 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1227 es
->hloc32W
= hNew32W
;
1228 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1232 EDIT_LockBuffer(es
);
1234 if (es
->buffer_size
< size
) {
1235 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1236 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1239 TRACE("We now have %d+1\n", es
->buffer_size
);
1245 /*********************************************************************
1249 * Try to fit size + 1 bytes in the undo buffer.
1252 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1256 if (size
<= es
->undo_buffer_size
)
1259 TRACE("trying to ReAlloc to %d+1\n", size
);
1261 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1262 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1263 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1268 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1274 /*********************************************************************
1276 * EDIT_UpdateTextRegion
1279 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1281 if (es
->flags
& EF_UPDATE
) {
1282 es
->flags
&= ~EF_UPDATE
;
1283 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1285 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1289 /*********************************************************************
1294 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1296 if (es
->flags
& EF_UPDATE
) {
1297 es
->flags
&= ~EF_UPDATE
;
1298 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1300 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1303 /*********************************************************************
1305 * EDIT_SL_InvalidateText
1307 * Called from EDIT_InvalidateText().
1308 * Does the job for single-line controls only.
1311 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1316 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1317 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1318 EDIT_UpdateText(es
, &rc
, TRUE
);
1322 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
1324 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1328 /*********************************************************************
1330 * EDIT_ML_InvalidateText
1332 * Called from EDIT_InvalidateText().
1333 * Does the job for multi-line controls only.
1336 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1338 INT vlc
= get_vertical_line_count(es
);
1339 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1340 INT el
= EDIT_EM_LineFromChar(es
, end
);
1349 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1352 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1353 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1354 if (sl
< es
->y_offset
) {
1358 if (el
> es
->y_offset
+ vlc
) {
1359 el
= es
->y_offset
+ vlc
;
1360 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1362 GetClientRect(es
->hwndSelf
, &rc1
);
1363 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1365 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1366 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1367 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1369 EDIT_GetLineRect(es
, sl
, sc
,
1370 EDIT_EM_LineLength(es
,
1371 EDIT_EM_LineIndex(es
, sl
)),
1373 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1374 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1375 for (l
= sl
+ 1 ; l
< el
; l
++) {
1376 EDIT_GetLineRect(es
, l
, 0,
1377 EDIT_EM_LineLength(es
,
1378 EDIT_EM_LineIndex(es
, l
)),
1380 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1381 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1383 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1384 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1385 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1390 /*********************************************************************
1392 * EDIT_InvalidateText
1394 * Invalidate the text from offset start up to, but not including,
1395 * offset end. Useful for (re)painting the selection.
1396 * Regions outside the linewidth are not invalidated.
1397 * end == -1 means end == TextLength.
1398 * start and end need not be ordered.
1401 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1407 end
= get_text_length(es
);
1415 if (es
->style
& ES_MULTILINE
)
1416 EDIT_ML_InvalidateText(es
, start
, end
);
1418 EDIT_SL_InvalidateText(es
, start
, end
);
1422 /*********************************************************************
1426 * note: unlike the specs say: the order of start and end
1427 * _is_ preserved in Windows. (i.e. start can be > end)
1428 * In other words: this handler is OK
1431 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1433 UINT old_start
= es
->selection_start
;
1434 UINT old_end
= es
->selection_end
;
1435 UINT len
= get_text_length(es
);
1437 if (start
== (UINT
)-1) {
1438 start
= es
->selection_end
;
1439 end
= es
->selection_end
;
1441 start
= min(start
, len
);
1442 end
= min(end
, len
);
1444 es
->selection_start
= start
;
1445 es
->selection_end
= end
;
1447 es
->flags
|= EF_AFTER_WRAP
;
1449 es
->flags
&= ~EF_AFTER_WRAP
;
1450 /* Compute the necessary invalidation region. */
1451 /* Note that we don't need to invalidate regions which have
1452 * "never" been selected, or those which are "still" selected.
1453 * In fact, every time we hit a selection boundary, we can
1454 * *toggle* whether we need to invalidate. Thus we can optimize by
1455 * *sorting* the interval endpoints. Let's assume that we sort them
1457 * start <= end <= old_start <= old_end
1458 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1459 * in 5 comparisons; i.e. it is impossible to do better than the
1461 ORDER_UINT(end
, old_end
);
1462 ORDER_UINT(start
, old_start
);
1463 ORDER_UINT(old_start
, old_end
);
1464 ORDER_UINT(start
, end
);
1465 /* Note that at this point 'end' and 'old_start' are not in order, but
1466 * start is definitely the min. and old_end is definitely the max. */
1467 if (end
!= old_start
)
1471 * ORDER_UINT32(end, old_start);
1472 * EDIT_InvalidateText(es, start, end);
1473 * EDIT_InvalidateText(es, old_start, old_end);
1474 * in place of the following if statement.
1475 * (That would complete the optimal five-comparison four-element sort.)
1477 if (old_start
> end
)
1479 EDIT_InvalidateText(es
, start
, end
);
1480 EDIT_InvalidateText(es
, old_start
, old_end
);
1484 EDIT_InvalidateText(es
, start
, old_start
);
1485 EDIT_InvalidateText(es
, end
, old_end
);
1488 else EDIT_InvalidateText(es
, start
, old_end
);
1492 /*********************************************************************
1494 * EDIT_UpdateScrollInfo
1497 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1499 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1502 si
.cbSize
= sizeof(SCROLLINFO
);
1503 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1505 si
.nMax
= es
->line_count
- 1;
1506 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1507 si
.nPos
= es
->y_offset
;
1508 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1509 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1510 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1513 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1516 si
.cbSize
= sizeof(SCROLLINFO
);
1517 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1519 si
.nMax
= es
->text_width
- 1;
1520 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1521 si
.nPos
= es
->x_offset
;
1522 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1523 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1524 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1529 /*********************************************************************
1531 * EDIT_EM_LineScroll_internal
1533 * Version of EDIT_EM_LineScroll for internal use.
1534 * It doesn't refuse if ES_MULTILINE is set and assumes that
1535 * dx is in pixels, dy - in lines.
1538 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1541 INT x_offset_in_pixels
;
1542 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1545 if (es
->style
& ES_MULTILINE
)
1547 x_offset_in_pixels
= es
->x_offset
;
1552 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1555 if (-dx
> x_offset_in_pixels
)
1556 dx
= -x_offset_in_pixels
;
1557 if (dx
> es
->text_width
- x_offset_in_pixels
)
1558 dx
= es
->text_width
- x_offset_in_pixels
;
1559 nyoff
= max(0, es
->y_offset
+ dy
);
1560 if (nyoff
>= es
->line_count
- lines_per_page
)
1561 nyoff
= max(0, es
->line_count
- lines_per_page
);
1562 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1567 es
->y_offset
= nyoff
;
1568 if(es
->style
& ES_MULTILINE
)
1571 es
->x_offset
+= dx
/ es
->char_width
;
1573 GetClientRect(es
->hwndSelf
, &rc1
);
1574 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1575 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1576 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1577 /* force scroll info update */
1578 EDIT_UpdateScrollInfo(es
);
1580 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1581 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1582 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1583 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1587 /*********************************************************************
1591 * NOTE: dx is in average character widths, dy - in lines;
1594 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1596 if (!(es
->style
& ES_MULTILINE
))
1599 dx
*= es
->char_width
;
1600 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1604 /*********************************************************************
1609 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1613 if (!(es
->style
& ES_MULTILINE
))
1614 return (LRESULT
)FALSE
;
1624 if (es
->y_offset
< es
->line_count
- 1)
1629 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1632 if (es
->y_offset
< es
->line_count
- 1)
1633 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1636 return (LRESULT
)FALSE
;
1639 INT vlc
= get_vertical_line_count(es
);
1640 /* check if we are going to move too far */
1641 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1642 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1644 /* Notification is done in EDIT_EM_LineScroll */
1646 EDIT_EM_LineScroll(es
, 0, dy
);
1647 return MAKELONG(dy
, TRUE
);
1651 return (LRESULT
)FALSE
;
1655 /*********************************************************************
1660 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1663 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1664 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1665 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1669 /*********************************************************************
1674 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1676 if (es
->style
& ES_MULTILINE
) {
1680 INT cw
= es
->char_width
;
1685 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1686 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1687 vlc
= get_vertical_line_count(es
);
1688 if (l
>= es
->y_offset
+ vlc
)
1689 dy
= l
- vlc
+ 1 - es
->y_offset
;
1690 if (l
< es
->y_offset
)
1691 dy
= l
- es
->y_offset
;
1692 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1693 if (x
< es
->format_rect
.left
)
1694 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1695 if (x
> es
->format_rect
.right
)
1696 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1697 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1699 /* check if we are going to move too far */
1700 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1701 dx
= es
->text_width
- ww
- es
->x_offset
;
1702 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1703 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1710 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1711 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1712 if (x
< es
->format_rect
.left
) {
1713 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1716 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1717 } while ((x
< goal
) && es
->x_offset
);
1718 /* FIXME: use ScrollWindow() somehow to improve performance */
1719 EDIT_UpdateText(es
, NULL
, TRUE
);
1720 } else if (x
> es
->format_rect
.right
) {
1722 INT len
= get_text_length(es
);
1723 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1726 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1727 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1728 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1729 /* FIXME: use ScrollWindow() somehow to improve performance */
1730 EDIT_UpdateText(es
, NULL
, TRUE
);
1734 if(es
->flags
& EF_FOCUSED
)
1735 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1739 /*********************************************************************
1744 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1746 INT e
= es
->selection_end
;
1750 if ((es
->style
& ES_MULTILINE
) && e
&&
1751 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1753 if (e
&& (es
->text
[e
- 1] == '\r'))
1757 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1758 EDIT_EM_ScrollCaret(es
);
1762 /*********************************************************************
1766 * Only for multi line controls
1767 * Move the caret one line down, on a column with the nearest
1768 * x coordinate on the screen (might be a different column).
1771 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1773 INT s
= es
->selection_start
;
1774 INT e
= es
->selection_end
;
1775 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1776 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1777 INT x
= (short)LOWORD(pos
);
1778 INT y
= (short)HIWORD(pos
);
1780 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1783 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1784 EDIT_EM_ScrollCaret(es
);
1788 /*********************************************************************
1793 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1795 BOOL after_wrap
= FALSE
;
1798 /* Pass a high value in x to make sure of receiving the end of the line */
1799 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1800 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1801 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1803 e
= get_text_length(es
);
1804 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1805 EDIT_EM_ScrollCaret(es
);
1809 /*********************************************************************
1814 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1816 INT e
= es
->selection_end
;
1820 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1821 if (es
->text
[e
] == '\n')
1823 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1827 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1828 EDIT_EM_ScrollCaret(es
);
1832 /*********************************************************************
1836 * Home key: move to beginning of line.
1839 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1843 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1844 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1845 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1846 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1849 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1850 EDIT_EM_ScrollCaret(es
);
1854 /*********************************************************************
1856 * EDIT_MovePageDown_ML
1858 * Only for multi line controls
1859 * Move the caret one page down, on a column with the nearest
1860 * x coordinate on the screen (might be a different column).
1863 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1865 INT s
= es
->selection_start
;
1866 INT e
= es
->selection_end
;
1867 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1868 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1869 INT x
= (short)LOWORD(pos
);
1870 INT y
= (short)HIWORD(pos
);
1872 e
= EDIT_CharFromPos(es
, x
,
1873 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1877 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1878 EDIT_EM_ScrollCaret(es
);
1882 /*********************************************************************
1884 * EDIT_MovePageUp_ML
1886 * Only for multi line controls
1887 * Move the caret one page up, on a column with the nearest
1888 * x coordinate on the screen (might be a different column).
1891 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1893 INT s
= es
->selection_start
;
1894 INT e
= es
->selection_end
;
1895 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1896 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1897 INT x
= (short)LOWORD(pos
);
1898 INT y
= (short)HIWORD(pos
);
1900 e
= EDIT_CharFromPos(es
, x
,
1901 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1905 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1906 EDIT_EM_ScrollCaret(es
);
1910 /*********************************************************************
1914 * Only for multi line controls
1915 * Move the caret one line up, on a column with the nearest
1916 * x coordinate on the screen (might be a different column).
1919 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1921 INT s
= es
->selection_start
;
1922 INT e
= es
->selection_end
;
1923 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1924 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1925 INT x
= (short)LOWORD(pos
);
1926 INT y
= (short)HIWORD(pos
);
1928 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1931 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1932 EDIT_EM_ScrollCaret(es
);
1936 /*********************************************************************
1938 * EDIT_MoveWordBackward
1941 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1943 INT s
= es
->selection_start
;
1944 INT e
= es
->selection_end
;
1949 l
= EDIT_EM_LineFromChar(es
, e
);
1950 ll
= EDIT_EM_LineLength(es
, e
);
1951 li
= EDIT_EM_LineIndex(es
, l
);
1954 li
= EDIT_EM_LineIndex(es
, l
- 1);
1955 e
= li
+ EDIT_EM_LineLength(es
, li
);
1958 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
1962 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
1963 EDIT_EM_ScrollCaret(es
);
1967 /*********************************************************************
1969 * EDIT_MoveWordForward
1972 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
1974 INT s
= es
->selection_start
;
1975 INT e
= es
->selection_end
;
1980 l
= EDIT_EM_LineFromChar(es
, e
);
1981 ll
= EDIT_EM_LineLength(es
, e
);
1982 li
= EDIT_EM_LineIndex(es
, l
);
1984 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
1985 e
= EDIT_EM_LineIndex(es
, l
+ 1);
1987 e
= li
+ EDIT_CallWordBreakProc(es
,
1988 li
, e
- li
+ 1, ll
, WB_RIGHT
);
1992 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
1993 EDIT_EM_ScrollCaret(es
);
1997 /*********************************************************************
2002 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2006 LOGFONTW underline_font
;
2007 HFONT hUnderline
= 0;
2016 BkMode
= GetBkMode(dc
);
2017 BkColor
= GetBkColor(dc
);
2018 TextColor
= GetTextColor(dc
);
2020 if (es
->composition_len
== 0)
2022 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2023 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2024 SetBkMode( dc
, OPAQUE
);
2028 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2029 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2030 underline_font
.lfUnderline
= TRUE
;
2031 hUnderline
= CreateFontIndirectW(&underline_font
);
2032 old_font
= SelectObject(dc
,hUnderline
);
2035 li
= EDIT_EM_LineIndex(es
, line
);
2036 if (es
->style
& ES_MULTILINE
) {
2037 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2038 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2040 LPWSTR text
= EDIT_GetPasswordPointer_SL(es
);
2041 TextOutW(dc
, x
, y
, text
+ li
+ col
, count
);
2042 GetTextExtentPoint32W(dc
, text
+ li
+ col
, count
, &size
);
2044 if (es
->style
& ES_PASSWORD
)
2045 HeapFree(GetProcessHeap(), 0, text
);
2048 if (es
->composition_len
== 0)
2050 SetBkColor(dc
, BkColor
);
2051 SetTextColor(dc
, TextColor
);
2052 SetBkMode( dc
, BkMode
);
2057 SelectObject(dc
,old_font
);
2059 DeleteObject(hUnderline
);
2066 /*********************************************************************
2071 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2073 INT s
= es
->selection_start
;
2074 INT e
= es
->selection_end
;
2081 if (es
->style
& ES_MULTILINE
) {
2082 INT vlc
= get_vertical_line_count(es
);
2084 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2089 TRACE("line=%d\n", line
);
2091 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2092 x
= (short)LOWORD(pos
);
2093 y
= (short)HIWORD(pos
);
2094 li
= EDIT_EM_LineIndex(es
, line
);
2095 ll
= EDIT_EM_LineLength(es
, li
);
2096 s
= min(es
->selection_start
, es
->selection_end
);
2097 e
= max(es
->selection_start
, es
->selection_end
);
2098 s
= min(li
+ ll
, max(li
, s
));
2099 e
= min(li
+ ll
, max(li
, e
));
2100 if (rev
&& (s
!= e
) &&
2101 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2102 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2103 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2104 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2106 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2110 /*********************************************************************
2112 * EDIT_AdjustFormatRect
2114 * Adjusts the format rectangle for the current font and the
2115 * current client rectangle.
2118 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2122 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2123 if (es
->style
& ES_MULTILINE
)
2125 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2127 vlc
= get_vertical_line_count(es
);
2128 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2130 /* correct es->x_offset */
2131 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2132 max_x_offset
= es
->text_width
- fw
;
2133 if(max_x_offset
< 0) max_x_offset
= 0;
2134 if(es
->x_offset
> max_x_offset
)
2135 es
->x_offset
= max_x_offset
;
2137 /* correct es->y_offset */
2138 max_y_offset
= es
->line_count
- vlc
;
2139 if(max_y_offset
< 0) max_y_offset
= 0;
2140 if(es
->y_offset
> max_y_offset
)
2141 es
->y_offset
= max_y_offset
;
2143 /* force scroll info update */
2144 EDIT_UpdateScrollInfo(es
);
2147 /* Windows doesn't care to fix text placement for SL controls */
2148 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2150 /* Always stay within the client area */
2151 GetClientRect(es
->hwndSelf
, &ClientRect
);
2152 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2154 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2155 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2157 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2161 /*********************************************************************
2165 * note: this is not (exactly) the handler called on EM_SETRECTNP
2166 * it is also used to set the rect of a single line control
2169 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2173 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2175 CopyRect(&es
->format_rect
, rc
);
2177 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2178 es
->format_rect
.left
++;
2179 es
->format_rect
.right
--;
2181 if (es
->format_rect
.bottom
- es
->format_rect
.top
2182 >= es
->line_height
+ 2)
2184 es
->format_rect
.top
++;
2185 es
->format_rect
.bottom
--;
2188 else if (es
->style
& WS_BORDER
) {
2189 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2190 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2191 es
->format_rect
.left
+= bw
;
2192 es
->format_rect
.right
-= bw
;
2193 if (es
->format_rect
.bottom
- es
->format_rect
.top
2194 >= es
->line_height
+ 2 * bh
)
2196 es
->format_rect
.top
+= bh
;
2197 es
->format_rect
.bottom
-= bh
;
2201 es
->format_rect
.left
+= es
->left_margin
;
2202 es
->format_rect
.right
-= es
->right_margin
;
2203 EDIT_AdjustFormatRect(es
);
2207 /*********************************************************************
2211 * returns line number (not index) in high-order word of result.
2212 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2213 * to Richedit, not to the edit control. Original documentation is valid.
2214 * FIXME: do the specs mean to return -1 if outside client area or
2215 * if outside formatting rectangle ???
2218 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2226 GetClientRect(es
->hwndSelf
, &rc
);
2227 if (!PtInRect(&rc
, pt
))
2230 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2231 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2235 /*********************************************************************
2239 * Enable or disable soft breaks.
2241 * This means: insert or remove the soft linebreak character (\r\r\n).
2242 * Take care to check if the text still fits the buffer after insertion.
2243 * If not, notify with EN_ERRSPACE.
2246 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2248 es
->flags
&= ~EF_USE_SOFTBRK
;
2250 es
->flags
|= EF_USE_SOFTBRK
;
2251 FIXME("soft break enabled, not implemented\n");
2257 /*********************************************************************
2261 * Hopefully this won't fire back at us.
2262 * We always start with a fixed buffer in the local heap.
2263 * Despite of the documentation says that the local heap is used
2264 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2265 * buffer on the local heap.
2268 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2272 if (!(es
->style
& ES_MULTILINE
))
2276 hLocal
= es
->hloc32W
;
2282 UINT countA
, alloc_size
;
2283 TRACE("Allocating 32-bit ANSI alias buffer\n");
2284 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2285 alloc_size
= ROUND_TO_GROW(countA
);
2286 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2288 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2291 textA
= LocalLock(es
->hloc32A
);
2292 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2293 LocalUnlock(es
->hloc32A
);
2295 hLocal
= es
->hloc32A
;
2298 es
->flags
|= EF_APP_HAS_HANDLE
;
2299 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2304 /*********************************************************************
2309 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2312 INT line_len
, dst_len
;
2315 if (es
->style
& ES_MULTILINE
) {
2316 if (line
>= es
->line_count
)
2320 i
= EDIT_EM_LineIndex(es
, line
);
2322 line_len
= EDIT_EM_LineLength(es
, i
);
2323 dst_len
= *(WORD
*)dst
;
2326 if(dst_len
<= line_len
)
2328 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2331 else /* Append 0 if enough space */
2333 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2340 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2341 if(!ret
&& line_len
) /* Insufficient buffer size */
2343 if(ret
< dst_len
) /* Append 0 if enough space */
2344 ((LPSTR
)dst
)[ret
] = 0;
2350 /*********************************************************************
2355 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2357 UINT s
= es
->selection_start
;
2358 UINT e
= es
->selection_end
;
2365 return MAKELONG(s
, e
);
2369 /*********************************************************************
2373 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2376 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, LPCWSTR lpsz_replace
, BOOL send_update
, BOOL honor_limit
)
2378 UINT strl
= strlenW(lpsz_replace
);
2379 UINT tl
= get_text_length(es
);
2390 TRACE("%s, can_undo %d, send_update %d\n",
2391 debugstr_w(lpsz_replace
), can_undo
, send_update
);
2393 s
= es
->selection_start
;
2394 e
= es
->selection_end
;
2396 if ((s
== e
) && !strl
)
2401 size
= tl
- (e
- s
) + strl
;
2405 /* Issue the EN_MAXTEXT notification and continue with replacing text
2406 * such that buffer limit is honored. */
2407 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2408 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2409 /* Buffer limit can be smaller than the actual length of text in combobox */
2410 if (es
->buffer_limit
< (tl
- (e
-s
)))
2413 strl
= es
->buffer_limit
- (tl
- (e
-s
));
2416 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2420 /* there is something to be deleted */
2421 TRACE("deleting stuff.\n");
2423 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2425 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2426 buf
[bufl
] = 0; /* ensure 0 termination */
2428 strcpyW(es
->text
+ s
, es
->text
+ e
);
2429 text_buffer_changed(es
);
2432 /* there is an insertion */
2433 tl
= get_text_length(es
);
2434 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
));
2435 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2437 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2438 p
[i
] = lpsz_replace
[i
];
2439 if(es
->style
& ES_UPPERCASE
)
2440 CharUpperBuffW(p
, strl
);
2441 else if(es
->style
& ES_LOWERCASE
)
2442 CharLowerBuffW(p
, strl
);
2443 text_buffer_changed(es
);
2445 if (es
->style
& ES_MULTILINE
)
2447 INT st
= min(es
->selection_start
, es
->selection_end
);
2448 INT vlc
= get_vertical_line_count(es
);
2450 hrgn
= CreateRectRgn(0, 0, 0, 0);
2451 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2452 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2453 /* if text is too long undo all changes */
2454 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2456 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2458 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2460 text_buffer_changed(es
);
2461 EDIT_BuildLineDefs_ML(es
, s
, e
,
2462 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2465 hrgn
= CreateRectRgn(0, 0, 0, 0);
2466 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2470 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2471 EDIT_CalcLineWidth_SL(es
);
2472 /* remove chars that don't fit */
2473 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2474 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2475 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2477 EDIT_CalcLineWidth_SL(es
);
2479 text_buffer_changed(es
);
2480 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2486 utl
= strlenW(es
->undo_text
);
2487 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2488 /* undo-buffer is extended to the right */
2489 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2490 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2491 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2492 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2493 /* undo-buffer is extended to the left */
2494 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2495 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2497 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2499 es
->undo_position
= s
;
2501 /* new undo-buffer */
2502 EDIT_MakeUndoFit(es
, e
- s
);
2503 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2504 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2505 es
->undo_position
= s
;
2507 /* any deletion makes the old insertion-undo invalid */
2508 es
->undo_insert_count
= 0;
2510 EDIT_EM_EmptyUndoBuffer(es
);
2514 if ((s
== es
->undo_position
) ||
2515 ((es
->undo_insert_count
) &&
2516 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2518 * insertion is new and at delete position or
2519 * an extension to either left or right
2521 es
->undo_insert_count
+= strl
;
2523 /* new insertion undo */
2524 es
->undo_position
= s
;
2525 es
->undo_insert_count
= strl
;
2526 /* new insertion makes old delete-buffer invalid */
2527 *es
->undo_text
= '\0';
2530 EDIT_EM_EmptyUndoBuffer(es
);
2534 HeapFree(GetProcessHeap(), 0, buf
);
2538 /* If text has been deleted and we're right or center aligned then scroll rightward */
2539 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2541 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2543 if (delta
< 0 && es
->x_offset
)
2545 if (abs(delta
) > es
->x_offset
)
2548 es
->x_offset
+= delta
;
2552 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2553 es
->flags
|= EF_MODIFIED
;
2554 if (send_update
) es
->flags
|= EF_UPDATE
;
2557 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2561 EDIT_UpdateText(es
, NULL
, TRUE
);
2563 EDIT_EM_ScrollCaret(es
);
2565 /* force scroll info update */
2566 EDIT_UpdateScrollInfo(es
);
2569 if(send_update
|| (es
->flags
& EF_UPDATE
))
2571 es
->flags
&= ~EF_UPDATE
;
2572 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2577 /*********************************************************************
2581 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2584 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2586 if (!(es
->style
& ES_MULTILINE
))
2590 WARN("called with NULL handle\n");
2594 EDIT_UnlockBuffer(es
, TRUE
);
2600 LocalFree(es
->hloc32A
);
2612 countA
= LocalSize(hloc
);
2613 textA
= LocalLock(hloc
);
2614 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2615 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2617 ERR("Could not allocate new unicode buffer\n");
2620 textW
= LocalLock(hloc32W_new
);
2621 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2622 LocalUnlock(hloc32W_new
);
2626 LocalFree(es
->hloc32W
);
2628 es
->hloc32W
= hloc32W_new
;
2632 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2634 es
->flags
|= EF_APP_HAS_HANDLE
;
2635 EDIT_LockBuffer(es
);
2637 es
->x_offset
= es
->y_offset
= 0;
2638 es
->selection_start
= es
->selection_end
= 0;
2639 EDIT_EM_EmptyUndoBuffer(es
);
2640 es
->flags
&= ~EF_MODIFIED
;
2641 es
->flags
&= ~EF_UPDATE
;
2642 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2643 EDIT_UpdateText(es
, NULL
, TRUE
);
2644 EDIT_EM_ScrollCaret(es
);
2645 /* force scroll info update */
2646 EDIT_UpdateScrollInfo(es
);
2650 /*********************************************************************
2654 * NOTE: this version currently implements WinNT limits
2657 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2659 if (!limit
) limit
= ~0u;
2660 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2661 es
->buffer_limit
= limit
;
2665 /*********************************************************************
2669 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2670 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2671 * margin according to the textmetrics of the current font.
2673 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2674 * of the char's width as the margin, but this is not how Windows handles this.
2675 * For all other fonts Windows sets the margins to zero.
2677 * FIXME - When EC_USEFONTINFO is used the margins only change if the
2678 * edit control is equal to or larger than a certain size.
2679 * Interestingly if one subtracts both the left and right margins from
2680 * this size one always seems to get an even number. The extents of
2681 * the (four character) string "'**'" match this quite closely, so
2682 * we'll use this until we come up with a better idea.
2684 static int calc_min_set_margin_size(HDC dc
, INT left
, INT right
)
2686 WCHAR magic_string
[] = {'\'','*','*','\'', 0};
2689 GetTextExtentPointW(dc
, magic_string
, sizeof(magic_string
)/sizeof(WCHAR
) - 1, &sz
);
2690 return sz
.cx
+ left
+ right
;
2693 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2694 WORD left
, WORD right
, BOOL repaint
)
2697 INT default_left_margin
= 0; /* in pixels */
2698 INT default_right_margin
= 0; /* in pixels */
2700 /* Set the default margins depending on the font */
2701 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2702 HDC dc
= GetDC(es
->hwndSelf
);
2703 HFONT old_font
= SelectObject(dc
, es
->font
);
2704 GetTextMetricsW(dc
, &tm
);
2705 /* The default margins are only non zero for TrueType or Vector fonts */
2706 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2709 /* This must be calculated more exactly! But how? */
2710 default_left_margin
= tm
.tmAveCharWidth
/ 2;
2711 default_right_margin
= tm
.tmAveCharWidth
/ 2;
2712 min_size
= calc_min_set_margin_size(dc
, default_left_margin
, default_right_margin
);
2713 GetClientRect(es
->hwndSelf
, &rc
);
2714 if(rc
.right
- rc
.left
< min_size
) {
2715 default_left_margin
= es
->left_margin
;
2716 default_right_margin
= es
->right_margin
;
2719 SelectObject(dc
, old_font
);
2720 ReleaseDC(es
->hwndSelf
, dc
);
2723 if (action
& EC_LEFTMARGIN
) {
2724 es
->format_rect
.left
-= es
->left_margin
;
2725 if (left
!= EC_USEFONTINFO
)
2726 es
->left_margin
= left
;
2728 es
->left_margin
= default_left_margin
;
2729 es
->format_rect
.left
+= es
->left_margin
;
2732 if (action
& EC_RIGHTMARGIN
) {
2733 es
->format_rect
.right
+= es
->right_margin
;
2734 if (right
!= EC_USEFONTINFO
)
2735 es
->right_margin
= right
;
2737 es
->right_margin
= default_right_margin
;
2738 es
->format_rect
.right
-= es
->right_margin
;
2741 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2742 EDIT_AdjustFormatRect(es
);
2743 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2746 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2750 /*********************************************************************
2752 * EM_SETPASSWORDCHAR
2755 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2759 if (es
->style
& ES_MULTILINE
)
2762 if (es
->password_char
== c
)
2765 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2766 es
->password_char
= c
;
2768 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2769 es
->style
|= ES_PASSWORD
;
2771 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2772 es
->style
&= ~ES_PASSWORD
;
2774 EDIT_UpdateText(es
, NULL
, TRUE
);
2778 /*********************************************************************
2783 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2785 if (!(es
->style
& ES_MULTILINE
))
2787 HeapFree(GetProcessHeap(), 0, es
->tabs
);
2788 es
->tabs_count
= count
;
2792 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
2793 if (es
->tabs
== NULL
) // reactos r33503
2798 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2804 /*********************************************************************
2806 * EM_SETWORDBREAKPROC
2809 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
2811 if (es
->word_break_proc
== wbp
)
2814 es
->word_break_proc
= wbp
;
2816 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2817 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2818 EDIT_UpdateText(es
, NULL
, TRUE
);
2823 /*********************************************************************
2828 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
2833 /* As per MSDN spec, for a single-line edit control,
2834 the return value is always TRUE */
2835 if( es
->style
& ES_READONLY
)
2836 return !(es
->style
& ES_MULTILINE
);
2838 ulength
= strlenW(es
->undo_text
);
2840 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
2841 if (utext
== NULL
) // reactos r33503
2842 return FALSE
; // reactos r33503
2844 strcpyW(utext
, es
->undo_text
);
2846 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2847 es
->undo_insert_count
, debugstr_w(utext
));
2849 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2850 EDIT_EM_EmptyUndoBuffer(es
);
2851 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, TRUE
, TRUE
);
2852 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2853 /* send the notification after the selection start and end are set */
2854 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2855 EDIT_EM_ScrollCaret(es
);
2856 HeapFree(GetProcessHeap(), 0, utext
);
2858 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2859 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
2864 /* Helper function for WM_CHAR
2866 * According to an MSDN blog article titled "Just because you're a control
2867 * doesn't mean that you're necessarily inside a dialog box," multiline edit
2868 * controls without ES_WANTRETURN would attempt to detect whether it is inside
2869 * a dialog box or not.
2871 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
2873 return (es
->flags
& EF_DIALOGMODE
);
2877 /*********************************************************************
2882 static void EDIT_WM_Paste(EDITSTATE
*es
)
2887 /* Protect read-only edit control from modification */
2888 if(es
->style
& ES_READONLY
)
2891 OpenClipboard(es
->hwndSelf
);
2892 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
2893 src
= GlobalLock(hsrc
);
2894 EDIT_EM_ReplaceSel(es
, TRUE
, src
, TRUE
, TRUE
);
2897 else if (es
->style
& ES_PASSWORD
) {
2898 /* clear selected text in password edit box even with empty clipboard */
2899 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
2905 /*********************************************************************
2910 static void EDIT_WM_Copy(EDITSTATE
*es
)
2912 INT s
= min(es
->selection_start
, es
->selection_end
);
2913 INT e
= max(es
->selection_start
, es
->selection_end
);
2921 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
2922 dst
= GlobalLock(hdst
);
2923 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
2924 dst
[len
] = 0; /* ensure 0 termination */
2925 TRACE("%s\n", debugstr_w(dst
));
2927 OpenClipboard(es
->hwndSelf
);
2929 SetClipboardData(CF_UNICODETEXT
, hdst
);
2934 /*********************************************************************
2939 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
2941 /* Protect read-only edit control from modification */
2942 if(es
->style
& ES_READONLY
)
2945 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
2949 /*********************************************************************
2954 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
2961 /*********************************************************************
2966 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
2970 control
= GetKeyState(VK_CONTROL
) & 0x8000;
2974 /* If it's not a multiline edit box, it would be ignored below.
2975 * For multiline edit without ES_WANTRETURN, we have to make a
2978 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
2979 if (EDIT_IsInsideDialog(es
))
2982 if (es
->style
& ES_MULTILINE
) {
2983 if (es
->style
& ES_READONLY
) {
2984 EDIT_MoveHome(es
, FALSE
, FALSE
);
2985 EDIT_MoveDown_ML(es
, FALSE
);
2987 static const WCHAR cr_lfW
[] = {'\r','\n',0};
2988 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, TRUE
, TRUE
);
2993 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
2995 static const WCHAR tabW
[] = {'\t',0};
2996 if (EDIT_IsInsideDialog(es
))
2998 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, TRUE
, TRUE
);
3002 if (!(es
->style
& ES_READONLY
) && !control
) {
3003 if (es
->selection_start
!= es
->selection_end
)
3006 /* delete character left of caret */
3007 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3008 EDIT_MoveBackward(es
, TRUE
);
3014 if (!(es
->style
& ES_PASSWORD
))
3015 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3018 if (!(es
->style
& ES_READONLY
))
3019 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3022 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3023 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3026 if (!(es
->style
& ES_READONLY
))
3027 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3031 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3032 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3035 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127)) {
3039 EDIT_EM_ReplaceSel(es
, TRUE
, str
, TRUE
, TRUE
);
3046 #if 0 // Removed see Revision 43925 comments.
3047 /*********************************************************************
3052 static void EDIT_WM_Command(EDITSTATE
*es
, INT code
, INT id
, HWND control
)
3054 if (code
|| control
)
3059 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3062 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3065 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3068 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3071 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3074 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3075 EDIT_EM_ScrollCaret(es
);
3078 ERR("unknown menu item, please report\n");
3085 /*********************************************************************
3089 * Note: the resource files resource/sysres_??.rc cannot define a
3090 * single popup menu. Hence we use a (dummy) menubar
3091 * containing the single popup menu as its first item.
3093 * FIXME: the message identifiers have been chosen arbitrarily,
3094 * hence we use MF_BYPOSITION.
3095 * We might as well use the "real" values (anybody knows ?)
3096 * The menu definition is in resources/sysres_??.rc.
3097 * Once these are OK, we better use MF_BYCOMMAND here
3098 * (as we do in EDIT_WM_Command()).
3101 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3103 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3104 HMENU popup
= GetSubMenu(menu
, 0);
3105 UINT start
= es
->selection_start
;
3106 UINT end
= es
->selection_end
;
3109 ORDER_UINT(start
, end
);
3112 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3114 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3116 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3118 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3120 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3122 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3124 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3127 /* Windows places the menu at the edit's center in this case */
3128 GetClientRect(es
->hwndSelf
, &rc
);
3129 MapWindowPoints(es
->hwndSelf
, 0, (POINT
*)&rc
, 2);
3130 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3131 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3134 if (!(es
->flags
& EF_FOCUSED
))
3135 SetFocus(es
->hwndSelf
);
3138 selectedItem
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
, x
, y
, 0, es
->hwndSelf
, NULL
);
3139 // Added see Revision 43925 comments.
3140 switch (selectedItem
) {
3142 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3145 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3148 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3151 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3154 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3157 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3158 EDIT_EM_ScrollCaret(es
);
3161 ERR("unknown menu item, please report\n");
3169 /*********************************************************************
3174 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3176 if(!count
) return 0;
3180 lstrcpynW(dst
, es
->text
, count
);
3181 return strlenW(dst
);
3185 LPSTR textA
= (LPSTR
)dst
;
3186 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3187 textA
[count
- 1] = 0; /* ensure 0 termination */
3188 return strlen(textA
);
3192 /*********************************************************************
3197 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3199 HWND hLBox
= es
->hwndListBox
;
3207 hCombo
= GetParent(es
->hwndSelf
);
3211 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3213 if (key
== VK_UP
|| key
== VK_DOWN
)
3215 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3218 if (msg
== WM_KEYDOWN
|| nEUI
)
3219 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3225 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3227 /* make sure ComboLBox pops up */
3228 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3233 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3236 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3238 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, bDropped
? FALSE
: TRUE
, 0);
3240 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3245 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3251 /*********************************************************************
3255 * Handling of special keys that don't produce a WM_CHAR
3256 * (i.e. non-printable keys) & Backspace & Delete
3259 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3264 if (GetKeyState(VK_MENU
) & 0x8000)
3267 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3268 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3273 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3278 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3279 EDIT_MoveUp_ML(es
, shift
);
3282 EDIT_MoveWordBackward(es
, shift
);
3284 EDIT_MoveBackward(es
, shift
);
3287 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3291 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3292 EDIT_MoveDown_ML(es
, shift
);
3294 EDIT_MoveWordForward(es
, shift
);
3296 EDIT_MoveForward(es
, shift
);
3299 EDIT_MoveHome(es
, shift
, control
);
3302 EDIT_MoveEnd(es
, shift
, control
);
3305 if (es
->style
& ES_MULTILINE
)
3306 EDIT_MovePageUp_ML(es
, shift
);
3308 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3311 if (es
->style
& ES_MULTILINE
)
3312 EDIT_MovePageDown_ML(es
, shift
);
3314 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3317 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3318 if (es
->selection_start
!= es
->selection_end
) {
3325 /* delete character left of caret */
3326 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3327 EDIT_MoveBackward(es
, TRUE
);
3329 } else if (control
) {
3330 /* delete to end of line */
3331 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3332 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3335 /* delete character right of caret */
3336 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3337 EDIT_MoveForward(es
, TRUE
);
3345 if (!(es
->style
& ES_READONLY
))
3351 /* If the edit doesn't want the return send a message to the default object */
3352 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3356 if (!EDIT_IsInsideDialog(es
)) break;
3358 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3359 if (HIWORD(dw
) == DC_HASDEFID
)
3361 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3364 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3365 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3371 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3372 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3375 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3376 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3383 /*********************************************************************
3388 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3390 es
->flags
&= ~EF_FOCUSED
;
3392 if(!(es
->style
& ES_NOHIDESEL
))
3393 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3394 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3399 /*********************************************************************
3403 * The caret position has been set on the WM_LBUTTONDOWN message
3406 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3409 INT e
= es
->selection_end
;
3414 es
->bCaptureState
= TRUE
;
3415 SetCapture(es
->hwndSelf
);
3417 l
= EDIT_EM_LineFromChar(es
, e
);
3418 li
= EDIT_EM_LineIndex(es
, l
);
3419 ll
= EDIT_EM_LineLength(es
, e
);
3420 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3421 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3422 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3423 EDIT_EM_ScrollCaret(es
);
3424 es
->region_posx
= es
->region_posy
= 0;
3425 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3430 /*********************************************************************
3435 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3440 es
->bCaptureState
= TRUE
;
3441 SetCapture(es
->hwndSelf
);
3442 EDIT_ConfinePoint(es
, &x
, &y
);
3443 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3444 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3445 EDIT_EM_ScrollCaret(es
);
3446 es
->region_posx
= es
->region_posy
= 0;
3447 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3449 if (!(es
->flags
& EF_FOCUSED
))
3450 SetFocus(es
->hwndSelf
);
3456 /*********************************************************************
3461 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3463 if (es
->bCaptureState
) {
3464 KillTimer(es
->hwndSelf
, 0);
3465 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3467 es
->bCaptureState
= FALSE
;
3472 /*********************************************************************
3477 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3479 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3484 /*********************************************************************
3489 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3495 /* If the mouse has been captured by process other than the edit control itself,
3496 * the windows edit controls will not select the strings with mouse move.
3498 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3502 * FIXME: gotta do some scrolling if outside client
3503 * area. Maybe reset the timer ?
3506 EDIT_ConfinePoint(es
, &x
, &y
);
3507 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3508 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3509 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3510 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3511 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3516 /*********************************************************************
3521 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3534 BOOL rev
= es
->bEnableState
&&
3535 ((es
->flags
& EF_FOCUSED
) ||
3536 (es
->style
& ES_NOHIDESEL
));
3537 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3539 GetClientRect(es
->hwndSelf
, &rcClient
);
3541 /* get the background brush */
3542 brush
= EDIT_NotifyCtlColor(es
, dc
);
3544 /* paint the border and the background */
3545 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3547 if(es
->style
& WS_BORDER
) {
3548 bw
= GetSystemMetrics(SM_CXBORDER
);
3549 bh
= GetSystemMetrics(SM_CYBORDER
);
3551 if(es
->style
& ES_MULTILINE
) {
3552 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3553 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3556 /* Draw the frame. Same code as in nonclient.c */
3557 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3558 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3559 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3560 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3561 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3562 SelectObject(dc
, old_brush
);
3564 /* Keep the border clean */
3565 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3566 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3569 GetClipBox(dc
, &rc
);
3570 FillRect(dc
, &rc
, brush
);
3572 IntersectClipRect(dc
, es
->format_rect
.left
,
3573 es
->format_rect
.top
,
3574 es
->format_rect
.right
,
3575 es
->format_rect
.bottom
);
3576 if (es
->style
& ES_MULTILINE
) {
3578 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3581 old_font
= SelectObject(dc
, es
->font
);
3583 if (!es
->bEnableState
)
3584 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3585 GetClipBox(dc
, &rcRgn
);
3586 if (es
->style
& ES_MULTILINE
) {
3587 INT vlc
= get_vertical_line_count(es
);
3588 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3589 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3590 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3591 EDIT_PaintLine(es
, dc
, i
, rev
);
3594 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3595 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3596 EDIT_PaintLine(es
, dc
, 0, rev
);
3599 SelectObject(dc
, old_font
);
3602 EndPaint(es
->hwndSelf
, &ps
);
3606 /*********************************************************************
3611 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3613 es
->flags
|= EF_FOCUSED
;
3615 if (!(es
->style
& ES_NOHIDESEL
))
3616 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3618 /* single line edit updates itself */
3619 if (!(es
->style
& ES_MULTILINE
))
3621 HDC hdc
= GetDC(es
->hwndSelf
);
3622 EDIT_WM_Paint(es
, hdc
);
3623 ReleaseDC(es
->hwndSelf
, hdc
);
3626 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3627 EDIT_SetCaretPos(es
, es
->selection_end
,
3628 es
->flags
& EF_AFTER_WRAP
);
3629 ShowCaret(es
->hwndSelf
);
3630 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3634 /*********************************************************************
3638 * With Win95 look the margins are set to default font value unless
3639 * the system font (font == 0) is being set, in which case they are left
3643 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3651 dc
= GetDC(es
->hwndSelf
);
3653 old_font
= SelectObject(dc
, font
);
3654 GetTextMetricsW(dc
, &tm
);
3655 es
->line_height
= tm
.tmHeight
;
3656 es
->char_width
= tm
.tmAveCharWidth
;
3658 SelectObject(dc
, old_font
);
3659 ReleaseDC(es
->hwndSelf
, dc
);
3661 /* Reset the format rect and the margins */
3662 GetClientRect(es
->hwndSelf
, &clientRect
);
3663 EDIT_SetRectNP(es
, &clientRect
);
3664 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3665 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3667 if (es
->style
& ES_MULTILINE
)
3668 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3670 EDIT_CalcLineWidth_SL(es
);
3673 EDIT_UpdateText(es
, NULL
, TRUE
);
3674 if (es
->flags
& EF_FOCUSED
) {
3676 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3677 EDIT_SetCaretPos(es
, es
->selection_end
,
3678 es
->flags
& EF_AFTER_WRAP
);
3679 ShowCaret(es
->hwndSelf
);
3684 /*********************************************************************
3689 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3690 * The modified flag is reset. No notifications are sent.
3692 * For single-line controls, reception of WM_SETTEXT triggers:
3693 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3696 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
3698 LPWSTR textW
= NULL
;
3699 if (!unicode
&& text
)
3701 LPCSTR textA
= (LPCSTR
)text
;
3702 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
3703 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
3705 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
3709 if (es
->flags
& EF_UPDATE
)
3710 /* fixed this bug once; complain if we see it about to happen again. */
3711 ERR("SetSel may generate UPDATE message whose handler may reset "
3714 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3717 TRACE("%s\n", debugstr_w(text
));
3718 EDIT_EM_ReplaceSel(es
, FALSE
, text
, FALSE
, FALSE
);
3720 HeapFree(GetProcessHeap(), 0, textW
);
3725 EDIT_EM_ReplaceSel(es
, FALSE
, empty_stringW
, FALSE
, FALSE
);
3728 es
->flags
&= ~EF_MODIFIED
;
3729 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3731 /* Send the notification after the selection start and end have been set
3732 * edit control doesn't send notification on WM_SETTEXT
3733 * if it is multiline, or it is part of combobox
3735 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3737 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3738 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3740 EDIT_EM_ScrollCaret(es
);
3741 EDIT_UpdateScrollInfo(es
);
3745 /*********************************************************************
3750 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
, INT width
, INT height
)
3752 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3754 TRACE("width = %d, height = %d\n", width
, height
);
3755 SetRect(&rc
, 0, 0, width
, height
);
3756 EDIT_SetRectNP(es
, &rc
);
3757 EDIT_UpdateText(es
, NULL
, TRUE
);
3762 /*********************************************************************
3766 * This message is sent by SetWindowLong on having changed either the Style
3767 * or the extended style.
3769 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3771 * See also EDIT_WM_NCCreate
3773 * It appears that the Windows version of the edit control allows the style
3774 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3775 * style variable which will generally be different. In this function we
3776 * update the internal style based on what changed in the externally visible
3779 * Much of this content as based upon the MSDN, especially:
3780 * Platform SDK Documentation -> User Interface Services ->
3781 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3782 * Edit Control Styles
3784 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3786 if (GWL_STYLE
== which
) {
3787 DWORD style_change_mask
;
3789 /* Only a subset of changes can be applied after the control
3792 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3794 if (es
->style
& ES_MULTILINE
)
3795 style_change_mask
|= ES_WANTRETURN
;
3797 new_style
= style
->styleNew
& style_change_mask
;
3799 /* Number overrides lowercase overrides uppercase (at least it
3800 * does in Win95). However I'll bet that ES_NUMBER would be
3801 * invalid under Win 3.1.
3803 if (new_style
& ES_NUMBER
) {
3804 ; /* do not override the ES_NUMBER */
3805 } else if (new_style
& ES_LOWERCASE
) {
3806 new_style
&= ~ES_UPPERCASE
;
3809 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3810 } else if (GWL_EXSTYLE
== which
) {
3811 ; /* FIXME - what is needed here */
3813 WARN ("Invalid style change %ld\n",which
);
3819 /*********************************************************************
3824 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3826 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3827 if (EDIT_EM_CanUndo(es
))
3830 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3831 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3834 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3838 /*********************************************************************
3843 static void EDIT_WM_Timer(EDITSTATE
*es
)
3845 if (es
->region_posx
< 0) {
3846 EDIT_MoveBackward(es
, TRUE
);
3847 } else if (es
->region_posx
> 0) {
3848 EDIT_MoveForward(es
, TRUE
);
3851 * FIXME: gotta do some vertical scrolling here, like
3852 * EDIT_EM_LineScroll(hwnd, 0, 1);
3856 /*********************************************************************
3861 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3866 if (!(es
->style
& ES_MULTILINE
))
3869 if (!(es
->style
& ES_AUTOHSCROLL
))
3873 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3876 TRACE("SB_LINELEFT\n");
3878 dx
= -es
->char_width
;
3881 TRACE("SB_LINERIGHT\n");
3882 if (es
->x_offset
< es
->text_width
)
3883 dx
= es
->char_width
;
3886 TRACE("SB_PAGELEFT\n");
3888 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3891 TRACE("SB_PAGERIGHT\n");
3892 if (es
->x_offset
< es
->text_width
)
3893 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3901 TRACE("SB_RIGHT\n");
3902 if (es
->x_offset
< es
->text_width
)
3903 dx
= es
->text_width
- es
->x_offset
;
3906 TRACE("SB_THUMBTRACK %d\n", pos
);
3907 es
->flags
|= EF_HSCROLL_TRACK
;
3908 if(es
->style
& WS_HSCROLL
)
3909 dx
= pos
- es
->x_offset
;
3914 if(pos
< 0 || pos
> 100) return 0;
3915 /* Assume default scroll range 0-100 */
3916 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3917 new_x
= pos
* (es
->text_width
- fw
) / 100;
3918 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3921 case SB_THUMBPOSITION
:
3922 TRACE("SB_THUMBPOSITION %d\n", pos
);
3923 es
->flags
&= ~EF_HSCROLL_TRACK
;
3924 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3925 dx
= pos
- es
->x_offset
;
3930 if(pos
< 0 || pos
> 100) return 0;
3931 /* Assume default scroll range 0-100 */
3932 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3933 new_x
= pos
* (es
->text_width
- fw
) / 100;
3934 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3937 /* force scroll info update */
3938 EDIT_UpdateScrollInfo(es
);
3939 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3943 TRACE("SB_ENDSCROLL\n");
3946 * FIXME : the next two are undocumented !
3947 * Are we doing the right thing ?
3948 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3949 * although it's also a regular control message.
3951 case EM_GETTHUMB
: /* this one is used by NT notepad */
3954 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3955 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3958 /* Assume default scroll range 0-100 */
3959 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3960 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3962 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
3966 TRACE("EM_LINESCROLL16\n");
3971 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
3977 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3978 /* check if we are going to move too far */
3979 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
3980 dx
= es
->text_width
- fw
- es
->x_offset
;
3982 EDIT_EM_LineScroll_internal(es
, dx
, 0);
3988 /*********************************************************************
3993 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
3997 if (!(es
->style
& ES_MULTILINE
))
4000 if (!(es
->style
& ES_AUTOVSCROLL
))
4009 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4010 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4011 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4013 EDIT_EM_Scroll(es
, action
);
4020 TRACE("SB_BOTTOM\n");
4021 dy
= es
->line_count
- 1 - es
->y_offset
;
4024 TRACE("SB_THUMBTRACK %d\n", pos
);
4025 es
->flags
|= EF_VSCROLL_TRACK
;
4026 if(es
->style
& WS_VSCROLL
)
4027 dy
= pos
- es
->y_offset
;
4030 /* Assume default scroll range 0-100 */
4033 if(pos
< 0 || pos
> 100) return 0;
4034 vlc
= get_vertical_line_count(es
);
4035 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4036 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4037 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4038 es
->line_count
, es
->y_offset
, pos
, dy
);
4041 case SB_THUMBPOSITION
:
4042 TRACE("SB_THUMBPOSITION %d\n", pos
);
4043 es
->flags
&= ~EF_VSCROLL_TRACK
;
4044 if(es
->style
& WS_VSCROLL
)
4045 dy
= pos
- es
->y_offset
;
4048 /* Assume default scroll range 0-100 */
4051 if(pos
< 0 || pos
> 100) return 0;
4052 vlc
= get_vertical_line_count(es
);
4053 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4054 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4055 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4056 es
->line_count
, es
->y_offset
, pos
, dy
);
4060 /* force scroll info update */
4061 EDIT_UpdateScrollInfo(es
);
4062 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4066 TRACE("SB_ENDSCROLL\n");
4069 * FIXME : the next two are undocumented !
4070 * Are we doing the right thing ?
4071 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4072 * although it's also a regular control message.
4074 case EM_GETTHUMB
: /* this one is used by NT notepad */
4077 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4078 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4081 /* Assume default scroll range 0-100 */
4082 INT vlc
= get_vertical_line_count(es
);
4083 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4085 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4089 TRACE("EM_LINESCROLL %d\n", pos
);
4094 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4099 EDIT_EM_LineScroll(es
, 0, dy
);
4103 /*********************************************************************
4107 * FIXME: is this right ? (or should it be only VSCROLL)
4108 * (and maybe only for edit controls that really have their
4109 * own scrollbars) (and maybe only for multiline controls ?)
4110 * All in all: very poorly documented
4113 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4115 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4116 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4120 /********************************************************************
4122 * The Following code is to handle inline editing from IMEs
4125 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4128 LPWSTR lpCompStr
= NULL
;
4129 LPSTR lpCompStrAttr
= NULL
;
4132 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4139 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
+ sizeof(WCHAR
));
4142 ERR("Unable to allocate IME CompositionString\n");
4147 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4148 lpCompStr
[buflen
/sizeof(WCHAR
)] = 0;
4150 if (CompFlag
& GCS_COMPATTR
)
4153 * We do not use the attributes yet. it would tell us what characters
4154 * are in transition and which are converted or decided upon
4156 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4160 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4163 ERR("Unable to allocate IME Attribute String\n");
4164 HeapFree(GetProcessHeap(),0,lpCompStr
);
4167 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4169 lpCompStrAttr
[dwBufLenAttr
] = 0;
4172 lpCompStrAttr
= NULL
;
4175 /* check for change in composition start */
4176 if (es
->selection_end
< es
->composition_start
)
4177 es
->composition_start
= es
->selection_end
;
4179 /* replace existing selection string */
4180 es
->selection_start
= es
->composition_start
;
4182 if (es
->composition_len
> 0)
4183 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4185 es
->selection_end
= es
->selection_start
;
4187 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, TRUE
, TRUE
);
4188 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4190 es
->selection_start
= es
->composition_start
;
4191 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4193 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4194 HeapFree(GetProcessHeap(),0,lpCompStr
);
4197 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4202 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4208 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
+sizeof(WCHAR
));
4211 ERR("Unable to alloc buffer for IME string\n");
4215 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4216 lpResultStr
[buflen
/sizeof(WCHAR
)] = 0;
4218 /* check for change in composition start */
4219 if (es
->selection_end
< es
->composition_start
)
4220 es
->composition_start
= es
->selection_end
;
4222 es
->selection_start
= es
->composition_start
;
4223 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4224 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, TRUE
, TRUE
);
4225 es
->composition_start
= es
->selection_end
;
4226 es
->composition_len
= 0;
4228 HeapFree(GetProcessHeap(),0,lpResultStr
);
4231 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4236 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4238 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4239 es
->composition_start
= es
->selection_end
;
4242 hIMC
= ImmGetContext(hwnd
);
4246 if (CompFlag
& GCS_RESULTSTR
)
4247 EDIT_GetResultStr(hIMC
, es
);
4248 if (CompFlag
& GCS_COMPSTR
)
4249 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4250 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4251 ImmReleaseContext(hwnd
, hIMC
);
4252 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4256 /*********************************************************************
4260 * See also EDIT_WM_StyleChanged
4262 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4267 TRACE("Creating %s edit control, style = %08x\n",
4268 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4270 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4272 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4275 * Note: since the EDITSTATE has not been fully initialized yet,
4276 * we can't use any API calls that may send
4277 * WM_XXX messages before WM_NCCREATE is completed.
4280 es
->is_unicode
= unicode
;
4281 es
->style
= lpcs
->style
;
4283 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4285 es
->hwndSelf
= hwnd
;
4286 /* Save parent, which will be notified by EN_* messages */
4287 es
->hwndParent
= lpcs
->hwndParent
;
4289 if (es
->style
& ES_COMBO
)
4290 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4292 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4293 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4295 /* Number overrides lowercase overrides uppercase (at least it
4296 * does in Win95). However I'll bet that ES_NUMBER would be
4297 * invalid under Win 3.1.
4299 if (es
->style
& ES_NUMBER
) {
4300 ; /* do not override the ES_NUMBER */
4301 } else if (es
->style
& ES_LOWERCASE
) {
4302 es
->style
&= ~ES_UPPERCASE
;
4304 if (es
->style
& ES_MULTILINE
) {
4305 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4306 if (es
->style
& WS_VSCROLL
)
4307 es
->style
|= ES_AUTOVSCROLL
;
4308 if (es
->style
& WS_HSCROLL
)
4309 es
->style
|= ES_AUTOHSCROLL
;
4310 es
->style
&= ~ES_PASSWORD
;
4311 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4312 /* Confirmed - RIGHT overrides CENTER */
4313 if (es
->style
& ES_RIGHT
)
4314 es
->style
&= ~ES_CENTER
;
4315 es
->style
&= ~WS_HSCROLL
;
4316 es
->style
&= ~ES_AUTOHSCROLL
;
4319 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4320 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4321 es
->style
&= ~ES_CENTER
;
4322 es
->style
&= ~WS_HSCROLL
;
4323 es
->style
&= ~WS_VSCROLL
;
4324 if (es
->style
& ES_PASSWORD
)
4325 es
->password_char
= '*';
4328 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4329 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4331 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4333 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4335 es
->undo_buffer_size
= es
->buffer_size
;
4337 if (es
->style
& ES_MULTILINE
)
4338 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4343 * In Win95 look and feel, the WS_BORDER style is replaced by the
4344 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4345 * control a nonclient area so we don't need to draw the border.
4346 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4347 * a nonclient area and we should handle painting the border ourselves.
4349 * When making modifications please ensure that the code still works
4350 * for edit controls created directly with style 0x50800000, exStyle 0
4351 * (which should have a single pixel border)
4353 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4354 es
->style
&= ~WS_BORDER
;
4355 else if (es
->style
& WS_BORDER
)
4356 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4361 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4362 HeapFree(GetProcessHeap(), 0, es
->first_line_def
);
4363 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4364 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4365 HeapFree(GetProcessHeap(), 0, es
);
4370 /*********************************************************************
4375 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4379 TRACE("%s\n", debugstr_w(name
));
4381 * To initialize some final structure members, we call some helper
4382 * functions. However, since the EDITSTATE is not consistent (i.e.
4383 * not fully initialized), we should be very careful which
4384 * functions can be called, and in what order.
4386 EDIT_WM_SetFont(es
, 0, FALSE
);
4387 EDIT_EM_EmptyUndoBuffer(es
);
4389 /* We need to calculate the format rect
4390 (applications may send EM_SETMARGINS before the control gets visible) */
4391 GetClientRect(es
->hwndSelf
, &clientRect
);
4392 EDIT_SetRectNP(es
, &clientRect
);
4394 if (name
&& *name
) {
4395 EDIT_EM_ReplaceSel(es
, FALSE
, name
, FALSE
, FALSE
);
4396 /* if we insert text to the editline, the text scrolls out
4397 * of the window, as the caret is placed after the insert
4398 * pos normally; thus we reset es->selection... to 0 and
4401 es
->selection_start
= es
->selection_end
= 0;
4402 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4403 * Messages are only to be sent when the USER does something to
4404 * change the contents. So I am removing this EN_CHANGE
4406 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4408 EDIT_EM_ScrollCaret(es
);
4410 /* force scroll info update */
4411 EDIT_UpdateScrollInfo(es
);
4412 /* The rule seems to return 1 here for success */
4413 /* Power Builder masked edit controls will crash */
4415 /* FIXME: is that in all cases so ? */
4420 /*********************************************************************
4425 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4430 LocalFree(es
->hloc32W
);
4433 LocalFree(es
->hloc32A
);
4435 pc
= es
->first_line_def
;
4439 HeapFree(GetProcessHeap(), 0, pc
);
4443 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4444 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4445 HeapFree(GetProcessHeap(), 0, es
);
4451 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4454 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4456 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4459 /*********************************************************************
4461 * EditWndProc_common
4463 * The messages are in the order of the actual integer values
4464 * (which can be found in include/windows.h)
4466 LRESULT WINAPI
EditWndProc_common( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4468 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4473 pWnd
= ValidateHwnd(hwnd
);
4478 NtUserSetWindowFNID(hwnd
, FNID_EDIT
);
4483 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4485 if (!es
&& msg
!= WM_NCCREATE
)
4486 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4488 if (es
&& (msg
!= WM_NCDESTROY
)) EDIT_LockBuffer(es
);
4492 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4496 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4497 EDIT_EM_ScrollCaret(es
);
4503 CopyRect((LPRECT
)lParam
, &es
->format_rect
);
4507 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4508 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4509 EDIT_UpdateText(es
, NULL
, TRUE
);
4514 if ((es
->style
& ES_MULTILINE
) && lParam
)
4515 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4519 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4523 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4526 case EM_SCROLLCARET
:
4527 EDIT_EM_ScrollCaret(es
);
4532 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4537 es
->flags
|= EF_MODIFIED
;
4539 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4542 case EM_GETLINECOUNT
:
4543 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4547 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4551 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4555 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4559 result
= EDIT_EM_GetThumb(es
);
4562 /* these messages missing from specs */
4567 FIXME("undocumented message 0x%x, please report\n", msg
);
4568 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4572 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4580 textW
= (LPWSTR
)lParam
;
4583 LPSTR textA
= (LPSTR
)lParam
;
4584 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4585 if (!(textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
)))) break;
4586 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4589 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, TRUE
, TRUE
);
4593 HeapFree(GetProcessHeap(), 0, textW
);
4598 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
4601 case EM_SETLIMITTEXT
:
4602 EDIT_EM_SetLimitText(es
, wParam
);
4606 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4611 result
= (LRESULT
)EDIT_EM_Undo(es
);
4615 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4618 case EM_LINEFROMCHAR
:
4619 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4622 case EM_SETTABSTOPS
:
4623 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4626 case EM_SETPASSWORDCHAR
:
4631 charW
= (WCHAR
)wParam
;
4634 CHAR charA
= wParam
;
4635 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
4638 EDIT_EM_SetPasswordChar(es
, charW
);
4642 case EM_EMPTYUNDOBUFFER
:
4643 EDIT_EM_EmptyUndoBuffer(es
);
4646 case EM_GETFIRSTVISIBLELINE
:
4647 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4650 case EM_SETREADONLY
:
4652 DWORD old_style
= es
->style
;
4655 SetWindowLongW( hwnd
, GWL_STYLE
,
4656 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
4657 es
->style
|= ES_READONLY
;
4659 SetWindowLongW( hwnd
, GWL_STYLE
,
4660 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4661 es
->style
&= ~ES_READONLY
;
4664 if (old_style
^ es
->style
)
4665 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4671 case EM_SETWORDBREAKPROC
:
4672 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4675 case EM_GETWORDBREAKPROC
:
4676 result
= (LRESULT
)es
->word_break_proc
;
4679 case EM_GETPASSWORDCHAR
:
4682 result
= es
->password_char
;
4685 WCHAR charW
= es
->password_char
;
4687 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
4694 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4698 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4701 case EM_GETLIMITTEXT
:
4702 result
= es
->buffer_limit
;
4705 case EM_POSFROMCHAR
:
4706 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4707 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4710 case EM_CHARFROMPOS
:
4711 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4714 /* End of the EM_ messages which were in numerical order; what order
4715 * are these in? vaguely alphabetical?
4719 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
4723 result
= EDIT_WM_NCDestroy(es
);
4724 // es = NULL; reactos
4726 NtUserSetWindowFNID(hwnd
, FNID_DESTROY
);
4731 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4733 if (es
->style
& ES_MULTILINE
)
4734 result
|= DLGC_WANTALLKEYS
;
4738 es
->flags
|=EF_DIALOGMODE
;
4740 if (((LPMSG
)lParam
)->message
== WM_KEYDOWN
)
4742 int vk
= (int)((LPMSG
)lParam
)->wParam
;
4744 if (es
->hwndListBox
)
4746 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4747 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4748 result
|= DLGC_WANTMESSAGE
;
4760 strng
[0] = wParam
>> 8;
4761 strng
[1] = wParam
& 0xff;
4762 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
4763 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
4764 result
= EDIT_WM_Char(es
, charW
);
4776 CHAR charA
= wParam
;
4777 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
4780 if (es
->hwndListBox
)
4782 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4784 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4785 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4789 result
= EDIT_WM_Char(es
, charW
);
4796 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4797 if (wParam
<= 0x000fffff)
4799 if(wParam
> 0xffff) /* convert to surrogates */
4802 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4803 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4805 else EDIT_WM_Char(es
, wParam
);
4814 #if 0 // Removed see Revision 43925 comments.
4816 EDIT_WM_Command(es
, HIWORD(wParam
), LOWORD(wParam
), (HWND
)lParam
);
4819 case WM_CONTEXTMENU
:
4820 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4829 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4832 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
4833 LPWSTR nameW
= NULL
;
4836 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
4837 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4838 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
4840 result
= EDIT_WM_Create(es
, nameW
);
4841 HeapFree(GetProcessHeap(), 0, nameW
);
4850 es
->bEnableState
= (BOOL
) wParam
;
4851 EDIT_UpdateText(es
, NULL
, TRUE
);
4855 /* we do the proper erase in EDIT_WM_Paint */
4860 result
= (LRESULT
)es
->font
;
4864 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
4867 case WM_GETTEXTLENGTH
:
4868 if (unicode
) result
= get_text_length(es
);
4869 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
4870 NULL
, 0, NULL
, NULL
);
4874 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4878 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4882 result
= EDIT_WM_KillFocus(es
);
4885 case WM_LBUTTONDBLCLK
:
4886 result
= EDIT_WM_LButtonDblClk(es
);
4889 case WM_LBUTTONDOWN
:
4890 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4894 result
= EDIT_WM_LButtonUp(es
);
4897 case WM_MBUTTONDOWN
:
4898 result
= EDIT_WM_MButtonDown(es
);
4902 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4905 case WM_PRINTCLIENT
:
4907 EDIT_WM_Paint(es
, (HDC
)wParam
);
4915 EDIT_WM_SetFocus(es
);
4919 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4923 /* FIXME: actually set an internal flag and behave accordingly */
4927 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
4932 EDIT_WM_Size(es
, (UINT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
4935 case WM_STYLECHANGED
:
4936 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4939 case WM_STYLECHANGING
:
4940 result
= 0; /* See EDIT_WM_StyleChanged */
4944 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
4952 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4957 int gcWheelDelta
= 0;
4958 UINT pulScrollLines
= 3;
4959 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4961 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
4962 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4965 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
4966 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
4968 int cLineScroll
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
4969 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
4970 result
= EDIT_EM_LineScroll(es
, 0, cLineScroll
);
4976 /* IME messages to make the edit control IME aware */
4977 case WM_IME_SETCONTEXT
:
4980 case WM_IME_STARTCOMPOSITION
:
4981 es
->composition_start
= es
->selection_end
;
4982 es
->composition_len
= 0;
4985 case WM_IME_COMPOSITION
:
4986 EDIT_ImeComposition(hwnd
, lParam
, es
);
4989 case WM_IME_ENDCOMPOSITION
:
4990 if (es
->composition_len
> 0)
4992 EDIT_EM_ReplaceSel(es
, TRUE
, empty_stringW
, TRUE
, TRUE
);
4993 es
->selection_end
= es
->selection_start
;
4994 es
->composition_len
= 0;
4998 case WM_IME_COMPOSITIONFULL
:
5004 case WM_IME_CONTROL
:
5008 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5012 /* reactos: check GetWindowLong in case es has been destroyed during processing */
5013 if (IsWindow(hwnd
) && es
&& GetWindowLongPtrW(hwnd
, 0))
5014 EDIT_UnlockBuffer(es
, FALSE
);
5016 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5021 /*********************************************************************
5023 * EditWndProc (USER32.@)
5025 LRESULT WINAPI
EditWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5027 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
5030 /*********************************************************************
5032 * EditWndProcW (USER32.@)
5034 LRESULT WINAPI
EditWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5036 return EditWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
5039 /*********************************************************************
5040 * edit class descriptor
5042 static const WCHAR editW
[] = {'E','d','i','t',0};
5043 const struct builtin_class_descr EDIT_builtin_class
=
5046 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5047 EditWndProcA
, /* procA */
5048 EditWndProcW
, /* procW */
5050 sizeof(EDITSTATE
*) + sizeof(WORD
), /* extra */
5052 sizeof(EDITSTATE
*), /* extra */
5054 IDC_IBEAM
, /* cursor */