4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
7 * Copyright Frank Richter, 2005
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * - EDITBALLOONTIP structure
26 * - EM_GETCUEBANNER/Edit_GetCueBannerText
27 * - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
28 * - EM_SETCUEBANNER/Edit_SetCueBannerText
29 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
30 * - EM_GETIMESTATUS, EM_SETIMESTATUS
51 #include "wine/unicode.h"
52 #include "wine/debug.h"
53 #include "wine/heap.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
57 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
58 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
59 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
60 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
63 * extra flags for EDITSTATE.flags field
65 #define EF_MODIFIED 0x0001 /* text has been modified */
66 #define EF_FOCUSED 0x0002 /* we have input focus */
67 #define EF_UPDATE 0x0004 /* notify parent of changed state */
68 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
69 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
70 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
71 wrapped line, instead of in front of the next character */
72 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
73 #define EF_DIALOGMODE 0x0200 /* Indicates that we are inside a dialog window */
75 #define ID_CB_LISTBOX 1000
79 END_0
= 0, /* line ends with terminating '\0' character */
80 END_WRAP
, /* line is wrapped */
81 END_HARD
, /* line ends with a hard return '\r\n' */
82 END_SOFT
, /* line ends with a soft return '\r\r\n' */
83 END_RICH
/* line ends with a single '\n' */
86 typedef struct tagLINEDEF
{
87 INT length
; /* bruto length of a line in bytes */
88 INT net_length
; /* netto length of a line in visible characters */
90 INT width
; /* width of the line in pixels */
91 INT index
; /* line index into the buffer */
92 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data */
93 struct tagLINEDEF
*next
;
98 LPWSTR text
; /* the actual contents of the control */
99 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
100 UINT buffer_size
; /* the size of the buffer in characters */
101 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
102 HFONT font
; /* NULL means standard system font */
103 INT x_offset
; /* scroll offset for multi lines this is in pixels
104 for single lines it's in characters */
105 INT line_height
; /* height of a screen line in pixels */
106 INT char_width
; /* average character width in pixels */
107 DWORD style
; /* sane version of wnd->dwStyle */
108 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
109 INT undo_insert_count
; /* number of characters inserted in sequence */
110 UINT undo_position
; /* character index of the insertion and deletion */
111 LPWSTR undo_text
; /* deleted text */
112 UINT undo_buffer_size
; /* size of the deleted text buffer */
113 INT selection_start
; /* == selection_end if no selection */
114 INT selection_end
; /* == current caret position */
115 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
116 INT left_margin
; /* in pixels */
117 INT right_margin
; /* in pixels */
119 INT text_width
; /* width of the widest line in pixels for multi line controls
120 and just line width for single line controls */
121 INT region_posx
; /* Position of cursor relative to region: */
122 INT region_posy
; /* -1: to left, 0: within, 1: to right */
123 EDITWORDBREAKPROCW word_break_proc
;
124 INT line_count
; /* number of lines */
125 INT y_offset
; /* scroll offset in number of lines */
126 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
127 BOOL bEnableState
; /* flag keeping the enable state */
128 HWND hwndSelf
; /* the our window handle */
129 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
130 Even if parent will change, EN_* messages
131 should be sent to the first parent. */
132 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
133 INT wheelDeltaRemainder
; /* scroll wheel delta left over after scrolling whole lines */
135 * only for multi line controls
137 INT lock_count
; /* amount of re-entries in the EditWndProc */
140 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
141 HLOCAL hloc32W
; /* our unicode local memory block */
142 HLOCAL hlocapp
; /* The text buffer handle belongs to the app */
146 UINT composition_len
; /* length of composition, 0 == no composition */
147 int composition_start
; /* the character position for the composition */
151 SCRIPT_LOGATTR
*logAttr
;
152 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data for single line controls */
156 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
157 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
159 /* used for disabled or read-only edit control */
160 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
162 { /* Notify parent which has created this edit control */ \
163 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
164 SendMessageW(es->hwndParent, WM_COMMAND, \
165 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
166 (LPARAM)(es->hwndSelf)); \
169 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
171 /*********************************************************************
176 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
178 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
182 /*********************************************************************
187 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
189 es
->undo_insert_count
= 0;
190 *es
->undo_text
= '\0';
193 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
198 if ((!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
199 msg
= WM_CTLCOLORSTATIC
;
201 msg
= WM_CTLCOLOREDIT
;
203 /* Why do we notify to es->hwndParent, and we send this one to GetParent()? */
204 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
206 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
211 static inline UINT
get_text_length(EDITSTATE
*es
)
213 if(es
->text_length
== (UINT
)-1)
214 es
->text_length
= strlenW(es
->text
);
215 return es
->text_length
;
219 /*********************************************************************
223 * Find the beginning of words.
224 * Note: unlike the specs for a WordBreakProc, this function can
225 * only be called without linebreaks between s[0] up to
226 * s[count - 1]. Remember it is only called
227 * internally, so we can decide this for ourselves.
228 * Additionally we will always be breaking the full string.
231 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
235 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
243 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
244 psa
.eScript
= SCRIPT_UNDEFINED
;
246 es
->logAttr
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
247 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
254 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
261 while (index
< count
&& s
[index
] && !es
->logAttr
[index
].fSoftBreak
)
266 ret
= es
->logAttr
[index
].fWhiteSpace
;
269 ERR("unknown action code, please report !\n");
276 /*********************************************************************
278 * EDIT_CallWordBreakProc
280 * Call appropriate WordBreakProc (internal or external).
282 * Note: The "start" argument should always be an index referring
283 * to es->text. The actual wordbreak proc might be
284 * 16 bit, so we can't always pass any 32 bit LPSTR.
285 * Hence we assume that es->text is the buffer that holds
286 * the string under examination (we can decide this for ourselves).
289 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
293 if (es
->word_break_proc
)
294 ret
= es
->word_break_proc(es
->text
+ start
, index
, count
, action
);
296 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+ start
, count
+ start
, action
) - start
;
301 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
305 ScriptStringFree(&line_def
->ssa
);
306 line_def
->ssa
= NULL
;
310 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
312 LINEDEF
*line_def
= es
->first_line_def
;
315 EDIT_InvalidateUniscribeData_linedef(line_def
);
316 line_def
= line_def
->next
;
320 ScriptStringFree(&es
->ssa
);
325 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
330 if (line_def
->net_length
&& !line_def
->ssa
)
332 int index
= line_def
->index
;
333 HFONT old_font
= NULL
;
335 SCRIPT_TABDEF tabdef
;
339 udc
= GetDC(es
->hwndSelf
);
341 old_font
= SelectObject(udc
, es
->font
);
343 tabdef
.cTabStops
= es
->tabs_count
;
344 tabdef
.iScale
= GdiGetCharDimensions(udc
, NULL
, NULL
);
345 tabdef
.pTabStops
= es
->tabs
;
346 tabdef
.iTabOrigin
= 0;
348 hr
= ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
,
349 (1.5*line_def
->net_length
+16), -1,
350 SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1,
351 NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
354 WARN("ScriptStringAnalyse failed (%x)\n",hr
);
355 line_def
->ssa
= NULL
;
359 SelectObject(udc
, old_font
);
361 ReleaseDC(es
->hwndSelf
, udc
);
364 return line_def
->ssa
;
367 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
371 if (!(es
->style
& ES_MULTILINE
))
375 INT length
= get_text_length(es
);
376 HFONT old_font
= NULL
;
380 udc
= GetDC(es
->hwndSelf
);
382 old_font
= SelectObject(udc
, es
->font
);
384 if (es
->style
& ES_PASSWORD
)
385 ScriptStringAnalyse(udc
, &es
->password_char
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_PASSWORD
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
387 ScriptStringAnalyse(udc
, es
->text
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
390 SelectObject(udc
, old_font
);
392 ReleaseDC(es
->hwndSelf
, udc
);
398 line_def
= es
->first_line_def
;
399 while (line_def
&& line
)
401 line_def
= line_def
->next
;
405 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
409 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
411 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
415 /*********************************************************************
417 * EDIT_BuildLineDefs_ML
419 * Build linked list of text lines.
420 * Lines can end with '\0' (last line), a character (if it is wrapped),
421 * a soft return '\r\r\n' or a hard return '\r\n'
424 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
426 LPWSTR current_position
, cp
;
428 LINEDEF
*current_line
;
429 LINEDEF
*previous_line
;
431 INT line_index
= 0, nstart_line
, nstart_index
;
432 INT line_count
= es
->line_count
;
437 if (istart
== iend
&& delta
== 0)
440 previous_line
= NULL
;
441 current_line
= es
->first_line_def
;
443 /* Find starting line. istart must lie inside an existing line or
444 * at the end of buffer */
446 if (istart
< current_line
->index
+ current_line
->length
||
447 current_line
->ending
== END_0
)
450 previous_line
= current_line
;
451 current_line
= current_line
->next
;
453 } while (current_line
);
455 if (!current_line
) /* Error occurred start is not inside previous buffer */
457 FIXME(" modification occurred outside buffer\n");
461 /* Remember start of modifications in order to calculate update region */
462 nstart_line
= line_index
;
463 nstart_index
= current_line
->index
;
465 /* We must start to reformat from the previous line since the modifications
466 * may have caused the line to wrap upwards. */
467 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
470 current_line
= previous_line
;
472 start_line
= current_line
;
474 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
475 current_position
= es
->text
+ current_line
->index
;
476 vlc
= get_vertical_line_count(es
);
478 if (current_line
!= start_line
)
480 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
482 /* The buffer has been expanded, create a new line and
483 insert it into the link list */
484 LINEDEF
*new_line
= heap_alloc_zero(sizeof(*new_line
));
485 new_line
->next
= previous_line
->next
;
486 previous_line
->next
= new_line
;
487 current_line
= new_line
;
490 else if (current_line
->index
+ delta
< current_position
- es
->text
)
492 /* The previous line merged with this line so we delete this extra entry */
493 previous_line
->next
= current_line
->next
;
494 heap_free(current_line
);
495 current_line
= previous_line
->next
;
499 else /* current_line->index + delta == current_position */
501 if (current_position
- es
->text
> iend
)
502 break; /* We reached end of line modifications */
503 /* else recalculate this line */
507 current_line
->index
= current_position
- es
->text
;
508 orig_net_length
= current_line
->net_length
;
510 /* Find end of line */
511 cp
= current_position
;
513 if (*cp
== '\n') break;
514 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
519 /* Mark type of line termination */
521 current_line
->ending
= END_0
;
522 current_line
->net_length
= strlenW(current_position
);
523 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
524 current_line
->ending
= END_SOFT
;
525 current_line
->net_length
= cp
- current_position
- 1;
526 } else if (*cp
== '\n') {
527 current_line
->ending
= END_RICH
;
528 current_line
->net_length
= cp
- current_position
;
530 current_line
->ending
= END_HARD
;
531 current_line
->net_length
= cp
- current_position
;
534 if (current_line
->net_length
)
537 EDIT_InvalidateUniscribeData_linedef(current_line
);
538 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
539 if (current_line
->ssa
)
541 sz
= ScriptString_pSize(current_line
->ssa
);
542 /* Calculate line width */
543 current_line
->width
= sz
->cx
;
545 else current_line
->width
= es
->char_width
* current_line
->net_length
;
547 else current_line
->width
= 0;
549 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
551 /* Line breaks just look back from the end and find the next break and try that. */
553 if (!(es
->style
& ES_AUTOHSCROLL
)) {
554 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
561 prev
= current_line
->net_length
- 1;
562 w
= current_line
->net_length
;
563 d
= (float)current_line
->width
/(float)fw
;
564 if (d
> 1.2f
) d
-= 0.2f
;
566 if (next
>= prev
) next
= prev
-1;
568 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
569 next
, current_line
->net_length
, WB_LEFT
);
570 current_line
->net_length
= prev
;
571 EDIT_InvalidateUniscribeData_linedef(current_line
);
572 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
573 if (current_line
->ssa
)
574 sz
= ScriptString_pSize(current_line
->ssa
);
577 current_line
->width
= sz
->cx
;
581 } while (prev
&& current_line
->width
> fw
);
582 current_line
->net_length
= w
;
584 if (prev
== 0) { /* Didn't find a line break so force a break */
588 EDIT_InvalidateUniscribeData_linedef(current_line
);
589 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
591 if (current_line
->ssa
)
593 count
= ScriptString_pcOutChars(current_line
->ssa
);
594 piDx
= heap_alloc(sizeof(INT
) * (*count
));
595 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
597 prev
= current_line
->net_length
-1;
599 current_line
->width
-= piDx
[prev
];
601 } while ( prev
> 0 && current_line
->width
> fw
);
607 prev
= (fw
/ es
->char_width
);
610 /* If the first line we are calculating, wrapped before istart, we must
611 * adjust istart in order for this to be reflected in the update region. */
612 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
613 istart
= current_line
->index
+ prev
;
614 /* else if we are updating the previous line before the first line we
615 * are re-calculating and it expanded */
616 else if (current_line
== start_line
&&
617 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
619 /* Line expanded due to an upwards line wrap so we must partially include
620 * previous line in update region */
621 nstart_line
= line_index
;
622 nstart_index
= current_line
->index
;
623 istart
= current_line
->index
+ orig_net_length
;
626 current_line
->net_length
= prev
;
627 current_line
->ending
= END_WRAP
;
629 if (current_line
->net_length
> 0)
631 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
632 if (current_line
->ssa
)
634 sz
= ScriptString_pSize(current_line
->ssa
);
635 current_line
->width
= sz
->cx
;
638 current_line
->width
= 0;
640 else current_line
->width
= 0;
642 else if (current_line
== start_line
&&
643 current_line
->index
!= nstart_index
&&
644 orig_net_length
< current_line
->net_length
) {
645 /* The previous line expanded but it's still not as wide as the client rect */
646 /* The expansion is due to an upwards line wrap so we must partially include
647 it in the update region */
648 nstart_line
= line_index
;
649 nstart_index
= current_line
->index
;
650 istart
= current_line
->index
+ orig_net_length
;
655 /* Adjust length to include line termination */
656 switch (current_line
->ending
) {
658 current_line
->length
= current_line
->net_length
+ 3;
661 current_line
->length
= current_line
->net_length
+ 1;
664 current_line
->length
= current_line
->net_length
+ 2;
668 current_line
->length
= current_line
->net_length
;
671 es
->text_width
= max(es
->text_width
, current_line
->width
);
672 current_position
+= current_line
->length
;
673 previous_line
= current_line
;
675 /* Discard data for non-visible lines. It will be calculated as needed */
676 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
677 EDIT_InvalidateUniscribeData_linedef(current_line
);
679 current_line
= current_line
->next
;
681 } while (previous_line
->ending
!= END_0
);
683 /* Finish adjusting line indexes by delta or remove hanging lines */
684 if (previous_line
->ending
== END_0
)
686 LINEDEF
*pnext
= NULL
;
688 previous_line
->next
= NULL
;
691 pnext
= current_line
->next
;
692 EDIT_InvalidateUniscribeData_linedef(current_line
);
693 heap_free(current_line
);
694 current_line
= pnext
;
702 current_line
->index
+= delta
;
703 current_line
= current_line
->next
;
707 /* Calculate rest of modification rectangle */
712 * We calculate two rectangles. One for the first line which may have
713 * an indent with respect to the format rect. The other is a format-width
714 * rectangle that spans the rest of the lines that changed or moved.
716 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
717 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
718 rc
.bottom
= rc
.top
+ es
->line_height
;
719 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
720 rc
.left
= es
->format_rect
.left
;
722 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
723 rc
.right
= es
->format_rect
.right
;
724 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
727 rc
.left
= es
->format_rect
.left
;
728 rc
.right
= es
->format_rect
.right
;
730 * If lines were added or removed we must re-paint the remainder of the
731 * lines since the remaining lines were either shifted up or down.
733 if (line_count
< es
->line_count
) /* We added lines */
734 rc
.bottom
= es
->line_count
* es
->line_height
;
735 else if (line_count
> es
->line_count
) /* We removed lines */
736 rc
.bottom
= line_count
* es
->line_height
;
738 rc
.bottom
= line_index
* es
->line_height
;
739 rc
.bottom
+= es
->format_rect
.top
;
740 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
741 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
742 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
743 DeleteObject(tmphrgn
);
747 /*********************************************************************
749 * EDIT_CalcLineWidth_SL
752 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
754 EDIT_UpdateUniscribeData(es
, NULL
, 0);
758 size
= ScriptString_pSize(es
->ssa
);
759 es
->text_width
= size
->cx
;
765 /*********************************************************************
769 * Beware: This is not the function called on EM_CHARFROMPOS
770 * The position _can_ be outside the formatting / client
772 * The return value is only the character index
775 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
779 if (es
->style
& ES_MULTILINE
) {
781 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
783 LINEDEF
*line_def
= es
->first_line_def
;
784 EDIT_UpdateUniscribeData(es
, NULL
, line
);
785 while ((line
> 0) && line_def
->next
) {
786 line_index
+= line_def
->length
;
787 line_def
= line_def
->next
;
791 x
+= es
->x_offset
- es
->format_rect
.left
;
792 if (es
->style
& ES_RIGHT
)
793 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
794 else if (es
->style
& ES_CENTER
)
795 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
796 if (x
>= line_def
->width
) {
798 *after_wrap
= (line_def
->ending
== END_WRAP
);
799 return line_index
+ line_def
->net_length
;
801 if (x
<= 0 || !line_def
->ssa
) {
807 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
808 if (trailing
) index
++;
811 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
812 (line_def
->ending
== END_WRAP
));
818 x
-= es
->format_rect
.left
;
824 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
825 if (es
->style
& ES_RIGHT
)
827 else if (es
->style
& ES_CENTER
)
831 EDIT_UpdateUniscribeData(es
, NULL
, 0);
836 if (es
->x_offset
>= get_text_length(es
))
839 size
= ScriptString_pSize(es
->ssa
);
842 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
849 if (x
+ xoff
> 0 || !es
->ssa
)
851 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
852 if (trailing
) index
++;
861 const SIZE
*size
= NULL
;
863 size
= ScriptString_pSize(es
->ssa
);
866 else if (x
> size
->cx
)
867 index
= get_text_length(es
);
870 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
871 if (trailing
) index
++;
877 index
= es
->x_offset
;
884 /*********************************************************************
888 * adjusts the point to be within the formatting rectangle
889 * (so CharFromPos returns the nearest _visible_ character)
892 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
894 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
895 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
899 /*********************************************************************
904 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
909 if (!(es
->style
& ES_MULTILINE
))
911 if (index
> (INT
)get_text_length(es
))
912 return es
->line_count
- 1;
914 index
= min(es
->selection_start
, es
->selection_end
);
917 line_def
= es
->first_line_def
;
918 index
-= line_def
->length
;
919 while ((index
>= 0) && line_def
->next
) {
921 line_def
= line_def
->next
;
922 index
-= line_def
->length
;
928 /*********************************************************************
933 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
936 const LINEDEF
*line_def
;
938 if (!(es
->style
& ES_MULTILINE
))
940 if (line
>= es
->line_count
)
944 line_def
= es
->first_line_def
;
946 INT index
= es
->selection_end
- line_def
->length
;
947 while ((index
>= 0) && line_def
->next
) {
948 line_index
+= line_def
->length
;
949 line_def
= line_def
->next
;
950 index
-= line_def
->length
;
954 line_index
+= line_def
->length
;
955 line_def
= line_def
->next
;
963 /*********************************************************************
968 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
972 if (!(es
->style
& ES_MULTILINE
))
973 return get_text_length(es
);
976 /* get the number of remaining non-selected chars of selected lines */
977 INT32 l
; /* line number */
978 INT32 li
; /* index of first char in line */
980 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
981 /* # chars before start of selection area */
982 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
983 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
984 /* # chars after end of selection */
985 li
= EDIT_EM_LineIndex(es
, l
);
986 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
989 line_def
= es
->first_line_def
;
990 index
-= line_def
->length
;
991 while ((index
>= 0) && line_def
->next
) {
992 line_def
= line_def
->next
;
993 index
-= line_def
->length
;
995 return line_def
->net_length
;
999 /*********************************************************************
1004 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1006 INT len
= get_text_length(es
);
1015 index
= min(index
, len
);
1016 if (es
->style
& ES_MULTILINE
) {
1017 l
= EDIT_EM_LineFromChar(es
, index
);
1018 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1020 y
= (l
- es
->y_offset
) * es
->line_height
;
1021 li
= EDIT_EM_LineIndex(es
, l
);
1022 if (after_wrap
&& (li
== index
) && l
) {
1024 line_def
= es
->first_line_def
;
1026 line_def
= line_def
->next
;
1029 if (line_def
->ending
== END_WRAP
) {
1031 y
-= es
->line_height
;
1032 li
= EDIT_EM_LineIndex(es
, l
);
1036 line_def
= es
->first_line_def
;
1037 while (line_def
->index
!= li
)
1038 line_def
= line_def
->next
;
1040 lw
= line_def
->width
;
1041 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1044 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1050 if (es
->style
& ES_RIGHT
)
1052 else if (es
->style
& ES_CENTER
)
1057 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1062 if (es
->x_offset
>= get_text_length(es
))
1064 int leftover
= es
->x_offset
- get_text_length(es
);
1068 size
= ScriptString_pSize(es
->ssa
);
1073 xoff
+= es
->char_width
* leftover
;
1076 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1083 if (index
>= get_text_length(es
))
1088 size
= ScriptString_pSize(es
->ssa
);
1095 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1101 if (index
>= es
->x_offset
) {
1102 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1104 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1105 if (w
> es
->text_width
)
1107 if (es
->style
& ES_RIGHT
)
1108 x
+= w
- es
->text_width
;
1109 else if (es
->style
& ES_CENTER
)
1110 x
+= (w
- es
->text_width
) / 2;
1116 x
+= es
->format_rect
.left
;
1117 y
+= es
->format_rect
.top
;
1118 return MAKELONG((INT16
)x
, (INT16
)y
);
1122 /*********************************************************************
1126 * Calculates the bounding rectangle for a line from a starting
1127 * column to an ending column.
1130 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1132 SCRIPT_STRING_ANALYSIS ssa
;
1136 if (es
->style
& ES_MULTILINE
)
1138 const LINEDEF
*line_def
= NULL
;
1139 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1140 if (line
>= es
->line_count
)
1143 line_def
= es
->first_line_def
;
1145 INT index
= es
->selection_end
- line_def
->length
;
1146 while ((index
>= 0) && line_def
->next
) {
1147 line_index
+= line_def
->length
;
1148 line_def
= line_def
->next
;
1149 index
-= line_def
->length
;
1153 line_index
+= line_def
->length
;
1154 line_def
= line_def
->next
;
1158 ssa
= line_def
->ssa
;
1163 rc
->top
= es
->format_rect
.top
;
1167 rc
->bottom
= rc
->top
+ es
->line_height
;
1168 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1169 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1172 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1173 pt3
+=es
->format_rect
.left
;
1176 rc
->right
= max(max(pt1
, pt2
),pt3
);
1177 rc
->left
= min(min(pt1
, pt2
),pt3
);
1181 static inline void text_buffer_changed(EDITSTATE
*es
)
1183 es
->text_length
= (UINT
)-1;
1185 heap_free( es
->logAttr
);
1187 EDIT_InvalidateUniscribeData(es
);
1190 /*********************************************************************
1194 static void EDIT_LockBuffer(EDITSTATE
*es
)
1201 es
->text
= LocalLock(es
->hloc32W
);
1208 /*********************************************************************
1213 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1215 /* Edit window might be already destroyed */
1216 if (!IsWindow(es
->hwndSelf
))
1218 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1222 if (!es
->lock_count
)
1224 ERR("lock_count == 0 ... please report\n");
1230 ERR("es->text == 0 ... please report\n");
1234 if (force
|| (es
->lock_count
== 1))
1238 LocalUnlock(es
->hloc32W
);
1243 ERR("no buffer ... please report\n");
1253 /*********************************************************************
1257 * Try to fit size + 1 characters in the buffer.
1259 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1263 if (size
<= es
->buffer_size
)
1266 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1268 /* Force edit to unlock its buffer. es->text now NULL */
1269 EDIT_UnlockBuffer(es
, TRUE
);
1272 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1273 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1274 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1275 es
->hloc32W
= hNew32W
;
1276 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1280 EDIT_LockBuffer(es
);
1282 if (es
->buffer_size
< size
) {
1283 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1284 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1287 TRACE("We now have %d+1\n", es
->buffer_size
);
1293 /*********************************************************************
1297 * Try to fit size + 1 bytes in the undo buffer.
1300 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1304 if (size
<= es
->undo_buffer_size
)
1307 TRACE("trying to ReAlloc to %d+1\n", size
);
1309 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1310 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1311 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1316 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1322 /*********************************************************************
1324 * EDIT_UpdateTextRegion
1327 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1329 if (es
->flags
& EF_UPDATE
) {
1330 es
->flags
&= ~EF_UPDATE
;
1331 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1333 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1337 /*********************************************************************
1342 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1344 if (es
->flags
& EF_UPDATE
) {
1345 es
->flags
&= ~EF_UPDATE
;
1346 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1348 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1351 /*********************************************************************
1353 * EDIT_SL_InvalidateText
1355 * Called from EDIT_InvalidateText().
1356 * Does the job for single-line controls only.
1359 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1364 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1365 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1366 EDIT_UpdateText(es
, &rc
, TRUE
);
1369 /*********************************************************************
1371 * EDIT_ML_InvalidateText
1373 * Called from EDIT_InvalidateText().
1374 * Does the job for multi-line controls only.
1377 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1379 INT vlc
= get_vertical_line_count(es
);
1380 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1381 INT el
= EDIT_EM_LineFromChar(es
, end
);
1390 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1393 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1394 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1395 if (sl
< es
->y_offset
) {
1399 if (el
> es
->y_offset
+ vlc
) {
1400 el
= es
->y_offset
+ vlc
;
1401 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1403 GetClientRect(es
->hwndSelf
, &rc1
);
1404 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1406 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1407 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1408 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1410 EDIT_GetLineRect(es
, sl
, sc
,
1411 EDIT_EM_LineLength(es
,
1412 EDIT_EM_LineIndex(es
, sl
)),
1414 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1415 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1416 for (l
= sl
+ 1 ; l
< el
; l
++) {
1417 EDIT_GetLineRect(es
, l
, 0,
1418 EDIT_EM_LineLength(es
,
1419 EDIT_EM_LineIndex(es
, l
)),
1421 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1422 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1424 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1425 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1426 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1431 /*********************************************************************
1433 * EDIT_InvalidateText
1435 * Invalidate the text from offset start up to, but not including,
1436 * offset end. Useful for (re)painting the selection.
1437 * Regions outside the linewidth are not invalidated.
1438 * end == -1 means end == TextLength.
1439 * start and end need not be ordered.
1442 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1448 end
= get_text_length(es
);
1456 if (es
->style
& ES_MULTILINE
)
1457 EDIT_ML_InvalidateText(es
, start
, end
);
1459 EDIT_SL_InvalidateText(es
, start
, end
);
1463 /*********************************************************************
1467 * note: unlike the specs say: the order of start and end
1468 * _is_ preserved in Windows. (i.e. start can be > end)
1469 * In other words: this handler is OK
1472 static BOOL
EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1474 UINT old_start
= es
->selection_start
;
1475 UINT old_end
= es
->selection_end
;
1476 UINT len
= get_text_length(es
);
1478 if (start
== old_start
&& end
== old_end
)
1481 if (start
== (UINT
)-1) {
1482 start
= es
->selection_end
;
1483 end
= es
->selection_end
;
1485 start
= min(start
, len
);
1486 end
= min(end
, len
);
1488 es
->selection_start
= start
;
1489 es
->selection_end
= end
;
1491 es
->flags
|= EF_AFTER_WRAP
;
1493 es
->flags
&= ~EF_AFTER_WRAP
;
1494 /* Compute the necessary invalidation region. */
1495 /* Note that we don't need to invalidate regions which have
1496 * "never" been selected, or those which are "still" selected.
1497 * In fact, every time we hit a selection boundary, we can
1498 * *toggle* whether we need to invalidate. Thus we can optimize by
1499 * *sorting* the interval endpoints. Let's assume that we sort them
1501 * start <= end <= old_start <= old_end
1502 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1503 * in 5 comparisons; i.e. it is impossible to do better than the
1505 ORDER_UINT(end
, old_end
);
1506 ORDER_UINT(start
, old_start
);
1507 ORDER_UINT(old_start
, old_end
);
1508 ORDER_UINT(start
, end
);
1509 /* Note that at this point 'end' and 'old_start' are not in order, but
1510 * start is definitely the min. and old_end is definitely the max. */
1511 if (end
!= old_start
)
1515 * ORDER_UINT32(end, old_start);
1516 * EDIT_InvalidateText(es, start, end);
1517 * EDIT_InvalidateText(es, old_start, old_end);
1518 * in place of the following if statement.
1519 * (That would complete the optimal five-comparison four-element sort.)
1521 if (old_start
> end
)
1523 EDIT_InvalidateText(es
, start
, end
);
1524 EDIT_InvalidateText(es
, old_start
, old_end
);
1528 EDIT_InvalidateText(es
, start
, old_start
);
1529 EDIT_InvalidateText(es
, end
, old_end
);
1532 else EDIT_InvalidateText(es
, start
, old_end
);
1538 /*********************************************************************
1540 * EDIT_UpdateScrollInfo
1543 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1545 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1548 si
.cbSize
= sizeof(SCROLLINFO
);
1549 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1551 si
.nMax
= es
->line_count
- 1;
1552 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1553 si
.nPos
= es
->y_offset
;
1554 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1555 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1556 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1559 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1562 si
.cbSize
= sizeof(SCROLLINFO
);
1563 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1565 si
.nMax
= es
->text_width
- 1;
1566 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1567 si
.nPos
= es
->x_offset
;
1568 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1569 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1570 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1575 /*********************************************************************
1577 * EDIT_EM_LineScroll_internal
1579 * Version of EDIT_EM_LineScroll for internal use.
1580 * It doesn't refuse if ES_MULTILINE is set and assumes that
1581 * dx is in pixels, dy - in lines.
1584 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1587 INT x_offset_in_pixels
;
1588 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1591 if (es
->style
& ES_MULTILINE
)
1593 x_offset_in_pixels
= es
->x_offset
;
1598 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1601 if (-dx
> x_offset_in_pixels
)
1602 dx
= -x_offset_in_pixels
;
1603 if (dx
> es
->text_width
- x_offset_in_pixels
)
1604 dx
= es
->text_width
- x_offset_in_pixels
;
1605 nyoff
= max(0, es
->y_offset
+ dy
);
1606 if (nyoff
>= es
->line_count
- lines_per_page
)
1607 nyoff
= max(0, es
->line_count
- lines_per_page
);
1608 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1613 es
->y_offset
= nyoff
;
1614 if(es
->style
& ES_MULTILINE
)
1617 es
->x_offset
+= dx
/ es
->char_width
;
1619 GetClientRect(es
->hwndSelf
, &rc1
);
1620 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1621 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1622 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1623 /* force scroll info update */
1624 EDIT_UpdateScrollInfo(es
);
1626 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1627 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1628 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1629 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1633 /*********************************************************************
1637 * NOTE: dx is in average character widths, dy - in lines;
1640 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1642 if (!(es
->style
& ES_MULTILINE
))
1645 dx
*= es
->char_width
;
1646 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1650 /*********************************************************************
1655 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1659 if (!(es
->style
& ES_MULTILINE
))
1660 return (LRESULT
)FALSE
;
1670 if (es
->y_offset
< es
->line_count
- 1)
1675 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1678 if (es
->y_offset
< es
->line_count
- 1)
1679 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1682 return (LRESULT
)FALSE
;
1685 INT vlc
= get_vertical_line_count(es
);
1686 /* check if we are going to move too far */
1687 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1688 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1690 /* Notification is done in EDIT_EM_LineScroll */
1692 EDIT_EM_LineScroll(es
, 0, dy
);
1693 return MAKELONG(dy
, TRUE
);
1697 return (LRESULT
)FALSE
;
1701 /*********************************************************************
1706 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1709 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1710 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1711 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1715 /*********************************************************************
1720 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1722 if (es
->style
& ES_MULTILINE
) {
1726 INT cw
= es
->char_width
;
1731 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1732 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1733 vlc
= get_vertical_line_count(es
);
1734 if (l
>= es
->y_offset
+ vlc
)
1735 dy
= l
- vlc
+ 1 - es
->y_offset
;
1736 if (l
< es
->y_offset
)
1737 dy
= l
- es
->y_offset
;
1738 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1739 if (x
< es
->format_rect
.left
)
1740 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1741 if (x
> es
->format_rect
.right
)
1742 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1743 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1745 /* check if we are going to move too far */
1746 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1747 dx
= es
->text_width
- ww
- es
->x_offset
;
1748 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1749 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1756 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1757 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1758 if (x
< es
->format_rect
.left
) {
1759 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1762 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1763 } while ((x
< goal
) && es
->x_offset
);
1764 /* FIXME: use ScrollWindow() somehow to improve performance */
1765 EDIT_UpdateText(es
, NULL
, TRUE
);
1766 } else if (x
> es
->format_rect
.right
) {
1768 INT len
= get_text_length(es
);
1769 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1772 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1773 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1774 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1775 /* FIXME: use ScrollWindow() somehow to improve performance */
1776 EDIT_UpdateText(es
, NULL
, TRUE
);
1780 if(es
->flags
& EF_FOCUSED
)
1781 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1785 /*********************************************************************
1790 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1792 INT e
= es
->selection_end
;
1796 if ((es
->style
& ES_MULTILINE
) && e
&&
1797 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1799 if (e
&& (es
->text
[e
- 1] == '\r'))
1803 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1804 EDIT_EM_ScrollCaret(es
);
1808 /*********************************************************************
1812 * Only for multi line controls
1813 * Move the caret one line down, on a column with the nearest
1814 * x coordinate on the screen (might be a different column).
1817 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1819 INT s
= es
->selection_start
;
1820 INT e
= es
->selection_end
;
1821 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1822 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1823 INT x
= (short)LOWORD(pos
);
1824 INT y
= (short)HIWORD(pos
);
1826 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1829 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1830 EDIT_EM_ScrollCaret(es
);
1834 /*********************************************************************
1839 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1841 BOOL after_wrap
= FALSE
;
1844 /* Pass a high value in x to make sure of receiving the end of the line */
1845 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1846 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1847 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1849 e
= get_text_length(es
);
1850 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1851 EDIT_EM_ScrollCaret(es
);
1855 /*********************************************************************
1860 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1862 INT e
= es
->selection_end
;
1866 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1867 if (es
->text
[e
] == '\n')
1869 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1873 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1874 EDIT_EM_ScrollCaret(es
);
1878 /*********************************************************************
1882 * Home key: move to beginning of line.
1885 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1889 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1890 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1891 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1892 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1895 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1896 EDIT_EM_ScrollCaret(es
);
1900 /*********************************************************************
1902 * EDIT_MovePageDown_ML
1904 * Only for multi line controls
1905 * Move the caret one page down, on a column with the nearest
1906 * x coordinate on the screen (might be a different column).
1909 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1911 INT s
= es
->selection_start
;
1912 INT e
= es
->selection_end
;
1913 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1914 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1915 INT x
= (short)LOWORD(pos
);
1916 INT y
= (short)HIWORD(pos
);
1918 e
= EDIT_CharFromPos(es
, x
,
1919 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1923 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1924 EDIT_EM_ScrollCaret(es
);
1928 /*********************************************************************
1930 * EDIT_MovePageUp_ML
1932 * Only for multi line controls
1933 * Move the caret one page up, on a column with the nearest
1934 * x coordinate on the screen (might be a different column).
1937 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1939 INT s
= es
->selection_start
;
1940 INT e
= es
->selection_end
;
1941 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1942 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1943 INT x
= (short)LOWORD(pos
);
1944 INT y
= (short)HIWORD(pos
);
1946 e
= EDIT_CharFromPos(es
, x
,
1947 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1951 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1952 EDIT_EM_ScrollCaret(es
);
1956 /*********************************************************************
1960 * Only for multi line controls
1961 * Move the caret one line up, on a column with the nearest
1962 * x coordinate on the screen (might be a different column).
1965 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1967 INT s
= es
->selection_start
;
1968 INT e
= es
->selection_end
;
1969 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1970 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1971 INT x
= (short)LOWORD(pos
);
1972 INT y
= (short)HIWORD(pos
);
1974 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1977 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1978 EDIT_EM_ScrollCaret(es
);
1982 /*********************************************************************
1984 * EDIT_MoveWordBackward
1987 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1989 INT s
= es
->selection_start
;
1990 INT e
= es
->selection_end
;
1995 l
= EDIT_EM_LineFromChar(es
, e
);
1996 ll
= EDIT_EM_LineLength(es
, e
);
1997 li
= EDIT_EM_LineIndex(es
, l
);
2000 li
= EDIT_EM_LineIndex(es
, l
- 1);
2001 e
= li
+ EDIT_EM_LineLength(es
, li
);
2004 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2008 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2009 EDIT_EM_ScrollCaret(es
);
2013 /*********************************************************************
2015 * EDIT_MoveWordForward
2018 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2020 INT s
= es
->selection_start
;
2021 INT e
= es
->selection_end
;
2026 l
= EDIT_EM_LineFromChar(es
, e
);
2027 ll
= EDIT_EM_LineLength(es
, e
);
2028 li
= EDIT_EM_LineIndex(es
, l
);
2030 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2031 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2033 e
= li
+ EDIT_CallWordBreakProc(es
,
2034 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2038 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2039 EDIT_EM_ScrollCaret(es
);
2043 /*********************************************************************
2048 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2052 LOGFONTW underline_font
;
2053 HFONT hUnderline
= 0;
2062 BkMode
= GetBkMode(dc
);
2063 BkColor
= GetBkColor(dc
);
2064 TextColor
= GetTextColor(dc
);
2066 if (es
->composition_len
== 0)
2068 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2069 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2070 SetBkMode( dc
, OPAQUE
);
2074 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2075 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2076 underline_font
.lfUnderline
= TRUE
;
2077 hUnderline
= CreateFontIndirectW(&underline_font
);
2078 old_font
= SelectObject(dc
,hUnderline
);
2081 li
= EDIT_EM_LineIndex(es
, line
);
2082 if (es
->style
& ES_MULTILINE
) {
2083 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2084 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2086 TextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
);
2087 GetTextExtentPoint32W(dc
, es
->text
+ li
+ col
, count
, &size
);
2091 if (es
->composition_len
== 0)
2093 SetBkColor(dc
, BkColor
);
2094 SetTextColor(dc
, TextColor
);
2095 SetBkMode( dc
, BkMode
);
2100 SelectObject(dc
,old_font
);
2102 DeleteObject(hUnderline
);
2109 /*********************************************************************
2114 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2123 SCRIPT_STRING_ANALYSIS ssa
;
2125 if (es
->style
& ES_MULTILINE
) {
2126 INT vlc
= get_vertical_line_count(es
);
2128 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2133 TRACE("line=%d\n", line
);
2135 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2136 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2137 x
= (short)LOWORD(pos
);
2138 y
= (short)HIWORD(pos
);
2140 if (es
->style
& ES_MULTILINE
)
2142 int line_idx
= line
;
2144 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2146 LINEDEF
*line_def
= es
->first_line_def
;
2149 while (line_def
&& line_idx
)
2151 line_def
= line_def
->next
;
2154 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2155 lw
= line_def
->width
;
2157 if (es
->style
& ES_RIGHT
)
2159 else if (es
->style
& ES_CENTER
)
2162 x
+= es
->format_rect
.left
;
2167 li
= EDIT_EM_LineIndex(es
, line
);
2168 ll
= EDIT_EM_LineLength(es
, li
);
2169 s
= min(es
->selection_start
, es
->selection_end
);
2170 e
= max(es
->selection_start
, es
->selection_end
);
2171 s
= min(li
+ ll
, max(li
, s
));
2172 e
= min(li
+ ll
, max(li
, e
));
2176 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2177 else if (rev
&& (s
!= e
) &&
2178 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2179 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2180 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2181 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2183 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2187 /*********************************************************************
2189 * EDIT_AdjustFormatRect
2191 * Adjusts the format rectangle for the current font and the
2192 * current client rectangle.
2195 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2199 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2200 if (es
->style
& ES_MULTILINE
)
2202 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2204 vlc
= get_vertical_line_count(es
);
2205 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2207 /* correct es->x_offset */
2208 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2209 max_x_offset
= es
->text_width
- fw
;
2210 if(max_x_offset
< 0) max_x_offset
= 0;
2211 if(es
->x_offset
> max_x_offset
)
2212 es
->x_offset
= max_x_offset
;
2214 /* correct es->y_offset */
2215 max_y_offset
= es
->line_count
- vlc
;
2216 if(max_y_offset
< 0) max_y_offset
= 0;
2217 if(es
->y_offset
> max_y_offset
)
2218 es
->y_offset
= max_y_offset
;
2220 /* force scroll info update */
2221 EDIT_UpdateScrollInfo(es
);
2224 /* Windows doesn't care to fix text placement for SL controls */
2225 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2227 /* Always stay within the client area */
2228 GetClientRect(es
->hwndSelf
, &ClientRect
);
2229 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2231 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2232 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2234 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2238 /*********************************************************************
2242 * note: this is not (exactly) the handler called on EM_SETRECTNP
2243 * it is also used to set the rect of a single line control
2246 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2250 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2252 CopyRect(&es
->format_rect
, rc
);
2254 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2255 es
->format_rect
.left
++;
2256 es
->format_rect
.right
--;
2258 if (es
->format_rect
.bottom
- es
->format_rect
.top
2259 >= es
->line_height
+ 2)
2261 es
->format_rect
.top
++;
2262 es
->format_rect
.bottom
--;
2265 else if (es
->style
& WS_BORDER
) {
2266 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2267 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2268 InflateRect(&es
->format_rect
, -bw
, 0);
2269 if (es
->format_rect
.bottom
- es
->format_rect
.top
>= es
->line_height
+ 2 * bh
)
2270 InflateRect(&es
->format_rect
, 0, -bh
);
2273 es
->format_rect
.left
+= es
->left_margin
;
2274 es
->format_rect
.right
-= es
->right_margin
;
2275 EDIT_AdjustFormatRect(es
);
2279 /*********************************************************************
2283 * returns line number (not index) in high-order word of result.
2284 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2285 * to Richedit, not to the edit control. Original documentation is valid.
2286 * FIXME: do the specs mean to return -1 if outside client area or
2287 * if outside formatting rectangle ???
2290 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2298 GetClientRect(es
->hwndSelf
, &rc
);
2299 if (!PtInRect(&rc
, pt
))
2302 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2303 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2307 /*********************************************************************
2311 * Enable or disable soft breaks.
2313 * This means: insert or remove the soft linebreak character (\r\r\n).
2314 * Take care to check if the text still fits the buffer after insertion.
2315 * If not, notify with EN_ERRSPACE.
2318 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2320 es
->flags
&= ~EF_USE_SOFTBRK
;
2322 es
->flags
|= EF_USE_SOFTBRK
;
2323 FIXME("soft break enabled, not implemented\n");
2329 /*********************************************************************
2333 * Hopefully this won't fire back at us.
2334 * We always start with a fixed buffer in the local heap.
2335 * Despite of the documentation says that the local heap is used
2336 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2337 * buffer on the local heap.
2340 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2342 if (!(es
->style
& ES_MULTILINE
))
2345 EDIT_UnlockBuffer(es
, TRUE
);
2347 /* The text buffer handle belongs to the app */
2348 es
->hlocapp
= es
->hloc32W
;
2350 TRACE("Returning %p, LocalSize() = %ld\n", es
->hlocapp
, LocalSize(es
->hlocapp
));
2355 /*********************************************************************
2360 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
)
2362 INT line_len
, dst_len
;
2366 if (es
->style
& ES_MULTILINE
)
2368 if (line
>= es
->line_count
)
2374 i
= EDIT_EM_LineIndex(es
, line
);
2376 line_len
= EDIT_EM_LineLength(es
, i
);
2377 dst_len
= *(WORD
*)dst
;
2379 if (dst_len
<= line_len
)
2381 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2384 else /* Append 0 if enough space */
2386 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2393 /*********************************************************************
2398 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2400 UINT s
= es
->selection_start
;
2401 UINT e
= es
->selection_end
;
2408 return MAKELONG(s
, e
);
2412 /*********************************************************************
2416 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2419 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, const WCHAR
*lpsz_replace
, UINT strl
,
2420 BOOL send_update
, BOOL honor_limit
)
2422 UINT tl
= get_text_length(es
);
2433 TRACE("%s, can_undo %d, send_update %d\n",
2434 debugstr_wn(lpsz_replace
, strl
), can_undo
, send_update
);
2436 s
= es
->selection_start
;
2437 e
= es
->selection_end
;
2439 EDIT_InvalidateUniscribeData(es
);
2440 if ((s
== e
) && !strl
)
2445 size
= tl
- (e
- s
) + strl
;
2449 /* Issue the EN_MAXTEXT notification and continue with replacing text
2450 * so that buffer limit is honored. */
2451 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2452 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2453 /* Buffer limit can be smaller than the actual length of text in combobox */
2454 if (es
->buffer_limit
< (tl
- (e
-s
)))
2457 strl
= min(strl
, es
->buffer_limit
- (tl
- (e
-s
)));
2460 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2464 /* there is something to be deleted */
2465 TRACE("deleting stuff.\n");
2467 buf
= heap_alloc((bufl
+ 1) * sizeof(WCHAR
));
2469 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2470 buf
[bufl
] = 0; /* ensure 0 termination */
2472 strcpyW(es
->text
+ s
, es
->text
+ e
);
2473 text_buffer_changed(es
);
2476 /* there is an insertion */
2477 tl
= get_text_length(es
);
2478 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
));
2479 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2481 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2482 p
[i
] = lpsz_replace
[i
];
2483 if(es
->style
& ES_UPPERCASE
)
2484 CharUpperBuffW(p
, strl
);
2485 else if(es
->style
& ES_LOWERCASE
)
2486 CharLowerBuffW(p
, strl
);
2487 text_buffer_changed(es
);
2489 if (es
->style
& ES_MULTILINE
)
2491 INT st
= min(es
->selection_start
, es
->selection_end
);
2492 INT vlc
= get_vertical_line_count(es
);
2494 hrgn
= CreateRectRgn(0, 0, 0, 0);
2495 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2496 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2497 /* if text is too long undo all changes */
2498 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2500 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2502 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2504 text_buffer_changed(es
);
2505 EDIT_BuildLineDefs_ML(es
, s
, e
,
2506 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2509 hrgn
= CreateRectRgn(0, 0, 0, 0);
2510 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2514 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2515 EDIT_InvalidateUniscribeData(es
);
2516 EDIT_CalcLineWidth_SL(es
);
2517 /* remove chars that don't fit */
2518 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2519 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2520 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2522 es
->text_length
= -1;
2523 EDIT_InvalidateUniscribeData(es
);
2524 EDIT_CalcLineWidth_SL(es
);
2526 text_buffer_changed(es
);
2527 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2533 utl
= strlenW(es
->undo_text
);
2534 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2535 /* undo-buffer is extended to the right */
2536 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2537 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2538 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2539 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2540 /* undo-buffer is extended to the left */
2541 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2542 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2544 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2546 es
->undo_position
= s
;
2548 /* new undo-buffer */
2549 EDIT_MakeUndoFit(es
, e
- s
);
2550 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2551 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2552 es
->undo_position
= s
;
2554 /* any deletion makes the old insertion-undo invalid */
2555 es
->undo_insert_count
= 0;
2557 EDIT_EM_EmptyUndoBuffer(es
);
2561 if ((s
== es
->undo_position
) ||
2562 ((es
->undo_insert_count
) &&
2563 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2565 * insertion is new and at delete position or
2566 * an extension to either left or right
2568 es
->undo_insert_count
+= strl
;
2570 /* new insertion undo */
2571 es
->undo_position
= s
;
2572 es
->undo_insert_count
= strl
;
2573 /* new insertion makes old delete-buffer invalid */
2574 *es
->undo_text
= '\0';
2577 EDIT_EM_EmptyUndoBuffer(es
);
2584 /* If text has been deleted and we're right or center aligned then scroll rightward */
2585 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2587 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2589 if (delta
< 0 && es
->x_offset
)
2591 if (abs(delta
) > es
->x_offset
)
2594 es
->x_offset
+= delta
;
2598 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2599 es
->flags
|= EF_MODIFIED
;
2600 if (send_update
) es
->flags
|= EF_UPDATE
;
2603 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2607 EDIT_UpdateText(es
, NULL
, TRUE
);
2609 EDIT_EM_ScrollCaret(es
);
2611 /* force scroll info update */
2612 EDIT_UpdateScrollInfo(es
);
2615 if(send_update
|| (es
->flags
& EF_UPDATE
))
2617 es
->flags
&= ~EF_UPDATE
;
2618 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2620 EDIT_InvalidateUniscribeData(es
);
2624 /*********************************************************************
2628 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2631 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2633 if (!(es
->style
& ES_MULTILINE
))
2639 EDIT_UnlockBuffer(es
, TRUE
);
2642 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2644 /* The text buffer handle belongs to the control */
2647 EDIT_LockBuffer(es
);
2648 text_buffer_changed(es
);
2650 es
->x_offset
= es
->y_offset
= 0;
2651 es
->selection_start
= es
->selection_end
= 0;
2652 EDIT_EM_EmptyUndoBuffer(es
);
2653 es
->flags
&= ~EF_MODIFIED
;
2654 es
->flags
&= ~EF_UPDATE
;
2655 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2656 EDIT_UpdateText(es
, NULL
, TRUE
);
2657 EDIT_EM_ScrollCaret(es
);
2658 /* force scroll info update */
2659 EDIT_UpdateScrollInfo(es
);
2663 /*********************************************************************
2667 * NOTE: this version currently implements WinNT limits
2670 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2672 if (!limit
) limit
= ~0u;
2673 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2674 es
->buffer_limit
= limit
;
2678 /*********************************************************************
2682 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2683 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2684 * margin according to the textmetrics of the current font.
2686 * When EC_USEFONTINFO is used in the non_cjk case the margins only
2687 * change if the edit control is equal to or larger than a certain
2688 * size. Though there is an exception for the empty client rect case
2689 * with small font sizes.
2691 static BOOL
is_cjk(UINT charset
)
2695 case SHIFTJIS_CHARSET
:
2696 case HANGUL_CHARSET
:
2697 case GB2312_CHARSET
:
2698 case CHINESEBIG5_CHARSET
:
2701 /* HANGUL_CHARSET is strange, though treated as CJK by Win 8, it is
2702 * not by other versions including Win 10. */
2706 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2707 WORD left
, WORD right
, BOOL repaint
)
2710 INT default_left_margin
= 0; /* in pixels */
2711 INT default_right_margin
= 0; /* in pixels */
2713 /* Set the default margins depending on the font */
2714 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2715 HDC dc
= GetDC(es
->hwndSelf
);
2716 HFONT old_font
= SelectObject(dc
, es
->font
);
2717 LONG width
= GdiGetCharDimensions(dc
, &tm
, NULL
);
2720 /* The default margins are only non zero for TrueType or Vector fonts */
2721 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2722 if (!is_cjk(tm
.tmCharSet
)) {
2723 default_left_margin
= width
/ 2;
2724 default_right_margin
= width
/ 2;
2726 GetClientRect(es
->hwndSelf
, &rc
);
2727 if (rc
.right
- rc
.left
< (width
/ 2 + width
) * 2 &&
2728 (width
>= 28 || !IsRectEmpty(&rc
)) ) {
2729 default_left_margin
= es
->left_margin
;
2730 default_right_margin
= es
->right_margin
;
2733 /* FIXME: figure out the CJK values. They are not affected by the client rect. */
2734 default_left_margin
= width
/ 2;
2735 default_right_margin
= width
/ 2;
2738 SelectObject(dc
, old_font
);
2739 ReleaseDC(es
->hwndSelf
, dc
);
2742 if (action
& EC_LEFTMARGIN
) {
2743 es
->format_rect
.left
-= es
->left_margin
;
2744 if (left
!= EC_USEFONTINFO
)
2745 es
->left_margin
= left
;
2747 es
->left_margin
= default_left_margin
;
2748 es
->format_rect
.left
+= es
->left_margin
;
2751 if (action
& EC_RIGHTMARGIN
) {
2752 es
->format_rect
.right
+= es
->right_margin
;
2753 if (right
!= EC_USEFONTINFO
)
2754 es
->right_margin
= right
;
2756 es
->right_margin
= default_right_margin
;
2757 es
->format_rect
.right
-= es
->right_margin
;
2760 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2761 EDIT_AdjustFormatRect(es
);
2762 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2765 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2769 /*********************************************************************
2771 * EM_SETPASSWORDCHAR
2774 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2778 if (es
->style
& ES_MULTILINE
)
2781 if (es
->password_char
== c
)
2784 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2785 es
->password_char
= c
;
2787 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2788 es
->style
|= ES_PASSWORD
;
2790 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2791 es
->style
&= ~ES_PASSWORD
;
2793 EDIT_InvalidateUniscribeData(es
);
2794 EDIT_UpdateText(es
, NULL
, TRUE
);
2798 /*********************************************************************
2803 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2805 if (!(es
->style
& ES_MULTILINE
))
2807 heap_free(es
->tabs
);
2808 es
->tabs_count
= count
;
2812 es
->tabs
= heap_alloc(count
* sizeof(INT
));
2813 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2815 EDIT_InvalidateUniscribeData(es
);
2820 /*********************************************************************
2822 * EM_SETWORDBREAKPROC
2825 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, EDITWORDBREAKPROCW wbp
)
2827 if (es
->word_break_proc
== wbp
)
2830 es
->word_break_proc
= wbp
;
2832 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2833 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2834 EDIT_UpdateText(es
, NULL
, TRUE
);
2839 /*********************************************************************
2844 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
2849 /* As per MSDN spec, for a single-line edit control,
2850 the return value is always TRUE */
2851 if( es
->style
& ES_READONLY
)
2852 return !(es
->style
& ES_MULTILINE
);
2854 ulength
= strlenW(es
->undo_text
);
2856 utext
= heap_alloc((ulength
+ 1) * sizeof(WCHAR
));
2858 strcpyW(utext
, es
->undo_text
);
2860 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2861 es
->undo_insert_count
, debugstr_w(utext
));
2863 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2864 EDIT_EM_EmptyUndoBuffer(es
);
2865 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, ulength
, TRUE
, TRUE
);
2866 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2867 /* send the notification after the selection start and end are set */
2868 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2869 EDIT_EM_ScrollCaret(es
);
2872 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2873 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
2878 /* Helper function for WM_CHAR
2880 * According to an MSDN blog article titled "Just because you're a control
2881 * doesn't mean that you're necessarily inside a dialog box," multiline edit
2882 * controls without ES_WANTRETURN would attempt to detect whether it is inside
2883 * a dialog box or not.
2885 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
2887 return (es
->flags
& EF_DIALOGMODE
);
2891 /*********************************************************************
2896 static void EDIT_WM_Paste(EDITSTATE
*es
)
2902 /* Protect read-only edit control from modification */
2903 if(es
->style
& ES_READONLY
)
2906 OpenClipboard(es
->hwndSelf
);
2907 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
2908 src
= GlobalLock(hsrc
);
2910 /* Protect single-line edit against pasting new line character */
2911 if (!(es
->style
& ES_MULTILINE
) && ((ptr
= strchrW(src
, '\n')))) {
2913 if (len
&& src
[len
- 1] == '\r')
2916 EDIT_EM_ReplaceSel(es
, TRUE
, src
, len
, TRUE
, TRUE
);
2919 else if (es
->style
& ES_PASSWORD
) {
2920 /* clear selected text in password edit box even with empty clipboard */
2921 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2927 /*********************************************************************
2932 static void EDIT_WM_Copy(EDITSTATE
*es
)
2934 INT s
= min(es
->selection_start
, es
->selection_end
);
2935 INT e
= max(es
->selection_start
, es
->selection_end
);
2943 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
2944 dst
= GlobalLock(hdst
);
2945 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
2946 dst
[len
] = 0; /* ensure 0 termination */
2947 TRACE("%s\n", debugstr_w(dst
));
2949 OpenClipboard(es
->hwndSelf
);
2951 SetClipboardData(CF_UNICODETEXT
, hdst
);
2956 /*********************************************************************
2961 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
2963 /* Protect read-only edit control from modification */
2964 if(es
->style
& ES_READONLY
)
2967 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2971 /*********************************************************************
2976 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
2983 /*********************************************************************
2988 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
2992 control
= GetKeyState(VK_CONTROL
) & 0x8000;
2996 /* If it's not a multiline edit box, it would be ignored below.
2997 * For multiline edit without ES_WANTRETURN, we have to make a
3000 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3001 if (EDIT_IsInsideDialog(es
))
3004 if (es
->style
& ES_MULTILINE
) {
3005 if (es
->style
& ES_READONLY
) {
3006 EDIT_MoveHome(es
, FALSE
, FALSE
);
3007 EDIT_MoveDown_ML(es
, FALSE
);
3009 static const WCHAR cr_lfW
[] = {'\r','\n'};
3010 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, 2, TRUE
, TRUE
);
3015 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3017 static const WCHAR tabW
[] = {'\t'};
3018 if (EDIT_IsInsideDialog(es
))
3020 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, 1, TRUE
, TRUE
);
3024 if (!(es
->style
& ES_READONLY
) && !control
) {
3025 if (es
->selection_start
!= es
->selection_end
)
3028 /* delete character left of caret */
3029 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3030 EDIT_MoveBackward(es
, TRUE
);
3036 if (!(es
->style
& ES_PASSWORD
))
3037 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3040 if (!(es
->style
& ES_READONLY
))
3041 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3044 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3045 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3048 if (!(es
->style
& ES_READONLY
))
3049 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3053 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3054 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3057 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127))
3058 EDIT_EM_ReplaceSel(es
, TRUE
, &c
, 1, TRUE
, TRUE
);
3065 /*********************************************************************
3067 * EDIT_ContextMenuCommand
3070 static void EDIT_ContextMenuCommand(EDITSTATE
*es
, UINT id
)
3074 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3077 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3080 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3083 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3086 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3089 SendMessageW(es
->hwndSelf
, EM_SETSEL
, 0, -1);
3092 ERR("unknown menu item, please report\n");
3098 /*********************************************************************
3102 * Note: the resource files resource/sysres_??.rc cannot define a
3103 * single popup menu. Hence we use a (dummy) menubar
3104 * containing the single popup menu as its first item.
3106 * FIXME: the message identifiers have been chosen arbitrarily,
3107 * hence we use MF_BYPOSITION.
3108 * We might as well use the "real" values (anybody knows ?)
3109 * The menu definition is in resources/sysres_??.rc.
3110 * Once these are OK, we better use MF_BYCOMMAND here
3111 * (as we do in EDIT_WM_Command()).
3114 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3116 HMENU menu
= LoadMenuA(GetModuleHandleA("user32.dll"), "EDITMENU");
3117 HMENU popup
= GetSubMenu(menu
, 0);
3118 UINT start
= es
->selection_start
;
3119 UINT end
= es
->selection_end
;
3123 ORDER_UINT(start
, end
);
3126 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3128 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3130 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3132 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3134 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3136 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3141 if (pt
.x
== -1 && pt
.y
== -1) /* passed via VK_APPS press/release */
3145 /* Windows places the menu at the edit's center in this case */
3146 GetClientRect(es
->hwndSelf
, &rc
);
3147 pt
.x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3148 pt
.y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3149 ClientToScreen(es
->hwndSelf
, &pt
);
3152 if (!(es
->flags
& EF_FOCUSED
))
3153 SetFocus(es
->hwndSelf
);
3155 cmd
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
| TPM_NONOTIFY
,
3156 pt
.x
, pt
.y
, 0, es
->hwndSelf
, NULL
);
3159 EDIT_ContextMenuCommand(es
, cmd
);
3165 /*********************************************************************
3170 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
)
3175 lstrcpynW(dst
, es
->text
, count
);
3176 return strlenW(dst
);
3179 /*********************************************************************
3184 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3186 HWND hLBox
= es
->hwndListBox
;
3194 hCombo
= GetParent(es
->hwndSelf
);
3198 TRACE("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3200 if (key
== VK_UP
|| key
== VK_DOWN
)
3202 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3205 if (msg
== WM_KEYDOWN
|| nEUI
)
3206 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3212 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3214 /* make sure ComboLBox pops up */
3215 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3220 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3223 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3225 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, !bDropped
, 0);
3227 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3232 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3238 /*********************************************************************
3242 * Handling of special keys that don't produce a WM_CHAR
3243 * (i.e. non-printable keys) & Backspace & Delete
3246 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3251 if (GetKeyState(VK_MENU
) & 0x8000)
3254 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3255 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3260 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3265 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3266 EDIT_MoveUp_ML(es
, shift
);
3269 EDIT_MoveWordBackward(es
, shift
);
3271 EDIT_MoveBackward(es
, shift
);
3274 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3278 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3279 EDIT_MoveDown_ML(es
, shift
);
3281 EDIT_MoveWordForward(es
, shift
);
3283 EDIT_MoveForward(es
, shift
);
3286 EDIT_MoveHome(es
, shift
, control
);
3289 EDIT_MoveEnd(es
, shift
, control
);
3292 if (es
->style
& ES_MULTILINE
)
3293 EDIT_MovePageUp_ML(es
, shift
);
3295 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3298 if (es
->style
& ES_MULTILINE
)
3299 EDIT_MovePageDown_ML(es
, shift
);
3301 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3304 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3305 if (es
->selection_start
!= es
->selection_end
) {
3312 /* delete character left of caret */
3313 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3314 EDIT_MoveBackward(es
, TRUE
);
3316 } else if (control
) {
3317 /* delete to end of line */
3318 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3319 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3322 /* delete character right of caret */
3323 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3324 EDIT_MoveForward(es
, TRUE
);
3332 if (!(es
->style
& ES_READONLY
))
3338 /* If the edit doesn't want the return send a message to the default object */
3339 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3343 if (!EDIT_IsInsideDialog(es
)) break;
3345 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3346 if (HIWORD(dw
) == DC_HASDEFID
)
3348 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3351 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3352 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3358 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3359 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3362 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3363 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3368 if (EDIT_EM_SetSel(es
, 0, get_text_length(es
), FALSE
))
3370 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3371 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3380 /*********************************************************************
3385 static LRESULT
EDIT_WM_KillFocus(HTHEME theme
, EDITSTATE
*es
)
3387 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3389 es
->flags
&= ~EF_FOCUSED
;
3391 if (!(es
->style
& ES_NOHIDESEL
))
3392 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3393 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3394 /* Throw away left over scroll when we lose focus */
3395 es
->wheelDeltaRemainder
= 0;
3400 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3405 /*********************************************************************
3409 * The caret position has been set on the WM_LBUTTONDOWN message
3412 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3415 INT e
= es
->selection_end
;
3420 es
->bCaptureState
= TRUE
;
3421 SetCapture(es
->hwndSelf
);
3423 l
= EDIT_EM_LineFromChar(es
, e
);
3424 li
= EDIT_EM_LineIndex(es
, l
);
3425 ll
= EDIT_EM_LineLength(es
, e
);
3426 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3427 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3428 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3429 EDIT_EM_ScrollCaret(es
);
3430 es
->region_posx
= es
->region_posy
= 0;
3431 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3436 /*********************************************************************
3441 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3446 es
->bCaptureState
= TRUE
;
3447 SetCapture(es
->hwndSelf
);
3448 EDIT_ConfinePoint(es
, &x
, &y
);
3449 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3450 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3451 EDIT_EM_ScrollCaret(es
);
3452 es
->region_posx
= es
->region_posy
= 0;
3453 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3455 if (!(es
->flags
& EF_FOCUSED
))
3456 SetFocus(es
->hwndSelf
);
3462 /*********************************************************************
3467 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3469 if (es
->bCaptureState
) {
3470 KillTimer(es
->hwndSelf
, 0);
3471 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3473 es
->bCaptureState
= FALSE
;
3478 /*********************************************************************
3483 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3485 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3490 /*********************************************************************
3495 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3501 /* If the mouse has been captured by process other than the edit control itself,
3502 * the windows edit controls will not select the strings with mouse move.
3504 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3508 * FIXME: gotta do some scrolling if outside client
3509 * area. Maybe reset the timer ?
3512 EDIT_ConfinePoint(es
, &x
, &y
);
3513 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3514 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3515 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3516 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3517 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3522 /*********************************************************************
3527 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3540 BOOL rev
= es
->bEnableState
&&
3541 ((es
->flags
& EF_FOCUSED
) ||
3542 (es
->style
& ES_NOHIDESEL
));
3543 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3545 /* The dc we use for calculating may not be the one we paint into.
3546 This is the safest action. */
3547 EDIT_InvalidateUniscribeData(es
);
3548 GetClientRect(es
->hwndSelf
, &rcClient
);
3550 /* get the background brush */
3551 brush
= EDIT_NotifyCtlColor(es
, dc
);
3553 /* paint the border and the background */
3554 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3556 if(es
->style
& WS_BORDER
) {
3557 bw
= GetSystemMetrics(SM_CXBORDER
);
3558 bh
= GetSystemMetrics(SM_CYBORDER
);
3560 if(es
->style
& ES_MULTILINE
) {
3561 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3562 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3565 /* Draw the frame. Same code as in nonclient.c */
3566 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3567 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3568 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3569 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3570 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3571 SelectObject(dc
, old_brush
);
3573 /* Keep the border clean */
3574 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3575 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3578 GetClipBox(dc
, &rc
);
3579 FillRect(dc
, &rc
, brush
);
3581 IntersectClipRect(dc
, es
->format_rect
.left
,
3582 es
->format_rect
.top
,
3583 es
->format_rect
.right
,
3584 es
->format_rect
.bottom
);
3585 if (es
->style
& ES_MULTILINE
) {
3587 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3590 old_font
= SelectObject(dc
, es
->font
);
3592 if (!es
->bEnableState
)
3593 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3594 GetClipBox(dc
, &rcRgn
);
3595 if (es
->style
& ES_MULTILINE
) {
3596 INT vlc
= get_vertical_line_count(es
);
3597 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3598 EDIT_UpdateUniscribeData(es
, dc
, i
);
3599 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3600 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3601 EDIT_PaintLine(es
, dc
, i
, rev
);
3604 EDIT_UpdateUniscribeData(es
, dc
, 0);
3605 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3606 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3607 EDIT_PaintLine(es
, dc
, 0, rev
);
3610 SelectObject(dc
, old_font
);
3613 EndPaint(es
->hwndSelf
, &ps
);
3616 static void EDIT_WM_NCPaint(HWND hwnd
, HRGN region
)
3618 DWORD exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3619 HTHEME theme
= GetWindowTheme(hwnd
);
3620 HRGN cliprgn
= region
;
3622 if (theme
&& exStyle
& WS_EX_CLIENTEDGE
)
3626 int cxEdge
= GetSystemMetrics(SM_CXEDGE
),
3627 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
3628 const int part
= EP_EDITTEXT
;
3629 int state
= ETS_NORMAL
;
3630 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3632 if (!IsWindowEnabled(hwnd
))
3633 state
= ETS_DISABLED
;
3634 else if (dwStyle
& ES_READONLY
)
3635 state
= ETS_READONLY
;
3636 else if (GetFocus() == hwnd
)
3637 state
= ETS_FOCUSED
;
3639 GetWindowRect(hwnd
, &r
);
3641 /* New clipping region passed to default proc to exclude border */
3642 cliprgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
,
3643 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
3644 if (region
!= (HRGN
)1)
3645 CombineRgn(cliprgn
, cliprgn
, region
, RGN_AND
);
3646 OffsetRect(&r
, -r
.left
, -r
.top
);
3648 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
3649 OffsetRect(&r
, -r
.left
, -r
.top
);
3651 if (IsThemeBackgroundPartiallyTransparent(theme
, part
, state
))
3652 DrawThemeParentBackground(hwnd
, dc
, &r
);
3653 DrawThemeBackground(theme
, dc
, part
, state
, &r
, 0);
3654 ReleaseDC(hwnd
, dc
);
3657 /* Call default proc to get the scrollbars etc. also painted */
3658 DefWindowProcW (hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
3661 /*********************************************************************
3666 static void EDIT_WM_SetFocus(HTHEME theme
, EDITSTATE
*es
)
3668 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3670 es
->flags
|= EF_FOCUSED
;
3672 if (!(es
->style
& ES_NOHIDESEL
))
3673 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3675 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3676 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3677 ShowCaret(es
->hwndSelf
);
3678 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3681 flags
|= RDW_FRAME
| RDW_ERASE
;
3683 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3687 /*********************************************************************
3691 * With Win95 look the margins are set to default font value unless
3692 * the system font (font == 0) is being set, in which case they are left
3696 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3704 EDIT_InvalidateUniscribeData(es
);
3705 dc
= GetDC(es
->hwndSelf
);
3707 old_font
= SelectObject(dc
, font
);
3708 GetTextMetricsW(dc
, &tm
);
3709 es
->line_height
= tm
.tmHeight
;
3710 es
->char_width
= tm
.tmAveCharWidth
;
3712 SelectObject(dc
, old_font
);
3713 ReleaseDC(es
->hwndSelf
, dc
);
3715 /* Reset the format rect and the margins */
3716 GetClientRect(es
->hwndSelf
, &clientRect
);
3717 EDIT_SetRectNP(es
, &clientRect
);
3718 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3719 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3721 if (es
->style
& ES_MULTILINE
)
3722 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3724 EDIT_CalcLineWidth_SL(es
);
3727 EDIT_UpdateText(es
, NULL
, TRUE
);
3728 if (es
->flags
& EF_FOCUSED
) {
3730 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3731 EDIT_SetCaretPos(es
, es
->selection_end
,
3732 es
->flags
& EF_AFTER_WRAP
);
3733 ShowCaret(es
->hwndSelf
);
3738 /*********************************************************************
3743 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3744 * The modified flag is reset. No notifications are sent.
3746 * For single-line controls, reception of WM_SETTEXT triggers:
3747 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3750 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
)
3752 if (es
->flags
& EF_UPDATE
)
3753 /* fixed this bug once; complain if we see it about to happen again. */
3754 ERR("SetSel may generate UPDATE message whose handler may reset "
3757 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3760 TRACE("%s\n", debugstr_w(text
));
3761 EDIT_EM_ReplaceSel(es
, FALSE
, text
, strlenW(text
), FALSE
, FALSE
);
3766 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3769 es
->flags
&= ~EF_MODIFIED
;
3770 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3772 /* Send the notification after the selection start and end have been set
3773 * edit control doesn't send notification on WM_SETTEXT
3774 * if it is multiline, or it is part of combobox
3776 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3778 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3779 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3781 EDIT_EM_ScrollCaret(es
);
3782 EDIT_UpdateScrollInfo(es
);
3783 EDIT_InvalidateUniscribeData(es
);
3787 /*********************************************************************
3792 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3794 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3796 GetClientRect(es
->hwndSelf
, &rc
);
3797 EDIT_SetRectNP(es
, &rc
);
3798 EDIT_UpdateText(es
, NULL
, TRUE
);
3803 /*********************************************************************
3807 * This message is sent by SetWindowLong on having changed either the Style
3808 * or the extended style.
3810 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3812 * See also EDIT_WM_NCCreate
3814 * It appears that the Windows version of the edit control allows the style
3815 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3816 * style variable which will generally be different. In this function we
3817 * update the internal style based on what changed in the externally visible
3820 * Much of this content as based upon the MSDN, especially:
3821 * Platform SDK Documentation -> User Interface Services ->
3822 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3823 * Edit Control Styles
3825 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3827 if (GWL_STYLE
== which
) {
3828 DWORD style_change_mask
;
3830 /* Only a subset of changes can be applied after the control
3833 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3835 if (es
->style
& ES_MULTILINE
)
3836 style_change_mask
|= ES_WANTRETURN
;
3838 new_style
= style
->styleNew
& style_change_mask
;
3840 /* Number overrides lowercase overrides uppercase (at least it
3841 * does in Win95). However I'll bet that ES_NUMBER would be
3842 * invalid under Win 3.1.
3844 if (new_style
& ES_NUMBER
) {
3845 ; /* do not override the ES_NUMBER */
3846 } else if (new_style
& ES_LOWERCASE
) {
3847 new_style
&= ~ES_UPPERCASE
;
3850 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3851 } else if (GWL_EXSTYLE
== which
) {
3852 ; /* FIXME - what is needed here */
3854 WARN ("Invalid style change %ld\n",which
);
3860 /*********************************************************************
3865 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3867 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3868 if (EDIT_EM_CanUndo(es
))
3871 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3872 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3875 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3879 /*********************************************************************
3884 static void EDIT_WM_Timer(EDITSTATE
*es
)
3886 if (es
->region_posx
< 0) {
3887 EDIT_MoveBackward(es
, TRUE
);
3888 } else if (es
->region_posx
> 0) {
3889 EDIT_MoveForward(es
, TRUE
);
3892 * FIXME: gotta do some vertical scrolling here, like
3893 * EDIT_EM_LineScroll(hwnd, 0, 1);
3897 /*********************************************************************
3902 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3907 if (!(es
->style
& ES_MULTILINE
))
3910 if (!(es
->style
& ES_AUTOHSCROLL
))
3914 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3917 TRACE("SB_LINELEFT\n");
3919 dx
= -es
->char_width
;
3922 TRACE("SB_LINERIGHT\n");
3923 if (es
->x_offset
< es
->text_width
)
3924 dx
= es
->char_width
;
3927 TRACE("SB_PAGELEFT\n");
3929 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3932 TRACE("SB_PAGERIGHT\n");
3933 if (es
->x_offset
< es
->text_width
)
3934 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3942 TRACE("SB_RIGHT\n");
3943 if (es
->x_offset
< es
->text_width
)
3944 dx
= es
->text_width
- es
->x_offset
;
3947 TRACE("SB_THUMBTRACK %d\n", pos
);
3948 es
->flags
|= EF_HSCROLL_TRACK
;
3949 if(es
->style
& WS_HSCROLL
)
3950 dx
= pos
- es
->x_offset
;
3955 if(pos
< 0 || pos
> 100) return 0;
3956 /* Assume default scroll range 0-100 */
3957 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3958 new_x
= pos
* (es
->text_width
- fw
) / 100;
3959 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3962 case SB_THUMBPOSITION
:
3963 TRACE("SB_THUMBPOSITION %d\n", pos
);
3964 es
->flags
&= ~EF_HSCROLL_TRACK
;
3965 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3966 dx
= pos
- es
->x_offset
;
3971 if(pos
< 0 || pos
> 100) return 0;
3972 /* Assume default scroll range 0-100 */
3973 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3974 new_x
= pos
* (es
->text_width
- fw
) / 100;
3975 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3978 /* force scroll info update */
3979 EDIT_UpdateScrollInfo(es
);
3980 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3984 TRACE("SB_ENDSCROLL\n");
3987 * FIXME : the next two are undocumented !
3988 * Are we doing the right thing ?
3989 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3990 * although it's also a regular control message.
3992 case EM_GETTHUMB
: /* this one is used by NT notepad */
3995 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3996 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3999 /* Assume default scroll range 0-100 */
4000 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4001 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4003 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4007 TRACE("EM_LINESCROLL16\n");
4012 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4018 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4019 /* check if we are going to move too far */
4020 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4021 dx
= es
->text_width
- fw
- es
->x_offset
;
4023 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4029 /*********************************************************************
4034 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4038 if (!(es
->style
& ES_MULTILINE
))
4041 if (!(es
->style
& ES_AUTOVSCROLL
))
4050 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4051 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4052 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4054 EDIT_EM_Scroll(es
, action
);
4061 TRACE("SB_BOTTOM\n");
4062 dy
= es
->line_count
- 1 - es
->y_offset
;
4065 TRACE("SB_THUMBTRACK %d\n", pos
);
4066 es
->flags
|= EF_VSCROLL_TRACK
;
4067 if(es
->style
& WS_VSCROLL
)
4068 dy
= pos
- es
->y_offset
;
4071 /* Assume default scroll range 0-100 */
4074 if(pos
< 0 || pos
> 100) return 0;
4075 vlc
= get_vertical_line_count(es
);
4076 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4077 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4078 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4079 es
->line_count
, es
->y_offset
, pos
, dy
);
4082 case SB_THUMBPOSITION
:
4083 TRACE("SB_THUMBPOSITION %d\n", pos
);
4084 es
->flags
&= ~EF_VSCROLL_TRACK
;
4085 if(es
->style
& WS_VSCROLL
)
4086 dy
= pos
- es
->y_offset
;
4089 /* Assume default scroll range 0-100 */
4092 if(pos
< 0 || pos
> 100) return 0;
4093 vlc
= get_vertical_line_count(es
);
4094 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4095 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4096 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4097 es
->line_count
, es
->y_offset
, pos
, dy
);
4101 /* force scroll info update */
4102 EDIT_UpdateScrollInfo(es
);
4103 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4107 TRACE("SB_ENDSCROLL\n");
4110 * FIXME : the next two are undocumented !
4111 * Are we doing the right thing ?
4112 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4113 * although it's also a regular control message.
4115 case EM_GETTHUMB
: /* this one is used by NT notepad */
4118 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4119 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4122 /* Assume default scroll range 0-100 */
4123 INT vlc
= get_vertical_line_count(es
);
4124 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4126 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4130 TRACE("EM_LINESCROLL %d\n", pos
);
4135 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4140 EDIT_EM_LineScroll(es
, 0, dy
);
4144 /*********************************************************************
4148 * FIXME: is this right ? (or should it be only VSCROLL)
4149 * (and maybe only for edit controls that really have their
4150 * own scrollbars) (and maybe only for multiline controls ?)
4151 * All in all: very poorly documented
4154 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4156 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4157 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4161 /********************************************************************
4163 * The Following code is to handle inline editing from IMEs
4166 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4170 LPSTR lpCompStrAttr
= NULL
;
4173 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4180 lpCompStr
= heap_alloc(buflen
);
4183 ERR("Unable to allocate IME CompositionString\n");
4188 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4190 if (CompFlag
& GCS_COMPATTR
)
4193 * We do not use the attributes yet. it would tell us what characters
4194 * are in transition and which are converted or decided upon
4196 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4200 lpCompStrAttr
= heap_alloc(dwBufLenAttr
+ 1);
4203 ERR("Unable to allocate IME Attribute String\n");
4204 heap_free(lpCompStr
);
4207 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4209 lpCompStrAttr
[dwBufLenAttr
] = 0;
4213 /* check for change in composition start */
4214 if (es
->selection_end
< es
->composition_start
)
4215 es
->composition_start
= es
->selection_end
;
4217 /* replace existing selection string */
4218 es
->selection_start
= es
->composition_start
;
4220 if (es
->composition_len
> 0)
4221 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4223 es
->selection_end
= es
->selection_start
;
4225 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4226 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4228 es
->selection_start
= es
->composition_start
;
4229 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4231 heap_free(lpCompStrAttr
);
4232 heap_free(lpCompStr
);
4235 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4240 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4246 lpResultStr
= heap_alloc(buflen
);
4249 ERR("Unable to alloc buffer for IME string\n");
4253 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4255 /* check for change in composition start */
4256 if (es
->selection_end
< es
->composition_start
)
4257 es
->composition_start
= es
->selection_end
;
4259 es
->selection_start
= es
->composition_start
;
4260 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4261 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4262 es
->composition_start
= es
->selection_end
;
4263 es
->composition_len
= 0;
4265 heap_free(lpResultStr
);
4268 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4273 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4275 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4276 es
->composition_start
= es
->selection_end
;
4279 hIMC
= ImmGetContext(hwnd
);
4283 if (CompFlag
& GCS_RESULTSTR
)
4285 EDIT_GetResultStr(hIMC
, es
);
4290 if (CompFlag
& GCS_COMPSTR
)
4291 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4292 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4294 ImmReleaseContext(hwnd
, hIMC
);
4295 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4299 /*********************************************************************
4303 * See also EDIT_WM_StyleChanged
4305 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
4310 TRACE("Creating edit control, style = %08x\n", lpcs
->style
);
4312 if (!(es
= heap_alloc_zero(sizeof(*es
))))
4314 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4317 * Note: since the EDITSTATE has not been fully initialized yet,
4318 * we can't use any API calls that may send
4319 * WM_XXX messages before WM_NCCREATE is completed.
4322 es
->style
= lpcs
->style
;
4324 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4326 es
->hwndSelf
= hwnd
;
4327 /* Save parent, which will be notified by EN_* messages */
4328 es
->hwndParent
= lpcs
->hwndParent
;
4330 if (es
->style
& ES_COMBO
)
4331 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4333 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4334 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4336 /* Number overrides lowercase overrides uppercase (at least it
4337 * does in Win95). However I'll bet that ES_NUMBER would be
4338 * invalid under Win 3.1.
4340 if (es
->style
& ES_NUMBER
) {
4341 ; /* do not override the ES_NUMBER */
4342 } else if (es
->style
& ES_LOWERCASE
) {
4343 es
->style
&= ~ES_UPPERCASE
;
4345 if (es
->style
& ES_MULTILINE
) {
4346 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4347 if (es
->style
& WS_VSCROLL
)
4348 es
->style
|= ES_AUTOVSCROLL
;
4349 if (es
->style
& WS_HSCROLL
)
4350 es
->style
|= ES_AUTOHSCROLL
;
4351 es
->style
&= ~ES_PASSWORD
;
4352 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4353 /* Confirmed - RIGHT overrides CENTER */
4354 if (es
->style
& ES_RIGHT
)
4355 es
->style
&= ~ES_CENTER
;
4356 es
->style
&= ~WS_HSCROLL
;
4357 es
->style
&= ~ES_AUTOHSCROLL
;
4360 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4361 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4362 es
->style
&= ~ES_CENTER
;
4363 es
->style
&= ~WS_HSCROLL
;
4364 es
->style
&= ~WS_VSCROLL
;
4365 if (es
->style
& ES_PASSWORD
)
4366 es
->password_char
= '*';
4369 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4370 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4372 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4374 if (!(es
->undo_text
= heap_alloc_zero((es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4376 es
->undo_buffer_size
= es
->buffer_size
;
4378 if (es
->style
& ES_MULTILINE
)
4379 if (!(es
->first_line_def
= heap_alloc_zero(sizeof(LINEDEF
))))
4384 * In Win95 look and feel, the WS_BORDER style is replaced by the
4385 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4386 * control a nonclient area so we don't need to draw the border.
4387 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4388 * a nonclient area and we should handle painting the border ourselves.
4390 * When making modifications please ensure that the code still works
4391 * for edit controls created directly with style 0x50800000, exStyle 0
4392 * (which should have a single pixel border)
4394 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4395 es
->style
&= ~WS_BORDER
;
4396 else if (es
->style
& WS_BORDER
)
4397 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4402 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4403 EDIT_InvalidateUniscribeData(es
);
4404 heap_free(es
->first_line_def
);
4405 heap_free(es
->undo_text
);
4406 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4407 heap_free(es
->logAttr
);
4413 /*********************************************************************
4418 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, const WCHAR
*name
)
4422 TRACE("%s\n", debugstr_w(name
));
4425 * To initialize some final structure members, we call some helper
4426 * functions. However, since the EDITSTATE is not consistent (i.e.
4427 * not fully initialized), we should be very careful which
4428 * functions can be called, and in what order.
4430 EDIT_WM_SetFont(es
, 0, FALSE
);
4431 EDIT_EM_EmptyUndoBuffer(es
);
4433 /* We need to calculate the format rect
4434 (applications may send EM_SETMARGINS before the control gets visible) */
4435 GetClientRect(es
->hwndSelf
, &clientRect
);
4436 EDIT_SetRectNP(es
, &clientRect
);
4440 EDIT_EM_ReplaceSel(es
, FALSE
, name
, strlenW(name
), FALSE
, FALSE
);
4441 /* if we insert text to the editline, the text scrolls out
4442 * of the window, as the caret is placed after the insert
4443 * pos normally; thus we reset es->selection... to 0 and
4446 es
->selection_start
= es
->selection_end
= 0;
4447 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4448 * Messages are only to be sent when the USER does something to
4449 * change the contents. So I am removing this EN_CHANGE
4451 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4453 EDIT_EM_ScrollCaret(es
);
4456 /* force scroll info update */
4457 EDIT_UpdateScrollInfo(es
);
4458 OpenThemeData(es
->hwndSelf
, WC_EDITW
);
4460 /* The rule seems to return 1 here for success */
4461 /* Power Builder masked edit controls will crash */
4463 /* FIXME: is that in all cases so ? */
4468 /*********************************************************************
4473 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4478 theme
= GetWindowTheme(es
->hwndSelf
);
4479 CloseThemeData(theme
);
4481 /* The app can own the text buffer handle */
4482 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
))
4483 LocalFree(es
->hloc32W
);
4485 EDIT_InvalidateUniscribeData(es
);
4487 pc
= es
->first_line_def
;
4495 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4496 heap_free(es
->undo_text
);
4502 static LRESULT CALLBACK
EDIT_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4504 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW(hwnd
, 0);
4505 HTHEME theme
= GetWindowTheme(hwnd
);
4509 TRACE("hwnd=%p msg=%#x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
4511 if (!es
&& msg
!= WM_NCCREATE
)
4512 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4514 if (es
&& (msg
!= WM_NCDESTROY
))
4515 EDIT_LockBuffer(es
);
4520 result
= EDIT_EM_GetSel(es
, (UINT
*)wParam
, (UINT
*)lParam
);
4524 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4525 EDIT_EM_ScrollCaret(es
);
4530 rect
= (RECT
*)lParam
;
4532 *rect
= es
->format_rect
;
4536 if ((es
->style
& ES_MULTILINE
) && lParam
)
4538 EDIT_SetRectNP(es
, (RECT
*)lParam
);
4539 EDIT_UpdateText(es
, NULL
, TRUE
);
4544 if ((es
->style
& ES_MULTILINE
) && lParam
)
4545 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4549 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4553 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4556 case EM_SCROLLCARET
:
4557 EDIT_EM_ScrollCaret(es
);
4562 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4567 es
->flags
|= EF_MODIFIED
;
4569 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4572 case EM_GETLINECOUNT
:
4573 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4577 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4581 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4585 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4589 result
= EDIT_EM_GetThumb(es
);
4592 /* these messages missing from specs */
4597 FIXME("undocumented message 0x%x, please report\n", msg
);
4598 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4602 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4607 const WCHAR
*textW
= (const WCHAR
*)lParam
;
4609 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, strlenW(textW
), TRUE
, TRUE
);
4615 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4618 case EM_SETLIMITTEXT
:
4619 EDIT_EM_SetLimitText(es
, wParam
);
4623 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4628 result
= (LRESULT
)EDIT_EM_Undo(es
);
4632 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4635 case EM_LINEFROMCHAR
:
4636 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4639 case EM_SETTABSTOPS
:
4640 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4643 case EM_SETPASSWORDCHAR
:
4644 EDIT_EM_SetPasswordChar(es
, wParam
);
4647 case EM_EMPTYUNDOBUFFER
:
4648 EDIT_EM_EmptyUndoBuffer(es
);
4651 case EM_GETFIRSTVISIBLELINE
:
4652 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4655 case EM_SETREADONLY
:
4657 DWORD old_style
= es
->style
;
4661 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | ES_READONLY
);
4662 es
->style
|= ES_READONLY
;
4666 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4667 es
->style
&= ~ES_READONLY
;
4670 if (old_style
^ es
->style
)
4671 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4677 case EM_SETWORDBREAKPROC
:
4678 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4682 case EM_GETWORDBREAKPROC
:
4683 result
= (LRESULT
)es
->word_break_proc
;
4686 case EM_GETPASSWORDCHAR
:
4687 result
= es
->password_char
;
4691 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4695 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4698 case EM_GETLIMITTEXT
:
4699 result
= es
->buffer_limit
;
4702 case EM_POSFROMCHAR
:
4703 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4704 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4707 case EM_CHARFROMPOS
:
4708 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4711 /* End of the EM_ messages which were in numerical order; what order
4712 * are these in? vaguely alphabetical?
4716 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
4720 result
= EDIT_WM_NCDestroy(es
);
4725 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4727 if (es
->style
& ES_MULTILINE
)
4728 result
|= DLGC_WANTALLKEYS
;
4732 MSG
*msg
= (MSG
*)lParam
;
4733 es
->flags
|= EF_DIALOGMODE
;
4735 if (msg
->message
== WM_KEYDOWN
)
4737 int vk
= (int)msg
->wParam
;
4739 if (es
->hwndListBox
)
4741 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4742 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4743 result
|= DLGC_WANTMESSAGE
;
4752 WCHAR charW
= wParam
;
4754 if (es
->hwndListBox
)
4756 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4758 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4759 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4763 result
= EDIT_WM_Char(es
, charW
);
4768 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4769 if (wParam
<= 0x000fffff)
4771 if (wParam
> 0xffff) /* convert to surrogates */
4774 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4775 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4778 EDIT_WM_Char(es
, wParam
);
4786 case WM_CONTEXTMENU
:
4787 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4795 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4803 es
->bEnableState
= (BOOL
) wParam
;
4804 EDIT_UpdateText(es
, NULL
, TRUE
);
4806 RedrawWindow(hwnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
4810 /* we do the proper erase in EDIT_WM_Paint */
4815 result
= (LRESULT
)es
->font
;
4819 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4822 case WM_GETTEXTLENGTH
:
4823 result
= get_text_length(es
);
4827 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4831 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4835 result
= EDIT_WM_KillFocus(theme
, es
);
4838 case WM_LBUTTONDBLCLK
:
4839 result
= EDIT_WM_LButtonDblClk(es
);
4842 case WM_LBUTTONDOWN
:
4843 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4847 result
= EDIT_WM_LButtonUp(es
);
4850 case WM_MBUTTONDOWN
:
4851 result
= EDIT_WM_MButtonDown(es
);
4855 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4858 case WM_PRINTCLIENT
:
4860 EDIT_WM_Paint(es
, (HDC
)wParam
);
4864 EDIT_WM_NCPaint(hwnd
, (HRGN
)wParam
);
4872 EDIT_WM_SetFocus(theme
, es
);
4876 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4880 /* FIXME: actually set an internal flag and behave accordingly */
4884 EDIT_WM_SetText(es
, (const WCHAR
*)lParam
);
4889 EDIT_WM_Size(es
, (UINT
)wParam
);
4892 case WM_STYLECHANGED
:
4893 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4896 case WM_STYLECHANGING
:
4897 result
= 0; /* See EDIT_WM_StyleChanged */
4901 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
4909 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4915 UINT pulScrollLines
= 3;
4916 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4918 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4920 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4924 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4925 /* if scrolling changes direction, ignore left overs */
4926 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
4927 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
4928 es
->wheelDeltaRemainder
+= wheelDelta
;
4930 es
->wheelDeltaRemainder
= wheelDelta
;
4932 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
4935 pulScrollLines
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
4936 cLineScroll
= pulScrollLines
* (float)es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
4937 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
4938 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
4943 /* IME messages to make the edit control IME aware */
4944 case WM_IME_SETCONTEXT
:
4947 case WM_IME_STARTCOMPOSITION
:
4948 es
->composition_start
= es
->selection_end
;
4949 es
->composition_len
= 0;
4952 case WM_IME_COMPOSITION
:
4953 EDIT_ImeComposition(hwnd
, lParam
, es
);
4956 case WM_IME_ENDCOMPOSITION
:
4957 if (es
->composition_len
> 0)
4959 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4960 es
->selection_end
= es
->selection_start
;
4961 es
->composition_len
= 0;
4965 case WM_IME_COMPOSITIONFULL
:
4971 case WM_IME_CONTROL
:
4974 case WM_IME_REQUEST
:
4977 case IMR_QUERYCHARPOSITION
:
4979 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
4982 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
4983 chpos
->pt
.x
= LOWORD(pos
);
4984 chpos
->pt
.y
= HIWORD(pos
);
4985 chpos
->cLineHeight
= es
->line_height
;
4986 chpos
->rcDocument
= es
->format_rect
;
4987 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
4988 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
4995 case WM_THEMECHANGED
:
4996 CloseThemeData (theme
);
4997 OpenThemeData(hwnd
, WC_EDITW
);
5001 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5005 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
5006 EDIT_UnlockBuffer(es
, FALSE
);
5008 TRACE("hwnd=%p msg=%x -- 0x%08lx\n", hwnd
, msg
, result
);
5013 void EDIT_Register(void)
5017 memset(&wndClass
, 0, sizeof(wndClass
));
5018 wndClass
.style
= CS_PARENTDC
| CS_GLOBALCLASS
| CS_DBLCLKS
;
5019 wndClass
.lpfnWndProc
= EDIT_WindowProc
;
5020 wndClass
.cbClsExtra
= 0;
5022 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*) + sizeof(WORD
);
5024 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*);
5026 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_IBEAM
);
5027 wndClass
.hbrBackground
= NULL
;
5028 wndClass
.lpszClassName
= WC_EDITW
;
5029 RegisterClassW(&wndClass
);